Under construction

Still being built. Things may change

The Will Rogers Phenomenon

Interview

Time limit1sMemory limit1024 MB

Summary
Given two groups of positive integers, find one number whose move to the other group raises the average of both groups, or report that none exists.
Level

Easy3 of 10

Topics
Brute force, Math
Solved
No attempts yet

Problem

Will Rogers (1879-1935) was an American comedian known for the following quote:

"When the Okies left Oklahoma and moved to California, they raised the average intelligence level in both states."

This apparent paradox, where moving one element from one set to another raises the average in both sets, is called the Will Rogers phenomenon. Write a program that reads two groups A and B, each containing at least two and at most ten positive integers. It must decide whether moving one number from one group to the other can raise the average in both groups. If it can, the program prints which number to move and which group to move it to.

Input

The first line contains two integers: the number of elements in the first group and the number of elements in the second group. Both values are between 1 and 10. The next line contains the numbers of the first group, and the line after that contains the numbers of the second group.

All numbers are between 11 and 2020.

Output

If moving one number from one group to the other raises the average in both groups, print one line with the number to move and the group it goes to, written as A or B. If several moves work, printing any one of them is enough.

If no such move exists, print NEJ.

Hint

In the first sample, the averages before any move are 22 for A and 44 for B. After moving the number 33 from B to A, the averages are 2.252.25 for A and 4.333…4.333\ldots for B.

In the second sample, the phenomenon cannot occur. For example, moving the number 55 from A to B raises the average in A, but the average in B stays the same.

Examples2

  1. Example 1

    Input
    3 4
    3 1 2
    4 3 5 4
    
    Expected output
    3 A
    
  2. Example 2

    Input
    2 2
    7 5
    4 6
    
    Expected output
    NEJ