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

s = input()
n = len(s) + 1
# max of...
#    * num of sequential '<' on the left side
#    * num of sequential '>' on the right side
li = list()
for i in range(n):
    left_str_rev = s[:i][::-1]
    left_num = left_str_rev.find('>')
    left_num = left_num if left_num >= 0 else len(left_str_rev)
    right_str = s[i:]
    right_num = right_str.find('<')
    right_num = right_num if right_num >= 0 else len(right_str)
    if i == 0:
        li.append(right_num)
    elif i == n - 1:
        li.append(left_num)
    else:
        li.append(max([left_num, right_num]))
print(sum(li))

### FIXED CODE ###

def main():
    S = input()
    smaller_cnt = [0]  # <
    seq_cnt = 0
    for c in S:
        if c != '<':
            seq_cnt = 0
        else:
            seq_cnt += 1
        smaller_cnt.append(seq_cnt)
    larger_cnt = [0]  # >
    for c in S[::-1]:
        if c != '>':
            seq_cnt = 0
        else:
            seq_cnt += 1
        larger_cnt.append(seq_cnt)
    larger_cnt.reverse()
    ans = 0
    for x, y in zip(smaller_cnt, larger_cnt):
        ans += max([x, y])
    print(ans)


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

N,M = map(int,input().split(' '))
sections = [list(map(int,input().split(' '))) for _ in range(M) ]

tmp_list = [sections[0]]
for i in range(1,len(sections)):
    for j in range(i):
        if sections[i] < tmp_list[j]:
            tmp_list.insert(j,sections[i])
            break
        if j == i -1:
            tmp_list.append(sections[i])
min_end = 10000000000000000
sorted_list = tmp_list
cnt = 0
for section in sorted_list:
    if min_end <= section[0]:
        cnt += 1
        min_end = min_end = 10000000000000000
    min_end = min(min_end,section[1])
cnt += 1
print(cnt)

### FIXED CODE ###

N,M = map(int,input().split(' '))
sections = [list(map(int,input().split(' '))) for _ in range(M) ]

'''
tmp_list = [sections[0]]
for i in range(1,len(sections)):
    for j in range(i):
        if sections[i] < tmp_list[j]:
            tmp_list.insert(j,sections[i])
            break
        if j == i -1:
            tmp_list.append(sections[i])
'''
min_end = 10000000000000000
sorted_list = sorted(sections)
cnt = 0
for section in sorted_list:
    if min_end <= section[0]:
        cnt += 1
        min_end = min_end = 10000000000000000
    min_end = min(min_end,section[1])
cnt += 1
print(cnt)
### BUGGY CODE ###

N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())
Vmax = max(v)*N+1
Wmax = max(w)*N+1
dp = [[Wmax] * (Vmax) for _ in range(N + 1)]
ans = int(0)
dp[0][0] = int(0)

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

for j in range(Vmax):
    if 0<=dp[N][j]<=W:
        ans = max(ans,j)

print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())
Vmax = max(v)*N+1
Wmax = max(w)*N+1
dp = [[Wmax] * (Vmax) for _ in range(N + 1)]
ans = int(0)
dp[0][0] = int(0)

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

for j in range(Vmax):
    if 0<=dp[N][j]<=W:
        ans = max(ans,j)

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

import numpy as np
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# だいたいpdfの通り
def main():
    l,a,b,md=MI()

    # 数列の要素がk桁になるのがi項目で、k+1桁になるのがj項目
    k=0
    i=0
    cc=np.eye(3,dtype=np.object)
    # 各桁数ごとに処理
    while i<l:
        k+=1
        j=(10**k-a+b-1)//b
        if j==0:continue
        if j>l:j=l
        # k桁の要素の個数がe
        e=j-i
        # i項目まで連結した整数をans[i],数列のi項目をs[i]とすると
        #                                       [10**k 0 0]
        # [ans[i],s[i],b] = [ans[i-1],s[i-1],b] [  1   1 0]
        #                                       [  0   1 1]
        # 最後の3x3行列をbbとして、e乗すればよいので、最小二乗法でやる
        bb=np.zeros((3,3),dtype=np.object)
        bb[0,0]=pow(10,k,md)
        bb[1,0]=bb[1,1]=bb[2,1]=bb[2,2]=1
        while e:
            if e&1:cc=np.dot(cc,bb)%md
            bb=np.dot(bb,bb)%md
            e>>=1
        i=j

    # bbの累乗からできたccを初期値にかけて、答えを出す
    ans=[0,a,b]
    ans=np.array(ans,dtype=np.object)
    ans=np.dot(ans,cc)%md
    print(ans[0])

main()


### FIXED CODE ###

import numpy as np
import sys

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# だいたいpdfの通り
def main():
    l,a,b,md=MI()

    # 数列の要素がk桁になるのがi項目で、k+1桁になるのがj項目
    k=0
    i=0
    ans=[0,a%md,b%md]
    ans=np.array(ans,dtype="i8")
    # 各桁数ごとに処理
    while i<l:
        k+=1
        j=(10**k-a+b-1)//b
        if j<=0:continue
        if j>l:j=l
        # k桁の要素の個数がe
        e=j-i
        # i項目まで連結した整数をans[i],数列のi項目をs[i]とすると
        #                                       [10**k 0 0]
        # [ans[i],s[i],b] = [ans[i-1],s[i-1],b] [  1   1 0]
        #                                       [  0   1 1]
        # 最後の3x3行列をbbとして、e乗すればよいので、繰り返し二乗法でやる
        bb=np.zeros((3,3),dtype="i8")
        bb[0,0]=pow(10,k,md)
        bb[1,0]=bb[1,1]=bb[2,1]=bb[2,2]=1
        while e:
            if e&1:ans=np.dot(ans,bb)%md
            bb=np.dot(bb,bb)%md
            e>>=1
        i=j

    print(ans[0])

main()
### BUGGY CODE ###

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print(p[5] % divisor)


### FIXED CODE ###

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print(p[5] % divisor)
### BUGGY CODE ###

import heapq
import math
n,m = map(int,input().split())
lst = [int(x) * (-1) for x in input().split()]
heapq.heapify(lst)
for use_cnt in range(m):
    num = heapq.heappop(lst) * -1
    nxt_num = math.floor(num / 2)
    heapq.heappush(lst,nxt_num * -1)
    if sum(lst) == 0:
        break
print(sum(lst) * (-1))

### FIXED CODE ###

import heapq
import math
n,m = map(int,input().split())
lst = [int(x) * (-1) for x in input().split()]
heapq.heapify(lst)
for use_cnt in range(m):
    num = heapq.heappop(lst) * -1
    nxt_num = math.floor(num / 2)
    heapq.heappush(lst,nxt_num * -1)
print(sum(lst) * (-1))
### BUGGY CODE ###


a = int(input())
b = list(map(int,input().split()))
c = []

ans = 0    

b = sorted(b, reverse=True)
c.append(b.pop(0))
ans += c[0]
c.append(b.pop(0))
nmax = 0
maxindex = 0
if a > 2:
    ans += c[1]
    c.append(b.pop(0))
    if a > 3:
        for i in range(a - 3):
            nmax = 0
            maxindex = 0
            for j in range(len(c)):
                if j + 1 == len(c):
                    s = min(c[j], c[0])
                else:
                    s = min(c[j], c[j + 1])
                if nmax < s:
                    nmax = s
                    maxindex = j + 1
            ans += nmax
            c.insert(maxindex, b.pop(0))
print(str(ans))

### FIXED CODE ###

a = int(input())
b = list(map(int,input().split()))
ans = 0
c = 0
list.sort(b, reverse=True)
ans += b.pop(0)
b.extend(b)
list.sort(b, reverse=True)

ans += sum(b[0:a-2])
print(str(ans))
### BUGGY CODE ###

from math import gcd

def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)



### FIXED CODE ###

from math import gcd

def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)
### BUGGY CODE ###

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

n, m = list(map(int, readline().split()))
a = sorted(list(map(int, readline().split())))
bc = []
for _ in range(m):
    b, c = list(map(int, readline().split()))
    for _ in range(b):
        bc.append(c)
bc.sort(key=lambda x: -x)
dbc = deque(bc)
for i in range(n):
    if len(dbc) > 0 and a[i] < dbc[0]:
        a[i] = dbc.popleft()

print(sum(a))

### FIXED CODE ###

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

n, m = list(map(int, readline().split()))
a = sorted(list(map(int, readline().split())))
bc = []
for _ in range(m):
    b, c = list(map(int, readline().split()))
    bc.append([b * c, c])
bc.sort(key=lambda x: -x[1])
dbc = deque(bc)
for i in range(n):
    if len(dbc) > 0 and a[i] < dbc[0][1]:
        a[i] = dbc[0][1]
        dbc[0][0] -= dbc[0][1]
        if dbc[0][0] == 0:
            dbc.popleft()

print(sum(a))
### BUGGY CODE ###

S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])

### FIXED CODE ###

S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])
### BUGGY CODE ###

N,M = map(int,input().split())
import numpy as np
A = [i for i in map(int,input().split())]
A = np.array(A)

for i in range(M):
  index = np.argmax(A)
  A[index] //= 2
  
print(np.sum(A))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

S = int(input())
StrS = str(S)
S_Surpus = S % 2019
LenS = len(str(S))
ListSurpus = []


for i in range(LenS):
    Surpus = (int(StrS[i]) * (10 ** (LenS - i - 1) )) % 2019
    ListSurpus.append(Surpus)

#print(ListSurpus)

ans = 0

for i in range(LenS):
    sum = ListSurpus[i]
    for j in range(i+1, LenS):
        sum += ListSurpus[j]
        if(sum % 2019 == 0):
            ans += 1
print(ans)

### FIXED CODE ###

S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

ans = 0
for i in Surpus:
    ans += i * (i - 1) // 2

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

def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    color_list = [-1] * n
    color_num = 0

    for a in a_list:
        # 増分が一番小さいものを選ぶ
        for index, color in enumerate(color_list[:color_num + 1]):
            if color < a:
                color_list[index] = a
                if index == color_num:
                    color_num = color_num + 1
                break
        # color_list[:color_num + 1] = sorted(color_list[:color_num + 1], reverse=True)
        # print(color_list)
    # print()
    # print(color_list)
    print(color_num)

# a1から順番に塗っていく
# 色ごとに、今まで塗った最大値を記録する
# 既存の色でぬれる場合は、なるべく最大値の増分が少なくなるように色を選ぶ
# 既存の色でぬれない場合は新しい色を作って最大値を記録する


### FIXED CODE ###

from bisect import bisect_left


def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    color_list = [-1] * n
    color_num = 0

    for a in a_list:
        # ２分探索
        index = bisect_left(color_list, a)
        # print(index)
        color_list[index - 1] = a
        if n - index == color_num:
            color_num = color_num + 1
        # print(color_list)
    # print()
    # print(color_list)
    print(color_num)

# a1から順番に塗っていく
# 色ごとに、今まで塗った最大値を記録する
# 既存の色でぬれる場合は、なるべく最大値の増分が少なくなるように色を選ぶ
# 既存の色でぬれない場合は新しい色を作って最大値を記録する
### BUGGY CODE ###

k ,s = map(int,input().split())

count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if s == (x+y+z):
                count += 1

print(count)

### FIXED CODE ###

k ,s = map(int,input().split())

count = 0
for x in range(k+1):
    for y in range(k+1):
        if (s - x - y) <= k and 0 <=(s-x-y):
            count+=1
print(count)
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in range(i,N):
        s = S[i:j+1]
        if S[j+1:].find(s) != -1:
            ans = max(ans,len(s))
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for i in range(1,N):
    c = 0
    cc = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cc += 1
        else:
            c = max(cc,c)
            cc = 0
    c = max(cc,c)
    c = min(i,c)
    ans = max(ans,c)
print(ans)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

K = int(input())
if K % 2 == 0:
	print(-1)
	sys.exit()

i = 1
v = 7 % K
while v != 0:
	i += 1
	v = (10 * v + 7) % K
print(i)


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

K = int(input())
i = 1
v = 7 % K
V = {v}
while v != 0:
	i += 1
	v = (10 * v + 7) % K
	if v in V:
		print(-1)
		break
	V.add(v)
else:
	print(i)
### BUGGY CODE ###

# -*- coding: utf-8 -*-


def merge(ns, left, mid, right):
    global count
    infinity = 10 ** 9
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1 + 1)]
    right_ns = [e for e in range(n2 + 1)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right)

n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)
ns = [str(n) for n in ns]

print(" ".join(ns))
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right)


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
A = sum(a)
ans = float("inf")
for i in range(1,N):
    if abs(2*sum(a[:i]) - A) < ans:
        ans = abs(2*sum(a[:i])-A)

print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
A = sum(a)
ans = float("inf")
p = 0
for i in range(N-1):
    p += a[i]
    if abs(2*p - A) < ans:
        ans = abs(2*p-A)

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

import itertools
import bisect
n,K=map(int, input().split(" "))
A=list(map(int, input().split(" ")))

A2=[0]
sum=0
for i in A:
    A2.append(i+sum)
    sum+=i

#print(A2)
A3=[]
for i in range(len(A2)):
    for k in range(len(A2)-i-1):
        A3.append(A2[k+1+i]-A2[i])
A3.sort()
#print(A3)
#print(len(A3))

tmparr=[]
for i in range(50):
    if 2**i-1>A3[-1]:
        break
    tmparr.append(2**i-1)
#print(tmparr)



for i in tmparr[::-1]:
    rem=len(A3)-bisect.bisect_right(A3,i)
    if rem>K:
        A4=A3[-rem:]
        break
#print(A4)

#A5=[]
#for i in A4:
#    A5.append(bin(i))

result=[]
c = list(itertools.combinations(A4,K));
for i in c:
    init=i[0]
    for k in i:
        init = init & k
    result.append(init)
#print(result)
print(max(result))

### FIXED CODE ###

import itertools
import bisect
n,K=map(int, input().split(" "))
A=list(map(int, input().split(" ")))

A2=[0]
sum=0
for i in A:
    A2.append(i+sum)
    sum+=i

#print(A2)
A3=[]
for i in range(len(A2)):
    for k in range(len(A2)-i-1):
        A3.append(A2[k+1+i]-A2[i])
A3.sort()
#print(A3)
#print(len(A3))

tmparr=[]
for i in range(50):
    if 2**i-1>A3[-1]:
        break
    tmparr.append(2**i-1)
#print(tmparr)


"""
for i in tmparr[::-1]:
    rem=len(A3)-bisect.bisect_right(A3,i)
    if rem>K:
        A4=A3[-rem:]
        break
"""
arr=A3
result=0
for i in tmparr[::-1]:
    count=0
    tmparr=[]
    for k in arr:
        if k & i+1 > 0:
            count+=1
            tmparr.append(k)
    if count>=K:
        arr=tmparr
        result+=i+1
print(result)
### BUGGY CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
lst=[1]*(n-k+1)
for i in range(n-k+1):
  if i==0:
    temp=1
    for j in range(k):
      temp*=A[j]
    lst[i]=temp
  else:
    temp=lst[i-1]//A[i-1]
    lst[i]=temp*A[i+k-1]
    print("Yes" if lst[i]>lst[i-1] else "No")

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(1, n-k+1):
    print("Yes" if A[i+k-1]>A[i-1] else "No")
### BUGGY CODE ###

def main():
    n,w = map(int,input().split())
    dp = [[0]*(w+1) for j in range(n+1)] # DPテーブルの作成
    v = []
    W = []
    for i in range(n):
        w_,v_ = map(int,input().split())
        v.append(v_)
        W.append(w_)
    for i in range(n):
        for j in range(w+1):
            if j >= W[i]:
                dp[i+1][j] = max(dp[i][j],dp[i][j-W[i]]+v[i])
            else:
                dp[i+1][j] = dp[i][j]
    print(dp[n][w])
main()

### FIXED CODE ###


import numpy as np
n, W = map(int,input().split())
w = []
v = []
for i in range(n):
    w_,v_= map(int,input().split())
    w.append(w_)
    v.append(v_)
dp = np.zeros(W+1, dtype=np.int64)
for i in range(n):
	dp[w[i]:] = np.maximum(dp[:-w[i]] + v[i], dp[w[i]:])
print(dp[W])
### BUGGY CODE ###

S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]
s = list(S)
s_is_reversed = False
for j in range(Q):
    if Query[j][0] == '1':
        s_is_reversed = not s_is_reversed
    elif Query[j][1] == '1':
        if s_is_reversed == False:
            s.insert(0,Query[j][2])
        else:
            s.append(Query[j][2])
    else:
        if s_is_reversed == False:
            s.append(Query[j][2])
        else:
            s.insert(0,Query[j][2])
if s_is_reversed == True:
    s.reverse()
printed = ''.join(s)
print(printed)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]
s = list(S)
d = deque(s)
d_is_reversed = False
for j in range(Q):
    if Query[j][0] == '1':
        d_is_reversed = not d_is_reversed
    elif Query[j][1] == '1':
        if d_is_reversed == False:
            d.appendleft(Query[j][2])
        else:
            d.append(Query[j][2])
    else:
        if d_is_reversed == False:
            d.append(Query[j][2])
        else:
            d.appendleft(Query[j][2])
if d_is_reversed == True:
    d.reverse()
printed = ''.join(d)
print(printed)
### BUGGY CODE ###

N = int(input())
L = [_ for _ in map(int,input().split())]
res = [L.index(i)+1 for i in range(1,N+1)]
print(' '.join(map(str, res)))

### FIXED CODE ###

N = int(input())
L = [_ for _ in map(int,input().split())]
res = []
for student,people in enumerate(L):
    res.append([people,student])
res.sort()
for s in res:
    print(s[1]+1,end = " ")
### BUGGY CODE ###

N=int(input())
edge=[list(map(int,input().split())) for i in range(N-1)]
INF=10**15
c=[[INF]*N for i in range(N)]
for i,j,w in edge:
    c[i-1][j-1]=w
    c[j-1][i-1]=w
Q,K=map(int, input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
from heapq import heappop,heappush
def dij(c,N,start):
    d=[INF]*N
    d[start]=0
    prev=[-1]*N
    q=[]
    heappush(q,(0,start))
    while len(q)>0:
        u=heappop(q)[1]
        for v in range(N):
            if c[u][v]<INF:
                temp=d[u]+c[u][v]
                if d[v]>temp:
                    d[v]=temp
                    prev[v]=u
                    heappush(q,(d[v],v))
    return d
d=dij(c,N,K-1)
for x,y in xy:
    print(d[x-1]+d[y-1])

### FIXED CODE ###

N=int(input())
edge=[list(map(int,input().split())) for i in range(N-1)]
inf=10**15
c=[[] for i in range(N)]
for i,j,w in edge:
    c[i-1].append((j-1,w))
    c[j-1].append((i-1,w))
Q,K=map(int, input().split())
d=[inf]*N
d[K-1]=0
v=[0]*N
import sys
sys.setrecursionlimit(10**5+9)
def dfs(p,v,d):
    for n,w in c[p]:
        if v[n]==0:
            d[n]=min(d[n],d[p]+w)
            v[n]=1
            dfs(n,v,d)
dfs(K-1,v,d)
xy=[list(map(int,input().split())) for i in range(Q)]
for x,y in xy:
    print(d[x-1]+d[y-1])
### BUGGY CODE ###

H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

from collections import deque

def bfs(ii, jj):
    Q = deque()
    visited = [[False for _ in range(W)] for _ in range(H)]

    Q.append((ii, jj, 0))
    while len(Q) > 0:
        i, j, dist = Q.popleft()
        visited[i][j] = True
        if A[i][j] == "#":
            return dist

        for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W and not visited[ni][nj]:
                Q.append((ni, nj, dist + 1))

ma = 0
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue
        ma = max(ma, bfs(i, j))
print(ma)

### FIXED CODE ###

from collections import deque
H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

Q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            Q.append((i, j, 0))

ans = 0
while Q:
    i, j, dist = Q.popleft()
    ans = max(ans, dist)
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))

print(ans)