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

sumA = sum(A)
ct = {0:1}

for a in A:
  nct = {}
  for k in ct:
    nct[k] = nct.get(k, 0) + ct[k]
    nct[k+a] = nct.get(k+a, 0) + ct[k]
  ct = nct

ct[0] = 0
medidx = (2**N)//2
n = 0
for i in range(sumA+1):
  n += ct.get(i, 0)
  if n >= medidx:
    print(i)
    exit()

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


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

ct = [0]*(sum(A)+1)
ct[0] = 1
ctlen = len(ct)

for a in A:
  for i in range(ctlen-a-1,-1,-1):
    ct[i+a] += ct[i]

ct[0] = 0
medidx = (2**N)//2
n = 0
for i in range(ctlen):
  n += ct[i]
  if n >= medidx:
    print(i)
    exit()

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


Question:
n, k = [ int(v) for v in input().split() ]
num = [ int(v) for v in input().split() ]
num_2 = [ max(i,0) for i in num ]

cum_num, cum_num_2 = [0] + cumsum(num), [0] + cumsum(num_2)

ans = 0
for i in range(n-k+1):
    ansl = cum_num_2[i]
    ansm = cum_num[k+i] - cum_num[i]
    ansr = cum_num_2[n] - cum_num_2[i+k]
    ans = max(ansl+max(ansm,0)+ansr, ans)
print(ans)

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


Question:
#解説読んだ

import math

N, L = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]

K = N * (N - 1) * (N - 2) / 3 / 2
x, y = 0, 0
for i in range(N - 1):
  for j in range(i + 1, N):
    a = (T[i] + T[j]) / 2
    b = a + L / 2
    t = j - i - 1
    k = N - 2 - t
    x += k * math.cos(2 * math.pi * a / L) / K
    x += t * math.cos(2 * math.pi * b / L) / K
    y += k * math.sin(2 * math.pi * a / L) / K
    y += t * math.sin(2 * math.pi * b / L) / K
print(x, y)

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


Question:
#解説読んだ

import math

N, L = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]

x, y = 0, 0
for i in range(N - 1):
  for j in range(i + 1, N):
    a = (T[i] + T[j]) / 2
    b = a + L / 2
    t = j - i - 1
    k = N - 2 - t
    x += k * math.cos(2 * math.pi * a / L)
    x += t * math.cos(2 * math.pi * b / L)
    y += k * math.sin(2 * math.pi * a / L)
    y += t * math.sin(2 * math.pi * b / L)
x /= N * (N - 1) * (N - 2) / 3 / 2
y /= N * (N - 1) * (N - 2) / 3 / 2
print(x, y)

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


Question:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    class UnionFind():
        def __init__(self, n):
            self.parent = [-1 for _ in range(n)]
            # 正==子: 根の頂点番号 / 負==根: 連結頂点数

        def find(self, x):
            # 要素xが属するグループの根を返す
            if self.parent[x] < 0:
                return x
            else:
                self.parent[x] = self.find(self.parent[x])
                return self.parent[x]

        def unite(self, x, y):
            # 要素xが属するグループと要素yが属するグループとを併合する
            x, y = self.find(x), self.find(y)
            if x == y:
                return False
            else:
                if self.size(x) < self.size(y):
                    x, y = y, x
                self.parent[x] += self.parent[y]
                self.parent[y] = x

        def same(self, x, y):
            # 要素x, yが同じグループに属するかどうかを返す
            return self.find(x) == self.find(y)

        def size(self, x):
            # 要素xが属するグループのサイズ（要素数）を返す
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            # 要素の根をリストで返す
            return self.parent[x] < 0

        def roots(self):
            # すべての根の要素をリストで返す
            return [i for i, x in enumerate(self.parent) if x < 0]

        def members(self, x):
            # 要素xが属するグループに属する要素をリストで返す
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def group_count(self):
            # グループの数を返す
            return len(self.roots())

        def all_group_members(self):
            # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
            return {r: self.members(r) for r in self.roots()}

    N = I()
    A = LI()
    B = LI()
    uf = UnionFind(N+1)
    Da = defaultdict(list)
    Db = defaultdict(list)
    bita = 0

    same = [False]*(N+1)
    for i in range(N):
        if A[i]==B[i]:
            same[i] = True
    if sum(same)==N:
        print(0)
        return

    for i,a in enumerate(A):
        bita ^= a
        if same[i]:
            continue
        Da[a].append(i)
    Da[bita].append(N)
    bitb = 0
    for i,b in enumerate(B):
        bitb ^= b
        if same[i]:
            continue
        Db[b].append(i)
    Db[bitb].append(N)
    if bita==bitb:
        same[N] = True
    #print(Da)
    #print(Db)
    for key,a in Da.items():
        if len(Db[key])!=len(a):
            print(-1)
            return

    for key,a in Da.items():
        uf.unite(a[0],Db[key][0])
        if len(a)==1:
            continue
        for i in a[1:]:
            uf.unite(a[0],i)
    for b in Db.values():
        if len(b)==1:
            continue
        for i in b[1:]:
            uf.unite(b[0],i)

    if uf.size(N)==N+1-sum(same):
        ans = uf.size(N)
        if bita!=bitb:
            ans -= 1
        print(an)
        return

    ans = -1
    used = [False]*(N+1)
    for i in range(N+1):
        #print(ans)
        if same[i]:
            continue
        p = uf.find(i)
        if used[p]:
            continue
        used[p] = True
        ans += (-uf.parent[p]+1)
        #print(ans)
    #if sum(used)>1:
    #    ans += 1
    if uf.size(N)>1:
        ans -= 1
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
5
0 2 3 6 9
2 9 0 6 3

5
0 2 3 6 9
2 9 0 6 14
# 4
5
0 2 3 6 9
2 3 0 6 14
# 5
5
0 2 3 6 9
2 0 3 9 14
# 5
"""

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


Question:
def examA():
    A, B, C = LI()
    ans = min(A*B*(C%2),A*C*(B%2),B*C*(A%2))
    print(ans)
    return

def examB():
    class segment_():
        def __init__(self, A, n, segfunc):
            #####単位元######要設定0or1orinf
            self.ide_ele = inf
            ####################
            self.num = 1 << (n - 1).bit_length()
            self.seg = [self.ide_ele] * 2 * self.num
            self.segfunc = segfunc
            # set_val
            for i in range(n):
                self.seg[i + self.num] = A[i]
                # built
            for i in range(self.num - 1, 0, -1):
                self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1])

        def update(self, k, r):
            k += self.num
            self.seg[k] = r
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        # 値xに1加算
        def update1(self, k):
            k += self.num
            self.seg[k] += 1
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def updateneg1(self, k):
            k += self.num
            self.seg[k] -= 1
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def query(self, p, q):
            if q < p:
                return self.ide_ele
            p += self.num;
            q += self.num
            res = self.ide_ele
            while p < q:
                if p & 1 == 1:
                    res = self.segfunc(res, self.seg[p])
                    p += 1
                if q & 1 == 1:
                    q -= 1
                    res = self.segfunc(res, self.seg[q])
                p >>= 1;
                q >>= 1
            return res
    N, x = LI()
    A = LI()
    Seg_min = segment_(A, N, lambda a, b: min(a,b))
    ans = inf
    for k in range(N):
        cur = 0
        for j in range(N):
            if j-k>=0:
                now = Seg_min.query(j-k,j+1)
            else:
                now = min(Seg_min.query(0,j+1),Seg_min.query(N-(k-j),N))
#            print(now,k,j)
            cur += now
        ans = min(ans,cur+k*x)

    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N, K = LI()
    A = LI()
    V = [[]for _ in range(N)]
    ans = 0
    if A[0]!=1:
        ans += 1
        A[0] = 1
    for i in range(1,N):
        V[A[i]-1].append(i)
    def dfs(p,s):
        depth = 0
        cnt = 0
        for i in V[s]:
            d,c = dfs(s,i)
            depth = max(depth,d)
            cnt += c
        depth += 1
        if depth==K and p!=0:
            depth = 0
            cnt += 1
        return depth,cnt
    _,cnt = dfs(0,0)
    ans += cnt
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

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


Question:
def combs_mod(n,k,mod):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans
def solve():
  mod = 998244353
  N, K = map(int, input().split())
  ans = 0
  if K<N:
    return ans
  com = combs_mod(K,K,mod)
  com2 = combs_mod(K-1,K-1,mod)
  for r in range(K+1):
    b = K-r
    dif = r-b
    if dif<0 or r<N:
      continue
    elif dif==0:
      ans += com2[r]
      if N>=2:
        ans -= com2[N-2]
    elif dif<N:
      ans += com[r] - com[N-1-dif]
    else:
      ans += com[r]
    ans %= mod
  return ans
print(solve())

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


Question:
n = int(input())
M = 10**4
dp = [0]*(2*M)
dp[M] = 1
A = tuple(map(int, input().split()))
for i, a in enumerate(A):
  for j in range(2*M):
    if j-a >= 0 and dp[j-a]:
      dp[j] = 1
l = sum(divmod(sum(A), 2))
now = M+l
while True:
  if dp[now]:
    print(now-M)
    break
  now += 1

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


Question:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#x,y = [int(i) for i in readline().split()]
MOD = 998244353
n = int(input())
s = input()

R = B = G = 0
ans = 1
for i in s:
    m = sorted([R,G,B])
    if eval(i) == m[-1]:
        ans *= n-m[-1]
        ans %= MOD
    elif eval(i) == m[1]:
        ans *= m[2]-m[1]
        ans %= MOD
    else:
        ans *= m[1]-m[0]
        ans %= MOD
    if i == "R":
        R += 1
    elif i == "G":
        G += 1
    elif i == "B":
        B += 1

print(ans)

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


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

ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		if b%2 == 0:
			ans += 2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)

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


Question:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

#gridのindexは入力値のまま扱う(grid=[1,1]~[H,W])
#left<x<rightの間が生存範囲(初めはグリッド全てが生存可能状態)
left=0
right=W+1
up=0
down=H+1

ans="YES"
#手を逆順で見ていく。
for s,t in zip(reversed(S),reversed(T)):
    if t=='R':#生存可能範囲を広げる(0より小さくならないようにする)
        left=max(0,left-1)
    elif t=="L":
        right=min(W+1,right+1)
    elif t=="D":
        up = max(0,up-1)
    else:
        down=min(H+1,down+1)

    if s=="R"
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    #もし、途中でright-left==1。つまり、生存可能範囲がなくなってしまったら、
    #落とされてしまうため、ans=NOにして終了する
    if right-left==1 or down-up==1:
        ans="NO"
        break

#全ての手を見た後で、スタート地点が生存可能範囲に入っていればOK
if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)

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


Question:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

left=0
right=W+1
up=0
down=H+1

ans="YES"
for i,(s,t) in enumerate(zip(reversed(S),reversed(T))):
    if i!=0:
        if t=='R':
            left=max(0,left-1)
        elif t=="L":
            right=min(W+1,right+1)
        elif t=="D":
            up = max(0,up-1)
        else:
            down=min(H+1,down+1)

    if s=="R":
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    if right-left==1 or down-upp==1:
        ans="NO"
        break

if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)

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


Question:
import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline

def acinput():
    return list(map(int, input().split(" ")))

def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact

H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))

def position_relative(direction,cs,flg,seq1,seq2):

    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg

        if cs<=0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg

        if cs < 0 or cs > N:
            return False

    return cs

sr=position_relative("R",initp[0],S,T)
sl = position_relative("L",initp[0],S,T)

su = position_relative("U",initp[1],S, T)
sd = position_relative("D", initp[1], S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("YES")
else:
    print("NO")

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


Question:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n==4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)

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


Question:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n==k==1:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sum(a[i:i+k]),0)+racc[i+k])
print(mx)

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


Question:
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N):
  if i < K:
    tmp+=a[i]
  else:
    if a[i]>0:
      ans+=a[i]
ans+=max(0,tmp)

ans2=0
tmp=0
for i in range(N-1,-1,-1):
  if ans < N-K:
    if a[i]>0:
      ans2+=a[i]
  else:
    tmp+=a[i]
ans2+=max(0,tmp)
print(max(ams2,ans))

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


Question:
from collections import defaultdict
mod = 998244353
N = int(input())
S = input()
colors = ['R', 'G', 'B']
invs = {'R':'GB', 'G':'BR', 'B':'RG'}
cnt = defaultdict(int)
ans = 1
for i in range(N*3):
    s = S[i]
    inv = invs[s]
    if cnt[inv] != 0:
        ans *= cnt[inv]
        cnt[inv]-=1
        continue
    flag = False
    for c in colors:
        if c == s:
            continue
        if cnt[c]:
            ans*=cnt[c]
            cnt[c]-=1
            cnt[c+s]+=1
            cnt[s+c]+=1
            flag = True
    if not flag:
        cnt[s]+=1
    ans%=mod
for i in range(1, N+1):
    ans*=i
    ans%=mod
print(ans)

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


Question:
import heapq as h
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
e6 = 10**6
q = [-b[i]*e6-i for i in range(n)]
q.sort()
cnt = 0
while q:
  w = -h.heappop(q)
  v, i = divmod(w, e6)
  u = b[i-1] + b[(i+1)%n]
  if v < u or a[i] == v: continue
  elif a[i] > v: print(-1); exit(0)
  t = (v-a[i])//u
  if not t: print(-1); exit(0)
  cnt += t
  b[i] -= t*u
  if b[i] > a[i]:
    h.heappush(q,-b[i]*e6-i)
print(cnt if a==b else -1)

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


Question:
from numpy import*
n,M=map(int,input().split())
l=n*3+1
d=zeros(l,n*5)
d[0][0]=1
for i in range(1,l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+roll(d[k],-1)*j+roll(d[j],1))%M
print(sum(d[-1][:l])%M)

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


Question:
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):j,k=i-1,j-1;d[i]=(d[i-3]*(k)*(j)+p.roll(d[k],-1)*(i-1)+p.roll(d[j],1))%M
print(d[-1][:l].sum()%M)

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


Question:
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):
  d[i]=(d[i-3]*(i-2)*(i-1)+p.roll(p[i-2],-1)*(i-1)+p.roll(d[i-1],1))%M
print(d[-1][:l].sum()%M)

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


Question:
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):
  d[i]=(d[i-3]*(i-2)*(i-1)+p.roll(p[i-2],-1)*(i-1)+p.roll(d[i-1],1))%M
print(d[-1][:l].sum()%M)

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


Question:
n,m=map(int,input().split())
N=3*n
d=[[0]*(N+1) for i in range(N+4)]
d[0][0]=1
for i in range(N):
  a,b,c,d=d[i:i+4]
  for j in range(N):
    b[j]=(b[j]+a[j])%m
    c[j+1]=(c[j+1]+a[j]*(i+1))%m
    d[j+1]=(d[j+1]+a[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

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


Question:
n,m=map(int,open(0))
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(1,n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j]+d0[j]*(i-1))%m
    d3[j+1]=(d3[j]+d0[j]*(i-1)*(i-2))%m
print(sum(d[n3][:n+1])%m)

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


Question:
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e))
  if res == k - 1 and a[e] != 0 and e != 0:
    ans[e] = 1
    res = 1
  return res + 1

dfs(0)
print(sum(ans))

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


Question:
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
c = [1] * n
def dfs(now, rank):
  c[now] = 0
  for e in edg[now]:
    if c[e]:
      if rank == k:
        ans[e] = 1
        dfs(e, 1)
      else:
        dfs(e, time + 1)
dfs(0, 1)
print(sum(ans))

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


Question:
import sys
sys.recursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
c = [1] * n
def dfs(now, time):
  c[now] = 0
  for e in edg[now]:
    if c[e]:
      if time == k:
        ans[e] = 1
        dfs(e, 1)
      else:
        dfs(e, time + 1)
dfs(0, 0)
print(sum(ans))

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


Question:
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
c = [1] * n
def dfs(now, time):
  c[now] = 0
  for e in edg[now]:
    if c[e]:
      if time == k:
        ans[e] = 1
        dfs(e, 1)
      else:
        dfs(e, time + 1)
dfs(0, 0)
print(sum(ans))

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


Question:
n=int(input())
a=sorted(map(int,input().split()))[::-1]
j=i=0
while n:i+=a[i]>i;j+=a[j]>=i,n-=1
print('SFeicrosntd'[(a[i-1]^i|j^i)&1::2])

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


Question:
n=int(input())
a=sorted(map(int,input().split()))[::-1]
j=i=x=0
while x<n:i+=a[i]>i;j+=a[j]>=i,x+=1
print('SFeicrosntd'[(a[i-1]^i|j^i)&1::2])

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


Question:
from sys import exit
from collections import defaultdict
import itertools
H,W,N = [int(n) for n in input().split()]
Sr,Sc = [int(n) for n in input().split()]
#上に
Uout = H-Sr + 1
#下に
Dout = Sr
#右に落とすのに必要な歩数
Rout = W - Sc + 1
#左に
Lout = Sc
S = str(input())
T = str(input())

def check(outcnt, C, A, lim, B):
    re = False
    for s,t in zip(S,T):
        if s == B and outcnt == lim -1:
            re = True
            break
        if( s == C):
            outcnt -= 1
        if(outcnt == 0 ):
            print("NO")
            exit()
        if(t == A and outcnt < lim):
            outcnt += 1
    if(re):
        check(outcnt, C, A, lim-1, B)
check(Rout, "R", "L", W, "L")
check(Lout, "L", "R", W, "R")
check(Uout, "U", "D", H, "D")
check(Dout, "D", "U", H, "U")
print("YES")

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


Question:
a=list(map(int,input().split()))
ans=min(a[0],a[3],a[4])
a[0]-=ans
a[3]-=ans
a[4]-=ans
ans*=3
if(ans>0&&(a[0]%2+a[3]%2+a[4]%2==2)):
  ans+=1
ans+=(a[0]//2*2)+(a[3]//2*2)+(a[4]//2*2)+a[1]
print(ans)

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


Question:
N = int(input())
C = [list(map(int,input().split())) for i in range(N)]
C.sort()
ans0 = 0
ans1 = 0
ans2 = 0
AM = []
Am = []
BM = []
Bm = []
for i in range(N):
    ans0 += C[i][0]
    ans1 += C[i][1]
    Min = min(C[i][0],C[i][1])
    Max = max(C[i][0],C[i][1])
    ans2 += Min
    if Min == C[i][0]:
        Am.append(C[i][0])
        BM.append(C[i][1])
    else:
        AM.append(C[i][0])
        Bm.append(C[i][1])
ans3 = sum(sorted(A+B)[:N])
if ans3 == ans2:
    ans3 += min(min(AM)-max(Am),min(BM)-max(Bm))

ans = min(ans0,ans1,ans3)
print(ans)

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


Question:
N, K = map(int, input().split())
*A, = map(int, input().split())
ans = -float('inf')
for i in range(N - K + 1):
    ans = max(ans, max(sum(A[i: i+K]), 0) + sum([a for a in A[:i] + A[i+K:] if a > 0]))
print(ans)

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


Question:
#d
#the niumbers of evens is important
#the point is, there is no influence to odd/even if you divide them by odd numbers.
#You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers

from math import gcd

def count(a):
    odd, even = 0,0
    for x in a:
        if x % 2 == 1: odd = odd + 1
        else: even = even + 1
    return odd,even

def deal(n,a):
    odd,even = count(a)
    if even == 0:
        return False
    if even % 2 == 1:
        return True
    if odd > 1:
        return False

    #the case where there is one odd (over 3) and even numbers of even numbers
    #calculate gcd by step by step
    g = 1
    for i in range(0,n):
        if a[i] % 2 == 1:
            if a[i] == 1:
                return False
            a[i]  -= 1
        g = gcd(a[i], g)
    return not deal(n,list(map(lambda x: x//g,a)))

n = int(input())
a = [int(i) for i in input().split()]
if deal(n,a):
    print('First')
else:
    print('Second')

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

from operator import itemgetter

n = int(input())
abli = []
for i in range(n):
    a, b = map(int, input().split())
    abli.append((a, i, 0))
    abli.append((b, i, 1))

abli.sort(key=itemgetter(0))
tmpans0 = sum(map(itemgetter(0),abli[:n]))

alist = []
blist = []
for x, i, aorb in abli[:n]:
    if not aorb:
        alist.append(i)
    else:
        blist.append(i)

flag = False
for i in range(n):
    if i in alist and i in blist:
        flag = True
        break
"""
abli.sort(key=itemgetter(0))
tmpans0 = sum(map(itemgetter(0), abli[:n]))
alist = [i for x, i, aorb in abli[:n] if not aorb]
blist = [i for x, i, aorb in abli[:n] if aorb]
flag = bool([i for i in range(n) if i in alist and i in blist])
"""

y, j, arob2 = abli[n]
z, k, arob3 = abli[n+1]
if flag:
    tmpans = tmpans0
else:
    tmpans = 10**16
    for x, i, aorb in abli[:n]:
        if j != i:
            tmp = tmpans0-x+y
        else:
            tmp = tmpans0-x+z
        if tmpans > tmp:
            tmpans = tmp

leftsum = sum([a for a,i,aorb in abli if not aorb])
rightsum = sum([b for b,i,aorb in abli if aorb])

print(min(leftsum, rightsum, tmpans))

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

from operator import itemgetter

n = int(input())
abli = []
for i in range(n):
    a, b = map(int, input().split())
    abli.append((a, i, 0))
    abli.append((b, i, 1))

abli.sort(key=itemgetter(0))
tmpans0 = sum(map(itemgetter(0), abli[:n]))
alist = [i for x, i, aorb in abli[:n] if not aorb]
blist = [i for x, i, aorb in abli[:n] if aorb]
flag = bool([i for i in range(n) if i in alist and i in blist])

y, j, arob2 = abli[n]
z, k, arob3 = abli[n+1]
if flag:
    tmpans = tmpans0
else:
    tmpans = 10**16
    for x, i, aorb in abli[:n]:
        if j != i:
            tmp = tmpans0-x+y
        else:
            tmp = tmpans0-x+z
        if tmpans > tmp:
            tmpans = tmp

leftsum = sum([a for a,i,aorb in abli if not aorb])
rightsum = sum([b for b,i,aorb in abli if aorb])

print(min(leftsum, rightsum, tmpans))

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

import itertools
from operator import itemgetter

n = int(input())
abli0 = [tuple(map(int, input().split())) for i in range(n)]
eabli0 = enumerate(abli0)
abli1 = list(map(lambda t: ((t[1][0], t[0], 0), (t[1][1], t[0], 1)), eabli0))
abli = list(itertools.chain.from_iterable(abli1))
abli.sort(key=itemgetter(0))
tmpans0 = sum(map(lambda t: t[0], abli[:n]))
alist = [i for x, i, aorb in abli[:n] if not aorb]
blist = [i for x, i, aorb in abli[:n] if aorb]
flag = bool([i for i in range(n) if i in alist and i in blist])

y, j, arob2 = abli[n]
z, k, arob3 = abli[n+1]
if flag:
    tmpans = tmpans0
else:
    tmpans = 2**62
    for x, i, aorb in abli[:n]:
        if j != i:
            tmp = tmpans0-x+y
        else:
            tmp = tmpans0-x+z
        if tmpans > tmp:
            tmpans = tmp

leftsum = sum(map(lambda x: x[0], abli0))
rightsum = sum(map(lambda x: x[1], abli0))

print(min(leftsum, rightsum, tmpans))

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 D
"""

import itertools
from functools import reduce
from functools import lru_cache

nn, k = map(int, input().split())
n = 2*nn
abli = []
for i in range(k):
    a, b = map(int, input().split())
    if a < b:
        abli.append((a, b))
    else:
        abli.append((b, a))
flattenabli = itertools.chain.from_iterable(abli)

cut = 10**9+7

unused = [1 for i in range(n+1)]
for a in flattenabli:
    unused[a] -= 1
unusedacum = list(itertools.accumulate(unused))

def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut

@lru_cache(maxsize=None)
def doubleFactorial(x):
    return reduce(lambda y, z: y*z % cut, range(x, 0, -2))

@lru_cache(maxsize=None)
def isSandwiched(i, j):
    return any(map(lambda k: abli[k][0] < i <= abli[k][1] <= j or i <= abli[k][0] <= j < abli[k][1], range(k)))

nonSandwichedNums = [[] for i in range(n+1)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        if not isSandwiched(i, j):
            nonSandwichedNums[i].append(j)

def numberUnderterminedBetween(i, j):
    return unusedacum[j]-unusedacum[i-1]

def pairCombinations(x):
    if x == 0:
        return 1
    elif x % 2 == 0:
        return doubleFactorial(x-1)
    else:
        return 0

def g(i, j):
    x = numberUnderterminedBetween(i, j)
    return pairCombinations(x)

undetermined = numberUnderterminedBetween(1, n)

ggg = [[0]*(i+1) for i in range(n+1)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        ggg[i].append(g(i, j))

ans = 0
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(1, n+1):
    for j in nonSandwichedNums[i]:
        dp[i][j] = (ggg[i][j]-sum([dp[i][kk]*ggg[kk+1][j] for kk in nonSandwichedNums[i] if kk < j])) % cut
        ans = (ans + dp[i][j]*pairCombinations(undetermined-numberUnderterminedBetween(i, j))) % cut

print(ans)

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 D
"""

import itertools
from functools import reduce
from functools import lru_cache

nn, k = map(int, input().split())
n = 2*nn
abli = []
for i in range(k):
    a, b = map(int, input().split())
    if a < b:
        abli.append((a, b))
    else:
        abli.append((b, a))
flattenabli = itertools.chain.from_iterable(abli)

cut = 10**9+7

unused = [1 for i in range(n+1)]
for a in flattenabli:
    unused[a] -= 1
unusedacum = list(itertools.accumulate(unused))

def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut

@lru_cache(maxsize=None)
def doubleFactorial(x):
    return reduce(lambda y, z: y*z % cut, range(x, 0, -2))

@lru_cache(maxsize=None)
def isSandwiched(i, j):
    return any(map(lambda k: abli[k][0] < i <= abli[k][1] <= j or i <= abli[k][0] <= j < abli[k][1], range(k)))

nonSandwichedNums = [[] for i in range(n+1)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        if not isSandwiched(i, j):
            nonSandwichedNums[i].append(j)

def numberUnderterminedBetween(i, j):
    return unusedacum[j]-unusedacum[i-1]

def pairCombinations(x):
    if x == 0:
        return 1
    elif x % 2 == 0:
        return doubleFactorial(x-1)
    else:
        return 0

def g(i, j):
    x = numberUnderterminedBetween(i, j)
    return pairCombinations(x)

undetermined = numberUnderterminedBetween(1, n)

ggg = [[0]*(i+1) for i in range(n+1)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        ggg[i].append(g(i, j))

@lru_cache(maxsize=None)
def dp(i, j):
    if isSandwiched(i, j):
        return 0
    gg = ggg[i][j]
    if gg == 0:
        return 0
    # return gg-sum([dp(i, k)*g(k+1, j) for k in range(i+1, j)]) % cut
    return (gg-sum([dp(i, k)*ggg[k+1][j] for k in nonSandwichedNums[i] if k < j])) % cut

print(sum([dp(i, j)*pairCombinations(undetermined-numberUnderterminedBetween(i, j)) for i, j in itertools.combinations(range(1, n+1), 2)]) % cut)

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

n, m = map(int, input().split())
ali = list(map(int, input().split()))

if m == 1:
    print(ali[0])
    print(2)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a % 2 == 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)

print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))

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


Question:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

n, m = map(int, input().split())
ali = list(map(int, input().split()))

if m == 1:
    print(ali[0])
    print(1)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a & 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)

print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))

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


Question:
from collections import Counter

S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t

    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)

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


Question:
#!/usr/bin/env python3
from math import cos, sin, pi
n, L = map(int, input().split())
t = [int(input()) for _ in range(n)]
ans = [0, 0]
for i in range(n):
    for j in range(i + 1, n):
        k = (n - 1 - j + i) - (j - i - 1)
        ans[0] += cos(pi * (t[i] + t[j]) / L) * k
        ans[1] += sin(pi * (t[i] + t[j]) / L) * k
for i in range(2):
    ans[i] /= n * (n - 1) * (n - 2) / 6
print(*ans, sep=' ')

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


Question:
#!/usr/bin/env python3
import math
import bisect
Q = int(input())
for _ in range(Q):
    A, B, C, D = map(int, input().split())
    K = math.ceil(max(A, B) / (min(A, B) + 1))
    xs = ((A - i + 1) * K < B - max(0, (i - 1) // K) for i in range(A + 1))
    p = bisect.bisect(list(xs), False)
    f = ''
    for i in range(C - 1, D):
        na = p - 1
        nb = max(0, (na - 1) // K)
        if i < nb * (K + 1):
            f += ('A', 'B')[i % (K + 1) == K]
        elif i < na + nb:
            f += 'A'
        else:
            j = A + B - i - 1
            nb = B - nb
            na = max(0, (nb - 1) // K)
            if j < na * (K + 1):
                f += ('B', 'A')[j % (K + 1) == K]
            else:
                f += 'B'
    print(f)

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


Question:
#!/usr/bin/env python3
import math
Q = int(input())
for _ in range(Q):
    A, B, C, D = map(int, input().split())
    K = math.ceil(max(A, B) / (min(A, B) + 1))
    f = ''
    ca, cb = 0, 0
    while A + B > 0:
        if B <= A * K:
            if A > 0 and ca < K:
                A -= 1
                ca += 1
                cb = 0
                f += 'A'
            elif B > 0:
                B -= 1
                ca = 0
                cb += 1
                f += 'B'
        else:
            if B > 0 and cb < K:
                B -= 1
                ca = 0
                cb += 1
                f += 'B'
            elif A > 0:
                A -= 1
                ca += 1
                cb = 0
                f += 'A'
    print(f[C - 1:D])

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


Question:
aI, aO, _, aJ, aL, _, _ = map(int,input().split())

"""
aO -> +1
aI, aJ, aL -> +3
aI * 2 -> +2
aJ * 2 -> +2
aL * 2 -> +2
"""

ansK = aO
for IJL in range(min(aI,aJ,aL) + 1):
    K = aO
    K += IJL * 3
    K += ((aI - IJL) // 2) * 2
    K += ((aJ - IJL) // 2) * 2
    K += ((aL - IJL) // 2) * 2
    ansK = max(ansK, K)

print(ansK)

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


Question:
from collections import Counter
s = input()
if len(set(s)) ==1:
    print(0)
    exit()
if len(set(s)) != len(s):
    cs = Counter(s)
    I = 0
    n = cs.most_common()[0][1]
    ans = 100
    while cs.most_common()[I][1] == n:
        id = [x for x, v in enumerate(s) if v == cs.most_common()[I][0]]
        x = 0
        for i in range(len(id)-1):
            if i == 0 and id[i] > 0 and x < id[i]:
                x = id[i]
            if id[i+1] - id[i] > x:
                x = id[i+1] - id[i] -1
        if ans > x: ans = x
        I += 1
else: ans = len(s) - len(s)//2
print(ans)

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


Question:
from collections import Counter
s = input()
if len(set(s)) ==1:
    print(0)
    exit()
if len(set(s)) != len(s):
    cs = Counter(s)
    I = 0
    n = cs.most_common()[0][1]
    ans = 100
    while cs.most_common()[I][1] == n:
        id = [x for x, v in enumerate(s) if v == cs.most_common()[I][0]]
        x = 0
        for i in range(len(id)-1):
            if id[i+1] - id[i] > x:
                x = id[i+1] - id[i] -1
        if ans > x: ans = x
        I += 1
else: ans = len(s) - len(s)//2
print(ans)

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


Question:
#AGC016-A
from collections import Counter
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
cnt = 0
result = []
for i in alphabet:
    s_tmp = s
    cnt = 0
    for k in range(len(s_tmp)):
        s_new= ""
        for j in range(len(s_tmp)-1):
            if s_tmp[j] == i or s_tmp[j+1] == i:
                s_new += i
            else:
                s_new += s_tmp[j]
        cnt += 1
        s_tmp = s_new
        if len(set(s_new)) == 1:
            result.append(cnt)
            break

#print(result)
print(min(result))

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


Question:
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

    ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)

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


Question:
from math import cos, sin, pi
from itertools import combinations
N, L = map(int, input().split())
T = [int(input()) for _ in range(N)]
PI2oL = 2*pi/L

csum, ssum = 0, 0
count = 0
for i, j in combinations(range(N), 2):
    count += 1
    mid1, num2 = (T[i] + T[j]) / 2, j - i - 1
    mid2, num1 = (mid1 + L/2) % L, N - num2 - 2
    csum += cos(PI2oL*mid1) * num1 + cos(PI2oL*mid2) * num2
    ssum += sin(PI2oL*mid1) * num1 + sin(PI2oL*mid2) * num2

print(csum/count/(N-2)*3, ssum/count/(N-2)*3)

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


Question:
for t in range(int(input())):
	a,b,c,d=map(int,input().split(' '));l,o=(a+b)//(min(a,b)+1),"";x,y=(a*l-b)//(l-1),(b*l-a)//(l-1)
	if a*l<=b:x,y=0,a+b
	elif b*l<=a:x,y=a+b,0
	for i in range(c,d+1):o+="AB"[i%(l+1)==0] if i<=x else "BA"[(a+b-i+1)%(l+1)==0] if a+b-i+1<=y else "AB"[a-x+x//(l+1)-y//(l+1)==0]
	print(o)

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


Question:
for t in range(int(input())):
	a,b,c,d=map(int,input().split(' '));l,x,y,o=(a+b)//(min(a,b)+1),(a*l-b)//(l-1),(b*l-a)//(l-1),""
	if a*l<=b:x,y=0,a+b
	elif b*l<=a:x,y=a+b,0
	for i in range(c,d+1):o+="AB"[i%(l+1)==0] if i<=x else "BA"[(a+b-i+1)%(l+1)==0] if a+b-i+1<=y else "AB"[a-x+x//(l+1)-y//(l+1)==0]
	print(o)

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


Question:
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)

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


Question:
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))
a=int(abin,2)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**(lb-1)-a)
else:
  print(2**(lb-1)-a+lbnd-a)

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


Question:
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))
a=int(abin,2)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(lbnd-a+1)
else:
  print(2**(lb-1)-a+lbnd-a+1)

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


Question:
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    del abin[0]
    del bbin[0]
  while abin[0]=="0":
    del abin[0]
cbin=bbin[1:]
while cbin[0]=="0":
  del cbin[0]
c=2**(len(cbin))
a=int(abin,2)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(lbnd-a+1)
else:
  print(2**(lb-1)-a+lbnd-a+1)

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


Question:
from math import gcd
n = int(input())
a = list(map(int,input().split()))
def gcds(ls):
  ret = 0
  for i in ls:
    ret = gcd(ret,i)
  return ret
def flg(ls):
  if (sum(ls)-len(ls))%2:
    ret = 1
  else:
    ret = 2
  return ret
if n%2 == 0:
  if sum(a)%2:
    print("Second")
  else:
    print("First")
else:
  cnt = 0
  while flg(a)%2 == 0:
    odd = 0
    oddidx = -1
    even = 0
    for i,x in enumerate(a):
      if x%2:
        odd += 1
        oddidx = i
      else:
        even += 1
    if odd == 1 and a[oddidx] > 1:
      a[oddidx] -= 1
      g = gcds(a)
      for i in range(n):
        a[i] //= g
      cnt += 1
    else:
      break
  if (flg(a)+cnt)%2 == 1:
    print("First")
  else:
    print("Second")

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


Question:
from collections import deque
def main():
    n, k = map(int, raw_input().split())
    s = raw_input().strip()
    ans = deque(list(s))
    if n == 1:
        if k % 2:
            print 'A' if s[0] == 'B' else 'B'
        else:
            print s[0]
        return
    f = True
    for i in xrange(400020):
        if i >= k:
            if f:
                print ''.join(list(ans))
            else:
                print ''.join('A' if x == 'B' else 'B' for x in ans)
            break
        if (ans[0] == 'A') == f:
            ans[0] = 'B' if f else 'A'
        else:
            f = not f
            ans.popleft()
            ans.append('A' if f else 'B')
    else:
        k -= 400020
        k %= 2
        if not f:
            ans = ['B' if x == 'A' else 'A' for x in ans]
            ans = deque(ans)
        if not k:
            if ans[0] == 'A':
                ans[0] = 'B'
            else:
                ans[0] = 'A'
        print ''.join(ans)
main()
from collections import deque
def main():
    n, k = map(int, raw_input().split())
    s = raw_input().strip()
    ans = deque(list(s))
    if n == 1:
        if k % 2:
            print 'A' if s[0] == 'B' else 'B'
        else:
            print s[0]
        return
    f = True
    for i in xrange(400020):
        if i >= k:
            if f:
                print ''.join(list(ans))
            else:
                print ''.join('A' if x == 'B' else 'B' for x in ans)
            break
        if (ans[0] == 'A') == f:
            ans[0] = 'B' if f else 'A'
        else:
            f = not f
            ans.popleft()
            ans.append('A' if f else 'B')
    else:
        k -= 400020
        k %= 2
        if not f:
            ans = ['B' if x == 'A' else 'A' for x in ans]
            ans = deque(ans)
        if not k:
            if ans[0] == 'A':
                ans[0] = 'B'
            else:
                ans[0] = 'A'
        print ''.join(ans)
main()

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


Question:
from collections import deque
def main():
    n, k = map(int, raw_input().split())
    s = raw_input().strip()
    ans = deque(list(s))
    if n == 1:
        if k % 2:
            print 'A' if s[0] == 'B' else 'B'
        else:
            print s[0]
        return
    f = True
    for i in xrange(800020):
        if i >= k:
            if f:
                print ''.join(list(ans))
            else:
                print ''.join('A' if x == 'B' else 'B' for x in ans)
            break
        if (ans[0] == 'A') == f:
            ans[0] = 'B' if f else 'A'
        else:
            f = not f
            ans.popleft()
            ans.append('A' if f else 'B')
    else:
        k -= 800020
        k %= 2
        if not f:
            ans = ['B' if x == 'A' else 'A' for x in ans]
            ans = deque(ans)
        if k:
            if ans[0] == 'A':
                ans[0] = 'B'
            else:
                ans[0] = 'A'
        print ''.join(ans)
main()
from collections import deque
def main():
    n, k = map(int, raw_input().split())
    s = raw_input().strip()
    ans = deque(list(s))
    if n == 1:
        if k % 2:
            print 'A' if s[0] == 'B' else 'B'
        else:
            print s[0]
        return
    f = True
    for i in xrange(800020):
        if i >= k:
            if f:
                print ''.join(list(ans))
            else:
                print ''.join('A' if x == 'B' else 'B' for x in ans)
            break
        if (ans[0] == 'A') == f:
            ans[0] = 'B' if f else 'A'
        else:
            f = not f
            ans.popleft()
            ans.append('A' if f else 'B')
    else:
        k -= 800020
        k %= 2
        if not f:
            ans = ['B' if x == 'A' else 'A' for x in ans]
            ans = deque(ans)
        if k:
            if ans[0] == 'A':
                ans[0] = 'B'
            else:
                ans[0] = 'A'
        print ''.join(ans)
main()

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


Question:
from sys import stdin
from collections import deque
n = int(stdin.readline())
a = map(int, stdin.readline().split())
a.sort()
f = 1
q = deque(a)
t = 1
while 1:
    if len(q) == 1:
        f = (q[0] - t + 1) & 1 ^ 1
        break
    if t == q[0] == q[-1]:
        f = len(q) & 1 ^ 1
        break
    x = q.pop()
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.append(x)
    while q and q[0] == t:
        q.popleft()
    t += 1
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.pop()
    if not q:
        f = 0
        break
print "First" if f else "Second"
from sys import stdin
from collections import deque
n = int(stdin.readline())
a = map(int, stdin.readline().split())
a.sort()
f = 1
q = deque(a)
t = 1
while 1:
    if len(q) == 1:
        f = (q[0] - t + 1) & 1 ^ 1
        break
    if t == q[0] == q[-1]:
        f = len(q) & 1 ^ 1
        break
    x = q.pop()
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.append(x)
    while q and q[0] == t:
        q.popleft()
    t += 1
    if len(q) == 1 and (q[0] - t + 1) & 1:
        f = 1
        break
    if t == q[0] == q[-1] and len(q) & 1:
        f = 1
        break
    q.pop()
    if not q:
        f = 0
        break
print "First" if f else "Second"

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


Question:
a = map(int, stdin.readline().split())
a.sort()
def f(j, t):
    global n
    for i in xrange(j, n):
        if a[i] != a[j]:
            break
    else:
        i = n
    x = (a[j] - t) & 1
    y = (i - j) & 1
    if i == n:
        return x ^ y
    elif (a[j] - t) == 1:
        return not f(i, a[j])
    else:
        return x ^ y ^ ((n - i) & 1)
print "First" if f(0, 0) else "Second"

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


Question:
import sys
from itertools import accumulate
from collections import deque

def solve():
    N, K = map(int, input().split())
    S = input()
    q = deque([1 if c == 'A' else 0 for c in S])
    cb = 1

    for i in range(K):
        if q[0] == cb:
            q[0] ^= 1
            # cb ^= 1
        else:
            q.popleft()
            q.append(cb ^ 1)
            cb ^= 1

    # print(q)

    ans = ['A' if (c ^ cb ^ 1) else 'B' for c in q]
    print(''.join(ans))

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

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


Question:
def run(K):
    n = 0
    trouts = []
    div = 0
    for i in range(2, 500):
        if K % (i**2) == 0:
            div = i
            break
    if K <= 500:
        for i in range(K):
            n = K
            trouts.append([i+1]*K)
    else:
        n = div
        cnt = K // div
        for i in range(cnt):
            trouts.append([j+1 for j in range(i*div, (i+1)*div)]*(K//(div**2)))
    return (n, trouts)

def main():
    K = int(input())
    n, trouts = run(K)
    print(n)
    for i in range(len(trouts)):
        print(' '.join(map(str, trouts[i])))

if __name__ == '__main__':
    main()

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


Question:
K  = int(input())
n = 0
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0

#Kが500以下の場合、斜め作戦にする
if K <= 500:
   n = K
   mat = [[0 for n1 in range(K)] for n2 in range(K)]
   for n1 in range(K):
      for n2 in range(K-n1):
         mat[n1][n1+n2] = n2+1
   for n1 in range(K):
      for n2 in range(n1):
         mat[n1][n2] = K+n2-n1+1

#Kが500以上の場合、斜めに1マスずつしのびこませる
else:
   n = 500
   mat = [[0 for n1 in range(500)] for n2 in range(500)]
   for n1 in range(500):
      for n2 in range(500-n1):
         mat[n1][n1+n2] = n2+1
   for n1 in range(500):
      for n2 in range(n1):
         mat[n1][n2] = 500+n2-n1+1

#行列の出力かんがえとく
print(n)

if K <= 500:
out = ""
for n1 in range(K):
   out = ""
   for n2 in range(K):
      out = out + " " + str(mat[n1][n2])
   print(out)
#Kが500以上の場合、斜めに1マスずつしのびこませる
else:
out = ""
for n1 in range(500):
   out = ""
   for n2 in range(500):
      out = out + " " + str(mat[n1][n2])
   print(out)

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


Question:
K  = int(input())
n = 0
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0

#Kが500以下の場合、斜め作戦にする
if K <= 500:
   n = K
   mat = [[0 for n1 in range(K)] for n2 in range(K)]
   for n1 in range(K):
      for n2 in range(K-n1):
         mat[n1][n1+n2] = n2+1
   for n1 in range(K):
      for n2 in range(n1):
         mat[n1][n2] = K+n2-n1+1

#Kが500以上の場合、斜めに1マスずつしのびこませる
else:
   n = 500
   mat = [[0 for n1 in range(500)] for n2 in range(500)]
   for n1 in range(500):
      for n2 in range(500-n1):
         mat[n1][n1+n2] = n2+1
   for n1 in range(500):
      for n2 in range(n1):
         mat[n1][n2] = 500+n2-n1+1

#行列の出力かんがえとく
print(n)
out = ""
for n1 in range(K):
   out = ""
   for n2 in range(K):
      out = out + " " + str(mat[n1][n2])
   print(out)

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


Question:
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 1
  prev_W = B
  for i in range(1, N+1):
    if i in g:
      W = (W * pow(B, i-prev_i, M)) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, prev_W = i, W

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 1
  prev_W = B
  for i in range(1, N+1):
    if i in g:
      W = (B * pow(B, prev_i-i, M)) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, prev_W = i, W

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  prev_i = N
  prev_W = pow(B, N, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      W = inv_mod(pow(B, prev_i-i, M), prev_W, M)
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, prev_W = i, W

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(input())

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  e = set(e)
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  x = 1
  for i in range(1, N+1):
    x = (x * B) % M
    if g[i]:
      sum_g[g[i]] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret += (sx*sy*sz) % M
  return ret%M

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  x = 1
  for i in range(1, N+1)
    x = (x * B) % M
    if g[i]:
      sum_g[g[i]] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret += (sx*sy*sz) % M
  return ret%M

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

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


Question:
import sys
from collections import Counter

# sys.stdin = open('c1.in')

def read_int_list():
    return list(map(int, input().split()))

def read_int():
    return int(input())

def read_str_list():
    return input().split()

def read_str():
    return input()

def vanish(p, details=False):
    while p:
        if details:
            print(p)
        n = len(p)
        q = [x for x in p if x != n]
        if len(q) == len(p):
            return False
        p = q[:]
    return True

def check(n):
    if n == 3:
        for i in range(1, n+1):
            for j in range(i, n+1):
                for k in range(j, n+1):
                    p = [i, j, k]
                    if vanish(p):
                        print(p)
                        # print()
                        # vanish(p, details=True)
    if n == 5:
        for i in range(1, n+1):
            for j in range(i, n+1):
                for k in range(j, n+1):
                    for l in range(k, n+1):
                        p = [i, j, k, l]
                        if vanish(p):
                            print(p)
                            # print()
                            # vanish(p, details=True)
    if n == 5:
        for i in range(1, n+1):
            for j in range(i, n+1):
                for k in range(j, n+1):
                    for l in range(k, n+1):
                        for m in range(l, n+1):
                            p = [i, j, k, l, m]
                            if vanish(p):
                                print(p)
                                # print()
                                # vanish(p, details=True)

def solve():
    # check(3)
    # check(4)
    # check(5)
    n, m = read_int_list()
    a = read_int_list()
    p = [read_int_list() for _ in range(m)]
    c = Counter(a)
    res = []
    for x, y in p:
        c[a[x-1]] -= 1
        a[x-1] = y
        c[a[x-1]] += 1
        covered = set(range(n))
        for i, ni in c.items():
            for j in range(i - ni, i):
                if j in covered:
                    covered.remove(j)
        r = len(covered)
        res.append(r)
    return '\n'.join(map(str, res))

def main():
    res = solve()
    print(res)

if __name__ == '__main__':
    main()

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


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

def encode(v, p):
    res = []
    tmp = []
    l = 0
    P = []
    def edfs(v, p):
        res = [0]
        cs = []
        for w in G[v]:
            if w == p:
                continue
            cs.append(edfs(w, v))
        cs.sort()
        for c in cs:
            res.extend(c)
        res.append(1)
        return res
    E = edfs(v, p)
    return E

def calc(E):
    st = []
    C = [0]
    P = []
    L = len(E)
    l = 0
    for i in range(L):
        if i and E[i-1] < E[i]:
            l += 1
        if E[i] == 0:
            st.append(i)
            P.append(None)
        else:
            j = st.pop()
            P.append(i)
            #P[i] = j
            P[j] = i
        C.append(l)
    return C, P

INF = 10**9
def merge(e1, e2):
    l1 = len(e1); l2 = len(e2)
    dp = [[0] * (l1+1) for i in range(l2+1)]

    C1, P1 = calc(e1)
    C2, P2 = calc(e2)

    prev = {}
    memo = {}
    def dfs(x, y):
        if (x, y) in memo:
            return memo[x, y]
        if x == l1 and y == l2:
            return 0
        res = INF
        p = None
        if x < l1 and y < l2 and e1[x] == e2[y]:
            r = dfs(x+1, y+1) + max(C1[x+1]-C1[x], C2[y+1]-C2[y])
            if r < res:
                res = r
                p = (x+1, y+1)
        if x < l1 and e1[x] == 0:
            r = dfs(P1[x]+1, y) + C1[P1[x]+1] - C1[x]
            if r < res:
                res = r
                p = (P1[x]+1, y)
        if y < l2 and e2[y] == 0:
            r = dfs(x, P2[y]+1) + C2[P2[y]+1] - C2[y]
            if r < res:
                res = r
                p = (x, P2[y]+1)
        memo[x, y] = res
        prev[x, y] = p
        return res
    prev[0, 0] = (0, 0)
    r = dfs(0, 0)
    v = (0, 0)
    res = []
    while v != (l1, l2):
        print(v)
        px, py = v
        x, y = v = prev[v]
        if px != x and py != y:
            res.append(e1[px])
        elif px != x:
            res.extend(e1[px:x])
        else:
            res.extend(e2[py:y])
    print(res)
    return r, res

from collections import deque
def bfs(v, p=-1):
    que = deque([v])
    dist = {v: 0, p: 0}
    prev = {}
    while que:
        u = que.popleft()
        d = dist[u]
        for w in G[u]:
            if w not in dist:
                dist[w] = d + 1
                prev[w] = u
                que.append(w)
    w = u
    res = []
    while w != v:
        res.append(w)
        w = prev[w]
    res.append(v)
    return u, res
def solve(u, v):
    if bfs(u, v) > (L+1)//2 < bfs(v, u):
        return 10**9
    E1 = encode(u, v)
    E2 = encode(v, u)
    #print(u, v, E1, E2)
    return merge(E1, E2)[0]*2
def vsolve(v):
    if bfs(u) > (L+1)//2:
        return 10**9
    E0 = encode(G[v][0], v)
    for w in G[v][1:]:
        E1 = encode(w, w)
        _, E0 = merge(E0, E1)
    C, P = calc(E0)
    #print(v, G[v][0], E0, C[-1], len(G[v]))
    return C[-1]*len(G[v])
v, _ = bfs(0)
w, D = bfs(v)
L = len(D)

col = (L + 1) // 2

ans = 10**18
for a, b in E9:
    ans = min(ans, solve(a, b))
for v in range(N):
    ans = min(ans, vsolve(v))
print(col, ans)

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


Question:
n,a,b=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0]
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=sorted(a),sorted(b)
if na!=nb:
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if a[i]!=b[i]:
		f[a[i]]=a[i]
f[a[n]]=a[n]
for i in range(n):
	if a[i]!=b[i]:
		ans+=1
		f[find(b[i])]=find(a[i])
for i,j in f:
	if i==j:
		ans+=1
print(ans-1)

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


Question:
n,a,b=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0]
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=sorted(a),sorted(b)
if sum([na[i]!=nb[i] for i in range(n+1)]):
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if a[i]!=b[i]:
		f[a[i]]=a[i]
f[a[n]]=a[n]
for i in range(n):
	if a[i]!=b[i]:
		ans+=1
		f[find(b[i])]=find(a[i])
for i,j in f:
	if i==j:
		ans+=1
print(ans-1)

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


Question:
n,a,b,ax,bx=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0],0,0
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
na,nb=a,b
a,b=sorted(a),sorted(b)
if sum([a[i]!=b[i] for i in range(n+1)]):
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if na[i]!=nb[i]:
		f[na[i]]=na[i]
f[na[n]]=na[n]
for i in range(n):
	if na[i]!=nb[i]:
		ans+=1
		f[find(nb[i])]=find(na[i])
for i,j in f:
	if i==j:
		ans+=1
print(ans-1)

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


Question:
n,a,b,ax,bx=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0],0,0
na,nb=a,b
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
a,b=sorted(a),sorted(b)
if sum([a[i]!=b[i] for i in range(n+1)]):
	print("-1")
	exit()
f=dict()
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
ans=0
for i in range(n):
	if na[i]!=nb[i]:
		f[na[i]]=na[i]
f[a[n]]=a[n]
for i in range(n):
	if na[i]!=nb[i]:
		ans+=1
		f[find(nb[i])]=find(na[i])
for i,j in f:
	if i==j:
		ans+=1
print(ans-1)

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


Question:
n,a,b,ax,bx=int(input()),list(map(int,input().split()))+[0],list(map(int,input().split()))+[0],0,0
na,nb=a,b
for i in range(n):
	a[n]^=a[i]
	b[n]^=b[i]
a,b=sorted(a),sorted(b)
if sum([a[i]!=b[i] for i in range(n+1)]):
	print("-1")
	exit()
mp=dict()
ax,bx=0,0
f=[i for i in range(n+1)]
def find(x):
	if f[x]==x:
		return x
	else:
		return find(f[x])
for i in range(n+1):
	mp[a[i]]=i
frog=True
for i in range(n):
	if na[i]!=nb[i]:
		frog=False
		f[find(mp[nb[i]])]=find(mp[na[i]])
if frog:
	print("0")
	exit()
st=set()
for i in range(n+1):
	st.add(find(mp[a[i]]))
print(n+len(st)-1)

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


Question:
n,k=map(int,input().split())
s=list(input())*2
p=['A' if s[i]=='B' else 'B' for i in range(n)]*2
head,tail=0,n
for i in range(2*n):
	if s[0]=='A':
		s[0],p[0]='B','A'
	else:
		s,p=p,s
		head+=1
		s[tail],p[tail]='A','B'
		tail+=1
	if i==k-1:
		print(''.join(s[head:tail]))
		break
else:
	if n%2==1 and k%2==1:
		if s[0]=='A':
			s[0],p[0]='B','A'
		else:
			s,p=p,s
			head+=1
			s[tail],t[tail]='A','B'
			tail+=1
	print(''.join(s[head:tail]))

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


Question:
n,k=map(int,input().split())
s,p=list(input()),""
def proc(t):
	return ['B']+t[1:] if t[0]=='A' else ['A' if t[i]=='B' else 'B' for i in range(1,n)]+['A']
for i in range(2*n):
	s=proc(s)
	if i==k-1:
		print(''.join(s))
		break
else:
	if n%2==1 and k%2==1:
		s=proc(s)
	print(''.join(s))

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


Question:
n,k=map(int,input().split())
s,p=list(input()),""
for i in range(k):
	cur,d,p,p2=0,1,str(s),p
	while cur>=0 and cur<n:
		if s[cur]=='A':
			s[cur]='B'
			d=-d
			cur+=d
		else:
			s[cur]='A'
			cur+=d
	if str(s)==p:
		print(''.join(s))
		break
	elif str(s)==p2:
		if k%2==i%2:
			print(''.join(s))
		else:
			print(''.join(filter(lambda x:x=='A' or x=='B',list(p))))
		break
else:
	print(''.join(s))

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


Question:
n,k=map(int,input().split())
s=list(input())
for i in range(k):
	cur,d,p=0,1,str(s)
	while cur>=0 and cur<n:
		if s[cur]=='A':
			s[cur]='B'
			d=-d
			cur+=d
		else:
			s[cur]='A'
			cur+=d
	if str(s)==p:
		break
print(''.join(s))

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


Question:
n, m=map(int, raw_input().split())
a=map(int, raw_input().split())
for i in range(m):
	x, y=map(int, raw_input().split())
	a[x-1]=y
	cnt=[0]*(n+1)
	for j in a:
		cnt[j]+=1
	cover=[0]*(n+1)
	result=0
	for j in range(n+1):
		for k in range(min(cnt[j], j)):
			cover[j-k]+=1
	result+=cover.count(0)-1
	print result

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


Question:
a=bin(input()+(1<<60))[2:]
b=bin(input()+(1<<60))[2:]
while a[0]==b[0]:
	a=a[1:]
	b=b[1:]
assert a[0]=="0" and b[0]=="1"
result=int("1"+"0"*(len(a)-1), 2)-int(a, 2)
b=b[1:]
while b and b[0]=="0":
	b=b[1:]
if not b:
	result=result*2+1
else:
	b="1"*len(b)
	if int(b, 2)>=int(a, 2):
		result+=(1<<(len(a)-1))
	else:
		result=result*2+int(b, 2)+1
print result

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


Question:
import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              # [A,2^t-1]
    r = t-1
    while 2**t + 2**r > B:
        r-=1
    # [2^t,2^t+2^{r+1}-1] \cup [2^t+A,2^{t+1}-1]
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t

print(ans)

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


Question:
n = input()
A = sorted(map(int, raw_input().split()), reverse=True)

x = 0
y = 0

def is_lose(x, y):
    return x >= n or y >= A[x]

while not is_lose(x+1, y+1):
    x += 1
    y += 1

x_ = x
count_x = 0
while not is_lose(x_+1, y):
    x_ += 1
    count_x += 1

y_ = y
count_y = 0
while not is_lose(x, y_+1):
    y_ += 1
    count_y += 1

if (count_x%2 == 0) and (count_y%2 == 0):
    print "Second"
else:
    print "First"

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


Question:
N = int(input())
z,w = [],[]
K = 0
for i in range(N):
  x,y = map(int,input().split())
  z.append(x)
  w.append(y)
for j in range(N-2):
  if z[j] == w[j] and z[j+1] == w[j+1] and z[j+2] == w[j+2]:
    K += 1

if K >= 1:
  print("Yes")
else:
  print("No")

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


Question:
N = int(input())
z,w = [],[]
K = 0
for i in range(N):
  x,y = map(int,input().split())
  z.append(x)
  w.append(y)
for j in range(N-2):
  if z[j] == w[j] and z[j+1] == w[j+1] and z[j+2] == w[j+2]:
    K += 1

if K >= 1:
  print("Yes")
else:
  print("No")

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


Question:
x = int(input())
if x == 0:
  print(1)
else:
  print(0)

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


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

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


Question:
#ABC134 C (再考察)

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

AA = sorted(A,reverse = True)
for i in range(N):
    if A[i] != AA[0]:
        print(AA[0])
    else:
        print(AA[1])

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


Question:
#ABC132 A

S = str(input())
T = [S[0],S[1],S[2],S[3]]
T.sort()
if T[0] == T[1] and T[2] == T[3] and T[1] != T[2]:
    print("Yes")
else:
    print("No")

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


Question:
#ABC132 A

S = str(input())
T = [S[0],S[1],S[2],S[3]]
T.sort()
if T[0] == T[1] and T[2] == T[3] and T[1] != T[2]:
    print("Yes")
else:
    print("No")

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


Question:
#ABC132 A

S = str(input())
T = [S[0],S[1],S[2],S[3]]
T.sort()
if T[0] == T[1] and T[2] == T[3] and T[1] != T[2]:
    print("Yes")
else:
    print("No")

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


Question:
#ABC132 B

n = int(input())
P = list(map(int,input().split()))
K = 0
for i in range(n-2):
    if (P[i] < P[i+1] and P[i+1] < P[i+2]) or (P[i+2] < P[i+1] and P[i+1] < P[i]):
        K += 1

print(K)

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


Question:
#ABC132 B

n = int(input())
P = list(map(int,input().split()))
K = 0
for i in range(n-2):
    if (P[i] < P[i+1] and P[i+1] < P[i+2]) or (P[i+2] < P[i+1] and P[i+1] < P[i]):
        K += 1

print(K)

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


Question:
W,H,x,y = map(int,input().split())
if x == W/2 and y == H/2:
    a = 1
else:
    a = 0
print(W*H/2,a)

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


Question:
W,H,x,y = map(int,input().split())
if x == W/2 and y == H/2:
    a = 1
else:
    a = 0
print(W*H/2,a)

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


Question:
N,K = map(int,input().split())
S = str(input())
T = list(map(str,S))

for i in range(N):
    if i == K-1:
        T[i] = str.lower(T[i])

print("".join(T))

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


Question:
n = int(input())
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)

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


Question:
n = int(input())
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)

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


Question:
n = int(input())
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)

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


Question:
n=int(input())

a,b=input().split()
a=a[:n]
b=b[:n]
n=0
for i in a:
	print(a[n],end='')
	print(b[n],end='')
	n+=1
print()

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


Question:
str1, str2 = input().split()
num1, num2 = map(int,input().split())
trim = input()

if trim == str1:
	num1 = num1 - 1
else:
  	num2 = num2 - 1

print("%d %d"  %(num1, num2))

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


Question:
str1, str2 = input().split()
num1, num2 = map(int,input().split())
trim = input()

if trim == str1:
	num1 = num1 - 1
else:
  	num2 = num2 - 1

print("%d %d"  %(num1, num2))

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


Question:
n = int(input())
list = list(map(int,input().split()))
count = 0
minimum = list[0]
for i in range(n):
  if minimum >= list[i]:
    count += 1
    minimum = list[i]

print("%d"%(count))

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


Question:
import sys
from itertools import accumulate

def main():
    input = sys.stdin.buffer.readline
    n, m, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    b = [0] + list(map(int, input().split()))
    a = list(accumulate(a))
    b = list(accumulate(b))
    ans = 0
    num_b = m
    for num_a in range(n + 1):
        sum_a = a[num_a]
        if sum_a > k:
            break
        while sum_a + b[num_b] > k:
            num_b -= 1
        ans = max(num_a + num_b, ans)
    print(ans)

if __name__ == '__main__':
    main()

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


Question:
import sys
MOD = 998244353

def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])

if __name__ == '__main__':
    main()

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


Question:
import sys
MOD = 998244353

def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])

if __name__ == '__main__':
    main()

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


Question:
import sys
MOD = 998244353

def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])

if __name__ == '__main__':
    main()

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


Question:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            fin = True
            break
        check[index] = count
        count += 1
        index = a[index]

if not fin:  # len(loop)<=K
    if (K + 1 - start) % len(loop[start:]) == 0:
        print(loop[-1] + 1)
    else:
        print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)

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


Question:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            fin = True
            break
        check[index] = count
        count += 1
        index = a[index]

if not fin:  # len(loop)<=K
    if (K + 1 - start) % len(loop[start:]) == 0:
        print(loop[-1] + 1)
    else:
        print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)

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


Question:
import sys
from math import factorial
input = sys.stdin.readline
N, M, K = map(int, input().split())
MOD = 998244353
inv = [1] * N
FAC = factorial(N - 1) % MOD
if M == 1:
    print(1 if K == N - 1 else 0)
else:
    res = 0
    for i in range(1, N):
        inv[i] = (inv[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    for k in range(K + 1):
        # k個の○とN-k-1個の|を並べる順列
        # punc = (N-1)!/k!/(N-k-1)!
        # punc = factorial(
        #     k + (N - k - 1)) // factorial(k) // factorial(N - k - 1)
        punc = FAC
        # punc *= pow(factorial(k), MOD - 2, MOD)
        punc *= inv[k]
        punc = punc % MOD
        # punc *= pow(factorial(N - k - 1), MOD - 2, MOD)
        punc *= inv[N - k - 1]
        punc = punc % MOD
        color = M * pow(M - 1, N - k - 1, MOD)
        res += ((punc % MOD) * color) % MOD
        res = res % MOD
    print(res % MOD)

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


Question:
import sys
from math import factorial
input = sys.stdin.readline
N, M, K = map(int, input().split())
MOD = 998244353
inv = [1] * N
FAC = factorial(N - 1) % MOD
if M == 1:
    print(1 if K == N - 1 else 0)
else:
    res = 0
    for i in range(1, N):
        inv[i] = (inv[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    for k in range(K + 1):
        # k個の○とN-k-1個の|を並べる順列
        # punc = (N-1)!/k!/(N-k-1)!
        # punc = factorial(
        #     k + (N - k - 1)) // factorial(k) // factorial(N - k - 1)
        punc = FAC
        # punc *= pow(factorial(k), MOD - 2, MOD)
        punc *= inv[k]
        punc = punc % MOD
        # punc *= pow(factorial(N - k - 1), MOD - 2, MOD)
        punc *= inv[N - k - 1]
        punc = punc % MOD
        color = M * pow(M - 1, N - k - 1, MOD)
        res += ((punc % MOD) * color) % MOD
        res = res % MOD
    print(res % MOD)

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


Question:
import sys
from math import factorial
input = sys.stdin.readline
N, M, K = map(int, input().split())
MOD = 998244353
inv = [1] * N
FAC = factorial(N - 1) % MOD
if M == 1:
    print(1 if K == N - 1 else 0)
else:
    res = 0
    for i in range(1, N):
        inv[i] = (inv[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    for k in range(K + 1):
        # k個の○とN-k-1個の|を並べる順列
        # punc = (N-1)!/k!/(N-k-1)!
        # punc = factorial(
        #     k + (N - k - 1)) // factorial(k) // factorial(N - k - 1)
        punc = FAC
        # punc *= pow(factorial(k), MOD - 2, MOD)
        punc *= inv[k]
        punc = punc % MOD
        # punc *= pow(factorial(N - k - 1), MOD - 2, MOD)
        punc *= inv[N - k - 1]
        punc = punc % MOD
        color = M * pow(M - 1, N - k - 1, MOD)
        res += ((punc % MOD) * color) % MOD
        res = res % MOD
    print(res % MOD)

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


Question:
import sys

def main():
    input = sys.stdin.buffer.readline
    h, n = map(int, input().split())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    max_a = max(a)
    # dp[j]:jダメージ与える魔力の最小値
    dp = [1e9] * (h + max_a + 1)
    dp[0] = 0
    for i in range(n):
        for j in range(1, h + max_a + 1):
            dp[j] = min(dp[j], dp[max(j - a[i], 0)] + b[i])
    print(min(dp[h:]))

if __name__ == "__main__":
    main()

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


Question:
import sys

def main():
    input = sys.stdin.buffer.readline
    h, n = map(int, input().split())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    max_a = max(a)
    # dp[j]:jダメージ与える魔力の最小値
    dp = [1e9] * (h + max_a + 1)
    dp[0] = 0
    for i in range(n):
        for j in range(1, h + max_a + 1):
            dp[j] = min(dp[j], dp[max(j - a[i], 0)] + b[i])
    print(min(dp[h:]))

if __name__ == "__main__":
    main()

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


Question:
from collections import Counter

def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = "".join(sorted(input()))
        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)

if __name__ == "__main__":
    main()

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


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

visit = [-1] * n   #到達しているかどうかを管理

D = [1]  # 循環するもののindexを格納

tmp = A[0]  #初期位置
ct = 1

while visit[tmp - 1] == -1:
    D.append(tmp)
    visit[tmp - 1] = ct  #到達済に変更
    if k == ct:
        print(tmp)
        exit()
    ct += 1
    tmp = A[tmp - 1]

#循環している場合の残りの処理
k -= visit[tmp - 1]
k %= (ct - visit[tmp - 1])
print(D[visit[tmp - 1] + k])

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


Question:
a, b, n = map(int, input().split())
y = 0
if n >= b:
    y = b - 1
else:
    y = n
print(int(a*y/b))

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


Question:
a, b, n = map(int, input().split())
y = 0
if n >= b:
    y = b - 1
else:
    y = n
print(int(a*y/b))

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


Question:
a, b, n = map(int, input().split())
y = 0
if n >= b:
    y = b - 1
else:
    y = n
print(int(a*y/b))

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


Question:
N = int(input())
S = [input() for _ in range(N)]
dict = {}
for i in range(N):
    if S[i] not in dict:
        dict[S[i]] = 1
print(len(dict))

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


Question:
S = input()

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")

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


Question:
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)

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


Question:
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)

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


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

t = N*500
if t >= K:
    print("Yes")
else:
    print("No")

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


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

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for  i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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


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

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for  i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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


Question:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

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


Question:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

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


Question:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

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


Question:
import math
ab = input()
ab = list(ab.split())
a, b = int(ab[0]), ab[1]
b = b[0] + b[2] + b[3]
b = int(b)

print(a * b // 100)

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


Question:
a = input()

A, B, C, K = map(int, a.split())

if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(2 * A + B - K)

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


Question:
from math import gcd
N=int(input())
A=list(map(int,input().split()))
g=gcd(A[0],A[1])
for i in A:
    g=gcd(g,i)
if g>1:
    print("not coprime")
    exit()
l=[0]*1000001
for i in A:
    l[i]+=1
for i in range(2,1000000):
    c=0
    for j in range(i,1000001,i):
        c+=l[j]
    if c>1:
        print("setwise coprime")
        break
else:
    print("pairwise coprime")

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


Question:
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
cx,cy=map(lambda x: int(x)+1,input().split())
dx,dy=map(lambda x: int(x)+1,input().split())
S=["#"*(W+4)]*2+["##"+input()+"##" for i in range(H)]+["#"*(W+4)]*2
l=[[-2]*(W+4) for i in range(H+4)]
for i in range(2,H+2):
    for j in range(2,W+2):
        if S[i][j]==".":
            l[i][j]=-1
l[cx][cy]=0
b=[(cx,cy)]
bb=[(cx,cy)]
t=0
while bb:
    while b:
        a=[]
        for i in b:
            if l[i[0]+1][i[1]]==-1:
                l[i[0]+1][i[1]]=t
                a.append((i[0]+1,i[1]))
            if l[i[0]-1][i[1]]==-1:
                l[i[0]-1][i[1]]=t
                a.append((i[0]-1,i[1]))
            if l[i[0]][i[1]+1]==-1:
                l[i[0]][i[1]+1]=t
                a.append((i[0],i[1]+1))
            if l[i[0]][i[1]-1]==-1:
                l[i[0]][i[1]-1]=t
                a.append((i[0],i[1]-1))
        bb+=a
        b=a
    aa=[]
    t+=1
    b=[]
    for i in bb:
        for j in range(-2,3):
            for k in range(-2,3):
                if l[i[0]+j][i[1]+k]==-1:
                    l[i[0]+j][i[1]+k]=t
                    aa.append((i[0]+j,i[1]+k))
                    b.append((i[0]+j,i[1]+k))
    if l[dx][dy]>=0:
        break
    bb=aa
print(l[dx][dy])

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