The Chicago Art Museum's Renaissance display consists of four hallways bordered around a square courtyard. A single guard is assigned to patrol the four hallways. When the guard starts working, he begins in one of the corners and walks clockwise. When he arrives at a subsequent corner he flips two coins. If both coins are heads, he changes the direction he is walking. Otherwise, he continues in the same direction. Let E be the expected number of lengths of hallway that he walks before he first returns to his starting corner. Let p be the probability that he walks strictly more than E lengths of hallway before returning to his starting corner. p can be expressed as ab where a and b are coprime positive integers. What is the value of a+b?

The guard may walk in the same hallway more than one time. Each time he walks in it counts as one length of hallway.

To find the value of a+b, we need to determine two things: the expected number of lengths of hallway E, and the probability p that the guard walks strictly more than E lengths before returning to his starting corner.

Let's start by calculating E, the expected number of lengths of hallway the guard walks before he first returns to his starting corner.

The guard starts in one of the corners and walks clockwise, so he walks a total of 4 lengths of hallway to complete a full circle around the courtyard. At each subsequent corner, he flips two coins. If both coins are heads, he changes direction; otherwise, he continues in the same direction.

Let's denote E_1, E_2, E_3, and E_4 as the expected number of lengths of hallway the guard walks before he returns to the starting corner when he is at the first, second, third, and fourth corner, respectively.

Since the guard starts at the first corner, he either returns to the starting corner immediately (probability 1/4) or moves to the second corner after one length of hallway (probability 3/4). In the latter case, the expected number of lengths of hallway he walks is E_2.

Similarly, at the second corner, the guard either returns to the starting corner immediately (probability 1/4) or moves to the third corner after one length of hallway (probability 3/4). In the latter case, the expected number of lengths of hallway he walks is E_3.

At the third corner, the guard can either return to the starting corner immediately (probability 1/4), move to the fourth corner after one length of hallway (probability 1/4), or stay at the third corner and change direction after two lengths of hallway (probability 1/2). The expected number of lengths of hallway he walks in the latter case is E_1.

At the fourth corner, the guard can either return to the starting corner immediately (probability 1/4), move to the first corner after one length of hallway (probability 1/4), or stay at the fourth corner and change direction after two lengths of hallway (probability 1/2). The expected number of lengths of hallway he walks in the latter case is E_2.

We can write the following equations:

E_1 = 1/4 + (3/4)(E_2)
E_2 = 1/4 + (3/4)(E_3)
E_3 = 1/4 + 1/4 + (1/2)(E_1)
E_4 = 1/4 + 1/4 + (1/2)(E_2)

To solve these equations, we can substitute the equations into each other to eliminate variables:

E_1 = 1/4 + (3/4)(1/4 + (3/4)(1/4 + (1/2)(E_1)))
E_1 = 1/4 + 3/16 + 9/64 + 3/128 + 9/128(E_1)
E_1 = 35/64 + 9/128(E_1)

Simplifying,

(128/128)(E_1) = (35/64) + (9/128)(E_1)
(119/128)(E_1) = 35/64

E_1 = (35/64)(128/119)
E_1 = 35/119

Therefore, the expected number of lengths of hallway E is 35/119.

Next, let's calculate the probability p that the guard walks strictly more than E lengths before returning to his starting corner.

To do this, we need to determine the probability that the guard walks exactly E lengths before returning. We can denote this probability as P(E).

To find P(E), let's consider the first corner. The guard moves from the first corner to the second corner after one length of hallway, and then continues in the same direction for E-1 more lengths of hallway before returning to the starting corner. So the probability of this happening is (3/4)(1/4)^(E-1).

Since there are four corners where the guard can start, the probability P(E) is:

P(E) = 4 * (3/4)(1/4)^(E-1)

The probability p that the guard walks strictly more than E lengths is 1 - P(E):

p = 1 - P(E)
p = 1 - 4 * (3/4)(1/4)^(E-1)
p = 1 - 4 * (3/4)(1/4)^(35/119-1)
p = 1 - 4 * (3/4)(1/4)^(34/119)
p = 1 - (3/4)(1/4)^(34/119+2)
p = 1 - (3/4)(1/4)^(4/7)
p = 1 - (3/4)(2/7)
p = 1 - 6/28
p = 22/28

Therefore, the value of a+b is 22+28=50.