import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    } main {
        Main main = new Main();
        main.solve();
    } Main main = new Main(); main new Main() main.solve() main.solve main String[] args args public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    } solve {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    } Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); scan new Scanner(new BufferedReader(new InputStreamReader(System.in))) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan 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] = scan.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] = scan.nextInt();
            }
        } {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        } for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                x[i][j] = scan.nextInt();
            } {
                x[i][j] = scan.nextInt();
            } x[i][j] = scan.nextInt() x[i][j] x[i] x i j scan.nextInt() scan.nextInt scan int answer = 0; answer 0 for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        } {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        } for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            } {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            } int d = 0; d 0 for (int k = 0; k < D; k++) {
                    d += (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 {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                } {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                } d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]) d (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 l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                } int l = 1; int l = 1; l 1 l * l <= d l * l l l d l++ l++ l {
                    if (l * l == d) {
                        answer += 1;
                    }
                } {
                    if (l * l == d) {
                        answer += 1;
                    }
                } if (l * l == d) {
                        answer += 1;
                    } l * l == d l * l l l d {
                        answer += 1;
                    } answer += 1 answer 1 System.out.println(answer) System.out.println System.out System System.out answer public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    }
} public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scan.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int d = 0;
                for (int k = 0; k < D; k++) {
                    d += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
                }
                for (int l = 1; l * l <= d; l++) {
                    if (l * l == d) {
                        answer += 1;
                    }
                }
            }
        }
        System.out.println(answer);
    }
}
