import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





}
} import java.io.BufferedReader; BufferedReader java.io import java.io.*; io.* java import java.util.*; util.* java import java.util.ArrayList; ArrayList java.util import java.util.Iterator; Iterator java.util import java.util.List; List java.util import java.util.Collections; Collections java.util import java.util.Arrays; Arrays java.util public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





}
} Main public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





} main {
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





} final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int sum = 0; sum 0 int count = 0; count 0 int[][] list = new int[n][d]; list new int[n][d] n d for(int i = 0; i < n ; i++){
        for(int j = 0; j < d ; j++){
            list[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++){
            list[i][j] = sc.nextInt();
        }
    } {
        for(int j = 0; j < d ; j++){
            list[i][j] = sc.nextInt();
        }
    } for(int j = 0; j < d ; j++){
            list[i][j] = sc.nextInt();
        } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
            list[i][j] = sc.nextInt();
        } {
            list[i][j] = sc.nextInt();
        } list[i][j] = sc.nextInt() list[i][j] list[i] list i j sc.nextInt() sc.nextInt sc for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    } {
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    } for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        } {
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        } for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            } int a = 0 ; int a = 0 ; a 0 a < d a d a++ a++ a {
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            } {
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            } sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]) sum (list[i][a] - list[j][a])*(list[i][a] - list[j][a]) (list[i][a] - list[j][a]) list[i][a] list[i] list i a list[j][a] list[j] list j a (list[i][a] - list[j][a]) list[i][a] list[i] list i a list[j][a] list[j] list j a if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            } Math.sqrt(sum) == (int)Math.sqrt(sum) Math.sqrt(sum) Math.sqrt Math sum (int)Math.sqrt(sum) Math.sqrt Math sum {
                count++;
            } count++ count sum = 0 sum 0 System.out.println(count) System.out.println System.out System System.out count final String[] args args public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





}
} public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





}
} Main
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    //final List<Integer> list = new ArrayList<>();
    int d = sc.nextInt();
    int sum = 0;
    int count = 0;

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

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

    for(int i = 0; i < n ; i++){
        for(int j = i + 1; j < n ; j++){
            for(int a = 0 ; a < d ; a++){
                sum += (list[i][a] - list[j][a])*(list[i][a] - list[j][a]);
            }
            if(Math.sqrt(sum) == (int)Math.sqrt(sum)){
                count++;
            }
            sum = 0;
        }
    }

    System.out.println(count);
    




    

    



    
  

    


    


    

    
    
    



    





}
}