
import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
} import java.util.*; util.* java public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
} Main private static final int INF = 1000000007; INF 1000000007 private static final int INF1 = Integer.MAX_VALUE; INF1 Integer.MAX_VALUE Integer Integer.MAX_VALUE 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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

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

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    } 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][d]; x new int[n][d] n d for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        } int tmp=0; int tmp=0; tmp 0 tmp < n tmp n tmp++ tmp++ tmp {
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        } {
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        } for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            } int tmp1= 0; int tmp1= 0; tmp1 0 tmp1< d tmp1 d tmp1++ tmp1++ tmp1 {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            } {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            } int tmpx = sc.nextInt(); tmpx sc.nextInt() sc.nextInt sc x[tmp][tmp1] = tmpx x[tmp][tmp1] x[tmp] x tmp tmp1 tmpx int result = 0; result 0 for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        } int tmp=0; int tmp=0; tmp 0 tmp<n tmp n tmp++ tmp++ tmp {
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        } {
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        } for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            } int tmp1=tmp + 1; int tmp1=tmp + 1; tmp1 tmp + 1 tmp 1 tmp1<n tmp1 n tmp1++ tmp1++ tmp1 {
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            } {
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            } long sum = 0; sum 0 for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                } int tmp2=0; int tmp2=0; tmp2 0 tmp2<d tmp2 d tmp2++ tmp2++ tmp2 {
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                } {
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                } long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2); part (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2) Math.pow Math Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]) Math.abs Math x[tmp][tmp2] - x[tmp1][tmp2] x[tmp][tmp2] x[tmp] x tmp tmp2 x[tmp1][tmp2] x[tmp1] x tmp1 tmp2 2 sum += part sum part double sumsqurt = Math.sqrt(sum); sumsqurt Math.sqrt(sum) Math.sqrt Math sum if(sumsqurt % 1 == 0){
                    result++;
                } sumsqurt % 1 == 0 sumsqurt % 1 sumsqurt 1 0 {
                    result++;
                } result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
} public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
} Main

import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    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][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
}
