Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = input()
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if k%2 ==0:
            if q[1]=='1':
                N = q[2] + N
            else:
                N = N + q[2]
        else:
            if q[1]=='2':
                N = q[2] + N
            else:
                N = N + q[2]

if k%2==1:
    ans = ''.join(list(reversed(N)))
    print(ans)
else:
    print(N)


### FIXED CODE ###

from collections import deque

N = deque(input())
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if k%2 ==0:
            if q[1]=='1':
                N.appendleft(q[2])
            else:
                N.append(q[2])
        else:
            if q[1]=='2':
                N.appendleft(q[2])
            else:
                N.append(q[2])
if k%2==1:
    ans=''
    for x in reversed(N):
        ans += x
else:
    ans=''
    for x in N:
        ans += x

print(ans)
### BUGGY CODE ###

import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.single_target_shortest_path(g,target=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][1])

### FIXED CODE ###

import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])
### BUGGY CODE ###

inf = 2019
L, R = map(int, input().split())
ans = 2018

for i in range(L, R):
    for j in range(i + 1, R + 1):
        tmp = int((i%inf * j%inf) % inf)
        ans = min(ans, tmp)
    if ans == 0:
        break

print(ans)

### FIXED CODE ###

inf = 2019
L, R = map(int, input().split())
ans = 0
df = R - L
if df < 2019:
    L = L % inf
    R = L + df
    ans = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            tmp = int((i * j) % inf)
            ans = min(ans, tmp)

print(ans)
### BUGGY CODE ###

import numpy as np
n,x,y = map(int, input().split())
s = np.zeros((n,n))
t = np.zeros(n)
for i in range(0,n):
  for j in range(i,n):
    s[i][j] = abs(i-j)
x = x-1
y = y-1
s[x][y] = 1
for i in range(0,n):
  for j in range(i,n):
    a = abs(i-x)+abs(j-y)+1
    if a < s[i][j]:
      s[i][j] = a

for i in range(0,n):
  for j in range(i,n):
    for k in range(0,n):
      if k+1 == s[i][j]:
        t[k+1] += 1

for k in range(1,n):
  print(int(t[k]))

### FIXED CODE ###

n,x,y = map(int, input().split())
t = [0 for i in range(n)]
x = x-1
y = y-1
for i in range(0,n):
  for j in range(i,n):
    a = abs(i-x)+abs(j-y)+1
    b = abs(i-j)
    if a < b:
      t[a-1] += 1
    else:
      t[b-1] += 1

for k in range(0,n-1):
  print(int(t[k]))
### BUGGY CODE ###

H, W, M = map(int, input().split())
targets = [list(map(int, input().split())) for _ in range(M)]
x_counter = [0 for _ in range(W + 1)]
y_counter = [0 for _ in range(H + 1)]
y_index = []
x_index = []
check = 0

for i in range(M):
    x, y = targets[i]
    y_counter[x] += 1
    x_counter[y] += 1

y_max, x_max = max(y_counter), max(x_counter)

for i in range(H + 1):
    if y_counter[i] == y_max:
        y_index.append(i)

for j in range(W + 1):
    if x_counter[j] == x_max:
        x_index.append(j)
check = len(y_index) * len(x_index)
for k in range(M):
    r, c = targets[k]
    if r in y_index and c in x_index:
        check -= 1

print(y_max + x_max if check > 0 else y_max + x_max -1)


### FIXED CODE ###

h,w,m=map(int,input().split())
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
    x,y=item[i]
    row[x-1]+=1
    col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
    r,c=item[i]
    if r-1 in xr and c-1 in xc:
        check-=1
print(mr+mc if check>0 else mr+mc-1)
### BUGGY CODE ###

N , A , B = map(int, input().split())
monsters = []
cnt = 0

for i in range(N):
    monsters.append(int(input()))

while True:
    monsters.sort(reverse=True)
    if monsters[0] <= 0:
        print(cnt)
        break
    
    monsters[0] -= A
    cnt += 1
    
    for j in range(1,N):
        monsters[j] -= B

### FIXED CODE ###

import math

N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]

add_damage = A-B
left = 1
right = 10**9
ans = float('inf')

for i in range(int(math.log(10**9, 2)+1)):
    T = (left+right) // 2
    h = H.copy()
    h = list(map(lambda x: max(0, x-T*B), h))
    h = list(map(lambda x: math.ceil(x / add_damage), h))
    need = sum(h)
    
    if need <= T:
        right = T
        ans = min(ans, T)
    else:
        left = T

print(int(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

class UnionFind:

    def __init__(self, n):
        self.parents = [i for i in range(n)]

    def merge(self, i, j):
        rooti = self.findroot(i)
        rootj = self.findroot(j)
        self.parents[rooti] = rootj

    def issame(self, i, j):
        rooti = self.findroot(i)
        rootj = self.findroot(j)
        return rooti == rootj

    def findroot(self, i, followed_indices=None):

        if i == self.parents[i]:
            return i
        else:
            root = self.findroot(self.parents[i])
            self.parents[i] = root # 経路圧縮
            return root
          
n, m = LI()
edge_list = []
for i in range(m):
  a, b = LI()
  edge_list.append((a-1, b-1))
  
ans = []

uf = UnionFind(n)
import collections

for e in edge_list[::-1]:
  p = [uf.findroot(i) for i in range(n)]
  c = collections.Counter(p)
  fuben = 0
  for k in c.keys():
    fuben += c[k] * (n-c[k])
  ans.append(fuben//2)
  uf.merge(e[0], e[1])

for a in ans[::-1]:
  print(a)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

class UnionFind:

    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.size_dict = {i:1 for i in range(n)}
        self.fuben = n * (n-1) / 2

    def merge(self, i, j):
        rooti = self.findroot(i)
        rootj = self.findroot(j)
        if rooti == rootj:
          return
        self.parents[rooti] = rootj
        sj = self.size_dict[rootj]
        si = self.size_dict[rooti]
        self.fuben -= sj*(n-sj)/2
        self.fuben -= si*(n-si)/2
        self.fuben += (sj+si)*(n-(sj+si))/2
        self.size_dict[rootj] += self.size_dict[rooti]
        self.size_dict[rooti] = 0

    def issame(self, i, j):
        rooti = self.findroot(i)
        rootj = self.findroot(j)
        return rooti == rootj

    def findroot(self, i, followed_indices=None):

        if i == self.parents[i]:
            return i
        else:
            root = self.findroot(self.parents[i])
            self.parents[i] = root # 経路圧縮
            return root
          
n, m = LI()
edge_list = []
for i in range(m):
  a, b = LI()
  edge_list.append((a-1, b-1))
  
ans = []

uf = UnionFind(n)
import collections

for e in edge_list[::-1]:
  ans.append(int(uf.fuben))
  uf.merge(e[0], e[1])

for a in ans[::-1]:
  print(a)
### BUGGY CODE ###

import math
N, M = map(int, input().split())

if int(math.sqrt(M)) > N:
    for i in range(M//N,0,-1):
        if M%i == 0:
            ans = i
            break
        else:
            continue
else:
    for i in range(M//N,0,-1):
        if M%i == 0:
            ans = i
            break
        else:
            continue

print(ans)

### FIXED CODE ###

import math
N, M = map(int, input().split())

if int(math.sqrt(M)) > N:
    divlist = []
    for i in range (N, int(math.sqrt(M))):
        if M%i == 0:
            divlist.append(i)
    
    if divlist != []:
        for i in range(N, int(math.sqrt(M))):
            if M%i == 0:
                ans = M//i
                break
    else:
        for i in range(N,0,-1):
            if M%i == 0:
                ans = i
                break
else:
    for i in range(M//N,0,-1):
        if M%i == 0:
            ans = i
            break
            
print(ans)
### BUGGY CODE ###

N = int(input())
A = (list(map(int, input().split(' '))))
D = {}
ans = 0
for i in A:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
for i in A:
    flg = True
    if D[i] > 1:
        continue
    for j in range(1,int(pow(i,0.5))+2):
        if not i%j:
            if j in D and i != j:
                flg = False
                break
            if j != i//j and i//j in D and i//j != i:
                    flg = False
                    break
    if flg:
        ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split(' '))))
ans = 0
m = max(A.keys())
L = [1]*(10**6+1)
for i in sorted(A.keys()):
    if not L[i]:
        continue
    if A[i] == 1:
        ans += 1
    for j in range(i,m+1,i):
        L[j] = 0
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
S = input()[:-1]


def solve():
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i, c in enumerate(S, 1):
        for j, k in enumerate(S, 1):
            if c == k:
                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1 if i +
                               dp[i-1][j-1] < j else 0)
    print(max([max(v) for v in dp]))


solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
S = input()[:-1]


def solve():
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i, c in enumerate(S, 1):
        for j, k in enumerate(S, 1):
            if c == k:
                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1 if i +
                               dp[i-1][j-1] < j else 0)
    print(max([max(v) for v in dp]))


solve()
### BUGGY CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    cum_A = [0]*(N+1)
    for i in range(N):
        cum_A[i+1] = cum_A[i] + A[i]

    dp = [[1<<60]*(N+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][i] = 0

    for l in range(2, N+1):
        # right = left + len - 1でrightが[0, N - 1]のように
        for left in range(N-l+1):
            right = left + l-1
            #if right>= N: continue
            cost = cum_A[right+1] - cum_A[left]
            for k in range(left, right):
                tmp = dp[left][k] + dp[k+1][right] + cost
                dp[left][right] = min(dp[left][right], tmp)

    return print(dp[0][N-1])


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    cum_A = [0]*(N+1)
    for i in range(N):
        cum_A[i+1] = cum_A[i] + A[i]

    dp = [[1<<60]*(N+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][i] = 0

    for l in range(2, N+1):
        # right = left + len - 1でrightが[0, N - 1]のように
        for left in range(N-l+1):
            right = left + l-1
            #if right>= N: continue
            cost = cum_A[right+1] - cum_A[left]
            for k in range(left, right):
                tmp = dp[left][k] + dp[k+1][right] + cost
                dp[left][right] = min(dp[left][right], tmp)

    return print(dp[0][N-1])

if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

import numpy as np


n, k = map(int, input().split())
h_arr = np.array(list(map(int, input().split())))
cost_arr = np.zeros(n)
for i in range(1, n):
    start = max(i-k, 0)
    cost_arr[i] = np.min(abs(h_arr[start:i] - h_arr[i]) + cost_arr[start:i])
print(int(cost_arr[-1]))


### FIXED CODE ###

import numpy as np

n, k = map(int, input().split())
h_arr = np.array(list(map(int, input().split())))
cost_arr = np.zeros(n, dtype=int)
for i in range(1, n):
    start = max(i-k, 0)
    cost_arr[i] = (abs(h_arr[start:i] - h_arr[i]) + cost_arr[start:i]).min()
print(int(cost_arr[-1]))
### BUGGY CODE ###

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

import math
K = min(K, 41)
for k in range(K):
  light = [0] * (N+1)
  for i in range(N):
    start = max(0,i-A[i])
    end = min(N-1, i+A[i])
    light[start] += 1
    light[end+1] -= 1
  for i in range(1,N):
    light[i] += light[i-1]
    
  A = light

light.pop()
print(" ".join(map(str,light)))


### FIXED CODE ###

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

import math
K = min(K, 43)
for k in range(K):
  light = [0] * (N+1)
  for i in range(N):
    start = max(0,i-A[i])
    end = min(N-1, i+A[i])
    light[start] += 1
    light[end+1] -= 1
  for i in range(1,N):
    light[i] += light[i-1]
    
  A = light

light.pop()
print(" ".join(map(str,light)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N, M, P = map(int, input().split())
    abc = [list(map(int, input().split())) for i in range(M)]
    INF = int(1e10)
    cost = [INF] * (N + 1)

    cost[1] = 0
    count = 0
    fin = False
    while True:
        no_change = True
        for i in range(M):
            a, b, c = abc[i]
            tmp = cost[a] - (c - P)
            if cost[b] > tmp:
                cost[b] = tmp
                no_change = False
        count += 1
        if no_change:
            fin = True
            break
        if count > 2 * N:
            break
        elif count > N:
            pre = cost[N]
    
    if fin:
        print(max(0, -cost[N]))
    else:
        if pre != cost[N]:
            print(-1)
        else:
            print(max(0, -cost[N]))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline

def belman(egdes, N, start, end):
    INF = int(1e10)
    cost = [INF] * N
    cost[start] = 0
    fin = False
    count = 0
    while True:
        no_change = True
        for edge in egdes:
            from_, to_, d = edge
            tmp = cost[from_] + d
            if cost[to_] > tmp:
                no_change = False
                cost[to_] = tmp
        count += 1
        if no_change:
            fin = True
            break
        elif count > N+1:
            break
    
    if fin:
        return max(0, -cost[end])
    else:
        return -1

def bfs(link, N, start):
    q = deque()
    check = [False] * N
    q.append(start)
    check[start] = True
    used = {start}
    while len(q) > 0:
        node = q.popleft()
        for next_ in link[node]:
            if not check[next_]:
                check[next_] = True
                q.append(next_)
                used.add(next_)
    return used
        

def main():
    N, M, P = map(int, input().split())

    link = [[] for i in range(N)]
    rlink = [[] for i in range(N)]
    edges = []

    for i in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        link[a].append(b)
        rlink[b].append(a)
        edges.append((a, b, -(c-P)))
    
    use_nodes = bfs(link, N, 0) & bfs(rlink, N, N-1)
    use_edges = [(a, b, c) for a, b, c in edges if a in use_nodes and b in use_nodes]
    print(belman(use_edges, N, 0, N-1))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import itertools
import numpy as np
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

N = int(input())
S = list(input())  # len:N

S = sorted(S)  #  アルファベット順に並べ替え
U = [0] * 26  #  ユニーク数数え上げ
tmp = "0"
count = 0
u_count = 0
for i in range(N):
    if i > 0:
        if tmp == S[i]:
            U[count] += 1
        else:
            tmp = S[i]
            count += 1
            U[count] += 1
    else:
        tmp = S[i]
        U[count] += 1


for u in range(26):
    if U[u] != 0:
        u_count += 1

U = sorted(U)

for i in range(len(U)):
    if U[0] == 0:
        U.pop(0)

count = 0

for i in range(1, u_count+1):
    count += np.sum(np.array(list(map(prod, list(itertools.combinations(U, i))))))

a = 10 ** 9 + 7
print(count % a)


### FIXED CODE ###

from collections import Counter
N = int(input())
S = input()
answer = 1
counter = Counter(S).most_common()

for i in range(len(counter)):
    answer = answer * (counter[i][1] + 1) % (10**9 + 7)

print(answer-1)
### BUGGY CODE ###

n,W=map(int,input().split())
MAX_V=10**5

weight=[]
value=[]

for i in range(n):
    w,v=map(int,input().split())
    weight.append(w)
    value.append(v)

dp=[[float('inf') for i in range(MAX_V)] for j in range(n+1)]
dp[0][0]=0
for i in range(n):
    sum_v=0
    while sum_v<MAX_V:
        if sum_v-value[i]>=0:
            dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i])
        dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v])
        sum_v+=1
sum_v=0
while sum_v<MAX_V:
    if dp[n][sum_v]<=W:res=sum_v
    sum_v+=1

print(res)

# copy

### FIXED CODE ###

N,W=map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
dp=[[float('inf') for i in range(V+1)] for j in range(N+1)]

dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=dp[i][j-v[i]]+w[i]
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])

for j in range(V+1):
    if dp[N][j]<=W:
        res=j
print(res)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
l=[]
r=[]
for i in range(q):
  li,ri=map(int,input().split())
  l.append(li)
  r.append(ri)
ans=[]
for i in range(q):
  cnt=0
  for j in range(l[i]-1,r[i]-1):
    if s[j]=='A' and s[j+1]=='C':
      cnt+=1
  ans.append(cnt)
for i in range(q):
  print(ans[i])

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]*(n)
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    a[i+1]=a[i]+1
  else:
    a[i+1]=a[i]
for i in range(q):
  l,r=map(int,input().split())
  ans=a[r-1]-a[l-1]
  print(ans)
### BUGGY CODE ###

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

L=[0]*M
R=[0]*M

for i in range(M):
  L[i],R[i]=map(int,input().split())

def prison(N,M,L,R):
  num=list(range(L[0],(R[0]+1)))
  for l,r in zip(L[1:],R[1:]):
    num=[i for i in num if l<=i<=r]
  return len(num)
print(prison(N,M,L,R))

### FIXED CODE ###

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

L=[0]*M
R=[0]*M

for i in range(M):
  L[i],R[i]=map(int,input().split())

def prison(N,M,L,R):
  max_val=min(R)
  min_val=max(L)
  num=max_val-min_val+1
  if num<=0:
    num=0
  return(num)

print(prison(N,M,L,R))
### BUGGY CODE ###

s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
for i in range(q):
    if a[i]=="1":
        if b==0:
            b=1
        else:
            b=0
    else:
        if b==0:
            if a[i][2]=="1":
                s=a[i][4]+s
            else:
                s=s+a[i][4]
        else:
            if a[i][2]=="1":
                s=s+a[i][4]
            else:
                s=a[i][4]+s
if b==0:
    print(s)
    exit()
s= ''.join(list(reversed(s)))
print(s)


### FIXED CODE ###

s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
c=""
d=""
if q<=10**5:
    for i in range(q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    if b==0:
        print(s)
    else:
        s= ''.join(list(reversed(s)))
        print(s)

else:
    for i in range(10**5):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    for i in range(10**5,q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    c=a[i][4]+c
                else:
                    d=d+a[i][4]
            else:
                if a[i][2]=="1":
                    d=d+a[i][4]
                else:
                    c=a[i][4]+c
    if b==0:
        print(c+s+d)
    else:
        c=''.join(list(reversed(c)))
        d=''.join(list(reversed(d)))
        s= ''.join(list(reversed(s)))
        print(d+s+c)
### BUGGY CODE ###

import numpy as np
import fractions
import sys
input = sys.stdin.readline


def f(x):
    res = 0
    while x % 2 == 0:
        x /= 2
        res += 1
    return res


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


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

    A = np.array(A) // 2

    t = f(A[0])
    for i in range(len(A)):
        if f(A[i]) != t:
            print(0)
            return 0
        A[i] >>= t
    M >>= t

    l = 1
    for i in range(N):
        l = lcm(l, A[i])
        if l > M:
            print(0)
            return 0

    M /= l
    ans = (M + 1) // 2
    print(int(ans))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import fractions
import sys
input = sys.stdin.readline


def f(x):
    res = 0
    while x % 2 == 0:
        x /= 2
        res += 1
    return res


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


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

    A = list(map(lambda x: x // 2, A))

    t = f(A[0])
    for i in range(len(A)):
        if f(A[i]) != t:
            print(0)
            return 0
        A[i] >>= t
    M >>= t

    l = 1
    for i in range(N):
        l = lcm(l, A[i])
        if l > M:
            print(0)
            return 0

    M /= l
    ans = (M + 1) // 2
    print(int(ans))


if __name__ == "__main__":
    main()