Katniss is in a very long straight tunnel and wants to get out of it. She can move along the tunnel in both directions. There is exactly one hatch in the tunnel, and if she reaches it, she can exit.

Unfortunately, it's not that simple. There are grates blocking the entire width of the tunnel at $n$ locations. The grates are locked, and Katniss cannot pass through a grate until she unlocks it. Fortunately, there are $n$ keys located at $n$ points along the tunnel. Each grate can be unlocked by exactly one of these $n$ keys. Once a grate is unlocked, Katniss can freely and repeatedly pass through it. She can pick up and hold an unlimited number of keys.

Katniss knows her own location, as well as the locations of all $n$ keys, all $n$ grates, and the hatch. She also knows which key unlocks which grate. Determine the minimum distance she must travel to escape.