Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2)
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()


Fixed submission:
def main():
    N, K = map(int, input().split())

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2))
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    pN = list(map(lambda s: int(s) + 1, input().split()))

    ans = 0
    for i in range(N + 1 - K):
        ans = max(ans, sum(pN[i:i + K]) / 2)

    print(ans)


main()


Fixed submission:
def main():
    N, K = map(int, input().split())

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2))
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    pN = list(map(int, input().split()))

    ans = 0
    for i in range(N + 1 - K):
        ans = max(ans, sum(map(lambda x: 1 + x, pN[i:i + K])) / 2)

    print(ans)


main()


Fixed submission:
def main():
    N, K = map(int, input().split())

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2))
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            A1 = 1
            c += A - 1
        c += 1
        B1 = (B - c)
        X = abs(A1 - ((A1 + B1) // 2)) + c

        c = 0
        if B < N:
            B2 = N
            c += B - 1
        c += 1
        A2 = (A + c)
        Z = abs(A2 - ((A2 + B2) // 2)) + c

        print(min(Y, X, Z))


main()


Fixed submission:
def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            c += A - 1
        c += 1
        B1 = B - c
        A1 = 1
        X = abs(A1 - ((A1 + B1) // 2)) + c
        if B1 < A1:
            X = 9999999999999999999999999999

        c = 0
        if B < N:
            c += N - B
        c += 1
        A2 = A + c
        B2 = N
        Z = abs(A2 - ((A2 + B2) // 2)) + c
        if B2 < A2:
            Z = 9999999999999999999999999999

        print(min(Y, X, Z))


main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            A1 = 1
            c += A - 1
        c += 1
        B1 = (B - c)
        X = abs(A1 - ((A1 + B1) // 2) + c)

        c = 0
        if B < N:
            B2 = N
            c += B - 1
        c += 1
        A2 = (A + c)
        Z = (abs(A2 - ((A2 + B2) // 2)) + c)

        print(min(Y, X, Z))


main()


Fixed submission:
def main():
    N, A, B = map(int, input().split())

    if (A + B) % 2 == 0:
        print(abs(A - ((A + B) // 2)))
    else:
        Y = min(B - 1, N - A)

        c = 0
        if 1 < A:
            c += A - 1
        c += 1
        B1 = B - c
        A1 = 1
        X = abs(A1 - ((A1 + B1) // 2)) + c
        if B1 < A1:
            X = 9999999999999999999999999999

        c = 0
        if B < N:
            c += N - B
        c += 1
        A2 = A + c
        B2 = N
        Z = abs(A2 - ((A2 + B2) // 2)) + c
        if B2 < A2:
            Z = 9999999999999999999999999999

        print(min(Y, X, Z))


main()
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
 
while A!=B:
  if A < B:
    A += A
  else:
    B += B
 
print(A)

Fixed submission:
from fractions import gcd


def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B = map(int, input().split())
print(lcm(A, B))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7


def main():
    N = int(input())
    AN = map(int, input().split())

    digits_ct = [(0, 0) for _ in range(65)]

    for A in AN:
        temp = A

        length = 0
        for _ in range(65):
            digit = temp & 0b1

            zero, one = digits_ct[length]
            if digit == 0:
                digits_ct[length] = (zero + 1, one)
            else:
                digits_ct[length] = (zero, one + 1)

            temp = temp >> 1
            length += 1

    ans = 0
    radix = 1
    for digit_ct in digits_ct:
        zero, one = digit_ct
        ans += (((zero * one) % MOD) * radix) % MOD
        ans = ans % MOD

        radix *= 2

    print(ans)


main()


Fixed submission:
MOD = 10**9 + 7


def main():
    N = int(input())
    AN = map(int, input().split())

    digits_ct = [(0, 0) for _ in range(65)]

    for A in AN:
        temp = A

        length = 0
        for _ in range(65):
            digit = temp & 0b1

            zero, one = digits_ct[length]
            if digit == 0:
                digits_ct[length] = (zero + 1, one)
            else:
                digits_ct[length] = (zero, one + 1)

            temp = temp >> 1
            length += 1

    ans = 0
    radix = 1
    for digit_ct in digits_ct:
        zero, one = digit_ct
        ans += (((zero * one) % MOD) * radix) % MOD
        ans = ans % MOD

        radix *= 2

    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
import math

N=int(input())

ans=999999999999
for i in range(1,math.sqrt(N)+1):
  if N % i == 0:
    ans = min(ans,i + N//i - 2)
print(ans)

Fixed submission:
import math

N=int(input())

ans=999999999999
for i in range(1,int(math.sqrt(N))+1):
  if N % i == 0:
    ans = min(ans,i + N//i - 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for i, index in enumerate(s_indexes[t_c]):
                if last_index < index:
                    s_pointer[t_c] = i
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)


main()


Fixed submission:
def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for j in range(s_pointer[t_c], s_length[t_c]):
                if last_index < s_indexes[t_c][j]:
                    s_pointer[t_c] = j
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)


main()
Buggy python submission (verdict: Time Limit Exceeded):
INF = 99999999999

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

dp = [INF for _ in range(N)]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k < N:
            diff = dp[i] + abs(hN[i] - hN[i + k])
            dp[i + k] = min(dp[i + k], diff)
        else:
            break
    # print("i={}, dp={}".format(i, dp))

print(dp[N - 1])


Fixed submission:
INF = 99999999999

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

dp = [INF for _ in range(N)]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k < N:
            diff = dp[i] + abs(hN[i] - hN[i + k])
            dp[i + k] = min(dp[i + k], diff)
        else:
            break
    # print("i={}, dp={}".format(i, dp))

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    sl = len(s)
    t = input()
    tl = len(t)

    # dp[s][t]: value
    dp = [[(0, "") for _ in range(tl + 1)] for _ in range(sl + 1)]

    for si in range(sl):
        for ti in range(tl):
            if s[si] == t[ti]:
                dp[si + 1][ti + 1] = (dp[si][ti][0] + 1, dp[si][ti][1] + s[si])
            else:
                dp[si + 1][ti + 1] = max(dp[si + 1][ti], dp[si][ti + 1])

    # import pprint
    # print("dp={}".format(pprint.pformat(dp)))

    print(dp[sl][tl][1])


main()


Fixed submission:
def main():
    s = input()
    sl = len(s)
    t = input()
    tl = len(t)

    # dp[s][t]: value
    dp = [[(0) for _ in range(tl + 1)] for _ in range(sl + 1)]

    for si in range(sl):
        for ti in range(tl):
            if s[si] == t[ti]:
                dp[si + 1][ti + 1] = dp[si][ti] + 1
            else:
                dp[si + 1][ti + 1] = max(dp[si + 1][ti], dp[si][ti + 1])

    # import pprint
    # print("dp={}".format(pprint.pformat(dp)))

    ret = []
    si, ti = sl, tl
    while 0 < si and 0 < ti:
        if dp[si][ti] == dp[si - 1][ti]:
            si -= 1
        elif dp[si][ti] == dp[si][ti - 1]:
            ti -= 1
        else:
            ret.insert(0, s[si - 1])
            si -= 1
            ti -= 1

    print("".join(ret))


main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python

s = input().strip()
k = int(input().strip())

flag = True
for i in range(k):
    if s[i] == '1':
        print(s[i])
        flag = False

if flag:
    print(s[1])


Fixed submission:
#!/usr/bin/env python


def main():
    s = input().strip()
    k = int(input().strip())

    # 1桁目が、1以外のときは、1桁目を表示
    if s[0] != '1':
        print(s[0])
        return

    count_one = 0
    for c in s:
        if c == '1':
            count_one += 1
        else:
            break

    if k <= count_one:
        print(1)
    else:
        print(s[count_one])


main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python

s = input().strip()
k = input().strip()

flag = True
for i in range(k):
    if s[i] == '1':
        print(s[i])
        flag = False

if flag:
    print(s[1])


Fixed submission:
#!/usr/bin/env python


def main():
    s = input().strip()
    k = int(input().strip())

    # 1桁目が、1以外のときは、1桁目を表示
    if s[0] != '1':
        print(s[0])
        return

    count_one = 0
    for c in s:
        if c == '1':
            count_one += 1
        else:
            break

    if k <= count_one:
        print(1)
    else:
        print(s[count_one])


main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python

s = input().strip()
k = input().strip()

if s[0] == '1':
    print(s[1])
else:
    print(s[0])


Fixed submission:
#!/usr/bin/env python


def main():
    s = input().strip()
    k = int(input().strip())

    # 1桁目が、1以外のときは、1桁目を表示
    if s[0] != '1':
        print(s[0])
        return

    count_one = 0
    for c in s:
        if c == '1':
            count_one += 1
        else:
            break

    if k <= count_one:
        print(1)
    else:
        print(s[count_one])


main()
Buggy python submission (verdict: Runtime Error):
N = int(input().split())
AN = list(map(int, input().split()))
 
print(sum(AN)-N)

Fixed submission:

import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)

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

print(sum(AN)-N)

Fixed submission:

import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)

Buggy python submission (verdict: Runtime Error):
import math

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)


Fixed submission:

import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)

Buggy python submission (verdict: Runtime Error):
import math

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)


Fixed submission:

import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)

Buggy python submission (verdict: Runtime Error):

import math

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)


Fixed submission:

import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)
Buggy python submission (verdict: Runtime Error):
import itertools

N_MAX = 100000
INF = float('inf')

n = int(input().rstrip())

dp = [INF for _ in range(N_MAX)]
dp[0] = 0
dp[1] = 1
dp[6] = 1
dp[9] = 1

for i in range(1, n + 1):

    # [1, 6, 36, ...]
    for j in itertools.takewhile(lambda x: x < N_MAX,
                                 (6 ** c for c in itertools.count())):
        dp[i] = min(dp[i], dp[i - j] + 1)

    # [1, 9, 81, ...]s
    for j in itertools.takewhile(lambda x: x < N_MAX,
                                 (9 ** c for c in itertools.count())):
        dp[i] = min(dp[i], dp[i - j] + 1)

print(dp[n])


Fixed submission:
def main():
    N = int(input())

    dp = [999999999999 for _ in range(N + 1)]
    dp[0] = 0

    for n in range(1, N + 1):
        # 1 yen
        dp[n] = min(dp[n], dp[n - 1] + 1)

        # 6 yen
        i = 6
        while i <= n:
            dp[n] = min(dp[n], dp[n - i] + 1)
            i *= 6

        # 9 yen
        i = 9
        while i <= n:
            dp[n] = min(dp[n], dp[n - i] + 1)
            i *= 9

    print(dp[N])


main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

import collections

E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

min_change_count = float('inf')

for i in range(n):
    w_line = line[0:i]
    e_line = line[i+1:] if i < n else []

    change_count = 0
    change_count += collections.Counter(w_line)[W]
    change_count += collections.Counter(e_line)[E]

    min_change_count = change_count if change_count < min_change_count else min_change_count


print(min_change_count)


Fixed submission:
E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

bef_change_count = line[1:].count(E)
min_change_count = bef_change_count

for leader_i in range(1, n):
    change_count = bef_change_count
    if line[leader_i] == E and line[leader_i - 1] == E:
        change_count -= 1
    elif line[leader_i] == W and line[leader_i - 1] == W:
        change_count += 1

    bef_change_count = change_count
    min_change_count = min(change_count, min_change_count)

print(min_change_count)
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = map(int, input().split())

for i in range(k):
    if abs(x - d) <= abs(x + d):
        x = abs(x - d)
    else:
        x = abs(x + d)
        
print(x)

Fixed submission:
x, k, d = map(int, input().split())

if x < 0:
    if x + k * d < 0:
        print(-x - k * d)
    else:
        a = -x // d
        x += a * d
        if (k - a) % 2 == 0:
            print(-x)
        else:
            print(x + d)
            
else:
    if x - k * d > 0:
        print(x - k * d)
    else:
        a = x // d
        x -= a * d
        if (k - a) % 2 == 0:
            print(x)
        else:
            print(d - x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = list(map(int, input().split()))

x = 1

for i in range(n):
    x = x * a[i]
    
if x <= 10 ** 18:
    print(x)
else:
    print(-1)


Fixed submission:
n = int(input())

a = sorted(list(map(int, input().split())))

x = 1

for i in range(n):
    x = x * a[i]
    if x == 0:
        break
    elif x > 10 ** 18:
        x = -1
        break

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

s = []
x = 0

for i in range(a):
    s.append(1)

for i in range(b):
    s.append(0)

for i in range(c):
    s.append(-1)
    
for i in range(k):
    x += s[i]
    
print(x)


Fixed submission:
a, b, c, k = map(int, input().split())

s = []
x = 0

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(2 * a + b - k)
else:
    print(a - c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    print(a.count(i+1))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = [0] * n

for i in range(n-1):
    b[(a[i]-1)] += 1
    
for i in range(n):
    print(b[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math

k = int(input())

x = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            x += math.gcd(math.gcd(a, b), c)
            
print(x)

Fixed submission:
import math

k = int(input())

x = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        t = math.gcd(a, b)
        for c in range(1, k+1):
            x += math.gcd(t, c)
            
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

a = []

while N > abs(N-K):
    N = abs(N-K)
    
print(N)

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

print(min(N%K, K-N%K))
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Fixed submission:
s = input()

if s == 'AAA' or s == 'BBB':
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

for t in range(10 ** 18):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(f * a + g)
    
else:
    print(f * (a+1))

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

for t in range(10 ** 100):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(f * a + g)
    
else:
    print(f * (a+1))

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

for t in range(10 ** 100):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

for t in range(10 ** 100):
    if len(array) < n:
        for p in range(a):
            array.append('blue')
        for q in range(b):
            array.append('red')
    else:
        break

x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

for t in range(10 ** 100):
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')
    if len(array) > n:
        break
    
x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

array = []

t = 0

while t < 10 ** 100:
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')
    t += 1
    
x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Fixed submission:
n, a, b = map(int, input().split())

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(a * f + g)
    
else:
    print(a * (f+1))