Harryxun/stf_run huggingface dataset:
#これだとTLEするっぽい
from collections import deque
H, W = list(map(int, input().split()))

city = []

for _ in range(H):
    city.append(list(input()))

black_grid = []

for i in range(H):
    for j in range(W):
        if city[i][j] == "#":
            black_grid.append((i, j))

dist = [[float("inf") for _ in range(W)] for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

for start in black_grid:
    sx, sy = start
    queue = deque()
    queue.append(start)
    dist[sy][sx] = 0

    while len(queue) > 0:
        now_x, now_y = queue.popleft()

        for dx_, dy_ in zip(dx, dy):
            adj_x = now_x + dx_
            adj_y = now_y + dy_

            if (not 0 <= adj_x < W) or (not 0 <= adj_y < H):
                continue

            if city[adj_y][adj_x] == "#":
                continue

            #初めてそのマスに到達する場合
            if dist[adj_y][adj_x] > H*W:
                dist[adj_y][adj_x] = dist[now_y][now_x] + 1
                queue.append((adj_x, adj_y))

            elif H*W > dist[adj_y][adj_x] > dist[now_y][now_x] + 1:
                dist[adj_y][adj_x] = dist[now_y][now_x] + 1
                queue.append((adj_x, adj_y))


ans = -1
for i in range(H):
    for j in range(W):
        if dist[i][j] <= H*W:
            ans = max(dist[i][j], ans)

print(ans)


### FIXED CODE ###

from collections import deque
H, W = list(map(int, input().split()))

g = []

for _ in range(H):
    g.append(list(input()))

dist = [[-1 for _ in range(W)] for _ in range(H)]
queue = deque()

for i in range(H):
    for j in range(W):
        if g[i][j] == "#":
            dist[i][j] = 0
            queue.append((j, i))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while len(queue) > 0:
    now_x, now_y = queue.popleft()

    for dx_, dy_ in zip(dx, dy):
        adj_x = now_x + dx_
        adj_y = now_y + dy_

        if (not 0 <= adj_x < W) or (not 0 <= adj_y < H):
            continue

        if g[adj_y][adj_x] == "#" :
            continue

        if g[adj_y][adj_x] == ".":
            g[adj_y][adj_x] = "#"
            queue.append((adj_x, adj_y))
            dist[adj_y][adj_x] = dist[now_y][now_x] + 1

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(dist[i][j], ans)

print(ans)
# coding: utf-8
div = 10 ** 9 + 7
n = int(input())
ans = 1
for i in range(1, N + 1):
  ans = (ans * i) % div
print(ans)

### FIXED CODE ###

# coding: utf-8
div = 10 ** 9 + 7
n = int(input())
ans = 1
for i in range(1, n + 1):
  ans = (ans * i) % div
print(ans)
from sys import stdin

N, M, *A = map(int, stdin.read().split())
req = {1: 2,
       2: 5,
       3: 5,
       4: 4,
       5: 5,
       6: 6,
       7: 3,
       8: 7,
       9: 6}

B = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)
min_ = min(B, key=lambda x: x[1])[1]


def dp(N, B, min_):
    if N == 0:
        return []
    elif N // min_ < 1:
        return None
    else:
        for a, n in B:
            if (N // min_) - ((N-n) // min_) == 1:
                ret = dp(N-n, B, min_)
                if ret is not None:
                    return [a] + ret


lst = dp(N, B, min_)
print(''.join(map(str, lst)))

### FIXED CODE ###

from sys import stdin

N, M, *A = map(int, stdin.read().split())
req = {1: 2,
       2: 5,
       3: 5,
       4: 4,
       5: 5,
       6: 6,
       7: 3,
       8: 7,
       9: 6}

B = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)
a_min, n_min = min(B, key=lambda x: x[1])
g = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]
l = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]
l.sort(key=lambda x: x[1], reverse=True)
C = g + l

def dp(rem, C):
    ret = None
    if rem == 0:
        ret = []
    elif rem > 0:
        for i in range(len(C)):
            a, m = C[i]
            nxt = dp(rem-m, C[i:])
            if nxt is not None:
                ret = [a] + nxt
                break
    return ret


i = 0
while True:
    quo = N // n_min - i
    rem = N % n_min + i * n_min
    lst = dp(rem, C)
    if lst is not None:
        lst = sorted(lst + [a_min] * (quo-len(lst)), reverse=True)
        print(''.join(map(str, lst)))
        break
    i += 1
n,x = map(int, input().split())
l = [ abs(i - x) for i in list(map(int, input().split()))]
l.sort(reverse=True)
if len(l) == 1:ans = l[0]
else:
  while len(l) != 1:
    l = list(set(l))
    l = [ l[i] - l[i+1] for i in range(len(l) - 1)]
  ans = l[0]
print(ans)

### FIXED CODE ###

a,b = map(int, input().split())
if a * b % 2 == 0 : print("No")
else : print("Yes")
s=str(input())
s[3]='8'
print(s)

### FIXED CODE ###

s=str(input())
S=list(s)
S[3]='8'
s=''.join(S)
print(s)
a = input
print(a.count('+') - a.count('-'))

### FIXED CODE ###

a = input()
print(a.count('+') - a.count('-'))
import sys
N, Y = map(int, input().split())

for x in range(N+1):
  for y in range(N+1):
    z = N-(x+y)
    if 10000*x + 5000*y + 1000*z = Y:
      print(x,y,z)
      sys.exit()

print(-1,-1,-1)

### FIXED CODE ###

import sys
N, Y = map(int, input().split())

for x in range(N+1):
  for y in range(N+1):
    z = N-(x+y)
    if z < 0: break
    elif 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      sys.exit()

print(-1,-1,-1)
import sys
import itertools
import networkx as nx
H, W = [int(_) for _ in input().split()]
S = b''.join(sys.stdin.buffer.read().split())

source = 2 * H * W
sink = source + 1

INF = 10**12

graph = nx.DiGraph()


def add(start, end, cap):
    graph.add_edge(start, end, capacity=cap)


for i in range(H * W):
    x, y = divmod(i, W)
    if S[i] == ord('.'):
        add(2 * i, 2 * i + 1, 1)
    else:
        add(source, 2 * i + 1, INF)
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        x1, y1 = x + dx, y + dy
        if 0 <= x1 < H and 0 <= y1 < W:
            j = x1 * W + y1
            add(2 * i + 1, 2 * j, INF)
        else:
            add(2 * i + 1, sink, INF)
ans = nx.minimum_cut_value(graph, source, sink)
ans = ans if ans < INF else -1
print(ans)


### FIXED CODE ###

import sys
import itertools
from scipy.sparse import csr_matrix, lil_matrix
from scipy.sparse.csgraph import maximum_flow

H, W = map(int, sys.stdin.buffer.readline().split())
S = b''.join(sys.stdin.buffer.read().split())

source = 2 * H * W
sink = source + 1

INF = source * 2

graph = lil_matrix((sink + 1, sink + 1), dtype=int)

for i in range(H * W):
    x, y = divmod(i, W)
    if S[i] == ord('.'):
        graph[2 * i, 2 * i + 1] = 1
    else:
        graph[source, 2 * i + 1] = INF
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        x1, y1 = x + dx, y + dy
        if 0 <= x1 < H and 0 <= y1 < W:
            j = x1 * W + y1
            graph[2 * i + 1, 2 * j] = 1
        else:
            graph[2 * i + 1, sink] = INF
graph = graph.tocsr()
ans = maximum_flow(graph, source, sink).flow_value
ans = ans if ans < INF else -1
print(ans)
N = int(input())
A = [int(i) for i in input().split(',')]

is_all_even = True
counter = 0
while True:
    for i, v in enumerate(A):
        if v % 2 == 0:
            A[i] = A[i] // 2
        else:
            is_all_even = False
    if is_all_even:
        counter += 1
    else:
        break
print(counter)



### FIXED CODE ###

i = input()
print(int(i[0] == '1') + int(i[1] == '1') + int(i[2] == '1'))
%import numpy as np
c1 = [int(i) for i in input().split()]
c2 = [int(i) for i in input().split()]
c3 = [int(i) for i in input().split()]
s = sum(c1) + sum(c2) + sum(c3)
print(s % 3 == 0)

### FIXED CODE ###

import numpy as np
c = np.array([[int(i) for i in input().split()] for _ in range(3)])
b = np.sum(c) % 3 == 0
b &= np.sum(c[0] - c[1]) % 3 == 0
b &= np.sum(c[0] - c[2]) % 3 == 0
b &= np.sum(c[1] - c[2]) % 3 == 0
c = c.T
b &= np.sum(c[0] - c[1]) % 3 == 0
b &= np.sum(c[0] - c[2]) % 3 == 0
b &= np.sum(c[1] - c[2]) % 3 == 0
print('Yes' if b else 'No')
print(2*a+b,a*b)


### FIXED CODE ###

a,b = map(int,input().split())
print(a*b,2*(a+b))
N=int(input())
x=[0]*N
y=[0]*N
h=[0]*N

for i in range(N):
    x[i],y[i],h[i]=map(int,input().split())

for tx in range(101):
    for ty in range(101):
        th=h[0]+abs(tx-x[0])+abs(ty-y[0])
        flag=1
        for i in range(N):
            nh=h[i]+abs(tx-x[i])+abs(ty-y[i])
            if nh!=th:
                flag=0
                break
        if flag==1:
            ans=[tx,ty,th]
            break

print(' '.join(map(str, ans)))     

### FIXED CODE ###

N=int(input())
x=[0]*N
y=[0]*N
h=[0]*N

ti=0

for i in range(N):
    x[i],y[i],h[i]=map(int,input().split())
    if h[i]!=0:
        ti=i



flag=0
for tx in range(101):
    if flag==1:
        break
    for ty in range(101):
        th=h[ti]+abs(tx-x[ti])+abs(ty-y[ti])
        flag=1
        for i in range(N):
            nh=h[i]+abs(tx-x[i])+abs(ty-y[i])
            if (h[i]!=0 and nh!=th) or (h[i]==0 and nh<th ):
                flag=0
                break
        if flag==1:
            ans=[tx,ty,th]
            break

print(' '.join(map(str, ans)))
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

for j in range(0, n-1, 1):
    if s[j] == "A" and s[j+1] == "C":
        aclist.append(j+1)

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    t_idx = 0
    b_idx = len(aclist)
    search_idx = int(len(aclist) / 2)

    while(b_idx + 1 < t_idx and aclist[search_idx] == l):
        if aclist[search_idx] > l:
            t_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
        elif aclist[search_idx] < l:
            b_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)

    for i in range(search_idx-1, len(aclist), 1):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)


### FIXED CODE ###

# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
  a = x[:i] + x[i+1:]
  a.sort()
  print(a[n//2])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
c = sorted(a)
mid1 = c[n//2-1]
mid2 = c[n//2]
if mid1 == mid2:
  for i in range(n):
    print(mid1)
  exit()
for i in range(n):
  if a[i] <= mid1:
    print(mid2)
  else:
    print(mid1)
N,M = map(int, input().split())

A = []
B = []
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())


for i in range(N-M):
    x = A[i].find(B[0])
    if x != -1:
        result = True
        break
    result = False

for j in range(1,M):
    idx = A[j][x:].find(B[j])
    if idx != x:
        result = False
        break

if result == True:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys
if __name__ == '__main__':

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

    A = []
    B = []
    for i in range(N):
        A.append(input())
    for i in range(M):
        B.append(input())

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                matc = True
                for k in range(M):
                    for l in range(M):
                        if A[i+k][j+l] == B[k][l]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break
                if matc == True:
                    print("Yes")
                    sys.exit(0)

    if matc == True:
        print("Yes")
    else:
        print("No")
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))):
        if N%i == 0:
            lst.append(i)
            
    return lst[-1]
    
def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True
  
if isPrime(N):
    print(N-1)
else:
    ans = divisor(N)
    A = ans
    B = N/ans
    print(int(A+B-2))#
#print(ans)
        

### FIXED CODE ###

# coding: utf-8
# Your code here!
import math
import sys
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if N == 2:
    print(1)
    sys.exit()
    
if len(ans) > 0:
    A = ans[-1]
    if A*A < N:
        B = int(N/A)
        print(A+B-2)
    else:
        print(2*A-2)
else:
    print(N-1)

'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''
N, K = [int(_) for _ in input().split()]
import math
MOD = 1000000000+7

ans = 0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    print( (combinations_count(K-1,i-1)*combinations_count(N-K+1,i))%MOD )



### FIXED CODE ###

N, K = [int(_) for _ in input().split()]
import math
MOD = 10**9+7

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    try:
        print( (combinations_count(K-1,i-1)*combinations_count(N-K+1,i))%MOD )
    except:
        print(0)
class SegTree(object):
  def __init__(self,op,e,n,init_val):
    self.num = 1<<(n-1).bit_length() 
    self.S = [e]*self.num*2
    self.op = op
    self.e = e
    for i,v in enumerate(init_val): self.S[self.num+i] = v
    for i in range(self.num-1,0,-1):
      self.S[i] = self.op(self.S[i*2], self.S[i*2+1])
      
  def set(self,index,value):
    idx = self.num+index
    self.S[idx] = value
    while idx>0:
      self.S[idx>>1] = self.op(self.S[idx],self.S[idx^1])
      idx>>=1
      
  def prod(self,l,r):
    res = self.e
    r += self.num
    l += self.num
    while l<r:
      if l&1:
        res = self.op(res,self.S[l])
        l += 1
      if r&1:
        res = self.op(self.S[r-1],res)
      l >>= 1
      r >>= 1
    return res
        
N,K = map(int,input().split())
ST = SegTree(max,0,300000,[0]*300000)
ans = 1
for i in range(N):
  A = int(input())-1
  v = ST.prod(A-K,A+K+1)+1
  ans = max(ans,v)
  ST.set(A,v)
print(ans)

### FIXED CODE ###

class SegTree(object):
  def __init__(self,op,e,n,init_val):
    self.num = 1<<(n-1).bit_length() 
    self.S = [e]*self.num*2
    self.op = op
    self.e = e
    for i,v in enumerate(init_val): self.S[self.num+i] = v
    for i in range(self.num-1,0,-1):
      self.S[i] = self.op(self.S[i*2], self.S[i*2+1])
      
  def set(self,index,value):
    idx = self.num+index
    self.S[idx] = value
    while idx>0:
      self.S[idx>>1] = self.op(self.S[idx],self.S[idx^1])
      idx>>=1
      
  def prod(self,l,r):
    res = self.e
    l = max(0,l)+self.num
    r = min(r,self.num-1)+self.num
    while l<r:
      if l&1:
        res = self.op(res,self.S[l])
        l += 1
      if r&1:
        res = self.op(self.S[r-1],res)
      l >>= 1
      r >>= 1
    return res
        
N,K = map(int,input().split())
ST = SegTree(max,0,300001,[0]*300001)
ans = 1
for i in range(N):
  A = int(input())
  l,r = max(0,A-K),min(A+K,300000)
  v = ST.prod(l,r+1)+1
  ans = max(ans,v)
  ST.set(A,v)
print(ans)
n = int(input())
a = list(map(int, input().split()))
t = [0] * (n + 1)
#t[i] = a0 + ... + a(i-1)
for i in range(n):
    t[i + 1] = t[i] + a[i]

'''
前処理O(N + log mod)でN以下の階乗および階乗の逆数を計算
-> O(1)でcomb(n, k)を計算できる
'''

mod = 10 ** 9 + 7
dp_F = [0] * (n * 2) 
dp_Finv = [0] * (n * 2)
dp_inv = [0] * (n * 2)
#dp_F[i] = i!

def factorial(n):
    if dp_F[n] > 0:
        return dp_F[n]
    elif n == 0:
        dp_F[0] = 1
        return 1
    else:
        dp_F[n] = n * factorial(n - 1) % mod
        return dp_F[n]

def inverse(n):
    #modでのnの逆数
    return pow(n, mod - 2, mod)

c = factorial(n)
def f(k):
    return ((c * inverse(k)) % mod)

ans = 0
for i in range(1, n):
    ans += t[i] * (f(n - i + 1) - f(i + 1))
    ans %= mod
ans += t[n] * sum([f(i) for i in range(1, n + 1)])
ans %= mod
print(ans)

### FIXED CODE ###

import sys; sys.setrecursionlimit(1000000)

n = int(input())
a = list(map(int, input().split()))
t = [0] * (n + 1)
#t[i] = a0 + ... + a(i-1)
for i in range(n):
    t[i + 1] = t[i] + a[i]

'''
前処理O(N + log mod)でN以下の階乗および階乗の逆数を計算
-> O(1)でcomb(n, k)を計算できる
'''

mod = 10 ** 9 + 7
dp_F = [0] * (n * 2) 
dp_Finv = [0] * (n * 2)
dp_inv = [0] * (n * 2)
#dp_F[i] = i!

def factorial(n):
    if dp_F[n] > 0:
        return dp_F[n]
    elif n == 0:
        dp_F[0] = 1
        return 1
    else:
        dp_F[n] = n * factorial(n - 1) % mod
        return dp_F[n]

def inverse(n):
    #modでのnの逆数
    return pow(n, mod - 2, mod)

c = factorial(n)
def f(k):
    return ((c * inverse(k)) % mod)

ans = 0
for i in range(1, n):
    ans += t[i] * (f(n - i + 1) - f(i + 1))
    ans %= mod
ans += t[n] * sum([f(i) for i in range(1, n + 1)])
ans %= mod
print(ans)
import sys
input = sys.stdin.readline

n,u,v = ( int(x) for x in input().split() )

u,v = u-1,v-1

# -1なら行先なし
a = [[] for i in range(n)]
b = [[] for i in range(n)]

for i in range(n-1):
	# 配列indexは0開始だからinputは-1
	l,m = ( int(x)-1 for x in input().split() )
	a[l].append(m)
	a[m].append(l)

def distance(cr,p,dist): # cr:current node, p:pathed or not, dist:out;each distance
	for i in a[cr]: #a[cr]から行ける各頂点へ
		p[cr] = 1
		if p[i] == 0 or dist[i] > dist[cr]+1: #まだ通っていなかったら
			p[i] = 1
			dist[i] = dist[cr]+1
			distance(i,p,dist)

# 欲しいのはdist of u-v, back way of u
# u視点のdistを調べる
p = [0]*(n)
dist_v = [0]*(n)
distance(v,p,dist_v)
# v視点のdistを調べる
p = [0]*(n)
dist_u = [0]*(n)
distance(u,p,dist_u)

for i in range(n):
	if dist_u[i] >= dist_v[i]:
		dist_u[i] = -1

tmp = max(dist_u)
max_idx = dist_u.index(tmp)

print(dist_v[max_idx] - 1)

### FIXED CODE ###

import sys
input = sys.stdin.readline

# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)

# G:graph, cr:current node, seen:is seen?, dist:out;each distance
def dfs(G,cr,seen,dist):
	seen[cr] = 1
	for i in G[cr]: #G[cr]から行ける各頂点へ
		if seen[i] == 0: #まだ通っていなかったら
			dist[i] = dist[cr]+1
			dfs(G,i,seen,dist)


n,u,v = (int(x) for x in input().split())

u,v = u-1,v-1

a = [[] for i in range(n)]

for i in range(n-1):
	# 配列indexは0開始だからinputは-1
	l,m = (int(x)-1 for x in input().split())
	a[l].append(m)
	a[m].append(l)

# v視点のdistを調べる
dist_u = [0]*n
dist_v = [0]*n

dfs(a,u,[0]*n,dist_u)
# u視点のdistを調べる
dfs(a,v,[0]*n,dist_v)

for i in range(n):
	if dist_u[i] >= dist_v[i]: # vが追いつける距離なら
		dist_v[i] = -1

print(max(dist_v) - 1)
from collections import deque
 
N, M= [int(i) for i in input().split(' ')]
graph = {}
 
for i in range(1,N+1):
  graph[i] = []
 
for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    
 
def bfs(graph, start):
  queue = [start]
  visited1 = []
  visited = {}
  for i in range(1,N+1):
    visited[i] = 0  
  miti = {}
  for i in range(1,N+1):
    miti[i] = 0
  where_from = [start-1]
  while queue:
    label = queue.pop(0)
    label2 = where_from.pop(0)
    if visited[label]==0:
      visited1.append(label)
      visited[label]=1
      if miti[label] != 0:
        return False
      miti[label] = label2
      queue += graph.get(label, [])
      where_from += [label]*len(graph.get(label, []))
    if len(visited1) == N:
      break
  if len(visited1) != N:
    return False
  return miti
 
miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i])
else:
  print('No')

### FIXED CODE ###

N, M= [int(i) for i in input().split(' ')]
graph = {}
 
for i in range(1,N+1):
  graph[i] = []
 
for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    
 
def bfs(graph, start):
  queue = [start]
  miti = [-1 for _ in range(N)]

  while queue:
    label = queue.pop(0)
    for i in graph[label]:
      if miti[i-1] < 0:
        queue.append(i)
        miti[i-1] = label
  return miti
 
miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i-1])
else:
  print('No')
n, x, m = map(int, input().split())
a = x
s = 0
h = []
h.append(a)
i = 0
fl = 0
while i < n:
    s += a
    a = (a*a) % m
    if a == 0:
      break
    i += 1
    if fl == 0 and a in h:
      fl = 1
      po = h.index(a)
      ss = 0
      for j in range(po):
        ss += h[j]
      s2 = s - ss
      f = (n - po) // (i - po)
      s2 *= f
      s = s2 + ss
      i2 = i - po
      i2 *= f
      i = i2 + po
    else:
      h.append(a)
print(s)

### FIXED CODE ###

S = input()
if S[-1] == 's':
    a = S+'es'
else:
    a = S+'s'
print(a)
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
    s = sum(a)
    thresh = s/4/m
    if a[m-1]<thresh:
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

### FIXED CODE ###

n,k = map(int,input().split())
def main():
    m = n%k
    print(min(m,k-m))

if __name__ == "__main__":
    main()
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 木 11/ 9 19:01:14 2017

# Usage
#
"""
from itertools import accumulate

def data_req():
    n_yado, m_ryotei = [int(i) for i in input().split(" ")]
    yado_distance = []
    ryotei = []
    for _ in range(n_yado):
        yado_distance.append(int(input()))
    for _ in range(m_ryotei):
        ryotei.append(int(input()))

    return yado_distance, ryotei


def search(distance, ryotei):
    """search.

    >>> search([2, 1, 1, 3, 2, 1], [2, -1, 3, 2, -3])
    18
    """
    acc = [0] + list(accumulate(distance, lambda x, y: x+y))
    ryotei_index = [0] + list(accumulate(ryotei, lambda x, y: x+y))
    # print(ryotei_index)
    res = []
    for index in enumerate(ryotei_index):
        if index[0] == 0:
            continue
        index = index[0]
        # print(index)
        # print(ryotei_index[index])
        # print(ryotei_index[index - 1])
        dist = abs(acc[ryotei_index[index]] - acc[ryotei_index[index - 1]])
        res.append(dist)
        # print(sum(res))
    # his = []
    #
    # for index in range(len(ryotei_index)):
    #     his.append(acc[ryotei_index[index + 1]] - acc[ryotei_index[index]])
    #
    # return sum(his)
    return sum(res)


if __name__ == '__main__':
    dis, ryotei = data_req()
    search(dis, ryotei)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 木 11/ 9 19:01:14 2017

# Usage
#
"""
from itertools import accumulate

def data_req():
    n_yado, m_ryotei = [int(i) for i in input().split(" ")]
    yado_distance = []
    ryotei = []
    for _ in range(n_yado - 1):
        yado_distance.append(int(input()))
    for _ in range(m_ryotei):
        ryotei.append(int(input()))

    return yado_distance, ryotei


def search(distance, ryotei):
    """search.

    >>> search([2, 1, 1, 3, 2, 1], [2, -1, 3, 2, -3])
    18
    """
    acc = [0] + list(accumulate(distance, lambda x, y: x+y))
    ryotei_index = [0] + list(accumulate(ryotei, lambda x, y: x+y))
    # print(ryotei_index)
    res = []
    for index in enumerate(ryotei_index):
        if index[0] == 0:
            continue
        index = index[0]
        # print(index)
        # print(ryotei_index[index])
        # print(ryotei_index[index - 1])
        dist = abs(acc[ryotei_index[index]] - acc[ryotei_index[index - 1]])
        res.append(dist)
        # print(sum(res))
    # his = []
    #
    # for index in range(len(ryotei_index)):
    #     his.append(acc[ryotei_index[index + 1]] - acc[ryotei_index[index]])
    #
    # return sum(his)
    return sum(res)


if __name__ == '__main__':
    dis, ryotei = data_req()
    print(search(dis, ryotei) % 100000)