Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
H, W, K = [int(x) for x in input().split()]
c = [[int(x) for x in list(input())] for _ in range(H)]
c.reverse()

max_score = 0
for y in range(H):
    for x in range(W):
        board = deepcopy(c)
        board[y][x] = None  # 消す
        score = 0
        erased = True
        coeff = 1
        while erased:
            erased = False
            # 落下させる
            for i in range(1, H):
                for j in range(W):
                    k = i
                    while k > 0 and board[k - 1][j] == None:
                        k -= 1
                    board[k][j], board[i][j] = board[i][j], board[k][j]

            # 消す
            for i in range(H):
                cnt = 1
                num = board[i][0]
                for j in range(1, W):
                    if board[i][j] != None and board[i][j] == board[i][j - 1]:
                        num = board[i][j]
                        cnt += 1
                    else:
                        if cnt >= K:
                            erased = True
                            score += coeff * cnt * num
                            board[i][j - cnt : j] = [None] * cnt
                        cnt = 1
                if cnt >= K:
                    erased = True
                    score += coeff * cnt * num
                    board[i][j - cnt + 1 : j + 1] = [None] * cnt

            coeff *= 2

        max_score = max(max_score, score)

print(max_score)

Fixed submission:
from copy import deepcopy
H, W, K = [int(x) for x in input().split()]
c = [[int(x) for x in list(input())] for _ in range(H)]
c.reverse()

max_score = 0
for y in range(H):
    for x in range(W):
        board = deepcopy(c)
        board[y][x] = None  # 消す
        score = 0
        erased = True
        coeff = 1
        while erased:
            erased = False
            # 落下させる
            for i in range(1, H):
                for j in range(W):
                    k = i
                    while k > 0 and board[k - 1][j] == None:
                        k -= 1
                    board[k][j], board[i][j] = board[i][j], board[k][j]

            # 消す
            for i in range(H):
                cnt = 1
                num = board[i][0]
                for j in range(1, W):
                    if board[i][j] != None and board[i][j] == board[i][j - 1]:
                        num = board[i][j]
                        cnt += 1
                    else:
                        if cnt >= K:
                            erased = True
                            score += coeff * cnt * num
                            board[i][j - cnt : j] = [None] * cnt
                        cnt = 1
                if cnt >= K:
                    erased = True
                    score += coeff * cnt * num
                    board[i][j - cnt + 1 : j + 1] = [None] * cnt

            coeff *= 2

        max_score = max(max_score, score)

print(max_score)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

cnt = [0] * 20010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 20010
flag = [0] * 20010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

Fixed submission:
N, Q = map(int, input().split())
S = input()

cnt = [0] * 200010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

cnt = [0] * 10010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 10010
flag = [0] * 10010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

Fixed submission:
N, Q = map(int, input().split())
S = input()

cnt = [0] * 200010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 1 :
    print("Hello World")
if n == 2 :
    a, b = map(int, input().split())
    print(a + b)

Fixed submission:
n = int(input())
if n == 1 :
    print("Hello World")
else :
    a = int(input())
    b = int(input())
    print(a + b)
Buggy python submission (verdict: Runtime Error):
k = int(input())
s = input()

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 10**6+5
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)

Fixed submission:
k = int(input())
s = input()

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2 == 1:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 2000005
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = map(int, input().split())
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
		break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
		break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
        break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = map(int, input().split())
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
	ans = ans * e;
	if ans > 10**18:
		ok = False
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)


Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = map(int, input().split())
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
	ans = ans * e;
	if ans > 10**18:
		ok = False
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)


Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
q = int(input())
x = {}
for i in lis:
    if i not in x:
        x[i]=1
    else:
        x[i]+=1
total = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    diff = b-a
    total += diff*x[a]
    x[b]+=x[a]
    print(total)

Fixed submission:
from collections import Counter
n = int(input())
lis = list(map(int,input().split()))
l = Counter(lis)
d = [0]+[l[i+1] for i in range(10**5)]
q = int(input())
s = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    if d[a]!=0:
        temp = d[a]
        d[a]=0
        d[b]+=temp
        s += temp*(b-a)
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int,input().split()))
prod = 1
for i in lis:
        prod=prod*i
print(prod) if(prod<=1000000000000000000) else print(-1)

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
prod = 1
if 0 in lis:
    print(0)
    exit(0)
for i in lis:
    if(prod>1000000000000000000):
        print(-1)
        exit(0)
    prod=prod*i
print(prod) if(prod<=1000000000000000000) else print(-1)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
flag=0
if s in t:
  if(len(t)-len(s)=1 and s[0]==t[0]):
    flag=1
print("Yes") if(flag) else print("No")

Fixed submission:
s = input()
t = input()
flag=0
if s in t:
  if(len(t)-len(s)==1 and s[0]==t[0]):
    flag=1
print("Yes") if(flag) else print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int, input().split()))
dp = {}
def TD(i):
    if i == n - 1:
        return 0

    if i in dp:
        return dp[i]
    mi = float('inf')
    for j in range(1, 3):
        if i + j < n:
            mi = min(mi, abs(lis[i] - lis[i+j])+TD(i+j))
    dp[i] = mi
    return mi
print(TD(0))   

Fixed submission:
from types import GeneratorType
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc
n = int(input())
lis = list(map(int, input().split()))
dp = {}
@bootstrap
def TD(i):
    if i == n - 1:
        yield 0

    if i in dp:
        yield dp[i]
    mi = float('inf')
    for j in range(1, 3):
        if i + j < n:
            tmp = yield TD(i+j)
            mi = min(mi, abs(lis[i] - lis[i+j])+ tmp)
    dp[i] = mi
    yield mi
print(TD(0))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for x,y in zip(A,B):
  dic[x] += 1
  dic[y] += 1
L = list(dic.values())
MAX = max(L)
if MAX > N:
  print("No"); exit()
INF = float("inf")
dicA_min = defaultdict(lambda: INF); dicA_max = defaultdict(lambda: 0)
dicB_min = defaultdict(lambda: INF); dicB_max = defaultdict(lambda: 0)
for i in range(N):
  dicA_min[A[i]] = min(dicA_min[A[i]],i)
  dicA_max[A[i]] = max(dicA_max[A[i]],i)
  dicB_min[B[i]] = min(dicB_min[B[i]],i)
  dicB_max[B[i]] = max(dicB_max[B[i]],i)
#print(dicA_min,dicA_max)
L = list(dicB_min.keys())
mink = -INF
maxk = INF
for t in L:
  if dicA_min[t] == INF:
    continue
  mink = max(dicA_max[t]-dicB_min[t]+1,mink)
  maxk = min(dicA_min[t]+N-dicB_max[t]-1,maxk)
#print(mink,maxk)
if mink >= 0:
  ans = B[-mink:] + B[:-mink]
else:
  ans = B[-mink:] + B[:-mink]
print("Yes")
print(*ans)

Fixed submission:
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for x,y in zip(A,B):
  dic[x] += 1
  dic[y] += 1
L = list(dic.values())
MAX = max(L)
if MAX > N:
  print("No"); exit()
INF = float("inf")
dicA_min = defaultdict(lambda: INF); dicA_max = defaultdict(lambda: 0)
dicB_min = defaultdict(lambda: INF); dicB_max = defaultdict(lambda: 0)
for i in range(N):
  dicA_min[A[i]] = min(dicA_min[A[i]],i)
  dicA_max[A[i]] = max(dicA_max[A[i]],i)
  dicB_min[B[i]] = min(dicB_min[B[i]],i)
  dicB_max[B[i]] = max(dicB_max[B[i]],i)
#print(dicA_min,dicA_max)
L = list(dicB_min.keys())
mink = -INF
maxk = INF
Flag = False
for t in L:
  if dicA_min[t] == INF:
    continue
  mink = max(dicA_max[t]-dicB_min[t]+1,mink)
  maxk = min(dicA_min[t]+N-dicB_max[t]-1,maxk)
  Flag = True
if not Flag:
  print("Yes")
  print(*B)
  exit()
#print(mink,maxk)
if mink >= 0:
  ans = B[-mink:] + B[:-mink]
else:
  ans = B[-mink:] + B[:-mink]
print("Yes")
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N,Q = map(int,input().split())
A = list(map(int,input().split()))
Tree = SegmentTree(A, segfunc, 0)
for _ in range(Q):
  query, a,b = map(int,input().split())
  if query == 0:
    Tree.add(a,b)
  else:
    print(Tree.sum(a,b))


Fixed submission:
def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N,Q = map(int,input().split())
A = list(map(int,input().split()))
Tree = SegmentTree(A, segfunc, 0)
for _ in range(Q):
  query, a,b = map(int,input().split())
  if query == 0:
    Tree.add(a,b)
  else:
    print(Tree.sum(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def segfunc(x,y):
  return max(x,y)

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)
INF = float("inf")
H,W,M = map(int,input().split())
A = [0 for _ in range(H)]
B = [0 for _ in range(W)]
Treeh = SegmentTree(A,segfunc,-INF)
Treew = SegmentTree(B,segfunc,-INF)
G = [[False]*W for _ in range(H)]
for i in range(M):
  h,w = map(int,input().split())
  h-=1;w-=1
  G[h][w] = True
  Treeh.add(h,1)
  Treew.add(w,1)
X = Treeh.sum(0,H)
Y = Treew.sum(0,W)
MaxX_L = []
for i in range(H):
  #print(Treeh.__getitem__(i))
  if Treeh.__getitem__(i) == X:
    MaxX_L.append(i)
MaxY_L = []
for i in range(W):
  #print(Treeh.__getitem__(i))
  if Treew.__getitem__(i) == Y:
    MaxY_L.append(i)
ans = X+Y
for x in MaxX_L:
  for y in MaxY_L:
    if not G[x][y]:
      print(ans)
      exit()
ans -= 1

print(ans)

Fixed submission:
H,W,M = map(int,input().split())
Bomb = []
H_num = [0 for _ in range(H)]
W_num = [0 for _ in range(W)]
for i in range(M):
  a,b = map(int,input().split())
  a-=1;b-=1
  Bomb.append([a,b])
  H_num[a] += 1
  W_num[b] += 1

HMAX = max(H_num);WMAX = max(W_num)
ans = HMAX+WMAX
HMAX_list = set([]); WMAX_list = set([])
for i in range(H):
  if H_num[i] == HMAX:
    HMAX_list.add(i)
for i in range(W):
  if W_num[i] == WMAX:
    WMAX_list.add(i)
kosu = len(HMAX_list)*len(WMAX_list)
cnt = 0
for z in Bomb:
  x = z[0];y = z[1]
  if x in HMAX_list and y in WMAX_list:
    cnt += 1
#print(kosu,cnt)
if cnt < kosu:
  print(ans)
else:
  print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
  P[i]-=1
#print(P)
C = list(map(int,input().split()))
Flag = True
for c in C:
  if c >= 0:
    Flag = False
    break
if Flag:
  print(max(C))
  exit()
L = []
for i in range(N):
  visited = set([])
  now = i
  temp = []
  while now not in visited:
    nxt = P[now]
    visited.add(now)
    temp.append(C[nxt])
    now = nxt
  L.append(temp)
#print(L)
ans = 0
S = []
for X in L:
  start = [0]
  for i in range(len(X)):
    temp = start[-1]+X[i]
    start.append(temp)
  S.append(start)
#print(S)
for X,SS in zip(L,S):
  n = len(X)
  cycle_sum = SS[-1]
  if K <= n:
    kouho = max(SS[:K+1])
  elif cycle_sum < 0:
    kouho = max(SS)
  else:
    amari = K%n
    loop = K//n
    first = 0 #余りよりも後で最大
    second = 0 #余りよりも前で最大
    first = (loop-1)*cycle_sum + max(SS)
    second = loop*cycle_sum + max(SS[:amari+1])
    kouho = max(first,second)
  ans = max(ans,kouho)
print(ans)
  
    
  


Fixed submission:
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
  P[i]-=1
#print(P)
C = list(map(int,input().split()))
Flag = True
for c in C:
  if c >= 0:
    Flag = False
    break
if Flag:
  print(max(C))
  exit()
L = []
for i in range(N):
  visited = set([])
  now = i
  temp = []
  while now not in visited:
    nxt = P[now]
    visited.add(now)
    temp.append(C[nxt])
    now = nxt
  L.append(temp)
#print(L)
ans = 0
S = []
for X in L:
  start = [0]
  for i in range(len(X)):
    temp = start[-1]+X[i]
    start.append(temp)
  S.append(start)
#print(S)
for X,SS in zip(L,S):
  n = len(X)
  cycle_sum = SS[-1]
  if K <= n:
    kouho = max(SS[:K+1])
  elif cycle_sum < 0:
    kouho = max(SS)
  else:
    amari = K%n
    loop = K//n
    first = 0 #余りよりも後で最大
    second = 0 #余りよりも前で最大
    first = (loop-1)*cycle_sum + max(SS)
    second = loop*cycle_sum + max(SS[:amari+1])
    kouho = max(first,second)
  ans = max(ans,kouho)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1,N+1): #1-N
  first = i; kosu = N//i
  end = kosu*i
  temp = (first+end)*kosu//2
  ans += temp
print(ans)


Fixed submission:
N = int(input())
ans = 0

for i in range(1,N+1):
  num = N//i
  temp = i*(1+num)*num//2
  ans += temp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n] * finv[r] * finv[n-r] % p

N = 2*pow(10,6)+100
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD


K = int(input())
S = str(input())
s = len(S)

ans = 0
for i in range(K+1):#後ろが0個からK個まで
  factor = pow(25,K-i,MOD)*pow(26,i,MOD)%MOD
  ans = (ans + factor*cmb(s+K-i-1,s-1,MOD))%MOD

ans = ans %MOD
print(ans)
  
  

Fixed submission:
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n] * finv[r] * finv[n-r] % p

N = 2*pow(10,6)+100
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD


K = int(input())
S = str(input())
s = len(S)

ans = 0
for i in range(K+1):#後ろが0個からK個まで
  factor = pow(25,K-i,MOD)*pow(26,i,MOD)%MOD
  ans = (ans + factor*cmb(s+K-i-1,s-1,MOD))%MOD

ans = ans %MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())
MOD = 998244353

dp = [[0 for _ in range(D+1)] for _ in range(C+1)]
dp[A][B] = 1
#dp[i][j] ヨコi番目でそこまでの最大の高さがj

for i in range(A,C+1):
  for j in range(B,D+1):
    if i > A:
      dp[i][j] += dp[i-1][j]*j
    if j > B:
      dp[i][j] += dp[i][j-1]*i
    if i > A and j > B:
      dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= MOD

ans = dp[C][D]
print(ans)
      

Fixed submission:
A,B,C,D = map(int,input().split())
MOD = 998244353

dp = [[0 for _ in range(D+1)] for _ in range(C+1)]
dp[A][B] = 1
#dp[i][j] ヨコi番目でそこまでの最大の高さがj

for i in range(A,C+1):
  for j in range(B,D+1):
    if i > A:
      dp[i][j] += dp[i-1][j]*j
    if j > B:
      dp[i][j] += dp[i][j-1]*i
    if i > A and j > B:
      dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= MOD

ans = dp[C][D]
print(ans)