Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())

W = set()
for a in range(0, F+1, 100 * A):
    for b in range(0, F - a+1, 100 * B):
        W.add(a + b)

S = set()
for c in range(0, F+1, C):
    for d in range(0, F - c+1, D):
        S.add(c + d)

ans = None
mx = 0
for w in W:
    for s in S:
        if 0 < w + s <= F and s <= w * E // 100:
            if mx < s/(w+s):
                ans = w+s, s
                mx = s/(w+s)
print(ans[0], ans[1])


Fixed submission:
A, B, C, D, E, F = map(int, input().split())

W = set()
for a in range(0, F+1, 100 * A):
    for b in range(0, F - a+1, 100 * B):
        W.add(a + b)

S = set()
for c in range(0, F+1, C):
    for d in range(0, F - c+1, D):
        S.add(c + d)

mx = -1
for w in W:
    for s in S:
        if 0 < w + s <= F and s <= w * E // 100:
            if mx < s/(w+s):
                ans = w+s, s
                mx = s/(w+s)
print(ans[0], ans[1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

counter = Counter()
for a in A:
    counter += Counter([a-1, a, a+1])
print(counter.most_common()[0][1])


Fixed submission:
N = int(input())
A = map(int, input().split())

C = [0 for _ in range(100000+2)]
for a in A:
    C[a] += 1
    C[a+1] += 1
    C[a+2] += 1
C.sort()
print(C[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = [int(raw_input()) - 1 for _ in range(N)]

ans = 0
i = 0
used = set([0, 1])
while True:
    if ans != 0 and i in used:
        break
    i = A[i]
    ans += 1
if i != 1:
    ans = -1
print ans


Fixed submission:
N = int(raw_input())
A = [int(raw_input()) - 1 for _ in range(N)]

ans = 0
i = 0
used = set([0, 1])
while True:
    if ans != 0 and i in used:
        break
    used.add(i)
    i = A[i]
    ans += 1
if i != 1:
    ans = -1
print ans

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = [int(raw_input()) - 1 for _ in range(N)]

ans = 0
i = 0
while True:
    if ans != 0 and i in [0, 1]:
        break
    i = A[i]
    ans += 1
if i == 0:
    ans = -1
print ans


Fixed submission:
N = int(raw_input())
A = [int(raw_input()) - 1 for _ in range(N)]

ans = 0
i = 0
used = set([0, 1])
while True:
    if ans != 0 and i in used:
        break
    used.add(i)
    i = A[i]
    ans += 1
if i != 1:
    ans = -1
print ans
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M = map(int, raw_input().split())
Q = [map(int, raw_input().split()) for _ in range(M)]

cnt = Counter()
for q in Q:
    cnt += Counter(q)

for k in cnt:
    if cnt[k] % 2 != 0:
        print "NO"
        exit()
print "YES"


Fixed submission:
N, M = map(int, raw_input().split())
Q = [map(int, raw_input().split()) for _ in range(M)]

cnt = [0 for _ in range(N)]
for a, b in Q:
    cnt[a-1] += 1
    cnt[b-1] += 1

for k in range(N):
    if cnt[k] % 2 != 0:
        print "NO"
        exit()
print "YES"
Buggy python submission (verdict: Runtime Error):
H, W, K = map(int, raw_input().split())

MAP = [raw_input() for _ in xrange(H)]
dist = [[10000 for _ in range(W)] for _ in xrange(H)]

for i in range(H):
    x = MAP[i].find('S')
    if x != -1:
        sy = i
        sx = MAP[i].find('S')

Q = []
q(sx, sy)]
visited[sy][sx] = 0
while len(Q) > 0:
    x, y = Q.pop()
    d = visited[y][x]
    for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
        px, py = x+dx, y+dy
        if px < 0 or px >= W:
            continue
        if py < 0 or py >= H:
            continue
        if abs(px - sx) + abs(py - sy) > K:
            continue
        if visited[py][px]:
            continue
        if MAP[py][px] == "#":
            continue
        Q.append((px, py))

d = 10000
for x in xrange(W):
    for y in xrange(H):
        if visited[y][x]:
            d = min(d, x, W-1-x)
            d = min(d, y, H-1-y)

if d == 0:
    print 1
elif d < K:
    print 2
else:
    print 1 + d/K


Fixed submission:
from collections import deque

H, W, K = map(int, raw_input().split())

MAP = [raw_input() for _ in xrange(H)]
visited = [[False for _ in xrange(W)] for _ in xrange(H)]

for y in range(H):
    x = MAP[y].find('S')
    if x != -1:
        sx = x
        sy = y

Q = deque()
Q.append((0, (sx, sy)))
visited[sy][sx] = True
while len(Q) > 0:
    cost, [x, y] = Q.popleft()
    for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
        px, py = x+dx, y+dy
        if 0 <= px < W and 0 <= py < H:
            if not visited[py][px] and MAP[py][px] != "#":
                visited[py][px] = True
                if cost + 1 < K:
                    Q.append((cost + 1, (px, py)))

d = 10000
for x in xrange(W):
    for y in xrange(H):
        if visited[y][x]:
            d = min(d, x, W-1-x)
            d = min(d, y, H-1-y)

print (d + K - 1) / K + 1
Buggy python submission (verdict: Runtime Error):
from copy import deepcopy

N, MA, MB = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]

DP = [[100000 for _ in range(401)] for _ in range(401)]
DP[0][0] = 0

S = {(0, 0)}
for a, b, c in X:
    DP2 = deepcopy(DP)
    for sa, sb in S:
        if DP[sa+a][sb+b] > DP2[sa][sb] + c:
            DP[sa+a][sb+b] = DP2[sa][sb] + c
    T = {(sa+a, sb+b) for sa, sb in S}
    S |= T

a, b = MA, MB
ans = 100000
while a <= 400 and b <= 400:
    ans = min(ans, DP[a][b])
    a += MA
    b += MB

if ans == 100000:
    print -1
else:
    print ans


Fixed submission:
A, B = map(int, raw_input().split())
card = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
if card.index(A) > card.index(B):
    print "Alice"
elif card.index(A) < card.index(B):
    print "Bob"
else:
    print "Draw"
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

N, MA, MB = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]

DP = [[100000 for _ in range(401)] for _ in range(401)]
DP[0][0] = 0

S = {(0, 0)}
for a, b, c in X:
    DP2 = deepcopy(DP)
    for sa, sb in S:
        if DP[sa+a][sb+b] > DP2[sa][sb] + c:
            DP[sa+a][sb+b] = DP2[sa][sb] + c
    T = {(sa+a, sb+b) for sa, sb in S}
    S |= T

a, b = MA, MB
ans = 100000
while a <= 400 and b <= 400:
    ans = min(ans, DP[a][b])
    a += MA
    b += MB

if ans == 100000:
    print -1
else:
    print ans


Fixed submission:
from collections import defaultdict

N, MA, MB = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]

dp = defaultdict()

dp[(0, 0)] = 0
for a, b, c in X:
    dp2 = defaultdict()
    for sa, sb in dp:
        if (sa+a, sb+b) not in dp:
            dp2[(sa+a, sb+b)] = dp[(sa, sb)] + c
        elif dp[(sa+a, sb+b)] > dp[(sa, sb)] + c:
            dp2[(sa+a, sb+b)] = dp[(sa, sb)] + c
    for (na, nb) in dp2:
        dp[(na, nb)] = dp2[(na, nb)]

a, b = MA, MB
ans = 100000
while a <= 400 and b <= 400:
    if (a, b) in dp:
        ans = min(ans, dp[(a, b)])
    a += MA
    b += MB

if ans == 100000:
    print -1
else:
    print ans
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    A_mod = [a % mod for a in A]
    ans = 0
    for i in range(N-1):
        sum_mod = sum(A_mod[i+1:]) % mod
        mul_mod = (A_mod[i] * sum_mod) % mod
        ans = (ans + mul_mod) % mod
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    A_cum_sum = [A[-1]]
    for a in A[::-1][1:]:
        A_cum_sum.append(a + A_cum_sum[-1])
    A_cum_sum = A_cum_sum[::-1]
    ans = 0
    for i in range(N-1):
        sum_mod = A_cum_sum[i+1] % mod
        mul_mod = (A[i] * sum_mod) % mod
        ans = (ans + mul_mod) % mod
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    reverse_flag = False
    for _ in range(Q):
        q = input().rstrip()
        if q == '1':
            reverse_flag = not reverse_flag
        else:
            _, F, C = q.split()
            if (F == '1' and reverse_flag is False) or (F == '2' and reverse_flag is True):
                S = C + S
            else:
                S = S + C
    if reverse_flag is True:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    reverse_flag = False
    head = ''
    tail = ''
    for _ in range(Q):
        q = input().rstrip()
        if q == '1':
            reverse_flag = not reverse_flag
        else:
            _, F, C = q.split()
            if (F == '1' and reverse_flag is False) or (F == '2' and reverse_flag is True):
                head += C
            else:
                tail += C
    if reverse_flag is True:
        print(tail[::-1] + S[::-1] + head)
    else:
        print(head[::-1] + S + tail)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    P = map(int, input().split())
    E = [(p+1)/2 for p in P]
    V = [sum(E[i:i+K]) for i in range(N-K+1)]
    print(max(V))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    P = map(int, input().split())
    E = [(p+1)/2 for p in P]
    sums = [sum(E[0:K])]
    for i in range(N-K):
        sums.append(sums[-1] - E[i] + E[i+K])
    print(max(sums))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_idx = []
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            ac_idx.append(i)
    for _ in range(Q):
        l, r = map(int, input().split())
        ans = 0
        for idx in ac_idx:
            if idx >= r-1:
                break
            elif idx >= l-1:
                ans += 1
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_freq = [0]
    for i in range(0, N-1):
        if S[i:i+2] == 'AC':
            ac_freq.append(ac_freq[-1] + 1)
        else:
            ac_freq.append(ac_freq[-1])
    ac_freq.append(ac_freq[-1])
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ac_freq[r-1] - ac_freq[l-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_flag = []
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            ac_flag.append(1)
        else:
            ac_flag.append(0)
    for _ in range(Q):
        l, r = map(int, input().split())
        print(sum(ac_flag[l-1:r-1]))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_freq = [0]
    for i in range(0, N-1):
        if S[i:i+2] == 'AC':
            ac_freq.append(ac_freq[-1] + 1)
        else:
            ac_freq.append(ac_freq[-1])
    ac_freq.append(ac_freq[-1])
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ac_freq[r-1] - ac_freq[l-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_flag = []
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            ac_flag.append(1)
        else:
            ac_flag.append(0)
    for _ in range(Q):
        l, r = map(int, input().split())
        print(sum(ac_flag[l-1:r-1]))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_freq = [0]
    for i in range(0, N-1):
        if S[i:i+2] == 'AC':
            ac_freq.append(ac_freq[-1] + 1)
        else:
            ac_freq.append(ac_freq[-1])
    ac_freq.append(ac_freq[-1])
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ac_freq[r-1] - ac_freq[l-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    PY = [tuple(map(int, input().split())) for _ in range(M)]
    result = [None for _ in range(M)]
    p_city = defaultdict(int)
    for py in sorted(PY, key = lambda x: x[1]):
        p_city[py[0]] += 1
        code = str(py[0]).zfill(6) + str(p_city[py[0]]).zfill(6)
        result[PY.index(py)] = code
    print("\n".join(result))


if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    PY = [tuple([i] + list(map(int, input().split()))) for i in range(M)]
    result = []
    p_city = defaultdict(int)
    for py in sorted(PY, key = lambda x: x[2]):
        p_city[py[1]] += 1
        code = str(py[1]).zfill(6) + str(p_city[py[1]]).zfill(6)
        result.append((py[0], code))
    print("\n".join([r[1] for r in sorted(result, key = lambda x: x[0])]))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc087/tasks/abc087_a
# 2020/07/04
def main():
    X, A, B = [int(input()) for _ in range(3)]
    remain = X - A
    print(remain % B)

if __name__ == '__main__':
    main()
def main():
    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        c, t = map(int, input().split())
        if t <= T:
            C.append(c)
    if len(C) == 0:
        print("TLE")
    else:
        print(min(C))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        c, t = map(int, input().split())
        if t <= T:
            C.append(c)
    if len(C) == 0:
        print("TLE")
    else:
        print(min(C))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    P = []
    M = []
    for x in X:
        if x < 0:
            M.append(-1 * x)
        else:
            P.append(x)
    M.reverse()

    if len(P) == 0:
        print(M[K - 1])
        exit()
    elif len(M) == 0:
        print(P[K - 1])
        exit()

    ans = 10 ** 10
    for i, m in enumerate(M, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = m
        else:
            p_idx = K - i - 1
            d = m * 2 + P[p_idx]
        if d < ans:
            ans = d

    for i, p in enumerate(P, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = p
        else:
            m_idx = K - i - 1
            d = p * 2 + M[m_idx]
        if d < ans:
            ans = d

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    P = []
    M = []
    for x in X:
        if x < 0:
            M.append(-1 * x)
        else:
            P.append(x)
    M.reverse()

    if len(P) == 0:
        print(M[K - 1])
        exit()
    elif len(M) == 0:
        print(P[K - 1])
        exit()

    ans = 10 ** 10
    for i, m in enumerate(M, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = m
        else:
            p_idx = K - i - 1
            if p_idx >= len(P):
                continue
            else:
                d = m * 2 + P[p_idx]
        if d < ans:
            ans = d

    for i, p in enumerate(P, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = p
        else:
            m_idx = K - i - 1
            if m_idx >= len(M):
                continue
            else:
                d = p * 2 + M[m_idx]
        if d < ans:
            ans = d

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = list(input())
    vals = set([])
    for i in range(N):
        vals.add(collections.Counter(S[0:i])["W"] + collections.Counter(S[i+1:])["E"])
    print(min(vals))

if __name__ == '__main__':
    main()

Fixed submission:
import collections
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = list(input())
    e_right = collections.Counter(S)["E"]
    w_left = 0
    vals = set([])
    for i in range(N):
        if S[i] == "E":
            e_right -= 1
        vals.add(w_left + e_right)
        if S[i] == "W":
            w_left += 1

    print(min(vals))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
t = sorted(input(), reverse=True)

ans = "Yes"
if s == t:
    ans = "No"
else:
    for i in range(len(s)):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            break
        else:
            ans = "No"
            break

print(ans)

Fixed submission:
s = sorted(input())
t = sorted(input(), reverse=True)

if s < t:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    n = input()
    n_sum = sum([int(c) for c in n])
    if n % n_sum == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    n_sum = sum([int(c) for c in str(n)])
    if n % n_sum == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    s = input()
    a_indexes = [i for i, c in enumerate(s) if c == "A"]
    z_indexes = [i for i, c in enumerate(s) if c == "Z"]
    max_length = 0
    for a_index in a_indexes:
        for z_index in z_indexes:
            if z_index - a_index > max_length:
                max_length = z_index - a_index
    print(max_length + 1)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    s = input()
    min_a_index = min([i for i, c in enumerate(s) if c == "A"])
    max_z_index = max([i for i, c in enumerate(s) if c == "Z"])
    print(max_z_index - min_a_index + 1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    s = input()
    a_indexes = [i for i, c in enumerate(s) if c == "A"]
    z_indexes = [i for i, c in enumerate(s) if c == "Z"]
    max_length = 0
    for a_index in a_indexes:
        for z_index in z_indexes:
            if z_index - a_index > max_length:
                max_length = z_index - a_index
    print(max_length + 1)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    s = input()
    min_a_index = min([i for i, c in enumerate(s) if c == "A"])
    max_z_index = max([i for i, c in enumerate(s) if c == "Z"])
    print(max_z_index - min_a_index + 1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    vals = [x + y + z for x in range(k+1) for y in range(k+1) for z in range(k+1)]
    print(len([v for v in vals if v == s]))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            if s - (x + y) <= k:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            for z in range(k+1):
                if x + y + z > s:
                    break
                if x + y + z == s:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            if s - (x + y) <= k:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            for z in range(k+1):
                if x + y + z > s:
                    break
                if x + y + z == s:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k+1):
        if x > s:
            break
        for y in range(k+1):
            if x + y > s:
                break
            if s - (x + y) <= k:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from math import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

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

l = lcm(ai) // 2
i = m // l
if i == 0:
    print(0)
    exit()
if i == 1:
    print(1)
    exit()
ans = int(bin(i)[:-1], 2) + 1

print(ans)


Fixed submission:
from fractions import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

def f(x):
    cnt = 0
    for c in reversed(bin(x)):
        if c == '0':
            cnt += 1
        else:
            return cnt
    return cnt

n, m = map(int, input().split())
ai = list(map(lambda x: x//2 , list(map(int, input().split()))))

t = f(ai[0])
for i, a in enumerate(ai):
    if f(a) != t:
        print('0')
        exit()
    ai[i] = a >> t

m = m >> t

l = lcm(ai)
i = m // l
ans = (i + 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

total = 0
for pat in combinations(range(n), 2):
    total += a[pat[0]] ^ a[pat[1]]
print(total % (10**9 + 7))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7

ans = 0
for i in range(61):
    zero = 0
    one = 0
    for ai in a:
        if ai>>i & 1:
            one += 1
        else:
            zero += 1
    ans += zero * one * 2**i
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int, input().split()))

ans = []
for i in range(1, n+1):
    ans.append(ai.index(i)+1)
ans = map(str, ans)
print(" ".join(ans))    


Fixed submission:
n = int(input())
ai = list(map(int, input().split()))

ans = [None]*n

for i in range(n):
    ans[ai[i]-1] = i+1

ans = map(str, ans)
print(" ".join(ans))