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