import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int[][] c = new int[a][b]; c new int[a][b] a b int counter = 0; counter 0 for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      } {
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      } for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        } int j = 0; int j = 0; j 0 j < b j b j++ j++ j {
          c[i][j] = sc.nextInt();
        } {
          c[i][j] = sc.nextInt();
        } c[i][j] = sc.nextInt() c[i][j] c[i] c i j sc.nextInt() sc.nextInt sc for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      } int x = 0; int x = 0; x 0 x < a x a x++ x++ x {
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      } {
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      } for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        } int v = 1; int v = 1; v 1 v < a-x v a-x a x v++ v++ v {
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        } {
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        } int d = 0; d 0 double e = 0; e 0 int f = 0; f 0 for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          } int y = 0; int y = 0; y 0 y < b y b y++ y++ y { 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          } { 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          } d += Math.pow(c[x][y] - c[x+v][y],2) d Math.pow(c[x][y] - c[x+v][y],2) Math.pow Math c[x][y] - c[x+v][y] c[x][y] c[x] c x y c[x+v][y] c[x+v] c x+v x v y 2 e = Math.sqrt(d) e Math.sqrt(d) Math.sqrt Math d f = (int)e f (int)e if(e - f == 0){
            counter++;
          } e - f == 0 e - f e f 0 {
            counter++;
          } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter sc.close() sc.close sc String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[][] c = new int[a][b];
    int counter = 0;
      for(int i = 0;i < a;i++){
        for(int j = 0;j < b;j++){
          c[i][j] = sc.nextInt();
        }
      }
      for(int x = 0;x < a;x++){
        for(int v = 1;v < a-x;v++){
          int d = 0;
          double e = 0;
          int f = 0;        
          for(int y = 0;y < b;y++){ 
              d += Math.pow(c[x][y] - c[x+v][y],2);
          }      
          e = Math.sqrt(d);
          f = (int)e;
          if(e - f == 0){
            counter++;
          }
        }
      }
    System.out.println(counter);
    sc.close();
  }
}