import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] X = new int[N][D]; X new int[N][D] N D double d = 0; d 0 int count = 0; count 0 for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        } 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] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                X[i][j] = Integer.parseInt(sc.next());
            } {
                X[i][j] = Integer.parseInt(sc.next());
            } X[i][j] = Integer.parseInt(sc.next()) X[i][j] X[i] X i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        } {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        } for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            } int j = i; int j = i; j i j < N - 1 j N - 1 N 1 j++ j++ j {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            } {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            } for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                } {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                } d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]) d Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]) Math.abs(X[j + 1][k] - X[i][k]) Math.abs Math X[j + 1][k] - X[i][k] X[j + 1][k] X[j + 1] X j + 1 j 1 k X[i][k] X[i] X i k Math.abs(X[j + 1][k] - X[i][k]) Math.abs Math X[j + 1][k] - X[i][k] X[j + 1][k] X[j + 1] X j + 1 j 1 k X[i][k] X[i] X i k d = Math.sqrt(d) d Math.sqrt(d) Math.sqrt Math d if (d == (int) d) {
                    count++;
                } d == (int) d d (int) d {
                    count++;
                } count++ count d = 0 d 0 PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.println(count) out.println out count sc.close() sc.close sc out.flush() out.flush out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    }
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] X = new int[N][D];
        double d = 0;
        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = i; j < N - 1; j++) {
                for (int k = 0; k < D; k++) {
                    d += Math.abs(X[j + 1][k] - X[i][k]) * Math.abs(X[j + 1][k] - X[i][k]);
                }
                d = Math.sqrt(d);
                if (d == (int) d) {
                    count++;
                }
                d = 0;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        sc.close();
        out.flush();
    }
}