import java.util.*;


class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  }
  public static boolean hantei(int a) {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  }
  } import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  }
  public static boolean hantei(int a) {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  }
  } Main public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int d = stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn int[][] x = new int[n][d]; x new int[n][d] n d for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    } int i = 0; int i = 0; i 0 i<x.length i x.length x x.length i++ i++ i {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    } {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    } for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      } int j = 0; int j = 0; j 0 j<x[i].length j x[i].length x[i] x i x[i].length j++ j++ j {
        x[i][j] = stdIn.nextInt();
      } {
        x[i][j] = stdIn.nextInt();
      } x[i][j] = stdIn.nextInt() x[i][j] x[i] x i j stdIn.nextInt() stdIn.nextInt stdIn int a = 0; a 0 int count = 0; count 0 for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    } int i = 0; int i = 0; i 0 i<x.length i x.length x x.length i++ i++ i {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    } {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    } for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      } int u = i+1; int u = i+1; u i+1 i 1 u<x.length u x.length x x.length u++ u++ u {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      } {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      } a = 0 a 0 for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      } int j = 0; int j = 0; j 0 j<x[i].length j x[i].length x[i] x i x[i].length j++ j++ j {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      } {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      } if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break; u<n u n a += (int)Math.pow(x[i][j]-x[u][j],2) a (int)Math.pow(x[i][j]-x[u][j],2) Math.pow Math x[i][j]-x[u][j] x[i][j] x[i] x i j x[u][j] x[u] x u j 2 break; if(hantei(a)) count+=1; hantei(a) hantei a count+=1 count 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public static boolean hantei(int a) {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  } hantei {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  } for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    } int i = 1; int i = 1; i 1 i<=(int)Math.sqrt(a) i (int)Math.sqrt(a) Math.sqrt Math a i++ i++ i {
      if(a==i*i) return true;
    } {
      if(a==i*i) return true;
    } if(a==i*i) return true; a==i*i a i*i i i return true; true return false; false int a a
import java.util.*;


class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int d = stdIn.nextInt();
    int[][] x = new int[n][d];
    for(int i = 0;i<x.length;i++) {
      for(int j = 0;j<x[i].length;j++) {
        x[i][j] = stdIn.nextInt();
      }
    }
    int a = 0;
    int count = 0;
    for(int i = 0;i<x.length;i++) {
      for(int u = i+1;u<x.length;u++) {
        a = 0;
      for(int j = 0;j<x[i].length;j++) {
        if(u<n) a += (int)Math.pow(x[i][j]-x[u][j],2);
        else break;
      }
      //System.out.println(a);
      if(hantei(a)) count+=1;
      }
    }
    System.out.println(count);
  }
  public static boolean hantei(int a) {
    for(int i = 1;i<=(int)Math.sqrt(a);i++) {
      if(a==i*i) return true;
    }
    return false;
  }
  }