import java.math.*;
import java.util.*;
import java.lang.Math;
public class Main {
    static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
} import java.math.*; math.* java import java.util.*; util.* java import java.lang.Math; Math java.lang public class Main {
    static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
} Main static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    } sol {
        return (int) Math.pow(a - b, 2);
    } return (int) Math.pow(a - b, 2); (int) Math.pow(a - b, 2) Math.pow Math a - b a b 2 int a a int b b public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    } 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 li[][] = new int[n][d]; li new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        } {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        } for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            } {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            } int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc li[i][j] = tmp li[i][j] li[i] li i j tmp List<Integer> rtli= new ArrayList<>(); rtli new ArrayList<>() for(int i=0;i<300;i++)
            rtli.add(i * i); int i=0; int i=0; i 0 i<300 i 300 i++ i++ i rtli.add(i * i); rtli.add(i * i) rtli.add rtli i * i i i int tmp = 0; tmp 0 int cnt = 0; cnt 0 for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        } {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        } for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            } {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            } for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    tmp += sol(li[i][k], li[j][k]);
                } {
                    tmp += sol(li[i][k], li[j][k]);
                } tmp += sol(li[i][k], li[j][k]) tmp sol(li[i][k], li[j][k]) sol li[i][k] li[i] li i k li[j][k] li[j] li j k if (rtli.contains(tmp)){
                    cnt++;
                } rtli.contains(tmp) rtli.contains rtli tmp {
                    cnt++;
                } cnt++ cnt tmp = 0 tmp 0 System.out.println(cnt) System.out.println System.out System System.out cnt sc.close() sc.close sc String[] args args public class Main {
    static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
} public class Main {
    static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
} Main
import java.math.*;
import java.util.*;
import java.lang.Math;
public class Main {
    static int sol(int a, int b) {
        return (int) Math.pow(a - b, 2);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int li[][] = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                int tmp = sc.nextInt();
                li[i][j] = tmp;
            }
        }
        List<Integer> rtli= new ArrayList<>();
        for(int i=0;i<300;i++)
            rtli.add(i * i);
        int tmp = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = 0; k < d; k++) {
                    tmp += sol(li[i][k], li[j][k]);
                }
                if (rtli.contains(tmp)){
                    cnt++;
                }
                tmp = 0;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}
