import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    }

    static int nextInt(){
        return Integer.parseInt(sc.next());
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.*; util.* java public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    }

    static int nextInt(){
        return Integer.parseInt(sc.next());
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
} Main static String br = System.getProperty("line.separator"); br System.getProperty("line.separator") System.getProperty System "line.separator" static Scanner sc  = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    } main {

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    } int N = nextInt(); N nextInt() nextInt int D = nextInt(); D nextInt() nextInt int[][] a = new int[N][D]; a new int[N][D] N D for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        } {
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        } for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            } int j=0; int j=0; j 0 j<D j D j++ j++ j {
                a[i][j] = nextInt();
            } {
                a[i][j] = nextInt();
            } a[i][j] = nextInt() a[i][j] a[i] a i j nextInt() nextInt boolean[][] reached = new boolean[N][N]; reached new boolean[N][N] N N for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            Arrays.fill(reached[i], false);
        } {
            Arrays.fill(reached[i], false);
        } Arrays.fill(reached[i], false) Arrays.fill Arrays reached[i] reached i false int count = 0; count 0 for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        } {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        } for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            } int j=0; int j=0; j 0 j<N j N j++ j++ j {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            } {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            } if (i == j || reached[i][j] || reached[j][i]) continue; i == j || reached[i][j] || reached[j][i] i == j || reached[i][j] || reached[j][i] i == j i j reached[i][j] reached[i] reached i j reached[j][i] reached[j] reached j i continue; int sum = 0; sum 0 for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                } {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                } sum += Math.pow(a[i][k] - a[j][k], 2) sum Math.pow(a[i][k] - a[j][k], 2) Math.pow Math a[i][k] - a[j][k] a[i][k] a[i] a i k a[j][k] a[j] a j k 2 reached[i][j] = true reached[i][j] reached[i] reached i j true int num = (int)Math.sqrt(sum); num (int)Math.sqrt(sum) Math.sqrt Math sum if(num == Math.sqrt(sum)){
                    count++;
                } num == Math.sqrt(sum) num Math.sqrt(sum) Math.sqrt Math sum {
                    count++;
                } count++ count println(count) println count String[] args args static int nextInt(){
        return Integer.parseInt(sc.next());
    } nextInt {
        return Integer.parseInt(sc.next());
    } return Integer.parseInt(sc.next()); Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    } println {
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    } PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.println(o) out.println out o out.flush() out.flush out Object o o static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    } print {
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    } PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.print(o) out.print out o out.flush() out.flush out Object o o public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    }

    static int nextInt(){
        return Integer.parseInt(sc.next());
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
} public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    }

    static int nextInt(){
        return Integer.parseInt(sc.next());
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
} Main
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){

        int N = nextInt();
        int D = nextInt();

        int[][] a = new int[N][D];
        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                a[i][j] = nextInt();
            }
        }

        boolean[][] reached = new boolean[N][N];
        for(int i=0; i<N; i++){
            Arrays.fill(reached[i], false);
        }

        int count = 0;
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if (i == j || reached[i][j] || reached[j][i]) continue;
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(a[i][k] - a[j][k], 2);
                }
                reached[i][j] = true;

                int num = (int)Math.sqrt(sum);
                if(num == Math.sqrt(sum)){
                    count++;
                }
            }
        }
        println(count);
    }

    static int nextInt(){
        return Integer.parseInt(sc.next());
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
}
