Harryxun/stf_run huggingface dataset:
s=list(input())

ima=0
wNum=0
for i in range(len(s)):
  if s[i]=="W":
    ima += i
    wNum += 1

def kasan(n):
  if n==0:
    return 0
  else:
    return kasan(n-1) + n
if wNum==0:
  print(0)
else:
  saigo = kasan(wNum-1)
  print(ima-saigo)

### FIXED CODE ###

s=list(input())

ima=0
wNum=0
for i in range(len(s)):
  if s[i]=="W":
    ima += i
    wNum += 1

def kasan(n):
  if n==0:
    return 0
  else:
    return kasan(n-1) + n

saigo = ((wNum-1)+0)*wNum//2
print(ima-saigo)
h1,m1,h2,m2,k = map(int(input()))

a = 60(h2-h1)
b = m2-m1
##起きている合計時間
c = a+b
##勉強開始時間の最遅時間
d = c-k
print(d)

### FIXED CODE ###

h1, m1, h2, m2, k = map(int, input().split())
##勉強できる時間
h = 60*(h2 - h1)
m = m2-m1
time = h + m - k
print(time)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())

a = prime_factorize(n-1)
b = [[a[0],1]]

for i in range(1,len(a)):
    if a[i]==b[-1][0]:
        b[-1][1]+=1
    else:
        b.append([a[i],1])

ans = 1
for i in range(len(b)):
    ans *= b[i][1]+1
ans-=1


for i in range(2,10**6):
    if n%i==0:
        x = n//i
        y = i
        x,y = min(x,y),max(x,y)
        if 1 in [x,y]:
            continue
        while y%x==0:
            y//=x
        if (y-1)%x==0:
            ans += 1
if n>=10**6:
    ans += 1
print(ans)


### FIXED CODE ###

import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())

if n == 2:
    print(1)
    exit()
"""elif n == 3:
    print(2)
    exit()
elif n==4:
    print(3)
    exit()
elif n==5:
    print(3)
    exit()
elif n==9:
    print(5)
    exit()
"""
a = prime_factorize(n-1)
b = [[a[0],1]]

for i in range(1,len(a)):
    if a[i]==b[-1][0]:
        b[-1][1]+=1
    else:
        b.append([a[i],1])

ans = 1
for i in range(len(b)):
    ans *= b[i][1]+1
ans-=1

g = []
for i in range(2,int(math.sqrt(n))+1):
    if n%i==0:
        x = n//i
        y = i
        x,y = min(x,y),max(x,y)
        if 1 in [x,y]:
            continue
        while y%x==0:
            y//=x
        if (y-1)%x==0:
            ans += 1
            g.append(i)

if n not in g:
    ans += 1
print(ans)
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
        dp[m] = ndp[m]
    dp[M] = ndp[M]
print(dp[-1] % MOD)

### FIXED CODE ###

numX, numA = [int(i) for i in input().split()]

if numX < numA:
    print(0)
else:
    print(10)
ans=0
for s in raw_input():
  if s in “ACGT”:
    ans+=1
print ans

### FIXED CODE ###

s=-1
S=raw_input()+"!"
ans=0
for i in range(len(S)):
  if S[i]in "ATCG":
    if s==-1:
      s=i
  elif s!=-1:
    ans=max(ans, i-s)
    s=-1
print ans
a, b, c, d = map(int, input().split())
takahashi = [a, b] if a>b else [b, a]
aoki = [c, d] if c>d else [d, c]
attackers = [takahashi, aoki]
attacker = 0

while 0 not in takahashi and 0 not in aoki:
  attackers[attacker^1][1] = max(0, attackers[attacker^1][1]-attackers[attacker][0])
  attackers[attacker^1].sort(reverse=True)
  attacker = attacker^1

if 0 in attackers[0]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

s, w = map(int, input().split())
print('unsafe' if w>=s else 'safe')
n,k = map(int,input().split())
output = []

for i in range(1,k):
  d = int(input())
  for j in range(1,d):
    output.append(int(input()))

print(n - len(set(output)))

### FIXED CODE ###

n,k = map(int,input().split())
ans = [1]*n

for i in range(k):
  d = int(input())
  for j in list(map(int,input().split())):
    ans[j-1] = 0

print(ans.count(1))
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(n):
    b2.append(b2[i]+b[i])
ans = 0
for i in range(len(a)):
    cnt = 0
    sm = 0
    while sm < k-a2[i]:
        sm += b[cnt]
        cnt += 1
    ans = max(cnt, ans)
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(m):
    b2.append(b2[i]+b[i])
ans = 0
cnt = m
for i in range(n+1):
    if a2[i] > k:
        break
    sm = 0
    while b2[cnt] > k-a2[i]:
        cnt -= 1
    ans = max(cnt+i, ans)
print(ans)
a,b = input().split()
print((a-1)*(b-1))

### FIXED CODE ###

a,b = [int(x) for x in input().split()]
print((a-1)*(b-1))
print(-~sum(map(int, imput().split()))//2)

### FIXED CODE ###

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

print(int((a+b)/2)+(a+b)%2)
a,b,c =  map(int,input().split())
if a < b < c:
    print('Yes')
elde:
    print('No')

### FIXED CODE ###

a,b,c = map(int,input().split())
if a < b < c:
    print('Yes')
else:
    print('No')
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N, M, L = map(int, raw_input().split())

def fact(n):
    if n <= 1:
        return 1
    return fact(n - 1) * n
MC = []
for i in range(M + 1):
    MC.append(fact(M) / fact(i) / fact(M - i))

p_lst = []
P_val = []
P_sum = []

for i in range(N):
    P, T, V = map(int, raw_input().split())
    p_lst.append((T, V))
    PP = []
    for k in range(M + 1):
        PP.append(MC[k] * (P ** k) * ((100 - P) ** (M - k)))
    P_val.append(list(PP))
    for k in range(M, 0, -1):
        PP[k - 1] += PP[k]
    P_sum.append(PP)

def comp(p1, p2, k1, k2):
    T1, V1 = p1
    T2, V2 = p2
    return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1)

for i in range(N):
    ans = 0
    index_lst = [0 for j in range(N)]
    for k1 in range(M + 1):
        ret = P_val[i][k1]
        for j in range(N):
            if i == j:
                continue
            flag = True
            while True:
                k2 = index_lst[j]
                if k2 > M:
                    ret *= 0
                    break
                if comp(p_lst[i], p_lst[j], k1, k2):
                    ret *= P_sum[j][k2]
                    break
                index_lst[j] += 1
        ans += ret
    ans = float(ans) / 100 ** (N * M)
    print ans



### FIXED CODE ###

#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N, M, L = map(int, raw_input().split())

def fact(n):
    if n <= 1:
        return 1
    return fact(n - 1) * n
MC = []
for i in range(M + 1):
    MC.append(fact(M) / fact(i) / fact(M - i))

p_lst = []
P_val = []
P_sum = []

for i in range(N):
    P, T, V = map(int, raw_input().split())
    p_lst.append((T, V))
    PP = []
    for k in range(M + 1):
        PP.append(float(MC[k] * (P ** k) * ((100 - P) ** (M - k))) / 100 ** M)
    P_val.append(list(PP))
    for k in range(M, 0, -1):
        PP[k - 1] += PP[k]
    P_sum.append(PP)

def comp(p1, p2, k1, k2):
    T1, V1 = p1
    T2, V2 = p2
    return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1)

for i in range(N):
    ans = 0
    index_lst = [0 for j in range(N)]
    for k1 in range(M + 1):
        ret = P_val[i][k1]
        for j in range(N):
            if i == j:
                continue
            while True:
                k2 = index_lst[j]
                if k2 > M:
                    ret *= 0
                    break
                if comp(p_lst[i], p_lst[j], k1, k2):
                    ret *= P_sum[j][k2]
                    break
                index_lst[j] += 1
        ans += ret
    print '%.10f' % ans
import math
A, B, C, D = map(int, input().split())
lcm = int((C*D) / math.gcd(C, D))
print((B - (B//C + B//D - B//lcm)) - ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)))

### FIXED CODE ###

from fractions import gcd
A, B, C, D = map(int, input().split())
lcm = int((C*D) / gcd(C, D))
print((B - (B//C + B//D - B//lcm)) -
      ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)))
moutain = [0 for i in range(10]
for i in range(10):
    moutain[i] = int(raw_input())
moutain.sort().reverse()
for i in range(3):
    moutain[i]


### FIXED CODE ###

moutain = [0 for i in range(10)]
for i in range(10):
    moutain[i] = int(raw_input())
moutain.sort(reverse=True)
for i in range(3):
    print moutain[i]
N = int(input())
A = [int(input()) for _ in range(N)]

dp = [0] * N
prev_i = [-1] * (10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] != -1:
    if prev_i[a] != i - 1:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
    else:
      dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1])

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

MOD = 10**9 + 7

dp = [0] * N
prev_i = [-1] * (2 * 10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] >= 0:
    if prev_i[a] == i - 1:
      dp[i] = dp[i - 1]
    else:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1] % MOD)
K, X = map(int, input().split())
print(range(x-k,x+k))


### FIXED CODE ###

K, X = map(int, input().split())
a=X-K+1
b=X+K
for i in range(a,b):
    print(i)
n,k,x,y = map(int, input().split)
print((k * x) + ((n - k) * y))

### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if(N<=K):
  print(X*N)
else:
  print(X*K+(N-K)*Y)
N, i = int(input().split())
print(N-i+1)

### FIXED CODE ###

N, i = map(int, input().split())
print(N-i+1)
s = raw_input()
K = int(raw_input())

arr = []
for i in range(len(s)):
    for j in  range(len(s) + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])

### FIXED CODE ###

s = raw_input()
K = int(raw_input())

arr = []
length = min(5, len(s))
for i in range(len(s)):
    for j in  range(length + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])
n, x = map(int, input().split())

def abs2(m):
    m = int(m)
    return abs(m-x)

# from fractions import gcd

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

xs = list(map(abs2, input().split()))
# xs = list(map(int, input().split()))

if n == 1:
    ans = xs[0]
else:
    ans = gcd(*xs)

# ans = abs(x-xs[0])
# for y in xs:
#     ans = gcd(*[ans, abs(x-y)])

print(ans)


### FIXED CODE ###

from fractions import gcd
n,x=map(int,input().split())
 
xlist=list(map(int,input().split()))
 
ans=abs(x-xlist[0])
for i in xlist:
    ans=gcd(ans,abs(x-i))
 
print(ans)
S = list(input())
K = int(input())
i = 0
ans = 0

while K > 0:
    K = K - S[i]**(5*10**16 + 1)
    ans = S[i]
    i += 1

print(ans)

### FIXED CODE ###

S = input()
K = int(input())

ans = 0
n1 = 0

for i in S:
    if i != "1":
        s = int(i)
        break
    
    else:
        n1 += 1

if n1 >= K:
    print(1)

else:
    print(s)
import numpy as np
a=np.array([[0]*10]*12)
n=int(input())
for i in range(n):
    b,f,r,v=map(int,input().split())
    a[ 3*b-4+f, r-1 ] += v
for i in range(12):
    if i > 0 and i%3==0:
        print('#'*20)
    print(' ', end='')
    print(' '.join(map(str,a[i,])))

### FIXED CODE ###

towers = [
    [[0 for i in range(10)] for j in range(3)] for k in range(4)
]
floor = 3
 
n = int(input())
for i in range(n):
    b,f,r,v = list(map(int,input().split()))
    towers[b-1][f-1][r-1] += v
 
for b in towers:
    for f in b:
        for r in f:
            print(' ' + str(r), end='')
        print('')
    if floor:
        print('#'*20)
        floor -= 1
from decimal import Decimal 
a = map(Decimal, input().split())

print(a[0]*a[1])


### FIXED CODE ###

from decimal import Decimal

# t = '1000000000000000 9.99'
a = list(map(Decimal, input().split()))
# a = list(map(Decimal, t.split()))

print(int(a[0]*a[1]))
#import matplotlib.pyplot as plt
import networkx as nx

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

G = [[0, 0, []] for i in range(n+1)]


#print(G.nodes())
for i in range(m) :
    G[D[i][0]][2].append([D[i][1], D[i][2]])
    G[D[i][1]][2].append([D[i][0], -D[i][2]])

global no
no = 0

def d(a):
    G[a][1] = 1
    A = []
    #print(len(G[a][2]))
    #print(G[a][2][0][0])
    for j in range(len(G[a][2])) :
        i = G[a][2][j][0]
        #print(set(list(nx.all_neighbors(G, a))))
        #print("{} {}".format(a,i))
        if G[i][1] == 0 :
            A.append(i)
            G[i][0] = G[a][0] + G[a][2][j][1]
            G[i][1] = 1
        else :
            #print("{} {} {}".format(G[i][0],G[a][0],G[a][2][j][1]))
            if G[i][0] != G[a][0] + G[a][2][j][1] :
                #print("A")
                global no
                no = 1
                #print("{} {}".format("no",no))
    for i in A :
        d(i)

for i in range(1,n+1):
    if G[i][1] == 0 :
        d(i)
        
if no == 1 :
    print("No")
else :
    print("Yes")
        


### FIXED CODE ###

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

A = [0] * (n+1)

M = [[] for i in range(n+1)]

for i in range(m):
    M[D[i][0]].append([D[i][1], D[i][2]])
    M[D[i][1]].append([D[i][0], -D[i][2]])

V = [0] * (n+1)


# print(M)

for ii in range(1, n+1):
    if V[ii] == 0 and len(M[ii]) > 0:

        Q = [[ii, 0]]
        st = 0
        while st < len(Q):
            # print(A,V,Q)
            node = Q[st][0]
            dist = Q[st][1]
            if V[node] == 0 and len(M[node]) > 0:
                V[node] = 1
                A[node] += dist
                for i in M[node]:
                    if V[i[0]] == 0:
                        Q.append([i[0], A[node] + i[1]])
            st += 1

# print(A)

def d():
    for i in range(m):
        if A[D[i][1]] - A[D[i][0]] != D[i][2]:
            return "No"
    return "Yes"

print(d())
a,*b,c=input()
print(a+Str(len(b))+c)


### FIXED CODE ###

a,*b,c=input()
print(a+str(len(b))+c)
import queue


def up(y, x, d):
    return y-1, x, d


def down(y, x, d):
    return y+1, x, d


def left(y, x, d):
    return y, x-1, d


def right(y, x, d):
    return y, x+1, d


def put_all(q, y, x, d):
    q.put((up(y, x, d)))
    q.put((down(y, x, d)))
    q.put((left(y, x, d)))
    q.put((right(y, x, d)))
    return


def put_not_all(q, y, x, d, distances):
    if distances[y-1][x] != -1:
        q.put((y-1, x, d))
    if distances[y+1][x] != -1:
        q.put((y+1, x, d))
    if distances[y][x-1] != -1:
        q.put((y, x-1, d))
    if distances[y][x+1] != -1:
        q.put((y, x+1, d))


def solve(maze, init_y, init_x, distances, H, W):
    if maze[init_y][init_x] == "#":
        return 0

    distances[init_y][init_x] = 0

    q = queue.Queue()
    put_all(q, init_y, init_x, 1)

    farthest = [0, init_y, init_x]
    while not q.empty():
        y, x, d = q.get()
        # print(x, y)
        if x < 0 or x >= W or y < 0 or y >= H:
            # print("continue")
            continue
        if maze[y][x] == "#":
            distances[y][x] = 0
            continue
        distance = distances[y][x]
        if distance == -1:
            distances[y][x] = d
            put_all(q, y, x, d+1)
            if d > farthest[0]:
                farthest = [d, y, x]

    return farthest


def main():
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    flag = False
    y = 0
    x = 0
    for i in range(H):
        for j in range(W):
            initial_map = [[-1 for _ in range(W)] for _ in range(H)]
            distance, y, x = solve(maze, i, j, initial_map, H, W)
            if distance > 0:
                flag = True
                break
        if flag:
            break
    initial_map = [[-1 for _ in range(W)] for _ in range(H)]
    max_distance, y, x = solve(maze, y, x, initial_map, H, W)

    print(max_distance)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def d_maze_master(INF=float('inf')):
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Maze = [list(input()) for _ in range(H)]

    def bfs(start_row, start_col):
        diff = ((-1, 0), (0, 1), (1, 0), (0, -1))

        def is_inside(row, col):
            return 0 <= row < H and 0 <= col < W

        queue = deque([(start_row, start_col)])
        dist = [[INF for _ in range(W)] for _ in range(H)]
        dist[start_row][start_col] = 0
        while queue:
            row, col = queue.pop()
            for dr, dc in diff:
                nr, nc = row + dr, col + dc
                if is_inside(nr, nc) and Maze[nr][nc] != '#' and dist[nr][nc] == INF:
                    queue.appendleft((nr, nc))
                    dist[nr][nc] = dist[row][col] + 1
        return dist

    ans = 0
    for start_row in range(H):
        for start_col in range(W):
            if Maze[start_row][start_col] == '#':
                continue
            dist = bfs(start_row, start_col)
            for row in range(H):
                for col in range(W):
                    if Maze[row][col] != '#':
                        ans = max(ans, dist[row][col])
    return ans

print(d_maze_master())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(sum(min(a, b), min(c, d)))

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a, b) + min(c, d))
s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    sh=dph[nh][x+sumh]
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    sv=dpv[nv][y+sumv]
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    if 0<=x+sumh<=2*sumh:
        sh=dph[nh][x+sumh]
    else:
        sh=False
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    if 0<=y+sumv<=2*sumv:
        sv=dpv[nv][y+sumv]
    else:
        sv=False
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')
H,W= map(int,raw_input().split())

M = []
for i in range(H):
	M.append(raw_input().split())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	answer = ""
	for j in range(W):
		if flag_list_H[i] and flag_list_W[j]:
			answer+=M[i][j] + " "
	print answer[:-1]

### FIXED CODE ###


H,W= map(int,raw_input().split())

M = []
for i in range(H):
	M.append(raw_input())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	if flag_list_H[i]:
		answer = ""
		for j in range(W):
			if flag_list_W[j]:
				answer+=M[i][j]
		print answer
def solution(edges):
    num_of_neighbor = {}
    for e in edges:
        if e[0] in num_of_neighbor:
            num_of_neighbor[e[0]] += 1
        else:
            num_of_neighbor[e[0]] = 1
        if e[1] in num_of_neighbor:
            num_of_neighbor[e[1]] += 1
        else:
            num_of_neighbor[e[1]] = 1
    n_2 = 0
    n_1 = 0
    for n in num_of_neighbor:
        if num_of_neighbor[n] == 2:
            n_2 += 1
        elif num_of_neighbor[n] == 1:
            n_1 += 1

        if n_2 == 2 and n_1 == 2:
            return 'YES'
        else:
            return 'NO'

e1 = [int(s) for s in input().split(' ')]
e2 = [int(s) for s in input().split(' ')]
e3 = [int(s) for s in input().split(' ')]
edges = [e1, e2, e3]
print(solution(edges))

### FIXED CODE ###

N, K = [int(s) for s in input().split(' ')]
x = 0
if N%2:
    x = (N + 1) / 2
else:
    x = N/ 2
if x>=K:
    print("YES")
else:
    print("NO")
import math
R = input()
l = 2*R*math.pi
print(l)

### FIXED CODE ###

import math
R = int(input())
l = 2*R*math.pi
print(l)
N,K=map(int,input().strip().split())
A=list(map(int,input().strip().split()))

l=[1]
x=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    x=y

cnt=[0 for n in range(N)]
for n in range(N):
    cnt[l[n]-1]+=1
    if cnt[l[n]-1]==2:
        temp=n
        break
for m in range(len(l)):
    if l[m]==temp:
        bias=m
        mul=temp-bias+1
        break

if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])

### FIXED CODE ###

N,K=map(int,input().strip().split())
A=list(map(int,input().strip().split()))

l=[1]
x=1
cnt=[0 for n in range(N)]
cnt[0]=1
for n in range(N):
    y=A[x-1]
    l.append(y)
    cnt[y-1]+=1
    x=y
    if cnt[y-1]==2:
        value=y
        temp=n
        break

for m in range(len(l)):
    if l[m]==value:
        bias=m
        mul=temp-bias+1
        break
    
if bias>K:
    print(l[K])
else:
    print(l[bias+(K-bias)%mul])
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
result = sum(b_list)
dif_list = []
for i in range(n -1):
  if a_list[i + 1] == a_list[i] + 1:
    dif_list.append(1)
  else:
    dif_list.append(0)
for m in range(len(dif_list)):
  if dif_list[m] == 1:
    result += c_list[m + 1]
print(result)

### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
result = sum(b_list)
dif_list = []
for i in range(n -1):
  if a_list[i + 1] == a_list[i] + 1:
    dif_list.append(1)
  else:
    dif_list.append(0)
for m in range(len(dif_list)):
   if dif_list[m] == 1:
    result += c_list[a_list[m] -1]
print(result)