PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000097. Bạn có thể thắng không? (Can U Win?)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bạn có thể thắng không? (Can U Win?)

Can U Win?

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

You control a chess knight k on an 8×88\times8 board with enemy pawns P, empty squares ., and forbidden cells #. The knight moves in L-shapes, with offsets (±1,±2)(\pm1,\pm2) or (±2,±1)(\pm2,\pm1). It may leap over occupied cells but may not land on a forbidden square. Determine whether the knight can capture all P pawns in at most NN moves.

Input

First an integer NN, the maximum number of moves. Exactly 8 board rows follow, each containing 8 characters from {k,P,.,#}. There is exactly one k piece; pp is the number of P pawns.

Output

Print exactly Yes if every pawn can be captured within at most NN moves; otherwise print No.

Subtasks

  • Subtask 1 (40 points): 0≤N≤8,  0≤p≤40\le N\le 8,\;0\le p\le 4. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 0≤N≤22,  0≤p≤80\le N\le 22,\;0\le p\le 8. All input-format and graph conditions above apply.

Examples

Input

1
k.......
..P.....
........
........
........
........
........
........

Output

Yes

Explanation

Knight k starts at row 1, column 1; pawn P is at row 2, column 3. Offset (1,2)(1,2) is a legal knight move. Since N=1N=1, the answer is Yes.