Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def slove():
    import sys
    input = sys.stdin.readline
    h, w, a, b = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        if i < b:
            print("".join(["0"] * a + ["1"] * (w - a)))
        else:
            print("".join(
    slove()


Fixed submission:
def slove():
    import sys
    input = sys.stdin.readline
    h, w, a, b = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        if i < b:
            print("".join(["0"] * a + ["1"] * (w - a)))
        else:
            print("".join(["1"] * a + ["0"] * (w - a)))


if __name__ == '__main__':
    slove()
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s
if cnt != 0:
    print(0)
else:
    print((c * math.factorial(n)) % (10 ** 9 + 7))


Fixed submission:
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s[i] + cnt) % 2 != 0:
        cnt += 1
    else:
        c = (c * (cnt if cnt != 0 else 1)) % (10 ** 9 + 7)
        cnt -= 1
    if cnt < 0:
        print(0)
        exit()
if cnt != 0:
    print(0)
else:
    print((c * math.factorial(n)) % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
import collections, heapq
s = tuple(input())
t = tuple(input())
ls = len(s)
idx = collections.defaultdict(list)
dct = collections.defaultdict(list)
ln = -1
for i, v in enumerate(s):
    idx[v].append(i)
for k in idx:
    heapq.heapify(idx[k])
for i in t:
    if idx[i]:
        while True:
            p = heapq.heappop(idx[i])
            heapq.heappush(idx[i], p + ls)
            if p > ln:
                ln = p
                break
    else:
        print(-1)
        exit()
print(ln + 1)


Fixed submission:
import collections, bisect
s = tuple(input())
t = tuple(input())
ls = len(s)
idx = collections.defaultdict(list)
dct = collections.defaultdict(list)
ln = -1
loop = 0
for i, v in enumerate(s):
    idx[v].append(i)
for i in t:
    t_idx = idx[i]
    if t_idx:
        bn = bisect.bisect_left(t_idx, ln + 1)
        if bn >= len(t_idx):
            ln = t_idx[0]
            loop += 1
        else:
            ln = t_idx[bn]
    else:
        print(-1)
        exit()
print(ls * loop + ln + 1)

Buggy python submission (verdict: Runtime Error):
import heapq
al = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5,
      "g": 6, "h": 7, "i": 8, "j": 9, "k": 10, "l": 11,
      "m": 12, "n": 13, "o": 14, "p": 15, "q": 16, "r": 17,
      "s": 18, "t": 19, "u": 20, "v": 21, "w": 22, "x": 23,
      "y": 24, "z": 25}
als = [[] for _ in range(26)]
for i in als:
    heapq.heapify(i)
s = list(input())
ls = len(s)
for i, v in enumerate(s):
    heapq.heappush(als[al[v]], i)
t = list(input())
last_no = 0
for i, v in enumerate(t):
    print(als, v)
    if len(als[al[v]]) != 0:
        while True:
            p = heapq.heappop(als[al[v]])
            heapq.heappush(als[al[v]], p + ls)
            if p > last_no:
                last_no = p
                break
    else:
        print(-1)
        exit()
print(last_no + 1)


Fixed submission:
import collections, bisect
s = tuple(input())
t = tuple(input())
ls = len(s)
idx = collections.defaultdict(list)
dct = collections.defaultdict(list)
ln = -1
loop = 0
for i, v in enumerate(s):
    idx[v].append(i)
for i in t:
    t_idx = idx[i]
    if t_idx:
        bn = bisect.bisect_left(t_idx, ln + 1)
        if bn >= len(t_idx):
            ln = t_idx[0]
            loop += 1
        else:
            ln = t_idx[bn]
    else:
        print(-1)
        exit()
print(ls * loop + ln + 1)
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = [sorted(list(input())) for _ in range(a)]
b.sort()
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        if b[i][0] == b[j][0]:
            if "".join(b[i]) == "".join(b[j]):
                cnt += 1
        else:
            break
print(cnt)


Fixed submission:
import collections
a = int(input())
b = ["".join(sorted(list(input()))) for _ in range(a)]
b = collections.Counter(b)
total = 0
for i in b.values():
    for j in range(1, i):
        total += j
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
a = int(input())
b = [list(input()) for _ in range(a)]
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        c = numpy.sort((b[i]))
        d = numpy.sort(b[j])
        if (c == d).all():
            cnt += 1
print(cnt)


Fixed submission:
import collections
a = int(input())
b = ["".join(sorted(list(input()))) for _ in range(a)]
b = collections.Counter(b)
total = 0
for i in b.values():
    for j in range(1, i):
        total += j
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        ab.append([a, b])
    heapq.heapify(ab)
    s_q = []
    heapq.heapify(s_q)
    d = m
    r = 0
    while True:
        while True:
            if len(ab) != 0:
                p = heapq.heappop(ab)
                if p[0] + d <= m:
                    heapq.heappush(s_q, -p[1])
                else:
                    heapq.heappush(ab, p)
                    break
            else:
                break
        if len(s_q) != 0:
            mr = -heapq.heappop(s_q)
            r += mr
        d -= 1
        if d == -1:
            break
    print(r)


if __name__ == '__main__':
    slove()


Fixed submission:
import heapq
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
heapq.heapify(lst)
r = []
heapq.heapify(r)
ans = 0
d = 1

while True:
    while True:
        if len(lst) != 0:
            p_lst = heapq.heappop(lst)
            if p_lst[0] <= d:
                heapq.heappush(r, - p_lst[1])
            else:
                heapq.heappush(lst, p_lst)
                break
        else:
            break
    if len(r) != 0:
        ans += - heapq.heappop(r)
    d += 1
    if d > m:
        print(ans)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
heapq.heapify(lst)
r = []
heapq.heapify(r)
ans = 0
d = 1

while True:
    while True:
        if len(lst) != 0:
            p_lst = heapq.heappop(lst)
            if p_lst[0] <= d:
                heapq.heappush(r, - p_lst[1])
            else:
                heapq.heappush(lst, p_lst)
                break
        else:
            break
    if len(r) != 0:
        ans += - heapq.heappop(r)
    d += 1
    if d > m:
        print(ans)
        exit()



Fixed submission:
import heapq
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
heapq.heapify(lst)
r = []
heapq.heapify(r)
ans = 0
d = 1

while True:
    while True:
        if len(lst) != 0:
            p_lst = heapq.heappop(lst)
            if p_lst[0] <= d:
                heapq.heappush(r, - p_lst[1])
            else:
                heapq.heappush(lst, p_lst)
                break
        else:
            break
    if len(r) != 0:
        ans += - heapq.heappop(r)
    d += 1
    if d > m:
        print(ans)
        exit()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a.copy(), reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    main()


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = a.copy()
b = sorted(b, reverse=True)
for i in a:
    if i == b[0]:
        print(b[1])
    else:
        print(b[0])

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a.copy(), reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    main()


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = a.copy()
b = sorted(b, reverse=True)
for i in a:
    if i == b[0]:
        print(b[1])
    else:
        print(b[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [int(readline()) for _ in range(n)]
    cnt = 0
    while len(a):
        cnt += 1
        t_a = []
        mt = -1
        for i in range(len(a)):
            if mt >= a[i]:
                t_a.append(a[i])
            else:
                mt = a[i]
        a = t_a
    print(cnt)


if __name__ == '__main__':
    solve()


Fixed submission:
import sys
import bisect

def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [int(readline()) for _ in range(n)]
    res = []
    for i in range(n-1, -1, -1):
        p = bisect.bisect_right(res, a[i])
        if len(res) == p:
            res.append(a[i])
        else:
            res[p] = a[i]
    print(len(res))


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    l, r = list(map(int, readline().split()))
    t = 10 ** 20
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            t = min(t, i * j % 2019)
        if t == 0:
            break
    print(t)


if __name__ == '__main__':
    solve()


Fixed submission:
l, r = map(int, input().split())
ans = 10 ** 9
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    l, r = list(map(int, readline().split()))
    t = 10 ** 20
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            t = min(t, i * j % 2019)
            if t == 0:
                break
    print(t)


if __name__ == '__main__':
    solve()


Fixed submission:
l, r = map(int, input().split())
ans = 10 ** 9
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            print(ans)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    l, r = list(map(int, input().rstrip('\n').split()))
    mmod = 10 ** 10
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            mmod = min(mmod, (i * j) % 2019)
            if mmod == 0:
                break
    print(mmod)


if __name__ == '__main__':
    slove()


Fixed submission:
l, r = map(int, input().split())
ans = 10 ** 9
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            print(ans)
            exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = [int(input().rstrip('\n')) for _ in range(m)]
    x = [0] * (n + 1)
    x[0] = 1 if 0 not in a else 0
    x[1] = 1 if 1 not in a else 0
    for i in range(2, n+1):
        if i not in a:
            x[i] = (x[i-1] + x[i-2]) % 1000000007
        else:
            x[i] = 0
    print(x[-1])


if __name__ == '__main__':
    slove()


Fixed submission:
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in [int(input()) for _ in range(m)]:
    dp[i] = -1
for i in range(n + 1):
    if i < 2:
        if dp[i] == -1:
            dp[i] = 0
    else:
        if dp[i] == -1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = [int(input().rstrip('\n')) for _ in range(m)]
    dp = [0] * (n + 1)
    dp[0] = 1 if 0 not in a else 0
    dp[1] = 1 if 1 not in a else 0
    for i in range(2, n + 1):
        if i not in a:
            dp[i] = (dp[i-1] + dp[i-2]) % (10 ** 9 + 7)
        else:
            dp[i] = 0
    print(dp[-1])


if __name__ == '__main__':
    slove()


Fixed submission:
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in [int(input()) for _ in range(m)]:
    dp[i] = -1
for i in range(n + 1):
    if i < 2:
        if dp[i] == -1:
            dp[i] = 0
    else:
        if dp[i] == -1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
dp = [0] * (n + 1)
dp[0] = 1 if 0 not in a else 0
dp[1] = 1 if 1 not in a else 0
for i in range(2, n + 1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[n])


Fixed submission:
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in [int(input()) for _ in range(m)]:
    dp[i] = -1
for i in range(n + 1):
    if i < 2:
        if dp[i] == -1:
            dp[i] = 0
    else:
        if dp[i] == -1:
            dp[i] = 0
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[n])
Buggy python submission (verdict: Runtime Error):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b, c, d = list(map(int, readline().split()))
    if s[c-1] == "#" or s[d-1] == "#":
        print("No")
    else:
        s = str(readline().rstrip().decode('utf-8'))
        wrc = 0
        brc = 0
        wc = 0
        bc = 0
        for i in range(n):
            if s[i] == "#":
                bc += 1
                wc = 0
            else:
                bc = 0
                wc += 1
            wrc = max(wrc, wc)
            brc = max(brc, bc)
        if c < d:
            if brc < 2:
                print("Yes")
            else:
                print("No")
        else:
            if brc >= 2 and wrc >= 3:
                print("Yes")
            else:
                print("No")


if __name__ == '__main__':
    solve()


Fixed submission:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b, c, d = list(map(int, readline().split()))
    s = str(readline().rstrip().decode('utf-8'))
    if c == d:
        print("No")
    elif c < d:
        print("Yes" if s[a-1:d+1].count("##") == 0 else "No")
    elif c > d:
        print("Yes" if s[a-1:c+1].count("##") == 0 and s[b-2:d+1].count("...") != 0 else "No")


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    v = list(map(int, input().rstrip('\n').split()))
    ms = 0
    t = []
    heapq.heapify(t)
    for i in range(1, k + 1):
        for j in range(i + 1):
            t.clear()
            if j != 0:
                for w in v[:j]:
                    heapq.heappush(t, w)
            if -i+j != 0:
                for w in v[-i+j:]:
                    heapq.heappush(t, w)
            for _ in range(k-i):
                if len(t) != 0:
                    p = heapq.heappop(t)
                    if p >= 0:
                        heapq.heappush(t, p)
                        break
            ms = max(ms, sum(t))
    print(ms)


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    v = list(map(int, input().rstrip('\n').split()))
    ms = 0
    for i in range(1, min(k + 1, len(v) + 1)):
        for j in range(i + 1):
            t = []
            heapq.heapify(t)
            if j != 0:
                for w in v[:j]:
                    heapq.heappush(t, w)
            if -i+j != 0:
                for w in v[-i+j:]:
                    heapq.heappush(t, w)
            for _ in range(k-i):
                if len(t) != 0:
                    p = heapq.heappop(t)
                    if p >= 0:
                        heapq.heappush(t, p)
                        break
                else:
                    break
            ms = max(ms, sum(t))
    print(ms)


if __name__ == '__main__':
    slove()
Buggy python submission (verdict: Time Limit Exceeded):
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    heapq.heapify(a)
    for b, c in bc:
        for i in range(b):
            p = heapq.heappop(a)
            if p < c:
                heapq.heappush(a, c)
            else:
                heapq.heappush(a, p)
                break
    print(sum(a))


if __name__ == '__main__':
    slove()


Fixed submission:
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    heapq.heapify(a)
    bc = sorted(bc, key=lambda x: x[1], reverse=True)
    for b, c in bc:
        bo = True
        for i in range(b):
            p = heapq.heappop(a)
            if p < c:
                heapq.heappush(a, c)
            else:
                heapq.heappush(a, p)
                bo = False
                break
        if not bo:
            break
    print(sum(a))


if __name__ == '__main__':
    slove()
Buggy python submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))
b = [0] * 3
c = [0] * 3
for i in range(len(a)):
    if i == 0:
        b[i] = a[i]
        c[-i-1] = a[-i-1]
    else:
        b[i] = fractions.gcd(a[i], b[i-1])
        c[-i-1] = fractions.gcd(a[-i-1], c[-i])
b.insert(0, 0)
c.append(0)
m_gcd = 0
print(b, c)
for i in range(len(b)-2):
    m_gcd = max(fractions.gcd(c[i+1], b[i]), m_gcd)
print(m_gcd)


Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
f = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        f[i] = a[i]
        r[-i-1] = a[-i-1]
    else:
        f[i] = fractions.gcd(f[i-1], a[i])
        r[-i-1] = fractions.gcd(r[-i], a[-i-1])
f.insert(0, 0)
r.append(0)
ans = 0
for i in range(len(f) - 1):
    ans = max(ans, fractions.gcd(f[i], r[i+1]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))
b = [0] * 3
c = [0] * 3
for i in range(len(a)):
    if i == 0:
        b[i] = a[i]
        c[-i-1] = a[-i-1]
    else:
        b[i] = fractions.gcd(a[i], b[i-1])
        c[-i-1] = fractions.gcd(a[-i-1], c[-i])
b.insert(0, 0)
c.append(0)
m_gcd = 0
for i in range(len(b)-1):
    m_gcd = max(fractions.gcd(c[i+1], b[i]), m_gcd)
print(m_gcd)


Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
f = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        f[i] = a[i]
        r[-i-1] = a[-i-1]
    else:
        f[i] = fractions.gcd(f[i-1], a[i])
        r[-i-1] = fractions.gcd(r[-i], a[-i-1])
f.insert(0, 0)
r.append(0)
ans = 0
for i in range(len(f) - 1):
    ans = max(ans, fractions.gcd(f[i], r[i+1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    if n >= m:
        print(0)
    else:
        x.sort()
        y = []
        for i, v in enumerate(x):
            if i != 0:
                y.append([abs(v - x[i-1]), i, i-1])
        y = sorted(y, key=lambda x: x[0], reverse=True)
        cnt = 0
        z = [0, m-1]
        for i in range(n-1):
            z.append(y[i][1])
            z.append(y[i][2])
        z.sort()
        for i in range(1, m, 2):
            cnt += abs((x[z[i]] - x[z[i-1]]))
        print(cnt)


if __name__ == '__main__':
    slove()


Fixed submission:
import heapq
n, m = map(int, input().split())
if n >= m:
    print(0)
else:
    x = list(map(int, input().split()))
    x.sort()
    d = []
    heapq.heapify(d)
    for i in range(1, m):
        heapq.heappush(d, [-abs(x[i] - x[i-1]), i, i - 1])
    total = 0
    a = [0, m - 1]
    for i in range(n-1):
        p = heapq.heappop(d)
        a.append(p[1])
        a.append(p[2])
    a.sort()
    total = 0
    for i in range(1, len(a), 2):
        total += abs(x[a[i]] - x[a[i-1]])
    print(total)
Buggy python submission (verdict: Runtime Error):
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    d = collections.deque(list("keyence"))
    s = str(input().rstrip('\n'))
    for i in range(len(s)):
        if len(p) == 0:
            break
        else:
            p = d.popleft()
            if p != s[i]:
                d.appendleft(p)
    print("YES" if len(d) == 0 else "NO")


if __name__ == '__main__':
    solve()


Fixed submission:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = list(str(input().rstrip('\n')))
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if "".join(s[:i + 1] + s[j:]) == "keyence":
                print("YES")
                exit()
    print("NO")


if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    d = collections.deque(list("keyence"))
    s = str(input().rstrip('\n'))
    for i in range(len(s)):
        p = d.popleft()
        if p != s[i]:
            d.appendleft(p)
    print("YES" if len(d) == 0 else "NO")


if __name__ == '__main__':
    solve()


Fixed submission:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = list(str(input().rstrip('\n')))
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if "".join(s[:i + 1] + s[j:]) == "keyence":
                print("YES")
                exit()
    print("NO")


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, readline().split()))
    wv = [list(map(int, readline().split())) for _ in range(n)]
    dp = [0] * (w + 1)
    for ww, vv in wv:
        for i in range(w-ww+1, -1, -1):
            if i + ww <= w:
                dp[i+ww] = max(dp[i+ww], dp[i] + vv)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Fixed submission:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, readline().split()))
    wv = [list(map(int, readline().split())) for _ in range(n)]
    dp = [10 ** 10] * (10 ** 3 * n + 1)
    dp[0] = 0
    max_v = 0
    for ww, vv in wv:
        for i in range(max_v, -1, -1):
            dp[i+vv] = min(dp[i+vv], dp[i] + ww)
            max_v = max(max_v, i+vv)
    mt = 0
    for i in range(len(dp)):
        if dp[i] <= w:
            mt = max(mt, i)
    print(mt)


if __name__ == '__main__':
    solve()