import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
} Main public static int n n d; d public static int[] square = new int[160]; square new int[160] 160 public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    } main {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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 for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        } int i=0; int i=0; i 0 i*i<16000 i*i i i 16000 i++ i++ i {
            square[i] = i*i;
        } {
            square[i] = i*i;
        } square[i] = i*i square[i] square i i*i i i int c = 0; c 0 for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        } {
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        } for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
                if(check(x[i],x[j])) c++;
            } {
                if(check(x[i],x[j])) c++;
            } if(check(x[i],x[j])) c++; check(x[i],x[j]) check x[i] x i x[j] x j c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    } check {
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    } int s = 0; s 0 for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        } int i=0; int i=0; i 0 i<d i d i++ i++ i {
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        } {
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        } s += (x1[i] - x2[i]) * (x1[i] - x2[i]) s (x1[i] - x2[i]) * (x1[i] - x2[i]) (x1[i] - x2[i]) x1[i] x1 i x2[i] x2 i (x1[i] - x2[i]) x1[i] x1 i x2[i] x2 i for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        } int i=0; int i=0; i 0 i<160 i 160 i++ i++ i {
            if(square[i] == s) return true;
        } {
            if(square[i] == s) return true;
        } if(square[i] == s) return true; square[i] == s square[i] square i s return true; true return false; false int[] x1 x1 int[] x2 x2 public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
}
