import java.util.Scanner;

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

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc int[][] arr1 = new int[N][D]; arr1 new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[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++) {
                arr1[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                arr1[i][j] = sc.nextInt();
            } {
                arr1[i][j] = sc.nextInt();
            } arr1[i][j] = sc.nextInt() arr1[i][j] arr1[i] arr1 i j sc.nextInt() sc.nextInt sc int count = 0; count 0 int temp = 0; temp 0 for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        } {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        } for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            } int k = 1; int k = 1; k 1 k < N - i k N - i N i k++ k++ k {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            } {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            } for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                } {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                } temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2) temp Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2) Math.pow Math Math.abs(arr1[i][j] - arr1[i+k][j]) Math.abs Math arr1[i][j] - arr1[i+k][j] arr1[i][j] arr1[i] arr1 i j arr1[i+k][j] arr1[i+k] arr1 i+k i k j 2 double temp_s = Math.sqrt(temp); temp_s Math.sqrt(temp) Math.sqrt Math temp if (temp_s == (int)temp_s) {
                        count++;
                    } temp_s == (int)temp_s temp_s (int)temp_s {
                        count++;
                    } count++ count temp = 0 temp 0 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) throws Exception {
        Scanner sc = new Scanner(System.in);

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

        for (int i = 0; i < N-1; i++) {
            for (int k = 1; k < N - i; k++) {
                for (int j = 0; j < D; j++) {
                    temp += Math.pow(Math.abs(arr1[i][j] - arr1[i+k][j]), 2);
                }
                double temp_s = Math.sqrt(temp);
                    if (temp_s == (int)temp_s) {
                        count++;
                    }
                    temp = 0;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

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

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

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

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                arr1[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        int temp = 0;

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