Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

from collections import defaultdict

# from typing import Dict, List, Optional, Set, Tuple

# def dfs(vertex: int, succ: Dict[int, List[int]], dp: Dict[int, int]) -> int:
def dfs(vertex, succ, dp):
    if vertex in dp:
        return dp[vertex]
    length = 0
    for s in succ[vertex]:
        length = max(length, 1 + dfs(s, succ, dp))
    dp[vertex] = length
    return length


# def solve(values: List[int], nb_vertices: int, nb_edges: int) -> int:
def solve(values, _nb_vertices, _nb_edges) -> int:
    succ = defaultdict(list)
    for s, d in values:
        succ[s].append(d)
    # all edges have a 0 length path starting at the edge
    dp = defaultdict(lambda: -1)
    for vertex in frozenset(succ.keys()):
        if vertex in dp:
            dp[vertex] = max(dp[vertex], dfs(vertex, succ, dp))
        else:
            dp[vertex] = dfs(vertex, succ, dp)
    return max(dp.values())


def do_job():
    "Do the work"
    # first line is number of test cases
    N, M = map(int, input().split())
    values = []
    for _ in range(M):
        values.append(tuple(map(int, input().split())))
    result = solve(values, N, M)
    print(result)


if __name__ == "__main__":
    do_job()


### FIXED CODE ###

#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import sys
from collections import defaultdict

sys.setrecursionlimit(pow(2, 31) - 1)

# from typing import Dict, List, Optional, Set, Tuple

# def dfs(vertex: int, succ: Dict[int, List[int]], dp: Dict[int, int]) -> int:
def dfs(vertex, succ, dp):
    if vertex in dp:
        return dp[vertex]
    length = 0
    for s in succ[vertex]:
        length = max(length, 1 + dfs(s, succ, dp))
    dp[vertex] = length
    return length


# def solve(values: List[int], nb_vertices: int, nb_edges: int) -> int:
def solve(values, _nb_vertices, _nb_edges) -> int:
    succ = defaultdict(list)
    for s, d in values:
        succ[s].append(d)
    # all edges have a 0 length path starting at the edge
    dp = defaultdict(lambda: -1)
    for vertex in frozenset(succ.keys()):
        if vertex in dp:
            dp[vertex] = max(dp[vertex], dfs(vertex, succ, dp))
        else:
            dp[vertex] = dfs(vertex, succ, dp)
    return max(dp.values())


def do_job():
    "Do the work"
    # first line is number of test cases
    N, M = map(int, input().split())
    values = []
    for _ in range(M):
        values.append(tuple(map(int, input().split())))
    result = solve(values, N, M)
    print(result)


if __name__ == "__main__":
    do_job()
A,B,C = map(int,input().split())
x = C - A + B
if X < 0:X = 0
print(X)

### FIXED CODE ###

A,B,C = map(int,input().split())
X = C - A + B
if X < 0:
    X = 0
print(X)
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

min_diff = 1000000000
for i in range(N-K+1):
    min_diff = min(min_diff, H[i+2] - H[i])

print(min_diff)


### FIXED CODE ###

N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()

min_diff = 1000000000
for i in range(N-K+1):
    min_diff = min(min_diff, H[i+K-1] - H[i])

print(min_diff)
n = int(input())
x = list(map(int, input().split()))

x.sort()

print("Yes" if x[-1] < sum(x[:-1] else "No")

### FIXED CODE ###

import sys

n = int(input())

l = list(map(int, input().split()))

for i in range(n):
    if l[i] >= sum(l) - l[i]:
        print("No")
        sys.exit()

print("Yes")
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
pq = deque(sorted(p + q, reverse=True))
r = deque(sorted([int(x) for x in input().split()]))

ans = sum(pq)

for i in range(len(r)):
    if r[-1] > pq[-1]:
        ans += r.pop() - pq.pop()

print(ans)

### FIXED CODE ###

from collections import deque

X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
pq = deque(sorted(p + q, reverse=True))
r = deque(sorted([int(x) for x in input().split()]))

ans = sum(pq)

for i in range(len(r)):
    if r[-1] > pq[-1]:
        ans += r.pop() - pq.pop()

print(ans)
def common():
   X = raw_input()
   Y = raw_input()
          
   for i in range(0. len(X)+1):
      s[i] = 0
          
   for i in range(0, len(X)):
      t = s + []
      for j in range(0, len(Y)):
         if s[i] == j[i]:
            s[j+1] = t[j] + 1
         elif s[j+1] < s[j]:
            s[j+1] = s[j]
       
   return s[-1]
 
q = input()     
for k in range(0, q):
   common()

### FIXED CODE ###

def common():
   X = raw_input()
   Y = raw_input()
  
   s = [0 for i in range(len(Y)+1)]
 
   for j in range(0, len(X)):
      t = s + []
      for k in range(0, len(Y)):
         if X[j] == Y[k]:
            s[k+1] = t[k] + 1
         elif s[k+1] < s[k]:
            s[k+1] = s[k]
  
   print s[-1]
 
q = input()
for l in range(0, q):
   common()
#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [[] for _ in range(N+1)]

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    for e in graph[edge]:
        if parent[edge] == e:
            continue
        else:
            parent[e] = edge
            counter[e] += counter[edge]
            dfs(graph,counter,e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)


### FIXED CODE ###

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [[] for _ in range(N+1)]

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())

S=set(range(a,m+1))
for i in range(n):
	K,*A=map(int,input().split())
	S&=set(A)
print(len(S))

### FIXED CODE ###

import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())

S=set(range(1,m+1))
for i in range(n):
	K,*A=map(int,input().split())
	S&=set(A)
print(len(S))
N, K = map(int, input().split())
p = list(map(int, input().split()))
 
now = sum(p[:K])
saidai = now
for i in range(K, N):
  now -= p[i-K]
  now += p[i+K]
  if now > saidai:
    saidai = now

print('{:.12f}'.format((saidai + K)/2))

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
 
now = sum(p[:K])
saidai = now
for i in range(K, N):
  now -= p[i-K]
  now += p[i]
  if now > saidai:
    saidai = now
 
print('{:.12f}'.format((saidai + K)/2))
H,W = map(int,input().split())
a = [[x for x in input()] for i in range(H)]
f = True
if H ==1 and W == 1:
    if a[0][0] == "#":
        print("No")
        f = False
if H == 1 and W != 1:
    if a[0][0] == "#":
        if a[0][1] == ".":
            print("No")
            f = False
    if a[0][-1] == "#":
        if a[0][-2] == ".":
            print("No")
            f = False
    for i in range(1,W-1):
        if a[0][i] == "#":
            if a[0][i-1] == "." and a[0][i+1] == ".":
                print("No")
                f = False
                break

if H != 1 and W == 1:
    if a[0][0] == "#":
        if a[1][0] == ".":
            print("No")
            f = False
    if a[-1][0] == "#":
        if a[-2][0] == ".":
            print("No")
            f = False
    for i in range(1,H-1):
        if a[i][0] == "#":
            if a[i-1][0] == "." and a[i+1][0] == ".":
                print("No")
                f = False
                break

if H != 1 and W != 1:
    if a[0][0] == "#":
        if a[0][1] == "." and a[1][0] == ".":
            print("No")
            f = False
    if a[0][-1] == "#":
        if a[0][-2] == "." and a[1][-1] == ".":
            print("No")
            f = False
    if a[-1][0] == "#":
        if a[-1][1] == "." and a[-2][0] == ".":
            print("No")
            f = False
    if a[-1][-1] == "#":
        if a[-1][-2] == "." and a[-2][-1] == ".":
            print("No")
            f = False
    for i in range(1,H-1):
        if a[0][i] == "#":
            if a[0][i-1] == "." and a[0][i+1] == "." and a[1][i] == ".":
                print("No")
                f = False
                break
        if a[-1][i] == "#":
            if a[-1][i-1] == "." and a[-1][i+1] == "." and a[-2][i] == ".":
                print("No")
                f = False
                break
    for i in range(1,W-1):
        if a[i][0] == "#":
            if a[i-1][0] == "." and a[i+1][0] == "." and a[i][1] == ".":
                print("No")
                f = False
                break
        if a[i][-1] == "#":
            if a[i-1][-1] == "." and a[i+1][-1] == "." and a[i][-2] == ".":
                print("No")
                f = False
                break
        if f:
            for i in range(1,H-1):
                for j in range(1,W-1):
                    if a[i][j] == "#":
                        if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                            print("No")
                            f = False
                            break
                            break
    if f:
        print("Yes")

### FIXED CODE ###

H,W = map(int,input().split())
a = [["."]*(W+2)]*(H+1)
f = True
for i in range(H):
    a[i+1] = ["."]
    a[i+1].extend([x for x in input()])
    a[i+1].append(".")
a.append(["."]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if a[i][j] == "#":
            if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                f = False
                break
                break
if f:
    print("Yes")
else:
    print("No")
def gcd(a, b):
    md = a % b
    if md == 0:
        return b
    return gcd(b, md)

def lcm(a, b):
    _gcd = gcd(a, b)
    return int((a * b) / _gcd)

n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    if t >= ans:
        ans = lcm(t, ans)
    else:
        ans = lcm(ans, t)
print(ans)

### FIXED CODE ###

from fractions import gcd
def lcm(a,b): return a*b//gcd(a,b)

n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(t, ans)
print(ans)
N = int(input())
 
ans = 0
 
for i in range(100):
    for j in range(100):
        if (i*4) + (y*7) == N:
            ans = ans+1
            

if ans == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n=int(input())
for i in range(100):
    for j in range(100):
        if 4*i+7*j==n:
            print("Yes")
            exit(0)
print("No")
n=int(input())
S1=input()
S2=input()

mod=1000000007
if n==1:
  print(3)
else:
  if S1[0]==S2[0]:
    ans,i=3,1
  else:
    ans,i=6,2
  while i<n:
    if S1[i]==S2[i]:
      ans *= 2%mod if S1[i-1]==S2[i-1] else 1%mod
      i+=1
    else:
      ans *= 2%mod if S1[i-1]==S2[i-1] else 3%mod
      i+=2
print(ans%(mod))

### FIXED CODE ###

n=int(input())
S1=input()
S2=input()

mod=1000000007
if n==1:
  ans=3
else:
  if S1[0]==S2[0]:
    ans,i=3,1
  else:
    ans,i=6,2
  while i<n:
    if S1[i]==S2[i]:
      ans *= 2%mod if S1[i-1]==S2[i-1] else 1%mod
      i+=1
    else:
      ans *= 2%mod if S1[i-1]==S2[i-1] else 3%mod
      i+=2
print(ans%(mod))
import math
a,b,h,m = map(int , input().split())
long_needle =(5 * m)/60 + h * 5  
sort_needle = m
ans = math.sqrt(a**2 + b **2 - 2*a*b*abs(math.cos(abs(math.pi*(long_needle-sort_needle))/30))
print(ans)


### FIXED CODE ###

import math
a,b,h,m = map(int , input().split())
long_needle =(5 * m)/60 + h * 5  
sort_needle = m
ans = math.sqrt(a**2 + b **2 - 2*a*b*math.cos(abs(math.pi*(long_needle-sort_needle))/30))
print(ans)
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

def find_min_cycle(a):
    memo = {1: 0}
    idx = 0
    cnt = 1

    while a[idx] not in memo:
        memo[a[idx]] = cnt
        cnt += 1
        idx = a[idx]-1

    return memo[a[idx]], cnt-memo[a[idx]], memo

offset, cycle_len, memo = find_min_cycle(a)
rmemo = {v: k for k, v in memo.items()}

if k <= offset:
    print(memo[k])
else:
    i = (k-offset)%cycle_len
    print(rmemo[offset+i])


### FIXED CODE ###

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

def find_min_cycle(a):
    memo = {1: 0}
    idx = 0
    cnt = 1

    while a[idx] not in memo:
        memo[a[idx]] = cnt
        cnt += 1
        idx = a[idx]-1

    return memo[a[idx]], cnt-memo[a[idx]], memo

offset, cycle_len, memo = find_min_cycle(a)
rmemo = {v: k for k, v in memo.items()}

if k <= offset:
    print(rmemo[k])
else:
    i = (k-offset)%cycle_len
    print(rmemo[offset+i])
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def inRange(h: int, w: int, H: int, W: int):
    return h >= 0 and w >= 0 and h < H and w < W


def solve(H: int, W: int, s: "List[str]"):
    for h in range(H):
        for w in range(W):
            cur = s[h][w]
            if cur == "#":
                if inRange(h-1, w, H, W) and s[h-1][w] == "#":
                    continue
                if inRange(h+1, w, H, W) and s[h+1][w] == "#":
                    continue
                if inRange(h, w-1, H, W) and s[h][w-1] == "#":
                    continue
                if inRange(h, w+1, H, W) and s[h][w+1] == "#":
                    continue
                print("No")
                sys.exit(0)
    print("Yes")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def inRange(h: int, w: int, H: int, W: int):
    return h >= 0 and w >= 0 and h < H and w < W


def solve(H: int, W: int, s: "List[str]"):
    failed = False
    for h in range(H):
        for w in range(W):
            cur = s[h][w]
            if cur == "#":
                if inRange(h-1, w, H, W) and s[h-1][w] == "#":
                    continue
                if inRange(h+1, w, H, W) and s[h+1][w] == "#":
                    continue
                if inRange(h, w-1, H, W) and s[h][w-1] == "#":
                    continue
                if inRange(h, w+1, H, W) and s[h][w+1] == "#":
                    continue
                failed = True
                break
        if failed:
            break
    print("No") if failed else print("Yes")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()
a, b, x = list(map(int, input().split()))

ans = 0
for i in range(a, b + 1):
    if i % x == 0:
        ans += 1
        
print(ans)


### FIXED CODE ###

print("A" + list(input().split()[1])[0] + "C")
import math
??
len_a, len_b, deg_C = map(int,input().split(" "))
rad_C = math.radians(deg_C)
??
#area
S = (1/2) * len_a * len_b * math.sin(rad_C)
#Length
L = len_a + len_b + math.sqrt(len_a ** 2 + len_b ** 2 + 1/2 * len_a * len_b * math.cos(rad_C))
#height
h = len_b * math.sin(rad_C)
??
print("{:.5f}".format(S))
print("{:.5f}".format(L))
print("{:.5f}".format(h))

### FIXED CODE ###

import math

len_a, len_b, deg_C = map(int,input().split(" "))
rad_C = math.radians(deg_C)

#area
S = (1/2) * len_a * len_b * math.sin(rad_C)
#Length
L = len_a + len_b + math.sqrt(len_a ** 2 + len_b ** 2 - 2 * len_a * len_b * math.cos(rad_C))
#height
h = len_b * math.sin(rad_C)

print("{:.5f}\n{:.5f}\n{:.5f}".format(S,L,h))
N, Ma, Mb = map(int, input().split())
Med = [tuple(map(int, input().split())) for _ in range(N)]
INF = 100000
from collections import defaultdict as dd
dp =  [dd(lambda:INF) for _ in range(N+1)]#dp[i,j]:Aがiグラム、Bがjグラムの時の最小予算
for n in range(1,N+1):
    a,b,c = Med[n-1]
    dp[n-1][0,0] = 0
    for (i,j),value in dp[n-1].items():
        dp[n][i+a,j+b] = min(dp[n-1][i+a,j+b],value+c)

ans = INF
for (i,j),value in dp[N].items():
    if i == j == 0:
        continue
    if i*Mb == j*Ma:
        ans = min(ans, value)
print(ans if ans != INF else -1)

### FIXED CODE ###

import collections
import copy
INF = 10000

#入力
N, Ma, Mb = map(int, input().split())
medichine = [tuple(map(int, input().split())) for _ in range(N)]

dp = {}
#dp初期化
dp = collections.defaultdict(lambda:INF)
dp[0,0] = 0

for a, b, c in medichine:
    dp_ = copy.copy(dp)
    for ca,cb in dp.keys():
        dp_[ca+a, cb+b] = min(dp_[ca+a, cb+b], dp[ca,cb]+c)
    dp = dp_    

ans = INF
for ca,cb in dp.keys():
    if ca == cb == 0: continue
    if ca*Mb == cb*Ma:
        ans = min(ans, dp[ca,cb])
        
print(-1 if ans == INF else ans)
# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s) + 1, 2):
    ans += s[i]
print(ans)

### FIXED CODE ###

# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s), 2):
    ans += s[i]
print(ans)
W,A,B = map(int,input().split())
if A <= B:
  a=A
  b=b
else:
  a=B
  b=A
print(b-a-W if a+W<b else int(0))

### FIXED CODE ###

W,A,B = map(int,input().split())
if A <= B:
  a=A
  b=B
else:
  a=B
  b=A
print(b-a-W if a+W<b else int(0))
N, K = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]

S.sort(key=lambda x: -x[1])
st = set()
first_acc, other_acc = [0], [0]
for t, d in S:
  if t in st:
    other_acc.append(other_acc[-1] + d)
  else:
    st.add(t)
    first_acc.append(first_acc[-1] + d)

ans = 0
for i in range(K + 1):
  if len(first_acc) <= i or len(other_acc) <= K - i:
    continue
  ans = max(ans, first_acc[i] + other_acc[K - i] + i * i)

print(ans)

### FIXED CODE ###

N, X = map(int, input().split())
a,p=[1],[1]
for i in range(N):
  a.append(a[i] * 2 + 3) 
  p.append(p[i] * 2 + 1)

def f(N,X):
  if N == 0:
    return 0 if X <= 0 else 1 
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1) 
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))
from scipy.special import comb
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += int(comb(cnt,2))
print(ans)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += cnt * (cnt-1) // 2
print(ans)
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................

### FIXED CODE ###

from collections import deque
def bfs():
  d=[[float("inf")]*m for _ in range(n)]
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  
  que=deque([])
  que.append((0,0))
  d[0][0]=0

  while que:
    p = que.popleft()
    if p[0]==n-1 and p[1]==m-1:
      break
    for i in range(4):
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
      if 0 <= nx < n and 0 <= ny < m and c[nx][ny] != "#" and d[nx][ny] == float("inf"):
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
  return d[n-1][m-1]

n, m = map(int, input().split())
c = [list(input()) for i in range(n)]

count=0
for i in range(n):
  for j in range(m):
    if c[i][j]=="#":
      count+=1
g=bfs()
if 0<g<float("inf"):
  print(n*m-g-1-count)
else:
  print(-1)
A = input()
while(A != '-'):
	m = int(input)
	for i in range(m):
		h = int(input())
		A = A[h:]+A[:h]
	print(A)
	A = input()


### FIXED CODE ###

A = input()
while(A != '-'):
	m = int(input())
	for i in range(m):
		h = int(input())
		A = A[h:]+A[:h]
	print(A)
	A = input()
x = input()
print(x**3)


### FIXED CODE ###


x = input()
x = int(x)
print(x**3)
volume = [1,2,4, 8]
value = tuple(map(int, input().split())
N = int(input())

counts = [10**10 for _ in range(N*4 + 1)]
counts[0] = 0

for i in range(4):
    for n in range(volume[i], N*4+1):
        counts[n] = min(counts[n], counts[n-volume[i]] + value[i])

print(counts[-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

volume = [1, 2, 4, 8]
value = {k:v for k, v in zip(volume, inpl())}
cosp = {k:v/k for k, v in value.items()}
N = int(input())
N = N*4
res = 0

for k, _ in sorted(cosp.items(), key=lambda x: x[1]):
    res += (N // k)*value[k]
    N = N % k
print(int(res))
n, m = map(int,input().split())

if n%2 == 1:
    for i in range(m):
        print(n//2-i,n//2+i+1)
else:
    ni = 1
    while ni < n//4 and ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1
    r -= 1
    while ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1


### FIXED CODE ###

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

if n%2 == 1:
    for i in range(m):
        print(n//2-i,n//2+i+1)
else:
    ni = 1
    l = 1
    r = n
    while ni <= n//4 and ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1
    r -= 1
    while ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1
def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid - 1
    return res <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(-1, 1_000_000_000, K))


### FIXED CODE ###

def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 2 * 10 ** 14 + 1
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = map(int, open(0).read().split())
print(binary_search(K))