@@ -0,0 +1,1237 @@
+import java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class BeautifulStrings %7B%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));%0A        Map%3CCharacter, Integer%3E frequencyMap = new HashMap%3C%3E();%0A        for (char c : reader.readLine().toCharArray()) %7B%0A            frequencyMap.put(c, frequencyMap.getOrDefault(c, 0) + 1);%0A        %7D%0A        int size = frequencyMap.size();%0A        if (size %3C 2 %7C%7C size %3E 4) %7B%0A            System.out.println(%22NO%22);%0A        %7D else if (size == 2) %7B%0A            for (Integer frequency : frequencyMap.values()) %7B%0A                if (frequency == 1) %7B%0A                    System.out.println(%22NO%22);%0A                    return;%0A                %7D%0A            %7D%0A            System.out.println(%22YES%22);%0A        %7D else if (size == 3) %7B%0A            for (Integer frequency : frequencyMap.values()) %7B%0A                if (frequency %3E 1) %7B%0A                    System.out.println(%22YES%22);%0A                    return;%0A                %7D%0A            %7D%0A            System.out.println(%22NO%22);%0A        %7D else %7B%0A            System.out.println(%22YES%22);%0A        %7D%0A    %7D%0A%7D%0A

Add BeautifulStrings