import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] array = new int[r][c]; array new int[r][c] r c for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                array[i][j] = sc.nextInt();
            } {
                array[i][j] = sc.nextInt();
            } array[i][j] = sc.nextInt() array[i][j] array[i] array i j sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        } int h = 0; int h = 0; h 0 h < r - 1 h r - 1 r 1 h++ h++ h {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        } {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        } for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            } int i = h + 1; int i = h + 1; i h + 1 h 1 i < r i r i++ i++ i {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            } {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            } int tmp = 0; tmp 0 for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                } {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                } tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2) tmp (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2) Math.pow Math Math.abs(array[h][j] - array[i][j]) Math.abs Math array[h][j] - array[i][j] array[h][j] array[h] array h j array[i][j] array[i] array i j 2 double tmp2 = Math.sqrt(tmp); tmp2 Math.sqrt(tmp) Math.sqrt Math tmp if (tmp2 == (int)tmp2) {
                    count++;
                } tmp2 == (int)tmp2 tmp2 (int)tmp2 {
                    count++;
                } count++ count 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) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] array = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        int count = 0;
        for (int h = 0; h < r - 1; h++) {
            for (int i = h + 1; i < r; i++) {
                int tmp = 0;
                for (int j = 0; j < c; j++) {
                    tmp += (int)Math.pow(Math.abs(array[h][j] - array[i][j]), 2);
                }
                
                double tmp2 = Math.sqrt(tmp);
                if (tmp2 == (int)tmp2) {
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
}
