
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner 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] = scanner.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] = scanner.nextInt();
            }
        } {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        } for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            } int j = 0 ; int j = 0 ; j 0 j < D j D j++ j++ j {
                X[i][j] = scanner.nextInt();
            } {
                X[i][j] = scanner.nextInt();
            } X[i][j] = scanner.nextInt() X[i][j] X[i] X i j scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        } {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        } for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            } int j = i + 1 ; int j = i + 1 ; j i + 1 i 1 j < N j N j++ j++ j {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            } {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            } int dist = 0; dist 0 for (int k = 0 ; k < D ; k++) {
                    dist += (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 {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                } dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) dist (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 n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                } int n = 1 ; int n = 1 ; n 1 n * n <= dist n * n n n dist n++ n++ n {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                } {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                } if (n * n == dist) {
                        count++;
                        break;
                    } n * n == dist n * n n n dist {
                        count++;
                        break;
                    } count++ count break; 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 scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
} Main

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        int[][] X = new int[N][D];

        for (int i = 0 ; i < N ; i++) {
            for (int j = 0 ; j < D ; j++) {
                X[i][j] = scanner.nextInt();
            }
        }
        
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            for (int j = i + 1 ; j < N ; j++) {
                int dist = 0;
                for (int k = 0 ; k < D ; k++) {
                    dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                for (int n = 1 ; n * n <= dist ; n++) {
                    if (n * n == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
}
