Question:
N = int(input())
ret = 0
a = ['3','5','7']
for i in range(357, N+1):
    t = list(set(str(i)))
    t.sort()
    if t == a:
        ret += 1
print(ret)

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


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


Question:
N = int(input())
S = []
for i in range(N):
    s = input()
    if s[0] in [ 'M','A','R','C','H' ]:
        S.append(s)

S = list(set(S))

N = len(S)
selected = [""] * 2
cnt = 0
for i in range(N):
    selected[0] = S[i][0]
    for k in range(i+1, N):
        if selected[0] == S[k][0]:
            continue
        selected[1] = S[k][0]
        for t in range(k+1, N):
            if selected[1] == S[t][0]:
                continue
            cnt += 1
print(cnt)

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


Question:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) > 2:
        r = mid
    else:
        l = mid
maxcnt = l

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) < 2:
        l = mid
    else:
        r = mid
mincnt = r

if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

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


Question:
if (n = input().split())[0] == n[2] : print('Yes')
else : print('No')

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


Question:
a, b, c, d = map(int, input().split())
row = [0 for i in range(101)]
for i in range(a, b+1) : row[i] += 1
for i in range(c, d+1) : row[i] += 1
if row.count(2) == 0 : print(0)
else : print(raw.count(2)-1)

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


Question:
a, b, c, d = map(int, input().split())
row = [i for i in range(101)]
row[a-1:b] += 1
row[c-1:d] += 1
print(row.count(0))

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


Question:
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')

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


Question:
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = TRUE
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')

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


Question:
def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    x = [i for i in range(a[-1])]
    ans = a[-1]
    for i in range(1,n):
        if len(x)==0:
            x = [i for i in range(a[-1-i])]
        e = x.pop(-1)
        if e>a[-1-i]:
            print(-1)
            return
        elif e<a[-1-i]:
            x = [i for i in range(a[-1-i])]
            ans += a[-1-i]
    if len(x)==0:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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


Question:
a=input()

s=['x','SAT','FRY','THU','WED','TUE','MON','SUN']

print(s.index(a))

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


Question:
n,m=map(int, input().split())
s=list(input())
count=0
x=0
y=0
s=['R']+s+['L']

for i in range(1,n+1):
    if s[i]=='L':
        if s[i-1]==s[i]:
            count+=1
    else:
        if s[i]==s[i+1]:
            count+=1

for i in range(1,n+1):
    if s[1]=='L':
        if s[i-1]=='R' and s[i]=='L':
            if i==1:
                x+=1
            else:
                y+=1

    else:
        if s[i]=='R' and s[i+1]=='L':
            if i==n:
                x+=1
            else:
                y+=1
if m<y:
    print(count+2*m)
elif m==y:
    print(count+y*2-1)
else:
    print(count+y*2-1+x)

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


Question:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

e = round(c * d / gcd(c, d))

f=(a-1)//c
g=b//c
h=(a-1)//d
k=b//d
l=(a-1)//e
m=b//e

x=(b-a+1)
y=g-f
z=k-h
w=m-l
print(f,g,h,k,l,m)
print(x-y-z+w)

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


Question:
n,a,b,c,d=map(int, input().split())
s=input()
v=0
x=0
for i in range(n-2):
    if c<d:
        if i>b and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
        elif c>d:
        if  i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.' :
            x=1
            break
if x==0 and c>d:
    print('No')
if x==1:
    for i in range(n-2):
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
    if v==0 and x==1:
        print('Yes')
if c<d and v==0:
    print('Yes')

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


Question:
n,a,b,c,d=map(int, input().split())
s=input()
v=0
x=0
for i in range(n-2):
    if c<d:
        if i>b and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break

    elif c>d:
        if  i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.' :
            x=1
            break
if x==0:
    print('No')

if x==1:
    for i in range(n-2):
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
    if v==0:
        print('Yes')
if c<d and v==0:
    print('Yes')
n,a,b,c,d=map(int, input().split())
s=input()
v=0
x=0
for i in range(n-2):
    if c<d:
        if i>b and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break

    elif c>d:
        if  i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.' :
            x=1
            break
if x==0 and c>d:
    print('No')

if x==1:
    for i in range(n-2):
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
    if v==0 and x==1:
        print('Yes')
if c<d and v==0:
    print('Yes')

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


Question:
n,a,b,c,d=map(int, input().split())
s=input()
v=0
x=0
for i in range(n-2):
    if c<d:
        if i>b and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break

    elif c>d:
        if  i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.' :
            x=1
            break
if c>d and x==0:
    print('No')

if x==1:
    for i in range(n-2):
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
    if v==0:

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


Question:
n,a,b,c,d=map(int, input().split())
s=input()
v=0
for i in range(n-2):
    if c<d:
        if i>a and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break

    elif c>d:
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            v+=1
            print('No')
            break

if c<d and v==0:
    print('Yes')

if v==0 and c>d and i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.':
    print('Yes')
        break
if V==0:
    print('No')

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


Question:
s=int(input())
a=(s-s%1000)-(s%1000-s%100)
b=s%100
if a<=1200 and b<=12:
  print('AMBIGUOUS')
elif a<=1200 and b>12:
  print('MMYY')
elif a>12 and b<=12:
  print('YYMM')
elif a>12 and B>12:
  print('NA')

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


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

m = a[0]
k = b[0]
for i in range(n):
    if a[i] >b[i] :
        ans = a[i]-b[i]
print(ans)

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


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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())

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

ans = 0

for bit in range(1 << N):
    sum = 0
    for i in range(N):
        if bit & (1 << i):
            sum += V[i]
            sum -= C[i]
    ans = max(ans, sum)

print(ans)

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


Question:
s = input()
print('Yes' if s[2]==s[3] && s[4]==s[5] else 'No')

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


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

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


Question:
s = str(input())
ans=0
for in range s:
    if '+' Then:
        ans += 1
    else:
        ans -= 1

print(ans)

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


Question:
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ch=[]
for i in range(n):
    ch.append((a[i],i))
ch.sort(reverse=True)
#print(ch)
dp=[[0]*(n+1) for _ in range(n+1)]
dp[1][1]=ch[0][0]*ch[0][1]
dp[1][0]=ch[0][0]*(n-1-ch[0][1])
for i in range(2,n+1):
    for j in range(i+1):
        if j>=1:
            dp[i][j]=max(dp[i][j],dp[i-1][j-1]+ch[i-1][0]*abs(ch[i-1][1]-j+1))
        if i-1>=j:
            dp[i][j]=max(dp[i][j],dp[i-1][j]+ch[i-1][0]*abs(n-i+j-ch[i-1][1]))
print(max(dp[n]))

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


Question:
n=int(input())
a=list(map(int,input().split()))
ch=[]
for i in range(n):
    ch.append((a[i],i))
ch.sort(reverse=True)
#print(ch)
dp=[[0]*(n+1) for _ in range(n+1)]
dp[1][1]=ch[0][0]*ch[0][1]
dp[1][0]=ch[0][0]*(n-1-ch[0][1])
for i in range(2,n+1):
    for j in range(i+1):
        if j>=1:
            dp[i][j]=max(dp[i][j],dp[i-1][j-1]+ch[i-1][0]*abs(ch[i-1][1]-j+1))
        if i-1>=j:
            dp[i][j]=max(dp[i][j],dp[i-1][j]+ch[i-1][0]*abs(n-i+j-ch[i-1][1]))
print(max(dp[n]))

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


Question:
a,b,x=map(int,input().split())
cnt=0
for i in range(1,11):
  if x-i*b>=0 and (x-i*b)//a>=10**(i-1):
    cnt+=1
if cnt==0 or x-i*b<0:
  print(0)
else:
  print(((x-cnt*b)-(x-cnt*b)%a)//a)

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


Question:
s=input()
n=len(s)+1
l=[0]*n
r=[0]*n
for i in range(n-1):
    if S[i]=='<':
      l[i+1]=l[i]+1
    if S[n-2-i]=='>':
      r[n-2-i]=r[n-1-i]+1
ans=0
for i in range(N):
  ans+=max(l[i],r[i])
print(ans)

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


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

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


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

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


Question:
a,b=map(int,input().split())
if (a+b)%==0:
  print((a+b)//2)
else:
  print('IMPOSSIBLE')

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


Question:
s=input()
sf=int(s[:2])
sl=int(s[2:4])
if sf>=13 or sl<=12 and sl>0:
  print('YYMM')
elif 12>=sf>0 and sl==0:
  print('MMYY')
elif sf>12 and sl=0 or sf=0 and sl>12:
  print('AMBIGUOUS')
else:
  print('NA')

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


Question:
n=int(input())
div=[0]*(n+1)
for i in range(1,n+1):
  k=i
  for j in range(1,int(i**0.5)+1):
    cnt=0
    while k%(j+1)==0:
      k//=(j+1)
      cnt+=1
    div[j+1]+=cnt
  if k>1:
    div[k]+=1
ans=0
d=dict()
for i,j,k in [[4,4,2],[24,2,1000],[14,4,1000],[74,1000,1000]]:
  cnti,cntj,cntk=0,0,0
  for l in range(2,n+1):
    if j==1000 and k==1000:
      if div[l]>=i:
        ans+=1
    for m in range(2,n+1):
      if l!=m and j!=1000 and k==1000:
        if div[l]>=i and div[m]>=j:
            ans+=1
      for o in range(2,n+1):
        if (m,l) not in d:
          if l!=o and l!=m and m!=o:
            if i!=1000 and j!=1000 and k!=1000:
              if div[l]>=i and div[m]>=j and div[o]>=k:
                ans+=1
                d[(l,m)]=0
print(ans)

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


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

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


Question:
a,b,c,d=map(int,input().split())
X=a*c
for i in range(a,b+1) :
  for j in range(c,d+1) :
    X=max(X,i*j)
print(X)

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


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

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


Question:
N=int(input())
a=list(map(int,input().split()))
a.sort()
for i in(1,N):
	a[0]=(a[0]+a[i])/2
print(a[0])

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


Question:
N=int(input())
a=list(map(int,input().split()))
for i in range(0,N):
	a.sort()
	x,y=map(int,a.pop())
	a.append((x+y)/2)

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


Question:
import numpy

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i + 1, n):
        a = numpy.array(x[i])
        b = numpy.array(x[j])
        num=numpy.linalg.norm(a-b)
        if num.is_integer() == True:
            cnt += 1
print(cnt)

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


Question:
import cython

n = int(input())
h = list(map(int, input().split())) + [0]

ans,cnt = 0, sum(h)
while cnt > 0:
    l, r = -1, n
    for num, i in enumerate(h):
        if (l == -1) and (i > 0):
            l = num
        if (l > -1) and (i == 0):
            r = num
            ans += 1
            cnt -= r - l
            for i in range(l, r):
                h[i] -= 1
            break
print(ans)

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


Question:
from collections import Counter

n, m = map(int, input().split())
ab = (list(map(int, input().split())) for _ in range(m))

cnt = Counter(sum(ab, []))
ans = all(cnt[i] % 2 == 0 for i in cnt)
print('YES' if ans else 'NO')

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


Question:
from collections import Counter

n, m = map(int, input().split())
ab = (list(map(int, input().split())) for _ in range(m))

cnt = Counter(sum(ab, []))
ans =  all(cnt[i] % 2 == 0 for i in cnt)
print('YES' if ans else 'NO')

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


Question:
N = int(intput())
print(N ** 3)

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


Question:
import numpy as np

N, M = map(int, input().split())
P = [None] * (N+1)
Y = [None] * (N+1)
for i in range(M):
    p, y = map(int, input().split())
    P[i] = p
    Y[i] = y
P = np.array(P)
Y = np.array(Y)
PY = np.c_[P, Y]
sort_ind = np.argsort(Y)
PY_sort = PY[sort_ind]
count = [0] * (N+1)
id_list = [None] * (N+1)
for i, py in enumerate(PY_sort):
    count[py[0]] += 1
    id_list[i] = (str(py[0]).zfill(6) + str(count[py[0]]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for city_id in id_list:
    print(city_id)

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


Question:
a = int(input())
b = int(input())
if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')

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


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


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

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


Question:
if S == 'ABC':
  S = 'ARC'
else:
  S = 'ABC'

print(S)

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


Question:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
md = pow(10,9) + 7

cnt_memo = [0]*(K+1)
cnt_R_memo = [0]*(K+1)

def main():
    ret = 0
    for k in range(1,K+1):
        cnt_R_memo[k]=pow(K//k,N)%md
    for k in range(K,0,-1):
        cnt_memo[k]=(cnt_R_memo[k] - sum(cnt_memo[2*k::k]))%md
        ret += (cnt_memo[k]*k)%md
    print(ret%md)

if __name__ == '__main__':
    main()

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


Question:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
md = pow(10,9) + 7

cnt_memo = [0]*(K+1)
cnt_R_memo = [0]*(K+1)

def main():
    ret = 0
    for k in range(1,K+1):
        cnt_R_memo[k]=pow(K//k,N)%md
    for k in range(K,0,-1):
        cnt_memo[k]=(cnt_R_memo[k] - sum(cnt_memo[2*k::k]))%md
        ret += (cnt_memo[k]*k)%md
    print(ret%md)

if __name__ == '__main__':
    main()

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


Question:
N = int(input())
S = input()
tmp = S[1]
ret = tmp
for i in S:
  if tmp == i:
    tmp = i
  else:
    ret += i
    tmp = i
print(len(ret))

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


Question:
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())

graph = [[] for _ in range(n)]
d = [[float("inf")]*n for i in range(n)]

for i in range(n):
    s = input()
    for j, sj in enumerate(s):
        d[i][i] = 1
        if sj == '1':
            graph[i].append(j)
            d[i][j] = 1
            d[j][i] = 1

colors = [0 for i in range(n)]

#2部グラフならTrue, そうでなければFalse
def is_bipartite():
    stack = [(0,1)] # (頂点、色)のタプルをスタックする。最初は(頂点0, 黒(1))
    while stack:
        #スタックから最後に追加された(頂点, 色)をpop
        v,color = stack.pop()
        #今いる点を着色
        colors[v] = color
        #今の頂点から行けるところをチェック
        for to in graph[v]:
            #同じ色が隣接してしまったらFalse
            if colors[to] == color:
                return False
            #未着色の頂点があったら反転した色と共にスタックに積む
            if colors[to] == 0:
                stack.append((to, -color))
    #調べ終わったら矛盾がないのでTrue
    return True

# ワーシャルフロイド法
# 全頂点間最短路
# d[i][j]は2頂点間i, j間の移動コストを格納, Mは頂点数

def warshall_floyd(d, M):
    for k in range(M):
        for i in range(M):
            for j in range(M):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    return d #d[i][j]に頂点i, j間の最短距離を格納

##############################

if is_bipartite():
    ret = 0
    for a in warshall_floyd(d,n):
        ret = max(ret, max(a))
    print(ret+1)
else:
    print(-1)

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


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

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


Question:
N = int(input())
H = list(map(int,input().split()))
H = [0]+H+[0]
for i in range(N,0,-1):
  if H[i-1]<=H[i]<=H[i+1]:
    H.pop(i)
  if H[i-1]>=H[i]>=H[i+1]:
    H.pop(i)
cnt = 0
flg = True
while flg:
  m = max(H)
  if m == 0:
    break
  i = H.index(m)
  d = min(H[i]-H[i+1], H[i]-H[i-1])
  cnt += d
  H[i+1]=max(0,H[i+1]-d)
  H[i-1]=max(0,H[i-1]-d)
  H.pop(i)
print(cnt)

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


Question:
a,b=map(int,input())
i=b-a
print(i*(i+1)//2-b)

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


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

def main():
    N = int(input())
    V = 10 ** 5 + 5
    edge = [[] * (2 * V) for _ in range(2 * V)]
    visited = [False] * (2 * V)
    for i in range(N):
        x, y = map(int, input().split())
        y += V
        edge[x].append(y)
        edge[y].append(x)

    def dfs(i):
        if visited[i]:
            return
        visited[i] = True
        cnt[i//V] += 1
        for j in edge[i]:
            dfs(j)
    ans = 0
    for i in range(2 * V):
        if visited[i]:
            continue
        cnt = [0,0]
        dfs(i)
        ans += cnt[0] * cnt[1]

    print(ans - N)

if __name__ == "__main__":
    main()

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


Question:
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(0, len(X)):
    sum = 0
    for j in range(0, len(X[i])):
        if i >= (len(X)-1):
            sum += X[i][j] - X[0][j]
        else:
            sum += (X[i][j] - X[i+1][j])**2

    if math.sqrt(sum).is_integer():
        cnt += 1
print(cnt)

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


Question:
import math
N, D = map(int, input().split())
X = []

for _ in range(N):
    X.append(list(map(int, input().split())))

cnt = 0
for i in range(0, len(X)):
    sum = 0
    for j in range(0, len(X[i])):
        if i >= len(X[i]):
            sum += X[i][j] - X[0][j]
        else:
            sum += (X[i][j] - X[i+1][j])**2

    if math.sqrt(sum).is_integer():
        cnt += 1
print(cnt)

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


Question:
S = list(input())
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if alp.index(S[i]) > alp.index(S[i+1]):
        #S[i] = S[i+1]
        print(''.join(S[:i-1])+alp[i])
        exit(0)

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


Question:
n=int(input())
ans += 1000*(n//500)
n=n%500
ans += n//5
print(ans)

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


Question:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,x=map(int,input().split())
    if a+b>x:
        print(0)
        sys.exit()
    for i in range(9,0,-1):#d(N)
        if x-b*i<a*10**(i-1):
            continue
        print(min(10**9,(x-b*i)//a))
        sys.exit()

if __name__=='__main__':
    main()

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


Question:
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==0:return 0 if x<=0 else 1
    if x<=1+A[n-1]:return f(n-1,x-1)
    if x<=2*A[n-1]+2:return 1+P[n-1]+f(n-1,x-A[n-1]-2)
def main():
    n,x=map(int,input().split())
    global A,P
    A=[1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
    P=[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]
    print(f(n,x))

if __name__=='__main__':
    main()

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


Question:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    if len(s)==26:
        for i,sx in enumerate(zyx):
            if s[i]!=sx:
                sxi=s.index(sx)
                s=s[:sxi]
                sy=s[-1]
                for j in range(26):
                    sz=chr(ord(sy)+1)
                    if not(sz in s):
                        print(s[:-1]+sz)
                        sys.exit()
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break

if __name__=='__main__':
    main()

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


Question:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    ss=set(s)
    if len(ss)==26:
        for i,sx in enumerate(zyx):
            print(i,sx,s)
            if s[i]!=sx:
                sxi=s.index(sx)
                s=s[:sxi]
                sy=s[-1]
                for j in range(26):
                    sz=chr(ord(sy)+1)
                    if not(sz in s):
                        print(s[:-1]+sz)
                        sys.exit()
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break

if __name__=='__main__':
    main()

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


Question:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    x,y=map(int,input().split())
    if x==-y:
        print(1)
    elif x*y>0:
        if x<y:
            print(y-x)
        else:
            print(x-y+2)
    elif x*y<0
        print(abs(x+y)+1)
    else:
        if x>0:
            print(x+1)
        elif x<0:
            print(-x)
        elif y>0:
            print(y)
        else:
            print(-y+1)

if __name__=='__main__':
    main()

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


Question:
n = int(input())
s = input()

p = [True]*n
for i in range(n-1):
  for j in range(i+1, n):
    if s[i] == s[j]:
      p[j] = False
    elif s[i] != s[j]:
      break
print(p.count(True))

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


Question:
from itertools import combinations
n = int(input())

march = ("M","A","R","C","H")
d = []
for _ in range(n):
  pre = input()[0]
  if pre in march: d.append(pre)

if len(d) < 3:
  print(0)
  exit()

ans = 0
for i in combinations(d,3):
  if len(set(i)) == 3:
    ans += 1
print(ans)

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


Question: print {'ABC':'ARC', 'ARC', 'ABC'}[raw_input()]

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


Question:
n,m = map(int, raw_input().split(' '))
print sum([1 for e in  map(int, raw_input().split(' ')) if e >= m else 0])

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


Question: print {(0,0):'NA', (0,1): 'YYMM', (1,0): 'MMYY', (1,1):'AMBIGUOUS'}[tuple(map(int,list(tuple([(0<int(s[2*i:2*i+2]) <= 12)	for i in range(2)]))))]

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


Question:
def f(s):return tuple([0<int(s[2*i:2*i+2]) <= 12	for i in range(0,2,2)])

print {(0,0):'NA', (0,1): 'YYMM', (1,0): 'MMYY', (1,1):'AMBIGUOUS'}[tuple(map(int,list(f(raw_input()))))]

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


Question:
def f(s):
  m,y = int(s[:2]), int(s[2:])
  return 0< m <= 12:

def g(s):
  y,m = int(s[:2]), int(s[2:])
  return 0< m <= 12:

s = raw_input()
p,q = f(s), g(s)

if p and q:
  print 'AMBIGUOUS'
elif p and not(q):
  print 'MMYY'
elif q and not(p):
  print 'YYMM'
else:
  print 'NA'

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


Question:
n,m,q = map(int, raw_input().split(' ')) #2 3 -10
bis = map(int, raw_input().split(' '))
c = 0
for _ in range(m):
	if sum([u*v for u,v in zip(map(int,raw_input().split(' ')),bis)]) + q > 0:
		c+=1
print c

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


Question:
"""
8
4 23 75 0 23 96 50 100
"""

[0,75,0,96,50,100]

n = int(raw_input())
ais = map(int, raw_input().split(' ')) #set()
i = 0
while(i < len(ais) and ais[i] == 0): i+=1
ais = ais[i:]

r = [0]
for i in range(len(ais)):
	if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0):
		r.append(ais[i])
	if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else +float('inf')):
		if i:
			r.append(ais[i])

t = 0
for i in range(0,len(r),2):
	if i + 1 < len(r):
		u,v = r[i],r[i+1]
		t += v-u
print t if len(ais) > 1 else ais[0]

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


Question:
"""
8
4 23 75 0 23 96 50 100
"""

[0,75,0,96,50,100]

n = int(raw_input())
ais = map(int, raw_input().split(' ')) #set()
i = 0
while(i < len(ais) and ais[i] == 0): i+=1
ais = ais[i:]

r = [0]
for i in range(len(ais)):
	if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0):
		r.append(ais[i])
	if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else 0):
		if i:
			r.append(ais[i])

t = 0
for i in range(0,len(r),2):
	if i + 1 < len(r):
		u,v = r[i],r[i+1]
		t += v-u
print t if len(ais) > 1 else ais[0]

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


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

for i in range(len(a) - 1):
    if a[i + 1] < a[i]:
        l.append(a[i]-a[i + 1])
        a[i + 1] = a[i]
print(sum(l))

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


Question:
n,m=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(0,len(a)):
  if a[i]>=m:
    ans+=1
print(ans)

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


Question:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A_sort = list(np.sort(A)[::-1])
A_index = list(np.argsort(A)[::-1])

dp = [-float('inf')]*(N+1)
dp[0] = 0

for i in range(N):
    dp_new = [-float('inf')]*(N+1)
    pi = A_index[i]  #もともといた場所
    for l in range(i+1):
        r = i - l   #右を選んだ回数
        dp_new[l+1] = max(dp_new[l+1],dp[l] + A_sort[i] * (pi-l))
        dp_new[l] = max(dp_new[l],dp[l] + A_sort[i] * ((N-r-1)-pi))
    dp = dp_new
print(max(dp))

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


Question:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A_sort = list(np.sort(A)[::-1])
A_index = list(np.argsort(A)[::-1])

dp = [[-float('inf')]*(N+1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    pi = A_index[i]  #もともといた場所
    for l in range(i+1):
        r = i - l   #右を選んだ回数
        dp[i+1][l+1] = max(dp[i+1][l+1],dp[i][l] + A_sort[i] * (pi-l))
        dp[i+1][l] = max(dp[i+1][l],dp[i][l] + A_sort[i] * ((N-r-1)-pi))

print(max(dp[N]))

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


Question:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
    t = K // i
    cnt = pow(t,N,MOD)
    for j in range(2,t+1):
        cnt -= d[i*j]
        cnt %= mod
    d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
    ans += num * cnt
    ans %= MOD
print(ans)

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


Question:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
N, W = map(int, readline().split())
SS = ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = readline().decode().rstrip()
for i in range(7):
    if S == SS[i]:
        print(7-i)
        sys.exit()

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


Question:
s = input()
a = 0
for x in s:
    if x == '+'
        a += 1
    else:
        a -= 1

print(a)

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


Question:
a = int(input())
b = int(input())

if a <= (a+b)//2 and b <= (a+b)//2:
    print("Yay!")
else:
    print(":(")

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


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

k,q=map(int,readline().split())
D=list(map(int,readline().split()))
NXM = map(int, read().split())

NXM=iter(NXM)
NXM=zip(NXM,NXM,NXM)

for n,x,m in NXM:
    tmpD=D%m
    SD=np.array([0]+tmpD,dtype=np.int64)
    SD=np.cumsum(SD)
    n-=1
    x=x%m
    x+=SD[-1]*(n//k)
    x+=SD[n%k]
    count=tmpD.count(0)*(n//k)
    count+=tmpD[:n%k].count(0)
    ans=n-x//m-count
    print(ans)

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


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

k,q=map(int,readline().split())
D=list(map(int,readline().split()))
NXM = map(int, read().split())

NXM=iter(NXM)
NXM=zip(NXM,NXM,NXM)

for n,x,m in NXM:
    tmpD=list(map(lambda x:x%m,D))
    SD=np.array([0]+tmpD,dtype=np.int64)
    SD=np.cumsum(SD)
    n-=1
    x=x%m
    x+=SD[-1]*(n//k)
    x+=SD[n%k]
    count=tmpD.count(0)*(n//k)
    count+=tmpD[:n%k].count(0)
    ans=n-x//m-count
    print(ans)

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


Question:
n,m,v,p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p-=1

a.sort(reverse=True)

ans=0
s = sum(a)

def safe(index):
    if a[p]>a[index]+m:
        return False
    i=0
    wall = -1
    while a[i]>=a[index]+m:
        if a[i]>=a[index]+m+1:
            wall = i
        i+=1
    if i>index:
        return True
    intg = 0
    while i<index:
        intg += a[index] + m - a[i]
        i+=1
    intg += (len(a)-1-index)*m + min(v,p - wall + 1)*m
    #print("intg = ",intg ,m*(v-1) )
    return intg >= m*(v-1)

left = 0
right = len(a)-1
ans = int((right - left)/2)
if safe(right):
    ans = right
else:
    j = safe(ans)
    while not(j and not safe(ans+1)):
        if j:
            left = ans
        else:
            right = ans
        ans = left + int((right - left)/2)
        j = safe(ans)
print(ans+1)
"""
for i in range(len(a)):
    print(a[i],safe(i))
"""

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


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

last=[-1]*(2*10**5+1)
nex=[-1]*n
prog=[0]*n

for i,a in enumerate(A*2):
    l=last[a]
    last[a]=i%n
    if nex[l]==-1 and l!=-1:
        nex[l]=(i+1)%n
        if i>=n or i+1==n:
            prog[l]=1
if nex[-1]==0:
    prog[-1]+=1

flag=False #いっぱいループ済か
stage=0
now=0
roop=[-1]*n
while True:
    if roop[now]!=-1 and flag==False:
        flag=True
        rr=stage-roop[now]
        stage=k-1-(k-1-stage)%rr
    if stage+prog[now]==k:
        break
    roop[now]=stage
    stage+=prog[now]
    now=nex[now]

A=A[now:]+A if k-1-stage else A[now:]
check=[0]*(2*10**5+1)
stack=[]
for a in A:
    if check[a]:
        while check[a]:
            check[stack.pop()]=0
        continue
    stack.append(a)
    check[a]=1

print(*stack)

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


Question:
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

breakFlag = False
for i in range(1,m-1):
    if a[i]%2==1:
        if a[0]%2==1:
            if a[len(a)-1]%2==1:
                print("Impossible")
                breakFlag = True
                break
            else:
                a[i],a[len(a)-1] = a[len(a)-1],a[i]
        else:
            a[i],a[0] = a[0],a[i]

if breakFlag==False:
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])
    if a[len(a)-1]==1:
        print(m-1)
        a.pop()
        a[0]+=1
    else:
        print(m)
        a[0]+=1
        a[len(a)-1] -= 1
    ans = ''.join([str(s)+" " for s in a])
    print(ans[:-1])

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


Question: print('NYoe s'[[*'000']in[eval(eval(t.replace(*' -')))for t in open(0)]::2])

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


Question:
a,b=[],
for z in[*open(0)][1:]:x,y=map(int,z.split());a+=x+y,;b+=x-y,
print(max(abs(max(a)-min(a)),abs(max(b)-min(b))))

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


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


Question: a,b=map(int,input().split());print([i for i in range(10**6)if a==i//12.5and b==i//10]+[-1][0])

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


Question:
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        *_,=map(temp.append,(self.popleft()for _ in range(n//2)))
        *_,=map(self.append,(self.popleft()for _ in range(n//2,n)))
        *_,=map(self.appendleft,temp[::-1])
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        *_,=map(temp.append,(self.pop()for _ in range(n//2)))
        *_,=map(self.appendleft,(self.pop()for _ in range(n//2,n)))
        *_,=map(self.append,temp[::-1])
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

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


Question:
from subprocess import*
with open('A.py','w')as f:
    f.write('a,b=map(int,input().split())\n')
    for i in range(-100,101):
        f.write('if a==%d:\n'%i)
        for j in range(-100,101):
            f.write('    if b==%d:print(%d)\n'%(j,max(i+j,i-j,i*j)))
call(('pypy3','A.py'))

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


Question:
n,k,*a=map(int,open(0).read().split())
l,r,*b=[[]for _ in range(10**6)]
for i,v in enumerate(a):
  b[v]+=i,
  l+=len(b[v]),
s=a[0]
i=c=0
while 1:
  j=l[i]%len(b[s])
  if(c>k-2)>j:
    r+=s,
    i+=1
  else:i=-~b[s][j]%n
  c+=j<1
  if i<1:
    if c>k-2:break
    k%=c+1
    c=0
  s=a[i]
print(*r)

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


Question:
from bisect import*
from collections import*
n,k,*a=map(int,open(0).read().split())
b=defaultdict(list)
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
"""
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)
"""
a*k

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


Question:
from bisect import*
n,k,*a=map(int,open(0).read().split())
b=[[]for _ in range(max(a)+1)]
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)

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


Question:
from bisect import*
n,k,*a=map(int,open(0).read().split())
b=[[]for _ in range(n+1)]
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=[]
for i in a*k:
  if i in s:s=s[:s.index(i)]
  else:s+=i,
print(*s)

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


Question:
from numpy import*
x=loadtxt(open(0),skiprows=1)
print(sum(triu([linalg.norm(i-x,2,1)%1==0for i in x],1)))

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


Question:
from networkx import*
def main():
    g=Graph()
    for a in[*open(0)][1:]:
        a,b=map(int,a.split())
        g.add_edge(a,b+.5)
    x=0
    for c in connected_components(g):
        s=g.subgraph(c)
        a,b=map(len,bipartite.sets(s))
        x+=a*b-s.size()
    print(x)
main()

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


Question:
from networkx import*
def main():
    g=Graph()
    for a in[*open(x:=0)][1:]:
        a,b=map(int,a.split())
        g.add_edge(a,b+.5)
    for c in connected_components(g):
        s=g.subgraph(c)
        a,b=map(len,bipartite.sets(s))
        x+=a*b-s.size()
    print(x)
main()

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


Question:
from networkx import*
def main():
    g=Graph()
    for a in[*open(x:=0)][1:]:
        a,b=map(int,a.split())
        g.add_edge(a,b+.5)
    for c in connected_components(g):
        a,b=map(len,bipartite.sets(s:=g.subgraph(c)))
        x+=a*b-s.size()
    print(x)
main()

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


Question:
from networkx import*
def main():
    g=Graph()
    for a in[*open(x:=0)][1:]:
        a,b=map(int,a.split())
        g.add_edge(a,7**6+b)
    for c in connected_components(g):
        a,b=map(len,algorithms.bipartite.sets(s:=g.subgraph(c)))
        x+=a*b-s.size()
    print(x)
main()

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


Question: n,a,b,c,d=map(int,input().split());s=input();t=[b-2:d+1];print('YNeos'[not'...'*(d<c)in t or'##'in s[a:c]+t::2])

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


Question: from scipy.misc import*;M=10**9+7;n,m,k=map(int,input().split());s=lambda x,y:sum(y*y*i*(x-i)for i in range(x));print((s(n,m)+s(m,n))%M*comb(n*m-2,k-2,1)%M)

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


Question: from scipy.misc import*;n,m,k=map(int,input().split());s=lambda x,y:sum(y*y*i*(x-i)for i in range(x));print((s(n,m)+s(m,n))*comb(n*m-2,k-2,1)%(10**9+7))

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


Question: s=input();print['NA','MMYY','YYMM','AMBIGUOUS'][(99<s<1300)-(0<s%100<13)*2]

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


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


Question: from scipy.sparse import*;n,*t=map(int,open(0).read().split());print('SFeicrosntd'[csgraph.dijkstra(csr_matrix(([1]*~-n,(t[::2],t[1::2])),[n+1]*2),0)[1:,1:].max()%3!=1::2])

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


Question:
from collections import*
def s():
 global a,b;f,q=[1]*-~n,deque([(a,0)])
 while q:
  a,b=q.popleft()
  for v in e[a]:q+=[(v,b+1)]*f[v];f[v]=0
n,*t=map(int,open(0).read().split())
e=[[]for _ in[0]*-~n]
for a,b in zip(t[::2],t[1::2]):e[a]+=b,;e[b]+=a,
s(),s()
print('SFeicrosntd'[b%3!=1::2])

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


Question: a=b=c=d=e=f=0;g=1;exec('a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,(g*4-b-c-d-a*3))%(10**9+7);'*int(input()));print(g)

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


Question: s=input();print(int(s[:2])+int(s[2:])//2)

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


Question:
n,k=map(int,input().split())
m=[0]*n
for i in range(1,n+1):m[i%k]+=1
print(m[0]*3+[m[k//2]*3,0][k%2])

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


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

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


Question:
from numpy import*
a=loadtxt(open(0),'i',skiprows=1)
n=x=len(a)
while a.any():
  t=bincount(a[:,0])
  x,a=min(x,max(t)),reshape(a[a!=argmax(t)],(n,-1))
print(x)

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


Question:
l=[0]*2**14
for i in open(0).read().split()[2:]:l[int(i)]+=1
print('YNEOS'[any(i%2for i in l)::2])

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


Question:
*c,=open(0).read().split()[2:]
print('YNEOS'[any(c.count(i)%2for i in set(c))::2])

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


Question:
from collections import*
H,*A=open(0)
H,W,K=map(int,H.split())
*A,=map(list,A)
for i,a in enumerate(A):
	if'S'in a:j=a.index('S');Q=deque([(0,i,j)])
d=1e9
while Q:
	c,i,j=Q.popleft();d=min(d,i,j,H-i-1,W-j-1)
	if c<K:
		for h,w in((i+1,j),(i,j+1),(i-1,j),(i,j-1)):
			if(H>h>-1<w<W)*'.'==A[h][w]:A[h][w]=0;Q+=(c+1,h,w),
print(1--d//K)

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


Question:
if __name__=='__main__':
    from collections import deque
    h, w, k = map(int, input().split())
    maze = [input() for _ in range(h)]
    visited = [[-1]*w for j in range(h)]
    for i in range(h):
        if 'S' in maze[i]:
            sy, sx = i, maze[i].index('S')
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    r = 10**18
    while queue:
        y, x = queue.popleft()
        r = min(r, y, x, h-1-y, w-1-x)
        if visited[y][x] == k: continue
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+i, x+j
            if new_y < 0 or new_y >= h: continue
            if new_x < 0 or new_x >= w: continue
            if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    print(1 -(-r // k))

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


Question:
from collections import deque;h,w,k=map(int,input().split());m=[input()for _ in[0]*h];v=[[-1]*w for _ in[0]*h];r=9**20
for i in range(h):
 if'S'in m[i]:j=m[i].index('S');q=deque([[i,j]])v[i][j]=0
while q:
 y,x=q.popleft()
 r=min(r,y,x,h-1-y,w-1-x)
 if v[y][x]==k:continue
 for i,j in([1,0],[-1,0],[0,1],[0,-1]):
  t,u=y+i,x+j
  if t>=0and t<h and u>=0and u<w and m[t][u]=='.'and v[t][u]<0:v[t][u]=v[y][x]+1;q.append([t,u])
print(1-(-r//k))

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


Question:
from collections import deque
h, w, k = map(int, input().split())
maze = [input() for _ in range(h)]
visited = [[-1]*w for j in range(h)]
for i in range(h):
    if 'S' in maze[i]:
        sy, sx = i, maze[i].index('S')
queue = deque([[sy, sx]])
visited[sy][sx] = 0
r = 10**18
while queue:
    y, x = queue.popleft()
    r = min(r, y, x, h-1-y, w-1-x)
    if visited[y][x] == k: continue
    for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        new_y, new_x = y+i, x+j
        if new_y < 0 or new_y >= h: continue
        if new_x < 0 or new_x >= w: continue
        if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
            visited[new_y][new_x] = visited[y][x] + 1
            queue.append([new_y, new_x])
print(1 -(-r // k))

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


Question: input();print('YNEOS'[eval(input().replace(' ','^'))&1::2])

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


Question: input();print('YNEOS'[eval(input().replace(' ','^'))::2])

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


Question:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
s=[0]
p=[0]
for i in range(1,n+1):
  s[i].append(s[i-1]+a[i])
  p[i].append(p[i-1]+max(0,a[i]))
ans=0
for i in range(1,n-k+1):
  t=max(0,s[i+k]-s[i-1])
  t+=p[i-1]+p[n]-p[i+k]
  ans=max(ans,t)
print(ans)

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


Question:
i,o,t,j,l,s,z=map(int,input().split())
a=(i//2+j//2+l//2)*2
print([a,max(a,((i-1)//2+(j-1)//2+(l-1)//2)*2+3)][i and j and l]+o)

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


Question:
from functools import lru_cache
@lru_cache(maxsize=None)
def search(i,j):
  global s,h,w
  if i==h-1and j==w-1:return 1
  r=0
  if i<h-1and s[i+1][j]=='#':r|=search(i+1,j)
  else if j<w-1and s[i][j+1]=='#':r|=search(i,j+1)
  if i>0and s[i-1][j]=='#':r=0
  if j>0and s[i][j-1]=='#':r=0
  return r
h,w=map(int,input().split())
s=[input()for _ in[0]*h]
print(('P'*search(0,0)or'Imp')+'ossible')

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


Question:
n,x,t=map(int,input().split())
r=math.ceil(n/x)*t
print(r)

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


Question:
n=int(input())
r=math.ceil(Fraction(360,n))
print(r)

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


Question:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60

def main():
    MOD = 1000000007
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(AB[::2], AB[1::2]):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    stack = deque([0])
    order = []
    prev = [0] * N
    prev[0] = -1
    while stack:
        v = stack.pop()
        order.append(v)
        for nv in G[v]:
            if nv != prev[v]:
                stack.append(nv)
                prev[nv] = v

    pow2 = [0] * (N + 1)
    pow2[0] = 1
    for i in range(N):
        pow2[i + 1] = pow2[i] * 2

    nodes = [1] * N
    numer = 0

    for v in reversed(order):
        if prev[v] != -1:
            nodes[prev[v]] += nodes[v]
        numer = (numer + pow2[N - 1] - 1 - (pow2[N - nodes[v]] - 1)) % MOD
        for nv in G[v]:
            if nv != prev[v]:
                numer = (numer - (pow2[nodes[nv]] - 1)) % MOD

    denom = pow2[N]
    ans = (numer * pow(denom, MOD - 2, MOD)) % MOD
    print(ans)
    return

if __name__ == '__main__':
    main()

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


Question:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60

def input():
    return stdin.readline().strip()

MOD = 1000000007

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

seen = [False] * N

numer = 0
pow2 = [1] * (N + 1)
for i in range(N):
    pow2[i + 1] = pow2[i] * 2 % MOD

def dfs1(v):
    global numer
    seen[v] = True
    nodes = []
    childs = 0
    for nv in G[v]:
        if not seen[nv]:
            nodes.append(dfs1(nv) + 1)
            childs += nodes[-1]
    if v != 0:
        nodes.append(N - childs - 1)
    if len(nodes) > 1:
        this_numer = pow2[N - 1] - (sum(pow2[n] - 1 for n in nodes) + 1)
        numer = (numer + this_numer) % MOD
    return childs

dfs1(0)

denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)

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


Question:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60

def input():
    return stdin.readline().strip()

MOD = 1000000007

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

childs = [0] * N
seen = [False] * N

def dfs1(v):
    seen[v] = True
    c = 0
    for nv in G[v]:
        if not seen[nv]:
            dfs1(nv)
            c += childs[nv] + 1
    childs[v] = c
    return

dfs1(0)

numer = 0
seen = [False] * N

pow2 = [1] * (N + 1)
for i in range(N):
    pow2[i + 1] = pow2[i] * 2 % MOD

def dfs2(v):
    global numer
    seen[v] = True
    nodes = []
    for nv in G[v]:
        if seen[nv]:
            nodes.append(N - childs[v] - 1)
        else:
            nodes.append(childs[nv] + 1)
    if len(nodes) > 1:
        this_numer = pow2[N - 1] - (sum(pow2[n] - 1 for n in nodes) + 1)
        numer = (numer + this_numer) % MOD
    for nv in G[v]:
        if not seen[nv]:
            dfs2(nv)
    return

dfs2(0)
denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)

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


Question:
from sys import stdin, setrecursionlimit
from functools import lru_cache

setrecursionlimit(10 ** 9)
INF = 1 << 60

def input():
    return stdin.readline().strip()

MOD = 1000000007

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

childs = [0] * N
seen = [False] * N

def dfs1(v):
    seen[v] = True
    c = 0
    for nv in G[v]:
        if not seen[nv]:
            dfs1(nv)
            c += childs[nv] + 1
    childs[v] = c
    return

dfs1(0)

numer = 0
seen = [False] * N

@lru_cache(maxsize=None)
def power(x, y, z):
    return pow(x, y, z)

def dfs2(v):
    global numer
    seen[v] = True
    nodes = []
    for nv in G[v]:
        if seen[nv]:
            nodes.append(N - childs[v] - 1)
        else:
            nodes.append(childs[nv] + 1)
    if len(nodes) > 1:
        this_numer = power(2, N - 1, MOD) - (sum(power(2, n, MOD) - 1 for n in nodes) + 1)
        numer = (numer + this_numer) % MOD
    for nv in G[v]:
        if not seen[nv]:
            dfs2(nv)
    return

dfs2(0)
denom = power(2, N, MOD)
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)

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


Question:
def main():
    import numpy as np
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    s = np.array(sorted(set(H+[0])), dtype=np.int64)
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    dp = np.full((k+1, l), 10**13, dtype=np.int64)
    dp[0, 0] = 0

    for i in range(n):
        h = H[i]
        dh = d[h]
        dp2 = np.zeros((k+1, l), dtype=np.int64)
        dp2[0] = np.full(l, 10**13, dtype=np.int64)
        dp2[1:, :] = dp[:-1, :]
        temp = np.concatenate([(h-s)[:dh], np.zeros(l-dh, dtype=np.int64)])
        for j in range(k+1):
            dp2[j, dh] = min(dp2[j, dh], min(dp[j, :]+temp))
        dp = dp2
    print(np.min(dp))

main()

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


Question:
def main():
    import numpy as np
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    s = np.array(sorted(set(H+[0])), dtype=np.int64)
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    a = max(s)-s
    dp = np.full((1, l), 10**13, dtype=np.int64)
    dp[0, 0] = 0

    if k > 0:
        for i in range(n):
            h = H[i]
            dh = d[h]
            dp2 = np.zeros((min(i+2, k+1), l), dtype=np.int64)
            if i < k:
                s_plus_a = a+dp[:]
                min_s = dp[:]
            else:
                s_plus_a = a+dp[:-1]
                min_s = dp[:-1]
            for j in range(l-2, -1, -1):
                min_s[:, j] = np.minimum(min_s[:, j+1], min_s[:, j])
            for j in range(1, l):
                s_plus_a[:, j] = np.minimum(s_plus_a[:, j-1], s_plus_a[:, j])
            dp2[1:, :] = np.minimum(min_s, s_plus_a - a)
            dp2[0, :] = 10**13
            if i < k:
                for j in range(l):
                    dp2[:-1, dh] = np.minimum(dp2[:-1, dh],
                                              dp[:, j]+max(h-s[j], 0))
            else:
                for j in range(l):
                    dp2[:, dh] = np.minimum(
                        dp2[:, dh], dp[:, j]+max(h-s[j], 0))
            dp = dp2
    else:
        for h in H:
            dh = d[h]
            dp2 = np.full((1, l), 10**13, dtype=np.int64)
            for j in range(l):
                dp2[:, dh] = np.minimum(dp2[:, dh], dp[:, j]+max(h-s[j], 0))
            dp = dp2
    print(np.min(dp))

main()

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


Question:
def main():
    n, K = map(int, input().split())
    H = list(map(int, input().split()))
    s = sorted(set(H+[0]))
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    m = max(s)
    a = [m-i for i in s]
    dp = [[10**13]*l for _ in range(K+1)]
    dp[0][0] = 0
    for h in H:
        dh = d[h]
        dp2 = [[10**13]*l for _ in range(K+1)]
        t = [[i+j for i, j in zip(a, kk)] for kk in dp]
        min_s = [[dp[i][j] for j in range(l)] for i in range(K+1)]
        for i in range(K+1):
            for j in range(l-2, -1, -1):
                min_s[i][j] = min(min_s[i][j+1], min_s[i][j])
            for j in range(1, l):
                t[i][j] = min(t[i][j-1], t[i][j])
            for j in range(l):
                t[i][j] = t[i][j]-a[j]
        for i in range(K):
            for j in range(l):
                dp2[i+1][j] = min(min_s[i][j], t[i][j])
        for i in range(K+1):
            dp2[i][dh] = min(dp2[i][dh], min(
                [dp[i][j]+max(h-s[j], 0) for j in range(l)]))
        dp = dp2
    print(min([min(i) for i in dp]))

main()

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


Question:
def main():
    import numpy as np
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    s = np.array(sorted(set(H+[0])), dtype=np.int64)
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    a = max(s)-s
    dp = np.full((k+1, l), 10**13, dtype=np.int64)
    dp[0, 0] = 0

    if k > 0:
        for h in H:
            dh = d[h]
            dp2 = np.zeros((k+1, l), dtype=np.int64)
            s_plus_a = a+dp[:-1]
            min_s = dp[:-1]
            for j in range(l-2, -1, -1):
                min_s[:, j] = np.minimum(min_s[:, j+1], min_s[:, j])
            for j in range(1, l):
                s_plus_a[:, j] = np.minimum(s_plus_a[:, j-1], s_plus_a[:, j])
            dp2[1:, :] = np.minimum(min_s, s_plus_a - a)
            dp2[0, :] = 10**13
            for j in range(l):
                dp2[:, dh] = np.minimum(dp2[:, dh], dp[:, j]+max(h-s[j], 0))
            dp = dp2
    else:
        for h in H:
            dh = d[h]
            dp2 = np.full((1, l), 10**13, dtype=np.int64)
            for j in range(l):
                dp2[:, dh] = np.minimum(dp2[:, dh], dp[:, j]+max(h-s[j], 0))
            dp = dp2
    print(np.min(dp))

main()

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


Question:
def main():
    n = int(input())
    lr = [list(map(int, input().split())) for _ in [0] * n]

    lr.sort(key=lambda x: (+x[1] - x[0]))
    box0 = [lr[0][0], lr[0][1]]
    box1 = [lr[1][0], lr[1][1]]
    for i in range(2, n):
        a1 = max(min(lr[i][1], box0[1]) - max(lr[i][0], box0[0])+1, 0) + max(box1[1] - box1[0]+1, 0)
        a2 = max(min(lr[i][1], box1[1]) - max(lr[i][0], box1[0])+1, 0) + max(box0[1] - box0[0]+1, 0)
        a3 = max(min(box0[1], box1[1]) - max(box0[0], box1[0])+1, 0) + max(lr[i][1] - lr[i][0]+1, 0)
        m = max(a1, a2, a3)
        if a1 == m:
            box0[0] = max(lr[i][0], box0[0])
            box0[1] = min(lr[i][1], box0[1])
        elif a2 == m:
            box1[0] = max(lr[i][0], box1[0])
            box1[1] = min(lr[i][1], box1[1])
        else:
            box0[0] = max(box0[0], box1[0])
            box0[1] = min(box0[1], box1[1])
            box1[0] = lr[i][0]
            box1[1] = lr[i][1]
    print(m)
main()

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


Question:
def main():
    from sys import stdin
    input = stdin.readline
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = bl(max_a, now_a[start-1]+1)-1
            flag = 0
            if now_a[start-1] == 0:
                flag = 1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                cnt += flag
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = bl(max_a, now_a[start-1]+1)-1
            flag = 0
            if now_a[start-1] == 0:
                flag = 1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                cnt += flag
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            p = now_a[start-1]
            q = bl(max_a, p+1)-1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                if now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, min(end, start+rest)):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, min(end, start+rest)):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 1, -1):
        rest = ans
        nex = now_a[0]
        # restの分だけ戻す
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, -1, -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
                if rest == 0:
                    break
        # 大きい方から使っていく
        while True:
            if cnt < use:
                ans_list.append(ans)
                break
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, end):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                    if rest == 0:
                        break
                end = start
    print(n)
    for i in ans_list[::-1]:
        print(i)

main()

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


Question:
def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))

    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m

    for i in range(262143,m):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=-1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=min(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[[i,i+k-2,0,0]]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append([ii,jj,2*now+1,l+1])
                qq.append([ii,jj,2*now+2,l+1])
        min_list.append(min(s))

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=n+1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=max(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[[i,i+k-2,0,0]]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append([ii,jj,2*now+1,l+1])
                qq.append([ii,jj,2*now+2,l+1])
        max_list.append(max(s))

    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False

    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False

    print(sum(flag))

if __name__ == '__main__':
	main()

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


Question:
def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))

    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m

    for i in range(262143,m):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=-1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=min(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[[i,i+k-2,0,0]]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append([ii,jj,2*now+1,l+1])
                qq.append([ii,jj,2*now+2,l+1])
        min_list.append(min(s))

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=n+1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=max(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[[i,i+k-2,0,0]]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append([ii,jj,2*now+1,l+1])
                qq.append([ii,jj,2*now+2,l+1])
        max_list.append(max(s))

    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False

    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False

    print(sum(flag))

if __name__ == '__main__':
	main()

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


Question:
def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))

    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m

    for i in range(262143,m):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=-1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=min(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[(i,i+k-2,0,0)]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,l+1))
                qq.append((ii,jj,2*now+2,l+1))
        min_list.append(min(s))

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=n+1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=max(segtree[2*i+1],segtree[2*i+2])

    for i in range(n-k+2):
        qq=[(i,i+k-2,0,0)]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,l+1))
                qq.append((ii,jj,2*now+2,l+1))
        max_list.append(max(s))

    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False

    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False

    print(sum(flag))

if __name__ == '__main__':
	main()

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


Question:
def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))

    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m

    for i in range(262143,m):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=-1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=min(segtree[2*i+1],segtree[2*i+2])

    def search(i,j,now):
        for k in range(20):
            if 2**k-1<=now<2**(k+1)-1:
                break
        kubun=2**k
        now2=now-kubun+1
        width=262144//kubun
        left=width*now2
        right=width*(now2+1)-1
        if i<=left and right<=j:
            return segtree[now]
        elif j<left or right<i:
            return n+1
        else:
            return min(search(i,j,2*now+1),search(i,j,2*now+2))

    for i in range(n-k+2):
        min_list.append(search(i,i+k-2,0))

    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=n+1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=max(segtree[2*i+1],segtree[2*i+2])

    def search(i,j,now):
        for k in range(20):
            if 2**k-1<=now<2**(k+1)-1:
                break
        kubun=2**(k)
        now2=now-kubun+1
        width=262144//kubun
        left=width*now2
        right=width*(now2+1)-1
        if i<=left and right<=j:
            return segtree[now]
        elif j<left or right<i:
            return -1
        else:
            return max(search(i,j,2*now+1),search(i,j,2*now+2))

    for i in range(n-k+2):
        max_list.append(search(i,i+k-2,0))

    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False

    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False

    print(sum(flag))

if __name__ == '__main__':
	main()

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


Question:
def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))

    min_list=[]
    max_list=[]

    segtree=[n+1]*524288

    for i in range(262143,262143+n):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        segtree[i]=min(segtree[2*i+1],segtree[2*i+2])

    def search(i,j,now):
        for k in range(20):
            if 2**k-1<=now<2**(k+1)-1:
                break
        kubun=2**(k)
        now2=now-kubun+1
        width=262144//kubun
        left=width*now2
        right=width*(now2+1)-1
        if i<=left and right<=j:
            return segtree[now]
        elif j<left or right<i:
            return n+1
        else:
            return min(search(i,j,2*now+1),search(i,j,2*now+2))

    for i in range(n-k+2):
        min_list.append(search(i,i+k-2,0))

    segtree=[-1]*524288

    for i in range(262143,262143+n):
        segtree[i]=x[i-262143]

    for i in range(262142,-1,-1):
        segtree[i]=max(segtree[2*i+1],segtree[2*i+2])

    def search(i,j,now):
        for k in range(20):
            if 2**k-1<=now<2**(k+1)-1:
                break
        kubun=2**(k)
        now2=now-kubun+1
        width=262144//kubun
        left=width*now2
        right=width*(now2+1)-1
        if i<=left and right<=j:
            return segtree[now]
        elif j<left or right<i:
            return -1
        else:
            return max(search(i,j,2*now+1),search(i,j,2*now+2))

    for i in range(n-k+2):
        max_list.append(search(i,i+k-2,0))

    cnt=0

    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False

    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False

    print(sum(flag))

if __name__ == '__main__':
	main()

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


Question:
def main():
    n = int(input())
    S = input()
    s = []
    mod = 998244353
    fact = 1
    for i in range(2, n+1):
        fact = fact*i % mod

    for i in S:
        if i == "R":
            s.append(0)
        elif i == "G":
            s.append(1)
        else:
            s.append(2)

    ans = 1
    color = [0, 0, 0]
    mode = []
    for i in range(3*n):
        if mode == []:
            color[s[i]] += 1
            if color[s[i]] > 0:
                mode.append(s[i])
        elif len(mode) == 1:
            if s[i] == mode[0]:
                color[s[i]] += 1
            else:
                color[s[i]] += 1
                if color[s[i]] > 0:
                    mode.append(s[i])
        else:
            rest = list({0, 1, 2}-{mode[0]}-{mode[1]})[0]
            if s[i] == rest:
                if color[rest] < 0:
                    color[rest] += 1
                else:
                    ans *= color[mode[0]]*color[mode[1]]
                    color[mode[0]] -= 1
                    color[mode[1]] -= 1
                    if color[mode[0]]+color[mode[1]] == 0:
                        mode = []
                    elif color[mode[0]] == 0:
                        mode = [mode[1]]
                    elif color[mode[1]] == 0:
                        mode = [mode[0]]
            else:
                color[s[i]] += 1
        if len(mode) == 2:
            if color[mode[0]] == color[mode[1]]:
                if color[mode[0]] < color[mode[1]]:
                    color[rest] -= color[mode[0]]
                    for i in range(color[mode[0]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = [mode[1]]
                elif color[mode[0]] > color[mode[1]]:
                    color[rest] -= color[mode[1]]
                    for i in range(color[mode[1]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = [mode[0]]
                else:
                    color[rest] -= color[mode[1]]
                    for i in range(color[mode[1]]):
                        ans *= color[mode[0]]*color[mode[1]]
                        color[mode[0]] -= 1
                        color[mode[1]] -= 1
                    mode = []
        ans = ans % mod
    print(ans*fact % mod)

main()

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


Question:
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        if a[i] >= a[i+1]:
            break
    else:
        print(1)
        return

    h = []
    heapq.heapify(h)
    kind = 1
    length = 0
    d = dict()
    for i in a:
        if length >= i:
            while h:
                hh = -heapq.heappop(h)
                if hh > i:
                    d.pop(hh)
                else:
                    heapq.heappush(h, -hh)
                    break
            for j in range(i, 0, -1):
                if j not in d:
                    d[j] = 2
                    heapq.heappush(h, -j)
                    kind = max(kind, 2)
                    while h:
                        hh = -heapq.heappop(h)
                        if hh > j:
                            d.pop(hh)
                        else:
                            heapq.heappush(h, -hh)
                            break
                    break
                else:
                    if d[j] < kind:
                        d[j] += 1
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
            else:
                d[i] += 1
                kind += 1
        length = i

    def value(kind):
        length = 0
        d = dict()
        for i in a:
            if length >= i:
                del_list = []
                for j in d:
                    if j > i:
                        del_list.append(j)
                for j in del_list:
                    d.remove(j)
                for j in range(i, 0, -1):
                    if j not in d:
                        d[j] = 2
                        break
                    else:
                        if d[j] < kind:
                            d[j] += 1
                            break
                        else:
                            d.pop(j)
                else:
                    return False
            length = i
        return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(kind, max(1, kind-30), value))

main()

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


Question:
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        if a[i] >= a[i+1]:
            break
    else:
        print(1)
        return

    h = []
    heapq.heapify(h)
    kind = 1
    length = 0
    d = dict()
    for i in a:
        if length >= i:
            while h:
                hh = -heapq.heappop(h)
                if hh > i:
                    d.pop(hh)
                else:
                    heapq.heappush(h, -hh)
                    break
            for j in range(i, 0, -1):
                if j not in d:
                    d[j] = 2
                    heapq.heappush(h, -j)
                    kind = max(kind, 2)
                    while h:
                        hh = -heapq.heappop(h)
                        if hh > j:
                            d.pop(hh)
                        else:
                            heapq.heappush(h, -hh)
                            break
                    break
                else:
                    if d[j] < kind:
                        d[j] += 1
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
            else:
                d[i] += 1
                kind += 1
        length = i

    def value(kind):
        h = []
        heapq.heapify(h)
        length = 0
        d = dict()
        for i in a:
            if length >= i:
                while h:
                    hh = -heapq.heappop(h)
                    if hh > i:
                        d.pop(hh)
                    else:
                        heapq.heappush(h, -hh)
                        break
                for j in range(i, 0, -1):
                    if j not in d:
                        d[j] = 2
                        heapq.heappush(h, -j)
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
                    else:
                        if d[j] < kind:
                            d[j] += 1
                            while h:
                                hh = -heapq.heappop(h)
                                if hh > j:
                                    d.pop(hh)
                                else:
                                    heapq.heappush(h, -hh)
                                    break
                            break
                else:
                    return False
            length = i
        return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(kind, 1, value))

main()

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


Question:
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        if a[i] >= a[i+1]:
            break
    else:
        print(1)
        return

    def value(kind):
        h = []
        heapq.heapify(h)
        length = 0
        d = dict()
        for i in a:
            if length >= i:
                while h:
                    hh = -heapq.heappop(h)
                    if hh > i:
                        d.pop(hh)
                    else:
                        heapq.heappush(h, -hh)
                        break
                for j in range(i, 0, -1):
                    if j not in d:
                        d[j] = 2
                        heapq.heappush(h, -j)
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
                    else:
                        if d[j] < kind:
                            d[j] += 1
                            while h:
                                hh = -heapq.heappop(h)
                                if hh > j:
                                    d.pop(hh)
                                else:
                                    heapq.heappush(h, -hh)
                                    break
                            break
                else:
                    return False
            length = i
        return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(n, 1, value))

main()

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


Question:
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        if a[i] >= a[i+1]:
            break
    else:
        print(1)
        return

    def value(kind):
        h = []
        heapq.heapify(h)
        length = 0
        d = dict()
        for i in a:
            if length >= i:
                while h:
                    hh = -heapq.heappop(h)
                    if hh > i:
                        d.pop(hh)
                    else:
                        heapq.heappush(h, -hh)
                        break
                for j in range(i, 0, -1):
                    if j not in d:
                        d[j] = 2
                        heapq.heappush(h, -j)
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
                    else:
                        if d[j] < kind:
                            d[j] += 1
                            while h:
                                hh = -heapq.heappop(h)
                                if hh > j:
                                    d.pop(hh)
                                else:
                                    heapq.heappush(h, -hh)
                                    break
                            break
                else:
                    return False
            length = i
        return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(n, 1, value))

main()

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


Question:
def main():
    N, M = map(int, input().split())
    S = [i == "B" for i in input()]
    ab = [list(map(int, input().split())) for _ in [0]*M]
    graph = [set() for _ in [0]*N]
    [graph[a-1].add(b-1) for a, b in ab]
    [graph[b-1].add(a-1) for a, b in ab]

    status = [[0, 0] for _ in [0]*N]

    for i in range(N):
        for j in g[i]:
            status[i][S[j]] += 1

    que = []
    for i, (p, q) in enumerate(status):
        if (p == 0) ^ (q == 0):
            que.append(i)

    while que:
        i = que.pop()
        c = S[i]
        for j in graph[i]:
            if i != j:
                graph[j].remove(i)
            status[j][c] -= 1
            p, q = status[j]
            if (p == 0) ^ (q == 0):
                que.append(j)
        g[i] = set()

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

main()

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


Question:
def main():
    from sys import stdin
    input=stdin.readline
    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
- Runtime Error
- Time Limit Exceeded