Under construction

Still being built. Things may change

False Coin

Interview

Time limit1sMemory limit128 MB

Summary
Given recorded balance weighings of N coins with exactly one false coin, output the coin number if the results identify it uniquely, otherwise 0.
Level

Medium5 of 10

Topics
Brute force, Implementation, Simulation, Array
Solved
No attempts yet

Problem

The “Gold Bar” bank has learned from reliable sources that its latest batch of NN coins contains exactly one false coin. The false coin differs in weight from the genuine ones (all genuine coins weigh the same); it may be either heavier or lighter.

To find the false coin, the bank clerks have only a simple two-pan balance. Placing coins on it tells you whether the total weight in the left pan is less than, greater than, or equal to the total weight in the right pan.

The clerks numbered the coins with distinct integers from 11 to NN. They then performed several weighings, each time placing an equal number of coins in the left and right pans, and recorded the coin numbers used and the result of every weighing.

Write a program that determines the number of the false coin from these recorded results.

Input

The first line contains two integers NN and KK separated by a space, where NN is the number of coins (2≤N≤1002 \le N \le 100) and KK is the number of weighings (1≤K≤1001 \le K \le 100).

The next 2K2K lines describe the weighings, two lines per weighing.

  • The first line of a weighing starts with an integer PiP_i (1≤Pi≤N/21 \le P_i \le N/2), the number of coins placed in each pan. It is followed by the PiP_i coin numbers in the left pan and then the PiP_i coin numbers in the right pan. All numbers are separated by spaces.
  • The second line is one of the characters <, >, or =, giving the result of the weighing:
    • < means the left pan is lighter than the right pan,
    • > means the left pan is heavier than the right pan,
    • = means the two pans weigh the same.

Output

If the given results determine the false coin uniquely, print its number. Otherwise print 00.

Examples2

  1. Example 1

    Input
    5 3
    2 1 2 3 4
    <
    1 1 4
    =
    1 2 5
    =
    
    Expected output
    3
    
  2. Example 2

    Input
    4 2
    1 1 2
    <
    1 3 2
    =
    
    Expected output
    1