Skip to lesson

Longest common prefix of codes

A medium problem for practising 5.4 Array & String Techniques. Solve it in your own IDE, check it against every test, and open a hint only when you are stuck. 0/1 solved.

1. Longest common prefix of codes

medium

The exam cell has a list of n course codes, such as CS101, CS102 and CS110. To print one heading for the list, they need the longest starting part that every code shares. For these three codes it is CS1.

Print that shared start. If the codes do not even share the first character, print NONE.

Input: The first line has one integer n. The second line has n codes separated by spaces.

Output: One line: the longest shared start, or NONE.

Limits: 1 ≤ n ≤ 10^4 · 1 ≤ length of each code ≤ 100 · Codes have only capital letters A–Z and digits 0–9

Example 1

Input

3
CS101 CS102 CS110

Output

CS1

All three codes start with CS1. The fourth characters 0, 0 and 1 differ.

Example 2

Input

3
ME201 EE201 CE201

Output

NONE

The first characters already differ.

Submit to solve