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

s = input()
Q = int(input())
S = list("S")
count = 0
for i in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        count += 1
        S = S[::-1]
    else:
        if int(q[1]) == 1:
            S = list(q[2]) + S
        else:
            S = S + list(q[2])

S = "".join(S)
if count%2 == 0:
    print(S.replace("S", s))
else:
    s = s[::-1]
    print(S.replace("S", s))


### FIXED CODE ###

s = input()
Q = int(input())
count = 0
right = []
left = []
for i in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        count += 1
    else:
        if count%2 == 0:
            if int(q[1]) == 1:
                left.append(q[2])
            else:
                right.append(q[2])
        else:
            if int(q[1]) == 1:
                right.append(q[2])
            else:
                left.append(q[2])

left = "".join(left)
right = "".join(right)
if count%2 == 0:
    left = left[::-1]
    print(left+s+right)
else:
    s = s[::-1]
    right = right[::-1]
    print(right+s+left)
### BUGGY CODE ###

# C - Attack Survival
N, K, Q = map(int, input().split())
a = [int(input()) for i in range(Q)]
A = 1 - (K-Q)
# print(N,K,Q,a,A)
for i in range(N):
    if a.count(i+1) >= A:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

# C - Attack Survival
from collections import Counter

N, K, Q = map(int, input().split())
a = [int(input()) for i in range(Q)]
A = Counter(a)
B = 1 - (K-Q)

for i in range(N):
    if A[i+1] >= B:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
b=0
c=s[1]
for j in range(s[0]-s[1]+1):
  a=sum(t[j:j+c])+s[1]
  b=max(b,a)
  a=0
print(b/2)

### FIXED CODE ###

s=list(map(int,input().split()))
t=list(map(int,input().split()))
c=s[1]
d=0
a=sum(t[0:c])
b=0
for j in range(s[0]-s[1]+1):
  if j==0:
    b=sum(t[:c])
    continue
  else:
    a+=(t[j+c-1]-t[j-1])
    b=max(b,a)
b+=s[1]
print(b/2)
### BUGGY CODE ###

import itertools
K, S = [int(i) for i in input().split()]

count = 0
for i in range(0, K+1):
    for j in range(0, K+1):
        for k in range(0, K+1):
            if i+j+k == S:
                count += 1
    
print(count)

### FIXED CODE ###

K, S = [int(i) for i in input().split()]

count = 0
for i in range(0, K+1):
    for j in range(0, K+1):
        k = S - i -j
        if 0 <= k <= K:
            count += 1
print(count)
### BUGGY CODE ###

a,b,n=map(int,input().split())
'''
lst=[]
for i in range(n+1):
    now=int(a*i/b)-a*int(i/b)
    lst.append(now)
print(max(lst))
'''
now=0
if n>=b:
    if n//b>=500000:
        ans=int(a*(n-1)/b)-a*int((n-1)/b)
        ans2=int(a*n/b)-a*int(n/b)
        for i in range(0,n//b+1,1000):
            ans3=int(a*(i*b-1)/b)-a*int((i*b-1)/b)
            now=max(now,ans3)
        print(max(ans,ans2,now))
        exit()
    ans=int(a*(n-1)/b)-a*int((n-1)/b)
    ans2=int(a*n/b)-a*int(n/b)
    for i in range(n//b+1):
        ans3=int(a*(i*b-1)/b)-a*int((i*b-1)/b)
        now=max(now,ans3)
    print(max(ans,ans2,now))

else:
    ans=int(a*(n)/b)-a*int((n)/b)
    print(max(ans,0))

### FIXED CODE ###

a,b,n=map(int,input().split())
def ans(x):
    return int(a*x/b)
print(ans(min(n,b-1)))
### BUGGY CODE ###

import collections
n = int(input())
a = input()
a = a.replace('R','1')
a = a.replace('G','2')
a = a.replace('B','3')
a = tuple(map(int,list(a)))
b = collections.Counter(a)
ans =b[3]*b[1]*b[2]
for i in range(n-2):
    for j in range(i+1,n-1):
        if a[i] == a[j]:
            continue
        c = j*2 -i
        if c < n:
            if sum([a[i],a[j],a[c]])==6:
                ans -= 1
print(ans)

### FIXED CODE ###

import collections
n = int(input())
a = input()
a = a.replace('R','1')
a = a.replace('G','2')
a = a.replace('B','3')
a = tuple(map(int,list(a)))
b = collections.Counter(a)
ans =b[3]*b[1]*b[2]
for i in range(n-2):
    for j in range(i+1,n):
        if a[i] == a[j]:
            continue
        c = j*2 -i
        if c < n:
            if a[i]+a[j]+a[c]==6:
                ans -= 1
        else:
            break
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
P=10**9+7
ans=0
BIN=[0]*N
for h in range(N):
    BIN[h]=bin(A[h])[2:].zfill(60)

for i in range(N-1):
    for j in range(i+1,N):
        ans+=A[i]^A[j]
print(ans%P)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
P=10**9+7
ans=0
BIN=[0]*N
for h in range(N):
    BIN[h]=bin(A[h])[2:].zfill(60)

for i in range(60):
    inc=0
    one=0
    zero=0
    for j in range(N):
        if BIN[j][59-i]=="0":
            zero+=1
        else:
            one+=1
    ans+=zero*one*2**i
print(ans%P)
### BUGGY CODE ###

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

# A_index[i] = ( value of A , index of A)
A_index = [ (A_list[i], i) for i in range(len(A_list)) ]
A_index.sort(reverse=True)


# dp[left][right] = score
dp = [ [0]*(N+1) for _ in range(N+1) ]


for L in range(N):
    for R in range(N-L):
        i = L + R
        dp[L+1][R] = max(dp[L+1][R], dp[L][R] + A_index[i][0] * abs(L - A_index[i][1]))
        dp[L][R+1] = max(dp[L][R+1], dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1]))


ans = max( [ dp[i][N-i] for i in range(N+1)] )
print(ans)


### FIXED CODE ###

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

# A_index[i] = ( value of A , index of A)
A_index = [ (A_list[i], i) for i in range(len(A_list)) ]
A_index.sort(reverse=True)


# dp[left][right] = score
dp = [ [0]*(N+1) for _ in range(N+1) ]


for L in range(N):
    for R in range(N-L):
        i = L + R
        append_L = dp[L][R] + A_index[i][0] * abs(L - A_index[i][1])
        append_R = dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1])
        
        dp[L+1][R] = max(dp[L+1][R], append_L)
        dp[L][R+1] = max(dp[L][R+1], append_R)


ans = max( [ dp[i][N-i] for i in range(N+1)] )
print(ans)
### BUGGY CODE ###

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

sm = 0
for i in range(0, n):
    sm = sm + a[i]

min_dif = sm

p = 0
for i in range(n-3):
    p = p + a[i]
    if 4*p < sm:
        next
    q = 0
    for j in range(i+1, n-2):
        q = q + a[j]
        if 3*q < sm - p:
            next
        r = 0
        for k in range(j+1, n-1):
            r = r + a[k]
            if 2*r < sm - p - q:
                next
            s = 0
            for l in range(k+1, n):
                s = s + a[l]
            d = max([p, q, r, s])-min([p, q, r, s])
            min_dif = min([d, min_dif])

p = 0
for i in range(n-3):
    p = p + a[i]
    if 4*p <= sm - 3*min_dif or 4*p >= sm + 3*min_dif:
        next
    q = 0
    for j in range(i+1, n-2):
        q = q + a[j]
        if 4*q <= sm - 3*min_dif or 4*q >= sm + 3*min_dif:
            next
        r = 0
        for k in range(j+1, n-1):
            r = r + a[k]
            if 4*r <= sm - 3*min_dif or 4*r >= sm + 3*min_dif:
                next
            s = 0
            for l in range(k+1, n):
                s = s + a[l]
            d = max([p, q, r, s])-min([p, q, r, s])
            min_dif = min([d, min_dif])

print(min_dif)


### FIXED CODE ###

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

t = list(0 for i in range(n+1))
for i in range(1, n+1):
    t[i] = t[i-1] + a[i-1]

def sum_a(i, j):
    return t[j]-t[i]

min_dif = sum_a(0, n)

i = 0
k = 2
for j in range(2, n-1):
    u = sum_a(0, j) // 2
    while sum_a(0, i) < u:
        i = i + 1
    if abs(sum_a(0, i-1)-sum_a(i-1, j)) < abs(sum_a(0, i) - sum_a(i, j)): 
        i = i - 1
    p = sum_a(0, i)
    q = sum_a(i, j)

    u = sum_a(j, n) // 2
    while sum_a(j, k) < u:
        k = k + 1
    if abs(sum_a(j, k-1)-sum_a(k-1, n)) < abs(sum_a(j, k) - sum_a(k, n)): 
        k = k - 1
    r = sum_a(j, k)
    s = sum_a(k, n)

    min_dif = min(min_dif, max(p, q, r, s)-min(p, q, r, s))

print(min_dif)
### BUGGY CODE ###

def main():
    A,B,K = map(int,input().split())
    while K > 0:
        if A >= 1:
            A -= 1
        elif B >= 1:
            B -= 1
        K -= 1
    print("{} {}".format(A,B))
main()

### FIXED CODE ###

def main():
    a,b,k = map(int,input().split())
    if a >= k:
        a-=k
    else:
        b -= (k - a)
        a = 0
        if b < 0:
            b = 0
    print(str(a)+" "+str(b))
main()
### BUGGY CODE ###

h,w = map(int,input().split())
s = [[(l == '.')*1 for l in list(input())] for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if i == 0:
      U[i][j] = s[i][j]
      D[h-i-1][j] = s[h-i-1][j]
    else:
      U[i][j] = (U[i-1][j]+1)*s[i][j]
      D[h-i-1][j] = (D[h-i][j]+1)*s[h-i-1][j]
    if j == 0:
      L[i][j] = s[i][j]
      R[i][w-j-1] = s[i][w-j-1]
    else:
      L[i][j] = (L[i][j-1]+1)*s[i][j]
      R[i][w-j-1] = (R[i][w-j]+1)*s[i][w-j-1]
for i in range(h):
  for j in range(w):
    m = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if ans < m:
      ans = m
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
s = [[(l == '.')*1 for l in list(input())] for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if i == 0:
      U[i][j] = s[i][j]
      D[h-i-1][j] = s[h-i-1][j]
    else:
      U[i][j] = (U[i-1][j]+1)*s[i][j]
      D[h-i-1][j] = (D[h-i][j]+1)*s[h-i-1][j]
    if j == 0:
      L[i][j] = s[i][j]
      R[i][w-j-1] = s[i][w-j-1]
    else:
      L[i][j] = (L[i][j-1]+1)*s[i][j]
      R[i][w-j-1] = (R[i][w-j]+1)*s[i][w-j-1]
for i in range(h):
  for j in range(w):
    m = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if ans < m:
      ans = m
print(ans)
### BUGGY CODE ###

h, w, m = map(int, input().split())
bord_x, bord_y = [0 for i in range(h)], [0 for i in range(w)]
bord = [[] for _i in range(h)]

for _i in range(m):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    bord_x[s] += 1
    bord_y[t] += 1
    bord[s].append(t)

x_max, y_max = max(bord_x), max(bord_y)
a = [x for x, p in enumerate(bord_x) if x_max==p]
b = [y for y, p in enumerate(bord_y) if y_max==p]

checker = 0
for i in a:
    for j in b:
        if not(j in bord[i]):
            import sys
            print(x_max+y_max)
            sys.exit()
        else:
            checker += 1
        if checker >= m:
            break

print(x_max+y_max-1)

### FIXED CODE ###

h, w, m = map(int, input().split())
bord_x, bord_y = [0]*h, [0]*w
 
hw = []
for _i in range(m):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    bord_x[s] += 1
    bord_y[t] += 1
    hw.append([s, t])
 
x_max, y_max = max(bord_x), max(bord_y)
 
cnt = 0
for i, j in hw:
    if bord_x[i] == x_max and bord_y[j] == y_max:
        cnt += 1
 
if cnt == bord_x.count(x_max)*bord_y.count(y_max):
    x_max -= 1
 
print(x_max+y_max)
### BUGGY CODE ###

from collections import Counter
n=int(input())
l=[]
for i in range(n):
    s=input()
    l.append(Counter(s))
ans=0
dfs=[1]*n
for i in range(n):
    if dfs[i]!=0:
        a=1
        for j in range(i+1,n):
            if dfs[j]!=0 and l[i]==l[j]:
                dfs[j]=0
                a+=1
        ans+=max(0,a*(a-1)//2)
print(ans)


### FIXED CODE ###

from collections import Counter
n=int(input())
l={}
ans=0
for i in range(n):
  s=input()
  ss=sorted(s)
  s="".join(ss)
  ans+=l.setdefault(s, 0) 
  l[s]+=1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
lst = [[] for _ in range(q)]
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    for i in range(l,r):
        lst[i].append(x)
for i in lst:
    if len(i) == 0:
        print(-1)
    else:
        print(i[0])

### FIXED CODE ###

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*(q+1)
right = [0]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    #各dにおいて一番最初にぶつかるxを求めたい
    while l < r:
        while ans[l] != -1:
            l = right[l]
        if r <= l:
            break
        ans[l] = x
        right[l] = r
        l += 1
for i in ans[:-1]:
    print(i)
### BUGGY CODE ###

N=int(input())
S=input()
R=0
G=0
B=0
for i in range(N):
    s=S[i]
    if s=="R":
        R+=1
    elif s=="G":
        G+=1
    else:
        B+=1
ans=R*G*B
for i in range(N-2):
    for j in range(i+1, N-1):
        if 0<=j+j-i<N:
            si=S[i]
            sj=S[j]
            sk=S[2*j-i]
            if si!=sj and sj!=sk and sk!=si:
                ans-=1
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
count=0
R=0
G=0
B=0
for i in range(N):
  if S[i]=="R":
    R+=1
  if S[i]=="G":
    G+=1
  if S[i]=="B":
    B+=1
count=0
for i in range(N-2):
  for j in range(i,N-1):
    k=j+j-i
    try:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
        count+=1
    except:
      pass
    
print(R*G*B-count)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def main():
    n, k = map(int, stdin.readline().split())
    p = list(map(int, stdin.readline().split()))

    sp = [0] * 1001

    for i in range(1, 1001):
        sp[i] = sum(range(i + 1)) / i

    max = 0
    max_index = 0

    for i in range(n - k + 1):
        tmp = sum(p[i: i + k])
        if tmp > max:
            max = tmp
            max_index = i

    ans = 0
    for i in range(max_index, max_index + k):
        ans += sp[p[i]]

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    n, k = map(int, stdin.readline().split())
    p = list(map(int, stdin.readline().split()))

    sp = [0] * 1001

    for i in range(1, 1001):
        sp[i] = sum(range(i + 1)) / i

    summary = [0] * n
    summary[0] = sp[p[0]]
    for i in range(1, n):
        summary[i] = summary[i - 1] + sp[p[i]]

    max = summary[k - 1]
    for i in range(k, n):
        tmp = summary[i] - summary[i - k]
        if tmp > max:
            max = tmp
    print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
### BUGGY CODE ###

n=int(input())
s=[]
ans=set()
for _ in range(n):
    s.append(str(input()))
count=[0]*len(set(s))
for i in range(len(set(s))):
    count[i]+=s.count(list(set(s))[i])
for k in range(len(set(s))):
    if max(count)==count[k]:
        ans.add(list(set(s))[k])
for l in range(len(ans)):
    print(sorted(ans)[l])

### FIXED CODE ###

import collections
n=int(input())
s=[]
for _ in range(n):
    s.append(str(input()))
ans=collections.Counter(s)
a=max(ans.values())
ans=[i for i,k in ans.items() if a==k]
print(*sorted(ans),sep="\n")
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
    return ord(c)-97
class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans))

def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
    n=int(input())
    S=list(input())
    q=int(input())
    set_s={chr(ord('a')+i):[] for i in range(26)}
    for i,s in enumerate(S):
        set_s[s].append(i)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            i,c=int(query[1])-1,query[2]
            if S[i]==c:continue
            set_s[S[i]].remove(i)
            set_s[c].insert(bisect_left(set_s[c],i),i)
            S[i]=c
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for i in range(26):
                ss=chr(ord('a')+i)
                if bisect(set_s[ss],r)>bisect_left(set_s[ss],l):
                    ans+=1
            print(ans)


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

from heapq import *
n,Q = list(map(int, input().split()))
Y=[]
for j in range(n):
    a=list(map(int, input().split()))
    Y.append([a[0]-a[2],a[1]-a[2],a[2]])
q = [int(input()) for i in range(Q)]
Y.sort()
X=[]
p=0
for d in q:
    while p<n and Y[p][0]<=d:
        heappush(X,(Y[p][2],Y[p][1]))
        p+=1
    while X and X[0][1] <= d:
        heappop(X)
    if X:
        print(X[0][0])
    else:
        print(-1)

### FIXED CODE ###

import sys
from heapq import *
input = sys.stdin.readline

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

stx=[[0]*3 for _ in range(n)]
for j in range(n):
    a = [int(i) for i in input().split()]
    stx[j]=[a[0]-a[2],a[1]-a[2],a[2]]
q = [int(input()) for i in range(Q)]
stx.sort()

xt=[]
pt=0
for d in q:
    while pt < n and stx[pt][0] <= d:
        heappush(xt,(stx[pt][2],stx[pt][1]))
        pt+=1
    while xt and xt[0][1] <= d:
        heappop(xt)
    if xt:
        print(xt[0][0])
    else:
        print(-1)
### BUGGY CODE ###

s = input()

count = 0
while True:
    s0 = s
    if s.count("10") != 0:
        count += 2 * s.count("10")
        s = s.replace("10","")
        #print(s)
    elif s.count("01") != 0:
        count += 2 * s.count("01")
        s = s.replace("01","")
        #print(s)
    if s0 == s:
        break

#print(s)
print(count)


"""
s = input()

count = 0
while True:
    s0 = s
    s = s.replace("10","",1)
    if s0 != s:
        count += 2
        #print(s)
    else:
        s1 = s
        s = s.replace("01","",1)
        if s1 != s:
            count += 2
            #print(s)
        else:
            break

#print(s)
print(count)
"""

### FIXED CODE ###

s = input()

s0 = s.count("0")
s1 = s.count("1")
#print(s0)
#print(s1)
print(len(s)-(max(s0,s1)-min(s0,s1)))
### BUGGY CODE ###

n = int(input())
i = 1

while True:
    x = i
    if  x % 3 == 0:
        print(" %d" ,i)
        i+=1
        if i > n:
            print()
            break
    if x % 10 == 3:
        print(" %d" ,i)
        i+=1
        if i > n:
            print()
            break
    else:
        x /= 10
        if x != 0:
            continue


### FIXED CODE ###

#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


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

import math
from functools import reduce
import copy
import fractions
N = int(input())
A = list(map(int,input().split()))

def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
ans = 0
count = 0
for i in range(N):
    B = copy.copy(A)
    a = B.pop(i)
    gcd_a = gcd_list(B)
    ans = max(ans,gcd_a)

print(ans)

### FIXED CODE ###

import fractions
N=int(input())
A=list(map(int,input().split()))

def gcd(x,y):
    if x==0:
        return y
    else:
        return gcd(y%x,x)

L=[0 for _ in range(N+1)]
L[0]=0
for i in range(N):
    L[i+1]=gcd(L[i],A[i])

R=[0 for i in range(N+1)]
R[N-1]=A[N-1]
for i in range(1,N)[::-1]:
    R[i-1]=gcd(R[i],A[i-1])

ans=0
for i in range(N):
    ans=max(ans,gcd(L[i],R[i+1]))
print(ans)
### BUGGY CODE ###

N=int(input())
A=[int(i) for i in input().split()]
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]
for i in B:
    while i[0] in A:
        A[A.index(i[0])]=i[1]
    print(sum(A))

### FIXED CODE ###

from collections import Counter
N=int(input())
A=[int(i) for i in input().split()]
Q=int(input())
K=Counter(A)
S=sum(A)
for i in range(Q):
    B,C=map(int,input().split())
    if C in K:
        K[C]+=K[B]
    else:
        K[C]=K[B]
    S+=((C-B)*K[B])
    print(S)
    K[B]=0
### BUGGY CODE ###

import queue as qu
import numpy as np
import functools as ft

words = lambda t : np.array(list(map(t, input().split())))

h,w = words(int)
mat = []
for _ in range(h):
    a = list(map(lambda x: x == "#", list(input())))
    mat.append(a)

mat = np.array(mat)
#print(mat)

prev = []
for i in range(h):
    for j in range(w):
        if mat[i][j]:
            prev.append((i,j))

def putL(l, x, y):
    if x != 0 and mat[x-1][y]:
        l.append((x-1,y))
        mat[x-1][y] = True
    if y != 0 and mat[x][y-1]:
        l.append((x,y-1))
        mat[x][y-1] = True
    if x != h-1 and mat[x+1][y]:
        l.append((x+1,y))
        mat[x+1][y] = True
    if y != w-1 and mat[x][y+1]:
        l.append((x,y+1))
        mat[x][y+1] = True
    return l

round = -1
while not len(prev) ==  0:
    #print(prev)
    #print(mat)
    round += 1
    next = []
    for (x,y) in prev:
        if x != 0 and not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if y != 0 and not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if x != h-1 and not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if y != w-1 and not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
    prev = next

print(round)


### FIXED CODE ###

import functools as ft

h,w = map(int, input().split())
mat = [[True] * (w+2)]
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True]*(w+2))

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))



round = -1
while prev:
    round += 1
    #print(prev)
    #print(mat)
    def calc(next, tup):
        x = tup[0]
        y = tup[1]
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
        return next
    next = ft.reduce(calc, prev, [])

    prev = next

print(round)