import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

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

        System.out.println(GoodDistance(N, D, X, 0));
    }
    public static int GoodDistance(int N, int D, int[][] X, int index) {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

        System.out.println(GoodDistance(N, D, X, 0));
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

        System.out.println(GoodDistance(N, D, X, 0));
    } 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[][] 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();
            }
        } 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] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc sc.close() sc.close sc System.out.println(GoodDistance(N, D, X, 0)) System.out.println System.out System System.out GoodDistance(N, D, X, 0) GoodDistance N D X 0 String[] args args public static int GoodDistance(int N, int D, int[][] X, int index) {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    } GoodDistance {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    } if (index >= N) {
            return 0;
        } index >= N index N {
            return 0;
        } return 0; 0 int ans = 0; ans 0 for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        } int i = index+1; int i = index+1; i index+1 index 1 i < N i N i++ i++ i {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        } {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        } long sum = 0; sum 0 for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            } {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            } sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]) sum (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]) (X[index][j] - X[i][j]) X[index][j] X[index] X index j X[i][j] X[i] X i j (X[index][j] - X[i][j]) X[index][j] X[index] X index j X[i][j] X[i] X i j long sum2 = (long)Math.sqrt(sum); sum2 (long)Math.sqrt(sum) Math.sqrt Math sum if (sum == sum2 * sum2) {
                ans++;
            } sum == sum2 * sum2 sum sum2 * sum2 sum2 sum2 {
                ans++;
            } ans++ ans return ans + GoodDistance(N, D, X, index + 1); ans + GoodDistance(N, D, X, index + 1) ans GoodDistance(N, D, X, index + 1) GoodDistance N D X index + 1 index 1 int N N int D D int[][] X X int index index public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

        System.out.println(GoodDistance(N, D, X, 0));
    }
    public static int GoodDistance(int N, int D, int[][] X, int index) {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

        System.out.println(GoodDistance(N, D, X, 0));
    }
    public static int GoodDistance(int N, int D, int[][] X, int index) {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int 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();
            }
        }
        sc.close();

        System.out.println(GoodDistance(N, D, X, 0));
    }
    public static int GoodDistance(int N, int D, int[][] X, int index) {
        if (index >= N) {
            return 0;
        }
        int ans = 0;
        for (int i = index+1; i < N; i++) {
            long sum = 0;
            for (int j = 0; j < D; j++) {
                sum += (X[index][j] - X[i][j]) * (X[index][j] - X[i][j]);
            }
            long sum2 = (long)Math.sqrt(sum);
            if (sum == sum2 * sum2) {
                ans++;
            }
        }
        return ans + GoodDistance(N, D, X, index + 1);
    }
}
