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[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
} 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[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    int[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  } main {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    int[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  } 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[][] x = new int[n][d]; x new int[n][d] n d double buf[][] = new double[n][n]; buf new double[n][n] n n int ans = 0; ans 0 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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      for(int k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    } {
      for(int k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    } for(int k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      } int k = 1; int k = 1; k 1 i + k < n i + k i k n k++ k++ k {
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      } {
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      } for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        } {
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        } buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]) buf[i][i + k] buf[i] buf i i + k i k (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]) (x[i][j] - x[i + k][j]) x[i][j] x[i] x i j x[i + k][j] x[i + k] x i + k i k j (x[i][j] - x[i + k][j]) x[i][j] x[i] x i j x[i + k][j] x[i + k] x i + k i k j for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    } {
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    } for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      } {
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      } if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        } (buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0) (buf[i][j] != 0) buf[i][j] buf[i] buf i j 0 (Math.sqrt(buf[i][j]) % 1 == 0) Math.sqrt(buf[i][j]) % 1 Math.sqrt(buf[i][j]) Math.sqrt Math buf[i][j] buf[i] buf i j 1 0 {
          ans += 1;
        } ans += 1 ans 1 System.out.println(ans) System.out.println System.out System System.out ans 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[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    int[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
} 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[][] x = new int[n][d];
    double buf[][] = new double[n][n];
    int ans = 0;

    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 k = 1; i + k < n; k++){
        for(int j = 0; j < d; j++){
        buf[i][i + k] +=  (x[i][j] - x[i + k][j]) * (x[i][j] - x[i + k][j]);
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if((buf[i][j] != 0) &&(Math.sqrt(buf[i][j]) % 1 == 0)){
          ans += 1;
        }
      }
    }

    System.out.println(ans);
    
  }
}
