#!/bin/python import sys def out_of_bounds(n, x, a): if x+a > n-1 or x+a < 0: return True else: return False def play_chess(n, x, y, a, b, moves, moves_list): moves_count = [] moves += 1 if (x+a == n-1 and y+b == n-1) or (x+b == n-1 and y+a == n-1) or (x-a == n-1 and y-b == n-1) or (x-b == n-1 and y-a == n-1) or (x+a == n-1 and y-b == n-1) or (x+b == n-1 and y-a == n-1) or (x-a == n-1 and y+b == n-1) or (x-b == n-1 and y+a == n-1): return moves if not out_of_bounds(n, x, a) and not out_of_bounds(n, y, b): if (x+a, y+b) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x+a, y+b, a, b, moves, moves_list+[(x+a, y+b)])) if not out_of_bounds(n, x, -a) and not out_of_bounds(n, y, b): if (x-a, y+b) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x-a, y+b, a, b, moves, moves_list+[(x-a, y+b)])) if not out_of_bounds(n, x, a) and not out_of_bounds(n, y, -b): if (x+a, y-b) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x+a, y-b, a, b, moves, moves_list+[(x+a, y-b)])) if not out_of_bounds(n, x, -a) and not out_of_bounds(n, y, -b): if (x-a, y-b) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x-a, y-b, a, b, moves, moves_list+[(x-a, y-b)])) if not out_of_bounds(n, x, b) and not out_of_bounds(n, y, a): if (x+b, y+a) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x+b, y+a, a, b, moves, moves_list+[(x+b, y+a)])) if not out_of_bounds(n, x, -b) and not out_of_bounds(n, y, a): if (x-b, y+a) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x-b, y+a, a, b, moves, moves_list+[(x-b, y+a)])) if not out_of_bounds(n, x, b) and not out_of_bounds(n, y, -a): if (x+b, y-a) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x+b, y-a, a, b, moves, moves_list+[(x+b, y-a)])) if not out_of_bounds(n, x, -b) and not out_of_bounds(n, y, -a): if (x-b, y-a) in moves_list: moves_count.append(-1) else: moves_count.append(play_chess(n, x-b, y-a, a, b, moves, moves_list+[(x-b, y-a)])) #if m1 != None and m2 != None: # if m1 <= m2: # return m1 # else: # return m2 #elif m1 != None: # return m1 #elif m2 != None: # return m2 moves_count = [m for m in moves_count if m != -1] if len(moves_count) == 0: return -1 else: return min(moves_count) if __name__ == "__main__": n = int(raw_input().strip()) for i in range(1, n): chest_moves = [] for j in range(1, n): chest_moves.append(play_chess(n, 0, 0, i, j, 0, [])) for c in chest_moves: print c, print # your code goes here