import java.util.Scanner;

public class Main {

    private static final int MOD = 1_000_000_007;

    private static int[][] X;
    private static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    }

    private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static final int MOD = 1_000_000_007;

    private static int[][] X;
    private static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    }

    private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    }
} Main private static final int MOD = 1_000_000_007; MOD 1_000_000_007 private static int[][] X; X private static int D; D public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    } 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 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 int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        } {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        } for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            } int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            } {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            } if (i == j) break; i == j i j break; if (distance(i, j)) cnt++; distance(i, j) distance i j cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    } distance {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    } double sum = 0; sum 0 for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        } {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        } long x = X[i][k] - X[j][k]; x X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k sum += x * x sum x * x x x double s = Math.sqrt(sum); s Math.sqrt(sum) Math.sqrt Math sum return s == Math.floor(s); s == Math.floor(s) s Math.floor(s) Math.floor Math s int i i int j j public class Main {

    private static final int MOD = 1_000_000_007;

    private static int[][] X;
    private static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    }

    private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    }
} public class Main {

    private static final int MOD = 1_000_000_007;

    private static int[][] X;
    private static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    }

    private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    }
} Main
import java.util.Scanner;

public class Main {

    private static final int MOD = 1_000_000_007;

    private static int[][] X;
    private static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        D = sc.nextInt();

        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 cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) break;

                if (distance(i, j)) cnt++;
            }
//            System.out.println();
        }

        System.out.println(cnt);
    }

    private static boolean distance(int i, int j) {
        double sum = 0;

        for (int k = 0; k < D; k++) {
            long x = X[i][k] - X[j][k];
            sum += x * x;
        }

        double s = Math.sqrt(sum);

        return s == Math.floor(s);
    }
}
