import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    }

}
 import java.awt.*; awt.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java import java.util.List; List java.util public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    }

} Main public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    } main {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    } 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 arr[][]=new int[n][d]; arr new int[n][d] n d for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[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++){
                arr[i][j]=sc.nextInt();
            }
        } {
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        } for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            } int j=0; int j=0; j 0 j<d j d j++ j++ j {
                arr[i][j]=sc.nextInt();
            } {
                arr[i][j]=sc.nextInt();
            } arr[i][j]=sc.nextInt() arr[i][j] arr[i] arr i j sc.nextInt() sc.nextInt sc int cnt=0; cnt 0 for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        } {
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        } for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            } {
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            } int sum=0; sum 0 for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                } int k=0; int k=0; k 0 k<d k d k++ k++ k {
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                } {
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                } sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k])) sum ((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k])) (arr[i][k]-arr[j][k]) arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k (arr[i][k]-arr[j][k]) arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k int tmp=sum; tmp sum int sqrt=(int)Math.sqrt(tmp); sqrt (int)Math.sqrt(tmp) Math.sqrt Math tmp if (sqrt*sqrt==sum){
                    cnt++;
                } sqrt*sqrt==sum sqrt*sqrt sqrt sqrt sum {
                    cnt++;
                } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    }

} public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    }

} Main
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int arr[][]=new int[n][d];
        for (int i=0;i<n;i++){
            for (int j=0;j<d;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int cnt=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                int sum=0;
                for (int k=0;k<d;k++){
                    sum+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
                }
                int tmp=sum;
                int sqrt=(int)Math.sqrt(tmp);
                if (sqrt*sqrt==sum){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);



    }

}

