import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}
 import java.util.*; util.* java import java.math.*; math.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    } 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 int cnt = 0; cnt 0 int[][] ar = new int[n][d]; ar new int[n][d] n d double[][] dist = new double[n][n]; dist new double[n][n] n n for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[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++) {
                ar[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                ar[i][j] = sc.nextInt();
            } {
                ar[i][j] = sc.nextInt();
            } ar[i][j] = sc.nextInt() ar[i][j] ar[i] ar i j sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        } {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        } for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            } {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            } for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                } {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                } dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2) dist[i][j] dist[i] dist i j Math.pow(Math.abs(ar[i][k]-ar[j][k]),2) Math.pow Math Math.abs(ar[i][k]-ar[j][k]) Math.abs Math ar[i][k]-ar[j][k] ar[i][k] ar[i] ar i k ar[j][k] ar[j] ar j k 2 dist[i][j] = Math.sqrt(dist[i][j]) dist[i][j] dist[i] dist i j Math.sqrt(dist[i][j]) Math.sqrt Math dist[i][j] dist[i] dist i j if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                } dist[i][j]-(int)dist[i][j] == 0 dist[i][j]-(int)dist[i][j] dist[i][j] dist[i] dist i j (int)dist[i][j] dist[i] dist i j 0 {
                    cnt++;
                } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

} io public static void br(){
        System.out.println("");
    } br {
        System.out.println("");
    } System.out.println("") System.out.println System.out System System.out "" public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    } YesNo {
        System.out.println(f?"Yes":"No");
    } System.out.println(f?"Yes":"No") System.out.println System.out System System.out f?"Yes":"No" f "Yes" "No" boolean f f public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    } YESNO {
        System.out.println(f?"YES":"NO");
    } System.out.println(f?"YES":"NO") System.out.println System.out System System.out f?"YES":"NO" f "YES" "NO" boolean f f class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


} Algo public static boolean isOdd(int n){
        return n % 2 == 1;
    } isOdd {
        return n % 2 == 1;
    } return n % 2 == 1; n % 2 == 1 n % 2 n 2 1 int n n public static boolean isEven(int n){
        return n % 2 == 0;
    } isEven {
        return n % 2 == 0;
    } return n % 2 == 0; n % 2 == 0 n % 2 n 2 0 int n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
} Main
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        int[][] ar = new int[n][d];
        double[][] dist = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ar[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dist[i][j] += Math.pow(Math.abs(ar[i][k]-ar[j][k]),2);
                }
                dist[i][j] = Math.sqrt(dist[i][j]);
                if(dist[i][j]-(int)dist[i][j] == 0){
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}

