import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 ans = 0; ans 0 int[][] ary = new int[n][d]; ary new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[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++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                ary[i][j] = Integer.parseInt(sc.next());
            } {
                ary[i][j] = Integer.parseInt(sc.next());
            } ary[i][j] = Integer.parseInt(sc.next()) ary[i][j] ary[i] ary i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ans += permutation(ary, n, i, i+1, d, 0);
        } {
            ans += permutation(ary, n, i, i+1, d, 0);
        } ans += permutation(ary, n, i, i+1, d, 0) ans permutation(ary, n, i, i+1, d, 0) permutation ary n i i+1 i 1 d 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      } permutation {
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      } if(N == o){
          return cnt;
        } N == o N o {
          return cnt;
        } return cnt; cnt int sum = 0; sum 0 for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        } int i = 0; int i = 0; i 0 i < d i d i++ i++ i {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        } {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        } int a = ary[n][i]; a ary[n][i] ary[n] ary n i int b = ary[o][i]; b ary[o][i] ary[o] ary o i sum += Math.abs(Math.pow((a-b),2)) sum Math.abs(Math.pow((a-b),2)) Math.abs Math Math.pow((a-b),2) Math.pow Math (a-b) a b 2 int sqrt = (int) Math.sqrt(sum); sqrt (int) Math.sqrt(sum) Math.sqrt Math sum if (sqrt * sqrt == sum) {
            cnt++;
        } sqrt * sqrt == sum sqrt * sqrt sqrt sqrt sum {
            cnt++;
        } cnt++ cnt o++ o return permutation(ary, N, n, o, d, cnt); permutation(ary, N, n, o, d, cnt) permutation ary N n o d cnt int[][] ary ary int N N int n n int o o int d d int cnt cnt public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
}