This page is still under construction.

Parts of this page are still being built. What you see may change.

Usaneko Matrix

Time limit1sMemory limit512 MB

Summary
Given two n x n grids and a sequence of drawn cards, track when each player first completes at least u or v full lines and report who wins at draw m.
Level

Medium7 of 10

Topics
Implementation, Simulation, Hash map, Math
Solved
No attempts yet

Problem

A rabbit and a cat play a game. The rules are as follows.

First, the two animals each write n2n^2 integers on paper in an n×nn \times n square grid, and each draws one playing card. Then they shuffle 1 000 000 cards, each bearing one of the numbers from 1 to 1 000 000, and draw them one at a time, alternating turns. Whenever a card is drawn, each animal marks the number on its own paper if that number appears there. The winning condition is that the number of "sets of nn marked numbers that lie on a single straight line" becomes at least the number on the playing card drawn at the start.

Answer which of the rabbit and the cat wins by the time the given mm-th card has been drawn. The winner is decided at the moment a card is drawn and marked, if exactly one of the two animals satisfies the winning condition; otherwise the game is a draw. Cards may still be drawn after one animal satisfies the winning condition, but this does not affect the outcome.

Input

Line 1: "nn uu vv mm" (the size of the square grid, the rabbit's playing card number, the cat's playing card number, the number of cards drawn) Lines 2 to n+1n+1: the n2n^2 numbers the rabbit writes on paper Lines n+2n+2 to 2n+12n+1: the n2n^2 numbers the cat writes on paper Lines 2n+22n+2 to 2n+m+12n+m+1: the mm cards drawn

  • 1≤n≤5001 \le n \le 500
  • 1≤u,v≤131 \le u, v \le 13
  • 1≤m≤100 0001 \le m \le 100\,000
  • 1≤1 \le (numbers written) ≤1 000 000\le 1\,000\,000

The n2n^2 numbers the rabbit writes, the n2n^2 numbers the cat writes, and the numbers on the mm drawn cards are each distinct within their own group.

Output

Print "USAGI" if the rabbit wins, "NEKO" if the cat wins, or "DRAW" for a draw, each on a single line.

Examples2

  1. Example 1

    Input
    3 2 2 10
    1 2 3
    4 5 6
    7 8 9
    1 2 3
    6 5 4
    7 8 9
    11
    4
    7
    5
    10
    9
    2
    1
    3
    8
    
    Expected output
    USAGI
    
  2. Example 2

    Input
    3 2 1 10
    1 2 3
    4 5 6
    7 8 9
    1 2 3
    6 5 4
    7 8 9
    11
    4
    7
    5
    10
    9
    2
    1
    3
    8
    
    Expected output
    DRAW