Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
num=map(int,str(n))
if num[-1]=="7" or num[-3]=="7" or num[-2]=="7":
    print("Yes")
else:
    print("No")

Fixed submission:
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7":
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n[-1]==7 or n[-3]==7 or n[-2]==7:
    print("Yes")
else:
    print("No")

Fixed submission:
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7":
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n[-1]==7 or n[-3]==7 or n[-2]==7
    print("Yes")
else:
    print("No")

Fixed submission:
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7":
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7"
    print("Yes")
else:
    print("No")

Fixed submission:
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7":
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n=str(input())
if n[1]=="7" or n[0]=="7" or n[2]=="7"
    print("Yes")
else:
    print("No")

Fixed submission:
n=str(input())
if n[-1]=="7" or n[-3]=="7" or n[-2]=="7":
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
li=[z,x,y]
print(" ".join(li))

Fixed submission:
x,y,z=map(int,input().split())
li=[z,x,y]
print(" ".join(map(str,li)))
Buggy python submission (verdict: Runtime Error):
s=input()
sl=list(reversed(s))
ns="".join(list(reversed(s)))
k=(len(s)-1)/2
t=s[:k]
tl=list(reversed(t))
nt="".join(list(reversed(t)))
n=(len(s)+3)/2
r=s[n-1:len(s)]
rl=list(reversed(r))
nr="".join(rl)
if s==ns and t==nt and r==nr:
    print("Yes")
else:
    print("No")

Fixed submission:
s=input()
sl=list(reversed(s))
ns="".join(list(reversed(s)))
k=int((len(s)-1)/2)
t=s[:k]
tl=list(reversed(t))
nt="".join(list(reversed(t)))
n=int((len(s)+3)/2)
r=s[n-1:len(s)]
rl=list(reversed(r))
nr="".join(rl)
if s==ns and t==nt and r==nr:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N/X * T

Fixed submission:
def calculate(N,X,T):
    x = N // X
    if x ==0:
        return T
    elif not N % X == 0:
        return (x + 1)*T;
    else:
        return x*T
N,X,T = map(int,input().split())
result = calculate(N,X,T)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    a = LI()
    ans = [1]*n
    for i in range(k-1, n):
        for j in range(k):
            ans[i] *= a[i-j]
        if i > k-1:
            if i == 0 or ans[i] > ans[i-1]:
                print('Yes')
            else:
                print('No')
    return


# Solve
if __name__ == "__main__":
    solve()


Fixed submission:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    a = LI()
    for i in range(k, n):
        if a[i] > a[i-k]:
            print('Yes')
        else:
            print('No')
    return


# Solve
if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    flag_list = [False] * n
    for _ in range(k-1):
        d = I()
        a = LIR(max(d-1, 1))
        for i in range(d):
            flag_list[a[0][i]-1] = True
    print(flag_list.count(False))
    
    return


if __name__ == "__main__":
    solve()


Fixed submission:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    flag_list = [False] * n
    for _ in range(k):
        d = I()
        a = LI()
        for i in range(d):
            flag_list[a[i]-1] = True
    print(flag_list.count(False))
    
    return


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    a = LI()
    for i in range(1,n):
        print(a.count(i))
    print(0)
    return


if __name__ == "__main__":
    solve()

Fixed submission:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    a = LI()
    ca = Counter(a)
    for i in range(1,n):
        print(ca[i])
    print(0)
    return


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
#!usr/bin/env python3


import sys


def I(): return int(sys.stdin.readline())


def solve():
    n = I()
    sli = [input() for i in range(n)]
    setli = set(sli)
    rank = {}
    for i in setli:
        j = sli.count(i)
        rank[i] = j
    for i in sorted([k for k, v in rank.items() if v == max(rank.values())]):
        print(i)


# Solve
if __name__ == "__main__":
    solve()


Fixed submission:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    a, b, c = LI()
    if a == b == c:
        print('No')
    elif a == b:
        print('Yes')
    elif a == c:
        print('Yes')
    elif b == c:
        print('Yes')
    else:
        print('No')


# Solve
if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    for i in range(k):
        h.pop(0)
    print(sum(h))
else:
    print(0)


Fixed submission:
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    print(sum(h[k:]))
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    for i in range(k):
        h.pop(0)
    print(sum(h))
else:
    print(0)


Fixed submission:
n, k = map(int, input().split())
h = sorted(map(int, input().split()), reverse=True)
if k == 0:
    print(sum(h))
elif k < n:
    print(sum(h[k:]))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
suuji = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(suuji[k - 1]

Fixed submission:
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k - 1])

Buggy python submission (verdict: Runtime Error):
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
if k == 32:
    raise Exception
print(data_list[k + 1])


Fixed submission:
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k - 1])

Buggy python submission (verdict: Runtime Error):
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k + 1])


Fixed submission:
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k - 1])

Buggy python submission (verdict: Runtime Error):
data_list = [
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
k = int(input())
print(data_list[k])


Fixed submission:
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import math

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])


def sqrtl(num):
    eps = pow(1.0, -10)
    a = math.sqrt(num)
    while True:
        a = (a + num / a) / 2
        if math.fabs(num - a * a) > eps:
            break
    return a


if sqrtl(a) + sqrtl(b) - sqrtl(c) < 0:
    print('Yes')
else:
    print('No')


Fixed submission:
import decimal
import math

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

if decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() < decimal.Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

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

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])


def sqrtl(num):
    eps = pow(1.0, -18)
    a = math.sqrt(num)
    while True:
        a = (a + num / a) / 2
        if math.fabs(num - a * a) > eps:
            break
    return a


if sqrtl(a) + sqrtl(b) - sqrtl(c) < 0:
    print('Yes')
else:
    print('No')


Fixed submission:
import decimal
import math

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

if decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() < decimal.Decimal(c).sqrt():
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import copy

ab = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

n = int(input())

# 最初はaで確定

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
    for v in value:
    print(v)


Fixed submission:
import copy

ab = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

n = int(input())

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
for v in value:
    print(v)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split(' '))
pp = list(map(int, input().split(' ')))

pp_ex = list(map(lambda p: (p + 1) / 2, pp))

max_ex = 0
# for i in range(k):
#     max_ex += pp_ex[i]

for i in range(0, n - k + 1):
    ex = 0
    for j in range(k):
        ex += pp_ex[i + j]
    if max_ex < ex:
        max_ex = ex

print(max_ex)


Fixed submission:
n, k = map(int, input().split(' '))
pp = list(map(int, input().split(' ')))

pp_ex = list(map(lambda p: (p + 1) / 2, pp))

max_ex = 0
for i in range(k):
    max_ex += pp_ex[i]
bef_ex = max_ex
for i in range(1, n - k + 1):
    ex = bef_ex - pp_ex[i - 1] + pp_ex[i + k - 1]
    bef_ex = ex
    if max_ex < ex:
        max_ex = ex

print(max_ex)

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

pp_ex = list(map(lambda p: (p * (p + 1) / 2) / p, pp))

max_ex = 0
for i in range(n - k + 1):
    ex = 0
    for j in range(k):
        ex += pp_ex[i + j]
    if max_ex < ex:
        max_ex = ex

print(max_ex)


Fixed submission:
n, k = map(int, input().split(' '))
pp = list(map(int, input().split(' ')))

pp_ex = list(map(lambda p: (p + 1) / 2, pp))

max_ex = 0
for i in range(k):
    max_ex += pp_ex[i]
bef_ex = max_ex
for i in range(1, n - k + 1):
    ex = bef_ex - pp_ex[i - 1] + pp_ex[i + k - 1]
    bef_ex = ex
    if max_ex < ex:
        max_ex = ex

print(max_ex)

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

max_ex = 0
for i in range(n - k + 1):
    ex = 0
    for j in range(k):
        p = pp[i + j]
        ex += (p * (p + 1) / 2) / p
    if max_ex < ex:
        max_ex = ex

print(max_ex)


Fixed submission:
n, k = map(int, input().split(' '))
pp = list(map(int, input().split(' ')))

pp_ex = list(map(lambda p: (p + 1) / 2, pp))

max_ex = 0
for i in range(k):
    max_ex += pp_ex[i]
bef_ex = max_ex
for i in range(1, n - k + 1):
    ex = bef_ex - pp_ex[i - 1] + pp_ex[i + k - 1]
    bef_ex = ex
    if max_ex < ex:
        max_ex = ex

print(max_ex)
Buggy python submission (verdict: Time Limit Exceeded):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = int(input())

    #output
    l = len(str(n))

    mod = 0
    for i in range(l):
        mod += int(str(n)[i])

    #  %%
    if mod % 9 == 0:
        print("Yes")
    else:
        print("No")

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = str(input())

    #output
    l = len(n)

    mod = 0
    for i in range(l):
        mod += int(n[i])
        mod %= 9 

    #  %%
    if mod == 0:
        print("Yes")
    else:
        print("No")

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    S = sum(A)
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        b, c = map(int, input().split())
        x = D[b]
        y = D[c]
        temp = -x * b + x * c
        print(S+temp)
        S += temp
        D[b] = 0
        D[c] += x  

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    from collections import Counter
    N = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    S = sum(A)
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        b, c = map(int, input().split())
        x = D[b]
        y = D[c]
        temp = -x * b + x * c
        print(S+temp)
        S += temp
        D[b] = 0
        D[c] += x  

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    answer = 1
    limit = pow(10, 18)

    for i in range(N):
        answer *= A[i]

    if answer > limit:
        print(-1)
        exit()
    else:
        print(answer) 

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    A = sorted(A, reverse = True)
    if A[-1] == 0:
        print(0)
        exit()
        
    answer = 1
    limit = pow(10, 18)
    for i in range(N):
        answer *= A[i]
        if answer > limit:
            print(-1)
            exit()
        else:
            continue

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    answer = 1
    for i in range(N):
        answer *= A[i]

    # %%
    if answer > pow(10, 18):
        print(-1)
    else:
        print(answer)    

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    A = sorted(A, reverse = True)
    if A[-1] == 0:
        print(0)
        exit()
        
    answer = 1
    limit = pow(10, 18)
    for i in range(N):
        answer *= A[i]
        if answer > limit:
            print(-1)
            exit()
        else:
            continue

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    N, M, K = map(int, input().split())

    #output
    mod = 998244353

    n_ = 4*10**5 + 5
    fun = [1]*(n_+1)
    for i in range(1,n_+1):
        fun[i] = fun[i-1]*i%mod
    rev = [1]*(n_+1)
    rev[n_] = pow(fun[n_],mod-2,mod)
    for i in range(n_-1,0,-1):
        rev[i] = rev[i+1]*(i+1)%mod
    def cmb(n,r):
        if n <= 0 or r < 0 or r > n: return 0
        return fun[n]*rev[r]%mod*rev[n-r]%mod

    answer = 0
    for i in range(K+1):
        answer += M*pow(M-1, N-(i+1), mod)*cmb(N-1, i) % mod

    answer %= mod

    if N == 1:
        answer = M
    else:
        continue

    print(answer)
    

if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    N, M, K = map(int, input().split())

    #output
    mod = 998244353

    n_ = 4*10**5 + 5
    fun = [1]*(n_+1)
    for i in range(1,n_+1):
        fun[i] = fun[i-1]*i%mod
    rev = [1]*(n_+1)
    rev[n_] = pow(fun[n_],mod-2,mod)
    for i in range(n_-1,0,-1):
        rev[i] = rev[i+1]*(i+1)%mod
    def cmb(n,r):
        if n <= 0 or r < 0 or r > n: return 0
        return fun[n]*rev[r]%mod*rev[n-r]%mod

    answer = 0
    for i in range(K+1):
        answer += M*pow(M-1, N-(i+1), mod)*cmb(N-1, i) % mod

    answer %= mod

    if N == 1:
        print(M)
        exit()

    print(answer)
    

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    from collections import Counter
    import itertools
    N = int(input())

    dp = [[0, 0] for _ in range(N)]
    for i in range(N):
        S = str(input())
        T = []
        for s in S:
            if s == "(":
                T.append(1)
            else:
                T.append(-1)
        x = list(itertools.accumulate(T))[-1]
        y = min(itertools.accumulate(T))
        dp[i] = [x, y]


    #output
    dp1 = [[x, y] for x, y in dp if x >= 0]
    dp2 = [[x, y] for x, y in dp if x < 0]
    dp1 = sorted(dp1, key = lambda x:x[1], reverse = True)
    dp2 = sorted(dp2, key = lambda x:x[0]-x[1], reverse = True)
    dp = dp1 + dp2

    checker = 0
    for p in dp:
        if checker + p[1] < 0:
            print("No")
            exit()
        checker += p[0]

    if checker == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    from collections import Counter
    import itertools
    N = int(input())

    dp = [[0, 0] for _ in range(N)]
    for i in range(N):
        S = str(input())
        T = []
        for s in S:
            if s == "(":
                T.append(1)
            else:
                T.append(-1)
        x = list(itertools.accumulate(T))[-1]
        y = min(itertools.accumulate(T))
        dp[i] = [x, y]


    #output
    dp1 = [[x, y] for x, y in dp if x >= 0]
    dp2 = [[x, y] for x, y in dp if x < 0]
    dp1 = sorted(dp1, key = lambda x:x[1], reverse = True)
    dp2 = sorted(dp2, key = lambda x:x[0]-x[1], reverse = True)
    dp = dp1 + dp2

    checker = 0
    for p in dp:
        if checker + p[1] < 0:
            print("No")
            exit()
        checker += p[0]

    if checker == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()