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

num_eas = s.count('E')



minres = 1000000
for i in range(n):
    a = s[:i].count("W")
    res = 2*a + num_eas - i
    if res < minres:
        minres = res

print(minres)


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

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))

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

num_wes = s.count('W')
num_eas = s.count('E')


res = []
for i in range(n):
    a = s[:i].count("W")
    res += [2*a + num_eas - i]
    
print(min(res))


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

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))

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

minres = 1000000
for i in range(n):
    res = s[:i].count("W") + s[i+1:].count("E")
    if res < minres:
        minres = res

print(minres)


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

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
res = []

for i in range(n):
    res += [s[:i].count("W") + s[i+1:].count("E")]

print(min(res))


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

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
res = []

for i in range(n):
    res += [s[:i].count("W") + s[i+1:].count("E")]

print(min(res))


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

num_eas = s.count('E')


res = []
res += [num_eas - s[0].count("E")]

for i in range(1,n):
    res += [res[i-1] + s[i-1].count("W") - s[i].count("E")]
    
print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])

Fixed submission:
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if j-i<=6:
            li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1]

Fixed submission:
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if j-i<=6:
            li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])
Buggy python submission (verdict: Runtime Error):
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b,c in itertools.product(list,list,list):
    v = 10*a + 5*b + c
    w = a + b + c
    if v == z and w == n:
        break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))


Fixed submission:
print("2018"+input()[4:])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b,c in itertools.product(list,list,list):
    v = 10*a + 5*b + c
    w = a + b + c
    if v == z and w == n:
        break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))


Fixed submission:
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b in itertools.product(list,list):
    c = n - a - b
    if c>=0:
        v = 10*a + 5*b + c
        w = a + b + c
        if v == z and w == n:
            break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b,c in itertools.product(list,list,list):
    v = 10*a + 5*b + c
    w = a + b + c
    if v == z and w == n:
        break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))

Fixed submission:
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b in itertools.product(list,list):
    c = n - a - b
    if c>=0:
        v = 10*a + 5*b + c
        w = a + b + c
        if v == z and w == n:
            break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ee = [list(map(int,input().split())) for _ in range(m)]

cnt = 0
for p in range(m):
    e = ee[:p] + ee[p+1:]
    dist = [[float("inf")]*n for _ in range(n)]
    
    for i in range(m-1):
        s,t = e[i]
        dist[s-1][t-1]=1
        dist[t-1][s-1]=1

    for i in range(n):
        dist[i][i]=0
    #[print(*dist[l]) for l in range(n)]
    #print("-------------------------")

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dist[i][k] != float("inf") and dist[k][j] != float("inf"):
                   dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    #[print(*dist[l]) for l in range(n)]
    #print("-------------------------")

    flag = True
    for i in range(n):
        if flag == False:
            break
        for j in range(n):
            if dist[i][j]==float("inf"):
                cnt += 1
                flag = False
                break
print(cnt)
 

Fixed submission:
n,m = map(int,input().split())
ee = [list(map(int,input().split())) for _ in range(m)]

cnt = 0
for p in range(m):
    e = ee[:p] + ee[p+1:]
    dist = [[float("inf")]*n for _ in range(n)]
    
    for i in range(m-1):
        s,t = e[i]
        dist[s-1][t-1]=1
        dist[t-1][s-1]=1

    for i in range(n):
        dist[i][i]=0
    #[print(*dist[l]) for l in range(n)]
    #print("-------------------------")

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dist[i][k] != float("inf") and dist[k][j] != float("inf"):
                   dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    #[print(*dist[l]) for l in range(n)]
    #print("-------------------------")

    flag = True
    for i in range(n):
        if flag == False:
            break
        for j in range(n):
            if dist[i][j]==float("inf"):
                cnt += 1
                flag = False
                break
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
n = int(input())
dist = [list(map(int,input().split())) for _ in range(n)]
e = copy.deepcopy(dist)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dist[i][j]>dist[i][k] + dist[k][j]:
                print(-1)
                sys.exit()
            if i!=j and i!=k and j!=k and dist[i][j]==dist[i][k] + dist[k][j]:
                #print(i,j,k)
                e[i][j]=float("inf")

#[print(*dist[l]) for l in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if e[i][j]!=float("inf"):
            ans += dist[i][j]
print(ans//2)



Fixed submission:
import sys
import copy
n = int(input())
dist = [list(map(int,input().split())) for _ in range(n)]
e = copy.deepcopy(dist)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dist[i][j]>dist[i][k] + dist[k][j]:
                print(-1)
                sys.exit()
            if i!=j and i!=k and j!=k and dist[i][j]==dist[i][k] + dist[k][j]:
                #print(i,j,k)
                e[i][j]=float("inf")

#[print(*dist[l]) for l in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if e[i][j]!=float("inf"):
            ans += dist[i][j]
print(ans//2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
n = int(input())
dist = [list(map(int,input().split())) for _ in range(n)]
e = copy.deepcopy(dist)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dist[i][j]>dist[i][k] + dist[k][j]:
                print(-1)
                sys.exit()
            if dist[i][j]==dist[i][k] + dist[k][j] and i!=j and i!=k and j!=k:
                #print(i,j,k)
                e[i][j]=float("inf")

#[print(*dist[l]) for l in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if e[i][j]!=float("inf"):
            ans += dist[i][j]
print(ans//2)

Fixed submission:
import sys
import copy
n = int(input())
dist = [list(map(int,input().split())) for _ in range(n)]
e = copy.deepcopy(dist)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dist[i][j]>dist[i][k] + dist[k][j]:
                print(-1)
                sys.exit()
            if i!=j and i!=k and j!=k and dist[i][j]==dist[i][k] + dist[k][j]:
                #print(i,j,k)
                e[i][j]=float("inf")

#[print(*dist[l]) for l in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if e[i][j]!=float("inf"):
            ans += dist[i][j]
print(ans//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
def dfs(A, start):
    global ans
    if len(A) == 2:
        ans += ((A[0]*A[1])%MOD)
        return
    else:
        for i in range(start, len(a)):
            A.append(a[i])
            dfs(A, i+1)
            A.pop()

dfs([], 0)
print(ans%MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
acc = [0]
ans = 0
for i in a:
    acc.append(acc[-1]+i)
acc = acc[1:]
for i, v in enumerate(a):
    ans += (v*(acc[-1]-acc[i]))%MOD
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
g = [[] for _ in range(n)]
visited = [-1] * n
for a, b in ab:
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
# print(g)
def dfs(start):
    global visited
    if visited[start] != -1:
        return 
    stack = []
    stack.append(start)
    visited[start] = start
    while stack:
        root = stack.pop()
        for j in g[root]:
            if visited[j] == -1:
                visited[j] = start
                stack.append(j)

for i in range(n):
    dfs(i)
# print(visited)
tmp = Counter(visited)
# print(tmp)
p = sorted([v for i, v in tmp.items() if v != 1])
island = len(p)
# print(island)
if island == 1:
    print(n)
else:
    print(p[-1])

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

if m == 0:
    print(1)
    exit()
    
g = [[] for _ in range(n)]
visited = [-1] * n
for a, b in ab:
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
# print(g)
def dfs(start):
    global visited
    if visited[start] != -1:
        return 1
    stack = []
    stack.append(start)
    visited[start] = start
    while stack:
        root = stack.pop()
        for j in g[root]:
            if visited[j] == -1:
                visited[j] = start
                stack.append(j)

for i in range(n):
    dfs(i)
# print(visited)
tmp = Counter(visited)
# print(tmp)
p = sorted([v for i, v in tmp.items() if v != 1])
island = len(p)
# print(island)
if island == 1:
    print(n)
else:
    print(p[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = list(input())
flag = False
ans = 0
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
for i in range(n//2):
    if c[i] == "R" and c[n-i-1] == "W":
        continue
    else:
        if c[i] == "W" and c[n-i-1] == "R":
            c[i] = "R"
            c[n-i-1] = "W"
            ans += 1
        elif c[i] == "W" and c[n-i-1] == "W":
            for j in range(n-i,i+1,-1):
                if c[j] == "R":
                    c[i] = "R"
                    c[j] = "W"
                    break
            ans += 1
        elif c[i] == "R" and c[n-i-1] == "R":
            for j in range(i+1, n-i-1):
                if c[j] == "W":
                    c[n-i-1] = "W"
                    c[j] = "R"  
                    break
            ans += 1
print(ans)

Fixed submission:
n = int(input())
c = list(input())
print(len([i for i, j in zip(sorted(c), c) if i != j])//2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
c = list(input())
flag = False
ans = 0
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
if c[0] == "W" and c[-1] == "R":
    ans += 1
    c[0], c[-1] = "R", "W"
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "W":
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "R":
    for i, v in enumerate(a):
        if i != 0 and v == "W":
            c[i] = "R"
            c[-1] = "W"
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
else:
    for i, v in enumerate(reversed(a)):
        if i != 0 and v == "R":
            c[n-1-i] = "W"
            c[0] = "R"
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)

Fixed submission:
n = int(input())
c = list(input())
print(len([i for i, j in zip(sorted(c), c) if i != j])//2)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
# 累積積を求める
acc = []
acc.append(a[0])
for v in a[1:]:
    acc.append(acc[-1]*v)
cand = []
cand.append(acc[k-1])
tmp = k
while tmp <= n-1:
    cand.append(acc[tmp]//acc[tmp-k])
    tmp += 1
for i in range(len(cand)-1):
    if cand[i] < cand[i+1]:
        print("Yes")
    else:
        print("No")

Fixed submission:
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
for i in range(n-k):
    if a[i] < a[i+k]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for i in a:
    ans *= i
print("-1" if ans > 10**18 else ans)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print("-1")
        exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
print("-1" if ans>10**18 else ans)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print("-1")
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Fixed submission:
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Buggy python submission (verdict: Runtime Error):
T = input()
T = list(T)
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Fixed submission:
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Buggy python submission (verdict: Runtime Error):
T = input()
T = list(T)
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if T[i+1] == D:
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Fixed submission:
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Buggy python submission (verdict: Runtime Error):
T = input()
T = list(T)
for i, v in enumerate(T):
    if i == 0:
        if T[i] == "?":
            if T[i+1] == D:
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

Fixed submission:
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
g = dict()

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = dict()
for i in range(k):
    target = g[target]
    if target not in visited:
        visited[target] = True
    else:
        p = find_num(target)
        break
for _ in range((k-1-i)%p):
    target = g[target]
print(target)

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

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = dict()
flag = False
for i in range(k):
    target = g[target]
    if target not in visited:
        visited[target] = True
    else:
        p = find_num(target)
        flag = True
        break
if flag:
    for _ in range((k-1-i)%p):
        target = g[target]
    print(target)
else:
    print(target)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
g = dict()

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = []
flag = False
for i in range(k):
    target = g[target]
    if target not in visited:
        visited.append(target)
    else:
        p = find_num(target)
        flag = True
        break
if flag:
    for _ in range((k-1-i)%p):
        target = g[target]
    print(target)
else:
    print(target)

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

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = dict()
flag = False
for i in range(k):
    target = g[target]
    if target not in visited:
        visited[target] = True
    else:
        p = find_num(target)
        flag = True
        break
if flag:
    for _ in range((k-1-i)%p):
        target = g[target]
    print(target)
else:
    print(target)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    whole = (n*(n-1)*(n-2))//6
    num = n-2
    cnt = 0
    for i in range(n-3):
        for j in range(i+1,n-1):
            if j == i+1:
                if s[i] == s[j]:
                    cnt += (n-(j+2))
                    continue
                for k in range(j+2,n):
                    if (j-i) == (k-j) or s[j] == s[k] or s[i] == s[k]:
                        cnt += 1
            else:
                if s[i] == s[j]:
                    cnt += (n-(j+1))
                    continue
                for k in range(j+1,n):
                    if (j-i) == (k-j) or s[j] == s[k] or s[i] == s[k]:
                        cnt += 1
    print(whole-num-cnt)

if __name__ == "__main__":
    main()

Fixed submission:
n = int(input())
S = input()
k = 0
num = 0
r, g, b = 0, 0, 0
for s in S:
    if s == "R": r += 1
    elif s == "G": g += 1
    else: b += 1
whole = r * g * b
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2 * j - i
        if k >= n:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            num += 1
print(whole - num)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
whole = (n*(n-1)*(n-2))//6
num = n-2
cnt = 0
for i in range(n-3):
    for j in range(i+1,n-1):
        if j == i+1:
            if s[i] == s[j]:
                cnt += (n-(j+2))
                continue
            for k in range(j+2,n):
                if (j-i) == (k-j):
                    cnt += 1
                    continue
                if s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
                    cnt+= 1
        else:
            if s[i] == s[j]:
                cnt += (n-(j+1))
                continue
            for k in range(j+1,n):
                if (j-i) == (k-j):
                    cnt += 1
                    continue
                if s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
                    cnt+= 1
print(whole-num-cnt)

Fixed submission:
n = int(input())
S = input()
k = 0
num = 0
r, g, b = 0, 0, 0
for s in S:
    if s == "R": r += 1
    elif s == "G": g += 1
    else: b += 1
whole = r * g * b
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2 * j - i
        if k >= n:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            num += 1
print(whole - num)