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());


        int[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
} 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());


        int[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 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[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 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[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 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[][] pointsX = new int[N][D]; pointsX new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[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++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                pointsX[i][j] = Integer.parseInt(sc.next());
            } {
                pointsX[i][j] = Integer.parseInt(sc.next());
            } pointsX[i][j] = Integer.parseInt(sc.next()) pointsX[i][j] pointsX[i] pointsX i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = 0; count 0 for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        } {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        } for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            } int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            } {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            } long sum = 0; sum 0 for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                } int j2 = 0; int j2 = 0; j2 0 j2 < D j2 D j2++ j2++ j2 {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                } {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                } sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]) sum Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]) Math.abs(pointsX[i][j2]-pointsX[j][j2]) Math.abs Math pointsX[i][j2]-pointsX[j][j2] pointsX[i][j2] pointsX[i] pointsX i j2 pointsX[j][j2] pointsX[j] pointsX j j2 Math.abs(pointsX[i][j2]-pointsX[j][j2]) Math.abs Math pointsX[i][j2]-pointsX[j][j2] pointsX[i][j2] pointsX[i] pointsX i j2 pointsX[j][j2] pointsX[j] pointsX j j2 if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                } Math.sqrt(sum) % 1 == 0 Math.sqrt(sum) % 1 Math.sqrt(sum) Math.sqrt Math sum 1 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[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 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[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
} 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());


        int[][] pointsX = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                pointsX[i][j] = Integer.parseInt(sc.next());
            }
        }

        int count = 0;
        for (int i = 1; i < N; i++) {
            
            for (int j = 0; j < i; j++) {
              	long sum = 0;
                for (int j2 = 0; j2 < D; j2++) {
                    sum += Math.abs(pointsX[i][j2]-pointsX[j][j2]) * Math.abs(pointsX[i][j2]-pointsX[j][j2]);
                }

                if (Math.sqrt(sum) % 1 == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}