content: public class Solution {
      public double dist(int[] p1, int[] p2) {
          return (p2[1] - p1[1]) * (p2[1] - p1[1]) + (p2[0] - p1[0]) * (p2[0] - p1[0]);
      }
      public boolean check(int[] p1, int[] p2, int[] p3, int[] p4) {
          return dist(p1,p2) > 0 && dist(p1, p2) == dist(p2, p3) && dist(p2, p3) == dist(p3, p4) && dist(p3, p4) == dist(p4, p1) && dist(p1, p3) == dist(p2, p4);
      }
      public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
          int[][] p = {p1,p2,p3,p4};
          return checkAllPermutations(p, 0);
      }
      boolean checkAllPermutations(int[][] p, int l) {
          if (l == 4) {
              return check(p[0], p[1], p[2], p[3]);
          } else {
              boolean res = false;
              for (int i = l; i < 4; i++) {
                  swap(p, l, i);
                  res |= checkAllPermutations(p, l + 1);
                  swap(p, l, i);
              }
              return res;
          }
      }
      public void swap(int[][] p, int x, int y) {
          int[] temp = p[x];
          p[x] = p[y];
          p[y] = temp;
      }
  }