import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
} import java.util.*; util.* java import java.math.*; math.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    } main {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int point = Integer.parseInt(sc.next()); point Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int jigen = Integer.parseInt(sc.next()); jigen Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc List<List<Integer>> pointList = new ArrayList(); pointList new ArrayList() for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        } int x=1; int x=1; x 1 x<=point x point x++ x++ x {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        } {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        } List<Integer> list = new ArrayList(); list new ArrayList() for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            } int y=1; int y=1; y 1 y<=jigen y jigen y++ y++ y {
                list.add(Integer.parseInt(sc.next()));
            } {
                list.add(Integer.parseInt(sc.next()));
            } list.add(Integer.parseInt(sc.next())) list.add list Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc pointList.add(list) pointList.add pointList list int res = 0; res 0 for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        } int x=1; int x=1; x 1 x<=point x point x++ x++ x {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        } {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        } List<Integer> compareList = pointList.get(x-1); compareList pointList.get(x-1) pointList.get pointList x-1 x 1 for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            } int y=1; int y=1; y 1 y<=point y point y++ y++ y {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            } {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            } if (x==y) {
                    continue;
                } x==y x y {
                    continue;
                } continue; List<Integer> list = pointList.get(y-1); list pointList.get(y-1) pointList.get pointList y-1 y 1 int r = 0; r 0 for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                } int z=1; int z=1; z 1 z<=jigen z jigen z++ z++ z {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                } {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                } int tmp1 = compareList.get(z-1); tmp1 compareList.get(z-1) compareList.get compareList z-1 z 1 int tmp2 = list.get(z-1); tmp2 list.get(z-1) list.get list z-1 z 1 r += (int)Math.pow(tmp1-tmp2,2) r (int)Math.pow(tmp1-tmp2,2) Math.pow Math tmp1-tmp2 tmp1 tmp2 2 double tmp = Math.sqrt(r); tmp Math.sqrt(r) Math.sqrt Math r double a = (int) tmp; a (int) tmp if (a*a ==tmp*tmp) {
                    res++;
                } a*a ==tmp*tmp a*a a a tmp*tmp tmp tmp {
                    res++;
                } res++ res System.out.println(res/2) System.out.println System.out System System.out res/2 res 2 String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
} Main
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
}
