Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

if len(S) == 1:
    print(0)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
    else:
        j = 0

print(c*K+j*(K-1))
# print(c, j)


Fixed submission:
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    S2 = S*2
    d = 0
    flg = False
    for i in range(len(S2)-1):
        if S2[i] == S2[i+1] and flg is False:
            d += 1
            flg = True
        else:
            flg = False

    ar = 0
    if c*2 != d:
        ar = 1

    if ar == 1:
        print((c+1)*K-1)
    else:
        print(c*K)
Buggy python submission (verdict: Time Limit Exceeded):
# import math


def trial_division(n):
    # 素因数を格納するリスト
    factor = set()
    # 2から√n以下の数字で割っていく
    # tmp = int(math.sqrt(n)) + 1
    for num in range(2, n+1):
        while n % num == 0:
            n //= num
            factor.add(num)
    # リストが空ならそれは素数
    if not factor:
        return set((1, n))
    else:
        factor.add(n)
        return factor


A, B = map(int, input().split())
# print(trial_division(A))
# print(trial_division(B))
print(len(trial_division(A) & trial_division(B)))


Fixed submission:
import math


def trial_division(n):
    # 素因数を格納するリスト
    factor = set()
    # 2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor.add(num)
    # リストが空ならそれは素数
    if not factor:
        return set((1, n))
    else:
        factor.add(n)
        factor.add(1)
        return factor


A, B = map(int, input().split())
# print(trial_division(A))
# print(trial_division(B))
print(len(trial_division(A) & trial_division(B)))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

dp = [[10**10 for B in range(1 << N)] for i in range(M+1)]
dp[0][0] = 0

for i in range(M):
    a, b = map(int, input().split())
    c = [int(j) for j in input().split()]
    C = sum([1 << (x-1) for x in c])

    for B in range(1 << N):
        dp[i+1][B] = min(dp[i][B], dp[i+1][B])
        dp[i+1][B | C] = min(dp[i+1][B | C], dp[i][B]+a)

if dp[M][(1 << N)-1] == 10**10:
    print(-1)
else:
    print(dp[M][(1 << N)-1])


Fixed submission:
N, M = map(int, input().split())
# print(N)

# DPテーブルを初期化
dp = [10**9] * 2**(N+1)  # dp[010100011010]: 状態010100011010に到達するための最小コスト
dp[0] = 0

# ループを回す
for i in range(M):
    a, b = map(int, input().split())
    c = [int(i) for i in input().split()]

    bit = 0
    for cb in c:
        bit += 2**(cb-1)

    for fromb in range(2**N):
        dp[fromb | bit] = min(dp[fromb | bit], dp[fromb]+a)

if dp[2**N-1] == 10**9:
    print(-1)
else:
    print(dp[2**N-1])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
# print(N)

# DPテーブルを初期化
dp = [10**9] * ((2**N) + 30)  # dp[010100011010]: 状態010100011010に到達するための最小コスト
dp[0] = 0

# ループを回す
for i in range(M):
    a, b = map(int, input().split())
    c = [int(i) for i in input().split()]

    bit = 0
    for cb in c:
        bit += 2**(cb-1)

    for fromb in range(2**N+1):
        dp[fromb | bit] = min(dp[fromb | bit], dp[fromb]+a)

if dp[2**N-1] == 10**9:
    print(-1)
else:
    print(dp[2**N-1])


Fixed submission:
N, M = map(int, input().split())
# print(N)

# DPテーブルを初期化
dp = [10**9] * 2**(N+1)  # dp[010100011010]: 状態010100011010に到達するための最小コスト
dp[0] = 0

# ループを回す
for i in range(M):
    a, b = map(int, input().split())
    c = [int(i) for i in input().split()]

    bit = 0
    for cb in c:
        bit += 2**(cb-1)

    for fromb in range(2**N):
        dp[fromb | bit] = min(dp[fromb | bit], dp[fromb]+a)

if dp[2**N-1] == 10**9:
    print(-1)
else:
    print(dp[2**N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()


def LCSubStr(X, Y, m, n):

    # Create a table to store lengths of
    # longest common suffixes of substrings.
    # Note that LCSuff[i][j] contains the
    # length of longest common suffix of
    # X[0...i-1] and Y[0...j-1]. The first
    # row and first column entries have no
    # logical meaning, they are used only
    # for simplicity of the program.

    # LCSuff is the table with zero
    # value initially in each cell
    LCSuff = [[0 for k in range(n+1)] for l in range(m+1)]

    # To store the length of
    # longest common substring
    result = 0

    # Following steps to build
    # LCSuff[m+1][n+1] in bottom up fashion
    for i in range(m + 1):
        for j in range(n + 1):
            if (i == 0 or j == 0):
                LCSuff[i][j] = 0
            elif (X[i-1] == Y[j-1]):
                LCSuff[i][j] = LCSuff[i-1][j-1] + 1
                result = max(result, LCSuff[i][j])
            else:
                LCSuff[i][j] = 0
    return result


ans = 0
for i in range(1, N):
    ls = LCSubStr(S[:i], S[i:], i, N-i)
    ans = max(ans, ls)
    # if len(ls) > ans:
    #     ans = len(ls)


print(ans)


Fixed submission:
n = int(input())
s = input()
ans = 0
for d in range(1, n):
    count = 0
    for i in range(n-d):
        if s[i] == s[i+d]:
            count += 1
        else:
            count = 0
        ans = max(min(count, d), ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()


def long_substr(data):
    substr = ''
    if len(data) > 1 and len(data[0]) > 0:
        for i in range(len(data[0])):
            for j in range(len(data[0])-i+1):
                if j > len(substr) and is_substr(data[0][i:i+j], data):
                    substr = data[0][i:i+j]
    return substr


def is_substr(find, data):
    if len(data) < 1 and len(find) < 1:
        return False
    for i in range(len(data)):
        if find not in data[i]:
            return False
    return True


ans = 0
for i in range(1, N):
    ls = long_substr([S[:i], S[i:]])
    # print(ls)
    if len(ls) > ans:
        ans = len(ls)


print(ans)


Fixed submission:
n = int(input())
s = input()
ans = 0
for d in range(1, n):
    count = 0
    for i in range(n-d):
        if s[i] == s[i+d]:
            count += 1
        else:
            count = 0
        ans = max(min(count, d), ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

MOD = 10**9 + 7

ans = 0
for i in range(N):
    for j in range(N):
        l, r = 0, 0
        if A[i] > A[j] and i < j:
            l += 1
        if A[i] > A[j] and i > j:
            r += 1
        ans += (1+K)*K//2*l
        ans += K*(K-1)//2*r
        ans %= MOD

print(ans)


Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

MOD = 10**9 + 7

ans = 0
for i in range(N):
    for j in range(N):
        l, r = 0, 0
        if A[i] > A[j] and i < j:
            l += 1
        if A[i] > A[j] and i > j:
            r += 1
        ans += (1+K)*K//2*l
        ans += K*(K-1)//2*r
        ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())

ab = []
for i in range(N-1):
    a, b = map(int, input().split())
    ab.append((a, b))
ab = sorted(ab, key=lambda x: (x[0], x[1]))

P = [0 for _ in range(N)]  # 0-indexed
for i in range(Q):
    p, x = map(int, input().split())
    P[p-1] += x

for i in range(N-1):
    a, b = ab[i]
    P[b-1] += P[a-1]

print(*P)


Fixed submission:
N, Q = map(int, input().split())

ab = []
for i in range(N-1):
    a, b = map(int, input().split())
    ab.append((a, b))
ab = sorted(ab, key=lambda x: x[0])

P = [0 for _ in range(N)]  # 0-indexed
for i in range(Q):
    p, x = map(int, input().split())
    P[p-1] += x

for i in range(N-1):
    a, b = ab[i]
    P[b-1] += P[a-1]

print(*P)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [-1]*(len(t)+1)
dp[0] = 0

for p in range(len(t)):
    d = s[dp[p] % len(s):].find(t[p])
    if d >= 0:
        dp[p+1] = dp[p]+d+1
    else:
        d = s[:dp[p] % len(s)].find(t[p])
        if d >= 0:
            dp[p+1] = dp[p]+d+1+len(s[dp[p] % len(s):])
        else:
            print(-1)
            exit()

print(dp[len(t)])


Fixed submission:
import bisect
from collections import defaultdict

S = input()
T = input()

if set(T) - set(S) != set():
    print(-1)
    exit()

d = defaultdict(list)
l = [0 for _ in range(26)]

for i, v in enumerate(S, 1):
    l[ord(v)-ord('a')] += 1
    d[v].append(i)

len_S = len(S)

# print(l)

ans = 0
c = 0
for t in T:
    i = bisect.bisect_left(d[t], c)
    # print(l[ord(t)-ord('a')])
    if i < l[ord(t)-ord('a')]:
        ans += d[t][i]-c+1
        c = d[t][i]+1
        # print(d[t][i])
    else:
        # print(ans, len_S, c, d[t][0])
        ans += len_S-c+d[t][0]+1
        c = d[t][0]+1
    # print(ans)

if ans > 10**100*len_S:
    print(-1)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [-1]*(len(t)+1)
dp[0] = 0

for p in range(len(t)):
    sd = s[dp[p] % len(s):]+s[:dp[p] % len(s)]
    d = sd.find(t[p])+1
    if d >= 1:
        dp[p+1] = dp[p]+d
    else:
        print(-1)
        exit()

print(dp[len(t)])


Fixed submission:
import bisect
from collections import defaultdict

S = input()
T = input()

if set(T) - set(S) != set():
    print(-1)
    exit()

d = defaultdict(list)
l = [0 for _ in range(26)]

for i, v in enumerate(S, 1):
    l[ord(v)-ord('a')] += 1
    d[v].append(i)

len_S = len(S)

# print(l)

ans = 0
c = 0
for t in T:
    i = bisect.bisect_left(d[t], c)
    # print(l[ord(t)-ord('a')])
    if i < l[ord(t)-ord('a')]:
        ans += d[t][i]-c+1
        c = d[t][i]+1
        # print(d[t][i])
    else:
        # print(ans, len_S, c, d[t][0])
        ans += len_S-c+d[t][0]+1
        c = d[t][0]+1
    # print(ans)

if ans > 10**100*len_S:
    print(-1)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [-1]*(len(t)+1)
dp[0] = 0

for p in range(len(t)):
    sd = s[dp[p] % len(s):]+s[:dp[p] % len(s)]
    d = sd.find(t[p])+1
    if d >= 1:
        dp[p+1] = dp[p]+d
    else:
        print(-1)
        exit()

print(dp[len(t)])


Fixed submission:
import bisect
from collections import defaultdict

S = input()
T = input()

if set(T) - set(S) != set():
    print(-1)
    exit()

d = defaultdict(list)
l = [0 for _ in range(26)]

for i, v in enumerate(S, 1):
    l[ord(v)-ord('a')] += 1
    d[v].append(i)

len_S = len(S)

# print(l)

ans = 0
c = 0
for t in T:
    i = bisect.bisect_left(d[t], c)
    # print(l[ord(t)-ord('a')])
    if i < l[ord(t)-ord('a')]:
        ans += d[t][i]-c+1
        c = d[t][i]+1
        # print(d[t][i])
    else:
        # print(ans, len_S, c, d[t][0])
        ans += len_S-c+d[t][0]+1
        c = d[t][0]+1
    # print(ans)

if ans > 10**100*len_S:
    print(-1)
else:
    print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N, M = map(int, input().split())

d = defaultdict(list)

for _ in range(N):
    A, B = map(int, input().split())
    d[A].append(B)

works = []
for k in range(M, 0, -1):
    d[k] = sorted(d[k], reverse=True)
    if M-k+1 >= 1:
        works.extend(d[k][:M-k+1])
        works = sorted(works, reverse=True)
        works = works[:M-k+1]
        # print(works)

works = sorted(works, reverse=True)

print(sum(works[:M]))


Fixed submission:
# from collections import defaultdict
import heapq
N, M = map(int, input().split())

W = []
for _ in range(N):
    W.append(tuple(map(int, input().split())))
W = sorted(W, key=lambda x: (x[0], -x[1]))


a = []
heapq.heapify(a)  # リストaのheap化

ans = 0
c = 0
for day in range(1, M+1):
    day_c = 0
    while c != N and W[c][0] == day:
        if day_c <= M-day:
            x = W[c][1]
            heapq.heappush(a, -x)  # heap化されたリストaに要素xを追加
            day_c += 1
        c += 1
    if len(a) >= 1:
        ans += -heapq.heappop(a)  # heap化されたリストaから最小値を削除＆その最小値を出力

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

sA = sum(A)


def trial_division(n):
    # 素因数を格納するリスト
    factor = []
    # 2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    # リストが空ならそれは素数
    if not factor:
        return 'prime number'
    else:
        factor.append(n)
        return factor


lst = sorted(trial_division(sum(A)))

n = len(lst)
for i in range((2 ** n)-1, 0, -1):
    c = 1
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            c *= lst[j]  # フラグが立っていたら bag に果物を詰める

    cnt = 0
    for a in A:
        cnt += min(a % c, c-(a % c))
    if cnt//2 <= K:
        print(c)
        exit()

print(1)


Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors


lst = make_divisors(sum(A))

for l in lst:
    cnt_m, cnt_p = 0, 0
    ml = sorted([i % l for i in A])
    for m in ml:
        if cnt_m <= K-m:
            cnt_m += m
        else:
            cnt_p += l-m
    if cnt_m <= K and cnt_p <= K:
        print(l)
        exit()
print(1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


ans = []
c = 0
for i in range(N, 0, -1):
    if A[i-1] % 2 == 1:
        c += 1
        ans.append(i)
        for j in make_divisors(i):
            A[j-1] += 1
print(c)
if c != 0:
    print(*ans[::-1])


Fixed submission:


from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]

d = defaultdict(int)
# balls = [0 for _ in range(N)]

ans = 0
for n in range(N, 0, -1):
    a_i = a[n-1]
    cnt = 0
    n2 = n*2
    while n2 <= N:
        cnt += d[n2]
        n2 += n
    if cnt % 2 != a_i:
        d[n] = 1
        ans += 1

print(ans)
if ans >= 1:
    for k, v in d.items():
        if v == 1:
            print(k)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

ans = []
for n in range(N, 0, -1):
    a_i = a[n-1]
    cnt = 0
    n2 = n*2
    while n2 <= N:
        if n2 in ans:
            cnt += 1
        n2 += n
    if cnt % 2 != a_i:
        ans.append(n)

print(len(ans))
if len(ans) != 0:
    print(*ans)


Fixed submission:


from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]

d = defaultdict(int)
# balls = [0 for _ in range(N)]

ans = 0
for n in range(N, 0, -1):
    a_i = a[n-1]
    cnt = 0
    n2 = n*2
    while n2 <= N:
        cnt += d[n2]
        n2 += n
    if cnt % 2 != a_i:
        d[n] = 1
        ans += 1

print(ans)
if ans >= 1:
    for k, v in d.items():
        if v == 1:
            print(k)
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
A = [int(i) for i in input().split()]


if N % 3 != 0:
    print('No')
    exit()

c = collections.Counter(A)

for v in c.values():
    if v % (N//3) != 0:
        print('No')
        exit()


if len(c) == 1 and c.most_common()[0][0] == 0:
    print('Yes')
    exit()
elif len(c) == 2 and c.most_common()[1][0] == 0 and c.most_common()[0][0] ^ 0 == c.most_common[0]:
    print('Yes')
    exit()
elif len(c) == 3 and \
        (c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0]) == 0:
    print('Yes')
    exit()


else:
    print('No')
    exit()


Fixed submission:
import collections
N = int(input())
A = [int(i) for i in input().split()]

if set(A) == {0}:
    print('Yes')
    exit()


if N % 3 != 0:
    print('No')
    exit()

c = collections.Counter(A)

for v in c.values():
    if v % (N//3) != 0:
        print('No')
        exit()


if len(c) == 2 and c.most_common()[1][0] == 0 and c.most_common()[0][0] ^ 0 == c.most_common()[0][0]:
    print('Yes')
    exit()
elif len(c) == 3 and \
        (c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0]) == 0:
    print('Yes')
    exit()


else:
    print('No')

Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
A = [int(i) for i in input().split()]


if N % 3 != 0:
    print('No')
    exit()

c = collections.Counter(A)
# print(len(c))
# print(c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0])

for v in c.values():
    # print(v)
    if v % (N//3) != 0:
        print('No')
        exit()


if len(c) == 1 and c.most_common[0] == 0:
    print('Yes')
    exit()
elif len(c) == 2 and c.most_common()[1][0] == 0 and c.most_common()[0][0] ^ 0 == c.most_common[0]:
    print('Yes')
    exit()
elif len(c) == 3 and \
        (c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0]) == 0:
    print('Yes')
    exit()


else:
    print('No')
    exit()


Fixed submission:
import collections
N = int(input())
A = [int(i) for i in input().split()]

if set(A) == {0}:
    print('Yes')
    exit()


if N % 3 != 0:
    print('No')
    exit()

c = collections.Counter(A)

for v in c.values():
    if v % (N//3) != 0:
        print('No')
        exit()


if len(c) == 2 and c.most_common()[1][0] == 0 and c.most_common()[0][0] ^ 0 == c.most_common()[0][0]:
    print('Yes')
    exit()
elif len(c) == 3 and \
        (c.most_common()[0][0] ^ c.most_common()[1][0] ^ c.most_common()[2][0]) == 0:
    print('Yes')
    exit()


else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math


def distribute(i):
    ls = []
    for t in itertools.combinations_with_replacement(range(1, K+1), i):
        # print(t)
        if sum(t) == K:
            ls.append(t)
    return ls


N, K = map(int, input().split())

for i in range(1, K+1):
    ans = 0
    ls = distribute(i)
    # print(ls)
    for ls_e in ls:
        # print(ls_e)
        c = 1
        for j in range(i):
            if N-K+1-j >= 1:
                c *= N-K+1-j
        # print(ls_e, c)
        for lsn in range(min(ls_e), max(ls_e)+1):
            if ls_e.count(lsn) >= 1:
                c //= math.factorial(ls_e.count(lsn))
        ans += c
    print(ans%(10**9+7))


Fixed submission:
from scipy.misc import comb
mod = 1000000007

N,K=map(int,input().split())

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
    else:
        print(comb(N-K+1,i,exact=True)*comb(K-1,i-1,exact=True)%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math


def distribute(i):
    ls = []
    for t in itertools.combinations_with_replacement(range(1, K+1), i):
        # print(t)
        if sum(t) == K:
            ls.append(t)
    return ls


N, K = map(int, input().split())

for i in range(1, K+1):
    ans = 0
    ls = distribute(i)
    # print(ls)
    for ls_e in ls:
        # print(ls_e)
        c = 1
        for j in range(i):
            if N-K+1-j >= 1:
                c *= N-K+1-j
        # print(ls_e, c)
        for lsn in range(min(ls_e), max(ls_e)+1):
            if ls_e.count(lsn) >= 1:
                c //= math.factorial(ls_e.count(lsn))
        ans += c
    print(ans%(10**9+7))


Fixed submission:
from scipy.misc import comb
mod = 1000000007

N,K=map(int,input().split())

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
    else:
        print(comb(N-K+1,i,exact=True)*comb(K-1,i-1,exact=True)%mod)
Buggy python submission (verdict: Runtime Error):
S=input()
if S[0]==S[1] or S[1]==S[2] or S[3]==S[4]:
    print('Bad')
else:
    print('Good')

Fixed submission:
S=input()
if S[0]==S[1] or S[1]==S[2] or S[2]==S[3]:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Runtime Error):
W,H,x,y=map(int,input().split())

print(W*H/2, 1 if W=2*x and H=2*y else 0)

Fixed submission:
W,H,x,y=map(int,input().split())

print(W*H/2, 1 if W==2*x and H==2*y else 0)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())

xy = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p, q = (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        d[(p, q)] += 1

print(N-max(d.values()))


Fixed submission:
from collections import defaultdict
N = int(input())

if N == 1:
    print(1)
    exit()

xy = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p, q = (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        d[(p, q)] += 1

print(N-max(d.values()))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())

xy = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p, q = (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        d[(p, q)] += 1

print(N-max(d.values()))


Fixed submission:
from collections import defaultdict
N = int(input())

if N == 1:
    print(1)
    exit()

xy = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p, q = (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        d[(p, q)] += 1

print(N-max(d.values()))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted([int(i) for i in input().split()])

M = 0
ans = []

if A[0] >= 0:
    ans.append((A[0], A[-1]))
    M = A[0]-A[-1]
    for i in range(1, N-1):
        if i != N-2:
            ans.append((M, A[i]))
            M -= A[i]
        else:
            ans.append((A[i], M))
            M = A[i]-M
elif A[-1] < 0:
    ans.append((A[0], A[-1]))
    M = A[0]-A[-1]
    for i in range(1, N-1):
        ans.append(M, A[i])
        M -= A[i]
else:
    exit()

print(M)
for t in ans:
    print(*t)


Fixed submission:
import bisect

N = int(input())
A = sorted([int(i) for i in input().split()])

zp = bisect.bisect_left(A, 0)
ans = []

M = A[0]
for i in range(max(zp, 1), N-1):
    ans.append((M, A[i]))
    M -= A[i]

ans.append((A[N-1], M))
M = A[N-1]-M

for i in range(1, min(zp, N-1)):
    ans.append((M, A[i]))
    M -= A[i]


print(M)
for a, b in ans:
    print(a, b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted([int(i) for i in input().split()])

M = 0
ans = []

if A[0] >= 0:
    ans.append((A[0], A[-1]))
    M = A[0]-A[-1]
    for i in range(1, N-1):
        if i != N-2:
            ans.append((M, A[i]))
            M -= A[i]
        else:
            ans.append((A[i], M))
            M = A[i]-M
elif A[-1] < 0:
    ans.append((A[0], A[-1]))
    M = A[0]-A[-1]
    for i in range(1, N-1):
        ans.append(M, A[i])
        M -= A[i]
else:
    exit()


Fixed submission:
import bisect

N = int(input())
A = sorted([int(i) for i in input().split()])

zp = bisect.bisect_left(A, 0)
ans = []

M = A[0]
for i in range(max(zp, 1), N-1):
    ans.append((M, A[i]))
    M -= A[i]

ans.append((A[N-1], M))
M = A[N-1]-M

for i in range(1, min(zp, N-1)):
    ans.append((M, A[i]))
    M -= A[i]


print(M)
for a, b in ans:
    print(a, b)