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[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
} 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[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  } main {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  } 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[][] m = new int[N][D]; m new int[N][D] N D for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    } {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    } for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
        m[i][j] = sc.nextInt();
      } {
        m[i][j] = sc.nextInt();
      } m[i][j] = sc.nextInt() m[i][j] m[i] m i j sc.nextInt() sc.nextInt sc Set<Integer> squares = new HashSet<>(); squares new HashSet<>() for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    } int i = 0; int i = 0; i 0 i*i <= 16000 i*i i i 16000 i++ i++ i {
      squares.add(i*i);
    } {
      squares.add(i*i);
    } squares.add(i*i) squares.add squares i*i i i int ans = 0; ans 0 for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    } 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++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    } {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    } for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      } {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      } int dist = calc(m, i, j); dist calc(m, i, j) calc m i j if (squares.contains(dist)) {
          ans++;
        } squares.contains(dist) squares.contains squares dist {
          ans++;
        } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  } calc {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  } int ret = 0; ret 0 for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    } int i = 0; int i = 0; i 0 i < m[0].length i m[0].length m[0] m 0 m[0].length i++ i++ i {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    } {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    } int t = Math.abs(m[a][i] - m[b][i]); t Math.abs(m[a][i] - m[b][i]) Math.abs Math m[a][i] - m[b][i] m[a][i] m[a] m a i m[b][i] m[b] m b i ret += t*t ret t*t t t return ret; ret int[][] m m int a a int b b public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
} public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
} 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[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
}
