Language: C++

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		try {
			sc = new Scanner(System.in);

			// ??\???
			while (sc.hasNextLine()) {
				String[] sentence = sc.nextLine().split(" ");

				// ???????????????1????????????????????¢???
				Main main = new Main();
				String frequencyWord = main.maxFrequency(sentence);

				// ????????????????????????????????¢???
				String longWord = main.maxLong(sentence);

				// ????????????
				System.out.println(frequencyWord + " " + longWord);
			}

		} finally {
			sc.close();
		}
	}

	// value?????????????????§??????key?????????
	public String maxFrequency(String[] s) {
		Map<String, Integer> frequency = new HashMap<String, Integer>();
		for (String word : s) {
			int count = 1;
			if (frequency.containsKey(word)) {
				count += frequency.get(word);
			}
			frequency.put(word, count);
		}

		return valueSort(frequency).get(0).getKey();

	}

	//
	public String maxLong(String[] str) {
		// ??????????????????????????????List?????\??????
		List<String> list = new ArrayList<String>(new HashSet<String>(
				Arrays.asList(str)));

		String max = new String();
		for (String s : list) {
			if (max.length() < s.length()) {
				max = s;
			}
		}
		return max;
	}

	// Map???value??§?????????????????????
	private List<Map.Entry<String, Integer>> valueSort(Map<String, Integer> map) {
		List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(
				map.entrySet());
		Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> map1,
					Map.Entry<String, Integer> map2) {
				return map2.getValue().compareTo(map1.getValue());
			}
		});
		return list;
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.ArrayList;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.Arrays;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.Collections;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Comparator;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.HashMap;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.HashSet;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.util.List;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import java.util.Map;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import java.util.Scanner;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:13:15: error: expected ':' before 'static'
   13 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:13:33: error: 'String' has not been declared
   13 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:13:42: error: expected ',' or '...' before 'args'
   13 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:40:15: error: expected ':' before 'String'
   40 |         public String maxFrequency(String[] s) {
      |               ^~~~~~~
      |               :
a.cc:40:16: error: 'String' does not name a type
   40 |         public String maxFrequency(String[] s) {
      |                ^~~~~~
a.cc:55:15: error: expected ':' before 'String'
   55 |         public String maxLong(String[] str) {
      |               ^~~~~~~
      |               :
a.cc:55:16: error: 'String' does not name a type
   55 |         public String maxLong(String[] str) {
      |                ^~~~~~
a.cc:70:16: error: expected ':' before 'List'
   70 |         private List<Map.Entry<String, Integer>> valueSort(Map<String, Integer> map) {
      |                ^~~~~
      |                :
a.cc:70:17: error: 'List' does not name a type
   70 |         private List<Map.Entry<String, Integer>> valueSort(Map<String, Integer> map) {
      |                 ^~~~
a.cc:81:2: error: expected ';' after class definition
   81 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:15:17: error: 'Scanner' was not declared in this scope
   15 |                 Scanner sc = null;
      |                 ^~~~~~~
a.cc:17:25: error: 'sc' was not declared in this scope
   17 |                         sc = new Scanner(System.in);
      |                         ^~
a.cc:17:34: error: expected type-specifier before 'Scanner'
   17 |                         sc = new Scanner(System.in);
      |                                  ^~~~~~~
a.cc:21:33: error: 'String' was not declared in this scope
   21 |                                 String[] sentence = sc.nextLine().split(" ");
      |                                 ^~~~~~
a.cc:21:40: error: expected primary-expression before ']' token
   21 |                                 String[] sentence = sc.nextLine().split(" ");
      |                                        ^
a.cc:24:45: error: conversion from 'Main*' to non-scalar type 'Main' requested
   24 |                                 Main main = new Main();
      |                                             ^~~~~~~~~~
a.cc:25:40: error: expected ';' before 'frequencyWord'
   25 |                                 String frequencyWord = main.maxFrequency(sentence);
      |                                        ^~~~~~~~~~~~~
a.cc:28:40: error: expected ';' before 'longWord'
   28 |                                 String longWord = main.maxLong(sentence);
      |                                        ^~~~~~~~
a.cc:31:33: error: 'System' was not declared in this scope
   31 |                                 System.out.println(frequencyWord + " " + longWord);
      |                                 ^~~~~~
a.cc:31:52: error: 'frequencyWord' was not declared in this scope
   31 |                                 System.out.println(frequencyWord + " " + longWord);
      |                                                    ^~~~~~~~~~~~~
a.cc:31:74: error: 'longWord' was not declared in this scope
   31 |                                 System.out.println(frequencyWord + " " + longWord);
      |                                                                          ^~~~~~~~
a.cc:34:19: error: expected 'catch' before 'finally'
   34 |                 } finally {
      |                   ^~~~~~~
a.cc:34:19: error: expected '(' before 'finally'
a.cc:34:19: error: 'finally' does not name a type
a.cc:34:27: error: expected ')' before '{' token
   34 |                 } finally {
      |                           ^
a.cc:34:19: note: to match this '('
   34 |                 } finally {
      |                   ^~~~~~~
a.cc:35:25: error: 'sc' was not declared in this scope
   35 |                         sc.close();
      |                         ^~