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

from heapq import heappop, heappush

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

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

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

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

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

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

flow = 0

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

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

cost = G.MinCost(flow)

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

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


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

from heapq import heappop, heappush

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

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

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

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

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

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

flow = 0

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

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

cost = G.MinCost(flow)

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

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


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

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

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


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

import itertools
import numpy as np

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

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

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

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

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

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

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

answer %= MOD
print(answer)

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


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

import itertools
import numpy as np

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

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

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

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

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

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

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

answer %= MOD
print(answer)

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


Question:
import sys
input = sys.stdin.readline

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

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

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

counter = [0] * (N+1)
covered = [0] * (N+N+10)
for a in A:
    counter[a] += 1
    covered[a-counter[a]+1] += 1
magic = sum(x==0 for x in covered[1:N+1])

for i,y in XY:
    x = A[i-1]
    A[i-1] = y
    rem = x - counter[x] + 1
    counter[x] -= 1
    counter[y] += 1
    add = y - counter[y] + 1
    covered[rem] -= 1
    if 1<=rem<=N and covered[rem] == 0:
        magic += 1
    if 1<=add<=N and covered[add] == 0:
        magic -= 1
    covered[add] += 1
    print(magic)

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


Question:
import sys
input = sys.stdin.readline

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

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

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

counter = [0] * (N+1)
covered = [0] * (N+N+10)
for a in A:
    counter[a] += 1
    covered[a-counter[a]+1] += 1
magic = sum(x==0 for x in covered[1:N+1])

for i,y in XY:
    x = A[i-1]
    A[i-1] = y
    rem = x - counter[x] + 1
    counter[x] -= 1
    counter[y] += 1
    add = y - counter[y] + 1
    covered[rem] -= 1
    if 1<=rem<=N and covered[rem] == 0:
        magic += 1
    if 1<=add<=N and covered[add] == 0:
        magic -= 1
    covered[add] += 1
    print(magic)

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


Question:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from functools import lru_cache

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

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

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

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

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


Question:
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

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

MOD = 10**9 + 7

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

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

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


Question:
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

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

MOD = 10**9 + 7

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

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

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


Question:
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

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

MOD = 10**9 + 7

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

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

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


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

import numpy as np

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

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

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

full = (1 << 60) - 1
uninity = [0] * (N+1)
dp = [0] * (N+1)
twice = [0] * (N+1)
for x in order[::-1]:
    p = parent[x]
    n = twice[x].bit_length() - 1
    if n >= 0:
        dp[x] |= (1 << (n+1)) - 1
    can_use = full & (~dp[x])
    lsb = can_use & (-can_use)
    uninity[x] = lsb
    dp[x] |= lsb
    dp[x] &= full & ~(lsb - 1)

    twice[p] |= (dp[x] & dp[p])
    dp[p] |= dp[x]

x = max(uninity)
answer = x.bit_length() - 1
print(answer)

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


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

import numpy as np

# どこかの長さKは最後に単色で残る
# そこを残すと決めると他は自由に設定できる

N,K = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)

Acum = A.cumsum()
range_sum = Acum[K-1:] - Acum[:N-(K-1)] + A[:N-(K-1)]

# 各地点を左端として、長さKの区間の合計を求める
Acum = A.cumsum()
range_sum = Acum[K-1:] - Acum[:N-(K-1)] + A[:N-(K-1)]
best = np.maximum(A,0)
best_cum = best.cumsum()
best_range_sum = best_cum[K-1:] - best_cum[:N-(K-1)] + best[:N-(K-1)]

min_loss = (best_range_sum - np.maximum(range_sum,0)).min()

answer = best.sum() - min_loss
print(answer)

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


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

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

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

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

V = set(range(N))

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

q

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

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

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


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

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

A.sort(reverse = True)

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

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

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

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


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

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

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

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

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

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

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


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

print(ans)

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


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

print(ans)

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


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

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

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

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


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

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

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

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


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

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

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

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


Question:
from operator import itemgetter

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

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

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

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


Question:
from operator import itemgetter

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

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

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

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


Question:
from operator import itemgetter

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

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

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

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


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

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

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


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

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

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

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

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

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

med=time.time()
#print(med-start)

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

print(ans)

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

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


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

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

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

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

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

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

med=time.time()
#print(med-start)

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

print(ans)

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

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


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

mod = 10**9+7 #出力の制限
N = 4*10**6
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

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

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

if K==1:
    print(1)
    exit()

dp=[0 for i in range(N+1)]
dp[N]=1

for i in range(N,-1,-1):
    for j in range(i-1,-1,-1):
        n=(N-(j+1))*(K-1)+N-i
        dp[j]+=(cmb(n+K-2,K-2,mod)*dp[j+1])%mod
        dp[j]%=mod

print((dp[0]*g1[N])%mod)

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


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

mod = 10**9+7 #出力の制限
N = 4*10**6
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

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

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

if K==1:
    print(1)
    exit()

dp=[0 for i in range(N+1)]
dp[N]=1

for i in range(N,-1,-1):
    for j in range(i-1,-1,-1):
        n=(N-(j+1))*(K-1)+N-i
        dp[j]+=(cmb(n+K-2,K-2,mod)*dp[j+1])%mod
        dp[j]%=mod

print((dp[0]*g1[N])%mod)

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


Question:
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)

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


Question:
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)

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


Question:
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)

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


Question:
n = int(input())
a = [int(input()) for _ in range(n)] + [0]
if a[0] > 0:
    print(-1)
else:
    ans = 0
    for i in range(n):
        if a[i] < a[i + 1] - 1:
            print(-1)
            break
        elif a[i] >= a[i + 1]:
            ans += a[i]
    else:
        print(ans)

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


Question:
N = input()
A = []
for i in xrange(N):
	A.append(input())
ans = 0
start = 0
for i in xrange(N):
	if A[i] > i - start:
		ans = -1
		break
	if A[i] > A[i-1] + 1:
		ans = -1
		break
	if i == 0:
		continue
	if A[i] == A[i - 1] + 1:
		ans += 1
		continue
	if A[i] == 0:
		start = i
		continue
	ans += A[i]
print ans

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


Question:
N = int(input()) - 1

LARGE = 10**9+7

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    return c0, a0, b0
# precompute
fac_list = [1]*(N+1)
fac = 1
for i in range(1, N+1):
    fac = (fac * i) % LARGE
    fac_list[i] = fac

fac_inv_list = [1]*(N+1)
for i in range(N+1):
    fac_inv_list[i] =  pow(fac_list[i], LARGE-2, LARGE)

def nCr(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE

def pat(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE

pat = 0
score = 0

for k in range(N+1):
    if k-1 >= N-k:
        res = (((fac_list[k-1]*fac_list[k]) % LARGE) * fac_inv_list[k-1-N+k]) % LARGE
        score = (score + (res - pat) * k) % LARGE
        # print(k, pat, res)
        pat = res
print(score)

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


Question:
N = int(input()) - 1

LARGE = 10**9+7

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    return c0, a0, b0
# precompute
fac_list = [1]*(N+1)
fac = 1
for i in range(1, N+1):
    fac = (fac * i) % LARGE
    fac_list[i] = fac

fac_inv_list = [1]*(N+1)
for i in range(N+1):
    fac_inv_list[i] =  pow(fac_list[i], LARGE-2, LARGE)

def nCr(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE

def pat(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE

pat = 0
score = 0

for k in range(N+1):
    if k-1 >= N-k:
        res = (((fac_list[k-1]*fac_list[k]) % LARGE) * fac_inv_list[k-1-N+k]) % LARGE
        score = (score + (res - pat) * k) % LARGE
        # print(k, pat, res)
        pat = res
print(score)

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


Question:
# D
res = 0

A = int(input())
B = int(input())

def pow2_floor_log2(x):
    res = 1
    while res*2 <= x:
        res *= 2
    return res

if A == B:
    res += 1

while A < B:
    # find log2A and log2B
    C = pow2_floor_log2(B)
    if A < C:
        # A to C
        res += C - A
        if B > C:
            B_ = C + pow2_floor_log2(B - C)*2 - 1
        else:
            B_ = C
        if C + A <= B_:
            res += C
            break
        else:
            res += (C - A) + (B_ - C + 1)
            break
    else:
        A -= C
        B -= C

print(res)

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


Question:
# D
res = 0

A = int(input())
B = int(input())

def pow2_floor_log2(x):
    res = 1
    while res*2 <= x:
        res *= 2
    return res

if A == B:
    res += 1

while A < B:
    # find log2A and log2B
    C = pow2_floor_log2(B)
    if A < C:
        # A to C
        res += C - A
        if B > C:
            B_ = C + pow2_floor_log2(B - C)*2 - 1
        else:
            B_ = C
        if C + A <= B_:
            res += C
            break
        else:
            res += (C - A) + (B_ - C + 1)
            break
    else:
        A -= C
        B -= C

print(res)

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


Question:
s = input()
a = 10000
for i in range(0, 26):
  n = 0
  t = 0
  b = True
  for j in range(0, len(s)):
    if s[j] != chr(ord("a")+i):
      t += 1
    elif b:
      n = max(n, t)
      t = 0
    else:
      n = max(n, (t+1)//2)
      t = 0
  n = max(n, t)
  a = min(a, n)
print(a)

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


Question:
from math import gcd

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

class Seg_min():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10
        self.func = min

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

class Seg_max():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10 * -1
        self.func = max

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

# aの最大値のindexを取得
max_ind = 0
max_num = -1
for ind,i in enumerate(a):
    if(i > max_num):
        max_ind = ind
        max_num = i

# max_ind が先頭になるように順番を変更
a = a[max_ind:] + a[:max_ind]
b = b[max_ind:] + b[:max_ind]

# Aiが小さい順に探索する。その順番を取得しておく。
order = [(i,ind) for ind,i in enumerate(a)]
order.sort()

# 累積和を作る。
# cs1は普通のBiの累積和
# cs2はi*Biの累積和
cs1_l = [0] * (n)
cs2_l = [0] * (n)
cs1_r = [0] * (n+1)
cs2_r = [0] * (n+1)

for i in range(1,n):
    cs1_l[i] = cs1_l[i-1] + b[i]
    cs2_l[i] = cs2_l[i-1] + b[i]*i

for i in range(1,n):
    cs1_r[-(i+1)] = cs1_r[-i] + b[-i]
    cs2_r[-(i+1)] = cs2_r[-i] + b[-i]*i

# 1週して戻ってくる点を追加しておく
a.append(a[0])
b.append(b[0])

# ゲームを終了する位置を記録・取得するためにセグ木を使う
seg_left = Seg_max( list(range(n+1)) )
seg_right = Seg_min( list(range(n+1)) )

# すべての点について、終了するかしないかを記録しておく。
end = [1] * (n+1)
# end[0] = 1
# end[-1] = 1

# 終了しない場合の期待値計算の関数
def calc_ex(ind):
    left = seg_left.query(0,ind)
    right = seg_right.query(ind+1,n+1)

    div = right - left
    wid_l = ind-left
    wid_r = right-ind
    # left-ind
    base = cs2_l[ind] - cs2_l[left] - (cs1_l[ind] - cs1_l[left])*left
    ex_l = base*2 * wid_r

    # ind-right
    base = cs2_r[ind] - cs2_r[right] - (cs1_r[ind] - cs1_r[right])*(n-right)
    ex_r = base*2 * wid_l

    ex = -ex_l - ex_r + b[ind]*wid_l*wid_r*2 + a[left]*wid_r + a[right]*wid_l

    return ex,div

# Aiが小さい順に期待値計算をして、終了するかどうか判断。
# A0は絶対に終了すべきなのでskip
order = [j for i,j in order][::-1]
flag = True
while(flag):
    flag = False
    while(order):
        ind = order.pop()
        if(ind==0):
            continue
        if(end[ind]==0):
            continue

        ex,div = calc_ex(ind)
        if(a[ind]*div < ex):
            end[ind] = 0
            seg_left.update(ind,0)
            seg_right.update(ind,n)

            left = seg_left.query(0,ind)
            right = seg_right.query(ind+1,n+1)
            if(left!=0):
                order.append(left)
            if(right!=n):
                order.append(right)
            flag = True

    if(flag):
        for i,val in enumerate(end[:-1]):
            if(val==1):
                order.append(i)

# 終了すべきポイントがわかったので期待値合計を計算
ans = [0] * (n)
for ind,flag in enumerate(end[:-1]):
    if(flag==1):
        ans[ind] = (a[ind],1)
    else:
        ex,div = calc_ex(ind)
        ans[ind] = (ex,div)

lcm = 1
for ex,div in ans:
    lcm = (lcm*div)//gcd(lcm,div)

ans_num = 0
for ex,div in ans:
    ans_num += ex*(lcm//div)

print(ans_num/(lcm*n))

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


Question:
from math import gcd

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

class Seg_min():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10
        self.func = min

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

class Seg_max():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10 * -1
        self.func = max

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

# aの最大値のindexを取得
max_ind = 0
max_num = -1
for ind,i in enumerate(a):
    if(i > max_num):
        max_ind = ind
        max_num = i

# max_ind が先頭になるように順番を変更
a = a[max_ind:] + a[:max_ind]
b = b[max_ind:] + b[:max_ind]

# Aiが小さい順に探索する。その順番を取得しておく。
order = [(i,ind) for ind,i in enumerate(a)]
order.sort()

# 累積和を作る。
# cs1は普通のBiの累積和
# cs2はi*Biの累積和
cs1_l = [0] * (n)
cs2_l = [0] * (n)
cs1_r = [0] * (n+1)
cs2_r = [0] * (n+1)

for i in range(1,n):
    cs1_l[i] = cs1_l[i-1] + b[i]
    cs2_l[i] = cs2_l[i-1] + b[i]*i

for i in range(1,n):
    cs1_r[-(i+1)] = cs1_r[-i] + b[-i]
    cs2_r[-(i+1)] = cs2_r[-i] + b[-i]*i

# 1週して戻ってくる点を追加しておく
a.append(a[0])
b.append(b[0])

# ゲームを終了する位置を記録・取得するためにセグ木を使う
seg_left = Seg_max( list(range(n+1)) )
seg_right = Seg_min( list(range(n+1)) )

# すべての点について、終了するかしないかを記録しておく。
end = [1] * (n+1)
# end[0] = 1
# end[-1] = 1

# 終了しない場合の期待値計算の関数
def calc_ex(ind):
    left = seg_left.query(0,ind)
    right = seg_right.query(ind+1,n+1)

    div = right - left
    wid_l = ind-left
    wid_r = right-ind
    # left-ind
    base = cs2_l[ind] - cs2_l[left] - (cs1_l[ind] - cs1_l[left])*left
    ex_l = base*2 * wid_r

    # ind-right
    base = cs2_r[ind] - cs2_r[right] - (cs1_r[ind] - cs1_r[right])*(n-right)
    ex_r = base*2 * wid_l

    ex = -ex_l - ex_r + b[ind]*wid_l*wid_r*2 + a[left]*wid_r + a[right]*wid_l

    return ex,div

# Aiが小さい順に期待値計算をして、終了するかどうか判断。
# A0は絶対に終了すべきなのでskip
order = [j for i,j in order][::-1]
flag = True
while(flag):
    flag = False
    while(order):
        ind = order.pop()
        if(ind==0):
            continue
        if(end[ind]==0):
            continue

        ex,div = calc_ex(ind)
        if(a[ind]*div < ex):
            end[ind] = 0
            seg_left.update(ind,0)
            seg_right.update(ind,n)

            left = seg_left.query(0,ind)
            right = seg_right.query(ind+1,n+1)
            if(left!=0):
                order.append(left)
            if(right!=n):
                order.append(right)
            flag = True

    if(flag):
        for i,val in enumerate(end[:-1]):
            if(val==1):
                order.append(i)

# 終了すべきポイントがわかったので期待値合計を計算
ans = [0] * (n)
for ind,flag in enumerate(end[:-1]):
    if(flag==1):
        ans[ind] = (a[ind],1)
    else:
        ex,div = calc_ex(ind)
        ans[ind] = (ex,div)

lcm = 1
for ex,div in ans:
    lcm = (lcm*div)//gcd(lcm,div)

ans_num = 0
for ex,div in ans:
    ans_num += ex*(lcm//div)

print(ans_num/(lcm*n))

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()))
b = list(map(int,input().split()))

class Seg_min():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10
        self.func = min

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

class Seg_max():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 10**10 * -1
        self.func = max

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

# aの最大値のindexを取得
max_ind = 0
max_num = -1
for ind,i in enumerate(a):
    if(i > max_num):
        max_ind = ind
        max_num = i

# max_ind が先頭になるように順番を変更
a = a[max_ind:] + a[:max_ind]
b = b[max_ind:] + b[:max_ind]

# Aiが小さい順に探索する。その順番を取得しておく。
order = [(i,ind) for ind,i in enumerate(a)]
order.sort()

# 累積和を作る。
# cs1は普通のBiの累積和
# cs2はi*Biの累積和
cs1_l = [0] * (n)
cs2_l = [0] * (n)
cs1_r = [0] * (n+1)
cs2_r = [0] * (n+1)

for i in range(1,n):
    cs1_l[i] = cs1_l[i-1] + b[i]
    cs2_l[i] = cs2_l[i-1] + b[i]*i

for i in range(1,n):
    cs1_r[-(i+1)] = cs1_r[-i] + b[-i]
    cs2_r[-(i+1)] = cs2_r[-i] + b[-i]*i

# 1週して戻ってくる点を追加しておく
a.append(a[0])
b.append(b[0])

# ゲームを終了する位置を記録・取得するためにセグ木を使う
seg_left = Seg_max( list(range(n+1)) )
seg_right = Seg_min( list(range(n+1)) )

# すべての点について、終了するかしないかを記録しておく。
end = [1] * (n+1)
# end[0] = 1
# end[-1] = 1

# 終了しない場合の期待値計算の関数
def calc_ex(ind):
    left = seg_left.query(0,ind)
    right = seg_right.query(ind+1,n+1)

    div = right - left
    wid_l = ind-left
    wid_r = right-ind
    # left-ind
    base = cs2_l[ind] - cs2_l[left] - (cs1_l[ind] - cs1_l[left])*left
    ex_l = base*2 * wid_r

    # ind-right
    base = cs2_r[ind] - cs2_r[right] - (cs1_r[ind] - cs1_r[right])*(n-right)
    ex_r = base*2 * wid_l

    ex = -ex_l - ex_r + b[ind]*wid_l*wid_r*2 + a[left]*wid_r + a[right]*wid_l

    return ex,div

# Aiが小さい順に期待値計算をして、終了するかどうか判断。
# A0は絶対に終了すべきなのでskip
order = [j for i,j in order][::-1]
flag = True
while(flag):
    flag = False
    while(order):
        ind = order.pop()
        if(ind==0):
            continue
        if(end[ind]==0):
            continue

        ex,div = calc_ex(ind)
        if(a[ind]*div < ex):
            end[ind] = 0
            seg_left.update(ind,0)
            seg_right.update(ind,n)

            left = seg_left.query(0,ind)
            right = seg_right.query(ind+1,n+1)
            if(left!=0):
                order.append(left)
            if(right!=n):
                order.append(right)
            flag = True

    if(flag):
        for i,val in enumerate(end[:-1]):
            if(val==1):
                order.append(i)

# 終了すべきポイントがわかったので期待値合計を計算
ans = [0] * (n)
for ind,flag in enumerate(end[:-1]):
    if(flag==1):
        ans[ind] = (a[ind],1)
    else:
        ex,div = calc_ex(ind)
        ans[ind] = (ex,div)

lcm = 1
for ex,div in ans:
    lcm = (lcm*div)//gcd(lcm,div)

ans_num = 0
for ex,div in ans:
    ans_num += ex*(lcm//div)

print(ans_num/(lcm*n))

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


Question:
def main():
    """"ここに今までのコード"""
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n = int(readline())
    data = tuple(map(int,read().split()))
    m1 = data[0]
    ab = data[1:1+2*m1]
    m2 = data[1+2*m1]
    cd = data[2+2*m1:2+2*(m1+m2)]
    m3 = data[2+2*(m1+m2)]
    ef = data[3+2*(m1+m2):]

    mod = 998244353
    mods = [1] * (n+10)
    base = pow(10,18,mod)
    for i in range(1,n+1):
        mods[i] = (mods[i-1] * base)%mod

    def calc_node(xy):
        links = [[] for _ in range(n+1)]
        it = iter(xy)
        for x,y in zip(it,it):
            if(x < y):
                x,y = y,x
            links[y].append(x)

        group = [-1] * (n+1)
        g_bit = [0] * (n+1)
        group[-1] = 0
        g_bit[-1] = 1
        num_max = 1
        for i in range(n,0,-1):
            tmp = 0
            for j in links[i]:
                tmp |= g_bit[j]
            cnt = 0
            while(tmp&1):
                tmp = tmp>>1
                cnt+=1
            group[i] = cnt
            g_bit[i] = 1 << cnt
            num_max = max(num_max,cnt)

        res = [0] * (num_max+1)
        for i,num in enumerate(group[1:],1):
            res[num] += mods[i]
            res[num] %= mod

        return res

    x = calc_node(ab)
    y = calc_node(cd)
    z = calc_node(ef)

    if(len(x) < len(y)):
        x,y = y,x
    if(len(y) < len(z)):
        y,z = z,y
    if(len(x) < len(y)):
        x,y = y,x

    len_2 = 2**(len(y)-1).bit_length()
    yz = [0] * (len_2)
    for j in range(len(y)):
        for k in range(len(z)):
            yz[j^k] += y[j]*z[k]
            yz[j^k] %= mod

    ans = 0
    for i,j in zip(x,yz):
        ans += i*j
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

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


Question:
def main():
    """"ここに今までのコード"""
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n = int(readline())
    data = tuple(map(int,read().split()))
    m1 = data[0]
    ab = data[1:1+2*m1]
    m2 = data[1+2*m1]
    cd = data[2+2*m1:2+2*(m1+m2)]
    m3 = data[2+2*(m1+m2)]
    ef = data[3+2*(m1+m2):]

    mod = 998244353
    mods = [1] * (n+10)
    base = pow(10,18,mod)
    for i in range(1,n+1):
        mods[i] = (mods[i-1] * base)%mod

    def calc_node(xy):
        links = [[] for _ in range(n+1)]
        it = iter(xy)
        for x,y in zip(it,it):
            if(x < y):
                x,y = y,x
            links[y].append(x)

        group = [-1] * (n+1)
        g_bit = [0] * (n+1)
        group[-1] = 0
        g_bit[-1] = 1
        num_max = 1
        for i in range(n,0,-1):
            tmp = 0
            for j in links[i]:
                tmp |= g_bit[j]
            cnt = 0
            while(tmp&1):
                tmp = tmp>>1
                cnt+=1
            group[i] = cnt
            g_bit[i] = 1 << cnt
            num_max = max(num_max,cnt)

        res = [0] * (num_max+1)
        for i,num in enumerate(group[1:],1):
            res[num] += mods[i]
            res[num] %= mod

        return res

    x = calc_node(ab)
    y = calc_node(cd)
    z = calc_node(ef)

    if(len(x) < len(y)):
        x,y = y,x
    if(len(y) < len(z)):
        y,z = z,y
    if(len(x) < len(y)):
        x,y = y,x

    len_2 = 2**(len(y)-1).bit_length()
    yz = [0] * (len_2)
    for j in range(len(y)):
        for k in range(len(z)):
            yz[j^k] += y[j]*z[k]
            yz[j^k] %= mod

    ans = 0
    for i,j in zip(x,yz):
        ans += i*j
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

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


Question:
def main():
    """"ここに今までのコード"""
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n = int(readline())
    data = tuple(map(int,read().split()))
    m1 = data[0]
    ab = data[1:1+2*m1]
    m2 = data[1+2*m1]
    cd = data[2+2*m1:2+2*(m1+m2)]
    m3 = data[2+2*(m1+m2)]
    ef = data[3+2*(m1+m2):]

    mod = 998244353
    mods = [1] * (n+10)
    base = pow(10,18,mod)
    for i in range(1,n+1):
        mods[i] = (mods[i-1] * base)%mod

    def calc_node(xy):
        links = [[] for _ in range(n+1)]
        it = iter(xy)
        for x,y in zip(it,it):
            if(x < y):
                x,y = y,x
            links[y].append(x)

        group = [-1] * (n+1)
        g_bit = [0] * (n+1)
        group[-1] = 0
        g_bit[-1] = 1
        num_max = 1
        for i in range(n,0,-1):
            tmp = 0
            for j in links[i]:
                tmp |= g_bit[j]
            cnt = 0
            while(tmp&1):
                tmp = tmp>>1
                cnt+=1
            group[i] = cnt
            g_bit[i] = 1 << cnt
            num_max = max(num_max,cnt)

        res = [0] * (num_max+1)
        for i,num in enumerate(group[1:],1):
            res[num] += mods[i]
            res[num] %= mod

        return res

    x = calc_node(ab)
    y = calc_node(cd)
    z = calc_node(ef)

    if(len(x) < len(y)):
        x,y = y,x
    if(len(y) < len(z)):
        y,z = z,y
    if(len(x) < len(y)):
        x,y = y,x

    len_2 = 2**(len(y)-1).bit_length()
    yz = [0] * (len_2)
    for j in range(len(y)):
        for k in range(len(z)):
            yz[j^k] += y[j]*z[k]
            yz[j^k] %= mod

    ans = 0
    for i,j in zip(x,yz):
        ans += i*j
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

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


Question:
"""

https://atcoder.jp/contests/agc033/tasks/agc033_e

Sの1文字目をRとしてよい

RB  から始まる場合　→ 全部交互以外無理(Nが奇数なら0)
RRB から始まる場合　→ Rは3連で置けば可能…

R*X + B*Y + R*Z …
とつながっていく

どこからスタートしても、RだけをX回移動したときにBの隣に来なくてはいけない
Rの長さが1なら可能

R*?,B,R*?,…
でつながっていく

最初のRがX個連続の時
片方の端との距離がX-2tでなくてはならない
Xが偶数の時、Rの連続長さはX+1以下の奇数
Xが奇数の時、端からスタートした奴は反対側に抜けなくてはいけないので
Rの連続長さはX以下の奇数？
結局は奇数個連続でしか置けない

●整理(Rから始まり、Bがある場合)：
Rは奇数個連続でしか置けない
Bは1個連続でしか置けない
→つまり、Nが奇数だとアウト

Bが来た以降を考えてみる
奇数だと、各点Rの左右のどちらかにしか抜けられない→対称的な移動になるはず
→つまり、最初のRを消化した後、全てのBの両端にいる場合が存在する

Bは奇数個の時のみ意味がある
→結局、Bの両端にいた場合が交換されるだけ
→よって、BはRの区切り以上の意味はない

Rが偶数個来るた場合、交互に移動すればおk
Rが奇数個来た場合、反対側に抜ける必要がある

結論：
RBがどちらも存在する場合、Nが偶数なら0、奇数の場合は
BでsplitしたRの個数の集合を考え,
r1,r2…,r? とする
Rは奇数個連続で置けて、その個数の最大は M = min( r1+1 , r? ) #r?が奇数の物
後は、M+1個以下の偶数個単位で区切る場合の数を調べればいい
dp→あらかじめ1番目の区間の位置に、ずれた分も考慮して値を入れておけばBITでもらうdpできる

RB片方の場合、Bが連続しないような置き方をすればいい
1番目がRの場合をdp → N番目までやる
1番目がBの場合をdp → N-1番目までやる(N番目は赤なので)

最後のRは意味がないので消しておく

REの原因究明したい
K < NNの場合？

"""

from sys import stdin
import sys
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:

    def __init__(self,N,first):
        self.NO = 2**(N-1).bit_length()
        self.First = first
        self.data = [first] * (2*self.NO)

    def calc(self,l,r):
        return (l+r) % mod

    def update(self,ind,x):
        ind += self.NO - 1
        self.data[ind] = x
        while ind >= 0:
            ind = (ind - 1)//2
            self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])

    def query(self,l,r):
        L = l + self.NO
        R = r + self.NO
        s = self.First
        while L < R:
            if R & 1:
                R -= 1
                s = self.calc(s , self.data[R-1])
            if L & 1:
                s = self.calc(s , self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get(self , ind):
        ind += self.NO - 1
        return self.data[ind]

N,M = map(int,stdin.readline().split())
S = list(stdin.readline()[:-1])
mod = 10**9+7

if "R" in S and "B" in S:

    if N % 2 == 1:
        print (0)
        sys.exit()

    lis = []
    now = 0
    while S[-1] == S[0]: #最後のRを消す
        del S[-1]
    for i in S:
        if i == S[0]:
            now += 1
        elif now > 0:
            lis.append(now)
            now = 0
    #print (lis)

    nmax = 0
    for i in range(len(lis)):
        if i == 0:
            if lis[i] % 2 == 0:
                nmax = lis[i] + 1
            else:
                nmax = lis[i]
        elif lis[i] % 2 == 1:
            nmax = min(nmax , lis[i])

    NN   = N//2
    K    = (nmax+1)//2
    print (NN,K,file=sys.stderr)

    if NN <= K:
        print ((pow(2,NN,mod)-1) * 2 % mod)
        sys.exit()

    ST = SegTree(NN,0)
    for i in range(K):
        ST.update(i,i+1)

    for i in range(1,NN):
        now = ST.get(i)
        plus = ST.query( max(0,i-K),i )
        ST.update( i , (now+plus) % mod )

    print (ST.get(NN-1) * 2 % mod)

else:

    ans = 0
    #1番目がRの場合
    dp = [1,0]
    for i in range(N-1):
        ndp = [0,0]
        ndp[0] = (dp[0] + dp[1]) % mod
        ndp[1] = dp[0]
        dp = ndp

    ans += sum(dp)

    #1番目がBの場合
    dp = [0,1]
    for i in range(N-2):
        ndp = [0,0]
        ndp[0] = (dp[0] + dp[1]) % mod
        ndp[1] = dp[0]
        dp = ndp
    ans += sum(dp)

    print (ans % mod)

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


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

#ライブラリインポート
from collections import defaultdict
answer = 0
#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")
class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

def DFS(G, visit, W, Wlist, node, K):
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, visit, W, Wlist, i, K)
			Wlist[node].append(W[i] + 1)

	val = 0
	for i in Wlist[node]:
		if i == K and node != 0:
			global answer
			answer += 1
		else:
			val = max(val, i)
	W[node] = val

#処理内容
def main():
	N, K = getlist()
	a = getlist()
	G = Graph()
	for i in range(1, N):
		G.add_edge(i, a[i] - 1)
		G.add_edge(a[i] - 1, i)
	ans = 0
	if a[0] != 1:
		ans += 1
	if K == 1:
		for i in range(1, N):
			if a[i] != 1:
				ans += 1
		print(ans)
		return

	#DFS
	W = [0] * N
	Wlist = [[] for i in range(N)]
	visit = ["No"] * N
	visit[0] = "Yes"

	DFS(G, visit, W, Wlist, 0, K)
	print(ans + answer)

if __name__ == '__main__':
	main()

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


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

DP=[[0]*(N+5) for i in range(3*N+5)]
DP[0][0]=1

for i in range(3*N):
    for j in range(N+1):
        DP[i][j]%=mod
        DP[i+1][j]+=DP[i][j]
        DP[i+2][j+1]+=((3*N-i)-1)*DP[i][j]
        DP[i+3][j+1]+=((3*N-i)-1)*((3*N-i)-2)*DP[i][j]

ANS=0
for i in range(N+1):
    ANS+=DP[3*N][i]
print(ANS%mod)

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


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

DP=[[0]*(N+5) for i in range(3*N+5)]
DP[0][0]=1

for i in range(3*N):
    for j in range(N+1):
        DP[i][j]%=mod
        DP[i+1][j]+=DP[i][j]
        DP[i+2][j+1]+=((3*N-i)-1)*DP[i][j]
        DP[i+3][j+1]+=((3*N-i)-1)*((3*N-i)-2)*DP[i][j]

ANS=0
for i in range(N+1):
    ANS+=DP[3*N][i]
print(ANS%mod)

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


Question:
import math

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

ANSX=ANSY=0

for i in range(N-1):
    for j in range(i+1,N):
        ANSX+=math.cos((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
        ANSY+=math.sin((T[i]+T[j])*math.pi/L)*(N-(j-i+1))

        ANSX+=math.cos((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
        ANSY+=math.sin((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)

print(ANSX/(N*(N-1)*(N-2)//6),ANSY/(N*(N-1)*(N-2)//6))

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


Question:
import numpy as np
import numba as nb

@nb.njit('(i1[:],)', cache=True)
def solve(s):
    n = len(s)
    size = n // 2
    MOD = 998244353
    dp_can = np.zeros((n + 1, size + 1, size + 1), dtype=np.int8)
    dp_cnt = np.zeros((n + 1, size + 1, size + 1), dtype=np.int64)

    dp_cnt[n, 0] = 1
    for j in range(size):
        dp_cnt[n, j + 1] = np.cumsum(dp_cnt[n, j]) % MOD

    for i in range(n - 1, -1, -1):
        if s[i] == 0:
            for j in range(size + 1):
                dp_cnt[i, j] = np.cumsum(dp_cnt[i + 1, j]) % MOD
        else:
            for k in range(size + 1):
                dp_cnt[i, :, k] = np.cumsum(dp_cnt[i + 1, :, k]) % MOD

    dp_can[0, 0, 0] = 1
    for i in range(n):
        dp_can[i + 1] |= dp_can[i]
        if s[i] == 0:
            dp_can[i + 1, 1:, :-1] |= dp_can[i, :-1, 1:]
        else:
            dp_can[i + 1, :-1, 1:] |= dp_can[i, 1:, :-1]
        if i < n - 1:
            if s[i] == 0 or s[i + 1] == 0:
                dp_can[i + 2, 1:, :] |= dp_can[i, :-1, :]
            if s[i] == 1 or s[i + 1] == 1:
                dp_can[i + 2, :, 1:] |= dp_can[i, :, :-1]
    dp_can[1:, 0, 0] = 0

    ans = 0

    for i in range(n, -1, -1):
        for j in range(size + 1):
            for k in range(size + 1):
                if dp_can[i, j, k] == 0:
                    continue

                ans = (ans + dp_cnt[i, j, k]) % MOD

                a, b = j, k
                for h in range(i - 1, -1, -1):
                    if s[h] == 0:
                        a -= 1
                    else:
                        b -= 1
                    if a < 0 or b < 0:
                        break
                    dp_can[h, a, b] = 0

    return ans

s = np.array([int(c) for c in input()], dtype=np.int8)
print(solve(s))

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


Question:
import sys

def find_permutation(aaa, use):
    """
    iの残り使用数がaaa[i-1]の状態で
    集合useにある文字群(1～k)を後ろに繋げる方法で
    それよりさらに後が破綻しないような繋げ方のうち
    辞書順最小のものを求める。

    ただし（この関数からは見えないが）現在確定済み配列の
    末尾 (k - |use|) 個は、useに含まれない要素が1回ずつ登場することを前提とする。
    （つまり、この関数の結果を繋げると、末尾 k 個が順列になる）

    どうやっても破綻する場合はNoneを返す。

    :param aaa:
    :param use:
    :return:
    """

    max_a = -1
    min_a = 1005
    max_fixed = -1

    for i in range(k):
        a = aaa[i]
        if i + 1 in use:
            min_a = min(min_a, a)
            max_a = max(max_a, a)
        else:
            max_fixed = max(max_fixed, a)

    if max(max_a, max_fixed + 1) > 2 * min_a:
        return None

    if max_a < 2 * min_a:
        return sorted(use)

    front = []
    rear = []
    either = []
    for i in use:
        if aaa[i - 1] == max_a:
            front.append(i)
        elif aaa[i - 1] == min_a:
            rear.append(i)
        else:
            either.append(i)

    max_front = front[-1]
    for i in either:
        if i < max_front:
            front.append(i)
        else:
            rear.append(i)
    front.sort()
    rear.sort()
    front.extend(rear)

    return front

def solve(k, aaa):
    if k == 1:
        return [1] * aaa[0]

    min_a = min(aaa)
    max_a = max(aaa)
    if min_a * 2 < max_a:
        return [-1]

    ans = []
    ans.extend(find_permutation(aaa, set(range(1, k + 1))))
    for i in range(k):
        aaa[i] -= 1

    remaining = sum(aaa)
    while remaining:
        use = set(range(1, k + 1))
        candidates = []
        for r in range(k):
            result = find_permutation(aaa, use)
            if result is not None:
                candidates.append(result)

            use.remove(ans[-r - 1])
        adopted = min(candidates)
        ans.extend(adopted)
        for i in adopted:
            aaa[i - 1] -= 1
        remaining -= len(adopted)

    return ans

k, *aaa = map(int, sys.stdin.buffer.read().split())
print(*solve(k, aaa))

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


Question:
import sys

def find_permutation(aaa, use):
    """
    iの残り使用数がaaa[i-1]の状態で
    集合useにある文字群(1～k)を後ろに繋げる方法で
    それよりさらに後が破綻しないような繋げ方のうち
    辞書順最小のものを求める。

    ただし（この関数からは見えないが）現在確定済み配列の
    末尾 (k - |use|) 個は、useに含まれない要素が1回ずつ登場することを前提とする。
    （つまり、この関数の結果を繋げると、末尾 k 個が順列になる）

    どうやっても破綻する場合はNoneを返す。

    :param aaa:
    :param use:
    :return:
    """

    max_a = -1
    min_a = 1005
    max_fixed = -1

    for i in range(k):
        a = aaa[i]
        if i + 1 in use:
            min_a = min(min_a, a)
            max_a = max(max_a, a)
        else:
            max_fixed = max(max_fixed, a)

    if max(max_a, max_fixed + 1) > 2 * min_a:
        return None

    if max_a < 2 * min_a:
        return sorted(use)

    front = []
    rear = []
    either = []
    for i in use:
        if aaa[i - 1] == max_a:
            front.append(i)
        elif aaa[i - 1] == min_a:
            rear.append(i)
        else:
            either.append(i)

    max_front = front[-1]
    for i in either:
        if i < max_front:
            front.append(i)
        else:
            rear.append(i)
    front.sort()
    rear.sort()
    front.extend(rear)

    return front

def solve(k, aaa):
    if k == 1:
        return [1] * aaa[0]

    min_a = min(aaa)
    max_a = max(aaa)
    if min_a * 2 < max_a:
        return [-1]

    ans = []
    ans.extend(find_permutation(aaa, set(range(1, k + 1))))
    for i in range(k):
        aaa[i] -= 1

    remaining = sum(aaa)
    while remaining:
        use = set(range(1, k + 1))
        candidates = []
        for r in range(k):
            result = find_permutation(aaa, use)
            if result is not None:
                candidates.append(result)

            use.remove(ans[-r - 1])
        adopted = min(candidates)
        ans.extend(adopted)
        for i in adopted:
            aaa[i - 1] -= 1
        remaining -= len(adopted)

    return ans

k, *aaa = map(int, sys.stdin.buffer.read().split())
print(*solve(k, aaa))

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


Question:
# salsa=0, rumba=1
# [0 1 0 1] 1より上の位に帯する操作

# 繰り上がりを考慮しつつ、3（より上）の位に対する操作を考える
# [1]       1の位が0である数字の、3の位に対する操作
# [0 1 0]   1の位が1である数字の、3の位に対する操作
# []        1の位が2である数字の、3の位に対する操作
# ある数字が"2"の時にルンバが来れば繰り上がる（上の位にルンバが波及）
# それ以外の状態では、上の位にとってルンバは無いのと同じことになる
# サルサは常に影響するが、連続した2つのサルサは打ち消し合い、無いのと同じことになる

# 再帰的に上の位を決める
# []        3,1の位が00,10である数字の、9の位に対する操作
# [1]       3,1の位が20である数字の、9の位に対する操作
# []        3,1の位が01,21である数字の、9の位に対する操作
# [0 1 0]   3,1の位が11である数字の、9の位に対する操作
# []        3,1の位が02,12,22である数字の、9の位に対する操作

# 一度繰り上がったら、例えば100.. と0がd個続くとして、
# 更にその上の位に波及させるには 2^d オーダーの操作が必要となるので、各操作列は徐々に減っていく

n = int(input())
t = input()
op = [[int(c == 'R') for c in t]]
ans = [0]

for d in range(n):
    k = 3 ** d
    nop = []
    nans = [0] * (k * 3)
    for g in range(3):  # d桁目の数
        for i in range(k):  # d桁目未満の数
            opg = op[i]
            opn = []
            h = g
            for o in opg:
                if o == 0:
                    if len(opn) > 0 and opn[-1] == 0:
                        opn.pop()
                    else:
                        opn.append(0)
                    if h == 1:
                        h = 2
                    elif h == 2:
                        h = 1
                else:
                    if h == 2:
                        h = 0
                        opn.append(1)
                    else:
                        h += 1
            nop.append(opn)
            nans[g * k + i] = h * k + ans[i]

    op = nop
    ans = nans

print(*ans)

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


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

n3 = n * 3
dp = [[0] * int(i * 1.5 + 5) for i in range(n3 + 1)]
dp[0][0] = dp[1][1] = dp[2][2] = dp[2][-1] = 1

for i in range(3, n3 + 1):
    i12 = (i - 1) * (i - 2)
    dpi3, dpi2, dpi1, dpi = dp[i - 3:i + 1]
    for j in range(-(i // 2), i + 1):
        tmp = dpi3[j] * i12
        tmp += dpi2[j + 1] * (i - 1)
        tmp += dpi1[j - 1]
        dpi[j] = tmp % MOD

print(sum(dp[-1][:n3 + 1]) % MOD)

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


Question:
def solve(n, m, s):
    f = s[0]
    MOD = 10 ** 9 + 7
    INF = 10 ** 6

    p = None
    seq = 0
    min_seq = INF
    for c in s:
        if c == p:
            seq += 1
        else:
            if p == f and (min_seq == INF or seq % 2 == 1):
                min_seq = min(min_seq, seq)
            seq = 1
            p = c

    if min_seq == INF:
        a, b = 1, 0
        for _ in range(n - 2):
            a, b = (a + b) % MOD, a
        return (3 * a + b) % MOD

    if n % 2 == 1:
        return 0

    n2 = n // 2
    ms = min(n2, min_seq // 2 + 1)

    dp = [0] * (n2 + 1)
    dp[0] = 1
    acc, reject = 1, 0
    for i in range(1, n2 + 1):
        dp[i] = (acc - reject) % MOD
        acc = (acc + dp[i]) % MOD
        if i >= ms:
            reject = (reject + dp[i - ms]) % MOD

    ans = 0
    for d in range(1, ms + 1):
        ans = (ans + dp[n2 - d] * d * 2) % MOD

    return ans

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

print(solve(n, m, s))

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


Question:
from operator import itemgetter

def get_identity():
    return list(range(1, n + 1))

def composition(ppp, qqq):
    return [ppp[q - 1] for q in qqq]

def reverse_composition(ppp, qqq):
    return [ppp[i] for i, q in sorted(enumerate(qqq), key=itemgetter(1))]

def solve(k, ppp, qqq):
    qp = reverse_composition(qqq, ppp)
    qpq = reverse_composition(qp, qqq)
    qpqp = composition(qpq, ppp)

    l, m = divmod(k - 1, 6)
    res = get_identity()
    tmp = qpqp
    while l:
        if l % 2 == 1:
            res = composition(res, tmp)
        tmp = composition(tmp, tmp)
        l >>= 1

    m = (k - 1) % 6
    if m == 0:
        base = ppp
    elif m == 1:
        base = qqq
    elif m == 2:
        base = reverse_composition(qqq, ppp)
    elif m == 3:
        res = composition(res, qqq)
        base = reverse_composition(get_identity(), ppp)
    elif m == 4:
        res = composition(res, qqq)
        res = reverse_composition(res, ppp)
        base = reverse_composition(get_identity(), qqq)
    elif m == 5:
        res = composition(res, qqq)
        res = reverse_composition(res, ppp)
        base = reverse_composition(get_identity(), qqq)
        base = composition(base, ppp)
    else:
        raise NotImplementedError

    ans = composition(res, base)
    ans = reverse_composition(ans, res)
    return ans

n, k = map(int, input().split())
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
print(*solve(k, ppp, qqq))

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


Question:
import sys

n, q = list(map(int, input().split()))
MOD = 10 ** 9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')

ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)

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


Question:
import numpy as np
from scipy.spatial import ConvexHull
from scipy.spatial.qhull import QhullError

def solve(n, pts):
    ans = [0] * n

    try:
        hull = ConvexHull(pts)
    except QhullError:
        lm = np.argmin(pts, axis=0)
        rm = np.argmax(pts, axis=0)
        if lm[0] != rm[0]:
            l, r = lm[0], rm[0]
        elif lm[1] != rm[0]:
            l, r = lm[1], rm[0]
        else:
            l, r = lm[0], rm[1]
        ans[l] = ans[r] = 0.5
        return ans

    ps = np.array(list(map(pts.__getitem__, hull.vertices)))
    vs = ps - np.roll(ps, 1, axis=0)

    vt = vs.T
    vt[0] *= -1
    arcs = np.arctan2(*vt)
    arcs = np.append(arcs, arcs[0])
    da = np.diff(arcs) / (2 * np.pi) % 1

    for i, a in zip(hull.vertices, da):
        ans[i] = a

    return ans

n = int(input())
pts = [list(map(int, input().split())) for _ in range(n)]
print('\n'.join(map(str, solve(n, pts))), end='')

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


Question:
import numpy as np
from scipy.spatial import ConvexHull
from scipy.spatial.qhull import QhullError

def solve(n, pts):
    ans = [0] * n

    try:
        hull = ConvexHull(pts)
    except QhullError:
        lm = np.argmin(pts, axis=0)
        rm = np.argmax(pts, axis=0)
        if lm[0] != rm[0]:
            l, r = lm[0], rm[0]
        elif lm[1] != rm[0]:
            l, r = lm[1], rm[0]
        else:
            l, r = lm[0], rm[1]
        ans[l] = ans[r] = 0.5
        return ans

    ps = np.array(list(map(pts.__getitem__, hull.vertices)))
    vs = ps - np.roll(ps, 1, axis=0)

    vt = vs.T
    vt[0] *= -1
    arcs = np.arctan2(*vt)
    arcs = np.append(arcs, arcs[0])
    da = np.diff(arcs) / (2 * np.pi) % 1

    for i, a in zip(hull.vertices, da):
        ans[i] = a

    return ans

n = int(input())
pts = [list(map(int, input().split())) for _ in range(n)]
print('\n'.join(map(str, solve(n, pts))), end='')

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


Question:
from collections import Counter

n, m = map(int, input().split())
an = list(map(int, input().split()))
ac_ = Counter(an)
ac = {i: ac_[i] if i in ac_ else 0 for i in range(1, n + 1)}
ad = [0] * n
for a, c in ac.items():
    for i in range(max(0, a - c), a):
        ad[i] += 1
ans = ad.count(0)
anss = []

for x, y in (map(int, input().split()) for _ in range(m)):
    ax = an[x - 1]
    xdi = ax - ac[ax]
    if xdi >= 0:
        ad[xdi] -= 1
        if ad[xdi] == 0:
            ans += 1
    ac[ax] -= 1
    ac[y] += 1
    ydi = y - ac[y]
    if ydi >= 0:
        ad[ydi] += 1
        if ad[ydi] == 1:
            ans -= 1
    an[x - 1] = y
    anss.append(ans)
print('\n'.join(map(str, anss)))

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


Question:
import math
N,L=map(int,input().split())
T=[int(input()) for i in range(N)]
X=0
Y=0
for i in range(N):
    for j in range(i+1,N):
        angle=math.pi*(T[j]+T[i])/L
        #print(math.cos(angle),math.sin(angle))
        X+=math.cos(angle)*(N-2-(j-i-1)*2)
        Y+=math.sin(angle)*(N-2-(j-i-1)*2)
A=(N*(N-1)*(N-2))//6
print(X/A,Y/A)

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


Question:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, K = map(int, input().split())
a = list(map(int, input().split()))
if K >= N - 1:
  print(int(a[0] != 1))
  exit(0)
res = 0
if a[0] != 1:
  a[0] = 1
  res += 1
e = dd(set)
inc = [0] * (N + 1)
for i in range(N):
  if i + 1 == a[i]: continue
  e[a[i]].add(i + 1)
  inc[a[i]] += 1

t = set()
def dfs(x):
  global res
  d = 0
  for y in e[x]:
    d = max(d, dfs(y) + 1)
  if d == K - 1:
    res += (a[x - 1] != 1)
    return -1
  return d

dfs(1)
print(res)

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


Question:
def rev(a):
    L = []
    for i in range(N):
        L.append(a % 3)
        a //= 3
    return int("".join(map(str, L)), 3)

def salsa():
    lazy[0] *= -1

def rumba():
    i = 0
    for k in range(N):
        if lazy[i] < 0:
            lazy[3*i+1] *= -1
            lazy[3*i+2] *= -1
            lazy[3*i+3] *= -1
            lazy[i] = 1
            value[3*i+1] ^= 3
            value[3*i+2] ^= 3
            value[3*i+3] ^= 3
        value[3*i+1] += 1
        value[3*i+2] += 1
        value[3*i+3] += 1
        value[3*i+1] %= 3
        value[3*i+2] %= 3
        value[3*i+3] %= 3
        i = 3 * i + (1 if value[3*i+1] == 0 else 2 if value[3*i+2] == 0 else 3)

def calcall():
    a = 1
    i = 0
    for k in range(1, N + 1):
        for _ in range(3 ** k):
            i += 1
            if lazy[(i-1)//3] < 0:
                lazy[i] *= -1
                if value[i]: value[i] ^= 3
            value[i] = value[i] * a + value[(i-1) // 3]
        a *= 3

N = int(input())
NN = 3 ** (N + 1) // 2
value = [(i-1) % 3 if i else 0 for i in range(NN)]
lazy = [1 for i in range(NN)]

for t in input():
    if t == "R":
        rumba()
    else:
        salsa()

calcall()

ANS = [0] * (3 ** N)
for i in range(3 ** N):
    ANS[rev(i)] = value[i + (NN - 1) // 3]

print(*ANS)

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


Question:
K = int(input())
M = 1000

def a(i, j):
    tmp = (i - j) % (M//2) + 1
    if j % 2 == 0 or M + 1 - tmp > K:
        return tmp
    else:
        return M + 1 - tmp

if K <= M//2:
    print(K)
    for i in range(K):
        print(*([i+1]*K))
else:
    print(M//2)
    for j in range(M//2):
        print(*([a(i, j) for i in range(M//2)]))

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


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)
    #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-sum(same):
        ans = uf.size(N)
        if bita!=bitb:
            ans -= 1
        print(ans)
        return

    ans = 0
    used = [False]*(N+1)
    for i in range(N):
        #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
    if bita!=bitb or len(Da[bita])>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
4
1 2 4 8
2 1 8 4
# 6
"""

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


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

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


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

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


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 fractions 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
    #if you write g = 1, it is a lie.
    if a[0] % 2 == 0:
        g = a[0]
    else:
        g = a[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:
- Compile Error
- No abnormally found
- Internal error
- 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))

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

print(ans)

Choices:
- Runtime Error
- Internal error
- No abnormally found
- Time 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))

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

print(ans)

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


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 and ali[0] == 1:
    print(1)
    print(1)
    print(1)
    exit()

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 == 0:
    lm = c[0]
    del c[0]
    rm = c.pop()

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:
- Internal error
- Time Limit Exceeded
- Compile Error
- No abnormally found


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))
    lo, hi = 0, A + 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        rA, rB = A - mid, B - max(0, (mid - 1) // K)
        if (rA + 1) * K < rB:
            hi = mid
        else:
            lo = mid

    f = ''
    for i in range(C - 1, D):
        na = lo
        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:
- No abnormally found
- Memory Limit Exceeded
- Compile Error
- 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))
    lo, hi = 0, A + 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        rA, rB = A - mid, B - max(0, (mid - 1) // K)
        if (rA + 1) * K < rB:
            hi = mid
        else:
            lo = mid

    f = ''
    for i in range(C - 1, D):
        na = lo
        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:
- Runtime Error
- Compile Error
- Time Limit Exceeded
- No abnormally found


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

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


Question:
from fractions 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("First")
  else:
    print("Second")
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:
- Memory Limit Exceeded
- Runtime Error
- No abnormally found
- Internal error