MediumSetsNot started

First repeated checkpoint

A route log lists checkpoint codes in travel order. Print the first code whose second visit occurs earliest. If the route never revisits a checkpoint, print NONE. This is about the first repeated event, not the alphabetically smallest repeated code.

Input

One line of space-separated checkpoint codes.

Output

The first code encountered for a second time, or NONE.

Example 1

Input

a b c b a

Output

b

The second b is encountered before the second a, so b wins even though a sorts first.

Constraints

  • The route has 1 to 200 checkpoint codes.
  • Codes are case-sensitive non-empty tokens.

Hints

Hint 1 of 2

A set answers whether a code has been visited.

Hint 2 of 2

Stop on the second visit; sorting loses event order.

Solution

Show a reference solution and explanation
 Python · reference solution
seen = set()
answer = 'NONE'
for code in input().split():
    if code in seen:
        answer = code
        break
    seen.add(code)
print(answer)

Why it works

Scan checkpoints in order, remembering prior codes in a set. The first membership hit is exactly the earliest second visit. Breaking immediately prevents a later repeated code from replacing the correct answer; if no hit occurs, NONE remains.

Lesson for this exercise: Sets in Python

Your program
seen = set()
answer = 'NONE'
for code in input().split():
    # Stop when this code has already appeared.
    pass
print(answer)

Tests: 4 cases including the examples. Passing every test marks the exercise solved in this browser.

How this page was checked. Every program on it was run with CPython 3.11 at build time; runs in your browser on CPython 3.14 (Pyodide) by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.