import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

} Main public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    } main {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    } int count = 0; count 0 Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in))); scanner new Scanner(new BufferedReader(new InputStreamReader(System.in))) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner int[][] points = new int[N][D]; points new int[N][D] N D for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[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++){
                points[i][j] = scanner.nextInt();
            }
        } {
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        } for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                points[i][j] = scanner.nextInt();
            } {
                points[i][j] = scanner.nextInt();
            } points[i][j] = scanner.nextInt() points[i][j] points[i] points i j scanner.nextInt() scanner.nextInt scanner for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        } {
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        } int[] point = points[i]; point points[i] points i for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            } {
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            } int[] otherP = points[j]; otherP points[j] points j int temp = 0; temp 0 for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                } {
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                } temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]) temp temp + (point[k] - otherP[k]) * (point[k] - otherP[k]) temp (point[k] - otherP[k]) * (point[k] - otherP[k]) (point[k] - otherP[k]) point[k] point k otherP[k] otherP k (point[k] - otherP[k]) point[k] point k otherP[k] otherP k if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                } Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0 Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) Math.sqrt(temp) Math.sqrt Math temp Math.floor(Math.sqrt(temp)) Math.floor Math Math.sqrt(temp) Math.sqrt Math temp 0 {
                    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) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

} public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] points = new int[N][D];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < D; j++){
                points[i][j] = scanner.nextInt();
            }
        }

        for(int i = 0; i < N; i++){
            int[] point = points[i];
            for(int j = i + 1; j < N; j++){
                int[] otherP = points[j];
                int temp = 0;
                for(int k = 0; k < D; k++){
                    temp = temp + (point[k] - otherP[k]) * (point[k] - otherP[k]);
                }
                if(Math.sqrt(temp) - Math.floor(Math.sqrt(temp)) == 0){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

}
