import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        Map<Integer,Integer> squares = new HashMap<>();

        for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        }

        int[][] dp = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        }

        int counter = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        }

        System.out.println(counter);
    }
} import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int d = scan.nextInt();

        Map<Integer,Integer> squares = new HashMap<>();

        for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        }

        int[][] dp = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        }

        int counter = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        }

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

        Map<Integer,Integer> squares = new HashMap<>();

        for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        }

        int[][] dp = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        }

        int counter = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        }

        System.out.println(counter);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int d = scan.nextInt();

        Map<Integer,Integer> squares = new HashMap<>();

        for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        }

        int[][] dp = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        }

        int counter = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        }

        System.out.println(counter);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan Map<Integer,Integer> squares = new HashMap<>(); squares new HashMap<>() for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        } int i = 1; int i = 1; i 1 i <= 200 i 200 i++ i++ i {
            squares.putIfAbsent(i*i,i);
        } {
            squares.putIfAbsent(i*i,i);
        } squares.putIfAbsent(i*i,i) squares.putIfAbsent squares i*i i i i int[][] dp = new int[n][d]; dp new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                dp[i][j] = scan.nextInt();
            } {
                dp[i][j] = scan.nextInt();
            } dp[i][j] = scan.nextInt() dp[i][j] dp[i] dp i j scan.nextInt() scan.nextInt scan int counter = 0; counter 0 for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        } {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        } for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            } {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            } int x = 0; x 0 for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                } {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                } x+=Math.pow(dp[i][k] - dp[j][k],2) x Math.pow(dp[i][k] - dp[j][k],2) Math.pow Math dp[i][k] - dp[j][k] dp[i][k] dp[i] dp i k dp[j][k] dp[j] dp j k 2 if(squares.containsKey(x)){
                    counter++;
                } squares.containsKey(x) squares.containsKey squares x {
                    counter++;
                } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        Map<Integer,Integer> squares = new HashMap<>();

        for (int i = 1; i <= 200; i++) {
            squares.putIfAbsent(i*i,i);
        }

        int[][] dp = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                dp[i][j] = scan.nextInt();
            }
        }

        int counter = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int x = 0;
                for (int k = 0; k < d; k++) {
                    x+=Math.pow(dp[i][k] - dp[j][k],2);
                }
                if(squares.containsKey(x)){
                    counter++;
                }
            }
        }

        System.out.println(counter);
    }
}