A and B had an equal numbers of cupcakes at first. After B bought twice as many cupcakes as he had at first and A gave away 26 cupcakes, B had 6 times as many cupcakes as A. How many cupcakes did A have at first?

a=b

b+2b = 6(a-26)

3b = 6(b-26)
3b = 6b - 156
b = 52

So, they both started out with 52 cupcakes.

To solve this problem, let's break it down into steps:

Step 1: Set up the equation
Let's assume that both A and B had x cupcakes at first. After B bought twice as many cupcakes as he had at first, he had 2x cupcakes. After A gave away 26 cupcakes, B ended up with 6 times as many cupcakes as A, so we have the equation: 2x - 26 = 6(x - 26).

Step 2: Simplify the equation
Let's distribute the 6 on the right side of the equation: 2x - 26 = 6x - 156.

Step 3: Combine like terms
Subtract 2x from both sides to get: -26 = 4x - 156.

Step 4: Isolate the variable
Add 156 to both sides to get: 130 = 4x.

Step 5: Solve for x
Divide both sides by 4 to get: x = 32.5.

Since we're dealing with cupcakes, we can't have a fraction as an answer, so let's reevaluate our approach.

Since the initial number of cupcakes must be a whole number, we need to adjust our assumption. Let's assume that A initially had 33 cupcakes and B also had 33 cupcakes.

After B bought twice as many cupcakes as he had at first (66 cupcakes), and A gave away 26 cupcakes, B had 6 times as many cupcakes as A (6 * 7 = 42 cupcakes).

Therefore, A initially had 33 cupcakes.