
import static java.lang.Math.sqrt;
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    }

} import static java.lang.Math.sqrt; import static java.lang.Math.sqrt; import static java.lang.Math.sqrt; import java.util.Scanner; Scanner java.util public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    }

} Main /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    } main {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    } 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 count = 0; count 0 int sum = 0; sum 0 int del[] = new int[d]; del new int[d] d int[][] point = new int[n][d]; point new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                point[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                point[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                point[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                point[i][j] = sc.nextInt();
            } {
                point[i][j] = sc.nextInt();
            } point[i][j] = sc.nextInt() point[i][j] point[i] point 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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        } 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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        } {
            for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        } for (int j = i + 1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            } {
                for (int k = 0; k < d; k++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            } for (int k = 0; k < d; k++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                } {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                } sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]) sum (point[i][k] -point[j][k])*(point[i][k] -point[j][k]) (point[i][k] -point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k (point[i][k] -point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k double k = sqrt(sum); k sqrt(sum) sqrt sum if ( k== (int) k) {
                    count++;
                } k== (int) k k (int) k {
                    count++;
                } count++ count sum = 0 sum 0 System.out.print(count) System.out.print System.out System System.out count String[] args args public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    }

} public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    }

} Main

import static java.lang.Math.sqrt;
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        int sum = 0;
        int del[] = new int[d];
        //int count = 0;
        int[][] point = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                point[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++) {
                    sum += (point[i][k] -point[j][k])*(point[i][k] -point[j][k]);
                }
                double k = sqrt(sum);
                if ( k== (int) k) {
                    count++;
                }
                sum = 0;
            }
        }
        System.out.print(count);
    }

}
