Question:
def main():
    from copy import deepcopy
    n, m = map(int, input().split())
    s = [i == "B" for i in input()]
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]

    g2 = [[0, 0] for _ in [0]*n]

    for i in range(n):
        for j in g[i]:
            g2[i][s[j]] += 1

    ss = []
    for i, (j, k) in enumerate(g2):
        if (j == 0 and k > 0) or (j > 0 and k == 0):
            ss.append(i)

    while ss:
        i = ss.pop()
        c = s[i]
        for j in deepcopy(g[i]):
            g[j].remove(i)
            g2[j][c] -= 1
            p, q = g2[j]
            if (p == 0 and q > 0) or (p > 0 and q == 0):
                ss.append(j)
        g[i] = set()

    for i in g:
        if len(i) > 0:
            print("Yes")
            return
    print("No")

main()

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


Question: print(["No","Yes"][input()[0]==input()[2]])

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


Question:
H,W=map(int,input().split())
G=[input()+"." for _ in range(4)]+["."*(W+1)]
p=[0,0]
while(p!=[H-1,W-1]):
    if G[p[0]+1][p[1]]==G[p[0]][p[1]+1]:
        print("Impossible")
        break
    elif G[p[0]+1][p[1]]=="#":
        p=[p[0]+1,p[1]]
    else:
        p=[p[0],p[1]+1]
else:
    print("Possible")

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


Question:
n, x = map(int, input().split())
def burger(x):
  if x == 0:
    return "P"
  else:
    return "B" + burger(x-1) + "P" + burger(x-1) + "B"
print(burger(n)[:x].count("P"))

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


Question:
from itertools import combinations
n = int(input())
Names = [""] * n
for i in range(n):
  Names[i] = input()
march = ["M", "A", "R", "C", "H"]
counter = 0
for three_man in combinations(Names, 3):
  if three_man[0][0] in march and three_man[1][0] in march and three_man[2][0] in march:
    if three_man[0][0] != three_man[1][0] and three_man[1][0] != three_man[2][0] and three_man[2][0] != three_man[0][0]:
      counter += 1
print(counter)

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


Question:
H, W, D = map(int,input().split())
dist = [[float("inf") for i in range(H*W+1)] for j in range(H*W+1)]
for i in range(H*W+1):
  dist[i][i] = 0
#dist[i][j]は隣接行列
pos = [[0,0] for i in range(H*W+1)]
for i in range(H):
  A = list(map(int,input().split()))
  for j in range(W):
    pos[A[j]] = [i+1, j+1]
for i in range(H*W+1-D):
  dist[i][i+D] = abs(pos[i][0]-pos[i+D][0])+abs(pos[i][1]-pos[i+D][1])
distances = [[] for i in range(D)]#あまりがiの距離
for i in range(1,H*W+1-D):
  d = dist[i][i+D]
  distances[i%D]+=[d]
distances2 = [[0] for i in range(D)]#累積和に直す
for i in range(D):
  K = len(distances[i])
  for j in range(K):
    distances2[i]+=[distances2[i][-1]+distances[i][j]]
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  q = L%D
  l, r = (L-1)//D, (R-1)//D
  print(distances2[q][r]-distances2[q][l])

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


Question:
import sys
N,M=map(int,input().split())
A=[]
B=[]
A+=[str(input()) for i in range(N)]
B+=[str(input()) for i in range(M)]
for i in range(N-M+1):
  for j in range(N-M+1):
    ans=1
    for k in range(M):
      for l in range(M):
        if B[k][l]!=A[i+k][j+l]:
          ans=0
    if ans:
      print("Yes")
      sys.exit()
print("No")

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


Question:
S = input()
T = input()
t = len(T)
for i in range(len(T)):
  a = 0
  b = 0
  for s in range(len(T)):
    if T[s:s+i+1] in S[s:len(S)-s]:
      b += 1
    print(s,b,T[s:s+i+1],S[s:len(S)-s])
  if b == 0:
    break
print(t-i)

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


Question:
S = input()
if S == ABC:
  print("ARC")
else:
  print("ABC")

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


Question:
a,b = map(int,input().split())
print(a+b if b%a == 0 else b-a)

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


Question:
A, B, C = map(int, input().split())
if A - B >= C:
　　print(0)
else:
　　print(C - A + B)

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


Question:
A, B = map(int,input().split())
if (A + B) % 2 == 1:
  print(IMPOSSIBLE)
else:
  print((A + B) / 2)

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


Question:
n = int(input())
count = 0
ans = 0
for i in range(n):
  a,b = map(int, input().split())
  if  a == b:
    count += 1
  else:
    count = 0
  if count >= 3:
    ans = 1
    break
if ans = 1:
  print('Yes')
else:
  print('No')

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


Question:
n = int(input())
point_list = []
for i in range(n):
  line = list(map(int, input().split()))
  point_list.append(line)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    x = abs(point_list[i][0] - point_list[j][0]) + abs(point_list[i][1] - point_list[j][1])
    if x > ans:
      ans = x
print(ans)

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


Question:
n,k = map(int,input().split())
h = list(map(int,input().split()))
print(len([i for i in range(4) if h[i]>=k]))

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


Question:
s = input()
a = 1<= int(s[:2]) <=12
b = 1<= int(s[2:]) <=12
if a and b:
    print("AMBIGUOUS")
elif a:
    print('MMYY')
elif b:
    print('YYMM')
else:
    print('NA')

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


Question:
s = list(map(int, input().split()))
print(ma(s) - min(s))

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


Question:
n = list(input())
s = sum([int(n[i]) for i in range(len(n))])
if n%s==0:
    print('Yes')
else:
    print('No')

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


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


Question:
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

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


Question:
n = int(input())
x = list(reversed(sorted(map(int,input().split()))))
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

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


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

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

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


Question:
n=input()
P= list(map(int,input().split()))
x=0
for i in range(0,n-2):
    if P[i+1] != max(P[i],P[i+1],P[i+2]) and P[i+1] != min(P[i],P[i+1],P[i+2]):
        x += 1

print(x)

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


Question:
N=int(input())
import numpy as np
A=np.zeros(N)
B=np.zeros(N)
for i in range(0,N):
  A[i],B[i] = map(int,input().split())

BB=list(set(list(B)))
for b in BB:
  if np.sum(A[B<=b])>b:
    print('No')
    break
else:
  print('Yes')

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


Question:
N=int(input())
import numpy as np
A=np.zeros(N)
B=np.zeros(N)
for i in range(0,N):
  A[i],B[i] = map(int,input().split())

for b in B:
  if np.sum(A[B<=b])>b:
    print('No')
    break
else:
  print('Yes')

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


Question:
N=int(input())
import numpy as np
A=np.zeros(N)
B=np.zeros(N)
for i in range(0,N):
  A[i],B[i] = map(int,input().split())

W=np.zeros((N,np.max(B)))
for i in range(0,N):
  for j in range(int(B[i]-A[i]),int(B[i])):
    W[i][j]=1

for b in B:
  if np.sum(W[:,0:b]) > b:
    print('No')
    break
else:
  print('Yes')

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


Question:
N,X=map(int,input().split())

from functools import lru_cache
import sys

sys.setrecursionlimit(10*20)

def count(N):
    if N == 0:
        return 1
    else:
        return 3 + 2 * count(N-1)

def calc(N,X):
    if N == 0:
        return 1
    center = count(N-1) + 1
    if X == 0 :
        return 0
    elif X < center:
        return calc(N-1,X-1)
    elif X == center:
        return calc(N-1,center-2) + 1
    elif X > center:
        return calc(N-1,X-center-1) + calc(N,center)
print(calc(N,X-1))

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


Question:
N,X=map(int,input().split())

from functools import lru_cache
import sys

sys.setrecursionlimit(10*20)

@lru_cache(maxsize=None)
def count(N):
    if N == 0:
        return 1
    else:
        temp = pan(N-1)
        return 3 + 2 * count(N-1)

@lru_cache(maxsize=None)
def calc(N,X):
    if N == 0:
        return 1
    center = count(N-1) + 1
    if X == 0 :
        return 0
    elif X < center:
        return calc(N-1,X-1)
    elif X == center:
        return calc(N-1,center-2) + 1
    elif X > center:
        return calc(N-1,X-center-1) + calc(N,center)
print(calc(N,X-1))

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


Question:
N, M, C = map(int, input().split())
B = []
A = []

B.append(map(int, input().split()))
for i in range(N):
	A.append(list(map(int, input().split())))

sum = 0
count = 0

for i in range(N):
	sum = 0
	for j in range(M):
		sum += A[i][j]
		sum += B[j]
	sum += C
	if sum > 0:
		count += 1

print(sum)

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


Question:
N, M = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))

#Sorted by first element
X.sort(key=lambda x:x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	total += X[i][1]
	ans += X[i][0] * X[i][1]
	if total > M:
		ans -= X[i][0] * (total-M)
		break
	i += 1
print(ans)

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


Question:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#temp1 = 1
	#temp2 = 1
	l1.append(temp1)
	l2.append(temp2)

while True:
	min_index = l1.index(min(l1))
	ans += (min(l1) * l2[min_index])
	rest -= l2[min_index]
	if rest <= 0:
		break
	l1.pop(min_index)

print(ans)

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


Question:
N, M = map(int, input().split())
l1 = []
l2 = []
ans = 0
rest = M
for i in (N+1):
	l1[i],l2[i]  = map(int, input().split())

while true:
	min_index = l1.index(min(l1))
	ans += (min(l1) * l2[min_index])
	rest -= l2[min_index]
	if rest == 0:
		break
	l1.pop(min_index)

print(ans)

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


Question:
N = int(input())
cnt = 0
for i in range(1,N+1):
  for j in range(1,N+1):
    if str(i)[0:1:] == str(j)[-1::] and str(i)[-1::] == str(j)[0:1:]:
      cnt += 1
print(cnt)

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


Question:
y, m, d = input().split("/")
if y * 365 + m * 12 + d > 2019 * 365 + 4 * 12 + 30:
  print("TBD")
else:
  print("Heisei")

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


Question:
A, B, C, D = map(int, input().split())
print(max(min(B,D) - max(A,C) 0))

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


Question:
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N-2):
  if P[i] > P[i+1] and P[i+1] > P[i+2] or P[i] < P[i+1] and P[i+1] < P[i+2] or :
    ans += 1

print(ans)

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


Question:
x,y = map(int,input().split())
if y == x:
    print(0)
else:
    if abs(y) >= abs(x):
        tmp = abs(y)-abs(x)
        if x>=0 and y>=0:
            print(tmp)
        elif x>=0 and y<0:
            print(tmp+1)
        elif x<0 and y>=0:
            print(tmp+1)
        else:
            print(abs(y)-x+1)
    else:
        if x>=0 and y>=0:
            print(x+y+1)
        elif x>=0 and y<0:
            print(x+y+1)
        elif x<0 and y>=0:
            print(y-x)
            print(1/0)
        else:
            print(y-x)

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


Question:
x,y = map(int,input().split())
if y == x:
    print(0)
else:
    if abs(y) >= abs(x):
        tmp = abs(y)-abs(x)
        if x>=0 and y>=0:
            print(tmp)
        elif x>=0 and y<0:
            print(tmp+1)
        elif x<0 and y>=0:
            #print(tmp+1)
            print(1/0)
        else:
            print(abs(y)-x+1)
    else:
        if x>=0 and y>=0:
            print(x+y+1)
        elif x>=0 and y<0:
            print(x+y+1)
        elif x<0 and y>=0:
            print(y-x)
        else:
            print(y-x)

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


Question:
x,y = map(int,input().split())
if y == x:
    print(0)
else:
    if abs(y) >= abs(x):
        tmp = abs(y)-abs(x)
        if x>=0 and y>=0:
            print(tmp)
        elif x>=0 and y<0:
            print(tmp+1)
        elif x<0 and y>=0:
            print(tmp+1)
        else:
            #print(abs(y)-x+1)
            print(1/0)
    else:
        if x>=0 and y>=0:
            print(x+y+1)
        elif x>=0 and y<0:
            print(x+y+1)
        elif x<0 and y>=0:
            print(y-x)
        else:
            print(y-x)

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


Question:
a, b, c, d = map(int, input().split())
    print(max([a*c, a*d, b*c, b*d]))

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


Question:
A = int(input())
B = int(input())
if (A > 9 or B > 9):
    print(':(')
else:
    print('Yay!')

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


Question:
A = int(input())
B = int(input())
if A>9 or B>9:
  print ':('
else:
  print 'Yay!'

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


Question:
A = int(input())
B = int(input())
if ((A > 9) or (B > 9)):
    print(':(')
else:
    print('Yay!')

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


Question:
#!/usr/bin/env python3
import sys

def main():
    S = input()
    T = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) < 26:
        U = set(T) - set(S)
        print(S + sorted(U)[0])
    else:
        if S == T[::-1]:
            print(-1)
        else:
            count = 1
            for i in range(25):
                if S[25-i] > S[24-i]:
                    break
                else:
                    count += 1
            t = T.index(S[25-count])
            print(S[:25-count] + T[t+1])

if __name__ == '__main__':
    main()

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


Question:
import itertools
import math

N = int(input())
S_list = []
for i in range(N):
    S_list.append(input())

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
a = sum(count)

x = a*(a-1)*(a-2)/math.factorial(3)

for c in count:
    if c > 2:
        x -= c*(c-1)*(c-2)/math.factorial(3)
    elif c == 2:
        x -= (a-2)

print(int(x))

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


Question:
#!/usr/bin/env python3
import sys
import math

def main():
    N = int(input())
    digit = math.floor(math.log10(N))
    ans = [9 * digit]
    ans.append(sum([int(s) for s in str(N)]))

    for i in range(1, digit+1):
        tmp = [int(s) for s in str(N//(10**i) * (10**i) - 1)]
        ans.append(sum(tmp))
    print(max(ans))

if __name__ == '__main__':
    main()

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


Question:
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''

N = int(input())
C = list(map(int,input().split()))

# コストの小さいものから更新していけばいい
C.sort()

# 2のべき乗は先に計算しておく
beki = []
for i in range(3*N+20):
    beki.append(int(math.pow(2, i))%MOD)

ans = 0
for i in range(N):
    ans += (C[i] * beki[2*N-2] * (N-i+1))%MOD

print(ans % MOD)

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


Question:
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''

N = int(input())
C = list(map(int,input().split()))

# コストの小さいものから更新していけばいい
C.sort()

# 2のべき乗は先に計算しておく
beki = []
for i in range(3*N+20):
    beki.append(int(math.pow(2, i)))

ans = 0
for i in range(N):
    ans += (C[i] * beki[2*N-2] * (N-i+1))

print(ans % MOD)

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


Question:
#author : dokueki

import sys

def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")

def main():
    s = input()
    if s[2] == s[3] and s[4] == s[5]:
        print("Yes")
    else:
        print(No)

if __name__ == "__main__":
    #IOE()
    main()

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


Question:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and a[i+1] == a[i] + 1:
        ans += c[a[i]-1]
print(ans)

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


Question:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and a[i+1] == a[i] + 1:
        ans += c[i-1]
print(ans)

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


Question:
n = int(input())
li = list(input())
print(max(li)-min(li))

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


Question:
if (a==0 and b==0) or (a>=13 and b>=13):
  print("NA")
elif 0<a<=12 and 0<a<=12:
  print("AMBIGUOUS")
elif 0<a<12:
  print("MMYY")
else:
  print("YYMM")

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

H,W = IL()
data = ILL(H)

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)

for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

#print(calc_prev_valid(0))
#exit()

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):

  a,b = data[i]
  now = b
  while now >= a:
    if B.el[now]:
      #print("shorisita",now)
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        #print((b+1),dic[b+1])
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0

    now = calc_prev_valid(now)

  #print(dic)
  #print(members)
  #print(prev_valid)
  #print(count_score)
  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b

  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()
  if i == 1500:
    exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b

  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()
  if i == 2000:
    exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b

  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()
  if i == 5000:
    exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b

  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()
  if i == 10**4:
    exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)

for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

#print(calc_prev_valid(0))
#exit()

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b
  while now >= a:
    if B.el[now]:
      #print("shorisita",now)
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        #print((b+1),dic[b+1])
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0

    now = calc_prev_valid(now)

  #print(dic)
  #print(members)
  #print(prev_valid)
  #print(count_score)
  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()

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


Question:
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b
  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

H,W = IL()
data = ILL(H)

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)

for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

#print(calc_prev_valid(0))
#exit()

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b
  while now >= a:
    if B.el[now]:
      #print("shorisita",now)
      count_score[now-dic[now]] -= members[now]
      if not members[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        #print((b+1),dic[b+1])
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0

    now = calc_prev_valid(now)

  #print(dic)
  #print(members)
  #print(prev_valid)
  #print(count_score)
  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

H,W = IL()
data = ILL(H)

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)

for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return -1
  else:
    return B.bisect(s)

#print(calc_prev_valid(0))
#exit()

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  if i == 9998:
    exit()
  a,b = data[i]
  now = b
  while now >= a:
    if B.el[now]:
      #print("shorisita",now)
      count_score[now-dic[now]] -= members[now]
      if not members[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        #print((b+1),dic[b+1])
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0

    now = calc_prev_valid(now)

  #print(dic)
  #print(members)
  #print(prev_valid)
  #print(count_score)
  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for j in range(H-i):
        print(-1)
      exit()

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()

dp = [[0 for j in range(N)] for i in range(N)]
dpmax = 0
dpmaxk = [0 for i in range(N)]
dpmaxl = [0 for i in range(N)]
score = 0
a,b,c,d,e = sorted(A[:5])
a -= 1
b -= 1
c -= 1
d -= 1
e -= 1

if a == b == c:
  dp[d][e] = 1
  dp[e][d] = 1
elif b == c == d:
  dp[a][e] = 1
  dp[e][a] = 1
elif c == d == e:
  dp[a][b] = 1
  dp[b][a] = 1

for i in range(N-2):
  """
  dpd = [dp[k][k] for k in range(N)]
  a,b,c = A[i*3+5:i*3+8]
  a -= 1
  b -= 1
  c -= 1
  if a == b == c:
    score += 1
    continue
  elif a == b:
    for k in range(N):
      dp[k][c] = max(dp[k][a],dp[a][k]) + 1
      dpmax = max(dpmax,dp[k][c])
      dpmaxk[k] = max(dpmaxk[k],dp[k][c])
      dpmaxl[c] = max(dpmaxl[c],dp[k][c])
  elif a == c:
    for k in range(N):
      dp[k][b] = max(dp[k][a],dp[a][k]) + 1
      dpmax = max(dpmax,dp[k][b])
      dpmaxk[k] = max(dpmaxk[k],dp[k][b])
      dpmaxl[b] = max(dpmaxl[b],dp[k][b])
  elif b == c:
    for k in range(N):
      dp[k][a] = max(dp[k][b],dp[b][k]) + 1
      dpmax = max(dpmax,dp[k][a])
      dpmaxk[k] = max(dpmaxk[k],dp[k][a])
      dpmaxl[a] = max(dpmaxl[a],dp[k][a])

  dp[b][c] = dpd[a] + 1
  dp[a][c] = dpd[b] + 1
  dp[a][b] = dpd[c] + 1
  dpmax = max(dpmax,dp[b][c],dp[a][c],dp[a][b])
  dpmaxk[b] = max(dpmaxk[b],dp[b][c])
  dpmaxl[c] = max(dpmaxl[c],dp[b][c])
  dpmaxk[a] = max(dpmaxk[a],dp[a][c])
  dpmaxl[c] = max(dpmaxl[c],dp[a][c])
  dpmaxk[a] = max(dpmaxk[a],dp[a][b])
  dpmaxl[b] = max(dpmaxl[b],dp[a][b])
  dp[a][b] = dpmax
  dp[b][c] = dpmax
  dp[a][c] = dpmax
  for j in range(N):
    dp[j][a] = dpmaxk[j]
    dp[j][b] = dpmaxk[j]
    dp[j][c] = dpmaxk[j]
    dp[a][j] = dpmaxl[j]
    dp[b][j] = dpmaxl[j]
    dp[c][j] = dpmaxl[j]
 """

z = A[-1]-1
print(max(dpmax,dp[z][z]+1)+score)

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()

dp = [[0 for j in range(N)] for i in range(N)]
dpmax = 0
dpmaxk = [0 for i in range(N)]
dpmaxl = [0 for i in range(N)]
score = 0
a,b,c,d,e = sorted(A[:5])
a -= 1
b -= 1
c -= 1
d -= 1
e -= 1

if a == b == c:
  dp[d][e] = 1
  dp[e][d] = 1
elif b == c == d:
  dp[a][e] = 1
  dp[e][a] = 1
elif c == d == e:
  dp[a][b] = 1
  dp[b][a] = 1

for i in range(N-2):
  dpd = [dp[k][k] for k in range(N)]
  a,b,c = A[i*3+5:i*3+8]
  a -= 1
  b -= 1
  c -= 1
  if a == b == c:
    score += 1
    continue
  elif a == b:
    for k in range(N):
      dp[k][c] = max(dp[k][a],dp[a][k]) + 1
      dpmax = max(dpmax,dp[k][c])
      dpmaxk[k] = max(dpmaxk[k],dp[k][c])
      dpmaxl[c] = max(dpmaxl[c],dp[k][c])
  elif a == c:
    for k in range(N):
      dp[k][b] = max(dp[k][a],dp[a][k]) + 1
      dpmax = max(dpmax,dp[k][b])
      dpmaxk[k] = max(dpmaxk[k],dp[k][b])
      dpmaxl[b] = max(dpmaxl[b],dp[k][b])
  elif b == c:
    for k in range(N):
      dp[k][a] = max(dp[k][b],dp[b][k]) + 1
      dpmax = max(dpmax,dp[k][a])
      dpmaxk[k] = max(dpmaxk[k],dp[k][a])
      dpmaxl[a] = max(dpmaxl[a],dp[k][a])
  """
  dp[b][c] = dpd[a] + 1
  dp[a][c] = dpd[b] + 1
  dp[a][b] = dpd[c] + 1
  dpmax = max(dpmax,dp[b][c],dp[a][c],dp[a][b])
  dpmaxk[b] = max(dpmaxk[b],dp[b][c])
  dpmaxl[c] = max(dpmaxl[c],dp[b][c])
  dpmaxk[a] = max(dpmaxk[a],dp[a][c])
  dpmaxl[c] = max(dpmaxl[c],dp[a][c])
  dpmaxk[a] = max(dpmaxk[a],dp[a][b])
  dpmaxl[b] = max(dpmaxl[b],dp[a][b])
  dp[a][b] = dpmax
  dp[b][c] = dpmax
  dp[a][c] = dpmax
  for j in range(N):
    dp[j][a] = dpmaxk[j]
    dp[j][b] = dpmaxk[j]
    dp[j][c] = dpmaxk[j]
    dp[a][j] = dpmaxl[j]
    dp[b][j] = dpmaxl[j]
    dp[c][j] = dpmaxl[j]
 """

z = A[-1]-1
print(max(dpmax,dp[z][z]+1)+score)

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

N = int(input())

@lru_cache(maxsize=None)
def count(n,a,b):
  counter = 0
  for i in range(1,n+1):
    if int(str(i)[0])==a and int(str(i)[-1])==b:
      counter += 1
  return counter

ans = 0
for i in range(10):
  for j in range(10):
    ans += count(N,i,j)*count(N,j,i)

print(ans)

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

N = int(input())

def count(n,a,b):
  counter = 0
  for i in range(1,n+1):
    if int(str(i)[0])==a and int(str(i)[-1])==b:
      counter += 1
  return counter

ans = 0
for i in range(10):
  for j in range(10):
    ans += count(N,i,j)*count(N,j,i)

print(ans)

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
C = inputIL()

C.sort()

MAX = (N+1)*pow(2,N-2,MOD)
MIN = pow(2,N-1,MOD)

if N>1:
  d = inv(N-1) * (MAX-MIN) % MOD
else:
  d = 0

ans = 0
for i in range(N):
  ans = (ans + (C[N-1-i] * (MIN+d*i)) % MOD ) % MOD

ans = (ans * pow(2,N,MOD)) % MOD

print(ans)

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


Question:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

T,X = inputIL()
pirnt(T/X)

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


Question:
S = input()
l = len(S)
num = 0
for i in range(n):
  if S[i] == '+':
    num = num +1
  else :
    num = num -1
print(num)

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


Question:
n,k =int(x) for x in input().split()
s = list(int(y) for y in input().split())
def min(a):
  min = 1000000
  for i in range(len(a)):
    if min > a[i]:
      min = a[i]
      index = i
  return index
c = min(s)
num = (c-1)//k + (len(s)-c)//k +2
print(num)

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


Question:
N=int(input())
xy=[tuple(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        ans=max(ans,abs(xy[i][0]-xy[j][0])+abs(xy[i][1]-xy[j][1]))
print(ans)

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


Question:
s = input()
t = s[0]
p = 1
i = 1
while i < len(s):
    if s[i] == t:
        i += 2
    else:
        i += 1
    t = s[i-1]
    p += 1

print(p)

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


Question:
n = int(input())
p = list(map(int,input().split()))
c = 0

for i in range(1,n - 1):
    if p[n - 1] < p[n] and p[n] < p[n + 1]:
        c = c + 1

print(c)

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


Question:
r,d,x = map(int,input().split())
p = []
for i in range(10):
    x = r * x - d
    p[i] = x

for i in range(10):
    print(p[i])

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


Question:
n = int(input())
i = n
m = 0
while i > 0
    m += i % 10
    i = i // 10

if n % m != 0:
    print('No')
else:
    print('Yes')

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


Question:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not j in s:
            s.append(j)
            break
    print(''.join(s))
else:
    if s == m:
        print(-1)
    else:
        x = s[-1]
        for i in range(25)[::-1]:
            if x > s[i]:
                s = s[:i]
                s.append(x)
                break
            if i == 0:
                z = m.index(s[0])
                s = m[z-1]
                break
        print(''.join(s))

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


Question:
n = int(input())
s = list(input().split())
s = set(s)
print(s)
if len(s) == 3:
    print('Three')
else:
    print('Four')

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


Question:
n = int(input())
s = [input().split]
if len(set(s)) == 3:
    print('Three')
else:
    print('Four')

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


Question:
n = int(input())
m = n // 100
if m == n[-1]:
    print('Yes')
else:
    print('No')

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


Question:
s = list(input())
n = s.count('N')
w = s.count('W')
s = s.count('S')
e = s.count('E')
if (n + s) % 2 == 0 and (w + e) % 2 == 0:
    print('Yes')
else:
    print('No')

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


Question:
s = input()
we = [0,0]
ns = [0,0]

for i in range(len(s)):
    if s[i] == ('N'):
        ns[0] == 1
    elif s[i] == ('W'):
        we[0] == 1
    elif s[i] == ('S'):
        ns[1] == 1
    else
        we[1] == 1

if sum(we) % 2 == 0 and sum(ns) % 2 == 0:
    print('Yes')
else:
    print('No')

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


Question:
p=input()
if p[len(p)-1]=='s':
  p.append('es')
  print(p)
else:
  p.append('s')
  print(p)

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


Question:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)
	return ret

print(dfs('0'))

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


Question:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)

print(dfs('0'))

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


Question:
s=input()
ans=0
for i in range(4):
  if s[i]='+':
    ans += 1
  else:
    ans -= 1
print(ans)

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


Question:
s=list(map(int,input()))
for i in range(10):
  s[2]=s[0]*s[2]-s[1]
  print(s[2])

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


Question: print(input().count("+")-input().count("-"))

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


Question:
import numpy as np
n=int(input())
d=[0]*101
def factorization(n):
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i==0:
            while temp%i==0:
                d[i]+=1
                temp //= i
    if temp!=1:
        d[temp]+=1
def cnt(k):
    return len(d[d>=k])
for i in range(2,n+1):
    factorization(i)
d=np.array(list(d.values()))
print(cnt(74)+cnt(24)*(cnt(2)-1)+cnt(14)*(cnt(4)-1)+cnt(4)*(cnt(4)-1)*(cnt(2)-2)//2)

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


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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')

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


Question:
n=int(input())
mod=10**9+7
if n==3:
    print(61)
    exit()
zt=['A','G','C','T']
for i in range(3):
    tmp=[]
    for j in zt:
        for k in list('AGCT'):
            tmp.append(j+k)
    zt=tmp
ng=set([])
for i in list('AGCT'):
    ng.add('AGC'+i)
    ng.add('AG'+i+'C')
    ng.add('A'+i+'GC')
    ng.add(i+'AGC')
    ng.add('ACG'+i)
    ng.add('GAC'+i)
    ng.add(i+'ACG')
    ng.add(i+'GAC')
z=set([])
for j in zt:
    if not j in ng:
        z.add(j)
zn=len(z)
dp=[[0 for j in range(zn)] for i in range(n-3)]
for i in range(zn):
   # if not z[i] in ng:
    dp[0][i]=1
for i in range(n-4):
    for j in range(zn):
        for k in range(zn):
            #if not z[k] in ng:
            if z[j][1:]==z[k][:3]:
                dp[i+1][k]+=dp[i][j]
                dp[i+1][k]%=mod
print(sum(dp[-1])%mod)

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


Question:
n=int(input())
mod=10**9+7
if n==3:
    print(61)
if n==4:
    print(230)
l=['A','C','G','T']
dic3=dict(AGC=1,ACG=1,GAC=1)
dic4=dict(AGTC=1,AGGC=1,ATGC=1)
ans=0
z=[]
for a in range(4):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                f=0
                s=""
                s+=l[a]
                s+=l[b]
                s+=l[c]
                s+=l[d]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f==0:
                    ans+=1
                    z+=[s]
n=n-4

if n>0:
    for i in range(n):
        ans%=mod
        ans*=4
        ans%=mod
        for j in range(len(z)):
            z=[]
            for k in range(4):
                f=0
                s=z[j][1:4]+l[k]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f>0:
                    ans-=1
                    z+=[s]
    print(ans%mod)

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


Question:
n=int(input())
mod=10**9+7
if n==3:
    print(61)
if n==4:
    print(230)
l=['A','C','G','T']
dic3=dict(AGC=1,ACG=1,GAC=1)
dic4=dict(AGTC=1,AGGC=1,ATGC=1)
ans=0
z=[]
for a in range(4):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                f=0
                s=""
                s+=l[a]
                s+=l[b]
                s+=l[c]
                s+=l[d]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f==0:
                    ans+=1
                    z+=[s]
n=n-4

if n>0:
    for i in range(n):
        ans*=4
        ans%=mod
        for j in range(len(z)):
            for k in range(4):
                f=0
                s=z[1:4]+l[k]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f>0:
                    ans-=1
    print(ans%mod)

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


Question:
n=int(input())
if n==3:
    print(61)
if n==4:
    print(230)
l=['A','C','G','T']
dic3=dict(AGC=1,ACG=1,GAC=1)
dic4=dict(AGTC=1,AGGC=1,ATGC=1)
ans=0
z=[]
for a in range(4):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                f=0
                s=""
                s+=l[a]
                s+=l[b]
                s+=l[c]
                s+=l[d]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f==0:
                    ans+=1
                    z+=[s]
n=n-4

if n>0:
    for i in range(n):
        ans*=4
        for j in range(len(z)):
            for k in range(4):
                f=0
                s=z[1:4]+l[k]
                if s[0:3] in dic3:
                    f+=1
                if s[1:4] in dic3:
                    f+=1
                if s in dic4:
                    f+=1
                if f>0:
                    ans-=1
    print(ans)

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


Question:
n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(10):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp

ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)

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


Question:
n=int(input())
s=list(str(n))
sn=0
for i range(len(s)):
    sn+=int(s[i])
if sn%n==0:
    print('Yes')
else:
    print('No')

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


Question:
n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
print(ans)

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


Question:
h,w=map(int,input())
r=[]
for i in range(h):
    r.append(list(input()))
t=[]
for i in range(h):
    for j in range(w):
        if r[i][j]=='#':
            t.append([i,j])
op=[[[0,0]]]
for i in range(h+w-2):
    tmp=[]
    for j in op:
        tmp.append(j+[[j[-1][0]+1,j[-1][1]]])
        tmp.append(j+[[j[-1][0],j[-1][1]+1]])
    op=tmp
for i in op:
    if sorted(i)==sorted(t):
        print('Possible')
        exit()
print('Impossible')

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


Question:
n=int(input())
co=int(0)
for i in range(n):
    now=int(input())
    if now%2==1:
        co+=1
if co%2==1:
    print("NO")
else:
    print("YES")

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


Question:
a=input()
b=0
for i in range(4)
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)

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


Question:
a=input()
b=0
for i while(4)
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)

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


Question:
n=input()
a=len(n)
p=0
m=0
while True:
    m+=int(n[p])
    p+=1
    if m==a:
        break
if int(n)%m==0:
    print('Yes')
else:
    print('No')

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


Question:
import math
A, B = map(int, input().split())
tmpa = math.floor(A / 0.08)
tmpb = math.floor(B / 0.1)
alst = []
blst = []

indexa = 0
while True:
    tmp = math.floor((tmpa + indexa) * 0.08)
    if tmp == A:
        alst.append(tmpa + indexa)
        indexa += 1
    elif tmp > A:
        break
    else:
        indexa += 1

indexb = 1
while True:
    tmp = math.floor((tmpb + indexb) * 0.1)
    if tmp == B:
        blst.append(tmpb + indexb)
        indexb += 1
    elif tmp == B:
        break
    else:
        indexb += 1
ans = -1
alst.sort()
blst.sort()
for i in alst:
    if blst.count(i) >= 1:
        ans = i
        break

print(ans)

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


Question:
S = input()
if int(S[2:]) >= 1 and int(S[2:]) <= 12:
    if int(S[:2]) <= 12 and int(S[:2]) >= 1:
        print('AMBIGUOUS')
    else:
        print('YYMM')
elif int(S[2:]) >= 13:
    if int(S[:2]) >= 1 and int(S[:2]) <= 12:
        print('MMYY')
    else:
        print('NA')
elif int(S[2:]) == 0:
    if int(S[:2]) >= 1 and int(S[:2] <= 12):
        print('MMYY')
    else:
        print('NA')
else:
    print('NA')

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


Question:
# 解説放送を見た
# https://youtu.be/9MphwmIsO7Q?t=5738

def main():
    mod = 10 ** 9 + 7

    n = int(input())
    *c, = map(int, input().split())

    c.sort()

    pw = [1 << j for j in range(n + 1)]

    ret = 0
    for l, x in enumerate(c):
        r = n - 1 - l  # lxr
        ret = (ret + x * pw[l] * (pw[r] + pw[r - 1] * r)) % mod

    ret = ret * pw[n] % mod

    print(ret)

if __name__ == '__main__':
    main()

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


Question:
def solve(N, LRs):
    from operator import itemgetter
    L = 0
    R = 1
    IND = 2

    LRs.sort(key=itemgetter(L))  # L昇順ソート
    LRs = tuple(LR + (ind,) for ind, LR in enumerate(LRs))

    min_r = min(LRs, key=itemgetter(R))  # R最小の区間 == 右端が一番左の区間
    max_l = max(LRs, key=itemgetter(L))  # L最大の区間 == 左端が一番右の区間

    ans = 0
    if min_r[IND] == max_l[IND]:
        # L最大とR最小の問題が一致する場合
        fixed = max(0, min_r[R] - max_l[L] + 1)
        max_ = max(0, max(x[R] - x[L] + 1 for x in LRs if x[IND] != max_l[IND]))
        ans = max(ans, fixed + max_)
    else:
        # L最大とR最小の問題が異なる場合

        # 両方の問題を同日実施する場合
        fixed = max(0, min_r[R] - max_l[L] + 1)
        max_ = max(0, max(x[R] - x[L] + 1 for x in LRs if x[IND] != max_l[IND]))
        ans = max(ans, fixed + max_)

        # 別日に実施する場合
        for x in LRs:
            # min_rと同日に実施する問題で、L最大の問題x
            if x[IND] == max_l[IND]:
                continue
            fixed = max(0, min_r[R] - x[L] + 1)
            r_ = min(LRs[j][R] for j in range(x[IND] + 1, N) if j != min_r[IND])
            # ここでTLEになるはず
            opp = max(0, r_ - max_l[L] + 1)
            ans = max(ans, fixed + opp)

    return ans

if __name__ == '__main__':
    N = int(input())
    LRs = [tuple(map(int, input().split())) for _ in range(N)]
    print(solve(N, LRs))

# 残った区間
# <-->, <--->
# <>は、いずれかの区間の左右端なので、n通り**4ある
# 右端が一番左にあるような区間に注目すると
# どの区間と組み合わせても、右端は変わらない（emptyになることはある）
# 右端が一番左 / 左端が一番右 に注目する

# 例外 == 両者一致 == 含まれるケース
# <----->
#  <--->
#   <->    ... この区間を含むとこの区間だけになるので、最長区間とそれ以外(これを含む）に分ける

# 右端が一番左 / 左端が一番右 を同じ区間に入れる場合と違う区間に入れる場合に分ける
# 同じ区間に入れる場合は、例外同様、最長区間とその他に分ける

# 右端が一番左 / 左端が一番右 を別日に実施する場合、
# x---o (右端は固定）
# xに決めたとき、 o---y yを最長になるようにしたい
# x---o (右端は固定）
# <---            xより左に左端があるもの : 別グループ（左端が一番右の区間以下確定）に入れると、
#                                     区間長維持または減少なので、x----oと同じグループに入れて、別グループの長さを維持したい
#       <---     oより右に左端があるもの : 別グループに入れないとx---o区間を取るという決め方に反する

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


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

# int(input())
# map(int, input().split())

# 2回のコンテストに問題を分ける、一回だけ出題
# すべての問題を解く参加者の人数の和を最大化

from time import perf_counter

def solve(n, e, time_counter):
    from operator import itemgetter
    e.sort(key=itemgetter(2, 0))
    # print(e)

    ans = 0

    min_ = set()
    for j in range(n):
        if e[j][2] == e[0][2]:
            min_.add(j)
        else:
            break

    max_ = set()
    for j in range(n - 1, -1, -1):
        if e[j][2] == e[-1][2]:
            max_.add(j)
        else:
            break

    for mx in max_:
        for mn in min_:
            if mx == mn:
                continue
            if perf_counter() - time_counter == 1.8:
                print(ans)
                exit()

            ll, lr, area_l = e[mx]  # 最大
            rl, rr, area_r = e[mn]  # 最小

            for i in range(n):
                if i in (mx, mn):
                    continue
                l, r, _ = e[i]

                sr = max(0, (rr - rl + 1))
                mr = max(0, (min(rr, r) - max(rl, l) + 1))
                diff_r = sr - mr

                sl = max(0, (lr - ll + 1))
                ml = max(0, (min(lr, r) - max(ll, l) + 1))
                diff_l = sl - ml

                if diff_r < diff_l:
                    rl = max(rl, l)
                    rr = min(rr, r)
                else:
                    ll = max(ll, l)
                    lr = min(lr, r)

            ans = max(ans, max(0, (lr - ll + 1)) + max(0, (rr - rl + 1)))
    print(ans)

if __name__ == '__main__':
    import sys

    time_counter = perf_counter()

    input = sys.stdin.readline
    n = int(input().rstrip())
    e = []
    for _ in range(n):
        lr = tuple(int(x) - 1 for x in input().rstrip().split())
        lr = lr + (lr[1] - lr[0] + 1,)
        e.append(lr)
    solve(n, e, time_counter)

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


Question:
def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    s = input()

    @lru_cache(maxsize=None)
    def cut(cur, t):
        if cur >= len(s):
            return 0

        ret = -1 << 30
        if t != s[cur]:
            ret = max(ret, cut(cur + 1, s[cur]) + 1)
        if t != s[cur:cur + 2]:
            ret = max(ret, cut(cur + 2, s[cur:cur + 2]) + 1)
        return ret

    ans = cut(0, '')

    print(ans)

if __name__ == '__main__':
    main()

# 一文字か二文字

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


Question:
import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
sr -= 1
sc -= 1

s = input()
t = input()

d = {
    'L': (0, -1),
    'R': (0, 1),
    'U': (-1, 0),
    'D': (1, 0)
}

memo = dict()

def next_move_pos(cur_r, cur_c, cur_step_index, bl_is_takahashi):
    if bl_is_takahashi:
        c = s[cur_step_index]
    else:
        c = t[cur_step_index]
    dr, dc = d[c]
    return cur_r + dr, cur_c + dc

def is_in_range(r, c):
    return 0 <= r < H and 0 <= c < W

def rec(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi):
    if memo.get((cur_r, cur_c, cur_step_index, bl_cur_player_takahashi), None):
        return memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)]

    if bl_cur_player_takahashi:
        nr, nc = next_move_pos(cur_r, cur_c, cur_step_index, True)
        if not is_in_range(nr, nc):
            memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = True
            return True
        if rec(nr, nc, cur_step_index, not bl_cur_player_takahashi):
            memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = True
            return True
        if rec(cur_r, cur_c, cur_step_index, not bl_cur_player_takahashi):
            memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = True
            return True
    else:
        if cur_step_index == N - 1:
            memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = False
            return False
        for nr, nc in (cur_r, cur_c), next_move_pos(cur_r, cur_c, cur_step_index, False):
            if not is_in_range(nr, nc): continue
            nnr, nnc = next_move_pos(nr, nc, cur_step_index + 1, True)
            if not is_in_range(nnr, nnc): continue
            if not rec(nr, nc, cur_step_index + 1, not bl_cur_player_takahashi):
                memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = False
                return False
            if not rec(cur_r, cur_c, cur_step_index + 1, not bl_cur_player_takahashi):
                memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = False
                return False
        memo[(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi)] = True
        return True

print('NO' if rec(sr, sc, 0, True) else 'YES')

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


Question:
import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
sr -= 1
sc -= 1

s = input()
t = input()

d = {
    'L': (0, -1),
    'R': (0, 1),
    'U': (-1, 0),
    'D': (1, 0)
}

def next_move_pos(cur_r, cur_c, cur_step_index, bl_is_takahashi):
    if bl_is_takahashi:
        c = s[cur_step_index]
    else:
        c = t[cur_step_index]
    dr, dc = d[c]
    return cur_r + dr, cur_c + dc

def is_in_range(r, c):
    return 0 <= r < H and 0 <= c < W

def rec(cur_r, cur_c, cur_step_index, bl_cur_player_takahashi):
    if bl_cur_player_takahashi:
        nr, nc = next_move_pos(cur_r, cur_c, cur_step_index, True)
        if not is_in_range(nr, nc):
            return True
        if rec(nr, nc, cur_step_index, not bl_cur_player_takahashi):
            return True
        if rec(cur_r, cur_c, cur_step_index, not bl_cur_player_takahashi):
            return True
    else:
        if cur_step_index == N - 1:
            return False
        for nr, nc in (cur_r, cur_c), next_move_pos(cur_r, cur_c, cur_step_index, False):
            if not is_in_range(nr, nc): continue
            nnr, nnc = next_move_pos(nr, nc, cur_step_index + 1, True)
            if not is_in_range(nnr, nnc): continue
            if not rec(nr, nc, cur_step_index + 1, not bl_cur_player_takahashi):
                return False
            if not rec(cur_r, cur_c, cur_step_index + 1, not bl_cur_player_takahashi):
                return False
        return True

print('NO' if rec(sr, sc, 0, True) else 'YES')

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


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

g = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1  # 1-indexed -> 0-indexed
    g[a].add(b)  # edge
    g[b].add(a)

q = [True for _ in range(n)]
left = n
i = 0
cnt_ok = 0
while left > 0:
    fa, fb = False, False
    for j in g[i]:
        if s[j] == 'A':
            fa = True
        elif s[j] == 'B':
            fb = True
        if fa and fb:
            break
    if fa and fb:
        cnt_ok += 1
        if cnt_ok == left:
            break
    else:
        s[j] = 'X'  # 除外された頂点
        q[i] = False
        left -= 1
        cnt_ok = 0
    i += 1
    if i == n:
        i = 0

print('Yes' if left > 0 else 'No')

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


Question:
# 解説
# https://img.atcoder.jp/agc018/editorial.pdf

def solve():
    import sys

    sys.setrecursionlimit(10 ** 7)

    def simulate(use: set):
        if not use:
            return n
        cnt = [0] * m
        for player in a:
            for sport in player:
                if sport in use:
                    cnt[sport] += 1
                    break
        max_ = max(cnt)
        ret = max_
        for j, c in enumerate(cnt):
            if c == max_:
                ret = min(ret, simulate(use - {j}))
        return ret

    n, m = map(int, input().split())
    a = [tuple(int(x) - 1 for x in input().split()) for _ in range(n)]
    use = set(range(m))
    return simulate(use)

print(solve())

# まず、すべてのスポーツを実施すると仮定して、どのスポーツに何人の人が参加するか調べます。
# ここで、最も参加人数の多いスポーツがスポーツ P で、その参加人数が Q 人だとします。
# 当り前ですが、この段階で、参加人数の最大値が Q の解が得られています。
# よって、あと考えるべきは、参加人数の最大値が Q 未満の解です。
# そして、そのような解において、スポーツ P は必ず実施されません。
# なので、Q 未満の解を求めるには、スポーツ P を候補から外した上で、
# もう一度同じ問題を解きなおせばよいです。
# これを再帰的に行っていけば、最終的な解を求めることができます。
# 再帰するごとに候補の数が減るので、再帰は合計 M 回呼ばれます。
# 誰がどのスポーツを選ぶのか愚直にシミュレーションすると O(NM) かかるので、
# 全体で O(NM2) でこの問題は解けました。
# なお、シミュレーションを工夫すると、全体で O(NM) でこの問題を解くこともできます。

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


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

cnt = 0
t = x
while True:
    if t * y > 0:
        if t > 0:
            if t < y:
                t += 1
                cnt += 1
            elif y < t:
                t *= (-1)
                cnt += 1
        elif t < 0:
            if abs(t) <= abs(y):
                t *= (-1)
                cnt += 1
            elif abs(t) > abs(y):
                t += 1
                cnt += 1
    elif t * y < 0:
        if t > 0:
            if abs(t) >= abs(y):
                t *= (-1)
                cnt += 1
            elif abs(t) < abs(y):
                t += 1
                cnt += 1
        elif t < 0:
            if abs(t) <= abs(y):
                t *= (-1)
                cnt += 1
            elif abs(t) > abs(y):
                t += 1
                cnt += 1
    else:
        #t * y == 0
        if t == 0:
            if t < y:
                t += 1
                cnt += 1
            elif y < t:
                t += 1
                cnt += 1
        elif y == 0:
            if t < y:
                t += 1
                cnt += 1
            elif y < t:
                t *= (-1)
                cnt += 1
    if t == y:
        break
print(cnt)

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


Question:
s = raw_input()
if(s[-1] == 's'):
    s += 'es'
else:
    s += 's'
print(s)

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


Question:
N=int(input())

step = sum([90*100**i for i in range(len(str(N))//2)])
dance_floor = sum([9*100**i for i in range(len(str(N))//2)])

ans = len(str(N))%2 * (N-step)  +  -1*(len(str(N))%2-1) * dance_floor
print(ans)

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


Question:
T,X=map(int,input())
print(float(T/X))

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


Question:
s=input()
if s==ABC:
  print('ARC')

elif s==ARC:
  print('ABC')

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


Question:
x=int(input())
i=x//500
a=(x-i)//5
sum=i*1000+a*5
print sum

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


Question:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(ave(a+b))

else:
  print('IMPOSSIBLE')

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


Question:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(ave(a+b))

else:
  print('impossible')

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


Question:
r,d,x=map(int,input().split())
for i in range(10)
  x=r*x-d
  print(x)

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


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

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


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

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


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

cnt=0
for i in a:
  if i%2=1:
    cnt+=1

if cnt%2==1:
  print('NO')

else:
  print('YES')

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


Question:
n=int(input())
a=list(map(int,input().split()))
a=[i if i%2==1 else None  for i in a]
if a.count()%2==1:
  print('NO')
else:
  print('YES')

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


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

ans=abs(abs(x)-abs(y))

if y<x<0 or 0<y<x:
    ans+=2

elif y<x x<0<y:
    ans+=1

print(ans)

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


Question:
def main():
    N = int(input())
    A = []
    B = []
    b_max = 0
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
        if b_max < b:
            b_max = b
    tasks = [0] * (b_max + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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


Question:
def main():
    N = int(input())
    A = []
    B = []
    b_max = 0
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
        if b_max < b:
            b_max = b
    tasks = [0] * (b_max + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0 or task == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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


Question:
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
    tasks = [0] * (max(B) + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0 or task == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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


Question:
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
    tasks = [[0] for _ in range(max(B) + 1)]
    for i in range(N):
        tasks[B[i]].append(A[i])
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0:
            continue
        time += sum(task)
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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


Question:
def main():
    word = input()
    count = {}
    for w in word:
        if w in count:
            count[w] += 1
        else:
            count[w] = 1
    count = sorted(count.items(), key=lambda x: x[1])
    target_list = []
    if count[-1][1] == 1:
        target_list.append(word[len(word) // 2])
    else:
        for i in range(-1, -len(word) - 1, -1):
            if count[i][1] == count[-1][1]:
                target_list.append(count[i][0])
            else:
                break
    answer = float("inf")
    for target in target_list:
        now_ans = 0
        now_word = word
        while len(set(now_word)) > 1:
            tmp = ""
            for i in range(len(now_word) - 1):
                if now_word[i] == target or now_word[i + 1] == target:
                    tmp += target
                else:
                    tmp += now_word[i]
            now_word = tmp
            now_ans += 1
        answer = min(answer, now_ans)
    print(answer)

if __name__ == '__main__':
    main()

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


Question:
s=input()
if s[1]=='B':
  s[1]='R'
else:
  s[1]='B'
print(s)

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