Celebrity P86176


pdf   zip


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 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.


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

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


    No Hi
    Ann Oak
  • Information
    Salvador Roura
    Official solutions
    User solutions