Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k=int(input())
s=input()
if s.len()<=k: print(s)
else: print(s[:k]+"...")


Fixed submission:
k=int(input())
s=input()
if len(s)<=k: print(s)
else: print(s[:k]+"...")

Buggy python submission (verdict: Runtime Error):
k=int(input)
s=input()
if s.len()<=k: print(s)
else: print(s[:k]+"...")

Fixed submission:
k=int(input())
s=input()
if len(s)<=k: print(s)
else: print(s[:k]+"...")
Buggy python submission (verdict: Runtime Error):
def main():
  n = int(input())
  print(n * (n-1) // 2)
 

main()

Fixed submission:
a = input()
b = input()
score = 0

for i in range(3):
  if a[i] == b[i]:
    score+=1

print(score)
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
  str = input()
  strList = [c for c in str]
  strList.append('e')
  strLength = len(strList)
  rLength = 0
  lLength = 0
  i = 0
  changePoint = 0

  child = [0 for i in range(strLength)]

  c = 'R'
  
  while(c != 'e'):
    c = strList[i]
    while(c == 'R'):
      i += 1
      c = strList[i]
      rLength += 1
    
    changePoint = i
    
    while(c == 'L'):
      i += 1
      c = strList[i]
      lLength += 1

    rRight = rLength/2
    rLeft = rLength - rRight

    lLeft = lLength/2
    lRight = lLength - lLeft

    child[changePoint-1] += rLeft + lLeft
    child[changePoint-1] += rRight + lRight
  
  for numOfChild in child:
    print(str(numOfChild) + ' ')

Fixed submission:
if __name__ == '__main__':
  str = input()
  strList = [c for c in str]
  strList.append('e')
  strLength = len(strList)
  rLength = 0
  lLength = 0
  i = 0
  changePoint = 0

  child = [0 for i in range(strLength-1)]

  c = 'R'
  
  while(c != 'e'):
    c = strList[i]
    while(c == 'R'):
      i += 1
      c = strList[i]
      rLength += 1
    
    changePoint = i
    
    while(c == 'L'):
      i += 1
      c = strList[i]
      lLength += 1

    rRight = int(rLength/2)
    rLeft = rLength - rRight

    lLeft = int(lLength/2)
    lRight = lLength - lLeft

    child[changePoint-1] += rLeft + lLeft
    child[changePoint] += rRight + lRight

    rLength = 0
    lLength = 0
  
  for numOfChild in child:
    print(numOfChild, end="")
    print(' ', end="")

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
  n = int(input())
  heights = map(int, input().split(' '))

  prev = -100
  answer = 'Yes'

  for height in heights:
    if (height >= prev + 1):
      height = height -1
    elif height == prev:
      height = height
    else:
      answer = 'No'
      print(answer)
      exit()
    prev = height
  print(answer)

Fixed submission:
if __name__ == '__main__':
  str = input()
  strList = [c for c in str]
  strList.append('e')
  strLength = len(strList)
  rLength = 0
  lLength = 0
  i = 0
  changePoint = 0

  child = [0 for i in range(strLength-1)]

  c = 'R'
  
  while(c != 'e'):
    c = strList[i]
    while(c == 'R'):
      i += 1
      c = strList[i]
      rLength += 1
    
    changePoint = i
    
    while(c == 'L'):
      i += 1
      c = strList[i]
      lLength += 1

    rRight = int(rLength/2)
    rLeft = rLength - rRight

    lLeft = int(lLength/2)
    lRight = lLength - lLeft

    child[changePoint-1] += rLeft + lLeft
    child[changePoint] += rRight + lRight

    rLength = 0
    lLength = 0
  
  for numOfChild in child:
    print(numOfChild, end="")
    print(' ', end="")
Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
ac=[0]*(n-1)
for i in range(1,n-1):
  ac[i]=ac[i-1]+(s[i]=="A" and s[i+1]=="C")
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r-1]-ac[l-1])

Fixed submission:
n,q=map(int,input().split())
s=input()
ac=[0]*(n+1)
for i in range(n):
  ac[i]=ac[i-1]+(s[i:i+2]=="AC")
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r-2]-ac[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
ac=[0]*(n-1)
for i in range(n-1):
  ac[i]=(s[i]=="A" and s[i+1]=="C")
ans=""
for i in range(q):
  l,r=map(int,input().split())
  ans+=str(sum(ac[l-1:r-1]))+"\n"
print(ans,end="")

Fixed submission:
n,q=map(int,input().split())
s=input()
ac=[0]*(n+1)
for i in range(n):
  ac[i]=ac[i-1]+(s[i:i+2]=="AC")
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r-2]-ac[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    count=0
    for j in range(l-1,r-1):
        count+=(s[j:j+2]=="AC")
    print(count)

Fixed submission:
n,q=map(int,input().split())
s=input()
ac=[0]*(n+1)
for i in range(n):
  ac[i]=ac[i-1]+(s[i:i+2]=="AC")
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r-2]-ac[l-2])
Buggy python submission (verdict: Runtime Error):
def ceil(x,y):
    if x%y==0:
        return x//y
    return x//y+1
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(reverse=True)
max_a=ab[0][0]
ab.sort(key=lambda x:x[1],reverse=True)
c=0
for i in range(n):
    if ab[i][1]>max_a and ab[i][0]!=max_a:
        c+=1
        h-=ab[i][1]
    if h<=0:
        break
if max_a <ab[0][1] and h>0:
   c+=1
   h-=ab[0][1]
c+=ceil(h,max_a) if h>0 else 0
print(c)

Fixed submission:
def comb(n,y):
    for i in range(n+1):
        for j in range(n+1-i):
            if 10000*i+5000*j+1000*(n-i-j)==y:
                return [i,j,n-i-j]
    return [-1,-1,-1]

n,y=map(int,input().split())
print("{} {} {}".format(*comb(n,y)))
Buggy python submission (verdict: Runtime Error):
N=int(input())
answer=0
for i in range(N):
  l,r = map(input().split())
  answer+=r-l+1
print(answer)

Fixed submission:
N=int(input())
sl=[]
for i in range(N):
  sl.append(list(map(int,input().split())))
sl.sort()
sl_table = [True for i in range(len(sl))]

for i in range(N):
  for j in range(min(i+1,N),N):
    if sl[j][0]-sl[i][1]>0:
      break
    sl[i]=[min(min(sl[i]),min(sl[j])),max(max(sl[i]),max(sl[j]))]
    sl_table[j]=False

print(sum((s[1]-s[0]+1)*sl_table[i] for i,s in enumerate(sl)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
sum=0
seats=[False for i in range(100000)]
for i in range(N):
  l,r=map(int,input.split())
  for j in range(l-1,r-1):
    seats[j]=True
print(sum(seats))

Fixed submission:
N=int(input())
sl=[]
for i in range(N):
  sl.append(list(map(int,input().split())))
sl.sort()
sl_table = [True for i in range(len(sl))]

for i in range(N):
  for j in range(min(i+1,N),N):
    if sl[j][0]-sl[i][1]>0:
      break
    sl[i]=[min(min(sl[i]),min(sl[j])),max(max(sl[i]),max(sl[j]))]
    sl_table[j]=False

print(sum((s[1]-s[0]+1)*sl_table[i] for i,s in enumerate(sl)))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from copy import copy

n = int(input())
s = input()

total_cnt = dict(Counter(s))
cnt = [total_cnt]
for i, c in enumerate(s):
    curr_cnt = copy(cnt[-1])
    curr_cnt[c] -= 1
    cnt.append(curr_cnt)

res = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n - 1):
        c2 = s[j]
        if c2 == c1:
            continue
        for c3 in "RGB":
            if c3 == c1 or c3 == c2:
                continue
            res += cnt[j + 1][c3]
            k = 2 * j - i
            if k >= n:
                continue
            if s[k] == c3:
                res -= 1
print(res)


Fixed submission:
from collections import Counter
from copy import copy

n = int(input())
s = input()

total_cnt = dict(Counter(s))
if len(total_cnt) < 3:
    print(0)
    exit()

cnt = [total_cnt]
for i, c in enumerate(s):
    curr_cnt = copy(cnt[-1])
    curr_cnt[c] -= 1
    cnt.append(curr_cnt)

res = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n - 1):
        c2 = s[j]
        if c2 == c1:
            continue
        for c3 in "RGB":
            if c3 == c1 or c3 == c2:
                continue
            res += cnt[j + 1][c3]
            k = 2 * j - i
            if k >= n:
                continue
            if s[k] == c3:
                res -= 1
print(res)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from copy import copy

n = int(input())
s = input()

total_cnt = dict(Counter(s))
cnt = [total_cnt]
for i, c in enumerate(s):
    curr_cnt = copy(cnt[-1])
    curr_cnt[c] -= 1
    cnt.append(curr_cnt)

res = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n - 1):
        c2 = s[j]
        if c2 == c1:
            continue
        for c3 in "RGB":
            if c3 == c1 or c3 == c2:
                continue
            res += cnt[j + 1][c3]
            k = 2 * j - i
            if k >= n:
                continue
            if s[k] == c3:
                res -= 1
print(res)


Fixed submission:
from collections import Counter
from copy import copy

n = int(input())
s = input()

total_cnt = dict(Counter(s))
if len(total_cnt) < 3:
    print(0)
    exit()

cnt = [total_cnt]
for i, c in enumerate(s):
    curr_cnt = copy(cnt[-1])
    curr_cnt[c] -= 1
    cnt.append(curr_cnt)

res = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n - 1):
        c2 = s[j]
        if c2 == c1:
            continue
        for c3 in "RGB":
            if c3 == c1 or c3 == c2:
                continue
            res += cnt[j + 1][c3]
            k = 2 * j - i
            if k >= n:
                continue
            if s[k] == c3:
                res -= 1
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, deque, defaultdict

n, x, y = map(int, input().split())

v = defaultdict(list)
for i in range(n):
    if i + 1 < n: v[i].append(i + 1)
    if i - 1 >= 0: v[i].append(i - 1)
v[x - 1].append(y - 1)
v[y - 1].append(x - 1)

cnt = Counter()
for start in range(n):
    dist = [float("inf")] * n
    q = deque()
    q.append([start, 0])
    while q:
        c, d = q.popleft()
        for next in v[c]:
            if dist[next] == float("inf"):
                q.append([next, d + 1])
                dist[next] = d + 1
    cnt += Counter(dist[start + 1:])

for i in range(1, n):
    print(cnt[i])


Fixed submission:
from collections import Counter, deque, defaultdict


def main():
    n, x, y = map(int, input().split())
    v = defaultdict(list)
    for i in range(n):
        if i + 1 < n: v[i].append(i + 1)
        if i - 1 >= 0: v[i].append(i - 1)
    v[x - 1].append(y - 1)
    v[y - 1].append(x - 1)

    cnt = Counter()
    for start in range(n):
        dist = [-1] * n
        q = deque()
        q.append([start, 0])
        while q:
            c, d = q.popleft()
            for next in v[c]:
                if dist[next] == -1:
                    q.append([next, d + 1])
                    dist[next] = d + 1
        cnt += Counter(dist[start + 1:])

    for i in range(1, n):
        print(cnt[i])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

rev = False
head = []
tail = []

for i in range(q):
    query = input()
    if query == "1":
        rev = not rev
    else:
        _, f, c = query.split()
        if (not rev and f == "1") or (rev and f == "2"):
            head.append(c)
        else:
            tail.append(c)

if not rev:
    print(*head[::-1], s, *tail, sep="")
else:
    print(*tail[::-1], s, *head, sep="")


Fixed submission:
s = list(input())
q = int(input())

rev = False
head = []
tail = []

for i in range(q):
    query = input()
    if query == "1":
        rev = not rev
    else:
        _, f, c = query.split()
        if (not rev and f == "1") or (rev and f == "2"):
            head.append(c)
        else:
            tail.append(c)

if not rev:
    res = head[::-1] + s + tail
else:
    res = tail[::-1] + s[::-1] + head

print(*res, sep="")

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

rev = False
head = []
tail = []

for _ in range(q):
    query = input()
    if query == "1":
        rev = not rev
    else:
        _, f, c = query.split()
        if (not rev and f == "1") or (rev and f == "2"):
            head.append(c)
        else:
            tail.append(c)

if not rev:
    print(*head[::-1], s, *tail, sep="")
else:
    print(*tail[::-1], s, *head, sep="")


Fixed submission:
s = list(input())
q = int(input())

rev = False
head = []
tail = []

for i in range(q):
    query = input()
    if query == "1":
        rev = not rev
    else:
        _, f, c = query.split()
        if (not rev and f == "1") or (rev and f == "2"):
            head.append(c)
        else:
            tail.append(c)

if not rev:
    res = head[::-1] + s + tail
else:
    res = tail[::-1] + s[::-1] + head

print(*res, sep="")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(lambda n: format(int(n), '060b')[::-1], input().split()))

mod = 10 ** 9 + 7

res = 0
power_of_two = 1
for d in range(60):
    one = sum(x[d] == "1" for x in arr)
    res += one * (n - one) * power_of_two
    res %= mod
    power_of_two *= 2
    power_of_two %= mod

print(res)


Fixed submission:
n = int(input())
arr = list(map(lambda n: format(int(n), '060b')[::-1], input().split()))

mod = 10 ** 9 + 7

res = 0
power_of_two = 1
for d in range(60):
    one = sum(x[d] == "1" for x in arr)
    res += one * (n - one) * power_of_two
    res %= mod
    power_of_two *= 2
    power_of_two %= mod

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
sum_rain = sum(a) // 2
a += a
ans_rain = []

for i in range(n):
    rest_rain = 0
    for j in range(i + 1, i + n, 2):
        rest_rain += a[j]
    ans_rain.append((sum_rain - rest_rain) * 2)

print(*ans_rain)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_rain = sum(a) // 2

rest_rain = 0
for i in range(1, n, 2):
    rest_rain += a[i]
first_ans = (sum_rain - rest_rain) * 2

res = []

res.append(first_ans)
prev_ans = first_ans

for i in range(n - 1):
    ans = (a[i] - prev_ans // 2) * 2
    res.append(ans)
    prev_ans = ans

print(*res)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = input()

string_set = set(a, b, c, d)

print("YES" if len(string_set) == 2 and not a ^ b ^ c ^ d else "NO")

Fixed submission:
from collections import Counter

arr = list(input())
c = Counter(arr)
print("Yes" if c.most_common()[0][1] == 2 and c.most_common()[1][1] == 2 else "No")
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

n, k = map(int, input().split())

mod = 10 ** 9 + 7
curr_sum = 0

for i in range(1, k + 1):
    ans = (comb(n - k + i, n - k, exact=True) - curr_sum)
    ans *= comb(k - 1, i - 1, exact=True)
    ans %= mod
    print(ans)
    curr_sum += ans



Fixed submission:
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    fact_n_div_k = (fact_n * pow(fact_k, mod - 2, mod)) % mod
    return (fact_n_div_k * pow(fact_n_k, mod - 2, mod)) % mod


n, k = map(int, input().split())
mod = 10 ** 9 + 7

for i in range(1, k + 1):
    ans = comb_mod(n - k + 1, i, mod) * comb_mod(k - 1, i - 1, mod)
    ans %= mod
    print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd


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


a, b, c, d = map(int, input().split())

cnt_b = b // c + b // d - b // lcm(c, d)
cnt_a = (a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d)

print(b - a + 1 - (cnt_b - cnt_a))



Fixed submission:
from fractions import gcd


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


a, b, c, d = map(int, input().split())

cnt_b = b // c + b // d - b // lcm(c, d)
cnt_a = (a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d)

print(b - a + 1 - (cnt_b - cnt_a))
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    n = input()
    length = len(n)
    mod = 10 ** 9 + 7

    cnt = 1
    j = n.count("1")

    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1) + 1) * pow(2, j)
            cnt %= mod

    print(cnt)


main()

Fixed submission:
def main():

    n = input()
    length = len(n)
    mod = 10 ** 9 + 7

    cnt = 1
    j = n.count("1")

    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1, mod) + 1) * pow(2, j, mod)
            cnt %= mod

    print(cnt)


main()

Buggy python submission (verdict: Runtime Error):
def main()
    
    n = input()
    length = len(n)
    mod = 10 ** 9 + 7
    
    cnt = 1
    j = n.count("1")
    
    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1) + 1) * pow(2, j)
            cnt %= mod
    
    print(cnt)


main()

Fixed submission:
def main():

    n = input()
    length = len(n)
    mod = 10 ** 9 + 7

    cnt = 1
    j = n.count("1")

    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1, mod) + 1) * pow(2, j, mod)
            cnt %= mod

    print(cnt)


main()

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
length = len(n)
mod = 10 ** 9 + 7

cnt = 1
j = n.count("1")

for digit, num in enumerate(n[::-1], 1):
    if num == "1":
        j -= 1
        cnt += (3 ** (digit - 1) + 1) * 2 ** j
        cnt %= mod

print(cnt)


Fixed submission:
def main():

    n = input()
    length = len(n)
    mod = 10 ** 9 + 7

    cnt = 1
    j = n.count("1")

    for digit, num in enumerate(n[::-1], 1):
        if num == "1":
            j -= 1
            cnt += (pow(3, digit - 1, mod) + 1) * pow(2, j, mod)
            cnt %= mod

    print(cnt)


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

cnt = 0

while "ABC" in S:
    cnt += S.count("ABC")
    S = S.replace("ABC", "BCA")

print(cnt)

Fixed submission:
S = input()

cnt = 0

S = S.replace("BC", "X")
S = S.replace("B", " ")
S = S.replace("C", " ")

arr = S.split()

for elem in arr:
    i = 0

    for char in elem:
        if char == "A":
            i += 1
        else:
            cnt += i

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


n, m, k = map(int, input().split())
s = 0
mod = 10 ** 9 + 7
for x in range(m):
    for i in range(x, m):
        s += abs(x-i) * n **2
for y in range(n):
    for j in range(y, n):
        s += abs(y-j) * m ** 2


print(s * comb_mod(n * m - 2, k - 2, mod) % mod)


Fixed submission:
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


n, m, k = map(int, input().split())
s = 0
mod = 10 ** 9 + 7
for x in range(m):
    s += (m - x - 1) * (m - x) // 2 * n **2
for y in range(n):
    s += (n - y - 1) * (n - y) // 2 * m ** 2


print(s * comb_mod(n * m - 2, k - 2, mod) % mod)
Buggy python submission (verdict: Runtime Error):
def union_find():
    # グラフの連結していないグループの数をunion_findで求める
    def get_parent(node):
        if par[node] == -1:
            return node
        else:
            par[node] = get_parent(par[node])
            return par[node]

    def merge(i, j):
        i = get_parent(i)
        j = get_parent(j)
        if i != j:
            par[j] = i
        return

    n, m = map(int, input().split())
    xy = [list(map(int, input().split())) for _ in range(m)]
    par = [-1] * n
    for x, y in xy:
        merge(x-1, y-1)
    print(par.count(-1))


union_find()

Fixed submission:
def union_find():
    # グラフの連結していないグループの数をunion_findで求める
    def get_parent(node):
        if par[node] == -1:
            return node
        else:
            par[node] = get_parent(par[node])
            return par[node]

    def merge(i, j):
        i = get_parent(i)
        j = get_parent(j)
        if i != j:
            par[j] = i
        return

    n, m = map(int, input().split())
    xyz = [list(map(int, input().split())) for _ in range(m)]
    par = [-1] * n
    for x, y, z in xyz:
        merge(x-1, y-1)
    print(par.count(-1))

union_find()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

one = []
zero = []
cnt_one = 0
cnt_zero = 0

if s[0] == "#":
    zero.append(0)

for i in s:
    if i == "#":
        cnt_one += + 1
        if cnt_zero != 0:
            zero.append(cnt_zero)
            cnt_zero = 0
    else:
        cnt_zero += 1
        if cnt_one != 0:
            one.append(cnt_one)
            cnt_one = 0

if cnt_one != 0:
    one.append(cnt_one)
else:
    zero.append(cnt_zero)

if s[-1] == "#":
    zero.append(0)

print(min(sum(one[:i]) + sum(zero[i+1:]) for i in range(len(one)+1)))

Fixed submission:
n = int(input())
s = input()

one = []
zero = []
cnt_one = 0
cnt_zero = 0

if s[0] == "#":
    zero.append(0)

for i in s:
    if i == "#":
        cnt_one += + 1
        if cnt_zero != 0:
            zero.append(cnt_zero)
            cnt_zero = 0
    else:
        cnt_zero += 1
        if cnt_one != 0:
            one.append(cnt_one)
            cnt_one = 0

if cnt_one != 0:
    one.append(cnt_one)
else:
    zero.append(cnt_zero)

if s[-1] == "#":
    zero.append(0)

sum = 0
sum_zero = [0]
for i in range(len(one)):
    sum += zero[len(one)-i]
    sum_zero.append(sum)

sum = 0
sum_one = [0]
for i in range(len(one)):
    sum += one[i]
    sum_one.append(sum)


print(min(sum_one[i] + sum_zero[len(one)-i] for i in range(len(one)+1)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    x, y, z, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    ab = [aa + bb for aa in a for bb in b]
    ab.sort(reverse=True)
    ab = ab[:3000]

    abc = [aabb + cc for aabb in ab for cc in c]
    abc.sort(reverse=True)

    for i in range(k):
        print(abc[i])


main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    x, y, z, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    ab = [aa + bb for aa in a for bb in b]
    ab.sort(reverse=True)
    ab = ab[:3000]

    abc = [aabb + cc for aabb in ab for cc in c]
    abc.sort(reverse=True)

    for i in range(k):
        print(abc[i])


main()