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();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  }
} 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();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  }
} Main public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) 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 String dummy = sc.nextLine(); dummy sc.nextLine() sc.nextLine sc int[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    } {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    } String[] s = sc.nextLine().split(" "); s sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
        x[i][j] = Integer.parseInt(s[j]);
      } {
        x[i][j] = Integer.parseInt(s[j]);
      } x[i][j] = Integer.parseInt(s[j]) x[i][j] x[i] x i j Integer.parseInt(s[j]) Integer.parseInt Integer s[j] s j int ans = 0; ans 0 for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) 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 sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    } {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    } for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      } {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      } int sum = 0; sum 0 for (int k = 0; k < d; k++) {
          sum += (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 {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        } {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        } sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) sum (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 if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++; Math.sqrt(sum) == (int)Math.sqrt(sum) Math.sqrt(sum) Math.sqrt Math sum (int)Math.sqrt(sum) Math.sqrt Math sum ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  }
} public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  }
} 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();
    String dummy = sc.nextLine();
    
    int[][] x = new int[n][d];

    for (int i = 0; i < n; i++) {
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < d; j++) {
        x[i][j] = Integer.parseInt(s[j]);
      }
    }

    
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
          sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        if (Math.sqrt(sum) == (int)Math.sqrt(sum)) ans++;
      }
    }

    System.out.println(ans);
  }
}
