Problem:
English Sentence

Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.

The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces.

Input

A text is given in a line. You can assume the following conditions:

The number of letters in the text is less than or equal to 1000.

The number of letters in a word is less than or equal to 32.

There is only one word which is arise most frequently in given text.

There is only one word which has the maximum number of letters in given text.

Output

The two words separated by a space.

Sample Input

Thank you for your mail and your lectures

Output for the Sample Input

your lectures

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	solve();
    }

    static void solve(){
	String[] w = new String[1000]; //単語保存
	int[] t = new int[1000];       //単語の回数
	String ml = "";               //最大の単語長を持つ単語
	int mt = 0;                    //最も多く出た単語の配列番号
	int a=0, i=0;
	while(kbd.hasNext()){
	    String s = kbd.next();
	    while(i<a && s.compareToIgnoreCase(w[i])!=0) i++;
	    if(i==a) {
		System.out.println(s);
		if(ml.length() < s.length()) ml = s;
		w[i] = s;
		t[i]++;
		if(t[mt] < t[i]) mt = i;
		a++;
	    }
	    else{
		t[i]++;
		if(t[mt] < t[i]) mt = i;
	    }
	    i=0;
	}
	System.out.println(w[mt]+" "+ml);
    }
}