import java.util.*;

public class Main
{
  public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  }
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  }
} import java.util.*; util.* java public class Main
{
  public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  }
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  }
} Main public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  } getDist {
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  } int dist = 0; dist 0 for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      } int i = 0; int i = 0; i 0 i<d i d i++ i++ i {
          dist += (y[i]-z[i])*(y[i]-z[i]);
      } {
          dist += (y[i]-z[i])*(y[i]-z[i]);
      } dist += (y[i]-z[i])*(y[i]-z[i]) dist (y[i]-z[i])*(y[i]-z[i]) (y[i]-z[i]) y[i] y i z[i] z i (y[i]-z[i]) y[i] y i z[i] z i return dist; dist int n n int d d int[] y y int[]z z public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  } main {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n d; d int cnt = 0; cnt 0 n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt() d sc.nextInt() sc.nextInt sc int[][] x = new int[n][d]; x new int[n][d] n d 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 int s_dist = 0; s_dist 0 double sqrt_dist = 0; sqrt_dist 0 for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    } {
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    } for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      } {
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      } s_dist = getDist(n, d, x[i], x[j]) s_dist getDist(n, d, x[i], x[j]) getDist n d x[i] x i x[j] x j sqrt_dist = Math.sqrt(s_dist) sqrt_dist Math.sqrt(s_dist) Math.sqrt Math s_dist if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        } sqrt_dist == (int)sqrt_dist sqrt_dist (int)sqrt_dist {
            cnt++;
        } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main
{
  public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  }
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  }
} public class Main
{
  public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  }
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  }
} Main
import java.util.*;

public class Main
{
  public static int getDist(int n, int d, int[] y, int[]z){
      int dist = 0;
      for(int i = 0; i<d; i++){
          dist += (y[i]-z[i])*(y[i]-z[i]);
      }
      return dist;
  }
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n, d;
	int cnt = 0;
    n = sc.nextInt();
    d = sc.nextInt();
    int[][] x = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0; j<d; j++){
        x[i][j] = sc.nextInt();
      }
    }
    
    int s_dist = 0;
    double sqrt_dist = 0;
	for(int i=0;i<n;i++){
      for(int j=i+1; j<n; j++){
        s_dist = getDist(n, d, x[i], x[j]);
        sqrt_dist = Math.sqrt(s_dist);
        if(sqrt_dist == (int)sqrt_dist)
        {
            cnt++;
        }
      }
    }
    System.out.println(cnt);
  }
}