import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String[] str = in.readLine().split(" "); str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int d = Integer.parseInt(str[1]); d Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int[][] x = new int[n][d]; x new int[n][d] n d int count = 0; count 0 for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    } {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    } str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
        x[i][j] = Integer.parseInt(str[j]);
      } {
        x[i][j] = Integer.parseInt(str[j]);
      } x[i][j] = Integer.parseInt(str[j]) x[i][j] x[i] x i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    } {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    } for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      } int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      } {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      } long c=0; c 0 for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        } {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        } c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]) c Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]) 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 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 if(Math.sqrt(c) % 1==0){
          count++;
        } Math.sqrt(c) % 1==0 Math.sqrt(c) % 1 Math.sqrt(c) Math.sqrt Math c 1 0 {
          count++;
        } 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) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] x = new int[n][d];
    int count = 0;
    for(int i = 0; i < n; i++) {
        str = in.readLine().split(" ");
      for(int j = 0; j < d ; j++) {
        x[i][j] = Integer.parseInt(str[j]);
      }
    }
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < i; j++) {
        long c=0;
        for(int k = 0; k < d; k++) {
          c += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
        }
        if(Math.sqrt(c) % 1==0){
          count++;
        }
      }
    }
    System.out.println(count);
  }
}