import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private List<int[]> prime_factorize(int N) {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    }

    private boolean check(List<int []> list) {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    }

    private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

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

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    }

} import java.util.*; util.* java import java.math.*; math.* java class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
} Main public static void main(String[] args) {
        new Solver().run();
    } main {
        new Solver().run();
    } new Solver().run() new Solver().run new Solver() String[] args args class Solver {

    private List<int[]> prime_factorize(int N) {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    }

    private boolean check(List<int []> list) {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    }

    private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

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

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    }

} Solver private List<int[]> prime_factorize(int N) {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    } prime_factorize {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    } List<int[]> res = new ArrayList<int[]>(); res new ArrayList<int[]>() for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        } int a = 2; int a = 2; a 2 a * a <= N a * a a a N a++ a++ a {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        } {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        } if (N % a != 0) continue; N % a != 0 N % a N a 0 continue; int ex = 0; ex 0 while (N % a == 0) {
                ++ex;
                N /= a;
            } N % a == 0 N % a N a 0 {
                ++ex;
                N /= a;
            } ++ex ex N /= a N a res.add(new int[]{a, ex}) res.add res new int[]{a, ex} if (N != 1) res.add(new int[]{N, 1}); N != 1 N 1 res.add(new int[]{N, 1}) res.add res new int[]{N, 1} return res; res int N N private boolean check(List<int []> list) {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    } check {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    } for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        } int[] a list {
            if (a[1] % 2 != 0) {
                return false;
            }
        } {
            if (a[1] % 2 != 0) {
                return false;
            }
        } if (a[1] % 2 != 0) {
                return false;
            } a[1] % 2 != 0 a[1] % 2 a[1] a 1 2 0 {
                return false;
            } return false; false return true; true List<int []> list list private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    } dist2 {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    } int sum = 0; sum 0 for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        } {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        } int v = X[i][k] - X[j][k]; v X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k sum += v * v sum v * v v v return sum; sum int[][] X X int N N int D D int i i int j j public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

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

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    } run {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

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

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    } 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 int[][] M = new int[N][D]; M 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 int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        } {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        } for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            } {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            } if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                } i != j i j {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                } int s = dist2(X, N, D, i, j); s dist2(X, N, D, i, j) dist2 X N D i j if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    } check(prime_factorize(s)) check prime_factorize(s) prime_factorize s {
                        cnt++;
                    } cnt++ cnt {
                    } System.out.println(cnt) System.out.println System.out System System.out cnt return;
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private List<int[]> prime_factorize(int N) {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    }

    private boolean check(List<int []> list) {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    }

    private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

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

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    }

}