Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A_ = []
    indices = []
    tmp = sorted(enumerate(A), reverse=True, key=lambda x:x[1])
    for row in tmp:
        k, v = row
        indices.append(k)
        A_.append(v)
    A = A_
    
    dp = [[0 for i in range(N+1)] for j in range(N+1)]
    for i in range(N):
        for j in range(0, N-i):
            a = A[i+j]
            idx = indices[i+j]
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a * abs(idx - i))
            dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a * abs(N - 1 - j - idx))
    result = -1
    for i in range(N):
        tmp = dp[i][N-i]
        if tmp > result:
            result = tmp
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

    dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
    for i in range(N):
        for j in range(0, N - i):
            idx, a = A[i + j]
            #idx = indices[i + j]
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * abs(idx - i))
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a * abs(N - 1 - j - idx))
    result = -1
    for i in range(N):
        tmp = dp[i][N - i]
        if tmp > result:
            result = tmp
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    s = [x-1 for x in s]
    answer = 'x' * N
    for i in range(M):
        if list(answer)[s[i]] == 'x':
            answer = answer[:s[i]] + str(c[i]) + answer[s[i]+1:]
        else:
            if str(c[i]) != answer[s[i]]:
                print(-1)
                return
        if s[i] == 0 and c[i]==0:
            head_flag = True
    answer = ''.join(answer)
    answer = answer.replace('x', '0')
    answer = int(answer)
    answer = str(answer)
    if len(answer) != N and head_flag ==True:
        print(-1)
    elif len(answer) < N:
        answer = '1' + '0' * (N - len(answer) - 1) + answer
        print(answer)
    elif len(answer) == N:
        print(answer)
    else:
        print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    s = [x-1 for x in s]
    answer = 'x' * N
    head_flag = False
    for i in range(M):
        if list(answer)[s[i]] == 'x':
            answer = answer[:s[i]] + str(c[i]) + answer[s[i]+1:]
        else:
            if str(c[i]) != answer[s[i]]:
                print(-1)
                return
        if s[i] == 0 and c[i]==0:
            head_flag = True
    answer = ''.join(answer)
    answer = answer.replace('x', '0')
    answer = int(answer)
    answer = str(answer)
    if len(answer) != N and head_flag ==True:
        print(-1)
    elif len(answer) < N:
        answer = '1' + '0' * (N - len(answer) - 1) + answer
        print(answer)
    elif len(answer) == N:
        print(answer)
    else:
        print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np
import math

def solve(N: int, X: "List[int]"):
    place = np.mean(X)
    place = round(place)
    result = 0
    for i in range(N):
        result += (X[i]-place) ** 2
    print(int(result))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    count = 0
    while True:
        N = N // K
        if N >= 1:
            count += 1
        else:
            break
    print (count+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

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


def solve(N: int, K: int):
    count = 0
    while True:
        N = N // K
        if N >= 1:
            count += 1
        else:
            break
    print (cont)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    count = 0
    while True:
        N = N // K
        if N >= 1:
            count += 1
        else:
            break
    print (count+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def expectation(x):
    return x * (1 + x) / (2 * x)

def solve(N: int, K: int, P: "List[int]"):
    largest = 0
    if K == 1:
        largest = expectation(max(P))
        print(largest)
        return

    for i, p in enumerate(P[:-K+1]):
        summation = 0
        for k in range(K):
            summation += expectation(P[i + k])

        if summation > largest:
            largest = summation

    print(largest)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, P)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

memory = {}

def expectation(x):
    if x in memory:
        return memory[x]
    else:
        return x * (1 + x) / (2 * x)

def solve(N: int, K: int, P: "List[int]"):
    largest = 0
    if K == 1:
        largest = expectation(max(P))
        print(largest)
        return

    for i, p in enumerate(P[:-K+1]):
        if i == 0:
            summation = 0
            for k in range(K):
                summation += expectation(P[i + k])
            if summation > largest:
                largest = summation
        else:
            summation -= expectation(P[i-1])
            summation += expectation(P[i + K - 1])
            if summation > largest:
                largest = summation

    print(largest)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, P)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np


def main():
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[0 for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    dp = [[np.inf for j in range(N)] for i in range(N)]
    for i in range(H):
        for j in range(W):
            n = W*i + j
            if j < W-1 and S[i][j] == '.' and S[i][j+1] == '.':
                dp[n][n+1] = dp[n+1][n] = 1
            if i < H-1 and S[i][j] == '.' and S[i+1][j] == '.':
                dp[n][n+W] = dp[n+W][n] = 1

    for i in range(N):
        dp[i][i] = 0


    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    
    answer = 0
    for i in range(N):
        for j in range(N):
            if answer < dp[i][j] and dp[i][j] != np.inf:
                answer = dp[i][j]
    print(answer)





def main_dijkstra(): # ダイクストラ法を全域に対して探索させた実装
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[line for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    data = np.zeros([N, N])
    for i in range(H):
        for j in range(W):
            n = W * i + j
            if j<W-1 and S[i][j]=='.' and S[i][j+1]=='.':
                data[n][n+1] = data[n+1][n] = 1
            if i<H-1 and S[i][j]=='.' and S[i+1][j]=='.':
                data[n][n+W] = data[n+W][n] = 1

    G = csgraph_from_dense(data)
    answer = 0
    for n in range(N):
        result = dijkstra(G, indices=n)
        result = [x for x in result if x!=np.inf]
        answer = max(answer, max(result))
    print(int(answer))
    pass

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np

def main():
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[line for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    data = np.zeros([N, N])
    for i in range(H):
        for j in range(W):
            n = W * i + j
            if j<W-1 and S[i][j]=='.' and S[i][j+1]=='.':
                data[n][n+1] = data[n+1][n] = 1
            if i<H-1 and S[i][j]=='.' and S[i+1][j]=='.':
                data[n][n+W] = data[n+W][n] = 1

    G = csgraph_from_dense(data)
    answer = 0
    for n in range(N):
        result = dijkstra(G, indices=n)
        result = [x for x in result if x!=np.inf]
        answer = max(answer, max(result))
    print(int(answer))
    pass

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if A > B:
        tmp = A
        A = B
        B = A
    
    count = 0
    while True:
        if (B - A) % 2 == 0:
            count += (B - A) // 2
            break
        else:
            if max(A-1, B-1) < max(N-A, N-B):
                A = max(1, A-1)
                B -= 1
                count += 1
            else:
                A += 1
                B = min(N, B+1)
                count += 1
    print(count)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if A > B:
        tmp = A
        A = B
        B = tmp
    
    count = 0
    while True:
        if (B - A) % 2 == 0:
            count += (B - A) // 2
            break
        elif A != 1 and B != N:
            if A-1 < N-B:
                count += A-1
                B = B - (A-1)
                A = 1


            else:
                count += N-B
                A = A + (N-B)
                B = N
        else:
            if A == 1:
                count += 1
                B -= 1
                
            elif B == N:
                count += 1
                A += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter
from collections import OrderedDict

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(OrderedDict(Counter(string)).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1
    result = 0
    for _, v in count_dict.items():
        result += sum([i for i in range(v)])
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(Counter(string).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1

    result = 0
    for _, v in count_dict.items():
        result += int((v-1) * 0.5 * (1 + v-1))
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math
import random



def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義

def solve(N, A):
    left = [A[0]]
    right = [A[N-1]]
    for i in range(1, N):
        left.append(gcd(left[i-1], A[i]))
    for i,j in zip(range(1,N),range(N-2, -1, -1)):
        right.append(gcd(right[i-1], A[j]))

    result = -1
    max_value = -1

    for i in range(N):
        if i == 0:
            current_value = right[N-2]
        elif i == N-1:
            current_value = left[N-2]
        else:
            current_value = gcd(left[i-1], right[N-i-2])
        if current_value > max_value:
            max_value = current_value
    print(max_value)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, T: int):
    count = 0
    for i in range(1,T+1,1):
        if i%A == 0:
            count += B
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(A, B, T)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math
import random



def solve(N, A):
    left = [A[0]]
    right = [A[N-1]]
    for i in range(1, N):
        left.append(math.gcd(left[i-1], A[i]))
    for i,j in zip(range(1,N),range(N-2, -1, -1)):
        right.append(math.gcd(right[i-1], A[j]))

    result = -1
    max_value = -1

    for i in range(N):
        if i == 0:
            current_value = right[N-2]
        elif i == N-1:
            current_value = left[N-2]
        else:
            current_value = math.gcd(left[i-1], right[N-i-2])
        if current_value > max_value:
            max_value = current_value
    print(max_value)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import math
import random


def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義

def solve(N, A):
    left = [A[0]]
    right = [A[N-1]]
    for i in range(1, N):
        left.append(gcd(left[i-1], A[i]))
    for i,j in zip(range(1,N),range(N-2, -1, -1)):
        right.append(gcd(right[i-1], A[j]))

    result = -1
    max_value = -1

    for i in range(N):
        if i == 0:
            current_value = right[N-2]
        elif i == N-1:
            current_value = left[N-2]
        else:
            current_value = gcd(left[i-1], right[N-i-2])
        if current_value > max_value:
            max_value = current_value
    print(max_value)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

#!/usr/bin/env python3
import sys


def solve(T: int, X: int):
    print(T / Xl)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(T, X)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(T: int, X: int):
    print(T / X)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(T, X)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8

S = input()


def irekae(str):
    return str.replace('BW', 'WB', 1)


count = 0
while 'BW' in S:
    S = irekae(S)
    count += 1

print(count)


Fixed submission:
#coding:utf-8

S = input()

margin = 0
for i, moji in enumerate(S):
    if moji == 'B':
        margin = i
        break

idx_list = []
for i, moji in enumerate(S[margin:]):
    if moji == 'W':
        idx_list.append(i)

q = len(idx_list) - 1
print(sum(idx_list) - int(0.5 * q * (q + 1)))