Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit(0)
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit(0)
while True:
    print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        break
print(mid+1)
s1 = raw_input()


Fixed submission:
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit(0)
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit(0)
while True:
    #print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    #print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        exit(0)
print(mid+1)
s1 = raw_input()

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit()
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit()
while True:
    print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        break
print(mid+1)
s1 = raw_input()


Fixed submission:
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit(0)
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit(0)
while True:
    #print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    #print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        exit(0)
print(mid+1)
s1 = raw_input()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(a[i-1])

a[0]=1000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)
comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]




Fixed submission:

n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10**10

m=int((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  
  for i in range(2,m+2):
    comfort+=(2*a[i])

  if(n%2 ==0):
    print(comfort)
  else:
    print(comfort+a[m+2])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(a[i-1])

a[0]=1000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)
comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]




Fixed submission:

n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10**10

m=int((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  
  for i in range(2,m+2):
    comfort+=(2*a[i])

  if(n%2 ==0):
    print(comfort)
  else:
    print(comfort+a[m+2])
Buggy python submission (verdict: Runtime Error):
#c
a, b = map(int ,input().split())
from math import *
print(a*b//math.gcd(a, b))

Fixed submission:
#c
a, b = map(int ,input().split())
from fractions import gcd
print(a*b//gcd(a, b))

Buggy python submission (verdict: Runtime Error):
#c
a, b = map(int ,input().split())
import math
print(a*b//math.gcd(a, b))

Fixed submission:
#c
a, b = map(int ,input().split())
from fractions import gcd
print(a*b//gcd(a, b))

Buggy python submission (verdict: Runtime Error):
#c
a, b = map(int ,input().split())
import math
print(a*b//math.gcd(a, b))

Fixed submission:
#c
a, b = map(int ,input().split())
from fractions import gcd
print(a*b//gcd(a, b))

Buggy python submission (verdict: Runtime Error):
#c
a, b = map(int ,input().split())
from math import gcd
print(a*b//gcd(a, b))

Fixed submission:
#c
a, b = map(int ,input().split())
from fractions import gcd
print(a*b//gcd(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = map(int, input().split())

res = 1
for i in a:
  if i == 0:
    print(0)
    break
  else:
    res *= i

else:
  if res > 10**18:
    print(-1)
  else:
    print(res)

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

res = 1
for i in a:
  if i == 0:
    print(0)
    break
  if res > 10**18: continue
  else: res *= i

else:
  print(-1 if res > 10**18 else res)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()

remainder = [0]*2019
remainder[0] = 1

for i in range(len(n)):
	remainder[int(n[i:])%2019] += 1
    
res = 0
for e in remainder:
	res += e*(e-1)//2

print(res)

Fixed submission:
n = input()

remainder = [0]*2019
remainder[0] += 1
x = 1
rem = 0

for i in range(1, len(n)+1):
	rem = (rem + int(n[-i])*x)%2019
	remainder[rem] += 1
	x *= 10
	x %= 2019
    
res = 0
for e in remainder:
	res += e*(e-1)//2

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product as p

N = int(input())
S = input()

def f(n, s):
  dic = {'R': [], 'G':[], 'B':[]}
  res = 0
  
  for i in range(N):
    dic[S[i]].append(i)
    
  for tpl in p(*dic.values()):
    l = sorted(tpl)
    if (l[2] + l[0])/2 != l[1]:
      res += 1
      
  return res

print(f(N, S))

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

dic = {k: 0 for k in "RGB"}

for i in range(n):
  dic[s[i]] += 1
  
res = dic['R'] * dic['G'] * dic['B']

for i in range(n):
  for j in range(i+1, n):
    k = 2*j - i
    if k >= n: continue
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]: res -= 1

print(res)
Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = 0
    ans = False
    while True :
        if k >= len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    S = list(input())
    k = 0
    ans = False
    
    while True :
        if len(S) % 2 != 0 :
            break 
        elif k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = 0
    ans = False
    while True :
        if k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    S = list(input())
    k = 0
    ans = False
    
    while True :
        if len(S) % 2 != 0 :
            break 
        elif k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
Q = [[] for _ in range(N)]
for i in range(N):
    line = input().split()
    Q[i] = line
reverse = 0
for i in range(N):
    if Q[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if Q[i][1] == '1' :
                S = Q[i][2] + S
            else :
                S = S +Q[i][2]
        else:
            if Q[i][1] == '1':
                S = S + Q[i][2]
            else:
                S = Q[i][2] + S
if reverse == 0 :
    print(S)
else:
    S = S[::-1]
    print(S)

Fixed submission:
S = input()
N = int(input())
Q = [[] for _ in range(N)]
for i in range(N):
    line = input().split()
    Q[i] = line
reverse = 0
r_b = ""
r_f = ""
for i in range(N):
    if Q[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if Q[i][1] == '1' :
                r_f = Q[i][2] + r_f
            else :
                r_b = r_b +Q[i][2]
        else:
            if Q[i][1] == '1':
                r_b = r_b +Q[i][2]
            else:
                r_f = Q[i][2] + r_f
if reverse == 0 :
    print(r_f + S + r_b)
else:
    r_f = r_f[::-1]
    r_b = r_b[::-1]
    S = S[::-1]
    print(r_b + S + r_f)

Buggy python submission (verdict: Runtime Error):
S = input().split()
N = int(input())
reverse = 0
r_b = []
r_f = []
for i in range(N):
    line = input().split()
    if line[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if line[i][1] == '1' :
                r_f = [line[i][2]] + r_f
            else :
                r_b.append(line[i][2])
        else:
            if line[i][1] == '1':
                r_b.append(line[i][2])
            else:
                r_f = [line[i][2]] + r_f

if reverse == 0 :
    S = r_f + S + r_b
    print("".join(S))
else:
    S.reverse()
    r_b.reverse()
    r_f.reverse()
    S = r_b + S + r_f
    print("".join(S))

Fixed submission:
S = input()
N = int(input())
Q = [[] for _ in range(N)]
for i in range(N):
    line = input().split()
    Q[i] = line
reverse = 0
r_b = ""
r_f = ""
for i in range(N):
    if Q[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if Q[i][1] == '1' :
                r_f = Q[i][2] + r_f
            else :
                r_b = r_b +Q[i][2]
        else:
            if Q[i][1] == '1':
                r_b = r_b +Q[i][2]
            else:
                r_f = Q[i][2] + r_f
if reverse == 0 :
    print(r_f + S + r_b)
else:
    r_f = r_f[::-1]
    r_b = r_b[::-1]
    S = S[::-1]
    print(r_b + S + r_f)
Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b-1,i))
    graph[b-1].append((a-1,i))
ans = 0
print(graph)
pos = 0
for i in range(N-1):
    if ans < len(graph[i]):
        ans = len(graph[i])
        pos = i
print(ans)

color = [-1 for i in range(N-1)]
def dps(now,pare,par_col=-1):
    col = 1
    for u,idx in graph[now]:
        if u != pare :
            if col == par_col :
                col += 1
            color[idx] = col
            dps(u,now,col)
            col += 1

dps(0,-1,-1)
print("\n".join(map(str,color)))

Fixed submission:
list = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
for i in range(len(list)):
    if S == list[i] :
        print("{}".format(7 - i))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    A = P[now:]
    A.sort()
    index = bisect.bisect_left(A,L[i]+0.1)
    ans += (len(A) - index)
print(ans)

Fixed submission:
import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
P.sort()
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    index = bisect.bisect_left(P,L[i]+0.1)
    ans += (len(P) - index)-now
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
print("{}".foramt(N**3))

Fixed submission:
N = int(input())
a = N * N * N
print("{}".format(a))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
para = [[c for c in input()] for i in range(N)]
for i in range(N):
  para[i].sort()

def check(a,b):

    if a == b :
        return True 
            
a = 0 
for i in range(N):
    for j in range(i+1,N):
        if check(para[i],para[j]):
            a += 1
print(a)

Fixed submission:
N = int(input())
para = [[c for c in input()] for i in range(N)]
b = []
dict = {}
ans = 0
for i in range(N):
    para[i].sort()
    b.append("".join(para[i]))
    if b[i] not in dict:
        dict[b[i]] = 1
    else :
        ans += dict[b[i]]
        dict[b[i]] += 1 

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
para = [input() for i in range(N)]
def check(a,b):
    p = []
    q = []
    for i in range(10):
        if a[i] == b[i] :
            continue
        else :
            p.append(a[i])
            q.append(b[i])
    p.sort()
    q.sort()
    if p == q :
        return True 
            
a = 0 
for i in range(N):
    for j in range(i+1,N):
        if check(para[i],para[j]):
            a += 1
print(a)


Fixed submission:
N = int(input())
para = [[c for c in input()] for i in range(N)]
b = []
dict = {}
ans = 0
for i in range(N):
    para[i].sort()
    b.append("".join(para[i]))
    if b[i] not in dict:
        dict[b[i]] = 1
    else :
        ans += dict[b[i]]
        dict[b[i]] += 1 

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
para_val = []
for i in range(m) :
    a,b = map(int,input().split())
    para_val.append([i for i in range(a,b+1)])

ans = [i for i in range(1,n+1)]

for i in range(m):
    ans = list(set(ans) & set(para_val[i]))

print(len(ans))

Fixed submission:
n,m = map(int,input().split())
para_val = []
for i in range(m) :
    a,b = map(int,input().split())
    para_val.append([a,b])

migi = []
hidari = []
for i,j in para_val:
    migi.append(i)
    hidari.append(j)

a = max(migi)
b = min(hidari)

if b - a >= 0 : print("{}".format(b-a+ 1))
else : print("0")

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
para_val = []
for i in range(m) :
    a,b = map(int,input().split())
    para_val.append([a,b])


ans = [[] for i in range(m+1)]
ans[0] = [(i+1) for i in range(n)]
for i in range(m):
    for j in range(len(ans[i])):
        if para_val[i][0] <= ans[i][j] <= para_val[i][1]:
            ans[i+1].append(ans[i][j])
print(len(ans[-1]))


Fixed submission:
n,m = map(int,input().split())
para_val = []
for i in range(m) :
    a,b = map(int,input().split())
    para_val.append([a,b])

migi = []
hidari = []
for i,j in para_val:
    migi.append(i)
    hidari.append(j)

a = max(migi)
b = min(hidari)

if b - a >= 0 : print("{}".format(b-a+ 1))
else : print("0")
Buggy python submission (verdict: Runtime Error):
input_val = []
for i in range(6) :
    input_val.append(int(input()))

input_size = len(input_val)
count = 0
for i in range(5) :
    stan_val = input_val[i]
    for j in range(i+1,5) :
        diff = abs(stan_val - input_val[j])
        if diff > input_val[5] :
            count += 1
            
        else : count = count

if count == 0 :
   print("Yay!")
else : print(":(")

Fixed submission:
a,b = [int(i) for i in input().split()]

x = 0
for i in range(2) :
    c = max(a,b)
    if c == a :
        x += a 
        a = a - 1
    else : 
        x += b
        b = b -1

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
class Heap:
    def __init__(self):
        self.sz = 0
        self.heap = []
    def push(self,x):
        cost = x[3]
        self.heap.append(x)
        i = self.sz
        self.sz += 1
        while i > 0 :
            p = int((i-1)/2)
            if p >= 0 and self.heap[p][3] <= cost:
                self.heap[i] = self.heap[p]
                i = p
            else :
                break
        self.heap[i] = x
    def pop2(self):
        ret = self.heap[0]
        cost = self.heap[-1]
        self.heap.pop(-1)
        self.sz -= 1
        i = 0
        while 2*i+1 < self.sz :
            a = 2 * i + 1
            b = 2 * i + 2
            if b < self.sz and self.heap[a][3] < self.heap[b][3] :
                a = b
            if self.heap[a][3] <= cost[3]:
                break
            self.heap[i] = self.heap[a]
            i = a
        self.heap[i] = cost
        return ret[3]



def main():
    X,Y,Z,K = map(int,input().split())
    size = max(X,Y,Z)
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    i = Heap()
    i.heap = [[0,0,0,A[0]+B[0]+C[0]],[0,0,0,0]]
    i.sz = 2
    count = [[[0 for i in range(Z+1)] for j in range(Y+1)] for k in range(X+1)]
    for p in range(K):
        x = i.heap[0]
        if x[0] + 1 < X  and count[x[0]+1][x[1]][x[2]] == 0 :
            i.push([x[0]+1, x[1] , x[2], A[x[0] + 1] + B[x[1]] + C[x[2]]])
            count[x[0] + 1][x[1]][x[2]] = 1
        if x[1] + 1 < Y  and count[x[0]][x[1]+1][x[2]] == 0:
            i.push([x[0], x[1] + 1, x[2], A[x[0]] + B[x[1] + 1 ] + C[x[2]]])
            count[x[0]][x[1] + 1][x[2]] = 1
        if x[2] + 1 < Z and count[x[0]][x[1]][x[2]+1] == 0:
            i.push([x[0] , x[1], x[2] + 1 , A[x[0]] + B[x[1]] + C[x[2] + 1 ]])
            count[x[0]][x[1]][x[2] + 1] = 1
        print(i.pop2())

if __name__ ==  "__main__":
    main()

Fixed submission:
import heapq

def main():
    X, Y, Z, K = map(int,input().split())
    A = [int(o) for o in input().split()]
    B = [int(o) for o in input().split()]
    C = [int(o) for o in input().split()]
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    A_size = len(A)
    B_size = len(B)
    C_size = len(C)
    heap = []
    heapq.heappush(heap,(-(A[0]+B[0]+C[0]),0,0,0))
    for i in range(K):
        val,a,b,c = heapq.heappop(heap)
        if a < (A_size-1) and (-(A[a+1]+B[b]+C[c]),a+1,b,c) not in heap:
            heapq.heappush(heap,(-(A[a+1]+B[b]+C[c]),a+1,b,c))
        if b < (B_size-1) and (-(A[a]+B[b+1]+C[c]),a,b+1,c) not in heap:
            heapq.heappush(heap,(-(A[a]+B[b+1]+C[c]),a,b+1,c))
        if c < (C_size-1) and (-(A[a]+B[b]+C[c+1]),a,b,c+1) not in heap:
            heapq.heappush(heap,(-(A[a]+B[b]+C[c+1]),a,b,c+1))
        print(-val)
if __name__ == "__main__" :
    main()
Buggy python submission (verdict: Runtime Error):
N, Q = map(int,input().split())
S = list(input())
'''
dp[i]: 1 ~ i 番目までにacが何個あるのか　
 dp[i+1] = dp[i] (S[i]=="A" and S[i+1] == "C")
         = dp[i] (else)
'''
dp = [0 for i in range(N+10)]
for i in range(1,N+1):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]

for i in range(Q) :
    a,b = map(int,input().split())
    print("{}".format(dp[b-1]-dp[a-1]))

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

dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]
val = [[] for i in range(Q)]
for i in range(Q) :
    a,b = map(int,input().split())
    val[i] = [a-1,b-1]
for i in range(Q):
    print("{}".format(dp[val[i][1]]-dp[val[i][0]]))

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
q_con = []
for i in range(q) :
    q_con.append(list(map(int,input().split())))

count = [0 for i in range(q)]

list_2 = [i for i in range(q)]
list_3 = [i for i in range(q)]
for i in range(q) :

    a = q_con[i][0] - 1
    b = q_con[i][1] 
    list_2[i] = s[:][a:b]
    list_3[i] = list_2[:][i].replace("AC","")
    p = (len(list_2[i])-len(list_3[i]))/2
    print("{}".format(int(p)))



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

dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]
val = [[] for i in range(Q)]
for i in range(Q) :
    a,b = map(int,input().split())
    val[i] = [a-1,b-1]
for i in range(Q):
    print("{}".format(dp[val[i][1]]-dp[val[i][0]]))

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = str(input().split())

q_con = []
for i in range(q) :
    q_con.append(list(map(int,input().split())))



count = [0 for i in range(q)]
for i in range(q) :
    a = q_con[i][0] + 1
    b = q_con[i][1] + 1
    for j in range(a,b) :
        if s[j] == "A" and s[j+1] == "C" :
            count[i] += 1
        else : pass 

for i in count :
    print(i)


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

dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]
val = [[] for i in range(Q)]
for i in range(Q) :
    a,b = map(int,input().split())
    val[i] = [a-1,b-1]
for i in range(Q):
    print("{}".format(dp[val[i][1]]-dp[val[i][0]]))
Buggy python submission (verdict: Time Limit Exceeded):
s = [int(i) for i in input()]
size = len(s)

def operation(strings):
    rest = []
    count = 0

    for i in range(len(strings)-1) :
        if strings[i] != strings[i+1] and count - 1  != i :
            rest.extend(strings[count:i])
            count = i + 2

    rest.extend(strings[count:])
    return rest 


while True :
    
    s = operation(s)
    if sum(s)  == len(s)  or sum(s)== 0:
        break
    else : continue
    
    
ans = size - len(s)
print(ans)

Fixed submission:
S = input()
s = list(S)
size = len(S)
stack = []
for i in range(size):
    if len(stack) == 0 :
        stack.append(s[i])
    else :
        if stack[-1] != s[i] :
            stack.pop(-1)
        else :
            stack.append(s[i])

print("{}".format(size-len(stack)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
height = [int(i) for i in input().split()] + [0]
k = 0
while True :
    for i in range(N):
        if height[i] > 0 :
            lv = i 
            break 

    for i in range(lv,N+1):
        if height[i] == 0 :
            uv = i 
            break 
    for i in range(lv,uv):
        height[i] -= 1
    k += 1
    if sum(height) == 0 :
        break 
print(k)

Fixed submission:
N = int(input())
height = [int(i) for i in input().split()] + [0]
k = 0
while True :
    if sum(height) == 0 :
        break 
    for i in range(N):
        if height[i] > 0 :
            lv = i 
            break 

    for i in range(lv,N+1):
        if height[i] == 0 :
            uv = i 
            break 
    for i in range(lv,uv):
        height[i] -= 1
    k += 1
print(k)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
para = []
for i in range(M):
    a,b = map(int,input().split())
    para.append([a,b,i])
para.sort(key = lambda x:(x[0],x[1]))
ans = []
memo = []
for i in range(M):
    if para[i][0] not in memo :
        cnt = 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
        memo.append(para[i][0])
    else : 
        cnt += 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
ans.sort(key=lambda x:x[1])
for i in range(M):
    print(ans[i][0])

Fixed submission:
N,M = map(int,input().split())
para = []
for i in range(M):
    a,b = map(int,input().split())
    para.append([a,b,i])
para.sort(key = lambda x:(x[0],x[1]))
ans = []
memo = [-1 for i in range(N+1)]
for i in range(M):
    if memo[para[i][0]] == -1 :
        cnt = 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
        memo[para[i][0]] = 0
    else : 
        cnt += 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
ans.sort(key=lambda x:x[1])
for i in range(M):
    print(ans[i][0])