Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cnt = 0

fir_num = nums[0]

del nums[0]

for i in range(n-2):
    fir_num += nums[0]
    cnt += 1
    if cnt == 2:
        del nums[0]
        cnt = 0

print(fir_num)









Fixed submission:
n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cnt = 0

fir_num = nums[0]

del nums[0]

for i in range(n-2):
    fir_num += nums[int(i/2)]


print(fir_num)

Buggy python submission (verdict: Runtime Error):
nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cf = nums[0]

for i in range(2, n):
    nums_min = min(nums[i-1], nums[i-2])
    cf += nums_min

print(cf)




Fixed submission:
n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cnt = 0

fir_num = nums[0]

del nums[0]

for i in range(n-2):
    fir_num += nums[int(i/2)]


print(fir_num)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
LA = len(A)
ans = A[0]
for i in range(LA-1):
    ans = ans*A[i+1]
if ans > 10**18:
    print('-1')
else:
    print(ans)



Fixed submission:
import sys

N = int(input())
A = list(map(int, input().split()))
LA = len(A)
ans = A[0]
for j in range(LA):
    if A[j] == 0:
        print('0')
        sys.exit()

for i in range(LA-1):
    ans = ans*A[i+1]
    if ans > 10**18:
        print('-1')
        sys.exit()
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import operator
from functools import reduce


def prime_factorize(n, divs):
    """素因数分解する。"""

    ans = defaultdict(int)
    for fac in divs:
        while n % fac == 0:
            ans[fac] += 1
            n //= fac
        if fac ** 2 > n:
            break
    if n != 1:
        ans[n] += 1
    return ans


def primes(n):
    """素因数分解する。"""
    def facs(n):
        """試し割り法における割る数を生成する。"""
        yield 2
        max_prime = int(pow(n, 0.5)) + 1
        for x in range(3, max_prime, 2):
            yield x

    nums = [1] * (n + 1)
    for i, fac in enumerate(nums):
        if i < 2:
            continue
        if fac == 0:
            continue
        for multi in range(i * 2, n + 1, i):
            nums[multi] = 0
    return [i for i, fac in enumerate(nums) if fac and i > 1]


def main():
    n = int(input())
    divs = primes(n)
    ans = 0
    for ab in range(1, n):
        prm = prime_factorize(ab, divs)
        tmp = reduce(operator.mul, (v+1 for v in prm.values()), 1)
        ans += tmp
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
def main():
    n = int(input())
    ab_max = n-1
    ans = sum(ab_max // a for a in range(1, n))
    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input()  # n
    array = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7
    ans = 0
    for i, ai in enumerate(array):
        for aj in array[i + 1:]:
            ans += ai * aj
            ans %= mod
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
from itertools import accumulate


def main():
    n = int(input())
    array = [int(x) for x in input().split()]
    acc = accumulate(array)
    mod = 10 ** 9 + 7
    ans = 0
    for i, ai in enumerate(acc):
        if i == n - 1:
            continue
        ans += ai * array[i + 1]
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input()  # n
    array = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7
    ans = 0
    for i, ai in enumerate(array):
        for aj in array[i + 1:]:
            ans += ai * aj
            ans %= mod
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
from itertools import accumulate


def main():
    n = int(input())
    array = [int(x) for x in input().split()]
    acc = accumulate(array)
    mod = 10 ** 9 + 7
    ans = 0
    for i, ai in enumerate(acc):
        if i == n - 1:
            continue
        ans += ai * array[i + 1]
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict


def main():
    people_count, info_count = [int(x) for x in input().split()]
    frieds_circle_ids = [-1] * people_count
    id_counter = defaultdict(int)
    new_id = 0
    for _ in range(info_count):
        a, b = [int(x) - 1 for x in input().split()]
        id_a = frieds_circle_ids[a]
        id_b = frieds_circle_ids[b]
        if id_a == -1 == id_b:
            frieds_circle_ids[a] = new_id
            frieds_circle_ids[b] = new_id
            id_counter[new_id] += 2
            new_id += 1
        elif id_a == -1:
            frieds_circle_ids[a] = id_b
            id_counter[id_b] += 1
        elif id_b == -1:
            frieds_circle_ids[b] = id_a
            id_counter[id_a] += 1
        else:
            pass
    return max(count for count in id_counter.values())


if __name__ == '__main__':
    print(main())


Fixed submission:
from collections import deque, defaultdict


def main():
    people_count, info_count = [int(x) for x in input().split()]
    if info_count == 0:
        return 1
    if info_count == 1:
        return 2

    friends = [set() for _ in range(people_count)]
    for _ in range(info_count):
        a, b = [int(x) - 1 for x in input().split()]
        friends[a].add(b)
        friends[b].add(a)
    seen = [False] * people_count
    circle_id = 0
    counter = defaultdict(int)
    for i, circle in enumerate(friends):
        if seen[i]:
            continue
        circle_id += 1
        qu = deque()
        qu.append(i)
        seen[i] == 1
        while qu:
            now = qu.popleft()
            for new in friends[now]:
                if seen[new]:
                    continue
                qu.append(new)
                seen[new] = True
                counter[circle_id] += 1
    return max(v for v in counter.values())


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
from collections import defaultdict


def facs(n):
    """試し割り法における割る数を生成する。"""
    yield 2
    for x in range(3, n, 2):
        yield x


def main():
    input()  # N
    array = [int(x) for x in input().split()]
    MAX_A = 10 ** 6 + 1
    histogram = defaultdict(int)
    for x in array:
        histogram[x] += 1

    for potential_prime in facs(MAX_A):
        count = sum(
            histogram[divider]
            for divider in range(potential_prime, MAX_A, potential_prime))
        if count > 1:
            break
    else:
        return 'pairwise coprime'

    gcd_total = reduce(gcd, array)
    if gcd_total == 1:
        return 'setwise coprime'
    else:
        return 'not coprime'


if __name__ == '__main__':
    print(main())


Fixed submission:
from math import gcd


def main():
    input()  # N
    array = [int(x) for x in input().split()]
    MAX_A = 10 ** 6 + 2
    histgram = [0] * MAX_A
    for x in array:
        histgram[int(x)] += 1
    pairwise = True
    for divider in range(2, MAX_A):
        count = 0
        for counted in histgram[divider::divider]:
            count += counted
        if count > 1:
            pairwise = False
    if pairwise:
        return 'pairwise coprime'
    gcd_now = 0
    for x in array:
        gcd_now = gcd(x, gcd_now)
    if gcd_now == 1:
        return 'setwise coprime'
    else:
        return 'not coprime'


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
def main():
    num = input()
    if num % 9 == 0:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
def main():
    num = input()
    total = 0
    for char in num:
        total += int(char)
        total %= 9
    if total == 0:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    ans = main()
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]
    scores_q = deque(scores)
    news = deque(scores[k:])
    former = 0
    rank = 1
    for score in scores[:k]:
        rank *= score

    for shift in range(n - k):
        former = rank
        remover = scores_q.popleft()
        new_commer = news.popleft()
        rank //= remover
        rank *= new_commer
        if former < rank:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]

    for remover, new_commer in zip(scores, scores[k:]):
        if remover < new_commer:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]
    former = 0
    rank = 1
    for score in scores[:k]:
        rank *= score

    for shift in range(n - k):
        former = rank
        rank //= scores[shift]
        rank *= scores[shift + k]
        if former < rank:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]

    for remover, new_commer in zip(scores, scores[k:]):
        if remover < new_commer:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
"""
(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)
"""
def func(x, y, z): return (x + y + z) ** 2 - x * y - y * z - z * x


def main():
    num = int(input())
    counter = [0] * (num + 1)
    # func(41, 41, 41) = 10086
    # func(99, 1, 1) = 10002
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 123 - x - y + 1):
                if (tmp := func(x, y, z)) <= num:
                    counter[tmp] += 1
    for count in counter[1:]:
        print(count)


if __name__ == '__main__':
    main()


Fixed submission:
"""
(x+y+z)^2 = (x^2+y^2+z^2) + 2(xy+yz+zx)
"""
def func(x, y, z): return (x + y + z) ** 2 - x * y - y * z - z * x


def main():
    num = int(input())
    counter = [0] * 20000
    # func(41, 41, 41) = 10086
    # func(99, 1, 1) = 10002
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 123 - x - y + 1):
                tmp = func(x, y, z)
                counter[tmp] += 1
    for key, count in enumerate(counter):
        if key == 0:
            continue
        if key > num:
            break
        print(count)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
import math


def main():
    n = int(input())
    digits = deque()
    alpha = ord('a') - 1
    maxex = int(math.log(n-1, 26))
    ex = 1
    zflag = False
    for ex in range(1, maxex + 2):
        bb = pow(26, ex - 1)
        aa = bb * 26
        rem = n % aa // bb
        n -= bb * rem
        if rem == 0:
            if n == 0:
                break
            rem += 26
            n -= aa
        digits.appendleft(chr(alpha + rem))

    [print(d, end='') for d in digits]
    print()


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque
import math


def main():
    n = int(input())
    if n == 1:
        print('a')
        return
    digits = deque()
    alpha = ord('a') - 1
    maxex = int(math.log(n-1, 26))
    ex = 1
    for ex in range(1, maxex + 2):
        bb = pow(26, ex - 1)
        aa = bb * 26
        rem = n % aa // bb
        n -= bb * rem
        if rem == 0:
            if n == 0:
                break
            rem += 26
            n -= aa
        digits.appendleft(chr(alpha + rem))

    [print(d, end='') for d in digits]
    print()


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from collections import deque
import math


def main():
    n = int(input())
    digits = deque()
    alpha = ord('a') - 1
    maxex = int(math.log(n, 27))
    ex = 1
    for ex in range(1, maxex + 2):
        bb = pow(26, ex - 1)
        aa = bb * 26
        rem = n % aa // bb
        n -= bb * rem
        digits.appendleft(alpha + rem)
    if n != 0:
        digits.appendleft(alpha + n)

    [print(chr(d), end='') for d in digits]
    print()


if __name__ == '__main__':
    main()


Fixed submission:
from collections import deque
import math


def main():
    n = int(input())
    if n == 1:
        print('a')
        return
    digits = deque()
    alpha = ord('a') - 1
    maxex = int(math.log(n-1, 26))
    ex = 1
    for ex in range(1, maxex + 2):
        bb = pow(26, ex - 1)
        aa = bb * 26
        rem = n % aa // bb
        n -= bb * rem
        if rem == 0:
            if n == 0:
                break
            rem += 26
            n -= aa
        digits.appendleft(chr(alpha + rem))

    [print(d, end='') for d in digits]
    print()


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


def main():
    number = int(input())
    numcount = defaultdict(int)
    for x in input().split():
        numcount[int(x)] += 1
    queries = int(input())
    for _ in range(queries):
        before, after = [int(x) for x in input().split()]
        tmp = numcount[before]
        numcount[before] -= tmp
        numcount[after] += tmp

        print(sum(num * count for num, count in numcount.items()))


if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict


def main():
    number = int(input())
    numcount = defaultdict(int)
    for x in input().split():
        numcount[int(x)] += 1
    queries = int(input())
    ans = sum(num * count for num, count in numcount.items())
    for _ in range(queries):
        before, after = [int(x) for x in input().split()]
        tmp = numcount[before]
        numcount[before] -= tmp
        numcount[after] += tmp
        ans += (after - before) * tmp
        print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input()
    integars = sorted(int(x) for x in input().split())
    ans = 0
    for i, x in enumerate(integars):
        chosen = True
        for j, y in enumerate(integars):
            if i == j:
                continue
            elif x % y == 0:
                chosen = False
                break
            elif i < j:
                break
        if chosen:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    numbers = int(input())
    array = [int(x) for x in input().split()]
    maximum = 1000001
    counter = [0] * maximum

    for x in array:
        if counter[x] != 0:
            counter[x] = 2
            continue
        else:
            for multiple in range(x, maximum, x):
                counter[multiple] += 1
    ans = 0
    for x in array:
        if counter[x] == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    count = int(input())
    integars = sorted(int(x) for x in input().split())
    ans = 0
    for i, x in enumerate(integars):
        chosen = True
        for j, y in enumerate(integars):
            if i == j:
                continue
            elif i + 1 < j:
                break
            elif x % y == 0:
                chosen = False
                break
        if chosen:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    numbers = int(input())
    array = [int(x) for x in input().split()]
    maximum = 1000001
    counter = [0] * maximum

    for x in array:
        if counter[x] != 0:
            counter[x] = 2
            continue
        else:
            for multiple in range(x, maximum, x):
                counter[multiple] += 1
    ans = 0
    for x in array:
        if counter[x] == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    count = int(input())
    integars = sorted(int(x) for x in input().split())
    ans = 0
    for i, x in enumerate(integars):
        chosen = True
        for j, y in enumerate(integars):
            if i == j:
                continue
            elif i + 1 < j:
                break
            elif x % y == 0:
                chosen = False
                break
        if chosen:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    numbers = int(input())
    array = [int(x) for x in input().split()]
    maximum = 1000001
    counter = [0] * maximum

    for x in array:
        if counter[x] != 0:
            counter[x] = 2
            continue
        else:
            for multiple in range(x, maximum, x):
                counter[multiple] += 1
    ans = 0
    for x in array:
        if counter[x] == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import math


def main():
    n = int(input())
    mod = 1000000007
    zeroes = 0
    counter = defaultdict(lambda: defaultdict(int))
    for _ in range(n):
        a, b = [int(x) for x in input().split()]
        denominator = math.gcd(a, b)
        x, y = a // denominator, b // denominator

        if x == y == 0:
            zeroes += 1
            continue
        if y < 0:
            # quadrant III, IV -> I, II
            x, y = -x, -y

        if x <= 0:
            # round 90° from quadrant II to I
            x, y = y, -x
            counter[(x, y)][1] += 1
        else:
            counter[(x, y)][0] += 1

    ans = 1
    for v in counter.values():
        now = 1
        now += pow(2, v[0], mod) - 1
        now += pow(2, v[1], mod) - 1
        ans = ans * now % mod
    ans += zeroes
    ans -= 1  # choose no fish
    return ans % mod


if __name__ == '__main__':
    print(main())


Fixed submission:
from collections import defaultdict
import math


def ggg(a, b):
    """規約分数を作る。n/0, 0/n は n=1,-1 にして返す。"""
    if a == b == 0:
        return 0, 0

    denominator = math.gcd(a, b)
    x, y = a // denominator, b // denominator
    return x, y


def main():
    n = int(input())
    mod = 1000000007
    zeroes = 0
    counter = defaultdict(lambda: defaultdict(int))
    for _ in range(n):
        a, b = [int(x) for x in input().split()]
        x, y = ggg(a, b)

        if x == y == 0:
            zeroes += 1
            continue
        if y < 0:
            # quadrant III, IV -> I, II
            x, y = -x, -y

        if x <= 0:
            # round 90° from quadrant II to I
            x, y = y, -x
            counter[(x, y)][1] += 1
        else:
            counter[(x, y)][0] += 1

    ans = 1
    for v in counter.values():
        now = 1
        now += pow(2, v[0], mod) - 1
        now += pow(2, v[1], mod) - 1
        ans = ans * now % mod
    ans += zeroes
    ans -= 1  # choose no fish
    return ans % mod


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
# class Map(dict):
#     def __missing__(self, key):
#         # この割当てなしのほうが速い。
#         # self[key] = 0
#         return 0


def main():
    int(input())

    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        got = d.get(i + height) or 0
        d[i + height] += got + 1
        ans += d.get(i - height) or 0

    return ans


if __name__ == '__main__':
    print(main())

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


Fixed submission:
class Map(dict):
    def __missing__(self, key):
        default_value = 0
        self[key] = default_value
        return default_value


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Runtime Error):
def main():
    int(input())
    d = {}
    ans = 0
    for i, height in enumerate(input().split()):
        d[i + height] += 1
        ans += d[i - height]


if __name__ == '__main__':
    print(main())


Fixed submission:
class Map(dict):
    def __missing__(self, key):
        default_value = 0
        self[key] = default_value
        return default_value


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    a, b, n = [int(x) for x in input().split()]
    gen = (a * x // b - x // b * a for x in range(min(b, n) + 1))
    return max(gen)


if __name__ == '__main__':
    print(main())


Fixed submission:
def main():
    a, b, n = [int(x) for x in input().split()]
    # gen = (a * x // b - x // b * a for x in range(min(b, n) + 1))

    if n >= b - 1:
        x = b - 1
    else:
        x = n

    return a * x // b - x // b * a


if __name__ == '__main__':
    print(main())