
import java.util.*;

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

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

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

        System.out.println(count);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt(); int d = stdIn.nextInt();
        int[][] x = new int[n][d];

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

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt(); int d = stdIn.nextInt();
        int[][] x = new int[n][d];

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

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

        System.out.println(count);
    } main {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt(); int d = stdIn.nextInt();
        int[][] x = new int[n][d];

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

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

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

import java.util.*;

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

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

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

        System.out.println(count);
    }
}