Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

def main():
    n, m, k = map(int, input().split())
    div = 998244353

    ret = 0
    comb = 1
    x = m * ((m-1) ** (n-k-1))
    comb_list = [0] * (k+1)
    x_list = [0] * (k+1)
    comb_list[0] = comb
    x_list[0] = x
    for i in range(1, k+1):
        comb = comb * (n-i) // i
        x = x * (m-1) % div
        comb_list[i] = comb
        x_list[i] = x

    for i in range(k+1):
        ret += comb_list[i] * x_list[k-i] % div
        ret %= div

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

def main():
    n, m, k = map(int, input().split())
    div = 998244353

    ret = 0
    comb = 1
    x = m * ((m-1) ** (n-k-1))
    comb_list = [comb]
    x_list = [x]
    for i in range(1, k+1):
        comb = comb * (n-i) // i
        x = x * (m-1) % div
        comb_list.append(comb)
        x_list.append(x)

    x_list.reverse()
    for i in range(k+1):
        ret += comb_list[i] * x_list[i] % div
        ret %= div

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

def main():
    n, m, k = map(int, input().split())
    div = 998244353

    ret = 0
    comb = 1
    x = m * ((m-1) ** (n-k-1))
    comb_list = [comb]
    x_list = [x]
    for i in range(1, k+1):
        comb = comb * (n-i) // i
        x = x * (m-1) % div
        comb_list.append(comb)
        x_list.append(x)

    x_list.reverse()
    for i in range(k+1):
        ret += comb_list[i] * x_list[i] % div
        ret %= div

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()

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

def main():
    n, m, k = map(int, input().split())
    div = 998244353

    ret = 0
    comb = 1
    x = m * ((m-1) ** (n-1))
    for i in range(k+1):
        if i >= 1:
            comb = comb * (n-i) // i % div
            x = x // (m-1)
        ret += comb * x % div
        ret %= div

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()