#P2412. Lexicographically Maximum Word in a Contiguous Segment

    ID: 15683 Type: Default 1000ms 256MiB

Lexicographically Maximum Word in a Contiguous Segment

Lexicographically Maximum Word in a Contiguous Segment

HansBug found a word list in an English book that contains N words. Each word consists of uppercase and lowercase English letters. Now he wants to find the lexicographically largest word from one contiguous segment of the word list.

Note: Since any contiguous segment containing the overall maximum word will yield that word as the lexicographical maximum, the problem essentially reduces to finding the lexicographically maximum word among all the given words.

Formally, given an integer N and a sequence of N words, output the word with the maximum lexicographical order. Comparisons are made using standard lexicographical order (i.e. using the ASCII values of characters).

inputFormat

The input consists of two lines:

  1. The first line contains a single integer N (1 ≤ N ≤ 105) which is the number of words.
  2. The second line contains N words separated by spaces. Each word consists solely of uppercase and lowercase English letters.

outputFormat

Output a single line containing the lexicographically maximum word.

sample

5
apple Banana orange kiwi grape
orange

</p>