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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
} 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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
} 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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] X = new int[N+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  } 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+1][D+1]; X new int[N+1][D+1] N+1 N 1 D+1 D 1 int[][] p = new int[N+1][N+1]; p new int[N+1][N+1] N+1 N 1 N+1 N 1 int count =0; count 0 for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    } int i =1; int i =1; i 1 i<=N i N i++ i++ i {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    } {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    } for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      } int j =1; int j =1; j 1 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=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    } int i=1; int i=1; i 1 i<=N i N i++ i++ i {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    } {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    } for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      } int j=i+1; int j=i+1; j i+1 i 1 j<=N j N j++ j++ j {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      } {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      } for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        } int k=1; int k=1; k 1 k<=D k D k++ k++ k {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        } {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        } p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) p[i][j] p[i] p i j (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        } int l=1; int l=1; l 1 l<=150 l 150 l++ l++ l {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        } {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        } if(p[i][j] == l * l) {
            count++;
            break;
          } p[i][j] == l * l p[i][j] p[i] p i j l * l l l {
            count++;
            break;
          } count++ count break; System.out.println(count) System.out.println System.out System System.out count 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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
} 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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
} 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+1][D+1];
    int[][] p = new int[N+1][N+1];
    int count =0;
    for (int i =1; i<=N; i++) {
      for (int j =1; j<=D; j++) {
        X[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=N; i++) {
      for (int j=i+1; j<=N; j++) {
        for (int k=1; k<=D; k++) {
          p[i][j] += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        for (int l=1; l<=150; l++) {
          if(p[i][j] == l * l) {
            count++;
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
}