Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S0 = input()
S = [S0[i] for i in range(N)]
minimum = N + 1

for i in range(N+1):
    m = 0
    for k in range(i):
        if S[k] != '.':
            m += 1
    for k in range(i, N):
        if S[k] != '#':
            m += 1
    if m < minimum:
        minimum = m

print(minimum)

Fixed submission:
from copy import deepcopy

N = int(input())
S = input()
M = [0 for i in range(N+1)]

for i in range(N):
    if S[i] != '#':
        M[0] += 1

mini = deepcopy(M[0])
    
for i in range(N):
    if S[i] == '#':
        M[i+1] = M[i] + 1
    else:
        M[i+1] = M[i] - 1
        if mini > M[i+1]:
            mini = deepcopy(M[i+1])

print(mini)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S0 = input()
S = [S0[i] for i in range(N)]
minimum = N + 1

for i in range(N+1):
    T = ['.' for j in range(i)] + ['#' for j in range(N-i)]
    m = 0
    for k in range(N):
        if S[k] != T[k]:
            m += 1
    if m < minimum:
        minimum = m

print(minimum)

Fixed submission:
from copy import deepcopy

N = int(input())
S = input()
M = [0 for i in range(N+1)]

for i in range(N):
    if S[i] != '#':
        M[0] += 1

mini = deepcopy(M[0])
    
for i in range(N):
    if S[i] == '#':
        M[i+1] = M[i] + 1
    else:
        M[i+1] = M[i] - 1
        if mini > M[i+1]:
            mini = deepcopy(M[i+1])

print(mini)
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
T = input()
S = [int(x) for x in list(str(T))]

L = []
num = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        num += 1
    else:
        L.append(num)
        num = 1
L.append(0)

if S[0] == 0:
    cand = L[0] + L[1]
    l = len(L)
    for i in range(1, (l+1)//2):
        length = L[2*i - 1] + L[2*i] + L[2*i + 1]
        cand = max(cand, length)
    print(cand)

Fixed submission:
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    S = input()

    """
    反転させる区間は独立であるとしてよい。実際反転させる２区間が左図のように
    オーバーラップしていたとすると、これは右図のように反転させるのと同値だからである：
               _______________                             _______  
        ______|_______        |     --->    ______        |       |
    ___|______|_______|_______|_____    ___|______|_______|_______|_____ 
    
    そうすると安直には0がなるべく長く連続している区間に反転をかけたくなるが、
    長い順に反転をかけた場合1が連続する保証がないのでダメ。

    そこで1の連続する箇所を固定したうえで、そこから0の連続する区間に順番に反転をかけることを考える。
    当然愚直にやるとTLEなので、累積和で実装する
    """

    A = []
    char = S[0]
    cnt = 1
    for i in range(1, N):
        if S[i] == char:
            cnt += 1
        else:
            A.append(cnt)
            char = S[i]
            cnt = 1
    A.append(cnt)
    #print("A={}".format(A))

    B = list(accumulate(A))
    B.append(B[-1])
    #print("B={}".format(B))
    l = len(A)
    if S[0] == '0':
        ans = B[min(K * 2 - 1, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 0:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    else:
        ans = B[min(K * 2, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 1:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    print(ans)
       


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = map(int, input().split())
    S = [-10**100]
    T = [-10**100]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**100)
    T.append(10**100)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 100
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + abs(S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + abs(T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main()


Fixed submission:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())

if K * 2 - 1 <= N:
    print('YES')
else:
    print('NO')

Fixed submission:
N_K = list(map(int, input().split()))
N = N_K[0]
K = N_K[1]

if K * 2 - 1 <= N:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
import sys, math
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    N = int(input())
    table = get_sieve_of_eratosthenes(N)
    #print(table)
    primes = defaultdict(int)
    for n in range(2, N + 1):
        for p in table:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            primes[p] += cnt
    #print(primes)
    
    over_3 = 0
    over_5 = 0
    over_15 = 0
    over_25 = 0
    over_75 = 0
    for p in primes:
        if primes[p] >= 2: over_3 += 1
        if primes[p] >= 4: over_5 += 1
        if primes[p] >= 14: over_15 += 1
        if primes[p] >= 24: over_25 += 1
        if primes[p] >= 74: over_75 += 1
    #print(over_3)
    #print(over_5)
    #print(over_15)
    #print(over_25)
    #print(over_75)
    
    val1 = over_5 * (over_5 - 1) * (over_3 - 2) // 2
    val2 = over_15 * (over_5 - 1)
    val3 = over_25 * (over_3 - 1)
    print(val1 + val2 + val3 + over_75)

    




if __name__ == "__main__":
    main()


Fixed submission:
import sys, math
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    N = int(input())
    if N < 10:
        print(0)
        return
    table = get_sieve_of_eratosthenes(N)
    #print(table)
    primes = defaultdict(int)
    for n in range(2, N + 1):
        for p in table:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            primes[p] += cnt
    #print(primes)
    
    over_3 = 0
    over_5 = 0
    over_15 = 0
    over_25 = 0
    over_75 = 0
    for p in primes:
        if primes[p] >= 2: over_3 += 1
        if primes[p] >= 4: over_5 += 1
        if primes[p] >= 14: over_15 += 1
        if primes[p] >= 24: over_25 += 1
        if primes[p] >= 74: over_75 += 1
    #print(over_3)
    #print(over_5)
    #print(over_15)
    #print(over_25)
    #print(over_75)
    
    val1 = over_5 * (over_5 - 1) * (over_3 - 2) // 2
    val2 = over_15 * (over_5 - 1)
    val3 = over_25 * (over_3 - 1)
    print(val1 + val2 + val3 + over_75)

    




if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    s = input()
    L = len(s)
    K = int(input())

    initial = []
    for i, c in enumerate(s):
        heappush(initial, (c, i))

    appeared = set([])
    string =[]
    cnt = 0
    while True:
        c, i = heappop(initial)
        for j in range(i + 1, L + 1):
            heappush(string, s[i:j])
        while initial[0][0] == c:
            c, i = heappop(initial)
            for j in range(i + 1, L + 1):
                heappush(string, s[i:j])
        while string:
            ans = heappop(string)
            #print(ans)
            if ans not in appeared:
                cnt += 1
                appeared.add(ans)
            if cnt == K:
                print(ans)
                return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    """
    文字列のソートをする際には計算量に要注意！
    数字の大小比較と違って文字列の比較の場合は１文字１文字左から順番に見ないといけない。
    そのため一回の比較でO(比較文字列の長さ)分の計算量がかかる。
    特に長さMの文字列N個をソートするのにかかる時間は
            ❌O(NlogN)
            ⭕️O(MNlogN)

    そこで文字列のソート時には文字数をなるべく小さくするのがポイント。
    今回K<=5なので、「答えはK<=5文字以下になる」のがミソ。
    """

    s = input()
    L = len(s)
    K = int(input())
    string = set([])
    for i in range(L):
        for j in range(i + 1, min(i + K, L) + 1):
            string.add(s[i:j])

    string = list(string)
    heapify(string)
    for _ in range(K):
        ans = heappop(string)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    s = input()
    L = len(s)
    K = int(input())
    string = set([])
    for i in range(L):
        for j in range(i + 1, L + 1):
            string.add(s[i:j])

    string = list(string)
    heapify(string)
    for _ in range(K):
        ans = heappop(string)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    """
    文字列のソートをする際には計算量に要注意！
    数字の大小比較と違って文字列の比較の場合は１文字１文字左から順番に見ないといけない。
    そのため一回の比較でO(比較文字列の長さ)分の計算量がかかる。
    特に長さMの文字列N個をソートするのにかかる時間は
            ❌O(NlogN)
            ⭕️O(MNlogN)

    そこで文字列のソート時には文字数をなるべく小さくするのがポイント。
    今回K<=5なので、「答えはK<=5文字以下になる」のがミソ。
    """

    s = input()
    L = len(s)
    K = int(input())
    string = set([])
    for i in range(L):
        for j in range(i + 1, min(i + K, L) + 1):
            string.add(s[i:j])

    string = list(string)
    heapify(string)
    for _ in range(K):
        ans = heappop(string)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    primes = get_sieve_of_eratosthenes(100000)
    like = [0] * 10**5
    for i in range(3, 10**5):
        if i in primes and (i + 1) // 2 in primes:
            like[i] = 1
    like = list(accumulate(like))

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        if l < 3: l = 3
        if r < 3:
            print(0)
            continue
        print(like[r] - like[l - 1])



if __name__ == "__main__":
    main()


Fixed submission:
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    primes = get_sieve_of_eratosthenes(100000)
    like = [0] * 10**5
    for i in range(3, 10**5):
        if i in primes and (i + 1) // 2 in primes:
            like[i] = 1
    like = list(accumulate(like))

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        if l < 3: l = 3
        if r < 3:
            print(0)
            continue
        print(like[r] - like[l - 1])



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    x, y =input().split()
    if ord(x) < ord(y):
        print("<")
    elif ord(X) > ord(y):
        print(">")
    else:
        print("=")
    


if __name__ == "__main__":
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    x, y =input().split()
    if ord(x) < ord(y):
        print("<")
    elif ord(x) > ord(y):
        print(">")
    else:
        print("=")
    


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    s = input()
    t = input()
    for i, c in enumerate(s):
        if t[-i-1] != c:
            print("NO")
            return
    print("YES")

if __name__ == "__main__":
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    ans = 1
    while ans ** 2 <= n: ans += 1
    print((ans - 1) ** 2)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    H, W = map(int, input().split())
    S = ['.' * W] + [input() for _ in range(H)] + ['.' * W]
    for i in range(1, H + 1):
        code = ""
        for j in range(W):
            if S[i][j] == '#':
                code += '#'
                continue
            if j == 0:
                string = S[i - 1][:2] + S[i][1] + S[i + 1][:2]
                cnt = string.count('#')
                code += str(cnt)
                continue
            if j == W - 1:
                string = S[i - 1][-2:] + S[i][-2] + S[i + 1][-2:]
                cnt = string.count('#')
                code += str(cnt)
                continue
            string = S[i - 1][j - 1:j + 2] + S[i][j - 1] + S[i][j + 1] + S[i + 1][j - 1:j + 2]
            cnt = string.count('#')
            code += str(cnt)
            continue
        print(code)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    H, W = map(int, input().split())
    S = ['.' * W] + [input() for _ in range(H)] + ['.' * W]
    if W == 1:
        for i in range(1, H + 1):
            if S[i] == '#':
                print('#')
                continue
            string = S[i - 1] + S[i + 1]
            cnt = string.count('#')
            print(str(cnt))
        return
    for i in range(1, H + 1):
        code = ""
        for j in range(W):
            if S[i][j] == '#':
                code += '#'
                continue
            if j == 0:
                string = S[i - 1][:2] + S[i][1] + S[i + 1][:2]
                cnt = string.count('#')
                code += str(cnt)
                continue
            if j == W - 1:
                string = S[i - 1][-2:] + S[i][-2] + S[i + 1][-2:]
                cnt = string.count('#')
                code += str(cnt)
                continue
            string = S[i - 1][j - 1:j + 2] + S[i][j - 1] + S[i][j + 1] + S[i + 1][j - 1:j + 2]
            cnt = string.count('#')
            code += str(cnt)
            continue
        print(code)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    A, B, C, D, E, F = map(int, input().split())
    weight = 0.1
    sugar = 0

    for p in range(F // (100 * A) + 1):
        for q in range((F - 100 * A) // (100 * B) + 1):
            upper = (A * p + B * q) * E
            water = (A * p + B * q) * 100
            if water == 0: continue
            for r in range(upper // C + 1):
                if water + r > F: continue
                s = min((upper - C * r) // D, F - (water + r))
                if s < 0: continue
                if sugar * (water + C * r + D * s) < (C * r + D * s) * weight:
                    weight = water + C * r + D * s
                    sugar = C * r + D * s
    if sugar = 0:
        print("0 0")
    else:
        print("{} {}".format(weight, sugar))

    


if __name__ == "__main__":
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    A, B, C, D, E, F = map(int, input().split())
    weight = 0.1
    sugar = 0

    for p in range(F // (100 * A) + 1):
        for q in range(0, (F - 100 * A * p) // (100 * B) + 1):
            upper = (A * p + B * q) * E
            water = (A * p + B * q) * 100
            if water == 0: continue
            for r in range(0, upper // C + 1):
                if water + C * r > F: continue
                s = (upper - C * r) // D
                while s >= 0 and water + C * r + D * s > F: s -= 1
                if s < 0: continue
                if sugar * (water + C * r + D * s) < (C * r + D * s) * weight:
                    weight = water + C * r + D * s
                    sugar = C * r + D * s
    if sugar == 0:
        print("{} 0".format(100 * A))
    else:
        print("{} {}".format(weight, sugar))

    


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    P = [0] + list(map(int, input().split()))
    ans = 0
    for i in range(1, N + 1):
        if i == P[i]:
            P[i + 1] = P[i]
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    P = [0] + list(map(int, input().split()))
    same = deque()
    for i in range(1, N + 1):
        if i == P[i]: same.append(i)
    if not same:
        print(0)
        return

    ans = 0
    x = same.popleft()
    if not same:
        print(1)
        return
    while same:
        if same[0] - x == 1:
            same.popleft()
            ans += 1
            if same:
                x = same.popleft()
                if not same:
                    ans += 1
                    break
        else:
            ans += 1
            x = same.popleft()
            if not same:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    L = list(map(int, input().split()))
    L.sort(reverse=True)
    print(sum[:K])

if __name__ == "__main__":
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    L = list(map(int, input().split()))
    L.sort(reverse=True)
    print(sum(L[:k]))

if __name__ == "__main__":
    main()