Question:
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

"""
ABC160-Fの解説放送での実装をPythonで焼きなおしてみました。
内訳：
    class Combination : mod付きの組み合わせの計算用クラス
    class DP : 木DPを行うためのクラス（本問用に特殊化）
    dfs(v, p=-1) : 頂点v以下の部分木に対してdpした結果を返す
    bfs(v, p=-1) : 頂点vに入ってくるdp値の総和を取り、頂点vの子供に親からのdp値を渡す
"""

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

# 早速グローバル変数として用意しておく
cmb = Combination(2 * 10 ** 5)

class DP:
    """
    木DPをする準備として、dpの値と木のサイズを両方保持するクラスを定義する。
    さらに演算子オーバーロードにより足し算記号でdpの値の更新（今回は組み合わせ含む掛け算）と
    木のサイズの合算を同時にやってくれるようにする。
    dp計算は全てmodを取ることに注意。
    """
    def __init__(self, m_dp=1, m_t=0, mod=10**9+7):
        self.dp = m_dp
        self.t = m_t
        self.mod = mod

    def __iadd__(self, other):
        """
        a = DP(3, 2); b = DP(4, 5)として
        a += bによりa = DP(12, 7)みたいになる。
        二つの木を合わせるために新しくつける根はまだ足していないことに注意。
        """
        self.dp *= other.dp * cmb(self.t + other.t, self.t)
        self.dp %= self.mod
        self.t += other.t
        return self

    def __sub__(self, other):
        """
        引き算も同様にオーバーロード（ただしこっちは二項演算）。
        また、こちらはbfsで親の木のdp値を送ることを念頭においていることに注意。
        """
        dp = self.dp * pow(other.dp * cmb(self.t - 1, other.t), self.mod - 2, self.mod) # dp = self.dp / other.dp * cmb(self.t - 1, other.t)
        t = self.t - other.t
        return DP(dp, t)

    def addRoot(self):
        self.t += 1
        return self

    def subroot(self):
        self.t -= 1
        return self

def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    mod = 10**9+7

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

    """
    まずは頂点0を根として木DPをする、すなわち頂点0に数字1を書き込んだ場合の
    残りの数の書き込み方の場合の数を計算する。
    """

    # 最初の木DPの途中経過を記録する配列を準備
    # dp[v][i] = (頂点vのi番目の子を根とする部分木から頂点vに渡されるdp値)
    dp = [[DP() for u in repn[v]] for v in range(N)]
    # dpSum[v] = (頂点vの子供を根とする部分木からそれぞれ頂点vに渡されるdp値の総和)
    dpSum = [DP() for _ in range(N)]

    def dfs(v, p=-1):
        """
        dfsというよりは木DPをした結果を返す関数。

        根がvの部分木（頂点pはvの親として含めない）のdp結果を返すが、
        そのためにvの各子供に対する部分木dpの結果を足し合わせて、
        最後に木のサイズを1(v自身の分)だけ増やしている。

        v自身が葉ノードの場合はDPクラス内で既に初期化が済んでいることに注意。
        """
        for i, u in enumerate(repn[v]):
            if u == p:
                continue
            dp[v][i] = dfs(u, v)
            dpSum[v] += dp[v][i]
        return dpSum[v].addRoot()

    dfs(0)
    # この時点で各dpSum[v]には、子供らのdp値を総和した値と、頂点vを含む木のサイズが記録される
    # for i in range(N):
    #     print("dpSum[{}]=[{}, {}]".format(i, dpSum[i].dp, dpSum[i].t))

    """
    次に全方位木DPのためのbfsを行う。
    全方位木そのもののアルゴリズムは解説放送を参照。
    あえてポイントを述べるとすれば、
        1. 木の各辺の向きが、部分木と１対１対応する。
        2. dfs時点で各辺の根に上がる向きの部分木dpは記録済み
        3. 逆向きの辺のdp値は、全ての隣接辺に対して入ってくる向きの
        　　dp値がわかっている頂点（例えば根）に関してならdp値の総和を
        　　考えることで出ていく向きのdp値がO(1)で求まる。
        4. これを隣接する頂点ごとに計算すればよい。
    """

    def bfs(v, dpP=DP(), p=-1):
        """
        頂点vからのbfsというかdfsで求めたdp値の逆伝搬（出ていく方のdp値）の計算を行う。
        dpPは頂点vの親から来る部分木のdp値。

        まず親から来る部分木のdp値を加えることで、頂点vに隣接する全ての辺から入ってくる
        dp値の総和を完成させる。

        このときdpSum[v]自体が頂点vを含んでしまうとdp計算で木のサイズを使う際に狂いが生じるので、
        一旦頂点vを除いたうえでdpPを加えて、その後頂点vを戻す（これで頂点vに対する解は求まった）。
        """

        if p != -1:
            dpSum[v].subroot()
            dpSum[v] += dpP
            dpSum[v].addRoot()

        # 次に頂点vのそれぞれの子（頂点u）に対して、頂点uを主役と見たときの親からのdp値を渡す。、
        for i, u in enumerate(repn[v]):
            if u == p:
                dp[v][i] = dpP
            else:
                d = dpSum[v] - dp[v][i]
                bfs(u, d, v)

    bfs(0)
    for i in range(N):
        # print("dpSum[{}]=[{}, {}]".format(i, dpSum[i].dp, dpSum[i].t))
        print(int(dpSum[i].dp))

if __name__ == "__main__":
    main()

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


Question:
from collections import deque
from bisect import bisect_right
from math import ceil

N, D, A = map(int, input().split())
monsters = []
for _ in range(N):
    x, h = map(int, input().split())
    monsters.append((x, h))
monsters.sort()
#print("monsters = {}".format(monsters))
"""
どうせ左端のモンスターはいつか倒さないといけない（かつ爆弾投下順は不問）ので、
左端のモンスターから順に、なるべく爆弾を右に寄せて落としていけば良い。

BITを使って区間に爆弾のダメージを追加して考えても良いが、
ここではimos法チックな回答を与える。

仮に全ての爆弾が前モンスターに攻撃を与えるとしよう。
すると各モンスターにどれだけ流れダメージが飛んできたかは累積和で求まる。->totalで累積ダメージを管理。
しかし今回は爆弾に有効範囲があるため、有効期限切れの爆弾ダメージはtotalから除く必要がある。
そこでキューに（爆弾のダメージが入る限界線、爆弾のダメージ）を追加していき、各モンスターを見たとき
爆弾の期限が切れていたらpopleftで期限切れ爆弾を捨てていく。
（それ以降のモンスターに対してもその爆弾は期限切れなので、永久に捨て去って問題ない）。

以下のサイトの解説が参考になりました↓
https://at274.hatenablog.com/entry/2020/02/01/060000
"""

total = 0
ans = 0
q = deque([])

for i in range(N):
    x, h = monsters[i]

    # 期限切れ爆弾を捨てていき、残ったまだ有効な爆弾分の累積ダメージをモンスターに与える
    while q and q[0][0] < x:
        total -= q[0][1]
        q.popleft()
    h -= total

    # まだモンスターも体力が残っていれば、爆弾で追加ダメージを与える
    if h > 0:
        # まずはモンスターをやっつける
        times = ceil(h / A)
        ans += times
        #print("ans+={} for monster {}".format(times, i))

        # その後後ろへの流れダメージをtotalに追加し、爆弾の有効範囲をキューに追加
        damage = times * A
        total += damage
        q.append((x + 2 * D, damage))

print(ans)

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


Question:
import sys
from bisect import bisect_left, bisect_right
import itertools

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
#print("A={}".format(A))
"""
この問題の前半は、合計の幸福度Xが上位M個未満に入るかを判定する。
    -> Xに関する二分探索をすることで、上位から丁度M番目の幸福度がわかる！

これを判定するために、左手の握手先をfix(A[i]とする)して、
右手の幸福度が(X - A[i])以上であるものの個数を数える。
"""

def within(X, M):
    """
    幸福度がX以上上がるような握手の組がM個未満ならTrue、そうでなければFalseを返す
    """
    pair = 0
    for i in range(N):
        idx = bisect_left(A, X - A[i])
        pair += N - idx
    if pair < M:
        #print("pair={}<M".format(pair))
        return True
    else:
        #print("pair={}>=M".format(pair))
        return False

"""
Xに関する二分探索をおこなった結果、
leftXはwithin(leftX, M) == Trueになる最小のX
"""
leftX = 0
rightX = A[-1] * 2 + 1
while leftX != rightX:
    middleX = (leftX + rightX) // 2
    #print("mid={}".format(middleX))
    if within(middleX, M):
        rightX = middleX
    else:
        leftX = middleX + 1
#print("leftX={}".format(leftX))

"""
これより後半、幸福度の総和を求める。
前半同様に左手をfixした上で、両手の幸福度の合計がleftX以上になるときの幸福度を加算していく。
単純に右手に関してfor文を回して加算するとTLEなので、
右手の幸福度に関しては先に累積和を求めておく。
"""
S = list(itertools.accumulate(A))
#print("S={}".format(S))
happy = 0
times = 0
for i in range(N):
    idx = bisect_left(A, leftX - A[i])
    times += N - idx
    #print("When i={}, idx={}, times={}".format(i, idx, times))
    if idx != 0:
        happy += A[i] * (N - idx) + (S[-1] - S[idx - 1])
    else:
        happy += A[i] * (N - idx) + S[-1]
    #print("happy={}".format(happy))
happy += (leftX - 1) * (M - times)

print(happy)

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


Question:
import sys
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()

def log(k, b):
    a = 0
    while b ** a <= k:
        a += 1
    return a - 1

N = int(input())
if N % 2 == 1:
    print(0)
else:
    k = N // 2
    a = log(k, 5)
    ans = 0
    for i in range(1, a + 1):
        ans += k // (5 ** i)
    print(ans)

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


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

# find the largest subsequence
packet = []
packet_len = 1
direction = S[0]
seq = 1
for i in range(1, N - 1):
    if S[i] == direction:
        seq += 1
    else:
        packet.append(seq)
        seq = 1
        direction = S[i]
        packet_len += 1

if S[N - 1] == direction:
    seq += 1
    packet.append(seq)
else:
    packet.append(seq)
    seq = 1
    direction = S[N - 1]
    packet.append(seq)
    packet_len += 1

#print(packet)
#print(packet_len)

# There is no need to choose the 'most invertible' index (i.e. max_idx) !!!
# Also, there is no need to rewrite the packet

num = 2 * K + 1
if packet_len == 1 or packet_len == 2 or num >= packet_len:
    print(N - 1)
elif num < packet_len:
    rem = packet_len - num
    print(N - rem - 1)

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


Question:
N = int(input())
print(N * (N - 1) // 2)

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


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

d = a - b
print(max(0, c - d))

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


Question:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():

    """
    x方向とy方向に分けて頂点を辺だと思うのは定石？？？（確かに長方形がメインなら直積分解したくなる？）
    このとき問題文は「長さ３のパスがあればパスを１本追加する操作を繰り返して、各連結成分を完全二部グラフにせよ」

    完全二部グラフになるのは背理法からすぐわかる。なので解法は(¥Sum_{i:component}X_i Y_i) - N
    """

    N = int(input())
    vertex_x = set([])
    vertex_y = set([])
    edge = []
    for _ in range(N):
        x, y = map(int, input().split())
        vertex_x.add(x)
        vertex_y.add(y)
        edge.append((x, y))

    # UnionFind()の都合上頂点は0-indexedの番号列で管理したいので
    # 頂点に対して連番づけを行う
    d = defaultdict(int)
    num = 0
    for x in vertex_x:
        d[(0, x)] = num
        num += 1
    x_num = num
    for y in vertex_y:
        d[(1, y)] = num
        num += 1

    # ここからメイン
    uftree = UnionFind(num)
    for x, y in edge:
        uftree.union(d[(0, x)], d[(1, y)])

    ans = 0
    for r in uftree.roots():
        X = 0
        Y = 0
        for v in uftree.members(r):
            if v < x_num:
                X += 1
            else:
                Y += 1
        ans += X * Y
    print(ans - N)

if __name__ == "__main__":
    main()

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


Question:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():

    """
    x方向とy方向に分けて頂点を辺だと思うのは定石？？？（確かに長方形がメインなら直積分解したくなる？）
    このとき問題文は「長さ３のパスがあればパスを１本追加する操作を繰り返して、各連結成分を完全二部グラフにせよ」

    完全二部グラフになるのは背理法からすぐわかる。なので解法は(¥Sum_{i:component}X_i Y_i) - N
    """

    N = int(input())
    vertex_x = set([])
    vertex_y = set([])
    edge = []
    for _ in range(N):
        x, y = map(int, input().split())
        vertex_x.add(x)
        vertex_y.add(y)
        edge.append((x, y))

    # UnionFind()の都合上頂点は0-indexedの番号列で管理したいので
    # 頂点に対して連番づけを行う
    d = defaultdict(int)
    num = 0
    for x in vertex_x:
        d[(0, x)] = num
        num += 1
    x_num = num
    for y in vertex_y:
        d[(1, y)] = num
        num += 1

    # ここからメイン
    uftree = UnionFind(num)
    for x, y in edge:
        uftree.union(d[(0, x)], d[(1, y)])

    ans = 0
    for r in uftree.roots():
        X = 0
        Y = 0
        for v in uftree.members(r):
            if v < x_num:
                X += 1
            else:
                Y += 1
        ans += X * Y
    print(ans - N)

if __name__ == "__main__":
    main()

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


Question:
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)

sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

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


Question:
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    S = input()

    """
    反転させる区間は独立であるとしてよい。実際反転させる２区間が左図のように
    オーバーラップしていたとすると、これは右図のように反転させるのと同値だからである：
               _______________                             _______
        ______|_______        |     --->    ______        |       |
    ___|______|_______|_______|_____    ___|______|_______|_______|_____

    そうすると安直には0がなるべく長く連続している区間に反転をかけたくなるが、
    長い順に反転をかけた場合1が連続する保証がないのでダメ。

    そこで1の連続する箇所を固定したうえで、そこから0の連続する区間に順番に反転をかけることを考える。
    当然愚直にやるとTLEなので、累積和で実装する
    """

    A = []
    char = S[0]
    cnt = 1
    for i in range(1, N):
        if S[i] == char:
            cnt += 1
        else:
            A.append(cnt)
            char = S[i]
            cnt = 1
    A.append(cnt)
    #print("A={}".format(A))

    B = list(accumulate(A))
    B.append(B[-1])
    #print("B={}".format(B))
    l = len(A)
    if S[0] == '0':
        ans = B[min(K * 2 - 1, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 0:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    else:
        ans = B[min(K * 2, l - 1)]
        for i in range(1, l - K * 2 + 1):
            if i % 2 == 1:
                j = i + K * 2 - 1
                val = B[j] - B[i - 1]
            else:
                j = i + K * 2
                val = B[j] - B[i - 1]
            #print("[{}, {}]->val={}".format(i, j, val))
            ans = max(ans, val)
    print(ans)

if __name__ == "__main__":
    main()

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


Question:
import sys, math
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

def main():
    N = int(input())
    if N < 10:
        print(0)
        return
    table = get_sieve_of_eratosthenes(N)
    #print(table)
    primes = defaultdict(int)
    for n in range(2, N + 1):
        for p in table:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            primes[p] += cnt
    #print(primes)

    over_3 = 0
    over_5 = 0
    over_15 = 0
    over_25 = 0
    over_75 = 0
    for p in primes:
        if primes[p] >= 2: over_3 += 1
        if primes[p] >= 4: over_5 += 1
        if primes[p] >= 14: over_15 += 1
        if primes[p] >= 24: over_25 += 1
        if primes[p] >= 74: over_75 += 1
    #print(over_3)
    #print(over_5)
    #print(over_15)
    #print(over_25)
    #print(over_75)

    val1 = over_5 * (over_5 - 1) * (over_3 - 2) // 2
    val2 = over_15 * (over_5 - 1)
    val3 = over_25 * (over_3 - 1)
    print(val1 + val2 + val3 + over_75)

if __name__ == "__main__":
    main()

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


Question:
def main():
  n = int(input())
  print(n**3)

main()

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


Question:
X,K,D = map(int, input().split())
absX = abs(X)
ans = 0
if absX//D > K:
  ans = absX - D*K
else:
  if (absX//D)%2 == (K%2):
    ans = absX%D
  else:
    posX = absX%D+D
    negX = abs(absX%D-D)
    if posX < negX:
      ans = posX
    else:
      ans = negX
print(ans)

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


Question:
N = int(input())
AList = list(map(int, input().split()))
Q = int(input())
dp = [0]*(10**5+1)
total = 0
for i in AList:
  dp[i] += 1
  total += i

for i in range(Q):
  B,C = map(int, input().split())
  bNum = dp[B]
  dp[B] = 0
  dp[C] += bNum
  cNum = dp[C]
  total = total - B*bNum + C*bNum
  print(total)

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


Question:
from decimal import Decimal
A,B = input().split()
print(int(int(A)*Decimal(B)))

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


Question:
a = list(map(int,input().split()))
N = a[0]
M = a[1]
dct = {}
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] in dct:
        val = dct[temp[0]] + temp[1]
        dct[temp[0]] = val
    else:
        dct[temp[0]] = temp[1]

dct = sorted(dct.items())
ruiseki = 0
loop = 0

cost = []
nums = []
ans = 0
lendct = len(dct)
for i in range(lendct):
    cost.append(dct[i][0])
    nums.append(dct[i][1])
if nums[0] >= M:
    print(str(cost[0]*M))
else:
    ans += cost[0]*nums[0]
    for i in range(1, 100001):
        nums[i] += nums[i-1]
        if nums[i] >= M:
            print(str(ans + cost[i]*(M - nums[i-1])))
            break
        ans += cost[i]*(nums[i]-nums[i-1])

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


Question:
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, M = map(int,input().split())
cities = []
for i in range(M):
    p, y = map(int,readline().split())
    temp = [p, y, i]
    cities.append(temp)
id = [1 for i in range(N)] #国i+1の都市に対して次に割り振るべきID
sortedcities = sorted(cities, key=lambda x:x[1])
for i in range(M):
    sortedcities[i].append(id[sortedcities[i][0]-1])
    id[sortedcities[i][0]-1] += 1
originalcities = sorted(sortedcities, key=lambda x:x[2])
for i in range(M):
    write(str(originalcities[i][0]).zfill(6) + str(originalcities[i][3]).zfill(6) + "\n")

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


Question:
from collections import deque

S = input()
lenS = len(S)
pops = 0
ans = lenS
stack = deque()
for i in range(lenS):
    if stack and S[i] == "T":
        a = stack.pop()
        if a == "S":
            ans -= 2
    else:
        stack.append(S[i])
print(str(ans))

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


Question:
N = int(input())
s = input()
r = s.count("R")
print(s[:r].count("W"))

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


Question:
def modpow(a,n,mod=10**9+7):
    res=1
    while n>0:
        if n&1:
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res%mod

def modcmb(n,r,mod=10**9+7):
    res=1
    div=min(r,n-r)
    for i in range(div):
        res=res*(n-i)*modpow(div-i,mod-2)%mod
    return res%mod

n,a,b=[int(i) for i in input().split()]
ans=modpow(2,n)-1
ans-=modcmb(n,a)
ans%=10**9+7
ans-=modcmb(n,b)
ans%=10**9+7
print(ans)

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


Question:
n,m=[int(i) for i in input().split()]
hoge=[tuple([int(i) for i in input().split()]) for j in range(n)]
hoge.sort()
ans=0
for i in range(len(hoge)):
    if hoge[i][1]>m:
        ans+=hoge[i][0]*m
        break
    else:
        ans+=hoge[i][0]*hoge[i][1]
        m-=hoge[i][1]
print(ans)

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


Question:
n,m=[int(i) for i in input().split()]
a=[input() for i in range(n)]
b=[input() for i in range(m)]
result=True
for i in range(m):
    if (b[i] in a[i])==False:
        result=False
        break
print("Yes" if result else "No")

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


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

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


Question:
N, D = map(int, input().split())
X = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    tmp = 0
    for k in range(D):
      tmp += abs(X[i][k]-X[j][k])**2
    tmp = tmp**0.5
    if tmp == int(tmp):
      ans += 1
print(ans)

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


Question:
N, D = map(int, input().split())
X = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    tmp = 0
    for k in range(D):
      tmp += abs(X[i][k]-X[j][k])**2
    tmp = tmp**0.5
    if tmp == int(tmp):
      ans += 1
print(ans)

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


Question:
n = int(input())
l = list(map(int, input().split()))
if max(l) < sum(l) - max(l):
    print('Yes')
else:
    print('No')

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


Question:
x= int(input())
k = 1
while True:
  a = x*k
  if a%360==0:
    print(k)
    break
  k+=1

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


Question:
x= int(input())
k = 1
while True:
  a = x*k
  if a%360==0:
    print(k)
    break
  k+=1

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


Question:
# 写経
# https://atcoder.jp/contests/abc177/submissions/16463802

import numpy as np
i4 = np.int32
i8 = np.int64

def solve(a, b, H, W):
    ret = np.empty(H, i8)
    for i in range(H):
        ret[i] = -1
    dp0 = np.arange(W) #初期位置
    dp = np.arange(W) #現在位置
    arg0 = W - 1
    arg = 0
    for i in range(H):
        r1 = np.searchsorted(dp, a[i])
        r2 = np.searchsorted(dp, b[i])
        if b[i] == W: #右端まで壁が続く場合
            if r1 == 0:
                return ret
            else:
                dp0 = dp0[: r1] #壁があるところより先は無視する
                dp = dp[: r1]
        else:
            dp[r1:r2] = b[i] #合流させる

        if arg0 > -1:   #直進する流れが残っている場合
            if r1 <= arg0 < r2: #壁がある場合
                for j in range(r1 - 1, -1, -1):
                    if dp[j] == dp0[j]:
                        arg0 = j    #ここまで直進してきた他の流れに乗り換える
                        ret[i] = i + 1
                        break
                else:
                    arg0 = -1
                    arg = np.argmin(dp - dp0) #残っている値の中での最小値
                    ret[i] = dp[arg] - dp0[arg] + i + 1
            else:
                ret[i] = i + 1
        else:
            if r1 <= arg < r2:
                arg = np.argmin(dp - dp0)
            ret[i] = dp[arg] - dp0[arg] + i + 1

        if i % 1000 == 999:
            m = 0
            prev = dp[0]
            for k in range(1, dp.shape[0]):
                if dp[k] > prev: #dp[0]とは別の流れにあるものについて
                    dp0[m] = dp0[k - 1] #最小のずれを持つもののみ残してまとめる
                    dp[m] = prev
                    m += 1
                    prev = dp[k]
            else: #流れが一つのみの場合はこの流れの実を追いかける
                dp0[m] = dp0[dp0.shape[0] - 1]
                dp[m] = prev
                m += 1
            dp0 = dp0[: m]
            dp = dp[: m]
            if arg0 > -1: #現在最小である流れなどの情報も更新しておく
                for j in range(m - 1, -1, -1):
                    if dp[j] == dp0[j]:
                        arg0 = j
                        break
            else:
                arg = np.argmin(dp - dp0)

    return ret

def main(in_file):
    stdin = open(in_file)
    H, W = [int(x) for x in stdin.readline().split()]
    ab = np.fromstring(stdin.read(), i8, sep=' ').reshape((-1, 2)).T.copy()
    ans = solve(ab[0] - 1, ab[1], H, W)
    p = '\n'.join([str(x) for x in ans.tolist()])
    print(p)

def cc_export():
    from numba.pycc import CC
    from numba.types import Array, int64
    cc = CC('my_module')
    cc.export('solve', (Array(int64, 1, 'C'), Array(int64, 1, 'C'), int64, int64))(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main('/dev/stdin')

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


Question:
X,K,D = map(int,input().split())
X = abs(X)
X_div_D = X//D

ans_min = X % D

if K <= X_div_D:
  print(X - K * D)
else:
  if (K % 2) ^ (X_div_D % 2) == 0:
    print(ans_min)
  else:
    print(abs(ans_min - D))

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


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

ans = N//X

if N%X != 0:
    ans+=1

print(ans*T)

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


Question:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

def main():
    H, W, K = [int(x) for x in input().split()]
    S = [list(input().strip()) for _ in range(H)]

    ans = float("inf")

    for n in range(2 ** (H - 1)):
        tmp = 0
        wn = [0] * 10
        wi = [set() for _ in range(10)]

        ni = 0
        for i in range(H):
            wi[ni].add(i)
            if n >> i & 1:
                ni += 1
                tmp += 1

        for i in range(W):
            f = False
            for j in range(H):
                for wii in range(ni + 1):
                    if j in wi[wii]:
                        if wn[wii] + int(S[j][i]) > K:
                            tmp += 1
                            f = True
                        else:
                            wn[wii] += int(S[j][i])
                        break
                if f:
                    break
            if f:
                for wii in range(ni + 1):
                    wn[wii] = 0
                for j in range(H):
                    for wii in range(ni + 1):
                        if j in wi[wii]:
                            wn[wii] += int(S[j][i])
                            break
                for wii in range(ni + 1):
                    if wn[wii] > K:
                        tmp = float("inf")

        ans = min(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main()

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


Question:
import sys
import bisect
from operator import itemgetter

input = sys.stdin.readline

def main():
    N, D, A = [int(x) for x in input().split()]
    XH = []
    X = []
    R = [0] * (N * 2)
    for _ in range(N):
        x, h = [int(x) for x in input().split()]
        XH.append((x, h))
        XH.append((x + 2 * D + 1, -float("inf")))
        X.append(x)
        X.append(x + 2 * D + 1)

    X.sort()
    XH.sort(key=itemgetter(0, 1))

    ans = 0
    ruiseki = 0

    for i in range(N * 2):
        x, h = XH[i]
        if h != -float("inf"):
            if h > ruiseki:
                tmpruiseki = -(-(h - ruiseki) // A) * A
                ans += -(-(h - ruiseki) // A)
                ruiseki += tmpruiseki
                nx = bisect.bisect_left(X, x + 2 * D + 1)
                if XH[nx][1] == -float("inf"):
                    R[nx] -= tmpruiseki
                else:
                    R[nx + 1] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += R[i]

    print(ans)

if __name__ == '__main__':
    main()

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


Question:
import sys
input = sys.stdin.readline

def check(A, F, mid, k):
    for i in range(len(A)):
        if A[i] * F[i] > mid:
            x = A[i] - mid // F[i]
            k -= x
        if k < 0:
            return False
    return True

def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    F = [int(x) for x in input().split()]

    A_s = sorted(A, reverse=True)
    F_s = sorted(F)

    l = -1
    r = 10 ** 13
    while r - l != 1:
        mid = (r + l) // 2
        if check(A_s, F_s, mid, K):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == '__main__':
    main()

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


Question:
s3="s"
es="es"
S=input()
if S[-1]=="s":
	s1= S + es
	print(s1)
else:
	s2 = S + s3
	print(s2)

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


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

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

N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)

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


Question:
A,B=[int(i) for i in input().split(" ")]
if A<=8 and B<=8:
    print("Yay!")
else:
    print(":(")

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


Question:
def get_line():
  return input().split(' ')

class element:
  def __init__(self, P, Y, idx):
    self.P = P
    self.Y = Y
    self.idx = idx
  def __lt__(self, other):
    return self.Y < other.Y

N, M = map(int, get_line())
els = [0] * M
for i in range(M):
  p, y = map(int, get_line())
  els[i] = element(p, y, i)

p_map = [[] for _ in range(N)]

for e in els:
  p_map[e.P - 1].append(e)

ans = [0] * M

for mp in p_map:
  cnt = 1
  for e in sorted(mp):
    ans[e.idx] = "{:06d}{:06d}".format(e.P, cnt)
    cnt = cnt + 1

for e in ans:
  print(e)

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

L = [[x, i] for i, x in enumerate(A)]
L.sort()
dp = [[-1]*N for _ in range(N)]

def rec(l, r):
	if l > r:
		return 0
	if dp[l][r] >= 0:
		return dp[l][r]
	idx = r-l  # 次に選ぶ幼児
	val, i = L[idx]
	dp[l][r] = max(abs(i-l)*val + rec(l+1, r), abs(r-i)*val + rec(l, r-1))
	return dp[l][r]

print(rec(0, N-1))

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
lim = N+10  # 必要そうな階乗の限界を入れる
fact = [1] * (lim+1)
fact_inv = [1] * (lim+1)
for n in range(1, lim+1):
    fact[n] = (fact[n-1] * n) % mod
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
    fact_inv[n-1] = (n * fact_inv[n]) % mod

tree = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(N-1):
	a, b = MAP()
	tree[a].append(b)
	tree[b].append(a)

order = []
parent = [0]*(N+1)
stack = [1]
while stack:
    n = stack.pop()
    order.append(n)
    for node in tree[n]:
        if node == parent[n]:
            continue
        stack.append(node)
        parent[node] = n

size = [1]*(N+1)
for v in order[::-1]:
    size[parent[v]] += size[v]

dpLeaf = [1] * (N+1)
for v in order[::-1]:
    pr = parent[v]
    dpLeaf[v] = dpLeaf[v]*fact[size[v]-1]%mod
    dpLeaf[pr] = dpLeaf[pr]*dpLeaf[v]*fact_inv[size[v]]%mod

ans = [0]*(N+1)
ans[1] = dpLeaf[1]
for v in order[1:]:
    pr = parent[v]
    ans[v] = (ans[pr]*pow(N-size[v], mod-2, mod)*size[v])%mod
print(*ans[1:], sep="\n")

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	H, W, K = MAP()
	S = np.array([list(map(int, list(input()))) for _ in range(H)])

	ans = INF
	for x in product([0, 1], repeat=H-1):
		cut = np.sum(x)
		if cut >= ans:
				continue
		r = 0
		l = []
		for i in range(H-1):
			if x[i]:
				l.append(np.sum(S[r:i+1, :], axis=0))
				r = i + 1
		l.append(np.sum(S[r:, :], axis=0))
		l = np.array(l)
		if np.max(l) > K:
			continue
		tmp = np.zeros(len(l), dtype=int)
		for i in range(W):
			tmp += l[:, i]
			if np.max(tmp) > K:
				cut += 1
				tmp = l[:, i]
			if cut >= ans:
				break

		ans = ans if ans <= cut else cut

	print(ans)

if __name__ == '__main__':
	main()

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	H, W, K = MAP()
	S = np.array([list(map(int, list(input()))) for _ in range(H)])

	ans = INF
	for x in product([0, 1], repeat=H-1):
		cut = np.sum(x)
		if cut >= ans:
				continue
		r = 0
		l = []
		for i in range(H-1):
			if x[i]:
				l.append(np.sum(S[r:i+1, :], axis=0))
				r = i + 1
		l.append(np.sum(S[r:, :], axis=0))
		l = np.array(l)
		if np.max(l) > K:
			continue
		tmp = np.zeros(len(l), dtype=int)
		for i in range(W):
			tmp += l[:, i]
			if np.max(tmp) > K:
				cut += 1
				tmp = l[:, i]
			if cut >= ans:
				break

		ans = ans if ans <= cut else cut

	print(ans)

if __name__ == '__main__':
	main()

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


Question:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = LIST()
S = input()

# stand = []
# reverse = []
# state = None
# count = 0
# tmp = None
# for i in S:
# 	if i == "0":
# 		state = "stand"
# 	else:
# 		state = "reverse"
# 	if tmp == "stand" and state == "reverse":
# 		stand.append(count)
# 		count = 1
# 	elif tmp == "reverse" and state == "stand":
# 		reverse.append(count)
# 		count = 1
# 	else: # 状態が前と同じ
# 		count += 1
# 	tmp = state
# if state == "stand":
# 	stand.append(count)
# else:
# 	reverse.append(count)

# if "0" not in S:
# 	print(len(S))
# else:
# 	if K >= len(stand): # 全員逆立ちにできる
# 		print(len(S))
# 	else:
# 		if len(stand) > len(reverse):
# 			reverse.append(0)
# 			reverse.insert(0, 0)
# 		if len(stand) == len(reverse) and S[0] == "0":
# 			reverse.insert(0, 0)
# 		if len(stand) == len(reverse) and S[0] == "1":
# 			reverse.append(0)
# 		# print(stand)
# 		# print(reverse)
# 		max_ = 0
# 		for i in range(max(1, 1+len(reverse)-(K+1))):
# 			# print(reverse[i:i+K+1],stand[i:i+K])
# 			tmp = sum(reverse[i:i+K+1]+stand[i:i+K])
# 			if tmp > max_:
# 				max_ = tmp
# 		print(max_)
indexes = [0]
if S[0] == "0":
    indexes.append(0)
for i in range(N-1):
	if S[i] != S[i+1]:
		indexes.append(i+1)
indexes.append(N)
if S[N-1] == "0":
    indexes.append(N)
ans = []
# print(indexes)
r = len(indexes)//2 -1
if K >= r:
	print(N)
else:
	print(max(indexes[2*(i+K)+1]-indexes[2*i] for i in range(r-K+1)))
	# for i in range(len(indexes)):
	# 	# print(i)
	# 	if i == len(indexes)-1:
	# 		break
	# 	if S[indexes[i]] == "0":
	# 		if i+2*K >= len(indexes):
	# 			continue
	# 		ans.append(indexes[i+2*K]-indexes[i])
	# 	else:
	# 		if i+2*K+1 >= len(indexes):
	# 			continue
	# 		ans.append(indexes[i+2*K+1]-indexes[i])
	# if ans == []:
	# 	print(len(S))
	# else:
	# 	print(max(ans))

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

AB, BC, CA = [int(x.strip("|")) for x in input().split()]
print(int(AB*BC/2))

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X, Y = MAP()

print(X+Y//2)

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


Question:
from collections import defaultdict

N = int(input())
W = [input().strip() for _ in range(N)]

dic = defaultdict(int)

for i in range(N):
  if i == 0:
    tmp = W[i][-1]
    dic[W[i]] += 1
  else:
    if tmp != W[i][0] or dic[W[i]]:
      print("No")
      break
    else:
      dic[W[i]] += 1
      tmp = W[i][-1]
else:
  print("Yes")

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


Question:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N, M, Q = MAP()
	LR = [LIST() for _ in range(M)]

	x = [[0]*N for _ in range(N)]
	for L, R in LR:
		x[L-1][R-1] += 1

	pq = [LIST() for _ in range(Q)]

	C = [[0]*N for _ in range(N)]

	for i in range(N):
		tmp = 0
		C[i] = list(accumulate(x[i]))

	for p, q in pq:
		p = p-1
		q = q-1
		ans = 0
		for i in range(p, q+1):
			if p-1 <= -1:
				ans += C[i][q]
			else:
				ans += C[i][q]-C[i][p-1]
		print(ans)

if __name__ == "__main__":
	main()

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


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

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


Question:
from functools import reduce
def nCr(n,r,DIV):
  # X/Y mod DIV == X*Y**(DIV-2)
  X=reduce(lambda x,y:x*y%DIV,range(n-r+1,n+1))
  Y=reduce(lambda x,y:x*y%DIV,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

DIV=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,DIV)-1
ans-=nCr(n,a,DIV)
ans-=nCr(n,b,DIV)
print(ans%DIV)

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


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

# M回の握手の幸福度最大化
# X以上になる握手を全て採用したときに、M通りを越える
# Xの最大値を求める

import bisect

ok=-1
ng=(10**10)+2

# x以上の握手をm通り以上作れるか
def isOk(x,m):
  cnt=0
  # 左手をループする
  for i in range(len(A)):
    left=A[i]
    minright=x-left
    # minright以上の数を数える
    cnt+=n-bisect.bisect_left(A,minright)
    if cnt>=m:
      return True
  return cnt>=m

while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOk(mid,m):
    ok=mid
  else:
    ng=mid

x=ok
# x以上となる幸福度を足し合わせる
# 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている

# 効率化のため累積和を作成
Asum=[0]+A
for i in range(1,len(Asum)):
  Asum[i]=Asum[i-1]+Asum[i]

# Aの添字i以降を全て足すときは、
# Asum[-1]-Asum[i]

ans=0
cnt=0
for i in range(len(A)):
  left=A[i]
  minright=x-left
  start=bisect.bisect_left(A,minright)
  cnt+=n-start
  ans+=left*(n-start)+(Asum[-1]-Asum[start])

if cnt>m:
  ans-=(cnt-m)*x

print(ans)

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


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

# M回の握手の幸福度最大化
# X以上になる握手を全て採用したときに、M通りを越える
# Xの最大値を求める

import bisect

ok=-1
ng=(10**10)+2

# x以上の握手をm通り以上作れるか
def isOk(x,m):
  cnt=0
  # 左手をループする
  for i in range(len(A)):
    left=A[i]
    minright=x-left
    # minright以上の数を数える
    cnt+=n-bisect.bisect_left(A,minright)
    if cnt>=m:
      return True
  return cnt>=m

while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOk(mid,m):
    ok=mid
  else:
    ng=mid

x=ok
# x以上となる幸福度を足し合わせる
# 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている

# 効率化のため累積和を作成
Asum=[0]+A
for i in range(1,len(Asum)):
  Asum[i]=Asum[i-1]+Asum[i]

# Aの添字i以降を全て足すときは、
# Asum[-1]-Asum[i]

ans=0
cnt=0
for i in range(len(A)):
  left=A[i]
  minright=x-left
  start=bisect.bisect_left(A,minright)
  cnt+=n-start
  ans+=left*(n-start)+(Asum[-1]-Asum[start])

if cnt>m:
  ans-=(cnt-m)*x

print(ans)

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


Question:
N=int(input())
if N%2==1:
  print(0)
  exit(0)

ans=0
n=N
div=10
while n>=div:
  ans+=n//div
  div*=5
print(ans)

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


Question:
S=input()
dp=[[0 for i in range(2)] for j in range(len(S))]
# dp[x]:x番目の文字に、dp[x][0]:1文字で来たときの最大分割数、dp[x][1]:2文字で来た時
dp[0][0]=1
dp[0][1]=-1
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    dp[i][0]=dp[i-1][1]+1
  elif S[i]!=S[i-1]:
    dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1
  if i-2>=0:
    dp[i][1]=max(dp[i-2][0],dp[i-2][1])+1
print(max(dp[-1][0],dp[-1][1]))

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


Question:
N=int(input())

nums=[]
all=set(['3','5','7'])
def dfs(x):
  if x>N:
    return
  if x>=357:
    if len(all-set(list(str(x))))==0:
      nums.append(x)
  for i in (3,5,7):
    dfs(x*10+i)

dfs(0)
print(len(nums))

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


Question:
n,m=map(int,input().split())
ans=0
import math
for i in range(1,int(math.sqrt(m))+1):
  if m%i!=0:
    continue
  i2=m//i
  if i*n<=m:
    ans=max(ans,i)
  if i2*n<=m:
    ans=max(ans,i2)
print(ans)

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


Question:
# ボールAとボールBをN個の箱に入れる
# A,Bを1つずつ同じ箱に入れることがあってもよい。
# まずAをN個の箱に1つずつ入れる
# その上で、BをN個の箱に1つずつ入れる（すでにAが入っているかどうか、区別する必要がない）
# AとBの個数の組み合わせを列挙し、そのすべてについて(N C (Aの個数)) * (N C (Bの個数))を計算した和が答え

import sys
readline = sys.stdin.readline

N,A,B,K = map(int,readline().split())

DIV = 998244353
n = (10 ** 6) * 2 # PyPyじゃないと通らない。 * 5が限界くらい
g1 = [1] * 2 + [0] * (n - 2) # 元テーブル
g2 = [1] * 2 + [0] * (n - 2) #逆元テーブル
inverse = [0, 1] + [0] * (n - 2) #逆元テーブル計算用テーブル

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

def nCr(n, r, DIV):
  if (r < 0 or r > n):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % DIV

# AとBを足してKになる組み合わせを探索する
ans = 0
for a in range(N + 1):
  b = K - a * A
  if b < 0:
    break # a * Aの時点で負の数。これ以上の探索も不要。
  if b % B != 0:
    continue # 組み合わせを作れない
  if (b // B) > N:
    continue # 箱に入れられない
  # この時点で、Aがa個とBがb個で作れることが確定する
  # (N C (Aの個数)) * (N C (Bの個数))
  ans += (nCr(N, a, DIV) * nCr(N, b // B, DIV)) % DIV
  ans %= DIV

print(ans)

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


Question:
# a b c
# b e d
# c d f
# について、
#  a  b  c [a  b]
#  b  e  d [b  e]
#  c  d  f [c  d]
# [a  b  c  a  b]
# [b  e  d  b  e]
# 左上の1,1から始まるものが条件を満たすなら、
# 2,2から始まるものも3,3から始まるものも条件を満たす
# 一つ条件を満たすのであれば、N個条件を満たすことになる。
# 従い、以下を順にチェックして答えをN倍すれば良い
#  a  b  c [a  b]
#  b  e  d [b  e]
#  c  d  f [c  d]

import sys
readline = sys.stdin.readline

N = int(readline())
grid = [None] * N
for i in range(N):
  S = readline().rstrip()
  grid[i] = S + S[:-1]

# 左上の頂点を(0,0)~(N-1,0)の全てをチェックする
ans = 0
for p in range(N):
  # 左上の頂点はp
  ok = True
  for i in range(N):
    for j in range(i+1):
      if grid[i][j + p] != grid[j][i + p]:
        ok = False
        break
    if not ok:
      break
  if ok:
    ans += 1

print(ans * N)

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


Question:
n,m=map(int,input().split())
b=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
  x,y=map(int,input().split())
  x,y=x-1,y-1
  if not b[x]:
    continue
  b[y]+=1
  if red[x]:
    red[y]=True

  b[x]-=1
  if b[x]==0:
    red[x]=False

print(red.count(True))

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


Question:
w,h,x,y=map(int,input().split())
s=float((w/2)*h)
ans=0
if w%2==0 and h%2==0:
    if w//2==x and h//2==y:
        ans=1
else:
    ans=0

print(str(float(s))+" "+str(ans))

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


Question:
n,m,c=map(int, raw_input().split())
b=list(map(int,raw_input().split()))
a=[]
for i in range(n):
    a.append(list(map(int,raw_input().split())))
counter=0
for i in range(n):
    d=0
    for k in range(m):
        d+=a[i][k]*b[k]
    if d+c>0:
        counter+=1
print counter

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


Question:
n=int(input())
l=[]
for i in range(3,n+1,2):
    c=0
    for k in range(1,i+1):
        if i%k==0:
            c+=1
        else:
            pass
    l.append(c)
print(l.count(8))

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


Question:
import sys
input = sys.stdin.readline
LLL = 1<<20

N, M = map(int, input().split())
R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a*2, b, 0))
for i in range(M):
    l, r = map(int, input().split())
    R.append((l*2-1, 2, i))
    R.append((r*2+1, 3, i))

R.sort(key=lambda x:x[0])
nodeid = 0
bf = -1
d = []
eid2lid = dict()
id2eid = dict()
G = [set()]
for x, f, i in R:
    if f <= 1:
        d.append(int(f != bf and bf != -1))
        bf = f
        nodeid += 1
        G.append(set())
    else:
        if f == 3:
#            print(x2id, l)
            lid = eid2lid[i]
            if nodeid != lid:
                G[nodeid].add((lid, i+1))
                G[lid].add((nodeid, i+1))
#                id2eid[lid*LLL+nodeid] = i
#            id2eid[(n2, n1)] = i
        eid2lid[i] = nodeid
d.append(int(bf==1))

xxs = [-1]*(nodeid+1)
g2 = [set() for _ in range(nodeid+1)]
vs = set()
cut_edges = set()
for i in range(nodeid+1):
    if i in vs:
        continue
    stack = [i]
    dfs_vs = []
    vs.add(i)
    while stack:
        v = stack.pop()
        dfs_vs.append(v)
        for u, j in G[v]:
            if u in vs:
                continue
            g2[v].add((u, j))
            stack.append(u)
            vs.add(u)
    for v in dfs_vs[::-1]:
        r = d[v]
        for u, j in g2[v]:
            ff = xxs[u]
            if ff:
                cut_edges.add(j)
            r = (r+ff)%2
        xxs[v] = r if v != 0 else 0
    if xxs[i]:
        print(-1)
        break
else:
    print(len(cut_edges))
    print(*sorted(cut_edges))

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


Question:
import sys
input = sys.stdin.readline
LLL = 1<<20

N, M = map(int, input().split())
R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a*2, b, 0))
for i in range(M):
    l, r = map(int, input().split())
    R.append((l*2-1, 2, i))
    R.append((r*2+1, 3, i))

R.sort(key=lambda x:x[0])
nodeid = 0
bf = -1
d = []
eid2lid = dict()
id2eid = dict()
G = [set()]
for x, f, i in R:
    if f <= 1:
        d.append(int(f != bf and bf != -1))
        bf = f
        nodeid += 1
        G.append(set())
    else:
        if f == 3:
#            print(x2id, l)
            lid = eid2lid[i]
            if nodeid != lid:
                G[nodeid].add((lid, i+1))
                G[lid].add((nodeid, i+1))
#                id2eid[lid*LLL+nodeid] = i
#            id2eid[(n2, n1)] = i
        eid2lid[i] = nodeid
d.append(int(bf==1))

xxs = [-1]*(nodeid+1)
g2 = [set() for _ in range(nodeid+1)]
vs = set()
cut_edges = set()
for i in range(nodeid+1):
    if i in vs:
        continue
    stack = [i]
    dfs_vs = []
    vs.add(i)
    while stack:
        v = stack.pop()
        dfs_vs.append(v)
        for u, j in G[v]:
            if u in vs:
                continue
            g2[v].add((u, j))
            stack.append(u)
            vs.add(u)
    for v in dfs_vs[::-1]:
        r = d[v]
        for u, j in g2[v]:
            ff = xxs[u]
            if ff:
                cut_edges.add(j)
            r = (r+ff)%2
        xxs[v] = r if v != 0 else 0
    if xxs[i]:
        print(-1)
        break
else:
    print(len(cut_edges))
    print(*sorted(cut_edges))

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


Question:
import sys
input = sys.stdin.readline
LLL = 1<<20

N, M = map(int, input().split())
R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a*2, b, 0))
for i in range(M):
    l, r = map(int, input().split())
    R.append((l*2-1, 2, i))
    R.append((r*2+1, 3, i))

R.sort(key=lambda x:x[0])
nodeid = 0
bf = -1
d = []
eid2lid = dict()
id2eid = dict()
G = [set()]
for x, f, i in R:
    if f <= 1:
        d.append(int(f != bf and bf != -1))
        bf = f
        nodeid += 1
        G.append(set())
    else:
        if f == 3:
#            print(x2id, l)
            lid = eid2lid[i]
            if nodeid != lid:
                G[nodeid].add((lid, i+1))
                G[lid].add((nodeid, i+1))
#                id2eid[lid*LLL+nodeid] = i
#            id2eid[(n2, n1)] = i
        eid2lid[i] = nodeid
d.append(int(bf==1))

xxs = [-1]*(nodeid+1)
g2 = [set() for _ in range(nodeid+1)]
vs = set()
cut_edges = set()
for i in range(nodeid+1):
    if i in vs:
        continue
    stack = [i]
    dfs_vs = []
    vs.add(i)
    while stack:
        v = stack.pop()
        dfs_vs.append(v)
        for u, j in G[v]:
            if u in vs:
                continue
            g2[v].add((u, j))
            stack.append(u)
            vs.add(u)
    for v in dfs_vs[::-1]:
        r = d[v]
        for u, j in g2[v]:
            ff = xxs[u]
            if ff:
                cut_edges.add(j)
            r = (r+ff)%2
        xxs[v] = r if v != 0 else 0
    if xxs[i]:
        print(-1)
        break
else:
    print(len(cut_edges))
    print(*sorted(cut_edges))

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


Question:
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

import sys
input = sys.stdin.readline

N = int(input())

d2 = [1]
inverse = [0, 1]
for _ in range(N):
    d2.append(2*d2[-1]%mod)
for i in range( 2,  10):
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

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

v2i = [0 for _ in range(N+1)]
def itt(v, p):
    cn = 0
    ms = []
    for u in G[v]:
        if u == p:
            continue
        un = itt(u, v)
        ms.append(un)
        cn += un
    if p != None:
        ms.append(N-1-cn)
    v2i[v] = ms
    return cn+1
itt(1, None)
r = 0
for v in range(1, N+1):
    ff = v2i[v]
    for f in ff:
        r += d2[f] - 1 % mod
r = N*d2[N-1]-N-r
for _ in range(N):
    r = r*500000004 % mod
print(r)

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


Question:
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

import sys
input = sys.stdin.readline

N = int(input())

d2 = [1]
inverse = [0, 1]
for _ in range(N):
    d2.append(2*d2[-1]%mod)
for i in range( 2,  10):
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

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

v2i = [0 for _ in range(N+1)]
def itt(v, p):
    cn = 0
    ms = []
    for u in G[v]:
        if u == p:
            continue
        un = itt(u, v)
        ms.append(un)
        cn += un
    if p != None:
        ms.append(N-1-cn)
    v2i[v] = ms
    return cn+1
itt(1, None)
r = 0
for v in range(1, N+1):
    ff = v2i[v]
    for f in ff:
        r += d2[f] - 1 % mod
r = N*d2[N-1]-N-r
for _ in range(N):
    r = r*500000004 % mod
print(r)

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


Question:
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

import sys
input = sys.stdin.readline

N = int(input())

d2 = [1]
inverse = [0, 1]
for _ in range(N):
    d2.append(2*d2[-1]%mod)
for i in range( 2,  10):
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

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

v2i = [0 for _ in range(N+1)]
def itt(v, p):
    cn = 0
    ms = []
    for u in G[v]:
        if u == p:
            continue
        un = itt(u, v)
        ms.append(un)
        cn += un
    if p != None:
        ms.append(N-1-cn)
    v2i[v] = ms
    return cn+1
itt(1, None)
r = 0
for v in range(1, N+1):
    ff = v2i[v]
    for f in ff:
        r += d2[f] - 1 % mod
r = N*d2[N-1]-N-r
for _ in range(N):
    r = r*500000004 % mod
print(r)

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


Question:
import sys
N, = map(int, input().split())
mx, md, my = 0, 0, 10**9
ps = []

for _ in range(N):
    x, y = map(int, input().split())
    mx = max(x, mx)
    my = min(y, my)
    md = max(y-x+1, md)
    ps.append([x,y])

ps.sort()
for p in ps:
#    p[1] *= -1
    if p == [mx, my]:
        print(my-mx+1+md)
        sys.exit()

for i, (x, y) in enumerate(ps):
    if y == my:
        mmx = x
        del ps[i]
        break

from collections import deque
rs = []
dq = deque()
for i in range(N-1):
    while True:
        if not len(dq):
            dq.append(i)
            break
        lxi = dq[-1]
        if ps[i][1] >= ps[lxi][1]:
            dq.append(i)
            break
        dq.pop()

r = max(my-mx+1, 0) + md
r = max(r, max(my - mmx + 1, 0) + max(ps[dq.popleft()][1] - mx + 1, 0))
#SegTree(pys, N-1, 10**9, min)
for i in range(N-2):
    x = max(ps[i][0], mmx)
    if len(dq):
        if i+1 == dq[0]:
            y = ps[dq.popleft()][1] # mx
    #y = min(p[1] for p in ps[i+1:])
#    print(r)
    r = max(r, max(my - x + 1, 0) + max(y - mx + 1, 0))
print(r)

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


Question:
MOD = 998244353

def zeta_gcd(a,primes):
    n = len(a)-1
    for p in primes:
        for i in range(n//p,0,-1):
            a[i] += a[p*i]
            a[i] %= MOD
def mobius_gcd(a,primes):
    n = len(a)
    for p in primes:
        for i in range(1,n):
            if i*p >= n: break
            a[i] -= a[p*i]
            a[i] %= MOD
def get_primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

NNN = 10**6 + 1
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )

N, = map(int, input().split())
X = list(map(int, input().split()))
primes = get_primes(NNN)
fs = [0]*NNN
for x in X:
    fs[x] += x
#print(fs)
zeta_gcd(fs, primes)
#print(fs)
for i, x in enumerate(fs):
    fs[i] = x**2
#print(fs)
mobius_gcd(fs, primes)
#print(fs)
r = 0
for i, f in enumerate(fs[1:]):
    i += 1
    r = (r + f*inverse[i]) % MOD
for x in X:
    r = (r - x) % MOD

print((r*inverse[2])%MOD)

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


Question: print(pow(int(input()), 3))

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


Question:
import sys
P = int(input())
As = list(map(int, input().split()))
rs = [0]*P
mod = P
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 3000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
C = []
for i in range(P):
    C.append(cmb(P-1, i))

for i in range(P):
    if As[i]:
        rs[0] += 1
        tmp = 1
        for k in range(P):
            k = P-1-k
            rs[k] += (-1 + 2*(k%2)) * tmp * C[k]
            rs[k] %= mod
            tmp = tmp * i % mod
print(*rs)

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


Question:
import sys
P = int(input())
As = list(map(int, input().split()))
rs = [0]*P
mod = P
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 3000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
C = []
for i in range(P):
    C.append(cmb(P-1, i))

for i in range(P):
    if As[i]:
        rs[0] += 1
        tmp = 1
        for k in range(P):
            k = P-1-k
            rs[k] += (-1 + 2*(k%2)) * tmp * C[k]
            rs[k] %= mod
            tmp = tmp * i % mod
print(*rs)

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


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

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


Question:
N = int(input().strip())
M = pow(10, 9) + 7
a = 1
g = 1
ag = 0
agg = 0
agt = 0
atg = 0
ac = 0
at = 0
aa = 0
ga = 0

al = 4
nal = 0

for i in range(N-1):
    nal = (al * 4) % M
    nal = (nal + M - (ag + ac + ga + agg + agt + atg) ) % M

    agg = ag
    agt = ag
    atg = at
    ag = a
    aa = a
    at = a
    nac = (a + M- ga) % M
    ga = g
    a = al
    g = (al + M - ac) % M
    ac = nac
    al = nal
print(al)

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


Question:
N, M = [int(x) for x in input().strip().split(' ')]

if N >= 1000:
    for i in range(M//N):
        n = (M//N)-i
        if M % n == 0:
            print(n)
            break
else:
    x = M//(M//N)
    for i in range(M):
        i = x +i
        if M % i == 0:
            print(M//i)
            break

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


Question:
a, b, _, k = [int(x) for x in input().strip().split(" ")]

if k % 2 == 0:
    print(a-b)
else:
    print(b-a)

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


Question:
N, = map(int, input().split())
X = set(map(str, input().split()))
if len(X) == 3:
    print("Three")
else:
    print("Four")

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


Question:
N = int(input())
ans = "Yes"
arr = []
for i in range(N):
    arr.append(input())
    if not i == 0:
        if arr[i-1][-1] == arr[i][0] and not arr[i] in arr[:-2]:
            pass
        else:
            ans = "No"
            break

print(ans)

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


Question:
n,x,t=map(int,input().split())
ans=0;
while(n>0):
	ans+=t;
	n-=x;
print(ans)

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


Question:
n,x,t = map(int,input().split())
if n % x == 0:
    print(n//x*t)
else:
    print((n//x+1)*t)

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


Question:
a = input().count("A")
if a == 3:
  print("No")
elif a == 0:
  print("No")
else:
  print("Yes")

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


Question:
n,a,b = map(int,input().split())
ans = a*(n//(a+b)) + min(n%(a+b),a)
print(ans)

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


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

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


Question:
li = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = map(int,input().split())
if li.index(a) == li.index(b):
    print("Draw")
elif li.index(a) > li.index(b):
    print("Alice")
else:
    print("Bob")

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


Question:
li = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = map(int,input().split())
if li.index(a) == li.index(b):
    print("Draw")
elif li.index(a) > li.index(b):
    print("Alice")
else:
    print("Bob")

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


Question:
B=[];C=[];S=0
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
  b,c=map(int,input().split())
  B.append(b)
  C.append(c)

X=[0]*(10**5+1)
for i in range(N):
  X[A[i]]+=1
  S=S+A[i]

#print(A)
#print(B)
#print(C)

for i in range(Q):
  X[C[i]]+=X[B[i]]
  S=S+X[B[i]]*(C[i]-B[i])
  X[B[i]]=0
  print(S)

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


Question:
N=int(input())
p=1
S=[]
A=[]
U=[]
T=[]
L= [list(map(str,input().split())) for i in range(N)]
for j in range(1,N+1):
  L[j-1].append(j)
L.sort(key=lambda x: x[0])
#print(L)
S=L[:]
S.sort(reverse=True,key=lambda x: int(x[1]))
#print(S)
T.append(L[0][0])
for i in range(1,N):
  if L[i-1][0]!=L[i][0]:
    T.append(L[i][0])
#print(T)
for j in range(len(T)):
  for k in range(N):
    if S[k][0]==T[j]:
      A.append(S[k][2])
for i in range(N):
  print(A[i])

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


Question:
def d(n):
  return len(str(n))

N=int(input())
if N==1:
  print(1)
else:
  i=0
  #print(int(N**0.5))
  while N%(int(N**0.5)-i)!=0:
    i=i+1
  print(max(d(int(N**0.5)-i),d(N//(int(N**0.5)-i))))

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


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

def calc_C(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r))) % (10**9 + 7)

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

ans = 0

# row
for i in range(N):
    ans += i * (N - i) * M * M % (10**9 + 7)

# col
for i in range(M):
    ans += i * (M - i) * N * N % (10**9 + 7)

ans = ans % (10**9 + 7)
ans = ans * calc_C(N * M - 2, K - 2) % (10**9 + 7)
print(ans)

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


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

def calc_C(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r))) % (10**9 + 7)

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

ans = 0

# row
for i in range(N):
    ans += i * (N - i) * M * M % (10**9 + 7)

# col
for i in range(M):
    ans += i * (M - i) * N * N % (10**9 + 7)

ans = ans % (10**9 + 7)
ans = ans * calc_C(N * M - 2, K - 2) % (10**9 + 7)
print(ans)

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


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

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    if len(pop_cands) == 0:
        break

    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break

    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)    # not necessary actually
print(mp_max)

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


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

ans = 0

for i in range(len(A)-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]

print(ans+sum(B))

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


Question:
A, B, C = map(int, input().split())

A -= B
C -= A

if C < 0:
    print(0)
else:
    print(C)

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


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

print(T / X)

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


Question:
N = input()

print("Yes" if N[0] == N[2] else "No")

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


Question:
N = input()

print("Yes" if N[0] == N[2] else "No")

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


Question:
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

temp=min(mod,a)
ans+=temp
print(ans)

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


Question:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv

    fac,finv,inv=COMinit(N,MOD)

    def COM(n, k, MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u

    def modpow(n,k,MOD):
        if k<0:
            return pow(modinv(n,MOD),-k,MOD)
        else:
            return pow(n,k,MOD)

    C.sort(reverse=1)
    ans=0
    for i in range(N):
        ans+=(modpow(2,i,MOD)+i*modpow(2,i-1,MOD))*2*modpow(2,N-(i+1),MOD)*C[i]
        ans%=MOD
    ans*=pow(2,N-1,MOD)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()

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


Question:
N,K=map(int,input().split())
h=list(map(int,input().split()))
s=0
for i in h:
  s+=1 if i >= K else 0
print(s)

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


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

if c >= a:
  c -= a
  b = max(0, b-c)
  print(0, b)
else:
  print(a-c, b)

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


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

if c >= a:
  c -= a
  b = max(0, b-c)
  print(0, b)
else:
  print(a-c, b)

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


Question:
y, m, d = map(int, input().split('/'))

if y < 2019:
	print("Heisei")
elif y == 2019:
	if m < 4 or (m == 4 and d <= 30):
		print("Heisei")
	else:
		print("TBD")
else:
	print("TBD")

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


Question:
y, m, d = map(int, input().split('/'))

if y < 2019:
	print("Heisei")
elif y == 2019:
	if m < 4 or (m == 4 and d <= 30):
		print("Heisei")
	else:
		print("TBD")
else:
	print("TBD")

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


Question:
y, m, d = map(int, input().split('/'))

if y < 2019:
	print("Heisei")
elif y == 2019:
	if m < 4 or (m == 4 and d <= 30):
		print("Heisei")
	else:
		print("TBD")
else:
	print("TBD")

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


Question:
ri = lambda: map(int, input().split(' '))
L = [1]
C = [1]

def rec(n, x):
	if x == 0:
		return 0

	if n == 0:
		return 1

	if x == L[n]:
		return 2*C[n-1] + 1

	ans = 0
	if x >= L[n-1] + 2:
		ans += C[n-1] + 1
		ans += rec(n-1, x-L[n-1]-2)
	else:
		ans += rec(n-1, x-1)

	return ans

if __name__ == '__main__':
	N, X = ri()
	for i in range(1, N+1):
		L.append(2*L[i-1] + 3)
		C.append(2*C[i-1] + 1)
	ans = rec(N, X)
	print(ans)

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


Question:
import itertools

n, m = map(int, input().split())
d = []
for _ in range(m):
    a, b, c = map(int, input().split())
    d.append((a - 1, b - 1, c))

wf = [[float('inf')] * n for _ in range(n)]
for a, b, c in d:
    wf[a][b] = wf[b][a] = c
for i in range(n):
    wf[i][i] = 0

for k, i, j in itertools.product(range(n), repeat=3):
    wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

ans = 0
for a, b, c in d:
    used = False
    for i in range(n):
        for j in range(i + 1, n):
            if wf[i][a] + c + wf[b][j] == wf[i][j] \
                    or wf[i][b] + c + wf[a][j] == wf[i][j] \
                    or wf[j][a] + c + wf[b][i] == wf[j][i] \
                    or wf[j][b] + c + wf[a][i] == wf[j][i]:
                used = True

    if not used:
        ans += 1

print(ans)

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


Question:
import itertools

n, m = map(int, input().split())
d = []
for _ in range(m):
    a, b, c = map(int, input().split())
    d.append((a - 1, b - 1, c))

wf = [[float('inf')] * n for _ in range(n)]
for a, b, c in d:
    wf[a][b] = wf[b][a] = c
for i in range(n):
    wf[i][i] = 0

for k, i, j in itertools.product(range(n), repeat=3):
    wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

ans = 0
for a, b, c in d:
    used = False
    for i in range(n):
        for j in range(i + 1, n):
            if wf[i][a] + c + wf[b][j] == wf[i][j] \
                    or wf[i][b] + c + wf[a][j] == wf[i][j] \
                    or wf[j][a] + c + wf[b][i] == wf[j][i] \
                    or wf[j][b] + c + wf[a][i] == wf[j][i]:
                used = True

    if not used:
        ans += 1

print(ans)

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


Question:
N=int(input())
ans=N
for i in range(N+1):
  cnt=0
  t=i
  while t>0:
    cnt+=t%6
    t//=6
  j=N-i
  while j>0:
    cnt+=j%9
    j//=9
  ans=min(ans,cnt)
print(ans)

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


Question:
import sys
readline = sys.stdin.readline

K, Q = map(int, readline().split())

D = list(map(int, readline().split()))

Ans = [None]*Q
for q in range(Q):
    n, x, mod = map(int, readline().split())
    x%= mod
    D2 = [d%mod for d in D]
    res = 0
    cnt = 0
    zero = 0
    for d2 in D2:
        res += d2
        if res > mod:
            cnt += 1
            res -= mod
        if not d2:
            zero += 1

    loop =  ((n-1)//K)
    minus = loop*cnt
    zero *= loop
    res2 = 0
    for i in range((n-1)%K):
        res2 += D2[i]
        if not D2[i]:
            zero += 1
        if res > mod:
            res -= mod
            minus += 1
    minus += (x%mod + loop*res + res2)//mod
    Ans[q] = n-1 - zero - minus
print('\n'.join(map(str, Ans)))

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


Question:
import sys
readline = sys.stdin.readline

MOD = 10**9+7
N = int(readline())
C = list(map(int, readline().split()))
C.sort()

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

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


Question:
import sys
readline = sys.stdin.readline

N, A, B = map(int, readline().split())

ans = None
if (B - A) % 2 == 0:
    ans = (B-A)//2
else:
    ans = A + (B - A - 1)//2
    ans = min(ans, N-B+1 + (-A+B-1)//2)
print(ans)

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


Question:
import sys
from itertools import accumulate
class Segtree:
    def __init__(self, A, intv, initialize = True, segf = max):
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        self.segf = segf
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-1, 0, -1):
                self.data[i] = self.segf(self.data[2*i], self.data[2*i+1])
        else:
            self.data = [intv]*(2*self.N0)

    def update(self, k, x):
        k += self.N0
        self.data[k] = x
        while k > 0 :
            k = k >> 1
            self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

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

    def binsearch(self, l, r, check, reverse = False):
        L, R = l+self.N0, r+self.N0
        SL, SR = [], []
        while L < R:
            if R & 1:
                R -= 1
                SR.append(R)
            if L & 1:
                SL.append(L)
                L += 1
            L >>= 1
            R >>= 1

        if reverse:
            for idx in (SR + SL[::-1]):
                if check(self.data[idx]):
                    break
            else:
                return -1
            while idx < self.N0:
                if check(self.data[2*idx+1]):
                    idx = 2*idx + 1
                else:
                    idx = 2*idx
            return idx
        else:
            for idx in (SL + SR[::-1]):
                if check(self.data[idx]):
                    break
            else:
                return -1
            while idx < self.N0:
                if check(self.data[2*idx]):
                    idx = 2*idx
                else:
                    idx = 2*idx + 1
            return idx

readline = sys.stdin.readline
N, K = map(int, readline().split())
P = list(map(int, readline().split()))
STmax = Segtree(P, 0, True, max)
STmin = Segtree(P, 10**9, True, min)
ans = N - K + 1
upper = [0]*(N-1)
for i in range(N-1):
    if P[i] > P[i+1]:
        upper[i] = 1
upper = list(accumulate(upper)) + [0]
cnt = 0
for i in range(N-K):
    if upper[i+K-2] == upper[i-1]:
        cnt += 1
    elif P[i+K] == STmax.query(i+1, i+K+1) and P[i] == STmin.query(i, i+K):
        ans -= 1
if upper[N-2] == upper[N-K-1]:
    cnt += 1
print(ans - max(0, cnt-1))

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


Question:
import sys
readline = sys.stdin.readline
MOD = 998244353
N = int(readline())
A = list(map(int, readline().split()))
mA = max(A) + 1
T = [0]*mA
i2 = pow(2, MOD-2, MOD)

table = [0]*mA
table2 = [0]*mA
for a in A:
    table[a] = (table[a] + a)%MOD
    table2[a] = (table2[a] + a*a)%MOD
prime = [True]*mA
for p in range(2, mA):
    if not prime[p]:
        continue
    for k in range((mA-1)//p, 0, -1):
        table[k] = (table[k] + table[k*p])%MOD
        table2[k] = (table2[k] + table2[k*p])%MOD
        prime[k*p] = False

T = [(x1*x1-x2)*i2%MOD for x1, x2 in zip(table, table2)]

ans = 0
coeff = [0]*mA
for i in range(1, mA):
    k = T[i]
    l = - coeff[i] + pow(i, MOD-2, MOD)
    ans = (ans+l*k)%MOD
    for j in range(2*i, mA, i):
        coeff[j] = (coeff[j] + l)%MOD
print(ans)

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


Question:
import sys
readline = sys.stdin.readline

import collections
class Dinic:
    def __init__(self, vnum):
        self.edge = [[] for i in range(vnum)]
        self.n = vnum
        # infはint型の方が良いかもね
        self.inf = float('inf')
    def addedge(self, st, en, c):
        self.edge[st].append([en, c, len(self.edge[en])])
        self.edge[en].append([st, 0, len(self.edge[st])-1])
    def bfs(self, vst):
        dist = [-1]*self.n
        dist[vst] = 0
        Q = collections.deque([vst])
        while Q:
            nv = Q.popleft()
            for vt, c, r in self.edge[nv]:
                if dist[vt] == -1 and c > 0:
                    dist[vt] = dist[nv] + 1
                    Q.append(vt)
        self.dist = dist
    def dfs(self, nv, en, nf):
        nextv = self.nextv
        if nv == en:
            return nf
        dist = self.dist
        ist = nextv[nv]
        for i, (vt, c, r) in enumerate(self.edge[nv][ist:], ist):
            if dist[nv] < dist[vt] and c > 0:
                df = self.dfs(vt, en, min(nf, c))
                if df > 0:
                    self.edge[nv][i][1] -= df
                    self.edge[vt][r][1] += df
                    return df
            nextv[nv] += 1
        return 0
    def getmf(self, st, en):
        mf = 0
        while True:
            self.bfs(st)
            if self.dist[en] == -1:
                break
            self.nextv = [0]*self.n
            while True:
                fl = self.dfs(st, en, self.inf)
                if fl > 0:
                    mf += fl
                else:
                    break
        return mf

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

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

st = 2*N
en = 2*N+1
used = set()
for num in range(M):
    T = Dinic(2*N+2)
    for i in range(N):
        T.addedge(st, i, 1)
        T.addedge(N+i, en, 1)
        for j in range(M):
            aij = A[i][j]
            if aij not in used:
                T.addedge(i, N+(aij-1)//M, 1)

    T.getmf(st, en)
    for i in range(N):
        candi = [e for e, cost, _ in T.edge[i+N] if cost == 1][0]
        for j in range(M):
            if A[candi][j] not in used and (A[candi][j]-1)//M == i:
                used.add(A[candi][j])
                B[candi][num] = A[candi][j]
                break
C = list(map(list, zip(*B)))
C = [sorted(c) for c in C]
C = list(map(list, zip(*C)))

for b in B:
    print(*b)

for c in C:
    print(*c)

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


Question:
import sys
readline = sys.stdin.readline

import collections
class Dinic:
    def __init__(self, vnum):
        self.edge = [[] for i in range(vnum)]
        self.n = vnum
        # infはint型の方が良いかもね
        self.inf = float('inf')
    def addedge(self, st, en, c):
        self.edge[st].append([en, c, len(self.edge[en])])
        self.edge[en].append([st, 0, len(self.edge[st])-1])
    def bfs(self, vst):
        dist = [-1]*self.n
        dist[vst] = 0
        Q = collections.deque([vst])
        while Q:
            nv = Q.popleft()
            for vt, c, r in self.edge[nv]:
                if dist[vt] == -1 and c > 0:
                    dist[vt] = dist[nv] + 1
                    Q.append(vt)
        self.dist = dist
    def dfs(self, nv, en, nf):
        nextv = self.nextv
        if nv == en:
            return nf
        dist = self.dist
        ist = nextv[nv]
        for i, (vt, c, r) in enumerate(self.edge[nv][ist:], ist):
            if dist[nv] < dist[vt] and c > 0:
                df = self.dfs(vt, en, min(nf, c))
                if df > 0:
                    self.edge[nv][i][1] -= df
                    self.edge[vt][r][1] += df
                    return df
            nextv[nv] += 1
        return 0
    def getmf(self, st, en):
        mf = 0
        while True:
            self.bfs(st)
            if self.dist[en] == -1:
                break
            self.nextv = [0]*self.n
            while True:
                fl = self.dfs(st, en, self.inf)
                if fl > 0:
                    mf += fl
                else:
                    break
        return mf

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

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

st = 2*N
en = 2*N+1
used = set()
for num in range(M):
    T = Dinic(2*N+2)
    for i in range(N):
        T.addedge(st, i, 1)
        T.addedge(N+i, en, 1)
        for j in range(M):
            aij = A[i][j]
            if aij not in used:
                T.addedge(i, N+(aij-1)//M, 1)

    T.getmf(st, en)
    for i in range(N):
        candi = [e for e, cost, _ in T.edge[i+N] if cost == 1][0]
        for j in range(M):
            if A[candi][j] not in used and (A[candi][j]-1)//M == i:
                used.add(A[candi][j])
                B[candi][num] = A[candi][j]
                break
C = list(map(list, zip(*B)))
C = [sorted(c) for c in C]
C = list(map(list, zip(*C)))

for b in B:
    print(*b)

for c in C:
    print(*c)

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


Question:
import sys
readline = sys.stdin.readline

import collections
class Dinic:
    def __init__(self, vnum):
        self.edge = [[] for i in range(vnum)]
        self.n = vnum
        # infはint型の方が良いかもね
        self.inf = float('inf')
    def addedge(self, st, en, c):
        self.edge[st].append([en, c, len(self.edge[en])])
        self.edge[en].append([st, 0, len(self.edge[st])-1])
    def bfs(self, vst):
        dist = [-1]*self.n
        dist[vst] = 0
        Q = collections.deque([vst])
        while Q:
            nv = Q.popleft()
            for vt, c, r in self.edge[nv]:
                if dist[vt] == -1 and c > 0:
                    dist[vt] = dist[nv] + 1
                    Q.append(vt)
        self.dist = dist
    def dfs(self, nv, en, nf):
        nextv = self.nextv
        if nv == en:
            return nf
        dist = self.dist
        ist = nextv[nv]
        for i, (vt, c, r) in enumerate(self.edge[nv][ist:], ist):
            if dist[nv] < dist[vt] and c > 0:
                df = self.dfs(vt, en, min(nf, c))
                if df > 0:
                    self.edge[nv][i][1] -= df
                    self.edge[vt][r][1] += df
                    return df
            nextv[nv] += 1
        return 0
    def getmf(self, st, en):
        mf = 0
        while True:
            self.bfs(st)
            if self.dist[en] == -1:
                break
            self.nextv = [0]*self.n
            while True:
                fl = self.dfs(st, en, self.inf)
                if fl > 0:
                    mf += fl
                else:
                    break
        return mf

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

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

st = 2*N
en = 2*N+1
used = set()
for num in range(M):
    T = Dinic(2*N+2)
    for i in range(N):
        T.addedge(st, i, 1)
        T.addedge(N+i, en, 1)
        for j in range(M):
            aij = A[i][j]
            if aij not in used:
                T.addedge(i, N+(aij-1)//M, 1)

    T.getmf(st, en)
    for i in range(N):
        candi = [e for e, cost, _ in T.edge[i+N] if cost == 1][0]
        for j in range(M):
            if A[candi][j] not in used and (A[candi][j]-1)//M == i:
                used.add(A[candi][j])
                B[candi][num] = A[candi][j]
                break
C = list(map(list, zip(*B)))
C = [sorted(c) for c in C]
C = list(map(list, zip(*C)))

for b in B:
    print(*b)

for c in C:
    print(*c)

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


Question:
N, A, B, C, D =  map(int, input().split())
S = input()
S = [False] + [s == '.' for s in S] + [False]
def check(s, t):
    i = s
    for _ in range(s, t+1):
        if i + 1 == t or i + 2 == t:
            return True
        if S[i+2]:
            i += 2
            continue
        if S[i+1]:
            i += 1
            continue
        return False

def checki(s, t):
    for i in range(s, t+1):
        if S[i-1] and S[i] and S[i+1]:
            return True
    return False

if A < B < D < C:
    if not check(B, D) or not check(A, C):
        print('No')
    elif checki(B, D):
        print('Yes')
    else:
        print('No')
else:
    if check(A, C) and check(B, D):
        print('Yes')
    else:
        print('No')

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


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

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


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


Question:
import sys
readline = sys.stdin.readline
from functools import reduce
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def calc(A):
    N = len(A)
    if N == 1:
        return A[0]%2 == 0

    K = sum(1 for a in A if a % 2 == 0)
    if K & 1:
        return True
    if N-K != 1:
        return False
    if min(A) == 1:
        return False
    A = [a-a%2 for a in A]
    g = reduce(gcd, A)
    A = [a//g for a in A]
    return not calc(A)

N = int(readline())
A = list(map(int, readline().split()))
print('First' if calc(A) else 'Second')

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


Question:
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N, x = inpl()
a = np.array(inpl())
b = np.copy(a)
ans = float('inf')
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)

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


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

Ab.sort(reverse=True)
#dp[i][j] Aの大きいじゅんにi個とったとき、左寄せj個、右寄せi-j個としたときのMAX
dp = [[0 for _ in range(N+5)] for _ in range(N+5)]
dp[0][0] = 0

for i in range(0,N):
  a, p = Ab[i]
  for j in range(0,i+1):
    r = i - j
    dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + a * (p-j))
    dp[i+1][j]  = max(dp[i+1][j], dp[i][j] + a * (N-r-p-1))

ans = 0
for i in range(N):
  ans = max(ans, dp[N][i])

print(ans)
#for a in dp:
#  print(a)

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


Question:
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0

for i in range(N):
  A = list(map(int, input().split()))
  work = C
  for j in range(M):
    work += A[j] * B[j]
  if work > 0:
    ans += 1

print(ans)

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


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

if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")

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


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

cnt = 0
for x in A:
  if x%2 == 1:
    cnt += 1

if cnt % 2 == 0:
  print("YES")
else:
  print("NO")

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


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

G = [[] for _ in range(N)]
INF = 10**9
D = [[ INF for _ in range(N)] for _ in range(N)]
for i in range(N):
  D[i][i] = 0

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

for k in range(N):
  for i in range(N):
    for j in range(N):
      if D[i][k] + D[k][j] < D[i][j]:
        D[i][j] = D[i][k] + D[k][j]
        D[j][i] = D[i][k] + D[k][j]

ans = 0
for a,b,c in E:
  flg = False
  for i in range(N):
    if D[i][a] + c == D[i][b]:
      flg = True
      break

  if not flg:
    ans += 1

print(ans)

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


Question:
import numpy as np

k, q = map(int, input().split())
d = np.array(list(map(int, input().split())), dtype=np.int64)
queries = [tuple(map(int, input().split())) for _ in range(q)]

for n, x, m in queries:
    d_mod = d % m
    rem_d_mod = d_mod[: (n - 1) % k]
    print(n - 1 - (x % m + ((n - 1) // k) * np.sum(d_mod) + np.sum(rem_d_mod)) // m
          - ((n - 1) // k) * np.count_nonzero(d_mod == 0) - np.count_nonzero(rem_d_mod == 0))

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


Question:
import sys
from operator import mul
from functools import reduce

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

MARCH = 'MARCH'
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = INT()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in MARCH]

A = [0]*5
for s in S:
	A[MARCH.index(s[0])] += 1

#print(A)

if sum(A) < 3:
	print(0)
	sys.exit()

ans = cmb(sum(A), 3)
#print(ans)

for a in A:
	if a<=1:continue
	if a>=3:
		ans -= cmb(a, 3)
	ans -= cmb(a, 2) * (sum(A)-a)

print(ans)

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


Question:
import sys
from operator import mul
from functools import reduce

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

MARCH = 'MARCH'
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = INT()
S = [input().rstrip() for _ in range(N)]

S = [s for s in S if s[0] in MARCH]

A = [0]*5
for s in S:
	A[MARCH.index(s[0])] += 1

#print(A)

if sum(A) < 3:
	print(0)
	sys.exit()

ans = cmb(sum(A), 3)
#print(ans)

for a in A:
	if a<=1:continue
	if a>=3:
		ans -= cmb(a, 3)
	ans -= cmb(a, 2) * (sum(A)-a)

print(ans)

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


Question:
n = int(input())
a = [int(x) for x in input().split()]

odd_list = [i for i in a if i%2]
odd_count = len(odd_list)

if (odd_count == 0 or odd_count %2 == 0):
    print("YES")
else:
    print("NO")

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