Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Fixed submission:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S)+1:
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))
Buggy python submission (verdict: Time Limit Exceeded):
def c_many_medians(N, X):
    x = [[0, 0] for _ in range(N)]
    for i, e in enumerate(X):
        x[i] = [i, e]
    x.sort(key=lambda k: k[1])
    mid = N // 2 - 1
    a, b = [0] * N, [0] * N
    for i, (k, v) in enumerate(x):
        p=x.index([k,v])
        a[k] = p
        b[i] = v
    ans = ['' for _ in range(N)]
    for i in a:
        if b[mid]>=b[a[i]]:
            ans[i]='{}'.format(b[mid+1])
        else:
            ans[i]='{}'.format(b[mid])
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Fixed submission:
def c_many_medians(N, X):
    # 解説どおり
    Y = sorted(X)
    ans = ['' for _ in range(N)]
    pos = N // 2
    for k, xi in enumerate(X):
        if xi < Y[pos]:
            ans[k] = str(Y[pos])
        else:
            ans[k] = str(Y[pos - 1])
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Buggy python submission (verdict: Time Limit Exceeded):
def c_many_medians(N, X):
    x = [[0, 0] for _ in range(N)]
    for i, e in enumerate(X):
        x[i] = [i, e]
    x.sort(key=lambda k: k[1])
    mid = N // 2 - 1
    a, b = [0] * N, [0] * N
    for i, (k, v) in enumerate(x):
        a[i] = k
        b[i] = v
    ans = ''
    for i in range(N):
        idx = a.index(i)
        value = b[idx]
        b.remove(value)
        ans += '{}\n'.format(b[mid])
        b.insert(idx, value)
    ans = ans[:-1]
    return ans

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Fixed submission:
def c_many_medians(N, X):
    # 解説どおり
    Y = sorted(X)
    ans = ['' for _ in range(N)]
    pos = N // 2
    for k, xi in enumerate(X):
        if xi < Y[pos]:
            ans[k] = str(Y[pos])
        else:
            ans[k] = str(Y[pos - 1])
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))
Buggy python submission (verdict: Time Limit Exceeded):
def d_two_sequences(N, A, B):
    from bisect import bisect_left, bisect_right
    ans = 0
    for k in range(28):
        T = 2**k
        b = sorted([i % (2 * T) for i in B])
        tmp = 0
        for a in [i % (2 * T) for i in A]:
            idx1 = bisect_left(b, T - a)
            idx2 = bisect_right(b, 2 * T - a - 1)
            idx3 = bisect_left(b, 3 * T - a)
            tmp += len(b[idx1:idx2]) + len(b[idx3:])
        if tmp & 1 == 1:
            ans += T
    return ans

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
print(d_two_sequences(N, A, B))

Fixed submission:
def d_two_sequences():
    # 参考: https://atcoder.jp/contests/abc091/submissions/6048882
    import numpy as np
    N = int(input())
    A = np.array(input().split(), dtype=np.int32)
    B = np.array(input().split(), dtype=np.int32)

    bit = 1 << 28  # 入力は 28bit 未満の非負整数
    ans = 0
    while bit:
        # bit + 1 番目以上のビットは考慮する必要がないため、mask で除いてしまう
        mask = 2 * bit - 1
        A &= mask
        B &= mask
        A.sort()
        B.sort()

        # numpy.searchsorted() は bisect.bisect_left() と同等
        x1, x2, x3 = (np.searchsorted(B, v - A).sum() for v in [bit, 2 * bit, 3 * bit])
        # [0, x1 - 1], [x2, x3 - 1] 番目の要素は、bit 番目のビットが 0 である
        # [x1, x2 - 1], [x3, N - 1] 番目の要素は、bit 番目のビットが 1 である
        zero_cnt = x1 + (x3 - x2)
        if (N - zero_cnt) % 2:
            ans += bit  # 解の bit 番目のビットは 1 である
        bit >>= 1  # 下位ビットへ
    return ans

print(d_two_sequences())
Buggy python submission (verdict: Runtime Error):
c = [[i for i in input().strip().split()] for j in range(3)]
print(c[0][0] + c[1][1] + c[2][2])

Fixed submission:
c = [input().strip() for j in range(3)]
print(c[0][0] + c[1][1] + c[2][2])
Buggy python submission (verdict: Time Limit Exceeded):
def d_checker(N, K, Q):
    import itertools
    # マス(x,y)が白⇔マス(x,y+K)が黒なので、希望の色がすべて黒になるようにする
    # 市松模様の周期は2Kなので、x,y座標をそれぞれ2Kで剰余を取った座標と同一視できる
    mat = [[0]*(4*K+1) for _ in range(4*K+1)]
    total = [[0]*(4*K+1) for _ in range(4*K+1)]
    for x, y, c in Q:
        if c == 'W':
            y += K
        mat[x % (2*K)][y % (2*K)] += 1

    for x in range(4*K+1):
        for y in range(4*K+1):
            mat[x][y] = mat[x % (2*K)][y % (2*K)]

    for i in range(4*K+1):
        for j in range(4*K+1):
            total[i][j] = mat[i][j]
            if j-1 >= 0:
                total[i][j] += total[i][j-1]
            if i-1 >= 0:
                total[i][j] += total[i-1][j]
            if i-1 >= 0 and j-1 >= 0:
                total[i][j] -= total[i-1][j-1]

    def get(x1, y1, x2, y2, total):
        ret = total[x2][y2]
        if x1 > 0:
            ret -= total[x1-1][y2]
        if y1 > 0:
            ret -= total[x2][y1-1]
        if x1 > 0 and y1 > 0:
            ret += total[x1-1][y1-1]
        return ret

    ans = 0
    for x in range(2*K+1):
        for y in range(2*K+1):
            tmp = 0
            tmp += get(x, y, x+K-1, y+K-1, total)
            tmp += get(x+K, y+K, x+2*K-1, y+2*K-1, total)
            ans = max(ans, tmp)

    return ans

N, K = [int(i) for i in input().split()]
Q = [(int(x), int(y), c)
    for x, y, c in [input().split() for i in range(N)]]
print(d_checker(N, K, Q))

Fixed submission:
def d_checker(N, K, Q):
    # マス(x,y)が白⇔マス(x,y+K)が黒なので、希望の色がすべて黒になるようにする
    # 市松模様の周期は2Kなので、x,y座標をそれぞれ2Kで剰余を取った座標と同一視できる
    mat = [[0]*(2*K+2) for _ in range(2*K+2)]
    total = [[0]*(4*K+2) for _ in range(4*K+2)]
    for x, y, c in Q:
        if c == 'W':
            y += K
        mat[(x % (2*K)) + 1][(y % (2*K)) + 1] += 1

    # 事前に累積和を取る
    for x in range(1, 4*K+1):
        for y in range(1, 4*K+1):
            total[x][y] = total[x][y-1] + \
                mat[((x-1) % (2*K)) + 1][((y-1) % (2*K)) + 1]
    for y in range(1, 4*K+1):
        for x in range(1, 4*K+1):
            total[x][y] += total[x-1][y]

    def get(x, y):
        # 市松模様の橋の黒の座標を決めたときに実現できる希望の数
        return total[x+K-1][y+K-1] + total[x-1][y-1] - total[x-1][y+K-1] - total[x+K-1][y-1]

    ans = 0
    for x in range(1, 2*K+1):
        for y in range(1, 2*K+1):
            ans = max(ans, get(x, y)+get(x+K, y+K))
    return ans

N, K = [int(i) for i in input().split()]
Q = [(int(x), int(y), c)
    for x, y, c in [input().split() for i in range(N)]]
print(d_checker(N, K, Q))
Buggy python submission (verdict: Runtime Error):
def c_Otoshidama_N(N, Y):
    yen = Y // 1000
    # yukichi,higuchi,noguchiはそれぞれ、1万円札、5千円札、千円札の枚数(モデルの名字)
    for yukichi in range(0, 2001):
        # 10*yukichi + 5*higuchi + noguchi = yen と
        # yukichi + higuchi + noguchi = N について、yukichiを決めたときの連立方程式の解
        tmp1 = (yen - N - 9 * yukichi)
        tmp2 = (5 * N - yen + 5 * yukichi)
        if tmp1 % 4 == 0 and tmp2 % 4 == 0:
            higuchi = tmp1 // 4
            noguchi = tmp2 // 4
            if higuchi >= 0 and noguchi >= 0:
                return '{} {} {}'.format(yukichi, higuchi, noguchi)
    # どの組み合わせでも条件を満たさなかった
    return '-1 -1 -1'
  
N,Y=[int(i) for i in input().split()]
print(c_Otoshidama(N, Y))


Fixed submission:
def c_Otoshidama(N, Y):
    ans = ''

    for yukichi in range(0, 2001):
        for higuchi in range(0, 2001):
            noguchi = N - yukichi - higuchi
            if noguchi >= 0:
                if Y == yukichi * 10000 + higuchi * 5000 + noguchi * 1000:
                    return '{} {} {}'.format(yukichi, higuchi, noguchi)
    return '-1 -1 -1'
  
N,Y=[int(i) for i in input().split()]
print(c_Otoshidama(N, Y))
Buggy python submission (verdict: Time Limit Exceeded):
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N - 1):
        time = 0
        c, s, f = STATION[i]
        time += s + c  # 最初の駅では、開通後時間sに発車し、c秒かけて次の駅へ行く
        for j in range(i + 1, N - 1):
            c_next, s_next, f_next = STATION[j]
            while time > s_next:
                s_next += f_next  # s_next-timeが、その駅で待機しなければならない時間
            time += s_next - time + c_next  # c_next秒かけて次の駅へ行く
        ans.append(time)
    ans.append(0)  # N番目の駅からN番目の駅に行く時間は0とする
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Fixed submission:
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))
Buggy python submission (verdict: Runtime Error):
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    T = min(T)
    return T

S = input()
print(d_WideFlip(S))

Fixed submission:
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    if len(T) > 0:
        return min(T)
    else:
        return n  # Sは0のみまたは1のみで構成されていた

S = input()
print(d_WideFlip(S))

Buggy python submission (verdict: Runtime Error):
def d_WideFlip(S):
    import re
    from collections import Counter

    d = Counter(S)
    zero = d['0']
    one_continue = re.findall(r'1+', S)
    one_continue = len(max(one_continue))
    return max(zero, one_continue)

S = input()
print(d_WideFlip(S))

Fixed submission:
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    if len(T) > 0:
        return min(T)
    else:
        return n  # Sは0のみまたは1のみで構成されていた

S = input()
print(d_WideFlip(S))
Buggy python submission (verdict: Runtime Error):
N = input()
if N[0]==N[1] and N[1]==N[2] and N[2]==N[3]:
  print('Yes')
elif N[1]==N[2] and N[2]==N[3] and N[3]==N[4]:
  print('Yes')
else:
  print('No')

Fixed submission:
def a_good_integer(N):
    if N[0] == N[1] and N[1] == N[2]:
        return('Yes')
    elif N[1] == N[2] and N[2] == N[3]:
        return('Yes')
    else:
        return('No')
      
N = input()
print(a_good_integer(N))
Buggy python submission (verdict: Runtime Error):
def d_abs(N, Z, W, A):
    # 山札の枚数が1枚なら、Xがそれを引いて終わる。山札が2枚以上なら、
    # Xは初手でN-1枚目かN枚目かのどちらかスコアが大きくなる方を取るのが最善。
    # そうしなかった場合、Xが最善手を取らなかったことになって前提に反するか、
    # Yが最善手を取ってスコアabs(A[N - 1] - A[N - 2])になるかのどちらかである
    ans = abs(A[0] - W) if N == 1 else max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))
    return ans

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Fixed submission:
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Buggy python submission (verdict: Runtime Error):
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(N)]
print(D_abs(N, Z, W, A))

Fixed submission:
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))
Buggy python submission (verdict: Time Limit Exceeded):
def C_SnukeFestival(N, A, B, C):
    a = sorted(A)
    b = sorted(B)
    c = sorted(C)

    l = N
    ans = 0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                if a[i] < b[j] and b[j] < c[k]:
                    ans += 1
    return ans

N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
print(C_SnukeFestival(N, A, B, C))
#間に合いそうもない

Fixed submission:
def C_SnukeFestival(N, A, B, C):
    a = sorted(A)
    b = sorted(B)
    c = sorted(C)

    import bisect
    ans = 0
    for j in range(N):
        # b[j]より小さなaの要素の個数
        i = bisect.bisect_left(a, b[j])
        # b[j]より大きなcの要素の個数
        k = N - bisect.bisect_right(c, b[j])
        ans += i * k
    return ans

N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
print(C_SnukeFestival(N, A, B, C))
Buggy python submission (verdict: Runtime Error):
def B_Addition_and_Multiplication(N, K):
  	if N==1:
      return 2
    multiply = 0  # 掛け算する回数
    add = 0  # 足し算する回数
    tmp = 1
    while tmp < K:
        tmp *= 2
        multiply += 1
    add = N - multiply

    ans = pow(2, multiply) + K * add
    return ans
  
N = int(input())
K = int(input())
print(B_Addition_and_Multiplication(N, K))

Fixed submission:
def B_Addition_and_Multiplication(N, K):
    if N==1:
        return 2
    multiply = 0  # 掛け算する回数
    add = 0  # 足し算する回数
    tmp = 1
    while tmp < K:
        tmp *= 2
        multiply += 1
    add = N - multiply

    ans = pow(2, multiply) + K * add
    return ans
  
N = int(input())
K = int(input())
print(B_Addition_and_Multiplication(N, K))
Buggy python submission (verdict: Time Limit Exceeded):
def D_Axis_Parallel_Rectangle(N, K, P):
    x = [0 for _ in range(N)]  # 点のx座標
    y = [0 for _ in range(N)]  # y座標
    x_array = [0 for _ in range(N)]
    y_array = [0 for _ in range(N)]
    for i in range(N):
        x[i] = P[i][0]
        y[i] = P[i][1]
        x_array[i] = x[i]
        y_array[i] = y[i]

    x_array = sorted(x_array)
    y_array = sorted(y_array)

    # すべての点を内部に含む、最大の面積を持つ矩形が初期値
    ans = (x_array[N - 1] - x_array[0]) * (y_array[N - 1] - y_array[0])

    # 全探索
    for xi in range(0, N, 1):
        for xj in range(xi + 1, N, 1):
            for yi in range(0, N, 1):
                for yj in range(yi + 1, N, 1):
                    num = 0
                    left = x_array[xi]
                    right = x_array[xj]
                    bottom = y_array[yi]
                    upper = y_array[yj]

                    for i in range(N):
                        if(left <= x[i] and x[i] <= right and bottom <= y[i] and y[i] <= upper):
                            num += 1
                    if num >= K:
                        ans = min(ans, (right - left) * (upper - bottom))
    return ans

N,K = [int(i) for i in input().split()]
P = [[int(i) for i in input().split()] for j in range(N)]
print(D_Axis_Parallel_Rectangle(N, K, P))

Fixed submission:
def D_Axis_Parallel_Rectangle(N, K, P):
    x = [0 for _ in range(N)]  # 点のx座標
    y = [0 for _ in range(N)]  # y座標
    x_array = [0 for _ in range(N)]
    y_array = [0 for _ in range(N)]
    for i in range(N):
        x[i] = P[i][0]
        y[i] = P[i][1]
        x_array[i] = x[i]
        y_array[i] = y[i]

    x_array = sorted(x_array)
    y_array = sorted(y_array)

    # すべての点を内部に含む、最大の面積を持つ矩形が初期値
    ans = (x_array[N - 1] - x_array[0]) * (y_array[N - 1] - y_array[0])

    # 全探索
    for xi in range(0, N, 1):
        for xj in range(xi + 1, N, 1):
            for yi in range(0, N, 1):
                for yj in range(yi + 1, N, 1):
                    num = 0
                    left = x_array[xi]
                    right = x_array[xj]
                    bottom = y_array[yi]
                    upper = y_array[yj]

                    for i in range(N):
                        if(left <= x[i] and x[i] <= right and bottom <= y[i] and y[i] <= upper):
                            num += 1
                    if num >= K:
                        ans = min(ans, (right - left) * (upper - bottom))
    return ans

N,K = [int(i) for i in input().split()]
P = [[int(i) for i in input().split()] for j in range(N)]
print(D_Axis_Parallel_Rectangle(N, K, P))
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if D[k] < v:
    ans = 'NO'
    break
print(ans)

Fixed submission:
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if count_D[k] < v:
    ans = 'NO'
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def c_4_over_n(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            # 条件式をwについて整理したときの分子と分母
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
            else:
                continue
            if 1 <= w <= 3500:
                ans = '{0} {1} {2}'.format(h, n, w)
                return ans
    return None

N = int(input())
print(c_4_over_n(N))

Fixed submission:
def c_4_over_n(N):
    for h in range(1, 3501):
        for n in range(1, h + 1):
            # 条件式をwについて整理したときの分子と分母
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            # このときwが正整数になる
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
                # 分母の値が小さなもの順に表示する(趣味)
                ans = '{0} {1} {2}'.format(*sorted([h, n, w]))
                return ans
    return None

N = int(input())
print(c_4_over_n(N))
Buggy python submission (verdict: Runtime Error):
def d_derangement(N, P):
    ans = 0
    is_target = True  # 要素番号iはチェックする必要があるか否か
    for i in range(N):
        if P[i] == i + 1 and is_target:
            # p_i=iならp_{i+1}とスワップすれば条件を満たす
            ans += 1
            is_target = False  # i+1番目はチェックする必要がない
        else:
            is_target = True
    return ans

N = int(input())
p = [int(i) for i in input().split()]
print(d_derangement(N, P))

Fixed submission:
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1: #p_i=iなら
            count += 1
            i += 2
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))

Buggy python submission (verdict: Runtime Error):
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1:
            if p[i + 1] == i + 2:
                count += 1
                i += 2
                continue
            else:
                count += 1
                i += 1
                continue
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))

Fixed submission:
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1: #p_i=iなら
            count += 1
            i += 2
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))
Buggy python submission (verdict: Runtime Error):
def c_multiple_clocks(N, T):
    from fractions import gcd
    from functools import reduce
    return reduce(lambda a, b: (a * b) // gcd(a, b), T)

N = int(input())
T = [int(input()) for _ in range(N)]
print(c_multiple_Clocks(N, T))

Fixed submission:
def Q3(x):
    def gcd(a, b):
        if b > a:
            a, b = b, a
        while b > 0:
            a, b = b, a % b
        return a

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

    N = x[0]
    lst = x[1:]
    if N == 1:
        return lst[0]
    else:
        l = lcm(lst[0], lst[1])
        for x in lst:
            l = lcm(l, x)
        return l

n = int(input())
t = [int(input()) for i in range(n)]
t.insert(0,n)
print(Q3(t))
Buggy python submission (verdict: Runtime Error):
string=input()
first=string[0]
last=string[len(string)-1]
mid=str(len(string[1:len(string-1)]))
print(first+mid+last)

Fixed submission:
string=input('')
first=string[0]
last=string[len(string)-1]
mid=str(len(string[1:len(string)-1]))
print(first+mid+last)
Buggy python submission (verdict: Runtime Error):
in=input("")
print("ABC{}".format(in))

Fixed submission:
x=input("")
print("ABC{}".format(x))

Buggy python submission (verdict: Runtime Error):
in=input()
print("ABC{}".format(in))

Fixed submission:
x=input("")
print("ABC{}".format(x))
Buggy python submission (verdict: Runtime Error):
x=input("")
k=0
while(pow(2,k)<=x):
  k+=1
print(k)

Fixed submission:
x=int(input(""))
k=0
while True:
  if pow(2,k)>x:
    break
  k+=1
print(pow(2,k-1))
Buggy python submission (verdict: Time Limit Exceeded):
def Q3(N, M, *arg):
    import numpy as np
    route = np.reshape(np.array(*arg), (M, 2))
    for x in route:
        if x[0] == 1:
            for y in route:
                if x[1] == y[0] and y[1] == N:
                    return 'POSSIBLE'
    return 'IMPOSSIBLE'

N, M = map(int, input().split())
l = [list(map(lambda x: int(x), input().split())) for i in range(M)]
l = [flatten for inner in l for flatten in inner]
print(Q3(N,M,l))

Fixed submission:
def Q3(N, M, *arg):
    import numpy as np
    route = np.reshape(np.array(*arg), (M, 2))
    string = 'IMPOSSIBLE'
    p = [False] * N
    q = [False] * N
    for x in route:
        if x[0] == 1:
            p[x[1]] = True
        elif x[1] == N:
            q[x[0]] = True
    for i in range(N):
        if p[i] and q[i]:
            string = 'POSSIBLE'
            break
    return string

N, M = map(int, input().split())
l = [list(map(lambda x: int(x), input().split())) for i in range(M)]
l = [flatten for inner in l for flatten in inner]
print(Q3(N,M,l))