N, S, E, W = 1, 2, 4, 8
DX = { E => 1, W => -1, N => 0, S => 0 }
DY = { E => 0, W => 0, N => -1, S => 1 }
OPPOSITE = { E => W, W => E, N => S, S => N }
TiwgUywgRSwgVyA9IDEsIDIsIDQsIDgKRFggICAgICAgICA9IHsgRSA9PiAxLCBXID0+IC0xLCBOID0+ICAwLCBTID0+IDAgfQpEWSAgICAgICAgID0geyBFID0+IDAsIFcgPT4gIDAsIE4gPT4gLTEsIFMgPT4gMSB9Ck9QUE9TSVRFICAgPSB7IEUgPT4gVywgVyA9PiAgRSwgTiA9PiAgUywgUyA9PiBOIH0=