import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    }
}
//鶏になれ import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt 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] = sc.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] = sc.nextInt();
            }
        } {
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        } for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            } int j = 0 ; int j = 0 ; j 0 j < d j d j++ j++ j {
                x[i][j] = sc.nextInt();
            } {
                x[i][j] = sc.nextInt();
            } x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int ebishu = 0; ebishu 0 sc.close() sc.close sc for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        } {
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        } for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            } int j = 0 ; int j = 0 ; j 0 j < i j i j++ j++ j {
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            } {
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            } double yono = 0; yono 0 for(int k = 0 ; k < d ; k++){
                    yono += (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 {
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } {
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) yono (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 yono = Math.sqrt(yono) yono Math.sqrt(yono) Math.sqrt Math yono if(yono % 1 == 0){
                    ebishu++;
                } yono % 1 == 0 yono % 1 yono 1 0 {
                    ebishu++;
                } ebishu++ ebishu System.out.println(ebishu) System.out.println System.out System System.out ebishu String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < d ; j++){
                x[i][j] = sc.nextInt();
            }
        }
        int ebishu = 0;
        sc.close();
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < i ; j++){
                double yono = 0;
                for(int k = 0 ; k < d ; k++){
                    yono += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                yono = Math.sqrt(yono);
                if(yono % 1 == 0){
                    ebishu++;
                }
            }
        }
        System.out.println(ebishu);
    }
}
//鶏になれ