import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
} Main public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    } main {
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    } MyReader r = new MyReader(); r new MyReader() int N N D; D {int[] a = r.ii(); N = a[0]; D = a[1];} int[] a = r.ii(); a r.ii() r.ii r N = a[0] N a[0] a 0 D = a[1] D a[1] a 1 int[][] X = new int[N][]; X new int[N][] N for(int i = 0; i < N; i++)
            X[i] = r.ii(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i X[i] = r.ii(); X[i] = r.ii() X[i] X i r.ii() r.ii r int ans = 0; ans 0 for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        } 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++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        } {
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        } for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            } {
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            } double d = 0; d 0 for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    d += pow(X[i][k]-X[j][k]);
                } {
                    d += pow(X[i][k]-X[j][k]);
                } d += pow(X[i][k]-X[j][k]) d pow(X[i][k]-X[j][k]) pow X[i][k]-X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k d = Math.sqrt(d) d Math.sqrt(d) Math.sqrt Math d if(d%1 == 0){
                    ans++;
                } d%1 == 0 d%1 d 1 0 {
                    ans++;
                } ans++ ans println(ans) println ans String[] args args static int pow(int x){
        return x*x;
    } pow {
        return x*x;
    } return x*x; x*x x x int x x static void print(Object o){
        System.out.print(o.toString());
    } print {
        System.out.print(o.toString());
    } System.out.print(o.toString()) System.out.print System.out System System.out o.toString() o.toString o Object o o static void println(Object o){
        System.out.println(o.toString());
    } println {
        System.out.println(o.toString());
    } System.out.println(o.toString()) System.out.println System.out System System.out o.toString() o.toString o Object o o static int Int(String s){
        return Integer.parseInt(s);
    } Int {
        return Integer.parseInt(s);
    } return Integer.parseInt(s); Integer.parseInt(s) Integer.parseInt Integer s String s s static long Long(String s){
        return Long.parseLong(s);
    } Long {
        return Long.parseLong(s);
    } return Long.parseLong(s); Long.parseLong(s) Long.parseLong Long s String s s static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    } MyReader MyReader(){
            super(new InputStreamReader(System.in));
        } MyReader {
            super(new InputStreamReader(System.in));
        } super(new InputStreamReader(System.in)) super new InputStreamReader(System.in) String s() throws IOException{
            return readLine();
        } s {
            return readLine();
        } return readLine(); readLine() readLine String[] ss() throws IOException{
            return s().split(" ");
        } ss {
            return s().split(" ");
        } return s().split(" "); s().split(" ") s().split s() s " " int i() throws IOException{
            return Int(s());
        } i {
            return Int(s());
        } return Int(s()); Int(s()) Int s() s int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        } ii {
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        } String[] ss = ss(); ss ss() ss int size = ss.length; size ss.length ss ss.length int[] ii = new int[size]; ii new int[size] size for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]); int j = 0; int j = 0; j 0 j < size j size j++ j++ j ii[j] = Integer.parseInt(ss[j]); ii[j] = Integer.parseInt(ss[j]) ii[j] ii j Integer.parseInt(ss[j]) Integer.parseInt Integer ss[j] ss j return ii; ii long l() throws IOException{
            return Long(s());
        } l {
            return Long(s());
        } return Long(s()); Long(s()) Long s() s long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        } ll {
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        } String[] ss = ss(); ss ss() ss int size = ss.length; size ss.length ss ss.length long[] ll = new long[size]; ll new long[size] size for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]); int j = 0; int j = 0; j 0 j < size j size j++ j++ j ll[j] = Long.parseLong(ss[j]); ll[j] = Long.parseLong(ss[j]) ll[j] ll j Long.parseLong(ss[j]) Long.parseLong Long ss[j] ss j return ll; ll BufferedReader public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
} public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
} Main
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}