import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
} import java.util.*; util.* java import java.util.stream.*; stream.* java.util public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
} Main public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  } main {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt() N in.nextInt() in.nextInt in D = in.nextInt(); D in.nextInt() in.nextInt in int[][] X = new int[N][D]; X new int[N][D] N D for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    } {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    } for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
        X[i][j] = in.nextInt();
      } {
        X[i][j] = in.nextInt();
      } X[i][j] = in.nextInt() X[i][j] X[i] X i j in.nextInt() in.nextInt in int ans = 0; ans 0 for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    } {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    } for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
        if (calc(X[i], X[j])) {
          ans++;
        }
      } {
        if (calc(X[i], X[j])) {
          ans++;
        }
      } if (calc(X[i], X[j])) {
          ans++;
        } calc(X[i], X[j]) calc X[i] X i X[j] X j {
          ans++;
        } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  } calc {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  } double sum = 0; sum 0 for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
      sum += Math.pow(a[i] - b[i], 2);
    } {
      sum += Math.pow(a[i] - b[i], 2);
    } sum += Math.pow(a[i] - b[i], 2) sum Math.pow(a[i] - b[i], 2) Math.pow Math a[i] - b[i] a[i] a i b[i] b i 2 return ((Math.sqrt(sum) * 10) % 10) == 0; ((Math.sqrt(sum) * 10) % 10) == 0 ((Math.sqrt(sum) * 10) % 10) (Math.sqrt(sum) * 10) Math.sqrt(sum) Math.sqrt Math sum 10 10 0 int[] a a int[] b b public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
} Main
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), D = in.nextInt();
    int[][] X = new int[N][D];

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        X[i][j] = in.nextInt();
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (calc(X[i], X[j])) {
          ans++;
        }
      }
    }
    System.out.println(ans);
  }

  public static boolean calc(int[] a, int[] b) {
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
      sum += Math.pow(a[i] - b[i], 2);
    }
    return ((Math.sqrt(sum) * 10) % 10) == 0;
  }
}