
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] dist = new int[n][d]; dist new int[n][d] n d for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        } {
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        } for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            } int j=0; int j=0; j 0 j<d j d j++ j++ j {
                dist[i][j] = Integer.parseInt(sc.next());
            } {
                dist[i][j] = Integer.parseInt(sc.next());
            } dist[i][j] = Integer.parseInt(sc.next()) dist[i][j] dist[i] dist i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc double sum = 0; sum 0 int count = 0; count 0 for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } {
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } {
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } sum = 0 sum 0 for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                } int k=0; int k=0; k 0 k<d k d k++ k++ k {
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                } {
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                } sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]) sum (dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]) (dist[i][k]-dist[j][k]) dist[i][k] dist[i] dist i k dist[j][k] dist[j] dist j k (dist[i][k]-dist[j][k]) dist[i][k] dist[i] dist i k dist[j][k] dist[j] dist j k sum = Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum if(sum == (int)sum){
                    count++;
                } sum == (int)sum sum (int)sum {
                    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 sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int[][] dist = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                dist[i][j] = Integer.parseInt(sc.next());
            }
        }
        sc.close();

        double sum = 0;
        int count = 0;
        for(int i=0;i<n;i++){
            
            for(int j=i+1;j<n;j++){
                sum = 0;
                for(int k=0;k<d;k++){
                    sum+=(dist[i][k]-dist[j][k])*(dist[i][k]-dist[j][k]);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}