import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        }


        System.out.println(cnt);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        }


        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        }


        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) 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[][] a = new int[n][d]; a new int[n][d] n d for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[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++) {
                a[i][j] = sc.nextInt();
            }
        } {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        } for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j<d j d j++ j++ j {
                a[i][j] = sc.nextInt();
            } {
                a[i][j] = sc.nextInt();
            } a[i][j] = sc.nextInt() a[i][j] a[i] a i j sc.nextInt() sc.nextInt sc long cnt = 0; cnt 0 for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        } {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        } for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            } int j = i+1; int j = i+1; j i+1 i 1 j<n j n j++ j++ j {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            } {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            } double x = 0; x 0 for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                } int k = 0; int k = 0; k 0 k<d k d k++ k++ k {
                    x += Math.pow(a[i][k] - a[j][k],2);
                } {
                    x += Math.pow(a[i][k] - a[j][k],2);
                } x += Math.pow(a[i][k] - a[j][k],2) x Math.pow(a[i][k] - a[j][k],2) Math.pow Math a[i][k] - a[j][k] a[i][k] a[i] a i k a[j][k] a[j] a j k 2 x = Math.sqrt(x) x Math.sqrt(x) Math.sqrt Math x if((x-(long)(x)) == 0) cnt++; (x-(long)(x)) == 0 (x-(long)(x)) x (long)(x) 0 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        }


        System.out.println(cnt);
    }
}