import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    }
    static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    }
}
class f{
    double ff(double d){
        return d * 2;
    }
}
 import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    }
    static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        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 d = sc.nextInt() d sc.nextInt() sc.nextInt sc ans=0; ans 0 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]=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(); 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] x[i] x i j sc.nextInt() sc.nextInt sc for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        } int k=0; int k=0; k 0 k<n k n k++ k++ k for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        } for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        } int l=k+1; int l=k+1; l k+1 k 1 l<n l n l++ l++ l {
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        } {
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        } int ret = 0; ret 0 for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2); int m=0; int m=0; m 0 m<d m d m++ m++ m ret+=Math.pow((x[k][m]-x[l][m]), 2); ret+=Math.pow((x[k][m]-x[l][m]), 2) ret Math.pow((x[k][m]-x[l][m]), 2) Math.pow Math (x[k][m]-x[l][m]) x[k][m] x[k] x k m x[l][m] x[l] x l m 2 if(isPerfectSquare(ret))ans+=1; isPerfectSquare(ret) isPerfectSquare ret ans+=1 ans 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    } isPerfectSquare {
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    } double sq = Math.sqrt(x); sq Math.sqrt(x) Math.sqrt Math x return ((sq - Math.floor(sq) == 0)); ((sq - Math.floor(sq) == 0)) sq - Math.floor(sq) sq Math.floor(sq) Math.floor Math sq 0 double x x class f{
    double ff(double d){
        return d * 2;
    }
} f double ff(double d){
        return d * 2;
    } ff {
        return d * 2;
    } return d * 2; d * 2 d 2 double d d public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    }
    static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    }
    static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    }
} Main
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt(), ans=0;
        int[][] x = new int[n][d];
        for(int i=0;i<n;i++)for(int j=0;j<d;j++)x[i][j]=sc.nextInt();
        for(int k=0;k<n;k++)for(int l=k+1;l<n;l++){
            int ret = 0;
            for(int m=0;m<d;m++)ret+=Math.pow((x[k][m]-x[l][m]), 2);
            if(isPerfectSquare(ret))ans+=1;
        }
        System.out.println(ans);
    }
    static boolean isPerfectSquare(double x){
        double sq = Math.sqrt(x);
        return ((sq - Math.floor(sq) == 0));
    }
}
class f{
    double ff(double d){
        return d * 2;
    }
}

