Celebrity P86176


Statement
 

pdf   zip

thehtml

In a party, we say that c is a celebrity if everybody knows c, but c knows nobody. (We do not care if c knows himself or herself.) Please write a program to tell if a party has a celebrity.

The party has n persons, each with a first name fi and a surname si. All those 2n strings have the same length m, and implicitly tell who knows who in a funny way. Given two characters a and b, let us define the “distance” between them as d(a, b) = (ab + 12) mod26 − 12. Observe that −12 ≤ d(a, b) ≤ 13. Now, given a first name fi and a surname sj, let us define the “total distance” between them as t(fi, sj) = ∑0 ≤ k < m d(fi[k], sj[k]). Then, i knows j if and only if t(fi, sj) > 0.

For instance, consider a small party with two persons with short names: Li Hu and No Hi. Since d(‵L′, ‵H′) = 4 and d(‵i′, ‵i′) = 0, we have t(‶Li″, ‶Hi″) = 4 > 0, so Li Hu does know No Hi. By contrast, t(‶No″, ‶Hu″) = 0, so No Hi does not know Li Hu.

Input

Input consists of several cases. Every case begins with n, followed by n names (first name and surname). All the given strings have the same length m. The first letter of each string is uppercase, the rest are lowercase. First names and surnames can be repeated, but the composition of them uniquely identifies one person. Assume 2 ≤ n ≤ 105 and 2 ≤ m ≤ 6.

Output

Print one line for every case. If the party has no celebrity, print “No”. If the party has one celebrity, print his or her name. If the party has more than one celebrity, print “I ‍should learn some logic”.

Public test cases
  • Input

    2
    Li Hu
    No Hi
    2
    John York
    Elsa Pope
    4
    Pam Kim
    Max Kim
    Ann Oak
    Ada Hay
    

    Output

    No Hi
    No
    Ann Oak
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++