import java.util.Scanner;
import java.util.stream.Stream;

class Main {
  private static void solve(int n, int d, int[][] x) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  }
} import java.util.Scanner; Scanner java.util import java.util.stream.Stream; Stream java.util.stream class Main {
  private static void solve(int n, int d, int[][] x) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  }
} Main private static void solve(int n, int d, int[][] x) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  } solve {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  } int count = 0; count 0 for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    } {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    } for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      } {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      } long distance = 0; distance 0 for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        } {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        } int diff = Math.abs(x[i][k] - x[j][k]); diff Math.abs(x[i][k] - x[j][k]) Math.abs Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k distance += diff * diff distance diff * diff diff diff double sqrt = Math.sqrt((double) distance); sqrt Math.sqrt((double) distance) Math.sqrt Math (double) distance if (Math.floor(sqrt) == sqrt) count++; Math.floor(sqrt) == sqrt Math.floor(sqrt) Math.floor Math sqrt sqrt count++ count System.out.println(count) System.out.println System.out System System.out count int n n int d d int[][] x x public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  } main {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] num = sc.nextLine().split(" "); num sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(num[0]); n Integer.parseInt(num[0]) Integer.parseInt Integer num[0] num 0 int d = Integer.parseInt(num[1]); d Integer.parseInt(num[1]) Integer.parseInt Integer num[1] num 1 int[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    } {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    } String[] xi = sc.nextLine().split(" "); xi sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]); int j = 0; int j = 0; j 0 j < d j d j++ j++ j x[i][j] = Integer.parseInt(xi[j]); x[i][j] = Integer.parseInt(xi[j]) x[i][j] x[i] x i j Integer.parseInt(xi[j]) Integer.parseInt Integer xi[j] xi j solve(n, d, x) solve n d x String[] args args
import java.util.Scanner;
import java.util.stream.Stream;

class Main {
  private static void solve(int n, int d, int[][] x) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long distance = 0;
        for (int k = 0; k < d; k++) {
          int diff = Math.abs(x[i][k] - x[j][k]);
          distance += diff * diff;
        }
        double sqrt = Math.sqrt((double) distance);
        if (Math.floor(sqrt) == sqrt) count++;
      }
    }
    System.out.println(count);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] num = sc.nextLine().split(" ");
    int n = Integer.parseInt(num[0]);
    int d = Integer.parseInt(num[1]);
    int[][] x = new int[n][d];
    for (int i = 0; i < n; i++) {
      String[] xi = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) x[i][j] = Integer.parseInt(xi[j]);
    }
    solve(n, d, x);
  }
}