import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

import static java.lang.StrictMath.floor;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util import static java.lang.StrictMath.floor; import static java.lang.StrictMath.floor; import static java.lang.StrictMath.floor; public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    } Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in))); sc new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] arr = new int[n][d]; arr new int[n][d] n d for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[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++) {
                arr[i][j] = sc.nextInt();
            }
        } {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        } for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j<d j d j++ j++ j {
                arr[i][j] = sc.nextInt();
            } {
                arr[i][j] = sc.nextInt();
            } arr[i][j] = sc.nextInt() arr[i][j] arr[i] arr i j sc.nextInt() sc.nextInt sc int res = 0; res 0 for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        } {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        } for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            } {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            } double dis = 0; dis 0 for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                } int k = 0; int k = 0; k 0 k<d k d k++ k++ k {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                } {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                } dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]) dis (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]) (arr[i][k] - arr[j][k]) arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k (arr[i][k] - arr[j][k]) arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k dis = Math.sqrt(dis) dis Math.sqrt(dis) Math.sqrt Math dis double temp = floor(dis); temp floor(dis) floor dis if ( temp - dis == 0) {
                    res++;
                } temp - dis == 0 temp - dis temp dis 0 {
                    res++;
                } res++ res System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

import static java.lang.StrictMath.floor;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] arr = new int[n][d];

        for(int i=0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        int res = 0;
        for(int i = 0; i < n; i++) {

            for(int j = i + 1; j < n; j++) {
                double dis = 0;
                for (int k = 0; k<d; k++) {
                    dis += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
                }
                dis = Math.sqrt(dis);
                double temp = floor(dis);
                if ( temp - dis == 0) {
                    res++;
                }

            }
        }
        System.out.println(res);
    }
}
