Question:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
print(dp[-1]*(2*p) % mod)

Choices:
- Runtime Error
- Internal error
- Compile Error
- Time Limit Exceeded


Question:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,b=map(int,input().split())
ans=1
while ans*8//100!=a or ans//10!=b:
    ans+=1
print(ans)

Choices:
- Memory Limit Exceeded
- Internal error
- Compile Error
- Time Limit Exceeded


Question:
n,k = map(int,input().split())
mod = 10**9+7
v = [0]*(k+1)
ans = 0
for i in range(k,0,-1):
    if v[i] == 0:
        v[i] = ((k//i)**n-sum(v[i::i])) % mod
        ans += v[i]*i
        ans %= mod
print(ans)

Choices:
- No abnormally found
- Internal error
- Time Limit Exceeded
- Runtime Error


Question:
n,k = map(int,input().split())
mod = 10**9+7
v = [0]*(k+1)
ans = 0
for i in range(k,0,-1):
    if v[i] == 0:
        v[i] = ((k//i)**n-sum(v[i::i])) % mod
for i in range(k+1):
    ans += v[i]*i
    ans %= mod
print(ans)

Choices:
- Internal error
- Memory Limit Exceeded
- No abnormally found
- Time Limit Exceeded


Question:
n = int(input())
ans = 0
tbl1 = [[0]*10 for i in range(10)]
tbl2 = [[0]*10 for i in range(10)]
# for j in range(10):
#     for k in range(10):
#         cnt1 = 0
#         cnt2 = 0
#         for i in range(1,n+1):
#             s = str(i)
#             if s[0] == str(k)and s[-1] == str(j):
#                 cnt1 += 1
#             if s[0] == str(j) and s[-1] == str(k):
#                 cnt2 += 1
#         ans += cnt1*cnt2
for i in  range(1,n+1):
    s = str(i)
    for j in range(10):
        for k in range(10):
            if s[0] == str(k)and s[-1] == str(j):
                tbl1[k][j] += 1
            if s[0] == str(j) and s[-1] == str(k):
                tbl2[j][k] += 1
for j in range(10):
        for k in range(10):
            ans += tbl1[k][j] * tbl2[j][k]
print(ans)

Choices:
- Time Limit Exceeded
- No abnormally found
- Internal error
- Memory Limit Exceeded


Question:
t,x = map(int(input()))
print(t/x)

Choices:
- Memory Limit Exceeded
- No abnormally found
- Runtime Error
- Compile Error


Question:
import sys
input = sys.stdin.readline
n = int(input())
s = str(input())
r = []
g = []
b = []
ra = r.append
ga = g.append
ba = b.append
for i in range(n):
  if s[i] == "R":
    ra(i)
  elif s[i] == "G":
    ga(i)
  else:
    ba(i)
c = len(r)*len(g)*len(b)
for ri in r:
  for gi in g:
    for bi in b:
      if 3*(max(ri,gi,bi)+min(ri,gi,bi)) == 2*(ri+gi+bi):
        c -= 1
print(c)

Choices:
- Time Limit Exceeded
- Internal error
- No abnormally found
- Runtime Error


Question:
import math
n = int(input())
d = int(input())
print(math.ceil(n/(2*d+1)))

Choices:
- Internal error
- Memory Limit Exceeded
- Runtime Error
- Compile Error


Question:
N,M,C = map(int,input().split())
B = list(map(input().split()))
result = 0
for i in range(N):
  C = 0
  A = list(map(input().split()))
  for j in range(M):
    C += B[j]*A[j]
  if sum(C) > 0:
    result += 1
  else:
    None
print(result)

Choices:
- No abnormally found
- Compile Error
- Memory Limit Exceeded
- Runtime Error


Question:
a = list(map(int,input().split(/)))
if a[1] > 4:
  print("TBD")
else:
  print("Heisei")

Choices:
- Runtime Error
- Internal error
- Compile Error
- Memory Limit Exceeded


Question:
N = int(input())
A = list(map(int,input().split()))
result = 0
for i in range(N-1):
  if A[i] == A[i+1]:
    result += 1
    if A[i+2]!=A[i+1] :
      A[i+1] = abs(A[i+2]-A[i+1])
    elif A[i+2]==A[i+1] and A[i+1]==1:
      A[i+1] = 2
    else:
      A[i+1] = 1
print(result)

Choices:
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded
- Internal error


Question:
x,y = map(int,input().split())
if abs(x) == abs(y):
  print(0 if a == b else 1)
elif x < y:
  print(min(y - x,abs(y + x) + 1))
else:
  print(min(abs(y+x),abs(y-x))+ 1 if a * b <= 0 else min(abs(y+x),abs(y-x))+ 2)

Choices:
- Internal error
- Memory Limit Exceeded
- Runtime Error
- No abnormally found


Question:
x,y = map(int,input().split())
ans = abs(abs(x)-abs(y))
print(ans if X * y > 0 else ans + 1)

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- Compile Error


Question:
S = input()
print("No" if (s.count("N") == 0 and s.count("S") > 0)\
		or (s.count("S") == 0 and s.count("N") > 0)\
		or (s.count("W") == 0 and s.count("E") > 0)\
		or (s.count("E") == 0 and s.count("W") > 0)\
		else "Yes")

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
S = input()
print("No" if(s.count("N") == 0 and s.count("S") > 0)\
		or (s.count("S") == 0 and s.count("N") > 0)\
		or (s.count("W") == 0 and s.count("E") > 0)\
		or (s.count("E") == 0 and s.count("W") > 0)\
		else "Yes")

Choices:
- Compile Error
- Internal error
- Runtime Error
- Memory Limit Exceeded


Question:
N,D=map(int,input().split())
print(math.ceil(N/(2*D+1)))

Choices:
- Time Limit Exceeded
- Internal error
- Compile Error
- Runtime Error


Question:
# B - Stone Monument
N, M = map(int,input().split())

tmp= (M-N)*( M-N+1)/2

ans( tmp-N)

Choices:
- No abnormally found
- Internal error
- Runtime Error
- Memory Limit Exceeded


Question:
from copy import deepcopy
N, K = map(int, input().split())
positiveD = [[] for _ in range(N+1)]
negativeD = [[] for _ in range(N+1)]
Const = []
for _ in range(K):
    inputList = [int(i) for i in input().split()]
    if inputList[0] == 0:
        Const = inputList
    elif inputList[1] > 0:
        positiveD[inputList[0]].append(inputList)
    else:
        negativeD[inputList[0]].append(inputList)

def ChooseGroup(DList): #i次項の中でxjを共通に持つ項を選ぶ
    Group = []
    if len(DList) == 1:
        Group.append(DList.pop())
        commonfact = Group[0][2]
    else:
        for a in range(len(DList)):
            for b in range(len(DList)):
                if a != b and set(DList[a][2:]) & set(DList[b][2:]):
                    commonfact = list(set(DList[a][2:]) & set(DList[b][2:]))[0]
                    break

        for items in DList:
            if commonfact in items[2:]:
                Group.append(items)
        for items in Group:
            DList.remove(items)
    return (Group, commonfact)

def PositiveDegrade(i, x, DList): #i次の項を下げる
    while DList[i]:
        CommonGroup, CommonFactor = ChooseGroup(DList[i])
        next = i - 1
        totalaH = 0
        for items in CommonGroup:
            newList = [next, items[1]]
            for d in items[2:]:
                if d != CommonFactor: newList.append(d)
            totalaH += items[1]
            negativeTerm = deepcopy(items)
            negativeTerm.append(N+x)
            negativeTerm[1] *= -1
            for j in DList[next]: #次数を落とした項を、該当するリストに格納
                if set(j[2:]) == set(newList[2:]):
                    j[1] += newList[1]
                    break
            else: DList[next].append(newList)
            negativeD[i].append(negativeTerm)
        for j in DList[2]:
            if j[2:] == [CommonFactor, N+x]:
                j[1] += totalaH
                break
        else: DList[2].append([2, totalaH, CommonFactor, N+x])
        x += 1

def NegativeDegrade(i, x, DList):
    while DList[i]:
        item = DList[i].pop()
        for j in positiveD[1]:
            if j[2] == N+x:
                j[1] += -item[1] * (i-1)
                break
        else: positiveD[1].append([1, -item[1] * (i-1), N + x])
        for d in item[2:]:
            DList[2].append([2, item[1], d, N + x])
        x += 1
    return x

x = 1
for i in reversed(range(3, N+1)):
    PositiveDegrade(i, x, positiveD)

for i in range(3, N+1):
    x = NegativeDegrade(i, x, negativeD)

Merged = [deepcopy(positiveD[1]), deepcopy(positiveD[2])]
for item in negativeD[1]:
    for compare in Merged[0]:
        if item[2:] == compare[2:]:
            compare[1] += item[1]
            if compare[1] == 0:
                Merged[0].remove(compare)
            break
    else: Merged[0].append(item)
for item in negativeD[2]:
    for compare in Merged[1]:
        if item[2:] == compare[2:]:
            compare[1] += item[1]
            if compare[1] == 0:
                Merged[1].remove(compare)
            break
    else: Merged[1].append(item)

L = len(Const) + len(Merged[0]) + len(Merged[1])
print(N+x-1, L)
if Const:
    print(" ".join(map(str, Const[0])))
for item in Merged[0]:
    print(" ".join(map(str, item)))
for item in Merged[1]:
    print(" ".join(map(str, item)))

Choices:
- Compile Error
- Memory Limit Exceeded
- Internal error
- Runtime Error


Question:
from math import ceil
N = int(input())
A = [int(a) for a in input().split()]

DP = [[False for i in range(max(A) * N + 1)] for n in range(N)]
DP[0][0], DP[0][A[0]] = True, True
maxN = A[0]
for i in range(1, N):
    a = A[i]
    for j in range(maxN+1):
        if DP[i-1][j]:
            DP[i][j] = True
            DP[i][j + a] = True
    maxN += a

for i in range(ceil(sum(A)/2), max(A) * N + 1):
    if DP[N-1][i]:
        print(i)
        break

Choices:
- Compile Error
- Time Limit Exceeded
- Memory Limit Exceeded
- Runtime Error


Question:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

Plus, Whole = [0], [0]
for i in range(N):
    Plus.append(Plus[-1] + max(A[i], 0))
    Whole.append(Whole[-1] + A[i])

Full = Plus[N-K] - Plus[0] + Whole[N] - Whole[N-K]
MaxScore = max(Full, Plus[N-K] - Plus[0])
for i in range(1, K):
    temp = Plus[N-K] - Plus[0] + Whole[N]-Whole[N-K+i] - (Plus[N-K] - Plus[N+1 -2*K])
    MaxScore = max(MaxScore, temp)

Fullb = Plus[N] - Plus[K] + Whole[K] - Whole[0]
MS2 = max(Fullb, Plus[N] - Plus[N-K])
for i in range(1, K):
    temp = Plus[N] - Plus[K] + Whole[K] - Whole[K-i] - (Plus[2*K-i] - Plus[K])
    MS2 = max(MS2, temp)

print(max(MaxScore, MS2))

Choices:
- Memory Limit Exceeded
- Runtime Error
- No abnormally found
- Internal error


Question:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)

n = len(Asorted)
start=0
end = n-P
Ap = A[-P]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if Ai + M < Ap:
    start = i+1
    continue
  limit = (Ai + M)*(n-P-i-1) - sum(Asorted[i+1:n-P]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(n-start)

Choices:
- No abnormally found
- Internal error
- Memory Limit Exceeded
- Runtime Error


Question:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
if P == 1:
  Asorted = sorted(A)
else:
  Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if i == n-1:
    start = n-1
    break
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Choices:
- Internal error
- No abnormally found
- Runtime Error
- Memory Limit Exceeded


Question:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if i == n-1:
    start = n-1
    break
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Choices:
- Memory Limit Exceeded
- Runtime Error
- Internal error
- Compile Error


Question:
N, K = map(int, input().split())
MOD = 10**9 + 7

dp = [0] * (K + 1)
ans = 0
for k in range(K, 0, -1):
    num = K // k
    dp[k] = pow(num, N)
    for n in range(2, num+1):
        if n*k <= K:
            dp[k] -= dp[n*k]
            dp[k] %= MOD

    ans += dp[k] * k % MOD
    ans %= MOD

print(ans)

Choices:
- Memory Limit Exceeded
- Compile Error
- Time Limit Exceeded
- No abnormally found


Question:
import bisect

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

Ap = A[-P] # 初期状態でP番目に大きい点数
idx = bisect.bisect_left(A, Ap) # 初期状態で得点がApより小さい問題の数
ans = N - idx # 初期状態で得点がAp以上であれば候補に入る

for i, a in enumerate(A[:idx]):
  j = 1
  b = a + M
  if b < Ap:
    continue
  n0 = bisect.bisect_right(A, a) # M人全員から投票されてもbを超えない問題の数
  n1 = N - bisect.bisect_left(A, b+1) # 投票されない状態で既にbより点数が高い問題の数
  mv = (V - n0) * M # 上の問題達には取り敢えず投票しておいて、他に選べる問題の数
  if mv <= 0:
    j = 0
    break
  else:
    res = False
    p = P - 1
    for _a in A[n0:][::-1]:
      if p:
        p -= 1
        diff = M
      else:
        diff = b - _a
      if diff <= 0:
        break
      else:
        mv -= diff
        if mv <= 0:
          res = True
          j = 0
          break
    if res:
      break

ans += idx - i - j # 一度候補に入る数を発見したら、それ以降も当然候補に入る
print(ans)

Choices:
- Internal error
- Runtime Error
- Time Limit Exceeded
- Compile Error


Question:
H, W = map(int, input().split())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0], [-1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')

Choices:
- Runtime Error
- Internal error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
S = input()
n = int('N' in S)
s = int('S' in S)
w = int('W' in W)
e = int('E' in E)

if n + s == 1 or w + e == 1:
  print('No')
else:
  print('Yes')

Choices:
- Time Limit Exceeded
- Internal error
- Runtime Error
- Memory Limit Exceeded


Question:
n=int(input())
a=map(int,input().split())
print(max(a)-min(a))

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
X = int(input())
rad = 90
cnt = 0

while True:
    cnt += 1
    if rad==360:
        break
    else:
        rad += X
        rad = rad if rad < 360 else rad = 360

print(cnt)

Choices:
- Runtime Error
- Internal error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
ans = 0
for i in range(n):
  l = list(map(int,input().split()))
  for j in range(m):
    ans += b[j]*a[j]
  if ans +c > 0:
    count += 1

  ans = 0
print(count)

Choices:
- Memory Limit Exceeded
- Runtime Error
- No abnormally found
- Internal error


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

l = [list(map(int,input().split())) for i in range(m)]

count = 0
while True:
    check = [0]* n

    for i in l:
        a,b = i

        for j in range(a,b):
            check[j] += 1

    index = check.index(max(check))
    count += 1
    dellist = []
    for i in range(len(l)):
        a,b = l[i][0],l[i][1]
        if index in range(a,b):
            dellist.append(i)
    num = 0
    for i in dellist:
        del l[i-num]
        num += 1

    if l == []:
        break

print(count)

Choices:
- Memory Limit Exceeded
- No abnormally found
- Time Limit Exceeded
- Compile Error


Question:
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
count = [0]*(m+1)
for i in a:
    count[i[0]] += 1
l = [0]*n
ans = max(count)
s = set()
for i in range(n-1):
    M = max(count)
    ind = count.index(M)
    s.add(ind)

    for j in range(n):
        if a[j][l[j]] == ind:

            count[ind] -= 1
            while a[j][l[j]] in s:
                l[j] += 1
            count[a[j][l[j]]] += 1
    ans = min(ans,max(count))

print(ans)

Choices:
- Runtime Error
- Time Limit Exceeded
- Memory Limit Exceeded
- No abnormally found


Question:
x,y = map(int,input().split())
ans = 0

if(y > 0):
    if(x > y):
        ans += 1
        ans += -y +x
    elif(x >= 0):
        ans += y -x
    elif(x > -y):
        ans += 1
        ans += y + x
    else:
        ans += 1
        ans += -y -x
else:
    if(x > -y):
        ans += 1
        ans += y + x
    elif(x >= 0):
        ans += 1
        ans += -y -x
    elif(x > y):
        ans += 1
        ans += -y +x
        ans += 1
    else:
        ans += y -x

if(x == 0 and y == 0) ans = 0
print(ans)

Choices:
- Internal error
- Memory Limit Exceeded
- Runtime Error
- No abnormally found


Question:
t,x=map(int,input().split)
print(t/x)

Choices:
- Compile Error
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(a):
  b += i//2

x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1

print(x)

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
mod = 10**9+7

if N == 2:
    print(1)
    exit()
elif N == 3:
    print(4)
    exit()

kaijou = [1]
for i in range(1,N+1):
    kaijou.append((kaijou[-1]*i) % mod)

kaijou_inverse = [1]
for i in range(1,N+1):
    kaijou_inverse[i] = pow(kaijou[i],mod-2,mod)

def nCr(n,r):
    if n < r:
        return 0
    return (kaijou_inverse[n]*kaijou_inverse[r]*kaijou_inverse[n-r]) % mod

ans = 0
for i in range(1,N):
    ans += i*kaijou[i]*kaijou[N-i-i]*nCr(i-1,N-1-i)
    ans %= mod

print(ans)

Choices:
- Runtime Error
- Compile Error
- Time Limit Exceeded
- Memory Limit Exceeded


Question:
a,b,c,d = map(int,input().split())
answer = 0
ac =a*c
ad = a*d
bc = b*C
bd = b*d
answer = max(ac,ad)
answer = max(answer,bc)
answer = max(answer,bd)
print(answer)

Choices:
- Runtime Error
- Compile Error
- No abnormally found
- Internal error


Question:
import heapq

N, M =map(int, input().split())
p = []

for _ in range(M):
    A, B= map(int, input().split())
    n = B - A
    m = {i for i in range(A, B)}
    heapq.heappush(p, (n, m))

n = 0
sets = []
for _ in range(M):
    n, q = heapq.heappop(p)
    for m, s in sets:
        if len(s - q) == 0:
            break
    else:
        heapq.heappush(sets, (max(q), q))

count = 0
minnum = -1
for _ in range(len(sets)):
    n, q = heapq.heappop(sets)
    if minnum in q:
        continue
    minnum = n
    count += 1

print(count)

Choices:
- Internal error
- Time Limit Exceeded
- Compile Error
- Memory Limit Exceeded


Question:
s=input()
num=0
for i in s:
  if i=="-":
    num-=1
  else
    num+=1
print(num)

Choices:
- Compile Error
- Internal error
- Runtime Error
- No abnormally found


Question:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from bisect import bisect_left, bisect_right
def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(n)]
    AB.sort()
    AB.append([INF, 0])
    for i in range(n, 0, -1):
        AB[i][1] ^= AB[i - 1][1]

    E = [[] for _ in range(n + 1)]
    for i in range(m):
        u, v = map(int, input().split())
        l = bisect_left(AB, [u, 0])
        r = bisect_right(AB, [v, 1])
        E[l].append((r, i + 1))
        E[r].append((l, i + 1))

    ans = []
    used = [False] * (n + 1)
    def dfs(v):
        used[v] = True
        res = AB[v][1]
        for nv, i in E[v]:
            if used[nv]:
                continue
            if dfs(nv):
                ans.append(i)
                res ^= 1
        return res

    for v in range(n + 1):
        if used[v]:
            continue
        if dfs(v):
            print(-1)
            return

    print(len(ans))
    if ans:
        print(*sorted(ans))
resolve()

Choices:
- Compile Error
- Time Limit Exceeded
- Memory Limit Exceeded
- Internal error


Question:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.buffer.readline().rstrip()
from bisect import bisect_left, bisect_right
def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(n)]
    AB.sort()
    AB.append([INF, 0])
    for i in range(n, 0, -1):
        AB[i][1] ^= AB[i - 1][1]

    E = [[] for _ in range(n + 1)]
    for i in range(m):
        u, v = map(int, input().split())
        l = bisect_left(AB, [u, 0])
        r = bisect_right(AB, [v, 1])
        E[l].append((r, i + 1))
        E[r].append((l, i + 1))

    ans = []
    used = [False] * (n + 1)
    def dfs(v):
        used[v] = True
        res = AB[v][1]
        for nv, i in E[v]:
            if used[nv]:
                continue
            r = dfs(nv)
            if r:
                ans.append(i)
            res ^= r
        return res

    for v in range(n + 1):
        if used[v]:
            continue
        if dfs(v):
            print(-1)
            return

    print(len(ans))
    if ans:
        print(*sorted(ans))
resolve()

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- No abnormally found
- Compile Error


Question:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    V=100
    W=[1 for i in range(V+1)]
    # Eratosthenes sieve (O(VloglogV))
    S=[1]*(V+1)
    S[0]=0; S[1]=0
    for p in range(2,V):
        if S[p]==0: continue
        W[p]*=1-p
        for k in range(2*p,V+1,p):
            W[k]*=1-p
            S[k]=0
    W=[W[i]/i if i else 0 for i in range(V+1)]
    n,k=map(int,input().split())
    ans=0
    for d in range(1,k+1):
        if k%d==0:
            ans+=d*W[d]*(n//d)*(n//d+1)//2%MOD
    print(round(ans)*k%MOD)
resolve()

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error
- Internal error


Question:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class mint(object):
    MOD=998244353

    def __init__(self,x):
        self.__x=x%self.MOD

    def __repr__(self):
        return str(self.__x)

    def __add__(self,other):
        return mint(self.__x+other.__x) if isinstance(other,mint) else mint(self.__x+other)

    def __sub__(self,other):
        return mint(self.__x-other.__x) if isinstance(other,mint) else mint(self.__x-other)

    def __mul__(self,other):
        return mint(self.__x*other.__x) if isinstance(other,mint) else mint(self.__x*other)

    def __truediv__(self,other):
        return mint(self.__x*pow(other.__x,self.MOD-2,self.MOD)) if isinstance(other, mint) else mint(self.__x*pow(other, self.MOD-2,self.MOD))

    def __pow__(self,other):
        return mint(pow(self.__x,other.__x,self.MOD)) if isinstance(other,mint) else mint(pow(self.__x,other,self.MOD))

    __radd__=__add__

    def __rsub__(self,other):
        return mint(other.__x-self.__x) if isinstance(other,mint) else mint(other-self.__x)

    __rmul__=__mul__

    def __rtruediv__(self,other):
        return mint(other.__x*pow(self.__x,self.MOD-2,self.MOD)) if isinstance(other,mint) else mint(other*pow(self.__x,self.MOD-2,self.MOD))

    def __rpow__(self,other):
        return mint(pow(other.__x,self.__x,self.MOD)) if isinstance(other,mint) else mint(pow(other,self.__x,self.MOD))

def resolve():
    # preparation
    p=int(input())
    mint.MOD=p
    invfact=[0]*p
    invfact[p-1]=mint(-1) # Wilson's theorem
    for i in range(2,p):
        invfact[p-i]=invfact[p-i+1]*(p-i+1)

    # initialize
    A=[0]*p
    for i,a in enumerate(map(int,input().split())):
        A[i]=mint(a)

    ans=[mint(0)]*p
    ans[0]=A[0]
    r=[mint(0)]*(p+1) # for use of r[-1]=0
    r[0]=mint(1)

    # iterate
    for k in range(1,p):
        newr=[0]*(p+1) # newr(x)=(x-(k-1))r(x)
        v=0 # v=f[k-1](k)
        power=1
        for i in range(p):
            v+=ans[i]*power
            power*=k
            newr[i]=r[i-1]-(k-1)*r[i]
        r=newr
        for i in range(p):
            ans[i]+=(A[k]-v)*invfact[k]*r[i]

    print(*ans)
resolve()

Choices:
- Compile Error
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
N = int(input().strip())

a = []
c = []
f = 0

for i in range(N):
    array = list(map(int, input().strip().split()))
    a.append(array)

for i in range(N):
	if(f == 0 or f == i-1):
		if(a[i][0] == a[i][1]):
			f=i
			c.append(1)
		else:
			f=0

if(len(c) >= 3):
  print("Yes")
else:
  print("No")

Choices:
- No abnormally found
- Compile Error
- Runtime Error
- Time Limit Exceeded


Question:
N = int(input().strip())

a = []
c =0
f = 0

for i in range(N):
    array = list(map(int, input().strip().split()))
    a.append(array)

for i in range(N):
	if(f == 0 or f == i-1):
		if(a[i][0] == a[i][1]):
			f=i
			c+=1
		else:
			f=0
			c=0
	else :
		f=0
		c=0

if(c >= 3):
  print("Yes")
else:
  print("No")

Choices:
- Time Limit Exceeded
- Runtime Error
- Memory Limit Exceeded
- Compile Error


Question:
import sys
N = int(input().strip())

if(N == 0):
  sys.exit()

a = []
c =0
f = 0
for i in range(N):
    array = list(map(int, input().strip().split()))
    a.append(array)
#print(a[4][1])
for i in range(N):
	if(f == 0 or f == i-1):
		if(a[i][0] == a[i][1]):
			f=i
			c+=1
		else:
			f=0
			c=0
if(c >= 3):
  print("Yes")
else:
  print("No")

Choices:
- Time Limit Exceeded
- Runtime Error
- Memory Limit Exceeded
- Compile Error


Question:
N = int(input())
now = 0
ans = 0
for i in range(1,N+1):
    if i%2 == 0:
        continue
    else:
        for j in range(1,i+1):
            if i%j == 0:
                now += 1
        if now == 8:
            ans += 1
        now = 0
print(ans)

Choices:
- No abnormally found
- Time Limit Exceeded
- Runtime Error
- Memory Limit Exceeded


Question:
n,k = map(int,input().split())
l = [_ for _ in range(1,n+1)]
#print(n,k,l)

x = []
for i in range(n):
    for j in range(n):
        if (l[i] + l[j]) % k == 0:
            x.append([l[i], l[j]])
#print(x)

y = 0
for p in range(len(x)):
    for q in range(n):
        if (x[p][0] + l[q]) % k == 0 and (x[p][1] + l[q]) % k == 0:
            y += 1
print(y)

Choices:
- Memory Limit Exceeded
- Compile Error
- Time Limit Exceeded
- Runtime Error


Question:
a, b, c, k = map(int,input().split())

if a==b==c:
    print(0)
    exit()

for i in range(k):
    a_=b+c
    b_=a+c
    c_=a+b
    if abs(a_-b_) > 10**18:
        print('Unfair')
        exit()
    a=a_
    b=b_
    c=c_

if k==0:
    print(a-b)
else:
    print(a_-b_)

Choices:
- Compile Error
- No abnormally found
- Time Limit Exceeded
- Runtime Error


Question:
from math import sin,cos
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1, N)])for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1,N)])for i in range(N)])/S)

Choices:
- Memory Limit Exceeded
- No abnormally found
- Compile Error
- Runtime Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10**9 + 7
N, K = map(int, read().split())

is_prime = np.zeros(K + 1, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 1, 2):
    if p * p >= K:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for p in primes.tolist():
    for i in range(K // p + 1):
        A[i] -= A[i * p]

answer = sum(i * x for i, x in enumerate(A))
print(answer % MOD)

Choices:
- Runtime Error
- No abnormally found
- Memory Limit Exceeded
- Compile Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
LR = list(zip(m,m))

if N==2:
    L1,R1 = LR[0]
    L2,R2 = LR[1]
    answer = (R1-L1+1) + (R2-L2+1)
    print(answer)
    exit()

# 片方に集める場合
max_width = max(R-L+1 for L,R in LR)

LR.sort()

INF=10**18
# Rが最小のもの
i = -1
opt_R = INF
for n,(L,R) in enumerate(LR):
    if opt_R>=R:
        opt_R=R
        i=n
j = -1
opt_L = -INF
for n,(L,R) in enumerate(LR):
    if opt_L<=L:
        opt_L=L
        j=n

if i==j:
    L,R = LR[i]
    answer = max_width + (R-L+1)
    print(answer)
    raise Exception
    exit()

L1,R1 = LR[i]; L2,R2 = LR[j]

LR = [(L,R) for n,(L,R) in enumerate(LR) if n != i and n != j]

LR.sort()

n = len(LR)
dpl = [(-INF,INF)]*(n+1)
dpr = [(-INF,INF)]*(n+1)

for i in range(n):
    a,b = dpl[i]
    L,R = LR[i]
    dpl[i+1] = (max(a,L),min(b,R))
for i in range(n,0,-1):
    a,b = dpr[i]
    L,R = LR[i-1]
    dpr[i-1] = (max(a,L),min(b,R))

answer = 0
for (a,b),(c,d) in zip(dpl,dpr):
    l1 = max(L1,a); r1 = min(R1,b)
    l2 = max(L2,c); r2 = min(R2,d)
    x = max(0,r1-l1+1) + max(0,r2-l2+1)
    if answer < x:
        answer = x

if answer < max_width:
    answer = max_width

print(answer)

Choices:
- Memory Limit Exceeded
- Internal error
- Time Limit Exceeded
- Runtime Error


Question:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 998244353

N = int(readline())
A = np.array(readline().split(),np.int32)

U = 10**6+100
counter = np.bincount(A,minlength=U)

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

x = np.arange(U,dtype=np.int64); x[0] = 1
fact = cumprod(x)
x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x)[::-1]

inv = np.zeros(U,dtype=np.int64)
inv[1:] = fact[:-1] * fact_inv[1:] % MOD

"""
・f(n) = sum_{gcd(a,b) == 1}ab
・g(n) = sum_{n|gcd(a,b)}ab
"""

"""
・S(n) = sum_{n|a} a
・T(n) = sum_{n|a} a^2
"""

x = np.arange(U,dtype=np.int64)*counter%MOD
y = np.arange(U,dtype=np.int64)**2%MOD*counter%MOD
S = np.zeros(U,dtype=np.int64)
T = np.zeros(U,dtype=np.int64)
M = int(U**.5+1)+10
for d in range(1,M):
    S[d] = (x[d::d]).sum()
    T[d] = (y[d::d]).sum()
for d in range(1,M):
    S[M:(U-1)//d+1] += x[M*d:U:d]
    T[M:(U-1)//d+1] += y[M*d:U:d]
S%=MOD
T%=MOD

G = (S*S-T)%MOD*inv[2]%MOD

for n in range(U-1,0,-1):
    G[n] -= G[2*n:U:n].sum()
    G[n] %= MOD

answer = (G*inv%MOD).sum()%MOD
print(answer)

Choices:
- Internal error
- Runtime Error
- Time Limit Exceeded
- Memory Limit Exceeded


Question:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
正則二部グラフの辺彩色
"""

import numpy as np

N,M = map(int,input().split())
grid = [[int(x) for x in input().split()] for _ in range(N)]

edge = []
for i,row in enumerate(grid):
    for j,x in enumerate(row):
        edge.append(((x-1)//M,N+i))

graph = [dict() for _ in range(N+N)] # 頂点ごろに、色->相手
rest_color = [set(range(M)) for _ in range(N+N)]

for u,v in edge:
    c = rest_color[u].pop()
    if c in rest_color[v]:
        graph[u][c] = v
        graph[v][c] = u
        rest_color[v].remove(c)
        continue
    # 交互道を作って色c,dと当てていく
    d = rest_color[v].pop()
    cd = c + d
    V = [u,v]
    next_c = c
    while next_c not in rest_color[v]:
        v = graph[v][next_c]
        V.append(v)
        next_c = cd - next_c
    rest_color[v].remove(next_c)
    rest_color[v].add(cd - next_c)
    for i,(u,v) in enumerate(zip(V,V[1:])):
        if i%2 == 0:
            graph[u][c] = v
            graph[v][c] = u
        else:
            graph[u][d] = v
            graph[v][d] = u

after = [[None] * M for _ in range(N)]

for i,row in enumerate(grid):
    mod_to_x = [[] for _ in range(N)]
    for x in row:
        mod_to_x[(x-1)//M].append(x)
    for color in range(M):
        after[i][color] = mod_to_x[graph[i][color] - N].pop()

Choices:
- Runtime Error
- Internal error
- No abnormally found
- Memory Limit Exceeded


Question:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
正則二部グラフの辺彩色
"""

import numpy as np

N,M = map(int,input().split())
grid = [[int(x) for x in input().split()] for _ in range(N)]

edge = []
for i,row in enumerate(grid):
    for j,x in enumerate(row):
        edge.append(((x-1)//M,N+i))

graph = [dict() for _ in range(N+N)] # 頂点ごろに、色->相手
rest_color = [set(range(M)) for _ in range(N+N)]

for u,v in edge:
    c = rest_color[u].pop()
    if c in rest_color[v]:
        graph[u][c] = v
        graph[v][c] = u
        rest_color[v].remove(c)
        continue
    # 交互道を作って色c,dと当てていく
    d = rest_color[v].pop()
    cd = c + d
    V = [u,v]
    next_c = c
    while next_c not in rest_color[v]:
        v = graph[v][next_c]
        V.append(v)
        next_c = cd - next_c
    rest_color[v].remove(next_c)
    rest_color[v].add(cd - next_c)
    for i,(u,v) in enumerate(zip(V,V[1:])):
        if i%2 == 0:
            graph[u][c] = v
            graph[v][c] = u
        else:
            graph[u][d] = v
            graph[v][d] = u

after = [[None] * M for _ in range(N)]

for i,row in enumerate(grid):
    mod_to_x = [[] for _ in range(N)]
    for x in row:
        mod_to_x[(x-1)//M].append(x)
    for color in range(M):
        after[i][color] = mod_to_x[graph[i][color] - N].pop()

B = np.array(after)
C = B.copy()
C.sort(axis = 0)
print('\n'.join(' '.join(row) for row in B.astype(str)))
print('\n'.join(' '.join(row) for row in C.astype(str)))

Choices:
- Memory Limit Exceeded
- No abnormally found
- Compile Error
- Runtime Error


Question:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
import itertools

P = int(input())
A = [int(x) for x in input().split()]

P,A

one = np.array([1], dtype=np.int64)
arr = [np.array([(-x)%P,1],dtype=np.int64) for x in range(P)]
L = [one] + list(itertools.accumulate(arr[:-1],lambda a,b: np.convolve(a,b) % P))
R = ([one] + list(itertools.accumulate(arr[1:][::-1],lambda a,b: np.convolve(a,b) % P)))[::-1]
X = [np.convolve(A,B) % P for A,B in zip(L,R)]

f = np.zeros(P,dtype=np.int64)
for a,x in zip(A,X):
    if a == 1:
        f -= x

f %= P
print(*f)

Choices:
- Time Limit Exceeded
- Compile Error
- Internal error
- Memory Limit Exceeded


Question:
import numpy as np
A=np.ones(1<<27,dtype=np.int64)

Choices:
- Internal error
- Memory Limit Exceeded
- Compile Error
- Time Limit Exceeded


Question:
import random
r = random.randint(1,3)

if r == 1:
  # TLE
  import time
  time.sleep(5)
elif r == 2:
  # MLE
  x = '01234567'
  x *= (1 << 27)
else:
  # RE
  RE

Choices:
- No abnormally found
- Runtime Error
- Memory Limit Exceeded
- Compile Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush

N = int(readline())
m = map(int,read().split())
data = list(zip(m,m,m))
R = data[:N]
B = data[N:]

class MinCostFlow:
    """
    最小費用流。負辺がないと仮定して、BellmanFordを省略している。
    """
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap, cost):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, cost, n2])
        self.G[to].append([fr, 0, -cost, n1])

    def MinCost(self, flow, negative_edge = False):
        if negative_edge:
            raise ValueError
        N = self.N; G = self.G; source = self.source; sink = self.sink
        INF = 10 ** 18
        prev_v = [0] * N; prev_e = [0] * N # 経路復元用
        H = [0] * N # potential
        mincost=0
        while flow:
            dist=[INF] * N
            dist[source]=0
            q = [source]
            mask = (1 << 20) - 1
            while q:
                x = heappop(q)
                dv = (x >> 20); v = x & mask
                if dist[v] < dv:
                    continue
                if v == sink:
                    break
                for i,(w,cap,cost,rev) in enumerate(G[v]):
                    dw = dist[v] + cost + H[v] - H[w]
                    if (not cap) or (dist[w] <= dw):
                        continue
                    dist[w] = dw
                    prev_v[w] = v; prev_e[w] = i
                    heappush(q, (dw << 20) + w)
            if dist[sink] == INF:
                raise Exception('No Flow Exists')
            # ポテンシャルの更新
            for v,d in enumerate(dist):
                H[v] += d
            # 流せる量を取得する
            d = flow; v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                cap = G[pv][pe][1]
                if d > cap:
                    d = cap
                v = pv
            # 流す
            mincost += d * H[sink]
            flow -= d
            v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                G[pv][pe][1] -= d
                rev = G[pv][pe][3]
                G[v][rev][1] += d
                v = pv
        return mincost

source = N+N; sink = N+N+1
V1 = N+N+2; V2 = N+N+3; V3 = N+N+4; V4 = N+N+5

G = MinCostFlow(N+N+6, source = source, sink = sink)
base = 10 ** 9 * 2 # 各辺に上乗せしておく -> 最後に引く
INF = 10 ** 18

flow = 0

for i,(x,y,c) in enumerate(R):
    flow += c
    G.add_edge(fr=source, to=i, cap=c, cost=0)
    G.add_edge(i,V1,INF,base-x-y)
    G.add_edge(i,V2,INF,base-x+y)
    G.add_edge(i,V3,INF,base+x-y)
    G.add_edge(i,V4,INF,base+x+y)

for i,(x,y,c) in enumerate(B,N):
    G.add_edge(fr=i, to=sink, cap=c, cost=0)
    G.add_edge(V1,i,INF,base+x+y)
    G.add_edge(V2,i,INF,base+x-y)
    G.add_edge(V3,i,INF,base-x+y)
    G.add_edge(V4,i,INF,base-x-y)

cost = G.MinCost(flow)

answer = base * (2 * flow) - cost
print(answer)

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- Compile Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush

N = int(readline())
m = map(int,read().split())
data = list(zip(m,m,m))
R = data[:N]
B = data[N:]

class MinCostFlow:
    """
    最小費用流。負辺がないと仮定して、BellmanFordを省略している。
    """
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap, cost):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, cost, n2])
        self.G[to].append([fr, 0, -cost, n1])

    def MinCost(self, flow, negative_edge = False):
        if negative_edge:
            raise ValueError
        N = self.N; G = self.G; source = self.source; sink = self.sink
        INF = 10 ** 18
        prev_v = [0] * N; prev_e = [0] * N # 経路復元用
        H = [0] * N # potential
        mincost=0
        while flow:
            dist=[INF] * N
            dist[source]=0
            q = [(0,source)]
            while q:
                dv,v = heappop(q)
                if dist[v] < dv:
                    continue
                if v == sink:
                    break
                for i,(w,cap,cost,rev) in enumerate(G[v]):
                    dw = dist[v] + cost + H[v] - H[w]
                    if (not cap) or (dist[w] <= dw):
                        continue
                    dist[w] = dw
                    prev_v[w] = v; prev_e[w] = i
                    heappush(q, (dw,w))
            if dist[sink] == INF:
                raise Exception('No Flow Exists')
            # ポテンシャルの更新
            for v,d in enumerate(dist):
                H[v] += d
            # 流せる量を取得する
            d = flow; v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                cap = G[pv][pe][1]
                if d > cap:
                    d = cap
                v = pv
            # 流す
            mincost += d * H[sink]
            flow -= d
            v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                G[pv][pe][1] -= d
                rev = G[pv][pe][3]
                G[v][rev][1] += d
                v = pv
        return mincost

source = N+N; sink = N+N+1
V1 = N+N+2; V2 = N+N+3; V3 = N+N+4; V4 = N+N+5

G = MinCostFlow(N+N+6, source = source, sink = sink)
base = 10 ** 9 * 2 # 各辺に上乗せしておく -> 最後に引く
INF = 10 ** 18

flow = 0

for i,(x,y,c) in enumerate(R):
    flow += c
    G.add_edge(fr=source, to=i, cap=c, cost=0)
    G.add_edge(i,V1,INF,base-x-y)
    G.add_edge(i,V2,INF,base-x+y)
    G.add_edge(i,V3,INF,base+x-y)
    G.add_edge(i,V4,INF,base+x+y)

for i,(x,y,c) in enumerate(B,N):
    G.add_edge(fr=i, to=sink, cap=c, cost=0)
    G.add_edge(V1,i,INF,base+x+y)
    G.add_edge(V2,i,INF,base+x-y)
    G.add_edge(V3,i,INF,base-x+y)
    G.add_edge(V4,i,INF,base-x-y)

cost = G.MinCost(flow)

answer = base * (2 * flow) - cost
print(answer)

Choices:
- Time Limit Exceeded
- Memory Limit Exceeded
- Runtime Error
- Compile Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush

N = int(readline())
m = map(int,read().split())
data = list(zip(m,m,m))
R = data[:N]
B = data[N:]

class MinCostFlow:
    """
    最小費用流。負辺がないと仮定して、BellmanFordを省略している。
    """
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap, cost):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, cost, n2])
        self.G[to].append([fr, 0, -cost, n1])

    def MinCost(self, flow, negative_edge = False):
        if negative_edge:
            raise ValueError
        N = self.N; G = self.G; source = self.source; sink = self.sink
        INF = 10 ** 18
        prev_v = [0] * N; prev_e = [0] * N # 経路復元用
        H = [0] * N # potential
        mincost=0
        while flow:
            dist=[INF] * N
            dist[source]=0
            q = [(0,source)]
            while q:
                dv,v = heappop(q)
                if dist[v] < dv:
                    continue
                for i,(w,cap,cost,rev) in enumerate(G[v]):
                    dw = dist[v] + cost + H[v] - H[w]
                    if (not cap) or (dist[w] <= dw):
                        continue
                    dist[w] = dw
                    prev_v[w] = v; prev_e[w] = i
                    heappush(q, (dw,w))
            if dist[sink] == INF:
                raise Exception('No Flow Exists')
            # ポテンシャルの更新
            for v,d in enumerate(dist):
                H[v] += d
            # 流せる量を取得する
            d = flow; v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                cap = G[pv][pe][1]
                if d > cap:
                    d = cap
                v = pv
            # 流す
            mincost += d * H[sink]
            flow -= d
            v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                G[pv][pe][1] -= d
                rev = G[pv][pe][3]
                G[v][rev][1] += d
                v = pv
        return mincost

source = N+N; sink = N+N+1
V1 = N+N+2; V2 = N+N+3; V3 = N+N+4; V4 = N+N+5

G = MinCostFlow(N+N+6, source = source, sink = sink)
base = 10 ** 9 * 2 # 各辺に上乗せしておく -> 最後に引く
INF = 10 ** 18

flow = 0

for i,(x,y,c) in enumerate(R):
    flow += c
    G.add_edge(fr=source, to=i, cap=c, cost=0)
    G.add_edge(i,V1,INF,base-x-y)
    G.add_edge(i,V2,INF,base-x+y)
    G.add_edge(i,V3,INF,base+x-y)
    G.add_edge(i,V4,INF,base+x+y)

for i,(x,y,c) in enumerate(B,N):
    G.add_edge(fr=i, to=sink, cap=c, cost=0)
    G.add_edge(V1,i,INF,base+x+y)
    G.add_edge(V2,i,INF,base+x-y)
    G.add_edge(V3,i,INF,base-x+y)
    G.add_edge(V4,i,INF,base-x-y)

cost = G.MinCost(flow)

answer = base * (2 * flow) - cost
print(answer)

Choices:
- No abnormally found
- Compile Error
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.frombuffer(b'-'+readline().rstrip(),'S1')
Q = int(readline())
query = map(int,read().split())

isD = S == b'D'
isM = S == b'M'
isC = S == b'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

def F(K):
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    return (x.cumsum() * isC).sum()

print('\n'.join(str(F(K)) for K in query))

Choices:
- Compile Error
- Memory Limit Exceeded
- Runtime Error
- No abnormally found


Question:
import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
INF = 10**18
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

opposite = 0
max_dist = 0

def f(d,x):
  global max_dist,opposite
  dx = d[x]
  if dx > max_dist:
    opposite = x
    max_dist = dx
  for y in edge[x]:
    if d[y] == INF:
      d[y] = dx + 1
      f(d,y)

if N != 1:
  # 0からの距離
  d = [INF] * N
  d[0] = 0
  f(d,0)

  v = opposite
  d = [INF] * N
  d[v] = 0
  f(d,v)

  X = max_dist

  ans = 'First' if max_dist%3 != 1 else 'Second'
  print(ans)
else:
  print('First')

Choices:
- Memory Limit Exceeded
- Compile Error
- Internal error
- Time Limit Exceeded


Question:
import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
INF = 10**18
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

opposite = 0
max_dist = 0
def f(d,x):
  global max_dist,opposite
  dx = d[x]
  if dx > max_dist:
    opposite = x
    max_dist = dx
  for y in edge[x]:
    if d[y] == INF:
      d[y] = dx + 1
      f(d,y)

# 0からの距離
d = [INF] * N
d[0] = 0
f(d,0)

v = opposite
d = [INF] * N
d[v] = 0
f(d,v)

X = max_dist

ans = 'First' if max_dist%3 != 1 else 'Second'
print(ans)

Choices:
- Time Limit Exceeded
- Internal error
- Runtime Error
- No abnormally found


Question:
H,W = map(int, input().split())
h,w = map(int, input().split())
answer = (H-h)*(W-w)
print(ans)

Choices:
- Runtime Error
- Compile Error
- Internal error
- No abnormally found


Question:
a,b = map(int,input())
print(a/b)

Choices:
- Time Limit Exceeded
- Runtime Error
- Compile Error
- Internal error


Question:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

B = [A[0]]
B_cnt = [1]
for i,(x,y) in enumerate(zip(A[:-1],A[1:])):
    if x < y and y < A[i+2]:
        continue
    if x == y:
        B_cnt[-1] += 1
    else:
        B.append(y)
        B_cnt.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a,a_cnt in zip(B,B_cnt):
        if digit[-1] < a:
            digit.append(a)
            cnt.append(a_cnt)
            continue
        if digit[-1] == a:
            cnt[-1] += a_cnt
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            if digit[-1] <= a:
                break
            n = digit.pop()
            k = cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += a_cnt
        else:
            digit.append(a)
            cnt.append(1+a_cnt)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = 2 # 可能?
while not test(right):
    left *= 2
    right *= 2
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Choices:
- No abnormally found
- Internal error
- Time Limit Exceeded
- Compile Error


Question:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

B = [A[0]]
B_cnt = [1]
for i,(x,y) in enumerate(zip(A[:-1],A[1:])):
    if x < y and y < A[i+2]:
        continue
    if x == y:
        B_cnt[-1] += 1
    else:
        B.append(y)
        B_cnt.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a,a_cnt in zip(B,B_cnt):
        if digit[-1] < a:
            digit.append(a)
            cnt.append(a_cnt)
            continue
        if digit[-1] == a:
            cnt[-1] += a_cnt
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            if digit[-1] <= a:
                break
            n = digit.pop()
            k = cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += a_cnt
        else:
            digit.append(a)
            cnt.append(1+a_cnt)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = N # 可能
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Choices:
- Compile Error
- Time Limit Exceeded
- No abnormally found
- Runtime Error


Question:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a in A:
        if digit[-1] < a:
            digit.append(a)
            cnt.append(1)
            continue
        if digit[-1] == a:
            cnt[-1] += 1
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            n = digit[-1]
            k = cnt[-1]
            if n <= a:
                break
            digit.pop()
            cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += 1
        else:
            digit.append(a)
            cnt.append(2)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = N # 可能
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Choices:
- Internal error
- Time Limit Exceeded
- Runtime Error
- No abnormally found


Question:
N = input()
A = [int(x) for x in input().split()]

answer = 0
for i in range(1,N):
  if A[i] == A[i-1]:
    A[i] = -1
    answer += 1
print(answer)

Choices:
- Runtime Error
- No abnormally found
- Internal error
- Time Limit Exceeded


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
import numpy as np
from functools import lru_cache
from operator import itemgetter

X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))

for i in [1,3,5]:
    X[i] += 1
    Y[i] += 1

X1 = X[:2]; X2 = X[2:4]; X3 = X[4:]
Y1 = Y[:2]; Y2 = Y[2:4]; Y3 = Y[4:]

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 2 * 10 ** 6 + 10
MOD = 10**9 + 7
fact, fact_inv = make_fact(U,MOD)

@lru_cache(16)
def make_comb(n):
    return fact[n] * fact_inv[:n+1] % MOD * fact_inv[:n+1][::-1] % MOD

answer = 0
tasks = []
for p in itertools.product([0,1],repeat=6):
    x1,x2,x3,y1,y2,y3 = [A[i] for A,i in zip([X1,X2,X3,Y1,Y2,Y3],p)]
    sgn = (-1) ** sum(p)
    a,b,c,d = x2-x1, x3-x2, x2-x1+y2-y1, x3-x2+y3-y2
    c += 2; d += 2; sgn = -sgn
    tasks.append((a,b,c,d,sgn))

tasks.sort(key = itemgetter(2))

for a,b,c,d,sgn in tasks:
    # (1+A)^c(1+B)^d / (A-B)^2 における A^aB^b の係数
    # まずはa+b+2次式部分を抽出する：A側の次数で持つ
    D = a + b + 2
    # A^i B^j の寄与。
    L = max(0, D-d)
    R = min(c, D)
    if L > R:
        continue
    x = make_comb(c)[L:R+1]
    L,R = D-R,D-L
    y = make_comb(d)[L:R+1]
    x = x * y[::-1] % MOD
    # B=1と見立てる。(1-A)^2 で割って、A^(a-L)の係数
    np.cumsum(x,out=x)
    x %= MOD
    np.cumsum(x,out=x)
    x %= MOD
    L,R = D-R,D-L
    if 0 <= a-L < len(x):
        answer += sgn * x[a-L]

answer %= MOD
print(answer)

Choices:
- Memory Limit Exceeded
- Runtime Error
- No abnormally found
- Compile Error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
import numpy as np
from functools import lru_cache

X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))

for i in [1,3,5]:
    X[i] += 1
    Y[i] += 1

X1 = X[:2]; X2 = X[2:4]; X3 = X[4:]
Y1 = Y[:2]; Y2 = Y[2:4]; Y3 = Y[4:]

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 2 * 10 ** 6 + 10
MOD = 10**9 + 7
fact, fact_inv = make_fact(U,MOD)

@lru_cache()
def make_comb(n):
    return fact[n] * fact_inv[:n+1] % MOD * fact_inv[:n+1][::-1] % MOD

answer = 0
for p in itertools.product([0,1],repeat=6):
    x1,x2,x3,y1,y2,y3 = [A[i] for A,i in zip([X1,X2,X3,Y1,Y2,Y3],p)]
    sgn = (-1) ** sum(p)
    a,b,c,d = x2-x1, x3-x2, x2-x1+y2-y1, x3-x2+y3-y2
    c += 2; d += 2; sgn = -sgn
    # (1+A)^c(1+B)^d / (A-B)^2 における A^aB^b の係数
    # まずはa+b+2次式部分を抽出する：A側の次数で持つ
    D = a + b + 2
    # A^i B^j の寄与。
    L = max(0, D-d)
    R = min(c, D)
    if L > R:
        continue
    x = make_comb(c)[L:R+1]
    L,R = D-R,D-L
    y = make_comb(d)[L:R+1]
    x = x * y[::-1] % MOD
    # B=1と見立てる。(1-A)^2 で割って、A^(a-L)の係数
    np.cumsum(x,out=x)
    x %= MOD
    np.cumsum(x,out=x)
    x %= MOD
    L,R = D-R,D-L
    if 0 <= a-L < len(x):
        answer += sgn * x[a-L]

answer %= MOD
print(answer)

Choices:
- Time Limit Exceeded
- Memory Limit Exceeded
- Runtime Error
- No abnormally found


Question:
import sys
input = sys.stdin.readline

"""
・とりあえず部分点解法：各クエリに対してO(N)
・いくつかを残していくつかを自由に埋める
・残すもの：被覆区間がoverlapしないように残す
・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。
"""

N,M = map(int,input().split())
A = [int(x) for x in input().split()]
XY = [tuple(int(x) for x in input().split()) for _ in range(M)]

def subscore_solution():
    from collections import Counter
    for x,y in XY:
        A[x-1] = y
        covered = [False] * (N+N+10)
        for key,cnt in Counter(A).items():
            for i in range(cnt):
                covered[max(0,key-i)] = True
        print(sum(not bl for bl in covered[1:N+1]))

if N <= 200 and M <= 200:
    subscore_solution()
    exit()

raise Exception

Choices:
- Compile Error
- Memory Limit Exceeded
- Runtime Error
- Time Limit Exceeded


Question:
import sys
input = sys.stdin.readline

"""
・とりあえず部分点解法：各クエリに対してO(N)
・いくつかを残していくつかを自由に埋める
・残すもの：被覆区間がoverlapしないように残す
・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。
"""

N,M = map(int,input().split())
A = [int(x) for x in input().split()]
XY = [tuple(int(x) for x in input().split()) for _ in range(M)]

def naive_solution(A):
    from collections import Counter
    covered = [False] * (N+N+10)
    for key,cnt in Counter(A).items():
        for i in range(cnt):
            covered[max(0,key-i)] = True
    return sum(not bl for bl in covered[1:N+1])

for x,y in XY:
    A[x-1] = y
    print(naive_solution(A))

Choices:
- Time Limit Exceeded
- No abnormally found
- Internal error
- Compile Error


Question:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

A = int(readline())
B = int(readline())

def can_make(A,B):
    # [A,B] の元のorで、{B} 以外の方法でBを作れるかどうか。たいていTrue
    if A == B:
        return False
    if B%2 == 0:
        return can_make((A+1)//2,B//2)
    # Bが奇数なら、{B-1,B}が満たす
    return True

def F(A,B):
    if A==B:
        return 1
    # 偶数の作り方
    ev = F((A+1)//2,B//2)
    # 奇数の作り方
    if A%2==0:
        A += 1
    if B%2 == 1:
        od = F(A//2,B//2)
    else:
        # 上位の桁では基本的にはA//2～B//2が使える。
        # ただし、{B} 以外でないといけない
        od = F(A//2,B//2)
        if not can_make(A//2,B//2):
            od -= 1
    return ev + od

answer = F(A,B)
print(answer)

Choices:
- Runtime Error
- Internal error
- Time Limit Exceeded
- Compile Error


Question:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def main(N, A, B, S):
    if A > B:
        A, B = B, A
    if np.max(S[2:] - S[:-2]) < A:
        return 0
    INF = 1 << 62
    S = np.append(S, INF)
    # A 未満でたどって、Xがどこまで置けるか
    X = np.zeros_like(S)
    for i in range(1, N + 1):
        if S[i] - S[i - 1] >= A:
            X[i] = X[i - 1]
        else:
            X[i] = i
    # 直前の Y としてありうる最も右
    Y = np.searchsorted(S, S - B, side='right') - 1
    dp = np.zeros_like(S)
    dp_cum = np.zeros_like(S)

    dp[0] = 1
    dp_cum[0] = 1
    for n in range(1, N + 1):
        if X[n - 1] == 0:
            # 初出の Y
            dp[n] = 1
        # 直前の Y の範囲
        l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n])
        if l <= r:
            dp[n] += dp_cum[r] - dp_cum[l] + dp[l]
        dp[n] %= MOD
        dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD
    return dp[-1]

signature = '(i8,i8,i8,i8[:],)'
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

N, A, B = map(int, readline().split())
S = np.array(read().split(), np.int64)

print(main(N, A, B, S))

Choices:
- Runtime Error
- No abnormally found
- Compile Error
- Internal error


Question:
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

INF = 10**18 + 100
N,A,B = map(int,input().split())
S = [-INF] + [int(x) for x in sys.stdin.read().split()]

MOD = 10**9 + 7

dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N+1) + [0]
dpY_cum = [1] * (N+1) + [0]
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
    iA = bisect_right(S,x-A)
    iB = bisect_right(S,x-B)
    # ....XY
    xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1]
    # ....YX
    yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1]
    # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
    if iA != n:
        dpY_left = n-1
    if iB != n:
        dpX_left = n-1
    dpX[n-1] = xy
    dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
    dpX_cum[n] = dpX_cum[n-1]
    dpY[n-1] = yx
    dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
    dpY_cum[n] = dpY_cum[n-1]

answer = dpX_cum[n] - dpX_cum[dpX_left-1]
answer += dpY_cum[n] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer)

dpX

Choices:
- Memory Limit Exceeded
- Runtime Error
- No abnormally found
- Internal error


Question:
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

INF = 10**18 + 100
N,A,B = map(int,input().split())
S = [-INF] + [int(x) for x in sys.stdin.read().split()]

MOD = 10**9 + 7

dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N+1)
dpY_cum = [1] * (N+1)
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
    iA = bisect_right(S,x-A)
    iB = bisect_right(S,x-B)
    # ....XY
    xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1]
    # ....YX
    yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1]
    # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
    if iA != n:
        dpY_left = n-1
    if iB != n:
        dpX_left = n-1
    dpX[n-1] = xy
    dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
    dpX_cum[n] = dpX_cum[n-1]
    dpY[n-1] = yx
    dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
    dpY_cum[n] = dpY_cum[n-1]

answer = dpX_cum[n] - dpX_cum[dpX_left-1]
answer += dpY_cum[n] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer)

Choices:
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded
- Internal error


Question:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left, bisect_right

INF = 10**18 + 100
N,A,B = map(int,input().split())
S = [-INF] + [int(x) for x in sys.stdin.read().split()]

MOD = 10**9 + 7

dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [0] * (N+1)
dpY_cum = [0] * (N+1)
dpX_cum[0] = 1
dpY_cum[0] = 1
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
    iA = bisect_right(S,x-A)
    iB = bisect_right(S,x-B)
    # ....XY
    xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1]
    # ....YX
    yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1]
    # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
    if iA != n:
        dpY_left = n-1
    if iB != n:
        dpX_left = n-1
    dpX[n-1] = xy
    dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
    dpX_cum[n] = dpX_cum[n-1]
    dpY[n-1] = yx
    dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
    dpY_cum[n] = dpY_cum[n-1]

answer = dpX_cum[n] - dpX_cum[dpX_left-1]
answer += dpY_cum[n] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer)

Choices:
- Compile Error
- Time Limit Exceeded
- Runtime Error
- Internal error


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

uninity = [0] * (N+1)
dp = [np.zeros(30,np.int64) for _ in range(N+1)]
answer = -1
for x in order[::-1]:
    p = parent[x]
    A = dp[x]
    twice = (A >= 2)
    if np.any(twice):
        k = np.where(twice)[0].max()
        A[:k] = 1
    lsb = np.where(A == 0)[0].min()
    if answer < lsb:
        answer += 1
    uninity[x] = lsb
    A[lsb] = 1
    A[:lsb] = 0
    A[A>0] = 1
    dp[p] += A

print(answer)

Choices:
- Runtime Error
- Memory Limit Exceeded
- Time Limit Exceeded
- Compile Error


Question:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8,i8,i8[:])', cache=True)
def main(N, K, A):
    B = np.maximum(A, 0)
    Acum = np.zeros(len(A) + 1, np.int64)
    Bcum = np.zeros(len(A) + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum[1:] = np.cumsum(B)
    ret = -(10**18)
    for l in range(N - K + 1):
        r = l + K
        sum1 = Bcum[l]
        sum2 = Bcum[-1] - Bcum[r]
        sum3 = Acum[r] - Acum[l]
        x = sum1 + sum2 + max(sum3, 0)
        ret = max(ret, x)
    return ret

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

print(main(N, K, A))

Choices:
- Runtime Error
- Memory Limit Exceeded
- Internal error
- Compile Error


Question:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,K = map(int,readline().split())
A = [int(x)-1 for x in readline().split()]

desc_edge = [set() for _ in range(N)]
parent = [0] * N
for i,x in enumerate(A[1:],1):
    # 根から葉に向かう向きに辺を持つ
    desc_edge[x].add(i)
    parent[i]=x

depth = [None] * N
q = [0]
depth[0]=0
while q:
    x = q.pop()
    for y in desc_edge[x]:
        q.append(y)
        depth[y] = depth[x]+1

V = set(range(N))

q=[]
depth_to_v = [[] for _ in range(N)]
for v,x in enumerate(depth):
    depth_to_v[x].append(v)
for d in range(N):
    q += depth_to_v[d]

answer = 0
while q:
    x = q.pop()
    if x == 0:
        break
    if x not in V:
        continue
    if depth[x] <= K:
        break
    answer += 1
    for _ in range(K-1):
        y = parent[y]
    # yの転送先を0に変更する、yの部分木は捨てる
    qq = [y]
    while qq:
        z = qq.pop()
        V.remove(z)
        for w in desc_edge[z]:
            if w in V:
                qq.append(w)

if A[0] != 0:
    answer += 1
print(answer)

Choices:
- Runtime Error
- No abnormally found
- Memory Limit Exceeded
- Time Limit Exceeded


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

A.sort(reverse = True)

A.append(0)
i = 0
while A[i + 1] < i + 1:
    i += 1

x = A[i] - (i + 1)
y = max(j for j in range(N) if A[j] <= i + 1) - i

answer = 'First' if x&1 or y&1 else 'Second'
print(answer)

Choices:
- No abnormally found
- Time Limit Exceeded
- Runtime Error
- Compile Error


Question:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,M = map(int,readline().split())
A = [int(x) for x in readline().split()]

OD = [x for x in A if x&1]
EV = [x for x in A if not x&1]

if len(OD) >= 3:
    print('Impossible')
    exit()

if len(A) == 1:
    if N == 1:
        B = [1]
    else:
        B = [1,N-1]
elif len(OD) == 0:
    B = A.copy()
    B[0] -= 1
    B[-1] += 1
elif len(OD) == 1:
    A = OD + EV
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
else:
    A = OD[0] + EV + OD[-1]
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
B = [x for x in B if x > 0]

print(*A)
print(len(B))
print(*B)

Choices:
- Time Limit Exceeded
- Memory Limit Exceeded
- Internal error
- Runtime Error


Question:
n = int(input())
s = ineput()
mod = 998244353
ans = 1
z, o, t = n, 0, 0
pre = ["", ["", ""]]
for i in range(3*n):
  if t != 0 and s[i] not in pre[1]:
    ans *= t
    ans %= mod
    t -= 1
    if t == 0:
      pre[1] = ["", ""]
  elif s[i] == pre[0] or o == 0:
    o += 1
    ans *= z
    ans %= mod
    z -= 1
    pre[0] = s[i]
  else:
    t += 1
    ans *= o
    ans %= mod
    o -= 1
    pre[1] = [pre[0], s[i]]
    if o == 0:
      pre[0] = ""

print(ans)

Choices:
- Time Limit Exceeded
- No abnormally found
- Runtime Error
- Compile Error


Question:
n = int(input())
s = input()
mod = 998244353
ans = 1
z, o, t = n, 0, 0
O, T = "", ""
for i in range(3*n):
  if T != "" and s[i] != O and s[i] != T:
    ans *= t
    ans %= mod
    t -= 1
    if t == 0:
      T = ""
  elif s[i] == O or O == "":
    o += 1
    ans *= zg
    ans %= mod
    z -= 1
    O = s[i]
  else:
    t += 1
    ans *= o
    ans %= mod
    o -= 1
    T = s[i]
    if o == 0:
      O = ""

print(ans)

Choices:
- No abnormally found
- Compile Error
- Internal error
- Runtime Error


Question:
p = int(input())
a = list(map(int, input().split()))

list_size = p-1

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % p)

f_r_list[-1] = pow(f_list[-1], p - 2, p)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % p)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % p) * f_r_list[r - 1]) % p

pows = [[1] for x in range(p)]
for i in range(p):
	for _ in range(p-1):
		pows[i].append((pows[i][-1] * i) % p)

ans = [0 for _ in range(p)]
for i, x in enumerate(a):
	if x == 0:
		continue
	ans[0] += 1
	ans[0] %= p
	for j in range(p):
		ans[j] -= pows[p-i][p-1-j] * comb(p-1, j)
		ans[j] %= p

print(*ans)

Choices:
- Compile Error
- Runtime Error
- No abnormally found
- Internal error


Question:
n = int(input())
c = []
not_c = []
chosen = set()
ans = 0
for i in range(n):
	a, b = map(int, input().split())
	not_c.append([max(a, b), i])
	c.append([min(a, b), i])
	ans += min(a, b)
	if a < b:
		chosen.add("a")
	elif a > b:
		chosen.add("b")

if len(chosen) < 2:
	print(ans)
else:
	c = sorted(c, reverse=True)
	not_c = sorted(not_c)
	#print(c, not_c)
	#used_c = [False] * n
	#used_n = [False] * n

	if c[0][1] != not_c[0][1]:
		ans = ans - c[0][0] + not_c[0][0]
		c_cur = 1
		not_cur = 1
	else:
		ans = min(ans - c[1][0] + not_c[0][0], ans - c[0][0] + not_c[1][0])
		if ans - c[1][0] + not_c[0][0] <= ans - c[0][0] + not_c[1][0]:
			c_cur = 2
			not_cur = 1
		else:
			c_cur = 1
			not_c = 2
	if c_cur < n and not_cur < n:
		while c[c_cur][0] > not_c[not_cur][0]:
			if c[c_cur][1] != not_c[not_cur][1]:
				ans = ans - c[c_cur][0] + not_c[not_cur][0]
				c_cur += 1
				not_cur += 1
			elif c_cur == n - 1 or not_cur == n - 1:
				break
			else:
				ans = min(ans - c[c_cur+1][0] + not_c[not_cur][0], ans - c[c_cur][0] + not_c[not_cur+1][0])
				if ans - c[c_cur+1][0] + not_c[not_cur][0] <= ans - c[c_cur][0] + not_c[not_cur+1][0]:
					c_cur += 2
					not_cur += 1
				else:
					c_cur += 1
					not_cur += 2
			if c_cur >= n or not_cur >= n:
				break
	print(ans)

Choices:
- No abnormally found
- Runtime Error
- Compile Error
- Time Limit Exceeded


Question:
n = int(input())
c = []
not_c = []
chosen = set()
ans = 0
for i in range(n):
	a, b = map(int, input().split())
	not_c.append([max(a, b), i])
	c.append([min(a, b), i])
	ans += min(a, b)
	if a < b:
		chosen.add("a")
	elif a > b:
		chosen.add("b")

if len(chosen) < 2:
	print(ans)
else:
	c = sorted(c, reverse=True)
	not_c = sorted(not_c)
	#print(c, not_c)
	#used_c = [False] * n
	#used_n = [False] * n

	if c[0][1] != not_c[0][1]:
		ans = ans - c[0][0] + not_c[0][0]
		c_cur = 1
		not_cur = 1
	else:
		ans = min(ans - c[1][0] + not_c[0][0], ans - c[0][0] + not_c[1][0])
		if ans - c[1][0] + not_c[0][0] <= ans - c[0][0] + not_c[1][0]:
			c_cur = 2
			not_cur = 1
		else:
			c_cur = 1
			not_c = 2
	if c_cur < n and not_cur < n:
		while c[c_cur][0] > not_c[not_cur][0]:
			if c[c_cur][1] != not_c[not_cur][1]:
				ans = ans - c[c_cur][0] + not_c[not_cur][0]
				c_cur += 1
				not_cur += 1
			elif c_cur == n - 1 or not_cur == n - 1:
				break
			else:
				ans = min(ans - c[c_cur+1][0] + not_c[not_cur][0], ans - c[c_cur][0] + not_c[not_cur+1][0])
				if ans - c[c_cur+1][0] + not_c[not_cur][0] <= ans - c[c_cur][0] + not_c[not_cur+1][0]:
					c_cur += 2
					not_cur += 1
				else:
					c_cur += 1
					not_c += 2
			if c_cur >= n or not_cur >= n:
				break
	print(ans)

Choices:
- Runtime Error
- No abnormally found
- Time Limit Exceeded
- Compile Error


Question:
n = int(input())
c = []
not_c = []
chosen = set()
ans = 0
for i in range(n):
	a, b = map(int, input().split())
	not_c.append([max(a, b), i])
	c.append([min(a, b), i])
	ans += min(a, b)
	if a < b:
		chosen.add("a")
	elif a > b:
		chosen.add("b")

if len(chosen) < 2:
	print(ans)
else:
	c = sorted(c, reverse=True)
	not_c = sorted(not_c)
	#print(c, not_c)
	#used_c = [False] * n
	#used_n = [False] * n

	if c[0][1] != not_c[0][1]:
		ans = ans - c[0][0] + not_c[0][0]
		c_cur = 1
		not_cur = 1
	else:
		ans = min(ans - c[1][0] + not_c[0][0], ans - c[0][0] + not_c[1][0])
		if ans - c[1][0] + not_c[0][0] <= ans - c[0][0] + not_c[1][0]:
			c_cur = 2
			not_cur = 1
		else:
			c_cur = 1
			not_c = 2
	if c_cur < n and not_cur < n:
		while c[c_cur][0] > not_c[not_cur][0]:
			if c[c_cur][1] != not_c[not_cur][1]:
				ans = ans - c[c_cur][0] + not_c[not_cur][0]
				c_cur += 1
				not_cur += 1
			else:
				ans = min(ans - c[c_cur+1][0] + not_c[not_cur][0], ans - c[c_cur][0] + not_c[not_cur+1][0])
				if ans - c[c_cur+1][0] + not_c[not_cur][0] <= ans - c[c_cur][0] + not_c[not_cur+1][0]:
					c_cur += 2
					not_cur += 1
				else:
					c_cur += 1
					not_c += 2
			if c_cur >= n or not_cur >= n:
				break
	print(ans)

Choices:
- No abnormally found
- Runtime Error
- Time Limit Exceeded
- Memory Limit Exceeded


Question:
n = int(input())
c = []
not_c = []
chosen = set()
ans = 0
for i in range(n):
	a, b = map(int, input().split())
	not_c.append([max(a, b), i])
	c.append([min(a, b), i])
	ans += min(a, b)
	if a < b:
		chosen.add("a")
	elif a > b:
		chosen.add("b")

if len(chosen) < 2:
	print(ans)
else:
	c = sorted(c, reverse=True)
	not_c = sorted(not_c)
	#print(c, not_c)
	#used_c = [False] * n
	#used_n = [False] * n

	if c[0][1] != not_c[0][1]:
		ans = ans - c[0][0] + not_c[0][0]
		c_cur = 1
		not_cur = 1
	else:
		ans = min(ans - c[1][0] + not_c[0][0], ans - c[0][0] + not_c[1][0])
		if ans - c[1][0] + not_c[0][0] <= ans - c[0][0] + not_c[1][0]:
			c_cur = 2
			not_cur = 1
		else:
			c_cur = 1
			not_c = 2
	while c[c_cur][0] > not_c[not_cur][0]:
		if c[c_cur][1] != not_c[not_cur][1]:
			ans = ans - c[c_cur][0] + not_c[not_cur][0]
			c_cur += 1
			not_cur += 1
		else:
			ans = min(ans - c[c_cur+1][0] + not_c[not_cur][0], ans - c[c_cur][0] + not_c[not_cur+1][0])
			if ans - c[c_cur+1][0] + not_c[not_cur][0] <= ans - c[c_cur][0] + not_c[not_cur+1][0]:
				c_cur += 2
				not_cur += 1
			else:
				c_cur += 1
				not_c += 2
		if c_cur >= n or not_cur >= n:
			break
	print(ans)

Choices:
- Time Limit Exceeded
- No abnormally found
- Runtime Error
- Compile Error


Question:
n = int(input())
c = []
not_c = []
chosen = set()
ans = 0
for i in range(n):
	a, b = map(int, input().split())
	not_c.append([max(a, b), i])
	c.append([min(a, b), i])
	ans += min(a, b)
	if a < b:
		chosen.add("a")
	elif a > b:
		chosen.add("b")

if len(chosen) < 2:
	print(ans)
else:
	c = sorted(c, reverse=True)
	not_c = sorted(not_c)
	#print(c, not_c)
	#used_c = [False] * n
	#used_n = [False] * n

	if c[0][1] != not_c[0][1]:
		ans = ans - c[0][0] + not_c[0][0]
		c_cur = 1
		not_cur = 1
	else:
		ans = min(ans - c[1][0] + not_c[0][0], ans - c[0][0] + not_c[1][0])
		if ans - c[1][0] + not_c[0][0] <= ans - c[0][0] + not_c[1][0]:
			c_cur = 2
			not_cur = 1
		else:
			c_cur = 1
			not_c = 2
	while c[c_cur][0] > not_c[not_cur][0]:
		if c[c_cur][1] != not_c[not_cur][1]:
			ans = ans - c[c_cur][0] + not_c[not_cur][0]
			c_cur += 1
			not_cur += 1
		else:
			ans = min(ans - c[c_cur+1][0] + not_c[not_cur][0], ans - c[c_cur][0] + not_c[not_cur+1][0])
			if ans - c[c_cur+1][0] + not_c[not_cur][0] <= ans - c[c_cur][0] + not_c[not_cur+1][0]:
				c_cur += 2
				not_cur += 1
			else:
				c_cur += 1
				not_c += 2
	print(ans)

Choices:
- Internal error
- Time Limit Exceeded
- No abnormally found
- Runtime Error


Question:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
used = []
now = 0
i = 0
j = 0

if abs(l_sort[0][0]) >= abs(r_sort[0][1]):
	while len(used) != n:
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.append(l_sort[i][2])
		i += 1
		if len(used) == n:
			break
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.append(r_sort[j][2])
		j += 1

	print(ans + abs(now))

else:
	while len(used) != n:
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.append(r_sort[j][2])
		j += 1
		if len(used) == n:
			break
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.append(l_sort[i][2])
		i += 1
		#print(now)

	print(ans + abs(now))

Choices:
- Memory Limit Exceeded
- Internal error
- Time Limit Exceeded
- No abnormally found


Question:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))
#print(l_sort, r_sort)

ans = 0
used = set()
now = 0
i = 0
j = 0

if abs(l_sort[0][0]) >= abs(r_sort[0][1]):
	while used != set(range(n)):
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.add(l_sort[i][2])
		i += 1
		#print(now)
		if used == set(range(n)):
			break
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.add(r_sort[j][2])
		j += 1
		#print(now)

	print(ans + abs(now))

else:
	while used != set(range(n)):
		while r_sort[j][2] in used:
			j += 1
		if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
			ans += abs(now - r_sort[j][1])
			now = r_sort[j][1]
		used.add(r_sort[j][2])
		j += 1
		#print(now)
		if used == set(range(n)):
			break
		while l_sort[i][2] in used:
			i += 1
		if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
			ans += abs(now - l_sort[i][0])
			now = l_sort[i][0]
		used.add(l_sort[i][2])
		i += 1
		#print(now)

	print(ans + abs(now))

Choices:
- Runtime Error
- Memory Limit Exceeded
- Compile Error
- Time Limit Exceeded


Question:
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) + [i] for i in range(n)]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))
#print(l_sort, r_sort)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)
	if used == set(range(n)):
		break
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)

ans1 = ans + abs(now)

ans = 0
used = set()
now = 0
i = 0
j = 0

while used != set(range(n)):
	while r_sort[j][2] in used:
		j += 1
	if not (r_sort[j][0] <= now and now <= r_sort[j][1]):
		ans += abs(now - r_sort[j][1])
		now = r_sort[j][1]
	used.add(r_sort[j][2])
	j += 1
	#print(now)
	if used == set(range(n)):
		break
	while l_sort[i][2] in used:
		i += 1
	if not (l_sort[i][0] <= now and now <= l_sort[i][1]):
		ans += abs(now - l_sort[i][0])
		now = l_sort[i][0]
	used.add(l_sort[i][2])
	i += 1
	#print(now)

ans2 = ans + abs(now)

#print(ans1, ans2)
print(max(ans1, ans2))

Choices:
- Compile Error
- No abnormally found
- Time Limit Exceeded
- Internal error


Question:
r, D, x = map(int, input(),split())

def calc(r, D, x):
  return (r * x) - D

for _ in range(10):
  x = calc(r, D, x)
  print(x)

Choices:
- Time Limit Exceeded
- No abnormally found
- Runtime Error
- Memory Limit Exceeded


Question:
a,b=(int(i)+11)%13 for i in input().split()
print("Bob" if a<b else "Alice" if a>b else "Draw")

Choices:
- Runtime Error
- Time Limit Exceeded
- No abnormally found
- Memory Limit Exceeded


Question:
n  =int(input())
D = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += D[i]*D[j]
print(ans)

Choices:
- Internal error
- Time Limit Exceeded
- No abnormally found
- Runtime Error


Question:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
target = s//2 if s%2==0 else s//2+1
l = 2001
dp = [0 for _ in range(n+1)]
dp[0] = 1
for i in range(1, n+1):
    dp[i] = dp[i-1] | (dp[i-1]<<a[i-1])
ans = float("inf")
for i in range(target, s+1):
    if (dp[n]>>i&1)==1:
        ans = min(ans, i)
        break
print(ans)

Choices:
- Time Limit Exceeded
- Memory Limit Exceeded
- No abnormally found
- Runtime Error


Question:
x = int(input())
slime = str(input())
i = 0
scount = 0
while(i < n-1):
    if(slime[i] != slime[i+1]):
        scount += 1
    i += 1
print(scount)

Choices:
- Internal error
- No abnormally found
- Memory Limit Exceeded
- Runtime Error


Question:
n,m,c = map(int,input().split())
ans = 0
for i in range(m):
    current = 0
    a = list(map(int,input().split()))
    for k,j in enumerate(a):
        current += j*(k+1)
    ans += 1 if c+current else 0
print(ans)

Choices:
- Runtime Error
- No abnormally found
- Memory Limit Exceeded
- Internal error


Question:
N,K=map(int,input().split())
c=0
for i in range(1,N+1):
    ans=[0,0,0]
    for j in range(1,2*N//K+1):
        if 1<=j*K-i<=N:
            for l in range(1,2*N//K+1):
                if 1<=l*K-j*K+i<=N and (2*i+l*K-j*K)%K==0:
                    count=0
                    ans[0]=i
                    ans[1]=j*K-i
                    ans[2]=l*K-j*K+i
                    ans.sort()
                    c+=1
print(c)

Choices:
- Time Limit Exceeded
- No abnormally found
- Memory Limit Exceeded
- Compile Error


Question:
N = input()
S = input()
new_S = ""
for i in range(int(N)):
    if i == 0:
        new_S += S[i]
    else:
        if S[i] != S[i-1]:
            new_S += S[i]
print(len(new_S))

Choices:
- Memory Limit Exceeded
- Time Limit Exceeded
- Runtime Error
- Internal error


Question:
    a,b = map(int,input().split())
    if a != 1 and b != 1:
        if a > b :
            print("Alice")
        elif a < b:
            print("Bob")
        else:
            print("Draw")
    elif a == 1 and b != 1:
        print("Alice")
    elif a != 1 and b == 1:
        print("Bob")
    else:
        print("Draw")

Choices:
- No abnormally found
- Memory Limit Exceeded
- Runtime Error
- Compile Error


Question:
import math
n=input()
a=map(int,input().split())

a.sort()

print(a[-1]-a[0])

Choices:
- Runtime Error
- Memory Limit Exceeded
- Compile Error
- Internal error


Question:
import math

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

a.sort()

print(a[-1]-a[0])

Choices:
- Memory Limit Exceeded
- Internal error
- Runtime Error
- Time Limit Exceeded


Question:
# -*- coding: utf-8 -*-
from heapq import heappush, heapreplace
from itertools import count, product, combinations
from functools import partial, reduce
from math import floor, ceil, sqrt, gcd
from collections import defaultdict, deque

def Primes_fnct():
    def b_search(L,t):
        #増大列LについてL[:+1]の要素すべてがt以下であるような最大のi<len(L)を返す。
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in [0]*search_range[1].bit_length():
            update_range(sum(search_range)//2)
        return search_range[0]

    P = [2,]
    Pappend = P.append
    Q = deque([])
    Qappend = Q.append
    Qpopleft = Q.popleft
    hq = []
    integer = count(3,2)
    current_i = 1
    valid_range = 1
    def Primes(*, max_int=None):
        nonlocal valid_range, current_i
        if max_int is None:
            return P[:]

        if  max_int - current_i <= 1:
            return P[:b_search(P,max_int)+1]

        for i in integer:
            if i >= valid_range:
                if Q:
                    q = Qpopleft()
                    heappush(hq, (q**2,q))
                valid_range = Q[0]**2 if Q else i**2

            m,r = hq[0] if hq else (0,0)
            if i != m:
                Pappend(i)
                Qappend(i)

            while m == i:
                heapreplace(hq, (m+2*r, r))
                m,r = hq[0]

            current_i = i
            if max_int - current_i <=1:
                break
        return P[:]
    return Primes

def factorization(m, Primes=None):
    F = defaultdict(int)
    if m < 2:
        return F

    while not m&1:
        F[2] += 1
        m >>= 1

    if Primes is None:
        Primes = Primes_fnct()

    Primes = deque(Primes(max_int=ceil(sqrt(m))+1))
    Primespopleft = Primes.popleft

    while m > 1 and Primes:
        p = Primespopleft()
        while not m%p:
            m //= p
            F[p] += 1

    if m > 1:
        F[m] += 1
    return F

def solve():
    N = int(input())
    Primes = Primes_fnct()
    F = defaultdict(int)
    for i in range(1,N+1):
        f = factorization(i)
        for k in f.keys():
            F[k] += f[k]
    P = defaultdict(set)
    for k in F.keys():
        for n in (2,4,14,24,74):
            if F[k] >= n:
                P[n] = P[n]|{k,}
    res = 0
    for Q in (((2,1),(4,2)), ((2,1),(24,1)), ((4,1),(14,1)), ((74,1),)):
        R = set()
        if all(len(P[q[0]]) >= q[1] for q in Q):
            for r in product(*(combinations(P[q[0]],q[1]) for q in Q)):
                r_ = [i for j in r for i in j]
                if len(r_) == len(set(r_)):
                    R |= {r,}
        res += len(R)

    return res

if __name__ == '__main__':
    print(solve())

Choices:
- Runtime Error
- Compile Error
- Internal error
- Memory Limit Exceeded


Question:
# -*- coding: utf-8 -*-
from heapq import heappush, heapreplace
from itertools import count, product, combinations
from functools import partial, reduce
from math import floor, ceil, sqrt, gcd
from collections import defaultdict, deque

def Primes_fnct():
    def b_search(L,t):
        #増大列LについてL[:+1]の要素すべてがt以下であるような最大のi<len(L)を返す。
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in [0]*search_range[1].bit_length():
            update_range(sum(search_range)//2)
        return search_range[0]

    P = [2,]
    Pappend = P.append
    Q = deque([])
    Qappend = Q.append
    Qpopleft = Q.popleft
    hq = []
    integer = count(3,2)
    current_i = 1
    valid_range = 1
    def Primes(*, max_int=None):
        nonlocal valid_range, current_i
        if max_int is None:
            return P[:]

        if  max_int - current_i <= 1:
            return P[:b_search(P,max_int)+1]

        for i in integer:
            if i >= valid_range:
                if Q:
                    q = Qpopleft()
                    heappush(hq, (q**2,q))
                valid_range = Q[0]**2 if Q else i**2

            m,r = hq[0] if hq else (0,0)
            if i != m:
                Pappend(i)
                Qappend(i)

            while m == i:
                heapreplace(hq, (m+2*r, r))
                m,r = hq[0]

            current_i = i
            if max_int - current_i <=1:
                break
        return P[:]
    return Primes

def factorization(m, Primes=None):
    F = defaultdict(int)
    if m < 2:
        return F

    while not m&1:
        F[2] += 1
        m >>= 1

    if Primes is None:
        Primes = Primes_fnct()

    Primes = deque(Primes(max_int=ceil(sqrt(m))+1))
    Primespopleft = Primes.popleft

    while m > 1 and Primes:
        p = Primespopleft()
        while not m%p:
            m //= p
            F[p] += 1

    if m > 1:
        F[m] += 1
    return F

def solve():
    N = int(input())
    Primes = Primes_fnct()
    F = defaultdict(int)
    for i in range(1,N+1):
        f = factorization(i)
        for k in f.keys():
            F[k] += f[k]
    P = defaultdict(set)
    for k in F.keys():
        for n in (2,4,14,24,74):
            if F[k] >= n:
                P[n] = P[n]|{k,}
    res = 0
    for Q in (((2,1),(4,2)), ((2,1),(24,1)), ((4,1),(14,1)), ((74,1),)):
        R = set()
        for r in product(*(combinations(P[q[0]],q[1]) for q in Q)):
            r_ = [i for j in r for i in j]
            if len(r_) == len(set(r_)):
                R |= {r,}
        res += len(R)

    return res

if __name__ == '__main__':
    print(solve())

Choices:
- Time Limit Exceeded
- Runtime Error
- No abnormally found
- Memory Limit Exceeded


Question:
def cmb(n, r, mod):#コンビネーションの高速計算
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

import time
S=input()
N=len(S)
#print(N)
start=time.time()
if N==1:
    exit(print(1))

dp=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]

dpf[0][0][0]=1
if S[0]=="0":
    dpf[1][1][0]=0
if S[1]=="0":
    dp[1][1][0]=0
if S[0]=="1":
    dpf[1][0][1]=0
if S[1]=="1":
    dp[1][0][1]=0
dpf[1][0][0]=2
Zero=1-int(S[0])+1-int(S[1])
One=int(S[0])+int(S[1])
for i in range(2,N):
    Zero+=1-int(S[i])
    One+=int(S[i])
    for j in range(Zero+1):
        for k in range(One+1):
            a,b=1-int(S[i]),int(S[i])
            dp[i][j][k]=max(dp[i-1][j-a][k-b]-2,dpf[i-1][j-a][k-b]-1)
            a,b=1-int(S[i-1]),int(S[i-1])
            if dp[i-2][j-a][k-b]>=0:
                dpf[i][j][k]=2*(dp[i-2][j-a][k-b]//2)
            if dpf[i-2][j-a][k-b]>=0:
                dpf[i][j][k]=max(2*(dpf[i-2][j-a][k-b]//2),dpf[i][j][k])
            if dp[i-1][j][k]>=0:
                dpf[i][j][k]=max(dp[i-1][j][k]+1-dp[i-1][j][k]%2,dpf[i][j][k])
            dpf[i][j][k]=max(dpf[i][j][k],dpf[i-1][j][k]+1)
    dpf[i][0][0]=i+1

data=[[[(dp[i][j][k]>=0 or dpf[i][j][k]>=0)&((j,k)!=(0,0)) for k in range(N+1)] for j in range(N+1)] for i in range(N)]
med=time.time()
#print(med-start)

S=[S[-i-1] for i in range(N)]
Zero=0
One=0
ans=1
check=set([])
one,zero=S.count("1"),S.count("0")
for i in range(N):
    Zero+=(S[i]=="1")
    One+=(S[i]=="0")
    for j in range(zero+1):
        for k in range(one+1):
            if data[N-1-i][j][k]:
                check.add((j,k))
    ncheck=set([])
    for j,k in check:
        A,B=1,1
        if j!=0:
            A=cmb(Zero+j-1,j,mod)
        if k!=0:
            B=cmb(One+k-1,k,mod)
        ans+=A*B
        ans%=mod
        a,b=1-int(S[i]),int(S[i])
        if j>=a and k>=b:
            ncheck.add((j-a,k-b))
    check=ncheck
    zero-=1-int(S[i])
    one-=int(S[i])

print(ans)

def check():
    res=0
    for i in range(N):
        for j in range(N+1):
            for k in range(N+1) :
                if data[i][j][k]:
                    print(i,j,k)
                    res+=1
    return res
#print(time.time()-start)

Choices:
- No abnormally found
- Runtime Error
- Compile Error
- Time Limit Exceeded


Question:
def cmb(n, r, mod):#コンビネーションの高速計算
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

S=input()
N=len(S)

dp=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]

dpf[0][0][0]=1
if S[0]=="0":
    dpf[1][1][0]=0
if S[1]=="0":
    dp[1][1][0]=0
if S[0]=="1":
    dpf[1][0][1]=0
if S[1]=="1":
    dp[1][0][1]=0
dpf[1][0][0]=2
for i in range(2,N):
    for j in range(N+1):
        for k in range(N+1):
            a,b=1-int(S[i]),int(S[i])
            dp[i][j][k]=max(dp[i-1][j-a][k-b]-2,dpf[i-1][j-a][k-b]-1)
            a,b=1-int(S[i-1]),int(S[i-1])
            if dp[i-2][j-a][k-b]>=0:
                dpf[i][j][k]=2*(dp[i-2][j-a][k-b]//2)
            if dpf[i-2][j-a][k-b]>=0:
                dpf[i][j][k]=max(2*(dpf[i-2][j-a][k-b]//2),dpf[i][j][k])
            if dp[i-1][j][k]>=0:
                dpf[i][j][k]=max(dp[i-1][j][k]+1-dp[i-1][j][k]%2,dpf[i][j][k])
            dpf[i][j][k]=max(dpf[i][j][k],dpf[i-1][j][k]+1)
    dpf[i][0][0]=i+1

data=[[[(dp[i][j][k]>=0 or dpf[i][j][k]>=0)&((j,k)!=(0,0)) for k in range(N+1)] for j in range(N+1)] for i in range(N)]

S=[S[-i-1] for i in range(N)]
Zero=0
One=0
ans=1
check=set([])
for i in range(N):
    Zero+=(S[i]=="1")
    One+=(S[i]=="0")
    for j in range(N+1):
        for k in range(N+1):
            if data[N-1-i][j][k]:
                check.add((j,k))
    ncheck=set([])
    for j,k in check:
        A,B=1,1
        if j!=0:
            A=cmb(Zero+j-1,j,mod)
        if k!=0:
            B=cmb(One+k-1,k,mod)
        ans+=A*B
        ans%=mod
        a,b=1-int(S[i]),int(S[i])
        if j>=a and k>=b:
            ncheck.add((j-a,k-b))
    check=ncheck

print(ans)

def check():
    res=0
    for i in range(N):
        for j in range(N+1):
            for k in range(N+1) :
                if data[i][j][k]:
                    print(i,j,k)
                    res+=1
    return res

Choices:
- Memory Limit Exceeded
- Runtime Error
- Internal error
- No abnormally found


Question:
import sys

input=sys.stdin.readline

N=int(input())
A=[-1]*N;B=[-1]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

ans=min(sum(A),sum(B))

temp=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)]
temp.sort()
data=[0]*N
for i in range(N):
    val,id=temp[i]
    data[id]+=1
S=sum(temp[i][0] for i in range(N))

for i in range(N):
    if data[i]==2:
        test=S
    elif data[i]==1:
        if temp[N-1][1]!=i:
            test=S+max(A[i],B[i])-temp[N-1][0]
        else:
            test=S+max(A[i],B[i])-temp[N-2][0]
    ans=min(test,ans)

print(ans)

Choices:
- Runtime Error
- No abnormally found
- Compile Error
- Internal error


Question:
import sys

input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    s=input()
    dic={"A":[0 for i in range(N)],"B":[0 for i in range(N)]}
    edge=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
        dic[s[a]][b]+=1
        dic[s[b]][a]+=1

    que=set([])
    check=0
    for i in range(N):
        if dic["A"][i]==0 or dic["B"][i]==0:
            que.add(i)
            dic["A"][v]=float("inf")
            dic["B"][v]=float("inf")

    while que:
        v=que.pop()
        check+=v+1
        for nv in edge[v]:
            dic[s[v]][nv]-=1
            if dic["A"][nv]==0 or dic["B"][nv]==0:
                dic["A"][v]=float("inf")
                dic["B"][v]=float("inf")
                que.add(nv)

    if check==N*(N+1)//2:
        print("No")
    else:
        print("Yes")

if __name__=="__main__":
    main()

Choices:
- No abnormally found
- Runtime Error
- Memory Limit Exceeded
- Compile Error


Question:
#####segfunc#####
def segfunc(x, y):
    if x[0]==0:
        return x
    else:
        return y
#################

#####ide_ele#####
ide_ele = [float("inf"),-1]
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k][0] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import sys

input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    s=input()
    dic={"A":[[0,i] for i in range(N)],"B":[[0,i] for i in range(N)]}
    edge=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
        dic[s[a]][b][0]+=1
        dic[s[b]][a][0]+=1

    dic={moji:SegTree(dic[moji],segfunc,ide_ele) for moji in dic}

    ban=set([])
    while True:
        a,index=dic["A"].query(0,N)
        b,index2=dic["B"].query(0,N)
        if a==0:
            ban.add(index)
            dic["A"].update(index,float("inf"))
            dic["B"].update(index,float("inf"))
            for v in edge[index]:
                dic[s[index]].update(v,-1)

        elif b==0:
            ban.add(index2)
            dic["A"].update(index2,float("inf"))
            dic["B"].update(index2,float("inf"))
            for v in edge[index2]:
                dic[s[index2]].update(v,-1)
        else:
            break

    check=set([i for i in range(N)])
    if ban==check:
        print("No")
    else:
        print("Yes")

if __name__=="__main__":
    main()

Choices:
- Time Limit Exceeded
- No abnormally found
- Memory Limit Exceeded
- Runtime Error