import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    }
}
 import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    } main {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int d = input.nextInt(); d input.nextInt() input.nextInt input int[][] array = new int[n][d]; array new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                array[i][j] = input.nextInt();
            } {
                array[i][j] = input.nextInt();
            } array[i][j] = input.nextInt() array[i][j] array[i] array i j input.nextInt() input.nextInt input int count = 0; count 0 double dis = 0; dis 0 for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        } 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++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        } {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        } for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            } 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++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            } {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            } for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                } {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                } dis += Math.pow(array[i][k] - array[j][k],2) dis 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 dis = Math.sqrt(dis) dis Math.sqrt(dis) Math.sqrt Math dis if(dis == (int)dis){
                    count++;
                } dis == (int)dis dis (int)dis {
                    count++;
                } count++ count dis = 0 dis 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 input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();
        int[][] array = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                array[i][j] = input.nextInt();
            }
        }
        int count = 0;
        double dis = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    dis += Math.pow(array[i][k] - array[j][k],2);
                }
                dis = Math.sqrt(dis);
                if(dis == (int)dis){
                    count++;
                }
                dis = 0;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

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

