import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] points = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    }
    System.out.println(ans);
  }
  static double getDistance(int[] p1, int[] p2) {
    double ret = 0;
    for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    }
    return Math.sqrt(ret);
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] points = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    }
    System.out.println(ans);
  }
  static double getDistance(int[] p1, int[] p2) {
    double ret = 0;
    for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    }
    return Math.sqrt(ret);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] points = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] points = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) 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 int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc int[][] points = new int[N][D]; points new int[N][D] N D for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[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++) points[i][j] = sc.nextInt(); for (int j = 0; j < D; j++) points[i][j] = sc.nextInt(); int j = 0; int j = 0; j 0 j < D j D j++ j++ j points[i][j] = sc.nextInt(); points[i][j] = sc.nextInt() points[i][j] points[i] points i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    } {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    } for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      } {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      } double d = getDistance(points[i], points[j]); d getDistance(points[i], points[j]) getDistance points[i] points i points[j] points j if (d == Math.ceil(d)) ans++; d == Math.ceil(d) d Math.ceil(d) Math.ceil Math d ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args static double getDistance(int[] p1, int[] p2) {
    double ret = 0;
    for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    }
    return Math.sqrt(ret);
  } getDistance {
    double ret = 0;
    for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    }
    return Math.sqrt(ret);
  } double ret = 0; ret 0 for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    } int i = 0; int i = 0; i 0 i < p1.length i p1.length p1 p1.length i++ i++ i {
      ret += Math.pow(p1[i]-p2[i],2);
    } {
      ret += Math.pow(p1[i]-p2[i],2);
    } ret += Math.pow(p1[i]-p2[i],2) ret Math.pow(p1[i]-p2[i],2) Math.pow Math p1[i]-p2[i] p1[i] p1 i p2[i] p2 i 2 return Math.sqrt(ret); Math.sqrt(ret) Math.sqrt Math ret int[] p1 p1 int[] p2 p2
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] points = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) points[i][j] = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        double d = getDistance(points[i], points[j]);
        if (d == Math.ceil(d)) ans++;
      }
    }
    System.out.println(ans);
  }
  static double getDistance(int[] p1, int[] p2) {
    double ret = 0;
    for (int i = 0; i < p1.length; i++) {
      ret += Math.pow(p1[i]-p2[i],2);
    }
    return Math.sqrt(ret);
  }
}