import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc D = sc.nextInt(); D sc.nextInt() sc.nextInt sc 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] = sc.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] = sc.nextInt(); for (int j = 0; j < D; j++) X[i][j] = sc.nextInt(); int j = 0; int j = 0; j 0 j < D j D j++ j++ j X[i][j] = sc.nextInt(); X[i][j] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      } for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      } int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      } {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      } int tmp = 0; tmp 0 for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); int k = 0; int k = 0; k 0 k < D k D k++ k++ k tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) tmp (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++; Math.sqrt(tmp) == (int)Math.sqrt(tmp) Math.sqrt(tmp) Math.sqrt Math tmp (int)Math.sqrt(tmp) Math.sqrt Math tmp ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), D = sc.nextInt();
    int[][] X = new int[N][D];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < D; j++) X[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < i; j++) {
        int tmp = 0;
        for (int k = 0; k < D; k++) tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        if (Math.sqrt(tmp) == (int)Math.sqrt(tmp)) ans++;
      }
    System.out.println(ans);
  }
}