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[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        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[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        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[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        System.out.println(count);
    } main {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        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[][] xArr = new int[N][D]; xArr new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        } {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        } for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                xArr[i][k] = scanner.nextInt();
            } {
                xArr[i][k] = scanner.nextInt();
            } xArr[i][k] = scanner.nextInt() xArr[i][k] xArr[i] xArr i k scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        } int h = 0; int h = 0; h 0 h < N h N h++ h++ h {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        } {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        } for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            } int i = h+1; int i = h+1; i h+1 h 1 i < N i N i++ i++ i {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            } {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            } double distance = 0; distance 0 for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                } {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                } distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2) distance Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2) Math.pow Math Math.abs(xArr[h][k] - xArr[i][k]) Math.abs Math xArr[h][k] - xArr[i][k] xArr[h][k] xArr[h] xArr h k xArr[i][k] xArr[i] xArr i k 2 double result = Math.sqrt(distance); result Math.sqrt(distance) Math.sqrt Math distance if (result == (int)result) count++; result == (int)result result (int)result 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 scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        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[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        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[][] xArr = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < D; k++) {
                xArr[i][k] = scanner.nextInt();
            }
        }

        int count = 0;
        for (int h = 0; h < N; h++) {
            for (int i = h+1; i < N; i++) {
                double distance = 0;
                for (int k = 0; k < D; k++) {
                    distance += Math.pow(Math.abs(xArr[h][k] - xArr[i][k]), 2);
                }
                double result = Math.sqrt(distance);
                if (result == (int)result) count++;
            }
        }
        System.out.println(count);
    }
}