#C13057. Longest String Finder

    ID: 42553 Type: Default 1000ms 256MiB

Longest String Finder

Longest String Finder

You are given a list of strings. Your task is to determine the longest string in the list, along with its length. In case there are multiple strings with the same maximum length, output the one that appears first.

More formally, if the list of strings is represented as \(S = [s_1, s_2, \dots, s_n]\), you need to find \(s_k\) such that \(|s_k| = \max_{1 \le i \le n} |s_i|\). If there are multiple \(s_i\) with this property, choose the one with the smallest index \(i\).

The input and output are processed via standard input (stdin) and standard output (stdout) respectively.

inputFormat

The first line of input contains an integer \(n\) representing the number of strings.

The following \(n\) lines each contain one string.

outputFormat

Output two lines:

  • The first line should contain the length of the longest string.
  • The second line should contain the longest string itself. If the list is empty, output 0 on the first line and an empty string on the second line.
## sample
4
apple
banana
cherry
date
6

banana

</p>