import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        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 n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(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[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[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++) {
                x[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] = sc.nextInt();
            } {
                x[i][j] = sc.nextInt();
            } x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        } {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        } for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            } {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            } double sum = 0; sum 0 for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                } {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                } sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2) sum Math.pow(Math.abs(x[i][k] - x[j][k]), 2) Math.pow Math Math.abs(x[i][k] - x[j][k]) Math.abs Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k 2 for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                } int k = 1; int k = 1; k 1 k <= sum k sum k++ k++ k {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                } {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                } if (Math.pow(k, 2) > sum) {
                        break;
                    } Math.pow(k, 2) > sum Math.pow(k, 2) Math.pow Math k 2 sum {
                        break;
                    } break; if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    } Math.pow(k, 2) == sum Math.pow(k, 2) Math.pow Math k 2 sum {
                        count++;
                        break;
                    } count++ count break; 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 n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        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 n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(Math.abs(x[i][k] - x[j][k]), 2);
                }
                for (int k = 1; k <= sum; k++) {
                    if (Math.pow(k, 2) > sum) {
                        break;
                    }
                    if (Math.pow(k, 2) == sum) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    }
}
