import java.util.*;
import java.util.Collections;

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());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
} import java.util.*; util.* java import java.util.Collections; Collections 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());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
} 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());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    } 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 int[][] x = new int[N][D]; x new int[N][D] N D int count = 0; count 0 for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(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] = Integer.parseInt(sc.next());
            }
        } {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        } for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                x[i][j] = Integer.parseInt(sc.next());
            } {
                x[i][j] = Integer.parseInt(sc.next());
            } x[i][j] = Integer.parseInt(sc.next()) x[i][j] x[i] x i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        } 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++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        } {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        } for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            } {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            } double[] dis = new double[D]; dis new double[D] D double sum = 0; sum 0 for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                } {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                } dis[k] = Math.pow(x[i][k] - x[j][k], 2) dis[k] dis k Math.pow(x[i][k] - x[j][k], 2) Math.pow Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k 2 sum += dis[k] sum dis[k] dis k sum = Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum if(sum - (int)sum == 0) {
                    count++;
                } sum - (int)sum == 0 sum - (int)sum sum (int)sum 0 {
                    count++;
                } count++ count System.out.println(count) System.out.println 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 = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
} 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());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
} Main
import java.util.*;
import java.util.Collections;

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());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
}