Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0


Fixed submission:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5+1)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0


Fixed submission:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5+1)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
input()
A = [int(a) for a in input().split()]
d = Counter(A)
sum_ = sum(A)
for q in range(int(input())):
    B,C = map(int,input().split())
    sum_ += ((C - B) * d[B])
    d[C] += d[B]
    del d[B]
    sum2 = 0
    for k,v in d.items():
        sum2 += k*v
    print(sum2)    

Fixed submission:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5+1)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
for q in range(int(input())):
    B,C = input().split()
    A = list(map(lambda x: x.replace(B,C),A))
    print(sum(map(lambda x: int(x),A)))

Fixed submission:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5+1)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
for q in range(int(input())):
    B,C = input().split()
    A = list(map(lambda x: x.replace(B,C),A))
    print(sum(map(lambda x: int(x),A)))

Fixed submission:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split()])
ans = sum(A)
lst = np.zeros(10**5+1)
for a in A:
    lst[a] += 1
   
for q in range(int(input())):
    B,C = map(int,input().split())
    ans += (C - B) * lst[B]
    print(int(ans))
    lst[C] += lst[B]
    lst[B] = 0
Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
    if ans > a:
        print(-1)
        exit()
    print(ans)  


Fixed submission:
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
for i in A:
    ans *= i
if ans > a:
    print(-1)
else:
    print(ans)  

Fixed submission:
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
for i in A:
    ans *= i
if ans > a:
    print(-1)
else:
    print(ans)  

Fixed submission:
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
ans = 1
for i in A:
    ans *= i
print(-1 if ans>10**18 else ans)  


Fixed submission:
N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from bisect import bisect

def soinsuu_bunkai(n):
    ret = {}
    p = 2
    while p * p <= n:
        while n % p == 0:
            ret[p]= ret[p]+1 if p in ret else 1
            n //= p
        p += 1
    if n != 1:
        ret[n] = 1
    return ret   
    
def make_triangle(n):
    lst = []
    sum_ = 0
    for i in range(1,n+1):
        sum_ += i
        lst.append(sum_)
    return lst    

N = int(input())
dic = soinsuu_bunkai(N)
lst = make_triangle(N)
#print(lst)
#print(dic)
ans = 0
for k,v in dic.items():
    b = bisect(lst,v)
    #print(b)
    ans += b
print(ans)    


Fixed submission:
from functools import reduce
from bisect import bisect

def soinsuu_bunkai(n):
    ret = {}
    p = 2
    while p * p <= n:
        while n % p == 0:
            ret[p]= ret[p]+1 if p in ret else 1
            n //= p
        p += 1
    if n != 1:
        ret[n] = 1
    return ret   
    
def make_triangle(n):
    cnt = 0
    sum_ = 0
    for i in range(1,n+1):
        sum_ += i
        if sum_ > n:
            break
        else:
            cnt += 1
    return cnt    

dic = soinsuu_bunkai(int(input()))
ans = 0
for k,v in dic.items():
    ans += make_triangle(v)  
print(ans)

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

n = N
memo = []
cnt = 0
while N > 1:
    for i in range(2,N+1):
        if i in memo:
            continue
        if N % i == 0:
            memo.append(i)
            n = N // i
            cnt += 1
        N = n    
print(cnt)        

Fixed submission:
from functools import reduce
from bisect import bisect

def soinsuu_bunkai(n):
    ret = {}
    p = 2
    while p * p <= n:
        while n % p == 0:
            ret[p]= ret[p]+1 if p in ret else 1
            n //= p
        p += 1
    if n != 1:
        ret[n] = 1
    return ret   
    
def make_triangle(n):
    cnt = 0
    sum_ = 0
    for i in range(1,n+1):
        sum_ += i
        if sum_ > n:
            break
        else:
            cnt += 1
    return cnt    

dic = soinsuu_bunkai(int(input()))
ans = 0
for k,v in dic.items():
    ans += make_triangle(v)  
print(ans)
Buggy python submission (verdict: Runtime Error):
import networkx as nx

N,M = map(int,input().split())
G = nx.Graph()
for i in range(M):
    A,B = map(int,input().split())
    G.add_edge(A,B)
print("Yes")
pre = nx.predecessor(G,1)
for i in range(2,N+1):
    print(pre[i][0])

Fixed submission:
import networkx as nx

N,M = map(int,input().split())
G = nx.Graph()
for i in range(M):
    A,B = map(int,input().split())
    G.add_edge(A,B)
print("Yes")
pre = nx.predecessor(G,1)
for i in range(2,N+1):
    print(pre[i][0])

Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx

N,M = map(int,input().split())
G = nx.Graph()
for i in range(M):
    A,B = map(int,input().split())
    G.add_edge(A,B)
print("Yes")
for i in range(2,N+1):
    pre = nx.predecessor(G,1)
    print(pre[i][0])

Fixed submission:
import networkx as nx

N,M = map(int,input().split())
G = nx.Graph()
for i in range(M):
    A,B = map(int,input().split())
    G.add_edge(A,B)
print("Yes")
pre = nx.predecessor(G,1)
for i in range(2,N+1):
    print(pre[i][0])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split()) 
A = [int(i)-1 for i in input().split()]
now = 0

while K:
    if K % 2: 
        now = A[now]
    tmp = A[:]
    for i in range(N):
        tmp[i] = A[A[i]]
    A = tmp[:]
    K //= 2
print(now + 1)

Fixed submission:
N,K = map(int,input().split()) #N = 4,K=5
A = [int(i)-1 for i in input().split()]
log_K = K.bit_length() #3bit (5 = 101)
next = [[-1]*N for _ in range(log_K)]

for i in range(N):
    next[0][i] = A[i]
    
for k in range(log_K - 1):
    for i in range(N):
        next[k+1][i] = next[k][next[k][i]]  

now = 0
for i in range(log_K)[::-1]: 
    if ((K >> i) & 1) == 1: 
        now = next[i][now]
print(now + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split()) #N = 4,K=5
A = [int(i)-1 for i in input().split()]
log_K = K.bit_length() #3bit (5 = 101)
next = [[-1]*N for _ in range(log_K)]

for i in range(N):
    next[0][i] = A[i]
    
for k in range(log_K - 1):
    for i in range(N):
        next[k+1][i] = next[k][next[k][i]]  

now = 0
for i in range(log_K)[::-1]: 
    if ((K >> i) & 1) == 1: 
        now = next[i][now]
print(now + 1) 

Fixed submission:
N,K = map(int,input().split()) #N = 4,K=5
A = [int(i)-1 for i in input().split()]
log_K = K.bit_length() #3bit (5 = 101)
next = [[-1]*N for _ in range(log_K)]

for i in range(N):
    next[0][i] = A[i]
    
for k in range(log_K - 1):
    for i in range(N):
        next[k+1][i] = next[k][next[k][i]]  

now = 0
for i in range(log_K)[::-1]: 
    if ((K >> i) & 1) == 1: 
        now = next[i][now]
print(now + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
cnt = 0
for a in range(1,N):
    for b in range(a+1,N+1):
        if abs(b-a) == A[a-1] + A[b-1]:
            cnt += 1
print(cnt)            

Fixed submission:
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
cnt = 0
for i in range(1,N+1):
    if i in l and i in r:
        cnt += l[i] * r[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
import itertools

abcd = []
N,M,Q = map(int,input().split())
for i in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append([a,b,c,d])
  
A = (list(itertools.product(list(range(1,M+1)),repeat=N)))

ans = 0
for i in A: )
    _sum = 0
    for j in abcd: 
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            _sum += j[3]
    if ans < _sum:
        ans = _sum
    
print(ans)        
            

Fixed submission:
import itertools

abcd = []
N,M,Q = map(int,input().split())
for i in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append([a,b,c,d])
  
A = itertools.combinations_with_replacement(list(range(1,M+1)),N)
ans = 0
for i in A: 
    _sum = 0
    for j in abcd: 
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            _sum += j[3]
    if ans < _sum:
        ans = _sum
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
for i in range(1,N+1):
    print(A.count(i))

Fixed submission:
from collections import Counter

N,*A = map(int,open(0).read().split())
c = Counter(A)
for i in range(1,N+1):
    if i not in c:
        print(0)
    else:
        print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,*A = map(int,open(0).read().split())
for i in range(1,N+1):
    print(A.count(i))

Fixed submission:
from collections import Counter

N,*A = map(int,open(0).read().split())
c = Counter(A)
for i in range(1,N+1):
    if i not in c:
        print(0)
    else:
        print(c[i])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
lst = list(range(0,N+1))
cnt = 0
for i in range(K,N+1):
    start = sum(lst[:i])
    end = sum(lst[-i:])
    cnt += end - start + 1
cnt += 1    
print(cnt)

Fixed submission:
N,K = map(int,input().split())
lst = list(range(0,N+1))
m = 10**9 + 7
cnt = 0
start = sum(lst[:K])
end = sum(lst[-K:])
cnt += end - start + 1
for i in range(K+1,N+2):
    start += lst[i-1] 
    end += lst[-i]
    cnt += end - start + 1
print(cnt % m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [*input()]
ans = 0
for left in range(N-2):
    for mid in range(left+1,N-1):
        for right in range(mid+1,N):
            if S[left]==S[mid] or S[left]==S[right] or S[mid]==S[right]:
                continue
            if mid - left == right - mid:
                continue
            ans += 1
print(ans)            
       

Fixed submission:
N = int(input())
S = input()     
all = S.count("R") * S.count("G") * S.count("B")
reigai = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2 * j - i
        if k > N-1:
            break
        if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
            reigai += 1
print(all - reigai)
Buggy python submission (verdict: Runtime Error):
from collections import deque

def make_lunlun():
    lst = []
    que = deque([1,2,3,4,5,6,7,8,9])
    for i in range(10):
        str_num = str(que.popleft())
        str_one = str_num[-1]
        a = str(int(str_one) - 1)
        b = str(int(str_one) + 1)
        #minus = int(str_num + a)
        same = int(str_num + str_one)
        #plus = int(str_num + b)
        if 0 < int(str_one) < 9:
            minus = int(str_num + a)
            plus = int(str_num + b)
            que.extend([minus,same,plus])
            lst.extend([minus,same,plus])
        elif int(str_one) == 0:
            plus = int(str_num + b)
            que.extend([same,plus])
            lst.extend([same,plus])
        else:
            minus = int(str_num + a)
            que.extend([minus,same])
            lst.extend([minus,same])
    print(lst[K - 10])    

K = int(input())
if K <= 12:
    print(K)
else:
    make_lunlun()
    

Fixed submission:
from collections import deque

def make_lunlun():
    lst = []
    que = deque([1,2,3,4,5,6,7,8,9])
    for i in range(100000):
        str_num = str(que.popleft())
        str_one = str_num[-1]
        a = str(int(str_one) - 1)
        b = str(int(str_one) + 1)
        #minus = int(str_num + a)
        same = int(str_num + str_one)
        #plus = int(str_num + b)
        if 0 < int(str_one) < 9:
            minus = int(str_num + a)
            plus = int(str_num + b)
            que.extend([minus,same,plus])
            lst.extend([minus,same,plus])
        elif int(str_one) == 0:
            plus = int(str_num + b)
            que.extend([same,plus])
            lst.extend([same,plus])
        else:
            minus = int(str_num + a)
            que.extend([minus,same])
            lst.extend([minus,same])
    print(lst[K - 10])    

K = int(input())
if K <= 12:
    print(K)
else:
    make_lunlun()
Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb
N,M = map(int,input().split())
even = comb(N,2)
odd = comb(M,2)
print(int(even) + int(odd))

Fixed submission:
S = [c for c in input()]
N = len(S) - 1
s1 = S[:(N-1)//2 + 1]
s2 = S[(N+3)//2:]

rs = list(reversed(S))
rs1 = list(reversed(s1))
rs2 = list(reversed(s2))
if S == rs and s1 == rs1 and s2 == rs2:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb
N,M = map(int,input().split())
even = int(comb(N,2))
odd = int(comb(M,2))
print(even + odd)

Fixed submission:
S = [c for c in input()]
N = len(S) - 1
s1 = S[:(N-1)//2 + 1]
s2 = S[(N+3)//2:]

rs = list(reversed(S))
rs1 = list(reversed(s1))
rs2 = list(reversed(s2))
if S == rs and s1 == rs1 and s2 == rs2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb
N,*A = map(int,open(0).read().split())
d = {}
for i in A:
    d[i]= d[i]+1 if i in d else 1
for i in A:
    dd = d.copy()
    dd[i] -= 1
    sum = 0
    for k,v in dd.items():
        sum += comb(v,2,exact=True)
    print(sum)

Fixed submission:
from scipy.misc import comb
N,*A = map(int,open(0).read().split())
d = {}
for i in A:
    d[i]= d[i]+1 if i in d else 1
count_d = {}
sum = 0
for k,v in d.items():
    count_d[k] = comb(v,2,exact=True)
    sum += count_d[k] 
 
for i in A:
    if count_d[i]>=1:
        print(sum - (d[i]-1))
    else:
        print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
S=[c for c in input()]
Q=int(input())
for i in range(Q):
    t=[a for a in input().split()]
    if t[0]=="1":
        S.reverse()
    else:
        if t[1]=="1":
            S.insert(0,t[2])
        else:
            S.append(t[2])
print("".join(S))            
    


Fixed submission:
from collections import deque
S=deque([c for c in input()])
Q=int(input())
flg=True
for i in range(Q):
    l=[a for a in input().split()]
    if l[0]=="1": 
        flg=not flg
    else:
        if l[1]=="1":
            if flg:
                S.appendleft(l[2])
            else:
                S.append(l[2])
        else:
            if flg:
                S.append(l[2])
            else:
                S.appendleft(l[2])
print("".join(S) if flg else "".join(list(reversed(S))))

Buggy python submission (verdict: Time Limit Exceeded):
S=[c for c in input()]
ans=S[:]
Q=int(input())
for i in range(Q):
    t=[a for a in input().split()]
    if t[0]=="1":
        ans=ans[::-1]
    else:
        if t[1]=="1":
            ans.insert(0,t[2])
        else:
            ans.append(t[2])
print("".join(ans))            
    

Fixed submission:
from collections import deque
S=deque([c for c in input()])
Q=int(input())
flg=True
for i in range(Q):
    l=[a for a in input().split()]
    if l[0]=="1": 
        flg=not flg
    else:
        if l[1]=="1":
            if flg:
                S.appendleft(l[2])
            else:
                S.append(l[2])
        else:
            if flg:
                S.append(l[2])
            else:
                S.appendleft(l[2])
print("".join(S) if flg else "".join(list(reversed(S))))
Buggy python submission (verdict: Runtime Error):
n,k,*p=map(int,open(0).read().split())
p.sort()
p.reverse()
l=p[:k]
_sum=0
before=l[0]
rate=1
for i in range(len(l)):
    s=0
    if i!=0:
        if l[i]==before:
            rate*=2
        else:
            before=l[i]
            rate=1
        for j in range(1,l[i]+1):
            s+=j
        _sum+=s/l[i]/rate    
    else:
        for j in range(1,l[i]+1):
            s+=j
        _sum+=s/l[i]
print(_sum) 

        
        

 


       




























Fixed submission:
n,k,*p=map(int,open(0).read().split())
l=[]
l.append(sum(p[:k]))
for i in range(k,n):
    l.append(l[-1]+p[i]-p[i-k])
ind=l.index(max(l))
ans=0
for i in range(k):
    ans += (1+p[ind+i])/2
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k,*p=map(int,open(0).read().split())
p.sort()
p.reverse()
l=p[:k]
print(l)
_sum=0
before=l[0]
rate=1
for i in range(len(l)):
    s=0
    if i!=0:
        if l[i]==before:
            rate*=2
        else:
            before=l[i]
            rate=1
        for j in range(1,l[i]+1):
            s+=j
        _sum+=s/l[i]/rate          
    else:
        for j in range(1,l[i]+1):
            s+=j
        _sum+=s/l[i]
print(_sum) 

        
        

 


       




























Fixed submission:
n,k,*p=map(int,open(0).read().split())
l=[]
l.append(sum(p[:k]))
for i in range(k,n):
    l.append(l[-1]+p[i]-p[i-k])
ind=l.index(max(l))
ans=0
for i in range(k):
    ans += (1+p[ind+i])/2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,*p=map(int,open(0).read().split())
a=[]
cnt=0
for i in range(1,n):
  a.append(min(p[0:i]))  
for i,j in zip(a,p[1:]):
  if i<j:
    cnt+=1
print(n-cnt)    

Fixed submission:
n,*p=map(int,open(0).read().split())
_min=max(p)
cnt=0
for i in p:
  _min=min(_min,i)
  if i>_min:
    cnt+=1
print(n-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,*p=map(int,open(0).read().split())
cnt=0
flg=True
for i in range(n):
  flg=True
  for j in range(0,i):
    if p[i]>p[j]:
      flg=False
      break
  if flg:
    cnt+=1
print(cnt)    
   

Fixed submission:
n,*p=map(int,open(0).read().split())
_min=max(p)
cnt=0
for i in p:
  _min=min(_min,i)
  if i>_min:
    cnt+=1
print(n-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,*p=map(int,open(0).read().split())
flg=True
cnt=0
for i in range(n):
  flg=True
  for j in range(i):
    if p[i]>p[j]:
      flg=False
  if flg:
    cnt+=1   
print(cnt)  


Fixed submission:
n,*p=map(int,open(0).read().split())
_min=max(p)
cnt=0
for i in p:
  _min=min(_min,i)
  if i>_min:
    cnt+=1
print(n-cnt)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
arr = np.full((n,n),9)
for i in range(n):
  nn = int(input())
  for j in range(nn):
    a,b = map(int,input().split())
    arr[i][a-1] = b

arr2 = arr.T
cnt = 0
for i in range(n):
  for j in range(n):
    if arr[i][j]==0 and arr2[i][j]==0:
      cnt += 1
    elif arr[i][j]==1 and arr2[i][j]==1:
      cnt+=1

print(cnt)

Fixed submission:
a,b,c = map(int, input().split())
print("win" if a+b+c <= 21 else "bust")
Buggy python submission (verdict: Runtime Error):
s = [*input()]
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: #一番最初
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): #符号が切り替わった時
        #前グループの処理
        if base == 1:
            b.reverse()
        max_ = max(a[-1],b[0])
        a.pop(-1)
        b[0] = max_
        a.extend(b)
        #新しい処理
        b = [0,1]
        base = hugo.index(s[i])
    else: #同じ符号が続いてる時
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: #一番ラストの符号
    b.append(b[-1] + 1)
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)    
else:
    #前グループの処理
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
    #今回の処理
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))
    

Fixed submission:
s = [*input()]
if len(s) == 1:
    print(1)
    exit()
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: #一番最初
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): #符号が切り替わった時
        #前グループの処理
        if base == 1:
            b.reverse()
        max_ = max(a[-1],b[0])
        a.pop(-1)
        b[0] = max_
        a.extend(b)
        #新しい処理
        b = [0,1]
        base = hugo.index(s[i])
    else: #同じ符号が続いてる時
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: #一番ラストの符号
    b.append(b[-1] + 1)
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)    
else:
    #前グループの処理
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
    #今回の処理
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from operator import add

n = int(input())
l1 = [int(i) for i in input().split()]
print(reduce(add, [l1[a]*l1[b] for a in range(n-1) for b in range(a+1,n)]))



Fixed submission:
a,b = map(int,input().split())
print(a-2*b if a-2*b>=0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[i for i in input()]
flg=True
while flg:
  flg=False
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s.pop(i)
      flg=True
      break
print(len(s))  

Fixed submission:
n=int(input())
s=[i for i in input()]
ss=[s[0]] 
for i in s:
  if ss[-1]!=i:
    ss.append(i)
print(len(ss))
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(i if n == 1 else 0.5 if n%2 == 0 else (n+1)/2/n)


Fixed submission:
n = int(input())
if n == 1:
  print(1)
elif n % 2 == 0:
  print(0.5)
else:
  print((n+1)/2/n)