import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    } 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[][] x = new int[n][]; x new int[n][] n for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            x[i] = new int[d];
        } {
            x[i] = new int[d];
        } x[i] = new int[d] x[i] x i new int[d] d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[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++) {
                x[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] = sc.nextInt();
            } {
                x[i][j] = sc.nextInt();
            } x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc sc.close() sc.close sc long[] candidates = new long[n * n]; candidates new long[n * n] n * n n n int counter = 0; counter 0 for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        } {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        } for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            } {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            } candidates[counter] = 0 candidates[counter] candidates counter 0 for (int k = 0; k < d; k++) {
                    candidates[counter] += (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 {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) candidates[counter] candidates counter (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 counter++ counter Set<Long> answerSet = new HashSet<>(); answerSet new HashSet<>() int max = (20 - (-20)) * (20 - (-20)) * 100; max (20 - (-20)) * (20 - (-20)) * 100 (20 - (-20)) * (20 - (-20)) * 100 (20 - (-20)) 20 (-20) 20 (20 - (-20)) 20 (-20) 20 100 for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        } int i = 1; int i = 1; i 1 i < max i max i++ i++ i {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        } {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        } long tmp = i * i; tmp i * i i i if (tmp > max) {
                break;
            } tmp > max tmp max {
                break;
            } break; answerSet.add(tmp) answerSet.add answerSet tmp int ans = 0; ans 0 for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        } long i candidates {
            if (answerSet.contains(i)) {
                ans++;
            }
        } {
            if (answerSet.contains(i)) {
                ans++;
            }
        } if (answerSet.contains(i)) {
                ans++;
            } answerSet.contains(i) answerSet.contains answerSet i {
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}
