import java.util.Scanner;

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util import static java.lang.Math.pow; import static java.lang.Math.pow; import static java.lang.Math.pow; import static java.lang.Math.sqrt; import static java.lang.Math.sqrt; import static java.lang.Math.sqrt; public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int d = scanner.nextInt(); d scanner.nextInt() scanner.nextInt scanner int[][] x = new int[n][d]; x new int[n][d] n d int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.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] = scanner.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] = scanner.nextInt();
            } {
                x[i][j] = scanner.nextInt();
            } x[i][j] = scanner.nextInt() x[i][j] x[i] x i j scanner.nextInt() scanner.nextInt scanner for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        } {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        } for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            } {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            } int tmp = 0; tmp 0 for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    tmp += pow(x[i][k] - x[j][k], 2);
                } {
                    tmp += pow(x[i][k] - x[j][k], 2);
                } tmp += pow(x[i][k] - x[j][k], 2) tmp pow(x[i][k] - x[j][k], 2) pow x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k 2 double sroot = sqrt(tmp); sroot sqrt(tmp) sqrt tmp if (sroot == (int) sroot) {
                    count++;
                } sroot == (int) sroot sroot (int) sroot {
                    count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int[][] x = new int[n][d];
        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp = 0;
                for (int k = 0; k < d; k++) {
                    tmp += pow(x[i][k] - x[j][k], 2);
                }
                double sroot = sqrt(tmp);
                if (sroot == (int) sroot) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}