Problem p03006 (python)

Fixed submission:
from collections import (
    Counter,
)


def input_ints():
    return list(map(int, input().strip().split()))


def _main():
    n = input_ints()[0]
    xy = [input_ints() for _ in range(n)]

    if len(xy) == 1:
        print(1)
        return

    (_, count), = Counter(
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ).most_common(1)

    print(len(xy) - count)


if __name__ == '__main__':
    _main()

Buggy submission (verdict: Runtime Error):
import logging
import unittest
from collections import (
    Counter,
)

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


def _main():
    n = input_ints()[0]
    xy = [input_ints() for _ in range(n)]

    (_, count), = Counter(
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ).most_common(1)

    print(len(xy) - count)


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Buggy submission (verdict: Runtime Error):
import logging
import unittest
from collections import (
    Counter,
)

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


def _main():
    n, = input_ints()
    xy = [input_ints() for _ in range(n)]

    (_, count), = Counter(
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ).most_common(1)

    print(len(xy) - count)


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Buggy submission (verdict: Runtime Error):
import functools as ft
import logging
import unittest
from collections import (
    namedtuple,
    Counter,
)
from heapq import (
    heappush,
    heappop,
)

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


@ft.total_ordering
class PrioritizedItem(namedtuple('PrioritizedItem', 'priority, value')):
    def __lt__(self, other):
        return self.priority < other.priority


def a_star(succ, cost, heuristic, start):
    cost_dict = {start: (heuristic(start), 0)}
    prev_dict = {}
    close = set()
    q = [PrioritizedItem(cost_dict[start], start)]

    while q:
        cost_u, u = heappop(q)
        if u not in close and cost_u <= cost_dict[u]:
            close.add(u)

            yield u, prev_dict, cost_dict

            for v in succ(u):
                cost_uv = cost(u, v)
                heuristic_v = heuristic(v)

                cost_v_old = cost_dict.get(v)
                cost_v_new = (
                    cost_u[1] + cost_uv + heuristic_v,
                    cost_u[1] + cost_uv,
                )
                if cost_v_old is None or cost_v_new < cost_v_old:
                    cost_dict[v] = cost_v_new
                    prev_dict[v] = u
                    heappush(q, PrioritizedItem(cost_v_new, v))
                    try:
                        close.remove(v)
                    except KeyError:
                        pass


def _main():
    n, = input_ints()
    xy = [tuple(input_ints()) for _ in range(n)]

    pq = [
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ]
    pq_counter = Counter(pq)

    ans = []
    for p, q in sorted(pq_counter, key=pq_counter.get)[::-1]:
        ans.append(len(xy) - pq_counter[p, q])

    print(min(ans))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Buggy submission (verdict: Runtime Error):
import functools as ft
import logging
import unittest
from collections import (
    namedtuple,
    Counter,
)
from heapq import (
    heappush,
    heappop,
)

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


@ft.total_ordering
class PrioritizedItem(namedtuple('PrioritizedItem', 'priority, value')):
    def __lt__(self, other):
        return self.priority < other.priority


def a_star(succ, cost, heuristic, start):
    cost_dict = {start: (heuristic(start), 0)}
    prev_dict = {}
    close = set()
    q = [PrioritizedItem(cost_dict[start], start)]

    while q:
        cost_u, u = heappop(q)
        if u not in close and cost_u <= cost_dict[u]:
            close.add(u)

            yield u, prev_dict, cost_dict

            for v in succ(u):
                cost_uv = cost(u, v)
                heuristic_v = heuristic(v)

                cost_v_old = cost_dict.get(v)
                cost_v_new = (
                    cost_u[1] + cost_uv + heuristic_v,
                    cost_u[1] + cost_uv,
                )
                if cost_v_old is None or cost_v_new < cost_v_old:
                    cost_dict[v] = cost_v_new
                    prev_dict[v] = u
                    heappush(q, PrioritizedItem(cost_v_new, v))
                    try:
                        close.remove(v)
                    except KeyError:
                        pass


def _main():
    n, = input_ints()
    xy = [tuple(input_ints()) for _ in range(n)]

    pq = [
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ]
    pq_counter = Counter(pq)

    ans = []
    for p, q in sorted(pq_counter, key=pq_counter.get)[::-1]:
        result = a_star(
            succ=lambda u: [u + (xy_,) for xy_ in xy],
            cost=lambda u, v: int(
                v[-1][0] - u[-1][0] != p
                or v[-1][1] - u[-1][1] != q
            ),
            heuristic=lambda u: 0,
            start=((float('inf'),) * 2,),
        )
        tail, prev_dict, cost_dict = (None,) * 3
        for tail, prev_dict, cost_dict in result:
            if len(tail) > len(xy):
                break
        ans.append(cost_dict[tail][0])
        debug([len(xy), pq_counter[p, q], ans[-1]])
        if len(xy) - pq_counter[p, q] == ans[-1]:
            break

    print(min(ans))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Buggy submission (verdict: Runtime Error):
import functools as ft
import logging
import unittest
from collections import (
    namedtuple,
)
from heapq import (
    heappush,
    heappop,
)

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


@ft.total_ordering
class PrioritizedItem(namedtuple('PrioritizedItem', 'priority, value')):
    def __lt__(self, other):
        return self.priority < other.priority


def a_star(succ, cost, heuristic, start):
    cost_dict = {start: (heuristic(start), 0)}
    prev_dict = {}
    close = set()
    q = [PrioritizedItem(cost_dict[start], start)]

    while q:
        cost_u, u = heappop(q)
        if u not in close and cost_u <= cost_dict[u]:
            close.add(u)

            yield u, prev_dict, cost_dict

            for v in succ(u):
                cost_uv = cost(u, v)
                heuristic_v = heuristic(v)

                cost_v_old = cost_dict.get(v)
                cost_v_new = (
                    cost_u[1] + cost_uv + heuristic_v,
                    cost_u[1] + cost_uv,
                )
                if cost_v_old is None or cost_v_new < cost_v_old:
                    cost_dict[v] = cost_v_new
                    prev_dict[v] = u
                    heappush(q, PrioritizedItem(cost_v_new, v))
                    try:
                        close.remove(v)
                    except KeyError:
                        pass


def _main():
    n, = input_ints()
    xy = [tuple(input_ints()) for _ in range(n)]

    pq = [
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ]

    ans = []
    for p, q in pq:
        result = a_star(
            succ=lambda u: [u + (xy_,) for xy_ in xy],
            cost=lambda u, v: int(
                v[-1][0] - u[-1][0] != p or v[-1][1] - u[-1][1] != q),
            heuristic=lambda u: 0,
            start=((float('inf'),) * 2,),
        )
        tail, prev_dict, cost_dict = (None,) * 3
        for tail, prev_dict, cost_dict in result:
            if len(tail) > len(xy):
                break
        ans.append(cost_dict[tail][0])

    print(min(ans))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()