import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  } main {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner 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] = scanner.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] = scanner.nextInt(); for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt(); int j = 0; int j = 0; j 0 j < D j D j++ j++ j x[i][j] = scanner.nextInt(); x[i][j] = scanner.nextInt() x[i][j] x[i] x i j scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    } 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++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    } {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    } for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      } {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      } long d = 0; d 0 for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        } {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        } d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) d (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 int dd = (int) Math.sqrt(d); dd (int) Math.sqrt(d) Math.sqrt Math d if (dd * dd == d) count++; dd * dd == d dd * dd dd dd d count++ count 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 scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
}
