@@ -0,0 +1,1708 @@
+//https://www.hackerrank.com/contests/101hack34/challenges/beautiful-pairs%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A  public static void main(String%5B%5D args) throws IOException %7B%0A    %0A    //Get input%0A    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A    final short N = Short.parseShort(br.readLine());%0A    final short%5B%5D A = toShortArray(br.readLine().split(%22 %22), N);%0A    final short%5B%5D B = toShortArray(br.readLine().split(%22 %22), N);%0A    br.close();%0A    br = null;%0A    %0A    //Count the occurrences of numbers in A%0A    Map%3CShort, Short%3E map = new HashMap%3CShort, Short%3E(N);%0A    for(short i = 0; i %3C N; ++i)%7B%0A      Short v = map.get(A%5Bi%5D);%0A      map.put(A%5Bi%5D, (short)(v == null ? 1 : v + 1));%0A    %7D%0A    %0A    //Match them up with themselves in B%0A    for(short i = 0; i %3C N; ++i)%7B%0A      Short v = map.get(B%5Bi%5D);%0A      %0A      //Ignore counting numbers unique to B%0A      if(v != null)%7B%0A        map.put(B%5Bi%5D, (short)(v - 1));%0A      %7D%0A    %7D%0A    %0A    //Subtract the number of mismatches from the%0A    //maximum amount of disjoint beautiful pairs (N)%0A    short pairwiseDisjointBeautifulPairs = N;%0A    for(Short v : map.values())%7B%0A      %0A      //Ignore counting excess numbers in B%0A      if(v %3E 0)%7B%0A        pairwiseDisjointBeautifulPairs -= v;%0A      %7D%0A    %7D%0A    %0A    //Make the obligatory change to B%0A    pairwiseDisjointBeautifulPairs += (pairwiseDisjointBeautifulPairs == N) ? -1 : 1;%0A    %0A    //Print output%0A    System.out.print(pairwiseDisjointBeautifulPairs);%0A  %7D%0A  %0A  private static short%5B%5D toShortArray(final String%5B%5D A, final int N)%7B%0A    final short%5B%5D B = new short%5BN%5D;%0A    for(int i = 0; i %3C N; ++i)%7B%0A      B%5Bi%5D = Short.parseShort(A%5Bi%5D);%0A    %7D%0A    return B;%0A  %7D%0A%7D%0A

Create beautiful-pairs.java