Harryxun/stf_run huggingface dataset:
n, m, p = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
 
for i in range(m):
    lst[i][2] = - (lst[i][2] - p)

d = [10**100] * (n+1)
d[1] = 0
rep = 0
 
while True:
    update = False
    for edge in lst:
        a,b,c = edge
        if d[a] != 10**100 and d[b] > d[a]+ c:
            if rep >= n:
                d[b] = -10**100
            else:
                d[b] = d[a] + c
            update = True
    if not update:
        break
    rep += 1
    if loop:
        break
    if rep > 2*n:
        break


if d[n] <= - 10**100:
    print(-1)
elif -d[n] < 0:
    print(0)
else:
    print(-d[n])

### FIXED CODE ###

n, m, p = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
 
for i in range(m):
    lst[i][2] = - (lst[i][2] - p)

d = [10**100] * (n+1)
d[1] = 0
rep = 0
 
while True:
    update = False
    for edge in lst:
        a,b,c = edge
        if d[a] != 10**100 and d[b] > d[a]+ c:
            if rep >= n:
                d[b] = -10**100
            else:
                d[b] = d[a] + c
            update = True
    if not update:
        break
    rep += 1
    if rep > 2*n:
        break

if d[n] <= - 10**100:
    print(-1)
elif -d[n] < 0:
    print(0)
else:
    print(-d[n])
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
while b[j] > K - a[i]:
    j -= 1
    ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
def search_dist(g, dist, e):
    for b, c in g.get(e):
        if dist[b] < 10**15:
            continue
        dist[b] = dist[e] + c
        search_dist(g, dist, b)

def main():
    g = {}
    N = int(input())
    for _ in range(N-1):
        a, b, c = list(map(int, input().split(' ')))
        g[a] = g.get(a, []) + [(b, c)]
        g[b] = g.get(b, []) + [(a, c)]
    Q, K = list(map(int, input().split(' ')))
    dist = [10**15]*(N+1)
    dist[K] = 0
    search_dist(g, dist, K)
    for _ in range(Q):
        x, y = list(map(int, input().split(' ')))
        print(dist[x]+dist[y])

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(int(1e5+10))

def search_dist(g, dist, e):
    for b, c in g.get(e):
        if dist[b] is not None:
            continue
        dist[b] = dist[e] + c
        search_dist(g, dist, b)

def main():
    g = {}
    N = int(input())
    for i in range(N+1):
        g[i] = []
    for _ in range(N-1):
        a, b, c = list(map(int, input().split(' ')))
        g[a] += [(b, c)]
        g[b] += [(a, c)]
    Q, K = list(map(int, input().split(' ')))
    dist = [None]*(N+1)
    dist[K] = 0
    search_dist(g, dist, K)
    cood = []
    for _ in range(Q):
        cood.append(list(map(int, input().split(' '))))

    for x, y in cood:
        print(dist[x]+dist[y])

if __name__ == '__main__':
    main()
a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
ans = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
c = -1
while True:
    c += 1
#for i in range(d):
    print(c)
    #print(len(ans))
    s, aq, bq, cq = map(int, q.pop())
    if len(al) > aq+1:
        if [al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq] not in ans:
            q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq] not in ans:
            q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1] not in ans:
            q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    q = sorted(q)

    if len(ans) > d:
        ans = sorted(ans, reverse=True)
        if ans[d-1][0] > q[len(q)-1][0]:
            break

ans = sorted(ans, reverse=True)
for i in range(d):
    print(ans[i][0])


### FIXED CODE ###

a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
ans = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
#while True:
for i in range(d):
    s, aq, bq, cq = map(int, q.pop())
    if len(al) > aq+1:
        if [al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq] not in ans:
            q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq] not in ans:
            q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1] not in ans:
            q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    q = sorted(q)

    #if len(ans) > d:
    #   ans = sorted(ans, reverse=True)
    #    if ans[d][0] > q[len(q)-1][0]:
    #        break

ans = sorted(ans, reverse=True)
for i in range(d):
    print(ans[i][0])
class UnionFind:
    # この時点でそれぞれのノードは自分を親としている
    # 初期化時に問題が0の頂点を認めるかに注意すること
    def __init__(self, n):
        self.N = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    # xの根を返す関数
    def root(self, x):
        visited_nodes = []
        while True:
            p = self.parent[x]
            if p == x:
                # 縮約
                for node in visited_nodes:
                    self.parent[node] = x
                return x
            else:
                visited_nodes.append(x)
                x = p

    # 木の結合を行う。親の配下に入る
    def unite(self, x, y):
        if not self.root(x) == self.root(y):
            if self.rank[x] > self.rank[y]:
                self.parent[self.root(y)] = self.root(x)
            else:
                self.parent[self.root(x)] = self.root(y)
                if self.rank[x] == self.rank[y]:
                    self.rank[self.root(y)] += 1

    def ifSame(self, x, y):
        return self.root(x) == self.root(y)

    # 木の根に到達すまでにたどるノードの配列を返す
    def printDebugInfo(self):
        print([self.root(i) for i in range(self.N)])


N, K = map(int, input().split())
A = [int(x) for x in input().split()]
tmp = [0 for _ in range(N)]
# bagに入る要素が多すぎてエラーが出ている

spot = 1
road = []
for _ in range(K):
    if not tmp[spot-1]:
        road.append(spot)
        tmp[spot-1] = 1
        spot = A[spot-1]
    else:
        break

# print(road)
till_loop = road.index(spot)
# print(till_loop)
loop = road[till_loop:]
# print(loop)
cycle_len = len(road) - road.index(spot)
# print(cycle_len)
answer = loop[(K-till_loop) % cycle_len]

print(answer)


### FIXED CODE ###

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
tmp = [0 for _ in range(N)]
# bagに入る要素が多すぎてエラーが出ている

spot = 1
road = [1]
tmp[0] = 1
for _ in range(K):
    n_s = A[spot-1]
    if not tmp[n_s-1] == 1:
        road.append(n_s)
        tmp[n_s-1] = 1
        spot = n_s
    else:
        spot = n_s
        break

till_loop = road.index(spot)
# print(till_loop)
loop = road[till_loop:]
# print(loop)
cycle_len = len(road) - road.index(spot)
# print(cycle_len)
answer = loop[(K-till_loop) % cycle_len]

print(answer)
mod = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(key=lambda x: abs(x), reverse=True)
ans = 1
if N == K:
    for i in range(K):
        ans *= A[i]
        if abs(ans) > mod:
            ans %= mod
elif len([v for v in A if v <= 0]) == N:
    for i in range(K):
        ans *= A[-(i + 1)]
        if abs(ans) > mod:
            ans %= mod
else:
    num_hu = len([v for v in A[:K] if v < 0])
    if num_hu % 2 == 0:
        for i in range(K):
            ans *= A[i]
            if abs(ans) > mod:
                ans %= mod
    else:
        if len([v for v in A[K:] if v >= 0]) == N - K:
            idx = K - 1
            while True:
                if A[idx] < 0:
                    break
                idx -= 1
            for i in range(idx):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
            ans *= A[K]
            ans %= mod
            for i in range(idx + 1, K):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
        elif len([v for v in A[K:] if v <= 0]) == N - K:
            idx = K - 1
            while True:
                if A[idx] > 0:
                    break
                idx -= 1
            for i in range(idx):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
            ans *= A[K]
            ans %= mod
            for i in range(idx + 1, K):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
        else:
            ans_1 = 1
            ans_2 = 1
            # ans_1
            min_hu_idx = K - 1
            while True:
                if A[min_hu_idx] < 0:
                    break
                min_hu_idx -= 1
            max_sei_idx = K
            while True:
                if A[max_sei_idx] > 0:
                    break
                max_sei_idx += 1
            for i in range(K):
                if i == min_hu_idx:
                    ans_1 *= A[max_sei_idx]
                else:
                    ans_1 *= A[i]
                if abs(ans_1) > mod:
                    ans_1 %= mod
            # ans_2
            min_sei_idx = K - 1
            while True:
                if A[min_sei_idx] > 0:
                    break
                min_sei_idx -= 1
            max_hu_idx = K
            while True:
                if A[max_hu_idx] < 0:
                    break
                max_hu_idx += 1
            for i in range(K):
                if i == min_sei_idx:
                    ans_2 *= A[max_hu_idx]
                else:
                    ans_2 *= A[i]
                if abs(ans_2) > mod:
                    ans_2 %= mod
            ans = max(ans_1, ans_2)
print(ans % mod)


### FIXED CODE ###

N = int(input())
for i in range(10):
    if (i + 1) * 1000 >= N:
        print((i + 1) * 1000 - N)
        break
N, Q = map(int, input().split())
nodes = [[] for i in range(N)]
for i in range(N-1):
  r, e = map(int, input().split())
  r, e = r - 1, e - 1
  nodes[r].append(e)
  nodes[e].append(r)
#print(nodes)

result = [0] * N
for i in range(Q):
  r, s = map(int, input().split()
  result[r-1] += s

def dfs(r, prev=-1):
  for i in nodes[r]:
    if i == prev:
      continue
    result[i] += result[r]
    dfs(i, r)

dfs(0)
print(" ".join(map(str, result)))

### FIXED CODE ###

#人の（ほぼ同じなのにうまくいかないので）
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
lines = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)
ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, parent):
    for u in lines[v]:
        if u != parent:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print (*ans)
n = int(input())
a = list(map(int, input().split()))
ans = 1; togU = 0; togD = 0
if a[1]>a[0]: togU = 1
elif a[1]<a[0]: togD = 1
for i in range(1,n):
  if not (togD or togU):
    if a[i]>a[i-1]: togU = 1; continue
    if a[i]<a[i-1]: togD = 1; continue
  if a[i]>a[i-1]:
    if togD:
      ans += 1
      togD = 0
      togU = 0
  elif a[i]<a[i-1]:
    if togU:
      ans += 1
      togU = 0
      togD = 0
print(ans)

### FIXED CODE ###

n = int(input())
if n>1: a = list(map(int, input().split()))
else: a = int(input()); print(1); exit()
ans = 1; togU = 0; togD = 0
if a[1]>a[0]: togU = 1
elif a[1]<a[0]: togD = 1
for i in range(1,n):
  if not (togD or togU):
    if a[i]>a[i-1]: togU = 1; continue
    if a[i]<a[i-1]: togD = 1; continue
  if a[i]>a[i-1]:
    if togD:
      ans += 1
      togD = 0
      togU = 0
  elif a[i]<a[i-1]:
    if togU:
      ans += 1
      togU = 0
      togD = 0
print(ans)
n=int(input())
s=list(input())
k=int(input())
for i in range(n):
  if s[i]!=s[k]:
    print("*",end="")
  else:
    print(s[i],end="")

### FIXED CODE ###

n=int(input())
s=list(input())
k=int(input())
for i in range(n):
  if s[i]!=s[k-1]:
    print("*",end="")
  else:
    print(s[i],end="")
def resolve():
    # 整数 1 つ
    n, m = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Route = [0] * (n+1)
    Route[0] = 1
    for i in range(n):
        if i+1 not in A:
            Route[i+1] += Route[i]
            Route[i+1] %= 10**9 + 7
        if i+2 not in A and i+2 <= n:
            Route[i+2] += Route[i]
            Route[i+2] %= 10**9 + 7

    print(Route[n+1])


resolve()

### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    is_safe = [True] * (N+2)
    for a in A:
        is_safe[a+1] = False

    dp = [0] * (N+2)
    dp[1] = 1
    for i in range(2, N+2):
        if is_safe[i]:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD
        else:
            dp[i] = 0

    return dp[N+1]


if __name__ == '__main__':
    print(main())
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from heapq import heappop,heappush
    n,k=map(int,input().split())
    A=[0]*n
    for i in range(n):
        t,d=map(int,input().split())
        t-=1
        A[i]=(t,d)
    A.sort(lambda x:-x[1]) # d の降順ソート

    # 各種の中で最大かどうかをわける
    B=[0]*n
    first=[1]*n
    for i,a in enumerate(A):
        t,d=a
        if(first[t]):
            first[t]=0
            B[i]=(d,1)
        else:
            B[i]=(d,0)

    # 初めは貪欲に d の大きい方から k 個取る
    S=[]
    for i in range(k):
        d,f=B[i]
        heappush(S,(f,d))
    x=sum(S[i][1] for i in range(k))
    y=sum(S[i][0] for i in range(k))
    ans=x+y*y

    # 残りの n-k について、Sからf=0で最小のものを捨て、B[k:]からf=1の中で最大のものを加える
    B=B[k:]
    for i in range(n-k):
        d,f=B[i]
        if(f==0): continue
        pf,pd=heappop(S)
        if(pf==1): break
        x+=d-pd
        y+=1
        ans=max(ans,x+y*y)
    print(ans)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from heapq import heappop,heappush
    n,k=map(int,input().split())
    A=[0]*n
    for i in range(n):
        t,d=map(int,input().split())
        t-=1
        A[i]=(t,d)
    A.sort(lambda x:-x[1]) # d の降順ソート

    # 各種の中で最大かどうかをわける
    B=[0]*n
    first=[1]*n
    for i,a in enumerate(A):
        t,d=a
        if(first[t]):
            first[t]=0
            B[i]=(d,1)
        else:
            B[i]=(d,0)

    # 初めは貪欲に d の大きい方から k 個取る
    S=[]
    for i in range(k):
        d,f=B[i]
        heappush(S,(f,d))
    x=sum(S[i][1] for i in range(k))
    y=sum(S[i][0] for i in range(k))
    ans=x+y*y

    # 残りの n-k について、Sからf=0で最小のものを捨て、B[k:]からf=1の中で最大のものを加える
    B=B[k:]
    for i in range(n-k):
        d,f=B[i]
        if(f==0): continue
        pf,pd=heappop(S)
        if(pf==1): break
        x+=d-pd
        y+=1
        ans=max(ans,x+y*y)
    print(ans)
resolve()
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)

### FIXED CODE ###

import sys
sys.setrecursionlimit(11000)
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)
n, m = map(int, input().split())
n_l = []
ans = [0, 0, 0]

for _ in range(n):
    l = list(map(int, input().split()))
    n_l.append(l)
for x in range(m):
    p = int(input())
    n_l[0:][x]
for i in n_l:
    print(sum(i))


### FIXED CODE ###

n, m = map(int, input().split())
n_l = []
ans = [0, 0, 0]

for _ in range(n):
    l = list(map(int, input().split()))
    n_l.append(l)
for x in range(m):
    p = int(input())
    for o in range(n):
        n_l[o][x] *= p
for i in n_l:
    print(sum(i))
X=int(input("X="))
if 30<=X<=40:
   print("Yes")
elif:-40<=X<30
   print("No")

### FIXED CODE ###

X=int(input(""))
if 30<=X:
   print("Yes")
else:
   print("No")
import numpy as np
import heapq

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

links = []

sums = np.zeros(n + 1)

oya = {}

for _ in range(n - 1):
  a, b= map(int, input().split())
  oya[b] = a
  heapq.heappush(links, [a, b])

uppers = np.eye(n + 1)

for l in links:
  oyaId = l[0]
  koId = l[1]

  while True: 
    uppers[oyaId, koId] = 1
    if oyaId in oya:
      oyaId = oya[oyaId]
    else:
      break
# print(uppers)
# print(sums)
for _ in range(m):
  p, x = map(int, input().split())
  sums += x * uppers[p, :]
print(*sums[1:].astype(np.int))
  

### FIXED CODE ###

from collections import defaultdict

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

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

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

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])
n,p = map(int,input().split())
N = round(p**(1/n))
for i in range(N,0,-1):
        if p%(i**n)==0:
            print(i)
            exit()

### FIXED CODE ###

N= input()
s = N.count("2")
print(s)
N, X, T = map(int,input().split())

if ( N % x ) == 0:
    print(( N // X ) * T )
else:
    print(( N // X + 1 ) * T )

### FIXED CODE ###

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

A = N % X

if ( A ) == 0:
    print(( N // X ) * T )
elif ( N % X ) != 0:
    print(( N // X + 1 ) * T )
print("Yes" if input()[0]==input()[1] else "No")

### FIXED CODE ###

a,b,c = input()
print("Yes" if a==c else "No")
b = input()
ans = 0
ls = []
for i in range(len(b)):
    if b[i] == "A" or b[i] == "T" or b[i] == "C" or b[i] == "G":
        ans += 1
    else:
        ls.append(ans)
        ans = 0
print(max(ls))


### FIXED CODE ###

b = input()
ans = ""

for i in range(len(b)):
    if b[i] == "A" or b[i] == "T" or b[i] == "C" or b[i] == "G":
        ans += "1"
    else:
        ans += "0"
#print(ans)

ls = ans.split("0")
#print(ls)
print(len(max(ls)))
while tmp > 0:
    sum += tmp % 10
    tmp /= 10

if n % sum == 0:
    print ("Yes")
else:
    print ("No")

### FIXED CODE ###

n =int(input())

s=eval("+".join(str(n)))
if n % s ==0:
  print('Yes')
else:
  print('No')
import fractions
n,m=map(int, input().split())
a=list(map(int, input().split()))
b=[]
for i in range(n):
    b.append(int(a[i]/2))

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

c=[lcm(b[0],b[1])]
for i in range(1,n):
    x=lcm(c[i-1],b[i])
    c.append(x)

d=int(m//c[len(c)-1])
ans=int((d+1)//2)
print(ans)


### FIXED CODE ###

import math
import fractions
n,m=map(int, input().split())
a=list(map(int, input().split()))
b=[]
s=math.floor(math.log2(max(a)))
buf=0
for i in range(n): #aは偶数なので、1/2した値の配列を作った
    b.append(int(a[i]//2))

for i in range(s+1): #2のi乗ですべての数が割れるかどうか
    for j in b:
        if j%(2**i)==0:
            buf+=1
        else:
            continue
    if buf==n:
        buf=0
        continue
    else:
        break

def lcm(x,y): #最小公倍数を求める関数の定義
    return (x*y)//fractions.gcd(x,y)

if buf!=0 and buf!=n: #偶奇が入り混じってるとき
    print(0)
elif n==1: #配列の要素が1つしかないとき
    d=int(m//b[0])
    print(int((d+1)//2))
else:
    c=[lcm(b[0],b[1])] #以下のサイクルで求めた最小公倍数を入れる配列
    for i in range(1,n):
        x=lcm(c[i-1],b[i])
        c.append(x)
        if x<m:
            continue
        else:
            break
    d=int(m//c[len(c)-1]) #最後の値(c[len(c)-1])が配列bの最小公倍数
    ans=int((d+1)//2)
    print(ans)
N,X = [int(x) for x in input().split()] # N と　X
list_2 = [int(x) for x in input().split()]
 
sum_list = []
for i in list_2:
    if sum(sum_list) < X:
      sum_list.append(i)
    elif sum(sum_list) == X:
      print(len(sum_list) + 1)
      break
    elif sum(sum_list) > X:
      print(len(sum_list))
      break
if sum(sum_list) < X:
    print(N + 1)


### FIXED CODE ###

input_line = input()
l = input_line.split(' ')
l = [int(x) for x in l]

if l[0] < l[1]:
    print(0)
else:
    print(10)
A, B = map(int, input().split())
print((A + B) // 2) if A % 2 == B % 2 else print("IMPOSSIBLE)

### FIXED CODE ###

A, B = map(int, input().split())
print((A + B) // 2) if A % 2 == B % 2 else print("IMPOSSIBLE")
n = int(input())
a = list(map(int, input().split()))

checker = [0 for _i in range(10**6+1)]
h = True
for i in a:
    if i == 1:
        continue
    num = i
    if num%2==0:
        checker[2] += 1
        if checker[2] >= 2:
            h = False
            break
    
    for j in range(3, int(i**0.5)+1):
        if num%j == 0:
            checker[j] += 1
            if checker[j] >= 2:
                h = False
                break
            num //= j
    if num == i:
        checker[num] += 1:
        if checker[num] >= 2:
            h = False
            break
if h == True:
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

### FIXED CODE ###

from math import gcd

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

checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1

if all(sum(checker[i::i])<2 for i in range(2,10**6+1)):
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')
A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

if A*B >= C*D:
  print (A*B)
else:
  print (C*D)


### FIXED CODE ###

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

ab = a * b
cd = c * d

if ab == cd:
    print(int(ab))
elif ab > cd:
    print(int(ab))
else:
    print(int(cd))
N=int(input())
if N % 2 = 0:
  print(N)
else:
  print(N*2)

### FIXED CODE ###

N=int(input())
if N % 2 == 0:
  print(N)
else:
  print(N*2)