import java.util.*;

public class Main {
  public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
  
  private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
  
  private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  }
} Main public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  } main {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  } int N N D; D int[][] X; X try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    } {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc D = sc.nextInt() D sc.nextInt() sc.nextInt sc X = new int[N][D] X new int[N][D] N D for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      } {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      } X[i] = new int[D] X[i] X i new int[D] D for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        } int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
          X[i][d] = sc.nextInt();
        } {
          X[i][d] = sc.nextInt();
        } X[i][d] = sc.nextInt() X[i][d] X[i] X i d sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    } {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    } for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      } {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      } int rSquared = 0; rSquared 0 for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        } int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        } {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        } int diff = X[i][d] - X[j][d]; diff X[i][d] - X[j][d] X[i][d] X[i] X i d X[j][d] X[j] X j d rSquared += diff * diff rSquared diff * diff diff diff double r = Math.sqrt(rSquared); r Math.sqrt(rSquared) Math.sqrt Math rSquared if ( isOk(r) ) {
          count++;
        } isOk(r) isOk r {
          count++;
        } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  } isOk {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  } int intValue = (int)Math.floor(value); intValue (int)Math.floor(value) Math.floor Math value return value == (double)intValue; value == (double)intValue value (double)intValue double value value public class Main {
  public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
  
  private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  }
} public class Main {
  public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
  
  private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int N, D;
    int[][] X;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      D = sc.nextInt();
      X = new int[N][D];
      for(int i = 0; i < N; i++) {
        X[i] = new int[D];
        for(int d = 0; d < D; d++) {
          X[i][d] = sc.nextInt();
        }
      }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
      for(int j = i+1; j < N; j++) {
        int rSquared = 0;
        for(int d = 0; d < D; d++) {
          int diff = X[i][d] - X[j][d];
          rSquared += diff * diff;
        }
        double r = Math.sqrt(rSquared);
        if ( isOk(r) ) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
  
  private static boolean isOk(double value) {
    int intValue = (int)Math.floor(value);
    return value == (double)intValue;
  }
}