import java.util.Scanner;
import java.io.PrintWriter;

class Main {
    static int distanceInteger(int n, int d, int[][] x) {
        int diff_sum, diff, sqrt, count = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        }
        return count;
    }

    static int sqrtInteger(int left, int right, int target) {
        if (left >= right) return left;
        int mid = (left + right) / 2;
        int midSquare = mid * mid;
        if (midSquare == target) return mid;
        if (midSquare < target) return sqrtInteger(mid + 1, right, target);
        return sqrtInteger(left, mid - 1, target);
    }



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }

        out.println(distanceInteger(n, d, x));
        out.flush();
    }
} import java.util.Scanner; Scanner java.util import java.io.PrintWriter; PrintWriter java.io class Main {
    static int distanceInteger(int n, int d, int[][] x) {
        int diff_sum, diff, sqrt, count = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        }
        return count;
    }

    static int sqrtInteger(int left, int right, int target) {
        if (left >= right) return left;
        int mid = (left + right) / 2;
        int midSquare = mid * mid;
        if (midSquare == target) return mid;
        if (midSquare < target) return sqrtInteger(mid + 1, right, target);
        return sqrtInteger(left, mid - 1, target);
    }



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }

        out.println(distanceInteger(n, d, x));
        out.flush();
    }
} Main static int distanceInteger(int n, int d, int[][] x) {
        int diff_sum, diff, sqrt, count = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        }
        return count;
    } distanceInteger {
        int diff_sum, diff, sqrt, count = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        }
        return count;
    } int diff_sum diff_sum diff diff sqrt sqrt count = 0; count 0 for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        } {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        } for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j ++ j ++ j {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            } {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            } diff_sum = 0 diff_sum 0 for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                } int l = 0; int l = 0; l 0 l < d l d l ++ l ++ l {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                } {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                } diff = x[i][l] - x[j][l] diff x[i][l] - x[j][l] x[i][l] x[i] x i l x[j][l] x[j] x j l diff_sum += diff * diff diff_sum diff * diff diff diff sqrt = sqrtInteger(0, diff_sum, diff_sum) sqrt sqrtInteger(0, diff_sum, diff_sum) sqrtInteger 0 diff_sum diff_sum if (sqrt * sqrt == diff_sum) count ++; sqrt * sqrt == diff_sum sqrt * sqrt sqrt sqrt diff_sum count ++ count return count; count int n n int d d int[][] x x static int sqrtInteger(int left, int right, int target) {
        if (left >= right) return left;
        int mid = (left + right) / 2;
        int midSquare = mid * mid;
        if (midSquare == target) return mid;
        if (midSquare < target) return sqrtInteger(mid + 1, right, target);
        return sqrtInteger(left, mid - 1, target);
    } sqrtInteger {
        if (left >= right) return left;
        int mid = (left + right) / 2;
        int midSquare = mid * mid;
        if (midSquare == target) return mid;
        if (midSquare < target) return sqrtInteger(mid + 1, right, target);
        return sqrtInteger(left, mid - 1, target);
    } if (left >= right) return left; left >= right left right return left; left int mid = (left + right) / 2; mid (left + right) / 2 (left + right) left right 2 int midSquare = mid * mid; midSquare mid * mid mid mid if (midSquare == target) return mid; midSquare == target midSquare target return mid; mid if (midSquare < target) return sqrtInteger(mid + 1, right, target); midSquare < target midSquare target return sqrtInteger(mid + 1, right, target); sqrtInteger(mid + 1, right, target) sqrtInteger mid + 1 mid 1 right target return sqrtInteger(left, mid - 1, target); sqrtInteger(left, mid - 1, target) sqrtInteger left mid - 1 mid 1 target int left left int right right int target target public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }

        out.println(distanceInteger(n, d, x));
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }

        out.println(distanceInteger(n, d, x));
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 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] = Integer.parseInt(sc.next());
            }
        } 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] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < d j d j ++ j ++ j {
                x[i][j] = Integer.parseInt(sc.next());
            } {
                x[i][j] = Integer.parseInt(sc.next());
            } x[i][j] = Integer.parseInt(sc.next()) x[i][j] x[i] x i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc out.println(distanceInteger(n, d, x)) out.println out distanceInteger(n, d, x) distanceInteger n d x out.flush() out.flush out String[] args args
import java.util.Scanner;
import java.io.PrintWriter;

class Main {
    static int distanceInteger(int n, int d, int[][] x) {
        int diff_sum, diff, sqrt, count = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                diff_sum = 0;
                for (int l = 0; l < d; l ++) {
                    diff = x[i][l] - x[j][l];
                    diff_sum += diff * diff;
                }
                sqrt = sqrtInteger(0, diff_sum, diff_sum);
                if (sqrt * sqrt == diff_sum) count ++;
            }
        }
        return count;
    }

    static int sqrtInteger(int left, int right, int target) {
        if (left >= right) return left;
        int mid = (left + right) / 2;
        int midSquare = mid * mid;
        if (midSquare == target) return mid;
        if (midSquare < target) return sqrtInteger(mid + 1, right, target);
        return sqrtInteger(left, mid - 1, target);
    }



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < d; j ++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }

        out.println(distanceInteger(n, d, x));
        out.flush();
    }
}
