import 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    }
} import java.util.*; util.* java 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    }
} 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] X = new int[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    } 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[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++){
                X[i][j] = sc.nextInt();
            }
        } {
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        } for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                X[i][j] = sc.nextInt();
            } {
                X[i][j] = sc.nextInt();
            } X[i][j] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc int[] dist = new int[n*(n-1)/2]; dist new int[n*(n-1)/2] n*(n-1)/2 n*(n-1) n (n-1) n 1 2 int distsum = 0; distsum 0 int count = 0; count 0 int p = 0; p 0 for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        } {
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        } for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            } {
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            } for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } {
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) distsum distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) distsum (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                } int l = 1; int l = 1; l 1 l <= distsum l distsum l++ l++ l {
                    if(distsum == l*l){
                        count++;
                    }
                } {
                    if(distsum == l*l){
                        count++;
                    }
                } if(distsum == l*l){
                        count++;
                    } distsum == l*l distsum l*l l l {
                        count++;
                    } count++ count distsum = 0 distsum 0 System.out.print(count) System.out.print 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 = sc.nextInt();
        int d = sc.nextInt();
        int[][] X = new int[n][d];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    }
} 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    }
} Main
import 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 i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                X[i][j] = sc.nextInt();
            }
        }
        int[] dist = new int[n*(n-1)/2];
        int distsum = 0;
        int count = 0;
        int p = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                for(int k = 0; k < d; k++){
                    distsum = distsum + (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }
                for(int l = 1; l <= distsum; l++){
                    if(distsum == l*l){
                        count++;
                    }
                }
                distsum = 0;
            }
        }
        System.out.print(count);
    }
}