import 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  }
  
  public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  }
  

  
} import java.util.*; util.* java 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  }
  
  public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  }
  

  
} 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int x[][] = new int[n][d];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  } 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 int dist2 =0; dist2 0 int answer =0; answer 0 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 for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    } {
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    } for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      } {
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      } dist2=0 dist2 0 for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        } int k=0; int k=0; k 0 k<d k d k++ k++ k {
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        } {
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        } dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) dist2 dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) dist2 (x[i][k]-x[j][k])*(x[i][k]-x[j][k]) (x[i][k]-x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k]-x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k if(isSq(dist2)){
          answer = answer+1;
        } isSq(dist2) isSq dist2 {
          answer = answer+1;
        } answer = answer+1 answer answer+1 answer 1 System.out.println(answer) System.out.println System.out System System.out answer String[] args args public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  } isSq {
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  } for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    } int i=0; int i=0; i 0 i<=N i N i++ i++ i {
      if(i*i==N){
        return true;
      }
    } {
      if(i*i==N){
        return true;
      }
    } if(i*i==N){
        return true;
      } i*i==N i*i i i N {
        return true;
      } return true; true return false; false int N N 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  }
  
  public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  }
  

  
} 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  }
  
  public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  }
  

  
} Main
import 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];
    int dist2 =0;
    int answer =0;
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        x[i][j]=sc.nextInt();
      }
    }
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        dist2=0;
        for(int k=0;k<d;k++){
          dist2 = dist2+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        if(isSq(dist2)){
          answer = answer+1;
        }
      }
    }
        
    System.out.println(answer);
       
  }
  
  public static boolean isSq(int N){
    for(int i=0;i<=N;i++){
      if(i*i==N){
        return true;
      }
    }
    return false;
  }
  

  
}