Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

n, m = map(int, input().split())

def calculation(number):
    factorial = math.factorial(number)
    combination = factorial/math.factorial(number-2)
    result = math.floor(combination/2)
    return result

if m == 1 or 0:
    if n == 1 or 0:
        print("0")
    else:
        print("{}".format(calculation(n)))
else:
    if n == 1 or 0:
        print("{}".format(calculation(m)))
    else:
        print("{}".format(calculation(n)+calculation(m)))


Fixed submission:
import math

n, m = map(int, input().split())

def calculation(number):
    factorial = math.factorial(number)
    combination = factorial/math.factorial(number-2)
    result = math.floor(combination/2)
    return result

if m == 1 or m == 0:
    if n == 1 or n == 0:
        print("0")
    else:
        print("{}".format(calculation(n)))
else:
    if n == 1 or n == 0:
        print("{}".format(calculation(m)))
    else:
        print("{}".format(calculation(n)+calculation(m)))
Buggy python submission (verdict: Runtime Error):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

c = 0
cnt = [0]*n

for i in range(n):
    cnt[A[i]] += 1

def combinations(n):
    return n*(n-1)//2

for i in range(n):
    c += combinations(cnt[i])

for i in range(n):
    ans = c
    ans -= combinations(cnt[A[i]])
    ans += combinations(cnt[A[i]]-1)
    print(ans)



Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

c = 0
cnt = [0]*n

for i in range(n):
    A[i] -= 1

for i in range(n):
    cnt[A[i]] += 1

def combinations(n):
    return n*(n-1)//2

for i in range(n):
    c += combinations(cnt[i])

for i in range(n):
    ans = c
    ans -= combinations(cnt[A[i]])
    ans += combinations(cnt[A[i]]-1)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
q = inint()

S = deque()

for i in range(len(s)):
    S.append(s[i])

for i in range(q):
    Q = instrl()
    if Q[0] == "1":
        S.reverse()
    else:
        if Q[1] == "1":
            S.appendleft(Q[2])
        else:
            S.append(Q[2])

print("".join(S))

Fixed submission:
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
q = inint()

S = deque()
f = [0,1]

for i in range(len(s)):
    S.append(s[i])

for i in range(q):
    Q = instrl()
    if Q[0] == "1":
        f = f[::-1]
    else:
        if f[0] == 0:
            if Q[1] == "1":
                S.appendleft(Q[2])
            else:
                S.append(Q[2])
        else:
            if Q[1] == "1":
                S.append(Q[2])
            else:
                S.appendleft(Q[2])

if f[0] == 1:
    S.reverse()

print("".join(S))

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
q = inint()

S = deque()

for i in range(len(s)):
    S.append(s[i])

for i in range(q):
    Q = instrl()
    if Q[0] == "1":
        S.reverse()
    else:
        if Q[1] == "1":
            S.appendleft(Q[2])
        else:
            S.append(Q[2])

print("".join(S))

Fixed submission:
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
q = inint()

S = deque()
f = [0,1]

for i in range(len(s)):
    S.append(s[i])

for i in range(q):
    Q = instrl()
    if Q[0] == "1":
        f = f[::-1]
    else:
        if f[0] == 0:
            if Q[1] == "1":
                S.appendleft(Q[2])
            else:
                S.append(Q[2])
        else:
            if Q[1] == "1":
                S.append(Q[2])
            else:
                S.appendleft(Q[2])

if f[0] == 1:
    S.reverse()

print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = []

s_append = s.append
for _ in range(n):
    s_append(input())

pop_times = collections.Counter(s)
most_common_word = []

most_common_word_append = most_common_word.append
for i in pop_times.most_common():
    if pop_times.most_common()[0][1] == i[1]:
        most_common_word_append(i[0])

for x in sorted(most_common_word):
    print(x)


Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
d = {}
ans = []

for st in s:
    d[st] = d.get(st, 0) + 1

t = max(d.values())
ans_append = ans.append

for x in d:
    if d[x] == t:
        ans_append(x)

ans = sorted(ans)
for x in ans:
    print(x)

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

n = int(input())
s = []
for _ in range(n):
    s.append(input())

pop_times = collections.Counter(s)
most_common_word = []

for i in pop_times.most_common():
    if pop_times.most_common()[0][1] == i[1]:
        most_common_word.append(i[0])

sorted_most_common_word = sorted(most_common_word)

for x in sorted_most_common_word:
    print(x)


Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
d = {}
ans = []

for st in s:
    d[st] = d.get(st, 0) + 1

t = max(d.values())
ans_append = ans.append

for x in d:
    if d[x] == t:
        ans_append(x)

ans = sorted(ans)
for x in ans:
    print(x)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
print(6-(a+b))


Fixed submission:
a = int(input())
b = int(input())
print(6-(a+b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

ans = 10**11

for i in range(n):
    if abs(sum(A[:i]) - sum(A[i:])) < ans:
        ans = abs(sum(A[:i]) - sum(A[i:]))

print(ans)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))

ans = 10**11
sum_A = sum(A)
l = 0

for a in A:
    l += a
    if abs(l - (sum_A - l)) < ans:
        ans = abs(l - (sum_A - l))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

ans = 0
a = 0
b = 0

for i in range(len(s)):
    a += s[i]
    if a == b:
        continue
    ans += 1
    b = a
    a = ""

print(ans)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

ans = 0
a = ""
b = ""

for i in range(len(s)):
    a += s[i]
    if a == b:
        continue
    ans += 1
    b = a
    a = ""

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

z = {():0}
ans = 0

def combinations(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(n):
    c = [0]*123
    s = input()
    for j in range(len(s)):
        c[ord(s[j])] += 1
    try:
        z[tuple(c)] += 1
    except:
        z[tuple(c)] = 1

for i in z:
    ans += combinations(z[i],2)

print(ans)

Fixed submission:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

z = {():0}
ans = 0

def combinations(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(n):
    c = [0]*123
    s = input()
    for j in range(len(s)):
        c[ord(s[j])] += 1
    try:
        z[tuple(c)] += 1
    except:
        z[tuple(c)] = 1

for i in z:
    ans += combinations(z[i],2)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, d = inintm()

print(b-a+1 - (-(-(b-a)//c) + -(-(b-a)//d))) + 1

Fixed submission:
import sys
import math

inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, d = inintm()

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(b - (b//c + b//d) + b//lcm(c,d) - ((a-1) - ((a-1)//c + (a-1)//d) + (a-1)//lcm(c,d)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

r, g, b, n = inintm()

ans = 0

for i in range(3001):
    for j in range(3001):
        if (n - (i*r + j*g)) >= 0 and (n - (i*r + j*g)) % b == 0:
            ans += 1

print(ans)


Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

r, g, b, n = inintm()

ans = 0

for i in range(3001):
    for j in range(3001):
        if (n - (i*r + j*g)) >= 0 and (n - (i*r + j*g)) % b == 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import numba
from numba import njit
i8 = numba.int64


@njit((i8, ), cache=True)
def main(n, m):

    A = []
    B = []
    cnt = 0
    ans = 0

    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    while cnt < m:
        A_min = min(A)
        A_min_index = A.index(A_min)
        if cnt + B[A_min_index] < m:
            ans += A_min * B[A_min_index]
            cnt += B[A_min_index]
            A.pop(A_min_index)
            B.pop(A_min_index)
        else:
            for i in range(B[A_min_index]):
                if cnt == m:
                    break
                ans += A_min
                cnt += 1

    print(ans)


n, m = map(int, input().split())

main(n, m)


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

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
from numba import njit


@njit('void(i8)')
def main(n, m):

    A = []
    B = []
    cnt = 0
    ans = 0

    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    while cnt < m:
        A_min = min(A)
        A_min_index = A.index(A_min)
        if cnt + B[A_min_index] < m:
            ans += A_min * B[A_min_index]
            cnt += B[A_min_index]
            A.pop(A_min_index)
            B.pop(A_min_index)
        else:
            for i in range(B[A_min_index]):
                if cnt == m:
                    break
                ans += A_min
                cnt += 1

    print(ans)


n, m = map(int, input().split())

main(n, m)


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

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

A = []
B = []
cnt = 0
ans = 0

for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


while cnt < m:
    A_min = min(A)
    A_min_index = A.index(A_min)
    if cnt + B[A_min_index] < m:
        ans += A_min * B[A_min_index]
        cnt += B[A_min_index]
        A.pop(A_min_index)
        B.pop(A_min_index)
    else:
        for i in range(B[A_min_index]):
            if cnt == m:
                break
            ans += A_min
            cnt += 1

print(ans)


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

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

orilen = len(s)
ans = 0

for i in range(orilen//2):
    s = s.replace("01", "")
    s = s.replace("10", "")

print(orilen - len(s))


Fixed submission:
s = input()

cnt_0 = 0
cnt_1 = 0

for i in range(len(s)):
    if s[i] == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

print(2*min(cnt_0, cnt_1))

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

orilen = len(s)
ans = 0

for i in range(10**5):
    s = s.replace("01", "")
    s = s.replace("10", "")

print(orilen - len(s))


Fixed submission:
s = input()

cnt_0 = 0
cnt_1 = 0

for i in range(len(s)):
    if s[i] == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

print(2*min(cnt_0, cnt_1))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(max(mod_min % (m % mod_min), 1))


Fixed submission:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(math.gcd(m, mod_min))

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(mod_min % (m % mod_min))

Fixed submission:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(math.gcd(m, mod_min))
Buggy python submission (verdict: Time Limit Exceeded):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()

h = []
ans = 10**10

for _ in range(n):
    h.append(inint())

h.sort()

for i in range(n-k+1):
    if h[i:i+k][-1] - h[i:i+k][0] < ans:
        ans = h[i:i+k][-1] - h[i:i+k][0]

print(ans)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()

h = []
ans = 10**10

for _ in range(n):
    h.append(inint())

h.sort()

for i in range(n-k+1):
    if h[i+k-1] - h[i] < ans:
        ans = h[i+k-1] - h[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

ans = 0
waru = 0
cnt = 0

while True:
    for i in range(n):
        if A[i] % 2 == 0:
            if waru == 1:
                A[i] *= 3
            else:
                A[i] //= 2
                waru = 1
        else:
            A[i] *= 3
    if waru == 0:
        print(ans)
        exit()
    else:
        ans += 1
    waru = 0


Fixed submission:
n = int(input())
A = list(map(int, input().split()))

ans = 0

for a in A:
    while a % 2 == 0:
        a /= 2
        ans += 1

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, k = inintm()

cnt = 0
ans = []
for i in range(a,b+1):
    cnt += 1
    if cnt <= k:
        if i not in ans:
            ans.append(i)

cnt = 0
for i in range(a,b+1)[::-1]:
    cnt += 1
    if cnt <= k:
        if i not in ans:
            ans.append(i)

ans = sorted(ans)

for i in ans:
    print(i)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, k = inintm()

for i in range(a,min(b, a+k-1)+1):
    print(i)
for i in range(max(a+k, b-k+1), b+1):
    print(i)

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, k = inintm()

cnt = 0
ans = []
for i in range(a,b+1):
    cnt += 1
    if cnt <= k:
        ans.append(i)

cnt = 0
for i in range(a,b+1)[::-1]:
    cnt += 1
    if cnt <= k:
        ans.append(i)

ans = sorted(list(set(ans)))

for i in ans:
    print(i)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, k = inintm()

for i in range(a,min(b, a+k-1)+1):
    print(i)
for i in range(max(a+k, b-k+1), b+1):
    print(i)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))

cnt_l = [0]*10**5
num = []
ans = 0

for i in A:
    cnt_l[i] += 1
    if i not in num:
        num.append(i)

cnt_l.sort()

cnt_l = cnt_l[10**5-len(num):]

if len(cnt_l) <= k:
    print(0)
    exit()

cnt_l = cnt_l[:k-1]

print(sum(cnt_l))

Fixed submission:
from collections import Counter

n, k = map(int, input().split())
A = list(map(int, input().split()))

c = Counter(A)

print(sum(sorted(c.values())[:len(c) - k]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

num = []
cnt = 0

for i in range(n):
    a = int(input())
    if a in num:
        num.pop(num.index(a))
        cnt -= 1
    else:
        num.append(a)
        cnt += 1

print(cnt)


Fixed submission:
n = int(input())
A = []

for i in range(n):
    a = int(input())
    A.append(a)

A.sort()

odd = 0
prev = A[0]
cnt = 1

for i in range(1,n):
    if A[i] != prev:
        if cnt % 2 == 1:
            odd += 1
        cnt = 1
        prev = A[i]
    else:
        cnt += 1

if cnt % 2 == 1:
    odd += 1

print(odd)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
a = list(map(int, input().split()))

a_processed = []

for i in a:
    a_processed[n:n] = [i-1, i, i+1]

print(a_processed.count(collections.Counter(a_processed).most_common()[0][0]))


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

ans_l = [0]*(10**5 + 2)

for i in a:
    ans_l[i-1] += 1
    ans_l[i] += 1
    ans_l[i+1] += 1

print(max(ans_l))
Buggy python submission (verdict: Runtime Error):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
P = inintl()

ans = 0

if n == 2:
    if P[0] == 1:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in range(n):
    if i+1 == P[i]:
        if i+2 == P[i+1]:
            continue
        else:
            ans += 1

print(ans)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
P = inintl()

ans = 0

for i in range(n-1):
    a = P[i]
    b = P[i+1]
    if a == i+1:
        P[i] = b
        P[i+1] = a
        ans += 1

if P[-1] == n:
    ans += 1

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


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

ans = 0

for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if s[i:j][0] == "A" and s[i:j][-1] == "Z":
            if len(s[i:j]) > ans:
                ans = len(s[i:j])

print(ans)

Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

ans = 0
flag = 0
a = 0

for i in range(len(s)):
    if flag != 1:
        if s[i] == "A":
            flag = 1
            a = i
    elif s[i] == "Z":
        ans = i-a+1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import permutations


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, l = inintm()

s = []
z = []

for _ in range(n):
    s.append(input())

for i in permutations(s,n):
    t = ""
    for j in i:
        t += j
    z.append(t)

z.sort()

print(z[0])


Fixed submission:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, l = inintm()

s = []

for _ in range(n):
    s.append(input())

s.sort()

print("".join(s))