package algorithms.triplesum;

import java.util.HashSet;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

public class Solution {

  private static final Scanner scanner = new Scanner(System.in);

  static long triplets(int[] a, int[] b, int[] c) {
    Set<Triplet> triplets = new HashSet<>();

    for (int aElement : a) {
      for (int bElement : b) {
        for (int cElement : c) {
          if (aElement <= bElement && bElement >= cElement) {
            triplets.add(Triplet.of(aElement, bElement, cElement));
          }
        }
      }
    }

    return triplets.size();
  }

  static class Triplet {
    private final int a;
    private final int b;
    private final int c;

    Triplet(int a, int b, int c) {
      this.a = a;
      this.b = b;
      this.c = c;
    }

    static Triplet of(int a, int b, int c) {
      return new Triplet(a, b, c);
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (!(o instanceof Triplet)) return false;
      Triplet triplet = (Triplet) o;
      return a == triplet.a && b == triplet.b && c == triplet.c;
    }

    @Override
    public int hashCode() {
      return Objects.hash(a, b, c);
    }

    @Override
    public String toString() {
      return "Triplet{" +
        "a=" + a +
        ", b=" + b +
        ", c=" + c +
        '}';
    }
  }

  public static void main(String[] args) {
    String[] lenaLenbLenc = scanner.nextLine().split(" ");
    int lena = Integer.parseInt(lenaLenbLenc[0]);
    int lenb = Integer.parseInt(lenaLenbLenc[1]);
    int lenc = Integer.parseInt(lenaLenbLenc[2]);

    int[] arra = new int[lena];

    String[] arraItems = scanner.nextLine().split(" ");
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    for (int i = 0; i < lena; i++) {
      int arraItem = Integer.parseInt(arraItems[i]);
      arra[i] = arraItem;
    }

    int[] arrb = new int[lenb];

    String[] arrbItems = scanner.nextLine().split(" ");
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    for (int i = 0; i < lenb; i++) {
      int arrbItem = Integer.parseInt(arrbItems[i]);
      arrb[i] = arrbItem;
    }

    int[] arrc = new int[lenc];

    String[] arrcItems = scanner.nextLine().split(" ");
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    for (int i = 0; i < lenc; i++) {
      int arrcItem = Integer.parseInt(arrcItems[i]);
      arrc[i] = arrcItem;
    }

    long ans = triplets(arra, arrb, arrc);

    System.out.println(ans);

    scanner.close();
  }
}

@@ -45,40 +45,13 @@
 til.
-HashSet;%0Aimport java.util.Object
+Array
 s;%0Ai
@@ -78,30 +78,8 @@
 ner;
-%0Aimport java.util.Set;
 %0A%0Apu
@@ -227,1106 +227,429 @@
     
-Set%3CTriplet%3E triplets = new HashSet%3C%3E();%0A%0A    for (int aElement : a) %7B%0A      for (int bElement : b) %7B%0A        for (int cElement : c) %7B%0A          if (aElement %3C= bElement && bElement %3E= cElement) %7B%0A            triplets.add(Triplet.of(aElement, bElement, cElement));%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A%0A    return triplets.size();%0A  %7D%0A%0A  static class Triplet %7B%0A    private final int a;%0A    private final int b;%0A    private final int c;%0A%0A    Triplet(int a, int b, int c) %7B%0A      this.a = a
+a = Arrays.stream(a).sorted().distinct().toArray();%0A    b = Arrays.stream(b).sorted().distinct().toArray();%0A    c = Arrays.stream(c).sorted().distinct().toArray();%0A%0A    int j = 0, k = 0
 ;%0A    
-  this.b = b;%0A      this.c = c;%0A    %7D%0A%0A    static Triplet of(int a, int b, int c) %7B%0A      return new Triplet(a, b, c);%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A      if (this == o) return true;%0A      if (!(o instanceof Triplet)) return false;%0A      Triplet triplet = (Triplet) o;%0A      return a == triplet.a && b == triplet.b && c == triplet.c;
+long solutions = 0;%0A%0A    for (int i : b) %7B%0A      while (j %3C a.length && a%5Bj%5D %3C= i) %7B%0A        j++;%0A      %7D%0A      while (k %3C c.length && c%5Bk%5D %3C= i) %7B
 %0A    
-%7D%0A%0A
     
-@Override%0A    public int hashCode() %7B%0A      return Objects.hash(a, b, c);%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A      return %22Triplet%7B%22 +%0A        %22a=%22 + a +%0A        %22, b=%22 + b +%0A        %22, c=%22 + c +%0A        '%7D';%0A    %7D
+k++;%0A      %7D%0A      solutions += (long) j * k;%0A    %7D%0A%0A    return solutions;
 %0A  %7D

change the triplets solution, it no longer timeouts