import java.util.Scanner;

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][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util 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][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} 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][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int d = sc.nextInt();
        
        int[][] x = new int[n][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } 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][d]; x new int[n][d] n d for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        } int a = 0; int a = 0; a 0 a < n a n a++ a++ a {
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        } {
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        } for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            } int b = 0; int b = 0; b 0 b < d b d b++ b++ b {
                x[a][b] = sc.nextInt();
            } {
                x[a][b] = sc.nextInt();
            } x[a][b] = sc.nextInt() x[a][b] x[a] x a b sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        } int a = 0; int a = 0; a 0 a < n-1 a n-1 n 1 a++ a++ a {
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        } {
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        } for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            } int c = 1; int c = 1; c 1 c < n-a c n-a n a c++ c++ c {
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            } {
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            } double distance = 0; distance 0 for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                } int b = 0; int b = 0; b 0 b < d b d b++ b++ b {
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                } {
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                } distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]) distance (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]) (x[a][b] - x[a+c][b]) x[a][b] x[a] x a b x[a+c][b] x[a+c] x a+c a c b (x[a][b] - x[a+c][b]) x[a][b] x[a] x a b x[a+c][b] x[a+c] x a+c a c b distance = Math.sqrt(distance) distance Math.sqrt(distance) Math.sqrt Math distance if(distance == Math.floor(distance)){
                    ans++;
                } distance == Math.floor(distance) distance Math.floor(distance) Math.floor Math distance {
                    ans++;
                } ans++ ans 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 = sc.nextInt();
        int d = sc.nextInt();
        
        int[][] x = new int[n][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} 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][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

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][d];
        for(int a = 0; a < n; a++){
            for(int b = 0; b < d; b++){
                x[a][b] = sc.nextInt();
            }
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int c = 1; c < n-a; c++){
                double distance = 0;
                for(int b = 0; b < d; b++){
                    distance += (x[a][b] - x[a+c][b]) * (x[a][b] - x[a+c][b]);
                }
                distance = Math.sqrt(distance);
                if(distance == Math.floor(distance)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}