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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    }

    private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    }
} 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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    }

    private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    }
} 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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    } 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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    } 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 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 int res = 0; res 0 for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        } {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        } for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                if (diff(X[i], X[j])) {
                    res++;
                }
            } {
                if (diff(X[i], X[j])) {
                    res++;
                }
            } if (diff(X[i], X[j])) {
                    res++;
                } diff(X[i], X[j]) diff X[i] X i X[j] X j {
                    res++;
                } res++ res System.out.println(res) System.out.println System.out System System.out res String[] args args private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    } diff {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    } int tmp = 0; tmp 0 for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        } int i = 0; int i = 0; i 0 i < X.length i X.length X X.length i++ i++ i {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        } {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        } tmp += Math.pow(Math.abs(X[i] - Y[i]), 2) tmp Math.pow(Math.abs(X[i] - Y[i]), 2) Math.pow Math Math.abs(X[i] - Y[i]) Math.abs Math X[i] - Y[i] X[i] X i Y[i] Y i 2 double d = Math.sqrt(tmp); d Math.sqrt(tmp) Math.sqrt Math tmp return d == (int) d; d == (int) d d (int) d int[] X X int[] Y Y 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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    }

    private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    }
} 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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    }

    private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    }
} Main
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];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = Integer.parseInt(sc.next());
            }
        }

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (diff(X[i], X[j])) {
                    res++;
                }
            }
        }

        System.out.println(res);

    }

    private static boolean diff(int[] X, int[] Y) {
        int tmp = 0;
        for (int i = 0; i < X.length; i++) {
            tmp += Math.pow(Math.abs(X[i] - Y[i]), 2);
        }

        double d = Math.sqrt(tmp);
        return d == (int) d;
    }
}
