import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    } main {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int[][] array = new int[a][b]; array new int[a][b] a b int count = 0; count 0 for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        } {
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        } for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < b j b j++ j++ j {
                array[i][j] = sc.nextInt();
            } {
                array[i][j] = sc.nextInt();
            } array[i][j] = sc.nextInt() array[i][j] array[i] array i j sc.nextInt() sc.nextInt sc double ans = 0; ans 0 for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        } int i = 0; int i = 0; i 0 i < a - 1 i a - 1 a 1 i++ i++ i {
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        } {
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        } for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < a j a j++ j++ j {
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            } {
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            } for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                } int k = 0; int k = 0; k 0 k < b k b k++ k++ k {
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                } {
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                } ans = ans + Math.pow(array[i][k] - array[j][k], 2) ans ans + Math.pow(array[i][k] - array[j][k], 2) ans Math.pow(array[i][k] - array[j][k], 2) Math.pow Math array[i][k] - array[j][k] array[i][k] array[i] array i k array[j][k] array[j] array j k 2 ans = Math.sqrt(ans) ans Math.sqrt(ans) Math.sqrt Math ans if(ans == (int)ans){
                    count++;
                } ans == (int)ans ans (int)ans {
                    count++;
                } count++ count ans = 0 ans 0 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    }
} public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[][] array = new int[a][b];
        int count = 0;
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                array[i][j] = sc.nextInt();
            }
        }
        double ans = 0;
        for(int i = 0; i < a - 1; i++){
            for(int j = i + 1; j < a; j++){
                for(int k = 0; k < b; k++){
                    ans = ans + Math.pow(array[i][k] - array[j][k], 2);
                }
                ans = Math.sqrt(ans);
                if(ans == (int)ans){
                    count++;
                }
                ans = 0;
            }
        }
        System.out.println(count);
    }
}