import java.util.*;

public class Main {

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

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {

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

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n,d;

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n,d;

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n d; d n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt() d sc.nextInt() sc.nextInt sc int[][] x = new int[n][d]; x new int[n][d] n d double ans = 0; ans 0 int count = 0; count 0 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 for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        } {
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        } for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            } int k=i+1; int k=i+1; k i+1 i 1 k<n k n k++ k++ k {
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            } {
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            } for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                } int j=0; int j=0; j 0 j<d j d j++ j++ j {
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                } {
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                } if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    } i!=(n-1) i (n-1) n 1 {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    } ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2) ans Math.pow(Math.abs(x[i][j] - x[k][j]), 2) Math.pow Math Math.abs(x[i][j] - x[k][j]) Math.abs Math x[i][j] - x[k][j] x[i][j] x[i] x i j x[k][j] x[k] x k j 2 {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    } ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2) ans Math.pow(Math.abs(x[i][j] - x[0][j]), 2) Math.pow Math Math.abs(x[i][j] - x[0][j]) Math.abs Math x[i][j] - x[0][j] x[i][j] x[i] x i j x[0][j] x[0] x 0 j 2 ans = Math.sqrt(ans) ans Math.sqrt(ans) Math.sqrt Math ans if(ans == (int)ans){
                count++;
            } ans == (int)ans ans (int)ans {
                count++;
            } count++ count ans = 0 ans 0 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 sc = new Scanner(System.in);
        int n,d;

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    }
} public class Main {

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

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {

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

        n = sc.nextInt();
        d = sc.nextInt();

        int[][] x = new int[n][d];

        double ans = 0;
        int count = 0;

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

        for(int i=0;i<n;i++){
            for(int k=i+1;k<n;k++){
                for(int j=0;j<d;j++){
                    if(i!=(n-1)) {
                        ans += Math.pow(Math.abs(x[i][j] - x[k][j]), 2);
                    }else {
                        ans += Math.pow(Math.abs(x[i][j] - x[0][j]), 2);
                    }
                }
                ans = Math.sqrt(ans);
            if(ans == (int)ans){
                count++;
            }
            ans = 0;
            }
        }

        System.out.println(count);
    }
}