import java.util.Scanner;

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

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int d = in.nextInt(); d in.nextInt() in.nextInt in 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] = in.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] = in.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] = in.nextInt();
            } {
                x[i][j] = in.nextInt();
            } x[i][j] = in.nextInt() x[i][j] x[i] x i j in.nextInt() in.nextInt in int count = 0; count 0 for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } int j = i; int j = i; j i j < n j n j++ j++ j {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } int dist = 0; dist 0 for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                } {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                } dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k])) dist (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k])) (Math.abs(x[i][k] - x[j][k])) Math.abs Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k (Math.abs(x[i][k] - x[j][k])) Math.abs Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } int k = 1; int k = 1; k 1 k <= Math.sqrt(dist) k Math.sqrt(dist) Math.sqrt Math dist k++ k++ k {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } if (k * k == dist) {
                        count++;
                        break;
                    } k * k == dist k * k k k 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 in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    }
} Main
import java.util.Scanner;

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

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = in.nextInt();
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i; j < n; j++) {
                int dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += (Math.abs(x[i][k] - x[j][k])) * (Math.abs(x[i][k] - x[j][k]));
                }

                for (int k = 1; k <= Math.sqrt(dist); k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);

    }
}
