import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    } 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 ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>(); plist new ArrayList<ArrayList<Double>>() for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        } int Ni = 0; int Ni = 0; Ni 0 Ni < N Ni N Ni++ Ni++ Ni {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        } {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        } ArrayList<Double> l = new ArrayList<>(); l new ArrayList<>() for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            } int Di = 0; int Di = 0; Di 0 Di < D Di D Di++ Di++ Di {
                l.add(sc.nextDouble());
            } {
                l.add(sc.nextDouble());
            } l.add(sc.nextDouble()) l.add l sc.nextDouble() sc.nextDouble sc plist.add(l) plist.add plist l int c = 0; c 0 for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        } ArrayList<Double> p1 plist {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        } {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        } for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            } ArrayList<Double> p2 plist {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            } {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            } if(p1==p2)continue; p1==p2 p1 p2 continue; double d = 0; d 0 for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                } int i=0; int i=0; i 0 i<D i D i++ i++ i {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                } {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                } d +=Math.pow(p2.get(i)-p1.get(i),2) d Math.pow(p2.get(i)-p1.get(i),2) Math.pow Math p2.get(i)-p1.get(i) p2.get(i) p2.get p2 i p1.get(i) p1.get p1 i 2 d = Math.sqrt(d) d Math.sqrt(d) Math.sqrt Math d if(d == (int)d) c++; d == (int)d d (int)d c++ c System.out.println(c/2) System.out.println System.out System System.out c/2 c 2 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        ArrayList<ArrayList<Double>> plist = new ArrayList<ArrayList<Double>>();
        for (int Ni = 0; Ni < N; Ni++) {
            ArrayList<Double> l = new ArrayList<>();
            for (int Di = 0; Di < D; Di++) {
                l.add(sc.nextDouble());
            }
            plist.add(l);
        }

        int c = 0;
        for (ArrayList<Double> p1 : plist) {
            for (ArrayList<Double> p2 : plist) {
                if(p1==p2)continue;
                double d = 0;
                for(int i=0; i<D; i++) {
                     d +=Math.pow(p2.get(i)-p1.get(i),2);
                }
                d = Math.sqrt(d);
                if(d == (int)d) c++;
            }
            
        }
        System.out.println(c/2);
    }

}