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