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

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

ans = S
for l in L:
    if len(l) == 1:
        ans = ''.join(list(reversed(ans)))
    elif l[1] == '1':
        ans = l[2] + ans
    else:
        ans = ans + l[2]
print(ans)

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)
### BUGGY CODE ###

def numS(S):
    if len(S)<4:
        return 0
    T=S[1:]
   # print(T)
    sum=0
    now=S[0]
    for i in range(len(T)):
        now2=T[i]
    #    print(now2)
        if now2!=now:
            for j in range(i+1,len(T)):
                now3=T[j]
     #           print(now,now2,now3)
                if now3!=now2 and now3!=now:
      #              print(i,j)
                    sum+=1
                    if 2*i+1==j:
                        sum-=1
    return numS(T)+sum
n=int(input())
S=input()
print(numS(S))

### FIXED CODE ###

n=int(input())
S=input()
R={}
G={}
B={}
r=0
g=0
b=0
for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None
cnt=len(R)*len(G)*len(B)
for b in B:
    for g in G:
        if (b+g)/2 in R:
            cnt-=1
for b in B:
    for r in R:
        if (b+r)/2 in G:
            cnt-=1
for r in R:
    for g in G:
        if (r+g)/2 in B:
            cnt-=1
print(cnt)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,-1,-1):
  x=0
  s=2**i
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,-1,-1):
  x=0
  s=2**i
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500*500)

class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

    def root(self, x):
        if self.par[x] < 0:
            return x
        return self.root(self.par[x])

    def unite(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.root(x)]

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

q = deque()
s = set()
ans = 0
for i in range(1, n+1):
    if i not in s:
        q.append(i)
        s.add(i)
        tmp = [i]
        while q:
            v = q.popleft()
            for ti in t[v]:
                if ti not in s:
                    tmp.append(ti)
                    q.append(ti)
                    s.add(ti)
    ans = max(ans, len(tmp))
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
    if 0 in a:
        print('0')
        exit()
    elif ans > 10**18:
        print('-1')
        exit()
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print('0')
    exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print('-1')
        exit()
print(ans)
### BUGGY CODE ###

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

def search_tree(trees, n):
    while type(trees[n]) == int:
        n = trees[n]
    return trees[n], n

all_ptn = N * (N-1) // 2
ans = [all_ptn]
trees = [{i} for i in range(N)]
for i in range(M-1, 0, -1):
    tree1, num1 = search_tree(trees, bridges[i][0]-1)
    tree2, num2 = search_tree(trees, bridges[i][1]-1)
    if tree1 != tree2:
        tmp = tree1.union(tree2)
        trees[num1] = tmp
        trees[num2] = num1
        ans.append(ans[-1] - len(tree1) * len(tree2))
        
    else:
        ans.append(ans[-1])
for i in range(M-1, -1, -1):
    print(ans[i])

### FIXED CODE ###

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

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
        self.rank = [0] * n
        
    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx == ry:
            return
        elif self.rank[rx] > self.rank[ry]:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
            
        else:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            if self.rank[rx] == self.rank[ry]:
                self.rank[ry] += 1
                
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

all_ptn = N * (N-1) // 2
ans = [all_ptn]
uf = UnionFind(N)
for i in range(M-1, 0, -1):
    x = bridges[i][0] - 1
    y = bridges[i][1] - 1
    if uf.same(x, y):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.count(x) * uf.count(y))
        uf.unite(x, y)
        
for i in range(M-1, -1, -1):
    print(ans[i])
### BUGGY CODE ###

N, W = map(int, input().split())
V = 10**5
INF = 10**18
dp = [INF]*(V+1)

dp[0] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(V, v-1, -1):
        if dp[j-v] + w <= W:
            dp[j] = min(dp[j], dp[j-v] + w)
for i in range(V, -1, -1):
    if dp[i] < INF:
        print(i)
        break

### FIXED CODE ###

N, W = map(int, input().split())
V = 10**5
INF = 10**18
dp = [INF]*(V+1)

dp[0] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(V, v-1, -1):
        if dp[j-v] + w <= W:
            dp[j] = min(dp[j], dp[j-v] + w)
for i in range(V, -1, -1):
    if dp[i] < INF:
        print(i)
        break
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for _ in range(q):
    l,r=map(int,input().split())
    t=s[l-1:r]
    c=0
    for a,b in zip(t,t[1:]):
        if a=='A' and b=='C':
            c+=1
    print(c)


### FIXED CODE ###

N, Q=map(int, input().split())
S = input()
t = [0]*(N + 1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False] * (K+1)

for i in range(K+1):
    for j in range(N):
        if i - A[j] >= 0 :
            dp[i] = dp[i] | (not dp[i-A[j]])

if dp[K]:
    print('First')
else:
    print('Second')


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False] * (K+1)

for i in range(K+1):
    for j in range(N):
        if i - A[j] >= 0 :
            dp[i] = dp[i] | (not dp[i-A[j]])

if dp[K]:
    print('First')
else:
    print('Second')
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    print(str(a.index(i+1)+1) + " ",end="")

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ls = [0]*n
j = 0
for i in a:
    ls[i-1] = j
    j += 1
for i in ls:
    print(str(i+1) + " ",end="")
### BUGGY CODE ###

# Not using k-d tree.

import sys
 
i_f = sys.stdin
 
n = int(i_f.readline())

Px = []
Py = []
for i in range(n):
    x, y = map(int, i_f.readline().split())
    Px.append([x, y, i])
    Py.append([y, x, i])

Px.sort()
Py.sort()

q = int(i_f.readline())

A = []

import bisect

for l in i_f:
    a = []
    
    sx, tx, sy, ty = map(int, l.split())
    
    x_low = bisect.bisect_left(Px, [sx, sy, 0])
    x_high = bisect.bisect_right(Px, [tx, ty, n], lo=x_low)
    y_low = bisect.bisect_left(Py, [sy, sx, 0])
    y_high = bisect.bisect_left(Py, [ty, tx, n], lo=y_low)
    
    x_width = x_high - x_low
    y_width = y_high - y_low

    if x_width < y_width:
        for p in Px[x_low:x_high]:
            if sy <= p[1] <= ty:
                a.append(p[2])
    else:
        for p in Py[y_low:y_high]:
            if sx <= p[1] <= tx:
                a.append(p[2])

    a.sort()
    if a:
        A.extend(a)
    A.append('')

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

### FIXED CODE ###

import sys, math
from operator import itemgetter
from bisect import bisect_left, bisect_right

f_i = sys.stdin

def main():
    n = int(f_i.readline())
    
    lx = []
    ly = []
    li = []
    for i in range(n):
        x, y = map(int, f_i.readline().split())
        lx.append(x)
        ly.append(y)
        li.append(i)

    x_width = max(lx) - min(lx)
    y_width = max(ly) - min(ly)
    if x_width > y_width:
        P = list(zip(lx, ly, li))
    else:
        P = list(zip(ly, lx, li))
    P.sort()

    interval = int(math.sqrt(n))

    low = [v1 for v1, v2, i in P[::interval]]
    high = [v1 for v1, v2, i in P[interval - 1::interval]] + [float('inf')]

    S = []
    v2_sec_list = []
    for i in range(0, n, interval):
        si = P[i:i + interval]
        si.sort(key=itemgetter(1))
        v2_s = [p[1] for p in si]
        v2_sec_list.append(v2_s)
        S.append(si)

    A = []

    q = f_i.readline()

    for l in f_i:
        sx, tx, sy, ty = map(int, l.split())
        a = []
        if x_width > y_width:
            for i in range(bisect_left(high, sx), bisect_right(low, tx)):
                v = S[i]
                k = v2_sec_list[i]
                for j in range(bisect_left(k, sy), bisect_right(k, ty)):
                    if sx <= v[j][0] <= tx:
                        a.append(v[j][2])
        else:
            for i in range(bisect_left(high, sy), bisect_right(low, ty)):
                v = S[i]
                k = v2_sec_list[i]
                for j in range(bisect_left(k, sx), bisect_right(k, tx)):
                    if sy <= v[j][0] <= ty:
                        a.append(v[j][2])
        
        if a:
            a.sort()
            A.extend(a)
        A.append('')

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

main()
### BUGGY CODE ###

q = int(input())
like2017 = []

# def is_prime(x):
#     if x==2:
#         return True
#     elif x%2==0:
#         return False

#     for i in range(3, x, 2):
#         if x!=i and x%i==0:
#             return False
#     return True

def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q&1 == 0:
        return False
    return pow(2, q-1, q) == 1

for i in range(1, 10001, 2):
    if i>2 and is_prime(i) and is_prime(int((i+1)/2)):
        like2017.append(1)
    else:
        like2017.append(0)

for i in range(q):
    l, r = map(int, input().split())
    print(sum(like2017[:int((r+1)/2)])-sum(like2017[:int((l-1)/2)]))


### FIXED CODE ###

import numpy as np
n=123456
q = int(input())
 
is_prime = np.ones(n+1,dtype=int)
is_prime[0]=0
is_prime[1]=0
 
for i in range(2,n+1):
    if(is_prime[i]==1):
        j=i+i
        while j <= n:
            is_prime[j] = 0
            j += i
 
cnt = [is_prime[x]*is_prime[(x+1)//2] for x in range(0,n+1)]
 
for i in range(1,n+1):
    cnt[i]+=cnt[i-1]
 
for i in range(q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)


## input
N,Q = map(int, input().split())
cnt = [0 for _ in range(N)]
route = defaultdict(lambda:set([]))
for _ in range(N-1):
  a,b = map(int, input().split())
  route[a-1].add(b-1)
  route[b-1].add(a-1)
for _ in range(Q):
  p,x = map(int, input().split())
  cnt[p-1] += x

## solve
def dfs(p,q):
  for r in route[q]:
    if p != r:
      cnt[r] += cnt[q]
      dfs(q,r)

dfs(-1,0)
print(" ".join([str(c) for c in cnt]))

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict,deque


## input
N,Q = map(int, input().split())
cnt = [0 for _ in range(N)]
route = defaultdict(lambda:set([]))
for _ in range(N-1):
  a,b = map(int, input().split())
  route[a-1].add(b-1)
  route[b-1].add(a-1)
for _ in range(Q):
  p,x = map(int, input().split())
  cnt[p-1] += x

## solve
stk = deque([0])
cost = [-1 for _ in range(N)]
cost[0] = cnt[0]
while len(stk) > 0:
  p = stk.pop()
  for q in route[p]:
    if cost[q] >= 0:
      continue
    cost[q] = cost[p] + cnt[q]
    stk.append(q)

print(*cost)
### BUGGY CODE ###

N = input()
a = []
for i in range(N):
        a.append(input())
B = max(a)
for i in range(N):
        if B == max(a):
                b = a.pop(i)
                print(max(a))
                a.insert(i,b)
        else:
                print(B)

### FIXED CODE ###

N = input()
a = []
for i in range(N):
        a.append(input())
b = sorted(a)
b0,b1 = b[-1],b[-2]
for i in range(N):
        if a[i]!=b0 :
                print(b0)
        else:
                print(b1)
### BUGGY CODE ###

q, h, s, d = map(int, input().split())
n = int(input())

ans = 10 ** 9

i_max = int(n / 0.25)
for i in range(i_max+1):
	j_max = int((n - 0.25 * i)/0.5)
	for j in range(j_max+1):
		k_max = int((n - 0.25 * i - 0.5 * j))
		for k in range(k_max+1):
			l_max = int((n - 0.25 * i - 0.5 * j - k))
			for l in range(l_max+1):
				_n = 0.25 * i + 0.5 * j + k + 2 * l
				if _n != n:
					continue
				_sum = i * q + j * h + k * s + d * l
				ans = min(ans, _sum)
print(ans)


### FIXED CODE ###

q, h, s, d = map(int, input().split())
n = int(input())
print(int(n/2) * min(q*8, h*4, s*2, d) + (n%2) * min(q*4, h*2, s))
### BUGGY CODE ###

a,b,n=map(int,input().split())
ans=0
for i in range(a,b+1):
  if i%n==0:
    ans+=1
print(ans)

### FIXED CODE ###

a,b,n=map(int,input().split())

if a%n==0:
  x=a//n
else:
  x=((a//n)+1)
  
if b%n==0:
  y=b//n
else:
  y=((b//n))
  
print(y-x+1)
### BUGGY CODE ###

def primes(n):
  l = [1 for i in range(n+1)]
  l[0] = l[1] = 0
  for i in range(2,int((n)**(1/2))+1):
    if l[i] == 1:
      for j in range(2,(n)//i+1):
        l[i*j] = 0
  return l

l = primes(50000)

while True:
  n = int(input())
  if n == 0:
    break
  count = 0
  for i in range(1,n//2+1):
    if (l[i] and l[n-i]):
      count += 1
  print(count)

### FIXED CODE ###

def primes(n):
  l = [1 for i in range(n+1)]
  l[0] = l[1] = 0
  for i in range(2,int((n)**(1/2))+1):
    if l[i] == 1:
      for j in range(2,n//i+1):
        l[i*j] = 0
  return l

l = primes(50000)
while True:
  n = int(input())
  if n == 0:
    break
  count = 0
  if not(n%2):
    for i in range(3,n//2+1,2):
      if (l[i] and l[n-i]):
        count += 1
    if n == 4:
      count = 1
  else:
    if l[n-2]:
      count += 1
  print(count)
### BUGGY CODE ###

n,m=map(int,input().split())
A=[input().split() for _ in range(m)]
ans="IMPOSSIBLE"
for i in range(m):
  if A[i][0]=="1":
    if [A[i][1],str(n)] in A:
      ans="POSSIBLE"
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
A=set()
B=set()
for i in range(m):
  a,b=input().split()
  if a=="1":
    A.add(b)
  if b==str(n):
    B.add(a)
print("POSSIBLE" if A&B else "IMPOSSIBLE")
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from bisect import bisect_left
from sys import stdin
from heapq import heappush, heappop


def main():
  ## input
  N,Q = map(int, stdin.readline().rstrip().split())
  STX = [[0,0,0] for _ in range(N)]
  for i in range(N):
    s,t,x = map(int, stdin.readline().rstrip().split())
    STX[i] = [x,s-x,t-x]
  Dn = [int(stdin.readline().rstrip()) for _ in range(Q)] + [10**10]
  ans = []

  for x,s,t in sorted(STX):
    l = bisect_left(Dn,s)
    r = l
    while Dn[r] < t:
      heappush(ans, (Dn[r],x))
      r += 1
    del Dn[l:r]

  for d in Dn[:-1]:
    heappush(ans, (d,-1))

  return ans


if __name__ == "__main__":
  ans = main()
  while len(ans) > 0:
    print(heappop(ans)[1])    


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

A,B,N = map(int,input().split())

max = 0
for i in range(1,N+1):
    m = int(A*i/B)-A*int(i/B)
    if m>max: max = m
print(max)

### FIXED CODE ###

A,B,N = map(int,input().split())

if N<B: m=N
else: m=B-1

l = int(A*m/B)-A*int(m/B)
print(l)
### BUGGY CODE ###

import sys

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

dif = []
for idx, v in enumerate(A_list, 1):
    dif.append(v - idx)
b = 0
dif_num = sum(map(abs, (map(lambda x: x + b, dif))))
b = 1
dif_num_plus = sum(map(abs, (map(lambda x: x + b, dif))))
b = -1
dif_num_minus = sum(map(abs, (map(lambda x: x + b, dif))))
if dif_num <= dif_num_plus and dif_num < dif_num_minus:
    print(dif_num)
    sys.exit()

p_f = True
if dif_num_plus < dif_num_minus:
    p_f = True
    b = 1
else:
    p_f = False
    b = -1

dif_num = min(dif_num, dif_num_plus, dif_num_minus)

while True:
    if p_f:
        b += 1
    else:
        b -= 1
    l = list((map(lambda x: x + b, dif)))
    dif_num2 = sum(map(abs, (map(lambda x: x + b, dif))))
    if dif_num2 < dif_num:
        dif_num = dif_num2
    else:
        break
print(dif_num)


### FIXED CODE ###

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

dif = []
for idx, v in enumerate(A_list, 1):
    dif.append(v - idx)

dif.sort()
if len(dif) % 2 == 1:
    b = dif[len(dif) // 2]
    print(sum(map(abs, (map(lambda x: x - b, dif)))))
else:
    b1 = dif[len(dif) // 2 - 1]
    b2 = dif[len(dif) // 2]
    print(min(sum(map(abs, (map(lambda x: x - b1, dif)))),
              sum(map(abs, (map(lambda x: x - b2, dif))))))
### BUGGY CODE ###

def main():
    #from sys import stdin
    #input = stdin.readline

    n, m, s, t = map(int, input().split())
    uvab = [list(map(int, input().split())) for _ in [0]*m]
    g_yen = [[] for _ in [0]*n]
    [g_yen[u-1].append([v-1, a]) for u, v, a, b in uvab]
    [g_yen[v-1].append([u-1, a]) for u, v, a, b in uvab]

    g_snk = [[] for _ in [0]*n]
    [g_snk[u-1].append([v-1, b]) for u, v, a, b in uvab]
    [g_snk[v-1].append([u-1, b]) for u, v, a, b in uvab]

    import heapq

    inf = 10**15

    yen = [inf for _ in [0]*n]
    h = [(0, s-1)]
    heapq.heapify(h)
    while h:
        d, i = heapq.heappop(h)
        if yen[i] == inf:
            yen[i] = d
            for x, y in g_yen[i]:
                heapq.heappush(h, (d+y, x))

    snk = [inf for _ in [0]*n]
    h = [(0, t-1)]
    heapq.heapify(h)
    while h:
        d, i = heapq.heappop(h)
        if snk[i] == inf:
            snk[i] = d
            for x, y in g_snk[i]:
                heapq.heappush(h, (d+y, x))

    cost = [yen[i]+snk[i] for i in range(n)]
    m = cost[-1]
    for i in range(n-1, -1, -1):
        m = min(m, cost[i])
        cost[i] = m

    for i in cost:
        print(10**15-i)


main()


### FIXED CODE ###

n,m,s,t=map(int,input().split())
uvab=[list(map(int,input().split())) for _ in [0]*m]
g_yen=[[] for _ in [0]*n]
[g_yen[u-1].append([v-1,a]) for u,v,a,b in uvab]
[g_yen[v-1].append([u-1,a]) for u,v,a,b in uvab]

g_snk=[[] for _ in [0]*n]
[g_snk[u-1].append([v-1,b]) for u,v,a,b in uvab]
[g_snk[v-1].append([u-1,b]) for u,v,a,b in uvab]

import heapq
def dijkstra(g,start):
    inf=10**15
    dist=[inf for _ in [0]*n]
    h=[(0,start)]
    heapq.heapify(h)
    while h:
        d,i=heapq.heappop(h)
        if dist[i]==inf:
            dist[i]=d
            for x,y in g[i]:
                heapq.heappush(h,(d+y,x))
    return dist

yen=dijkstra(g_yen,s-1)
snk=dijkstra(g_snk,t-1)

cost=[yen[i]+snk[i] for i in range(n)]
m=cost[-1]
for i in range(n-1,-1,-1):
    m=min(m,cost[i])
    cost[i]=m
    
for i in cost:
    print(10**15-i)
### BUGGY CODE ###

H, W = [int(x) for x in input().split()]

S = []
for _ in range(H):
    S.append(input())

TATE = [[0 for i in range(W + 1)] for j in range(H + 1)]
YOKO = [[0 for i in range(W + 1)] for j in range(H + 1)]


for j in range(1, H + 1):
    for i in range(1, W + 1):
        if S[j - 1][i - 1] == '.':
            YOKO[j][i] = YOKO[j][i - 1] + 1
        if S[j - 1][i - 1] == '.':
            TATE[j][i] = TATE[j - 1][i] + 1


for j in range(H, 0, -1):
    for i in range(W, 0, -1):
        if i != W and YOKO[j][i + 1] != 0 and S[j - 1][i - 1] == '.':
            YOKO[j][i] = YOKO[j][i + 1]
        if j != H and TATE[j + 1][i] != 0 and S[j - 1][i - 1] == '.':
            TATE[j][i] = TATE[j + 1][i]
ans = 0
for j in range(1, H + 1):
    for i in range(1, W + 1):
        ans = max(ans, TATE[j][i] + YOKO[j][i] - 1)

print(ans)








### FIXED CODE ###

H, W = [int(x) for x in input().split()]

S = []
for _ in range(H):
    S.append(input())

TATE = [[0 for i in range(W + 1)] for j in range(H + 1)]
YOKO = [[0 for i in range(W + 1)] for j in range(H + 1)]


for j in range(1, H + 1):
    for i in range(1, W + 1):
        if S[j - 1][i - 1] == '.':
            YOKO[j][i] = YOKO[j][i - 1] + 1
        if S[j - 1][i - 1] == '.':
            TATE[j][i] = TATE[j - 1][i] + 1


for j in range(H, 0, -1):
    for i in range(W, 0, -1):
        if i != W and YOKO[j][i + 1] != 0 and S[j - 1][i - 1] == '.':
            YOKO[j][i] = YOKO[j][i + 1]
        if j != H and TATE[j + 1][i] != 0 and S[j - 1][i - 1] == '.':
            TATE[j][i] = TATE[j + 1][i]
ans = 0
for j in range(1, H + 1):
    for i in range(1, W + 1):
        ans = max(ans, TATE[j][i] + YOKO[j][i] - 1)

print(ans)