import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);
    //ソート系
    /*
    *ソート(配列) Arrays.sort(配列名);
    *ソート(リスト)Collections.sort(foo);
    *逆順ソート(配列) Arrays.sort(配列名,  Collections.reverseOrder());
    *逆順ソート(リスト) Collections.reverse(リスト名);
    */

    //変換系
    /*
    *String to int : Integer.parseInt();
    *
    */
    public static double distance(double[] a,double[] b){
        double dis = 0;
        for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        }
        return Math.sqrt(dis);
    }
    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        double x[][] = new double[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        }
        int ans = 0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        }
        System.out.println(ans/2);

        
    }
} import java.util.*; util.* java import java.awt.*; awt.* java class Main {

    private static Scanner sc = new Scanner(System.in);
    //ソート系
    /*
    *ソート(配列) Arrays.sort(配列名);
    *ソート(リスト)Collections.sort(foo);
    *逆順ソート(配列) Arrays.sort(配列名,  Collections.reverseOrder());
    *逆順ソート(リスト) Collections.reverse(リスト名);
    */

    //変換系
    /*
    *String to int : Integer.parseInt();
    *
    */
    public static double distance(double[] a,double[] b){
        double dis = 0;
        for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        }
        return Math.sqrt(dis);
    }
    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        double x[][] = new double[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        }
        int ans = 0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        }
        System.out.println(ans/2);

        
    }
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) //変換系
    /*
    *String to int : Integer.parseInt();
    *
    */
    public static double distance(double[] a,double[] b){
        double dis = 0;
        for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        }
        return Math.sqrt(dis);
    } distance {
        double dis = 0;
        for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        }
        return Math.sqrt(dis);
    } double dis = 0; dis 0 for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        } int i = 0; int i = 0; i 0 i< a.length i a.length a a.length i++ i++ i {
            dis+=Math.pow(a[i] - b[i],2);
        } {
            dis+=Math.pow(a[i] - b[i],2);
        } dis+=Math.pow(a[i] - b[i],2) dis Math.pow(a[i] - b[i],2) Math.pow Math a[i] - b[i] a[i] a i b[i] b i 2 return Math.sqrt(dis); Math.sqrt(dis) Math.sqrt Math dis double[] a a double[] b b public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        double x[][] = new double[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        }
        int ans = 0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        }
        System.out.println(ans/2);

        
    } main {
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        double x[][] = new double[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        }
        int ans = 0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        }
        System.out.println(ans/2);

        
    } 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 double x[][] = new double[n][d]; x new double[n][d] n d for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        } 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]=Double.parseDouble(sc.next());
            }        
        } {
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        } for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j]=Double.parseDouble(sc.next());
            } {
                x[i][j]=Double.parseDouble(sc.next());
            } x[i][j]=Double.parseDouble(sc.next()) x[i][j] x[i] x i j Double.parseDouble(sc.next()) Double.parseDouble Double sc.next() sc.next sc int ans = 0; ans 0 for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        } {
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        } for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            } {
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            } if(i==j)continue; i==j i j continue; double dis = distance(x[i],x[j]); dis distance(x[i],x[j]) distance x[i] x i x[j] x j if(dis == (int)dis){
                    ans++;
                } dis == (int)dis dis (int)dis {
                    ans++;
                } ans++ ans System.out.println(ans/2) System.out.println System.out System System.out ans/2 ans 2 String[] args args
import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);
    //ソート系
    /*
    *ソート(配列) Arrays.sort(配列名);
    *ソート(リスト)Collections.sort(foo);
    *逆順ソート(配列) Arrays.sort(配列名,  Collections.reverseOrder());
    *逆順ソート(リスト) Collections.reverse(リスト名);
    */

    //変換系
    /*
    *String to int : Integer.parseInt();
    *
    */
    public static double distance(double[] a,double[] b){
        double dis = 0;
        for(int i = 0;i< a.length; i++){
            dis+=Math.pow(a[i] - b[i],2);
        }
        return Math.sqrt(dis);
    }
    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        double x[][] = new double[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j]=Double.parseDouble(sc.next());
            }        
        }
        int ans = 0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                double dis = distance(x[i],x[j]);
                if(dis == (int)dis){
                    ans++;
                }
            }
        }
        System.out.println(ans/2);

        
    }
}
