import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenAtCoderUtil {
    static Collection<Integer> nScan(Scanner sc, int n) {
        Collection<Integer>al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    static Pair<ArrayList<Integer>, ArrayList<Integer>> nScanPair(Scanner sc, int n) {
        Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>());
        for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        }
        return al;
    }
}

class Pair<K, V> implements Entry<K, V>, java.io.Serializable {
    private static final long serialVersionUID = -8499721149061103585L;

    private K key;
    private V value;

    public Pair(K key, V value) {
        this.key   = key;
        this.value = value;
    }

    public Pair(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    }

    public K getKey() {
        return key;
    }

    public V getValue() {
        return value;
    }

    public K setKey(K key) {
        K oldKey = this.key;
        this.key = key;
        return oldKey;
    }

    public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    }

    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    public int hashCode() {
        return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
    }

    public String toString() {
        return key + "=" + value;
    }

    private static boolean eq(Object o1, Object o2) {
        return o1 == null ? o2 == null : o1.equals(o2);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collection; Collection java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util import java.util.Map.Entry; Entry java.util.Map import java.util.Map; Map java.util public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    }
} Main public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    } main {
        Object o = run();
        if (o != null)
            System.out.println(o);
    } Object o = run(); o run() run if (o != null)
            System.out.println(o); o != null o null System.out.println(o) System.out.println System.out System System.out o String[] args args static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    } run {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    } try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        } {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int result = 0; result 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc ArrayList<ArrayList<Integer>> x = new ArrayList<>(); x new ArrayList<>() for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            } {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            } x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d)) x.add x (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d) ChenAtCoderUtil.nScan ChenAtCoderUtil sc d for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            } {
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            } for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                } {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                } if (i == j) continue; i == j i j continue; int sum = 0; sum 0 for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    } {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    } sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2) sum Math.pow(x.get(i).get(k) - x.get(j).get(k),2) Math.pow Math x.get(i).get(k) - x.get(j).get(k) x.get(i).get(k) x.get(i).get x.get(i) x.get x i k x.get(j).get(k) x.get(j).get x.get(j) x.get x j k 2 double s = Math.sqrt(sum); s Math.sqrt(sum) Math.sqrt Math sum if (s % 1 == 0) result++; s % 1 == 0 s % 1 s 1 0 result++ result return result/2; result/2 result 2 class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
} ChenNumberUtil static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    } getDivisors {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    } ArrayList<Integer> al = new ArrayList<>(); al new ArrayList<>() for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        } int i = 1; int i = 1; i 1 i * i <= n i * i i i n i++ i++ i {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        } {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        } if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            } n % i == 0 n % i n i 0 {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            } al.add(i) al.add al i if (n / i != i)
                    al.add(n / i); n / i != i n / i n i i al.add(n / i) al.add al n / i n i Collections.sort(al) Collections.sort Collections al return al; al int n n class ChenAtCoderUtil {
    static Collection<Integer> nScan(Scanner sc, int n) {
        Collection<Integer>al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    static Pair<ArrayList<Integer>, ArrayList<Integer>> nScanPair(Scanner sc, int n) {
        Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>());
        for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        }
        return al;
    }
} ChenAtCoderUtil static Collection<Integer> nScan(Scanner sc, int n) {
        Collection<Integer>al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    } nScan {
        Collection<Integer>al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    } Collection<Integer>al = new ArrayList<>(); al new ArrayList<>() for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            al.add(sc.nextInt());
        } {
            al.add(sc.nextInt());
        } al.add(sc.nextInt()) al.add al sc.nextInt() sc.nextInt sc return al; al Scanner sc sc int n n static Pair<ArrayList<Integer>, ArrayList<Integer>> nScanPair(Scanner sc, int n) {
        Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>());
        for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        }
        return al;
    } nScanPair {
        Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>());
        for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        }
        return al;
    } Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>()); al new Pair<>(new ArrayList<>(), new ArrayList<>()) for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        } {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        } al.getKey().add(sc.nextInt()) al.getKey().add al.getKey() al.getKey al sc.nextInt() sc.nextInt sc al.getValue().add(sc.nextInt()) al.getValue().add al.getValue() al.getValue al sc.nextInt() sc.nextInt sc return al; al Scanner sc sc int n n class Pair<K, V> implements Entry<K, V>, java.io.Serializable {
    private static final long serialVersionUID = -8499721149061103585L;

    private K key;
    private V value;

    public Pair(K key, V value) {
        this.key   = key;
        this.value = value;
    }

    public Pair(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    }

    public K getKey() {
        return key;
    }

    public V getValue() {
        return value;
    }

    public K setKey(K key) {
        K oldKey = this.key;
        this.key = key;
        return oldKey;
    }

    public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    }

    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    public int hashCode() {
        return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
    }

    public String toString() {
        return key + "=" + value;
    }

    private static boolean eq(Object o1, Object o2) {
        return o1 == null ? o2 == null : o1.equals(o2);
    }
} Pair private static final long serialVersionUID = -8499721149061103585L; serialVersionUID -8499721149061103585L 8499721149061103585L private K key; key private V value; value public Pair(K key, V value) {
        this.key   = key;
        this.value = value;
    } Pair {
        this.key   = key;
        this.value = value;
    } this.key   = key this.key this this.key key this.value = value this.value this this.value value K key key V value value public Pair(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    } Pair {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    } this.key   = entry.getKey() this.key this this.key entry.getKey() entry.getKey entry this.value = entry.getValue() this.value this this.value entry.getValue() entry.getValue entry Entry<? extends K, ? extends V> entry entry public K getKey() {
        return key;
    } getKey {
        return key;
    } return key; key public V getValue() {
        return value;
    } getValue {
        return value;
    } return value; value public K setKey(K key) {
        K oldKey = this.key;
        this.key = key;
        return oldKey;
    } setKey {
        K oldKey = this.key;
        this.key = key;
        return oldKey;
    } K oldKey = this.key; oldKey this.key this this.key this.key = key this.key this this.key key return oldKey; oldKey K key key public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    } setValue {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    } V oldValue = this.value; oldValue this.value this this.value this.value = value this.value this this.value value return oldValue; oldValue V value value public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    } equals {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    } if (!(o instanceof Map.Entry))
            return false; !(o instanceof Map.Entry) (o instanceof Map.Entry) o Map.Entry return false; false Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; e (Map.Entry<?, ?>) o return eq(key, e.getKey()) && eq(value, e.getValue()); eq(key, e.getKey()) && eq(value, e.getValue()) eq(key, e.getKey()) eq key e.getKey() e.getKey e eq(value, e.getValue()) eq value e.getValue() e.getValue e Object o o public int hashCode() {
        return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
    } hashCode {
        return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
    } return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()); (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()) (key == null ? 0 : key.hashCode()) key == null key null 0 key.hashCode() key.hashCode key (value == null ? 0 : value.hashCode()) value == null value null 0 value.hashCode() value.hashCode value public String toString() {
        return key + "=" + value;
    } toString {
        return key + "=" + value;
    } return key + "=" + value; key + "=" + value key + "=" + value key "=" value private static boolean eq(Object o1, Object o2) {
        return o1 == null ? o2 == null : o1.equals(o2);
    } eq {
        return o1 == null ? o2 == null : o1.equals(o2);
    } return o1 == null ? o2 == null : o1.equals(o2); o1 == null ? o2 == null : o1.equals(o2) o1 == null o1 null o2 == null o2 null o1.equals(o2) o1.equals o1 o2 Object o1 o1 Object o2 o2 Entry Serializable public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    }
} Main
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int result = 0;
            // String s = sc.next();
            // String ? = sc.next();

            int n = sc.nextInt();
            int d = sc.nextInt();
            // int b = sc.nextInt();

            ArrayList<ArrayList<Integer>> x = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                x.add((ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, d));
            }
            // ArrayList<Integer> ? = (ArrayList<Integer>) ChenAtCoderUtil.nScan(sc, m);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, n);
            // LinkedList<Integer> ? = (LinkedList<Integer>) ChenAtCoderUtil.nScan(sc, m);

            // Pair<ArrayList<Integer>, ArrayList<Integer>> pair = ChenAtCoderUtil.nScanPair(sc, m);
            // ArrayList<Integer> ? = pair.getKey();
            // ArrayList<Integer> ? = pair.getValue();

            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    int sum = 0;
                    for (int k = 0; k < d; k++) {
                        sum += Math.pow(x.get(i).get(k) - x.get(j).get(k),2);
                    }
                    double s = Math.sqrt(sum);
                    if (s % 1 == 0) result++;
                }
            }
            return result/2;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenAtCoderUtil {
    static Collection<Integer> nScan(Scanner sc, int n) {
        Collection<Integer>al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    static Pair<ArrayList<Integer>, ArrayList<Integer>> nScanPair(Scanner sc, int n) {
        Pair<ArrayList<Integer>, ArrayList<Integer>> al = new Pair<>(new ArrayList<>(), new ArrayList<>());
        for (int i = 0; i < n; i++) {
            al.getKey().add(sc.nextInt());
            al.getValue().add(sc.nextInt());
        }
        return al;
    }
}

class Pair<K, V> implements Entry<K, V>, java.io.Serializable {
    private static final long serialVersionUID = -8499721149061103585L;

    private K key;
    private V value;

    public Pair(K key, V value) {
        this.key   = key;
        this.value = value;
    }

    public Pair(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    }

    public K getKey() {
        return key;
    }

    public V getValue() {
        return value;
    }

    public K setKey(K key) {
        K oldKey = this.key;
        this.key = key;
        return oldKey;
    }

    public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    }

    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    public int hashCode() {
        return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
    }

    public String toString() {
        return key + "=" + value;
    }

    private static boolean eq(Object o1, Object o2) {
        return o1 == null ? o2 == null : o1.equals(o2);
    }
}