Under construction

Still being built. Things may change

Chocolate Bar Game

Time limit1sMemory limit512 MB

Summary
Ruby and Dia alternately eat a fully chocolate prime-sized square (each prime used once) or one single square, and the task is to find the winner under optimal play.
Level

Hard8 of 10

Topics
Game theory, Number theory, Matrix
Solved
No attempts yet

Problem

Dia and Ruby take turns playing a game with an n×nn \times n square chocolate bar. Ruby goes first. On each turn, the current player must do one of the following:

  1. Select a prime number pp that no player has selected in a previous round. Then choose a p×pp \times p square on the bar that contains no empty squares (X), and eat every chocolate square inside it.
  2. Eat any one 1×11 \times 1 chocolate square.

The player who eats the last chocolate square wins. Some squares are already eaten at the start. If both players play optimally, who wins? Note: "optimally" means that if a player has a strategy that wins no matter how the opponent responds, that player makes a move that keeps that strategy.

Input

The first line contains a single integer nn (1≤n≤20001 \le n \le 2000), the size of the chocolate bar. The next nn lines each contain nn characters. Each character is either X (an empty square) or - (a chocolate square).

Output

Print RUBY if Ruby wins, or DIA if Dia wins.

Examples1

  1. Example 1

    Input
    4
    ----
    ---X
    ----
    XXXX
    
    Expected output
    RUBY