// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    }
} import java.math.BigDecimal; BigDecimal java.math import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Objects; Objects java.util import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner java.util import java.util.stream.Stream; Stream java.util.stream public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    }
} Main public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    } main {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N = sc.nextLong(); N sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc double[][] X = new double[(int) N][(int) D]; X new double[(int) N][(int) D] (int) N (int) D int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = sc.nextDouble();
            }
        } 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.nextDouble();
            }
        } {
            for (int j = 0; j < D; j++) {
                X[i][j] = sc.nextDouble();
            }
        } for (int j = 0; j < D; j++) {
                X[i][j] = sc.nextDouble();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                X[i][j] = sc.nextDouble();
            } {
                X[i][j] = sc.nextDouble();
            } X[i][j] = sc.nextDouble() X[i][j] X[i] X i j sc.nextDouble() sc.nextDouble sc for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        } {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        } for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            } {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            } boolean flag = true; flag true double tmp = 0; tmp 0 for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) tmp (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k double ret = Math.sqrt(tmp); ret Math.sqrt(tmp) Math.sqrt Math tmp if (ret % 1.0 > 0.0001) {
                    flag = false;
                } ret % 1.0 > 0.0001 ret % 1.0 ret 1.0 0.0001 {
                    flag = false;
                } flag = false flag false cnt += flag ? 1 : 0 cnt flag ? 1 : 0 flag 1 0 System.out.println(cnt) System.out.println System.out System System.out cnt final String[] args args public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    }
} public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    }
} Main
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long D = sc.nextLong();
        // long K = sc.nextLong();
        double[][] X = new double[(int) N][(int) D];

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

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean flag = true;
                double tmp = 0;
                for (int k = 0; k < D; k++) {
                    tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                double ret = Math.sqrt(tmp);
                if (ret % 1.0 > 0.0001) {
                    flag = false;
                }
                cnt += flag ? 1 : 0;
            }
        }

        System.out.println(cnt);
    }
}