import java.util.*;
import java.lang.*;
import java.io.*;

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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* 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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

} 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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    } 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+1][D+1]; X new int[N+1][D+1] N+1 N 1 D+1 D 1 int c = 0; c 0 int m = 0 ; m 0 double sqrt = 0; sqrt 0 for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        } {
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        } for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            } int j = 1; int j = 1; j 1 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 for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        } int i = 1; int i = 1; i 1 i <= N -1 i N -1 N 1 i++ i++ i {
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        } {
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        } for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            } int j = i +1; int j = i +1; j i +1 i 1 j <= N j N j++ j++ j {
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            } {
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            } for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               } int k = 1; int k = 1; k 1 k <= D k D k++ k++ k {
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               } {
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               } m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]) m (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 sqrt = Math.sqrt(m) sqrt Math.sqrt(m) Math.sqrt Math m if(sqrt == (int)sqrt){
                    c++;
                } sqrt == (int)sqrt sqrt (int)sqrt {
                    c++;
                } c++ c m = 0 m 0 System.out.println(c) System.out.println System.out System System.out c 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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

} 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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

} Main
import java.util.*;
import java.lang.*;
import java.io.*;

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+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N -1; i++){
           for(int j = i +1; j <= N; j++){
            //    if(i == j){
            //         break;
            //    }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

}