Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [x + y for x in al for y in bl] 
print(min(price))

Fixed submission:
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [min(al)+min(bl)] 
print(min(price))

Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [x + y for x in al for y in bl] 
print(min(price))

Fixed submission:
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [min(al)+min(bl)] 
print(min(price))
Buggy python submission (verdict: Runtime Error):
S = input()
pritn("Yes" if "AB" in S or "BA" in S else "No")

Fixed submission:
S = input()
print("Yes" if "AB" in S or "BA" in S else "No")
Buggy python submission (verdict: Runtime Error):
s,t=input().split();a,b=map(int,input().split());print(f"{a-1} {b}" if s==input()else f"{a} {b-1}")

Fixed submission:
s,t=input().split();a,b=map(int,input().split());u=input();print("%d %d" %(a-1 if s==u else a,b-1 if s!=u else b))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = (int(x)for x in input().split())
    if n <= k:
        print(0)
        return
    hl = [int(x)for x in input().split()]
    hl = sorted(hl, reverse=1)
    for x in range(1, k+1):
        hl = hl[1:]
    print(sum(hl))


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n, k = (int(x) for x in input().split())
    if n <= k:
        print(0)
        return
    hl = [int(x) for x in input().split()]
    hl = sorted(hl, reverse=1)[k:]
    print(sum(hl))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print("ls:",ls)
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print("ls(sorted):",ls)
if debug:
    print("debug end")
for x in ls:
    print(x[0])

Fixed submission:
print(eval("3*"+input().replace(" ","+"))//2)
Buggy python submission (verdict: Runtime Error):
from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print(f"ls: {ls}")
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print(f"ls(sorted): {ls}")
if debug:
    print("debug end")
for x in ls:
    print(x[0])

Fixed submission:
from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print("ls:",ls)
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print("ls(sorted):",ls)
if debug:
    print("debug end")
for x in ls:
    print(x[0])
Buggy python submission (verdict: Runtime Error):
print(sum(int(input())))

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Runtime Error):
t,a,b=map(int,input());print((t*a,b)[t*a>b])

Fixed submission:
t,a,b=map(int,input().split())
if a*t>b:
    print(b)
else:
    print(a*t)
Buggy python submission (verdict: Runtime Error):
a,b = map(chr, input().split())
print("=" if a == b else ">" if a > b else "<")

Fixed submission:
a,b = map(ord, input().split())
print("=" if a == b else ">" if a > b else "<")
Buggy python submission (verdict: Runtime Error):
print(int(int(input())**.5)**2)

Fixed submission:
print("YNEOS"[input()!=input()[::-1]::2])
Buggy python submission (verdict: Runtime Error):
a=sorted(set(input())^set(map(chr(range(97,123)))));print(a and a[0]or None)

Fixed submission:
a=sorted(set(input())^set(chr(i)for i in range(97,123)));print(a and a[0]or None)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split());print(min(b,d)-max(a,c))

Fixed submission:
s=input();print("YNeos"[s!=s[::-1]::2])
Buggy python submission (verdict: Runtime Error):
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        inp.close();
        System.out.println((a + b) < 10 ? a + b : "error");
    }
}

Fixed submission:
p = sum(map(int, input().split()))
if p < 10:
    print(p)
else:
    print("error")

Buggy python submission (verdict: Runtime Error):
s=eval(input()).replace(" ","+");print(s if s < 10 else"10")

Fixed submission:
p = sum(map(int, input().split()))
if p < 10:
    print(p)
else:
    print("error")
Buggy python submission (verdict: Runtime Error):
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        inp.next();
        char s = inp.next().toCharArray()[0];
        System.out.println("A" + s + "C");
    }
}

Fixed submission:
a,b,c=input().split();print(a[0]+b[0]+c[0])
Buggy python submission (verdict: Runtime Error):
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int c = inp.nextInt();
        boolean flag = false;
        if ((a + b) == c) flag = true;
        if ((a + c) == b) flag = true;
        if ((b + c) == a) flag = true;
        System.out.println(flag ? "Yes" : "No");
    }
}

Fixed submission:
a, b, c = map(int, input().split())
if (a + b == c or a + c == b or b + c == a):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    r, c, k = map(int, input().split())
    item = [[0]*c for _ in range(r)]
    
    for i in range(k):
        a, b, v = map(int, input().split())
        item[a-1][b-1] = v
    
    dp0 = [[0]*(c+1) for _ in range(r+1)]
    dp1 = [[0]*(c+1) for _ in range(r+1)]
    dp2 = [[0]*(c+1) for _ in range(r+1)]
    dp3 = [[0]*(c+1) for _ in range(r+1)]
    
    for i in range(r):
        for j in range(c):
            if item[i][j] == 0:
                dp0[i+1][j+1] = max([dp0[i][j+1], dp0[i+1][j], dp1[i][j+1], dp2[i][j+1], dp3[i][j+1]])
                dp1[i+1][j+1] = dp1[i+1][j]
                dp2[i+1][j+1] = dp2[i+1][j]
                dp3[i+1][j+1] = dp3[i+1][j]
                continue
            dp0[i+1][j+1] = max([dp0[i][j+1], dp0[i+1][j], dp1[i][j+1], dp2[i][j+1], dp3[i][j+1]])
            dp1[i+1][j+1] = max(dp0[i+1][j]+item[i][j], dp1[i+1][j], dp0[i][j+1]+item[i][j], dp1[i][j+1]+item[i][j], dp2[i][j+1]+item[i][j], dp3[i][j+1]+item[i][j])
            dp2[i+1][j+1] = max(dp1[i+1][j]+item[i][j], dp2[i+1][j])
            dp3[i+1][j+1] = max(dp2[i+1][j]+item[i][j], dp3[i+1][j])
    
    ans = max([dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]])
    print(ans)
            
    
    
if __name__ == "__main__":
    main()




Fixed submission:
import sys
input = sys.stdin.readline

def main():
    r, c, k = map(int, input().split())
    item = [[0]*c for _ in range(r)]
    
    for i in range(k):
        a, b, v = map(int, input().split())
        item[a-1][b-1] = v
    
    dp0 = [[0]*(c+1) for _ in range(r+1)]
    dp1 = [[0]*(c+1) for _ in range(r+1)]
    dp2 = [[0]*(c+1) for _ in range(r+1)]
    dp3 = [[0]*(c+1) for _ in range(r+1)]
    
    for i in range(r):
        for j in range(c):
            if item[i][j] == 0:
                dp0[i+1][j+1] = max([dp0[i][j+1], dp0[i+1][j], dp1[i][j+1], dp2[i][j+1], dp3[i][j+1]])
                dp1[i+1][j+1] = dp1[i+1][j]
                dp2[i+1][j+1] = dp2[i+1][j]
                dp3[i+1][j+1] = dp3[i+1][j]
                continue
            dp0[i+1][j+1] = max([dp0[i][j+1], dp0[i+1][j], dp1[i][j+1], dp2[i][j+1], dp3[i][j+1]])
            dp1[i+1][j+1] = max(dp0[i+1][j]+item[i][j], dp1[i+1][j], dp0[i][j+1]+item[i][j], dp1[i][j+1]+item[i][j], dp2[i][j+1]+item[i][j], dp3[i][j+1]+item[i][j])
            dp2[i+1][j+1] = max(dp1[i+1][j]+item[i][j], dp2[i+1][j])
            dp3[i+1][j+1] = max(dp2[i+1][j]+item[i][j], dp3[i+1][j])
    
    ans = max([dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]])
    print(ans)
            
    
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from decimal import Decimal
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [divide(int(Decimal(float(input()))*1e9)) for _ in range(n)]

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1
    
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            dp[i][j] += dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1]

    ans = 0
    for i in range(n):
        c1, c2 = a[i]
        if (c1 >= 9 and c2 >= 9):
            ans -= 1
        ans += dp[18-c1][18-c2]
        
    print(ans//2)
    

if __name__ == "__main__":
    main()


Fixed submission:
def divide(n, p):
    c = 0
    while n%p == 0 and c < 18:
        c += 1
        n //= p
    return c

n = int(input())
table = [[0]*19 for _ in range(19)]
for i in range(n):
    sub = input()
    key = float(sub)
    if "." in sub:
        a, b = map(str, sub.split("."))
        s = int(a)*1000000000+10**(9-len(b))*int(b)
    else:
        s = int(sub)
        s *= 1000000000
    if key != s/1000000000:
        while True:
            pass
    c2, c5 = divide(s, 2), divide(s, 5)
    table[c2][c5] += 1

ans = 0
for i in range(19):
    for j in range(19):
        for k in range(19):
            for l in range(19):
                if i+k < 18 or j+l < 18:
                    continue;
                if i == k and j == l:
                    ans += table[i][j]*(table[k][l]-1)
                else:
                    ans += table[i][j]*table[k][l]

ans //= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>

int main(){
  int x;
  scanf("%d", &x);
  
  if (x >= 30){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  return 0;
}

Fixed submission:
x = int(input())
if x >= 30:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
import heapq

n, k = map(int, input().split())
a = [(-int(x), 1) for x in input().split()]
heapq.heapify(a)

for i in range(k):
  key = heapq.heappop(a)
  heapq.heappush(a, (key[0]*key[1]/(key[1]+1), key[1]+1))

print(math.ceil(-heapq.heappop(a)[0]))

Fixed submission:
import math

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

l, r = 0, 10**9+2

while r-l > 1:
  key = (r+l)//2
  count = 0
  for i in range(n):
    count += (a[i]-1)//key
  if count <= k:
    r = key
  else:
    l = key

print(r)
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [0]+[int(x) for x in input().split()]

count = sum(a)
p = n-1
ans = 0
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)
  
  

Fixed submission:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [0]+[int(x) for x in input().split()]

count = sum(a)
p = n-1
ans = 0
judge = True
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k and judge:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      else:
        judge = False
      break
  if count > k:
    break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

p, q = 0, 0
ans = 0
key = 0
while key <= k:
  if p == n and q == m:
    break
  elif p == n:
    if key+b[q] <= k:
      ans += 1
      key += b[q]
      q += 1
    else:
      break
  elif q == m:
    if key+a[p] <= k:
      ans += 1
      key += a[p]
      p += 1
    else:
      break
  else:
    if a[p] < b[q]:
      if key+a[p] <= k:
        ans += 1
        key += a[p]
        p += 1
      else:
        break
    elif a[p] > b[q]:
      if key+b[q] <= k:
        ans += 1
        key += b[q]
        q += 1
      else:
        break
    else:
      if a[p] + key > k:
        break
      if a[p+1] <= b[q+1]:
        ans += 1
        key += a[p]
        p += 1
      else:
        ans += 1
        key += b[q]
        q += 1

print(ans)

Fixed submission:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [0]+[int(x) for x in input().split()]

count = sum(a)
p = n-1
ans = 0
judge = True
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k and judge:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      else:
        judge = False
      break
  if count > k:
    break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
mod = pow(10, 9)+7
ans = 0
a = 1
b = 1
c = 1
for i in range(m-n+1, m+1):
  b *= i
  b %= mod
for i in range(n+1):
  k = -1 if i%2 else 1
  ans += k*a*b**2*c
  ans %= mod
  a *= m-i
  a %= mod
  b *= pow(m-i, mod-2, mod)
  b %= mod
  c *= n-i
  c *= pow(i+1, mod-2, mod)
  c %= mod
print(ans)

Fixed submission:
n, m = map(int, input().split())
mod = pow(10, 9)+7
ans = 0
a = 1
b = 1
c = 1
for i in range(m-n+1, m+1):
  b *= i
  b %= mod
for i in range(n+1):
  k = -1 if i%2 else 1
  ans += k*a*b**2*c
  ans %= mod
  a *= m-i
  a %= mod
  b *= pow(m-i, mod-2, mod)
  b %= mod
  c *= n-i
  c *= pow(i+1, mod-2, mod)
  c %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    mod = 998244353
    
    a, b, c, d = map(int, input().split())
    dp = dict()
    for i in range(a, c+1):
        for j in range(b, d+1):
            if i == a and j == b:
                dp[(i, j)] = 1
                continue
            if j == b:
                dp[(i, j)] = dp[(i-1, j)]*j%mod
                continue
            if i == a:
                dp[(i, j)] = dp[(i, j-1)]*i%mod
                continue
            dp[(i, j)] = (dp[(i-1, j)]*j+dp[(i, j-1)]*i+mod-dp[(i-1, j-1)]*(i-1)*(j-1))%mod
    print(dp[(c, d)])        
    

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    mod = 998244353
    
    a, b, c, d = map(int, input().split())
    dp = [[0]*(d+1) for _ in range(c+1)]
    for i in range(a, c+1):
        for j in range(b, d+1):
            if i == a and j == b:
                dp[i][j] = 1
                continue
            if j == b:
                dp[i][j] = dp[i-1][j]*j%mod
                continue
            if i == a:
                dp[i][j] = dp[i][j-1]*i%mod
                continue
            dp[i][j] = (dp[i-1][j]*j+dp[i][j-1]*i+mod-dp[i-1][j-1]*(i-1)*(j-1)%mod)%mod
    print(dp[c][d])        
            

if __name__ == "__main__":
    main()

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

def main():
    input = sys.stdin.readline
    mod = 998244353
    
    a, b, c, d = map(int, input().split())
    dp = dict()
    for i in range(a, c+1):
        for j in range(b, d+1):
            if i == a and j == b:
                dp[(i, j)] = 1
                continue
            if j == b:
                dp[(i, j)] = dp[(i-1, j)]*j%mod
                continue
            if i == a:
                dp[(i, j)] = dp[(i, j-1)]*i%mod
                continue
            dp[(i, j)] = (dp[(i-1, j)]*j+dp[(i, j-1)]*i+mod-dp[(i-1, j-1)]*(i-1)*(j-1))%mod
    print(dp[(c, d)])        
            

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    mod = 998244353
    
    a, b, c, d = map(int, input().split())
    dp = [[0]*(d+1) for _ in range(c+1)]
    for i in range(a, c+1):
        for j in range(b, d+1):
            if i == a and j == b:
                dp[i][j] = 1
                continue
            if j == b:
                dp[i][j] = dp[i-1][j]*j%mod
                continue
            if i == a:
                dp[i][j] = dp[i][j-1]*i%mod
                continue
            dp[i][j] = (dp[i-1][j]*j+dp[i][j-1]*i+mod-dp[i-1][j-1]*(i-1)*(j-1)%mod)%mod
    print(dp[c][d])        
            

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    key = 1
    nn = n
    while nn > 0:
        key += 1
        nn //= 2
    
    for _ in range(min([key*2, k])):
        b = [0]*n
        for i in range(n):
            l, r = max([i-a[i], 0]), min([i+a[i], n-1])
            b[l] += 1
            if r != n-1:
                b[r+1] -= 1
        for i in range(n):
            a[i] = 0
            a[i] += b[i]
            if i != 0:
                 a[i] += a[i-1]
    print(*a)

if __name__ == "__main__":
    main()

Fixed submission:
s = input()
print(s[:3])

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

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    key = 30
    nn = n
    while nn > 0:
        key += 1
        nn //= 2
    
    for _ in range(min([key, k])):
        b = [0]*n
        for i in range(n):
            l, r = max([i-a[i], 0]), min([i+a[i], n-1])
            b[l] += 1
            if r != n-1:
                b[r+1] -= 1
        for i in range(n):
            a[i] = 0
            a[i] += b[i]
            if i != 0:
                 a[i] += a[i-1]
    print(*a)

if __name__ == "__main__":
    main()


Fixed submission:
s = input()
print(s[:3])
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
books = [0]*n
for i in range(n):
  books[i] = [int(x) for x in input().split()]

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):n, m, x = map(int, input().split())
books = [0]*n
for i in range(n):
  books[i] = [int(x) for x in input().split()]

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      cost += books[j][0]
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)

Fixed submission:
n, m, x = map(int, input().split())
books = [0]*n
for i in range(n):
  books[i] = [int(x) for x in input().split()]

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      cost += books[j][0]
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy

def main():
  input = sys.stdin.readline
  n, k = map(int, input().split())
  a = [int(x)-1 for x in input().split()]
  key = [copy.deepcopy(a) for _ in range(61)]
  for i in range(60):
    for j in range(n):
      key[i+1][j] = key[i][key[i][j]]
  
  i = 0
  now = 0
  while k > 0:
    if k%2:
      now = key[i][now]
    k //= 2
    i += 1
  
  print(now+1)
  
if __name__ == "__main__":
  main()

Fixed submission:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

already = [0]*n
already[0] = 0
now = 0
count = 1
while True:
  count += 1
  now = a[now]-1
  if already[now]:
    k1 = already[now]
    k2 = count-already[now]
    break
  else:
    already[now] = count

if k > k2+k1:
  k -= k2+k1
  k %= k2
  ans = 1
  for i in range(k1):
    ans = a[ans-1]
  for i in range(k):
    ans = a[ans-1]
else:
  ans = 1
  for i in range(k):
    ans = a[ans-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
mod = 998244353

ans = 0
comb = 1
for i in range(k+1):
  ans += (((m*pow(m-1,n-i-1,mod))%mod)*comb)%mod
  ans %= mod
  comb *= (n-1-i)
  comb //= i+1

print(ans)

Fixed submission:
n, m, k = map(int, input().split())
mod = 998244353

ans = 0
comb = 1
for i in range(k+1):
  ans += (((m*pow(m-1,n-i-1,mod))%mod)*comb)%mod
  ans %= mod
  comb *= (n-1-i)
  comb %= mod
  comb *= pow(i+1, mod-2, mod)
  comb %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Fixed submission:
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10
  mod %= 2019

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = n
l = 0
while s > 0:
  l += 1
  s //= 10
key = [0]*2019
mod = 10
for i in range(l):
  judge = n%mod
  k = judge%2019
  key[k] += 1
  mod *= 10

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Fixed submission:
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10
  mod %= 2019

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
key = [0]*2019
for i in range(l):
  n = int(s[l-i-1:])
  k = n%2019
  key[k] += 1

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Fixed submission:
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10
  mod %= 2019

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)