CodeEff/ECCO huggingface dataset:
# Original solution
k=int(eval(input()))
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        ans[-1].append(x+str(z))
        if z<=8:
            ans[-1].append(x+str(z+1))
        if z>=1:
            ans[-1].append(x+str(z-1))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print((v[k-(d-l)-1]))

# Optimized solution
k=int(eval(input()))
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        ans[-1].append(x+str(z))
        if z<=8:
            ans[-1].append(x+str(z+1))
        if z>=1:
            ans[-1].append(x+str(z-1))
    d+=len(ans[-1])
ans[-1].sort()
print((ans[-1][k-d-1]))
# Original solution
from collections import deque

k = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
queue = deque(queue)
cnt = 0
while cnt < k:
    cnt += 1
    a = queue.popleft()
    hitoketa = a % 10
    kouho = [hitoketa - 1, hitoketa, hitoketa + 1]
    for b in kouho:
        if b >= 0 and b <= 9:
            queue.append(10 * a + b)
print(a)


# Optimized solution
from collections import deque

k = int(eval(input()))

LL = [i for i in range(1, 10)]
LL = deque(LL)
for j in range(k):
    num = LL.popleft()
    amari = num % 10
    kouho = [amari - 1, amari, amari + 1]
    for nn in kouho:
        if nn >= 0 and nn < 10:
            LL.append(10 * num + nn)
print(num)
# Original solution
import sys

N, K = list(map(int, sys.stdin.readline().split()))

if K == 0:
    print((N*N))
    sys.exit()

# b は K 以上
# a は b * c + K <= a < b * (c+1)
ans = 0
for i in range(1, N+1):
    # print(N // i, (i - K), max(N % i - K, 0))
    tmp = (N // i) * max(i - K, 0) + max(N % i + 1 - K, 0)
    ans += tmp

print(ans)

# Optimized solution
import sys

N, K = list(map(int, sys.stdin.readline().split()))

if K == 0:
    print((N*N))
    sys.exit()

ans = 0
for b in range(K+1, N+1):
    r = N // b
    # tmp = (b - K) * r
    # tmp2 = (N % b + 1 - K)
    # print(b, tmp, tmp2)
    tmp = (b - K) * r + max(0, N % b + 1 - K)
    ans += tmp

print(ans)
# Original solution
import sys
n,k = list(map(int,input().split()))
#if k == 0:
#    print(n**2)
 #   sys.exit
count = 0
for i in range(1,n+1):
    tmp_count = max(0,i - k)
    #print(i,n // i,tmp_count,(n // i)* tmp_count + max(0,(n % k)-k+1),max(0,(n % i)-k+1),n % i)
    count += (n // i)* tmp_count + max(0,(n % i)-k+1)

if k == 0:
  count -= n
print(count)

# Optimized solution
import sys
n,k = list(map(int,input().split()))
#if k == 0:
#    print(n**2)
 #   sys.exit
count = 0
for i in range(1,n+1):
    tmp_count = max(0,i - k)
    #print(i,n // i,tmp_count,(n // i)* tmp_count + max(0,(n % k)-k+1),max(0,(n % i)-k+1),n % i)
    count += (n // i)* tmp_count + max(0,(n % i)-k+1)

if k == 0:
    print((n**2))
else:
    print(count)
# Original solution
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
res = 0
for i in range(1, N + 1):
  u = max(i - K, 0)
  v = N // i
  x = max(N % i - K + 1, 0)
  res += u * v + x - (K == 0)
  #print(i, u, v, x)
  #print(res)
print(res)

# Optimized solution
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
res = 0
for x in range(K + 1, N + 1):
  res += (N // x) * (x - K) + max(0, N % x - K + (K > 0))
  #print(x, res)
print(res)
# Original solution
n, k = list(map(int, input().split()))

if k == 0:
    print((n**2))
    exit()

ans = 0
for i in range(1, n+1):
    if i <= k:
        continue
    q, r = divmod(n, i)
    if r < k:
        ans += (i-k)*q
    else:
        ans += (i-k)*q + (r-k+1)
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))

if k == 0:
    ans = n**2
    print(ans)
    exit()

ans = 0
for b in range(1, n+1):
    if b <= k:
        continue
    q, r = divmod(n, b)
    if r < k:
        ans += ((b-1)-k+1)*q
    else:
        ans += ((b-1)-k+1)*q + r-k+1
print(ans)
# Original solution
def calc0(N, K):
    r = 0
    for a in range(1, N + 1):
        for b in range(1, N + 1):
            if a % b >= K:
                print((a, b, a % b))
                r += 1
    return r

def calc1(N, K):
    result = 0
    for i in range(K, N):
        for x in range(i + 1, N + 1):
            if i > 0:
                r = (N + x - i) // x
            else:
                r = (N + x - i) // x - 1
            # print(i, x, r)
            result += r
    return result

def calc2(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        for i in range(K, min(N, x)):
            r = (N - i) // x + 1
            result += r
    return result

def calc2(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        for i in range(K, min(N, x)):
            r = (N - i) // x + 1
            result += r
    return result

def calc3(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        st = N - min(N, x) + 1
        ed = N - K
        if (ed < x):
            r = (ed - st + 1)
        else:
            r = 0
            for j in range(st, ed + 1):
                r += j // x + 1
        print((st, ed, x, r))
        result += r
    return result

def calc(N, K):
    if K == 0:
        return N**2
    result = 0
    for b in range(1, N + 1):
        if b <= K:
            continue
        n, m = divmod(N, b)
        r1 = (b - K) * n
        r2 = 0
        if m >= K:
            r2 = m - K + 1
        result += r1 + r2
    return result

N, K = [int(_) for _ in input().split()]
# print(calc2(N, K))
print((calc(N, K)))


# Optimized solution
def calc(N, K):
    if K == 0:
        return N**2
    result = 0
    for b in range(K + 1, N + 1):
        n, m = divmod(N, b)
        result += (b - K) * n
        if m >= K:
            result += m - K + 1
    return result

N, K = [int(_) for _ in input().split()]
print((calc(N, K)))
# Original solution
n,k=list(map(int,input().split()))
ans=0
for b in range(k+1,n+1):
  ans+=(n//b)*(b-k)
  m=n%b
  ans+=max(0,m-(k-1))
if k==0:ans-=n
print(ans)

# Optimized solution
n,k=list(map(int,input().split()))
ans=0
for b in range(k+1,n+1):
  m=(n//b)
  mm=n%b
  ans+=m*(b-k)
  ans+=max(0,mm-k+1)
print((ans-(n if k==0 else 0)))
# Original solution
n, k = list(map(int, input().split()))
ans = 0
if k == 0:
    ans = n*n
else:
    for i in range(1, n+1):
        ans += n//i * max(i-k, 0)
        a = n//i * max(i-k, 0)
        b = 0
        if i >= k and n % i != 0:
            ans += max(0, (n%i+1)-k)
            b = max(0, (n%i+1)-k)
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
ans = 0
if k == 0:
    ans = n * n
else:
    for i in range(1, n + 1):
        ans += n // i * max(i - k, 0)
        if i >= k and n % i != 0:
            ans += max(0, (n % i + 1) - k)
print(ans)
# Original solution
N, K = list(map(int, input().split()))

ans = 0
for b in range(K + 1, N + 1):
    p = N // b
    q = p * (b - K) + max(N % b - K + 1, 0)
    ans += q if K > 0 else q-1

print(ans)


# Optimized solution
N,K=list(map(int,input().split()));print((sum(N//b*(b-K)+max(N%b+1-K,0)-(K<1)for b in range(K+1,N+1))))
# Original solution
N, K = list(map(int, input().split()))

if K == 0:
    print((N**2))
    exit()

ans = 0
for div in range(K + 1, N + 1):
    cnt = N // div
    ans += cnt * (div - K)
    ans += max(0, (N % div) - K + 1)

print(ans)

# Optimized solution
N, K = list(map(int, input().split()))

if K == 0:
    print((N**2))
    exit()

ans = 0
for d in range(K + 1, N + 1):
    ans += (N // d) * (d - K)
    ans += max(0, N % d - K + 1)
print(ans)
# Original solution
n, k = list(map(int, input().split(' ')))
result = 0
for i in range(1, n+1):
    p = n//i
    result += p*max(0,i-k)
    result += max(0, n%i-k+1)
    if k == 0:
        result -= 1
print(result)

# Optimized solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        p = n//i
        result += p*max(0,i-k)
        result += max(0, n%i-k+1)
        if k == 0:
            result -= 1
    print(result)
main()
# Original solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        p = n//i
        result += p*max(0,i-k)
        result += max(0, n%i-k+1)
        if k == 0:
            result -= 1
    print(result)
main()

# Optimized solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        p = n//i
        result += p*max(0,i-k)
        result += max(0, n%i-k+1)
    if k == 0:
        result -= n
    print(result)
main()
# Original solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        p = n//i
        result += p*max(0,i-k)
        result += max(0, n%i-k+1)
    if k == 0:
        result -= n
    print(result)
main()

# Optimized solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        result += n//i*max(0,i-k) + max(0, n%i-k+1)
    if k == 0:
        result -= n
    print(result)
main()
# Original solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = 0
    for i in range(1, n+1):
        result += n//i*max(0,i-k) + max(0, n%i-k+1)
    if k == 0:
        result -= n
    print(result)
main()

# Optimized solution
def main():
    n, k = list(map(int, input().split(' ')))
    result = [n//i*max(0,i-k) + max(0, n%i-k+1) for i in range(1, n+1)]
    if k == 0:
        print((sum(result)-n))
    else:
        print((sum(result)))
main()
# Original solution
n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
    ans += ((n // b) * max(0, b - k)) + max(0, (n % b) - k + 1)
if k == 0:
    ans = n ** 2
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
    ans += ((n // b) * (b - k)) + max(0, (n % b) - k + 1)
if k == 0:
    ans = n ** 2
print(ans)
# Original solution
import math

n, k = list(map(int, input().split()))
res = 0
for b in range(1, n + 1):
    res += math.floor(n / b) * max(0, b - k) + max(0, n % b - k + 1)

if k == 0:
    res = n ** 2

print(res)


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))

    if k == 0:
        print((n ** 2))
        exit()

    res = 0
    for b in range(1, n + 1):
        res += n // b * max(0, b - k)
        res += max(0, n % b + 1 - k)
    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))

    if k == 0:
        print((n ** 2))
        exit()

    res = 0
    for b in range(1, n + 1):
        res += n // b * max(0, b - k)
        res += max(0, n % b + 1 - k)
    print(res)


if __name__ == '__main__':
    resolve()


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))
    if k == 0:
        print((n ** 2))
        exit()

    res = 0
    for b in range(1, n + 1):
        res += (n // b) * max(0, (b - k))
        res += max(0, (n % b) - (k - 1))
    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
n, k = [int(i) for i in input().split()]
ans = 0
if k == 0:
    ans = n*n
else:
    for b in range(k+1, n+1):
        # number of perfect cycle
        ans += max(n // b, 0) * (b-k)
        r = n % b
        ans += max(r - k+1, 0)
print(ans)

# Optimized solution
n, k = [int(i) for i in input().split()]
ans = 0
if k == 0:
    ans = n*n
else:
    for b in range(k+1, n+1):
        # number of perfect cycle
        ans += n // b * (b-k)
        r = n % b
        ans += max(r - k+1, 0)
print(ans)
# Original solution
n,k=list(map(int,input().split()))
a=0
for b in range(1,n+1):
    if b>k:
        a+=(b-k)*(n//b)+(n%b-k+1)*(n%b>k-1)-1*(k==0)
print(a)

# Optimized solution
n,k=list(map(int,input().split()))
a=0
for b in range(k+1,n+1):
  a+=(b-k)*(n//b)+(n%b-k+1)*(n%b>k-1)-1*(k==0)
print(a)
# Original solution
n,k = list(map(int,input().split()))
ans =0
if k==0:
    print((n**2))
    exit()
for i in range(k+1,n+1):
    ans+=(n//i)*(i-k) + max(0,n%i-k+1)
print(ans)

# Optimized solution
def solve():
    n,k = list(map(int,input().split()))
    res = 0
    for i in range(k+1,n+1):
        res+=(i-k)*(n//i)
        if n%i>=k:
            if k==0:
                res+=n%i
            else:
                res+=n%i-k+1
    print(res)
if __name__=='__main__':
    solve()
# Original solution
N,K = list(map(int,input().split()))
if K == 0:
    print((N*N))
    exit()

ans = 0
for b in range(1,N+1):
    cycle,rem = divmod(N,b)
    ans += cycle * max(0, b-K)
    ans += max(0, rem+1 - K)
print(ans)

# Optimized solution
N,K = list(map(int,input().split()))
if K == 0:
    print((N*N))
    exit()

ans = 0
for b in range(K+1,N+1):
    d,m = divmod(N,b)
    ans += d*(b-K) + max(0,m+1-K)
print(ans)
# Original solution
def main():
    N, K = list(map(int, input().split()))
    cnt = 0
    for b in range(1,N+1):
        cnt += (N // b) * max(0, b - K)
        cnt += max(0, (N % b) + 1 - K)

    if K == 0:
        cnt -= N

    print(cnt)


if __name__ == "__main__":
    main()

# Optimized solution
def num_divisors_cnt(n):
    table = [0] * (n + 1)
    
    for i in range(1, n+1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

def main():
    N, K = list(map(int, input().split()))
    ans = 0
    
    for i in range(K+1,N+1):
        cnt = i - K
        cnt *= N // i
        cnt += max((N % i) - K + 1,0)
        ans += cnt
    if K == 0:
        ans -= N
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n, k = list(map(int, input().split()))

ans = 0
if k == 0:
    print((n * n))
    exit()

for i in range(k + 1, n + 1):
    # 周期i
    # 0 1 2 3 ... i - 1, 0,
    # 1周期にi - kこk以上

    # 1始まりなのがめんどい
    # 最初1周期だけさせる
    m = n
    m -= i - 1
    ans += i - k

    full = m // i * (i - k)
    amari = m % i  # 周期の途中でnを超える
    ans += full + max(0, amari - k)
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
print((sum([n // i * (i - k) + max(0, n % i - k + 1)
           for i in range(k + 1, n + 1)]) - (k == 0) * n))
# Original solution
n,k = list(map(int,input().split()))
print((sum([(i-k)*(n//i)+max(0,n%i-max(0,k-1)) for i in range(k+1,n+1)])))

# Optimized solution
n,k = list(map(int,input().split()))
print((n**2 if not k else sum([(i-k)*(n//i)+max(0,n%i-k+1) for i in range(k+1,n+1)])))
# Original solution
N,K = list(map(int,input().split()))

ans = 0

for b in range(1,N+1) :
    p = N//b
    r = N % b
    ans += max(0, b-K)*p + max(0, r-K+1)
    
    if K == 0 :
        ans -= 1

print(ans)


# Optimized solution
N,K = list(map(int,input().split()))

ans = 0

for b in range(1,N+1) :
    p = N//b
    r = N % b
    ans += max(0, b-K)*p + max(0, r-K+1)
    
if K == 0 :
    ans -= N

print(ans)
# Original solution
N,K=list(map(int,input().split()))
 
b = K + 1
s = 0
while b <= N:
    c = N % b
    s += (N//b)*(b-K) + max(0,c-K+1)
    b += 1

print((s if K != 0 else N*N))


# Optimized solution
N,K=list(map(int,input().split()))
b,s=K+1,0
while b <= N:
 c=N%b
 s+=(N//b)*(b-K)+max(0,c-K+1)
 b+=1
print((s if K!=0 else N*N))
# Original solution
N,K=list(map(int,input().split()))
b,s=K+1,0
while b <= N:
 c=N%b
 s+=(N//b)*(b-K)+max(0,c-K+1)
 b+=1
print((s if K!=0 else N*N))

# Optimized solution
N,K=list(map(int,input().split()))
s=0
for b in range(K+1,N+1):s+=(N//b)*(b-K)+max(0,N%b-K+1)
print((s if K!=0 else N*N))
# Original solution
N,K=list(map(int,input().split()))
if K==0:
  print((N**2))
  exit(0)
ans=0
for i in range(K+1,N+1):
  cur=0
  base=i-(K-1)-1
  cur+=(N//i)*base
  rest=N%i
  cur+=max(rest-(K-1),0)
  ans+=cur
print(ans)

# Optimized solution
N,K=list(map(int,input().split()))
if K==0:
  print((N**2))
  exit(0)
ans=0
for i in range(K+1,N+1):
  base=i-(K-1)-1
  ans+=(N//i)*base
  rest=N%i
  ans+=max(rest-(K-1),0)
print(ans)
# Original solution
import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = list(map(int,input().split()))
if N == 1:
    print((1))
    exit()
graph = [set() for _ in range(N)]
for row in sys.stdin.readlines():
    x,y = list(map(int,row.split()))
    graph[x-1].add(y-1)
    graph[y-1].add(x-1)

ldp = [None] * N
rdp = [None] * N

def dfs_1(v=0,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    graph[v].discard(parent)
    ldp[v] = [1] * (len(graph[v])+1)
    rdp[v] = [1] * (len(graph[v])+1)
    vals = [dfs_1(w,v)+1 for w in graph[v]]
    for i,x in enumerate(vals,1):
        ldp[v][i] = ldp[v][i-1] * x % MOD
    for i,x in enumerate(reversed(vals),1):
        rdp[v][-i-1] = rdp[v][-i] * x % MOD
    return ldp[v][-1]

dfs_1()

def dfs_2(v=0,x=1):
    # それぞれの子以外の情報をマージして、子に渡さなければいけない
    dp[v] = x * ldp[v][-1] % MOD
    for w,p,q in zip(graph[v],ldp[v][:-1],rdp[v][1:]):
        dfs_2(w,x*p*q%MOD+1)

dp = [None] * N
dfs_2()

print(('\n'.join(map(str,dp))))

# Optimized solution
import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = list(map(int,input().split()))
if N == 1:
    print((1))
    exit()
graph = [set() for _ in range(N)]
for row in sys.stdin.readlines():
    x,y = list(map(int,row.split()))
    graph[x-1].add(y-1)
    graph[y-1].add(x-1)

ldp = [None] * N
rdp = [None] * N

def dfs_1(v=0,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    graph[v].discard(parent)
    ldp[v] = [1] * (len(graph[v])+1)
    rdp[v] = [1] * (len(graph[v])+1)
    vals = [dfs_1(w,v)+1 for w in graph[v]]
    for i,x in enumerate(vals,1):
        ldp[v][i] = ldp[v][i-1] * x % MOD
    for i,x in enumerate(reversed(vals),1):
        rdp[v][-i-1] = rdp[v][-i] * x % MOD
    return ldp[v][-1]

dfs_1()

dp = [None] * N
q = [(0,1)]
while q:
    v,x = q.pop()
    dp[v] = x*ldp[v][-1]%MOD
    for w,L,R in zip(graph[v],ldp[v][:-1],rdp[v][1:]):
        q.append((w,x*L*R%MOD+1))

print(('\n'.join(map(str,dp))))
# Original solution
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

N, M = list(map(int, readline().split()))
G = [[] for i in range(N)]
for i in range(N-1):
    x, y = list(map(int, readline().split()))
    G[x-1].append((y-1, 2*i))
    G[y-1].append((x-1, 2*i+1))
G0 = [None]*N
used = [0]*N
used[0] = 1
que = deque([0])
while que:
    v = que.popleft()
    g = []
    for e in G[v]:
        w, d = e
        if used[w]:
            continue
        g.append(e)
        used[w] = 1
        que.append(w)
    G0[v] = g


memo = [0]*(2*N+1)
def dfs0(v, p, e):
    r = 1
    for w, d in G0[v]:
        r = r * (1 + dfs0(w, v, d)) % M
    memo[e] = r
    return r


lv = [0]*(2*N); rv = [0]*(2*N)
ans = [None]*N
def dfs1(v, p, par):
    s = 1 + par
    for w, d in G0[v]:
        lv[d] = s
        s = s * (1 + memo[d]) % M
    s = 1
    for w, d in reversed(G0[v]):
        rv[d] = s
        s = s * (1 + memo[d]) % M
    for w, d in G0[v]:
        memo[d ^ 1] = x = lv[d] * rv[d] % M
        dfs1(w, v, x)


dfs0(0, -1, 2*N)
dfs1(0, -1, 0)
ans = []
for v in range(N):
    r = 1
    for w, d in G[v]:
        r = r * (1 + memo[d]) % M
    ans.append("%d\n" % r)
sys.stdout.writelines(ans)

# Optimized solution
import sys
from collections import deque

readline = sys.stdin.readline

N, M = list(map(int, readline().split()))
G = [[] for i in range(N)]
for i in range(N-1):
    x, y = list(map(int, readline().split()))
    G[x-1].append((y-1, 2*i))
    G[y-1].append((x-1, 2*i+1))

G0 = [None]*N
V = [(0, -1)]
used = [0]*N
used[0] = 1
que = deque([0])
while que:
    v = que.popleft()
    g = []
    for e in G[v]:
        w, d = e
        if used[w]:
            continue
        g.append(e)
        V.append(e)
        used[w] = 1
        que.append(w)
    G0[v] = g

memo = [0]*(2*N+1)
for v, e in reversed(V):
    r = 1
    for w, d in G0[v]:
        r = r * (1 + memo[d]) % M
    memo[e] = r

lv = [0]*(2*N); rv = [0]*(2*N)
for v, e in V:
    s = 1 + memo[e ^ 1]
    for w, d in G0[v]:
        lv[d] = s
        s = s * (1 + memo[d]) % M
    s = 1
    for w, d in reversed(G0[v]):
        rv[d] = s
        s = s * (1 + memo[d]) % M
    for w, d in G0[v]:
        memo[d ^ 1] = lv[d] * rv[d] % M

ans = []
for v in range(N):
    r = 1
    for w, d in G[v]:
        r = r * (1 + memo[d]) % M
    ans.append("%d\n" % r)
sys.stdout.writelines(ans)
# Original solution
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)

N, MOD = list(map(int, input().split()))

#計算量 log(m)くらい
def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u

G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = list(map(int, input().split()))
    G[x].append(y)
    G[y].append(x)

DP1 = [-1] * (N + 1)
DP1[0] = 1
parent = [-1] * (N + 1)
parent[1] = 0

def dfs(x, p):
    tmp = 1
    for next_ in G[x]:
        if next_ == p:
            continue
        parent[next_] = x
        tmp *= (dfs(next_, x) + 1)
    DP1[x] = tmp
    return tmp

dfs(1, 0)
# print (DP1)

DP2 = [-1] * (N + 1)
DP2[0] = 1
DP2[1] = 1
stack = [1]

while stack:
    x = stack.pop()
    for next_ in G[x]:
        if DP2[next_] != -1:
            continue
        tmp = DP1[x]
        tmp //= (DP1[next_] + 1)
        tmp *= DP2[parent[next_]]
        tmp += 1 #白色の分
        DP2[next_] = tmp
        stack.append(next_)

# print (DP2)

for i in range(1, N + 1):
    print((DP1[i] %  MOD * (DP2[i] % MOD) % MOD))

# Optimized solution
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)

N, MOD = list(map(int, input().split()))

#計算量 log(m)くらい
def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u

G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = list(map(int, input().split()))
    G[x].append(y)
    G[y].append(x)

DP1 = [-1] * (N + 1)
DP1[0] = 1
parent = [-1] * (N + 1)
parent[1] = 0

def dfs(x, p):
    tmp = 1
    for next_ in G[x]:
        if next_ == p:
            continue
        parent[next_] = x
        tmp *= (dfs(next_, x) + 1)
        tmp %= MOD
    DP1[x] = tmp
    return tmp

dfs(1, 0)
# print (DP1)

DP2 = [-1] * (N + 1)
DP2[0] = 1
DP2[1] = 1
stack = [1]

while stack:
    x = stack.pop()
    for next_ in G[x]:
        if DP2[next_] != -1:
            continue
        tmp = 1
        for y in G[x]:
            if y != next_ and y != parent[x]:
                tmp *= (DP1[y] + 1)
                tmp %= MOD
        tmp *= DP2[parent[next_]]
        tmp += 1 #白色の分
        DP2[next_] = tmp % MOD
        stack.append(next_)

# print (DP2)

for i in range(1, N + 1):
    print((DP1[i] * DP2[i] % MOD))