Under construction

Still being built. Things may change

Add Test Data

Time limit1sMemory limit1024 MB

Summary
Given M, print a maze of size at most 60 where the end is reachable but the number of paths from start to end is a multiple of M.
Level

Medium7 of 10

Topics
Dynamic programming, Math, Implementation
Solved
No attempts yet

Problem

Hyunbin wants to become an expert in dynamic programming, so he solves dynamic programming problems on an online judge every day. As usual, he was searching for one when he found the following problem.

There is an N×NN \times N maze. The top-left cell is (1,1)(1, 1) and the bottom-right cell is (N,N)(N, N). Each cell is either empty or a wall. Starting from (1,1)(1, 1), you want to reach (N,N)(N, N) by following these rules.

  1. When the current position is (r,c)(r, c), if (r,c+1)(r, c+1) is empty, you can move to (r,c+1)(r, c+1).
  2. When the current position is (r,c)(r, c), if (r+1,c)(r+1, c) is empty, you can move to (r+1,c)(r+1, c).
  3. When the current position is (r,c)(r, c), if (r+1,c)(r+1, c) and (r+2,c)(r+2, c) are both empty, you can move to (r+2,c)(r+2, c) in one step.

The start and the end cells are always empty. Print the number of ways to get from the start to the end, modulo MM. If the end cannot be reached from the start, print −1-1.

As soon as he saw it, Hyunbin thought it was a very simple dynamic programming problem, and he wrote the code in one minute. The pseudocode of his code is below.

function solve(N, M, Map):
    DP = [N + 1][N + 1]  # declare a DP array of size (N + 1) x (N + 1), filled with 0
    DP[1][1] = 1 % M  # set the start

    # '.' is an empty cell, '#' is a wall
    for r from 1 to N:
        for c from 1 to N:
            if Map[r][c] is '#':
                continue

            if r + 1 <= N and Map[r + 1][c] is '.':
                DP[r + 1][c] = (DP[r + 1][c] + DP[r][c]) % M  # move type 1

            if c + 1 <= N and Map[r][c + 1] is '.':
                DP[r][c + 1] = (DP[r][c + 1] + DP[r][c]) % M  # move type 2

            if r + 2 <= N and (Map[r + 1][c] and Map[r + 2][c]) is '.':
                DP[r + 2][c] = (DP[r + 2][c] + DP[r][c]) % M  # move type 3

    if DP[N][N] is 0:
        DP[N][N] = -1

    return DP[N][N]

His code was accepted, but Minwoo pointed out that it is wrong. If the end can be reached and the number of ways is a multiple of MM, the answer should be 00, but Hyunbin's code prints −1-1. Add test data that makes Hyunbin's code fail.

Input

The first line contains a positive integer MM (1≤M≤314 159 2651 \le M \le 314\,159\,265).

Output

On the first line, print an integer NN (2≤N≤602 \leq N \leq 60), the size of the maze.

On the next NN lines, print the maze as strings made only of . and #. The jj-th character of the ii-th line gives the state of cell (i,j)(i, j). . means an empty cell and # means a wall. The start and the end cells must be empty.

Examples2

  1. Example 1

    Input
    1
    
    Expected output
    2
    ..
    #.
    
  2. Example 2

    Input
    2
    
    Expected output
    3
    .##
    .##
    ...