import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
} import java.util.*; util.* java public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
} Main public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  } 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 int X[][] = new int[N][D]; X new int[N][D] N D int count = 0; count 0 for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    } 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] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    } {
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    } for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
        X[i][j] = scan.nextInt();
      } {
        X[i][j] = scan.nextInt();
      } X[i][j] = scan.nextInt() X[i][j] X[i] X i j scan.nextInt() scan.nextInt scan for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      } int k = 0; int k = 0; k 0 k < i k i k++ k++ k {
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      } {
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      } int kyori = 0; kyori 0 for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        } {
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        } kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]) kyori (X[i][j]-X[k][j])*(X[i][j]-X[k][j]) (X[i][j]-X[k][j]) X[i][j] X[i] X i j X[k][j] X[k] X k j (X[i][j]-X[k][j]) X[i][j] X[i] X i j X[k][j] X[k] X k j for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        } int l = 1; int l = 1; l 1 l*l <= kyori l*l l l kyori l++ l++ l {
          if(l*l == kyori){
            count++;
          }
        } {
          if(l*l == kyori){
            count++;
          }
        } if(l*l == kyori){
            count++;
          } l*l == kyori l*l l l kyori {
            count++;
          } count++ count System.out.println(count) System.out.println System.out System System.out count String[] arg arg public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
} public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
} Main
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
}