import 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    }
} 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    } 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 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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            for(int i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        } {
            for(int i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        } for(int i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            } int i2 = i+1; int i2 = i+1; i2 i+1 i 1 i2<n i2 n i2++ i2++ i2 {
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            } {
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            } double tmp = 0; tmp 0 for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                } int j = 0; int j = 0; j 0 j<d j d j++ j++ j {
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                } {
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                } tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2) tmp Math.pow(Math.abs(x[i][j] - x[i2][j]),2) Math.pow Math Math.abs(x[i][j] - x[i2][j]) Math.abs Math x[i][j] - x[i2][j] x[i][j] x[i] x i j x[i2][j] x[i2] x i2 j 2 tmp = Math.sqrt(tmp) tmp Math.sqrt(tmp) Math.sqrt Math tmp if(Math.floor(tmp) == tmp){
                    ans += 1;
                } Math.floor(tmp) == tmp Math.floor(tmp) Math.floor Math tmp tmp {
                    ans += 1;
                } ans += 1 ans 1 System.out.println(ans) System.out.println System.out System System.out ans 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    }
} 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import 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());
        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 i2 = i+1;i2<n;i2++){
                double tmp = 0;
                for(int j = 0;j<d;j++){
                    tmp += Math.pow(Math.abs(x[i][j] - x[i2][j]),2);
                }
                tmp = Math.sqrt(tmp);
                if(Math.floor(tmp) == tmp){
                    ans += 1;
                }
            }
        }
        System.out.println(ans);
    }
}