Harryxun/stf_run huggingface dataset:
def get_next_int():
    return int(input().rstrip("\n"))
def get_next_ints(delim=" "):
    return tuple([int(x) for x in input().rstrip("\n").split(delim)])
def main():
    n = get_next_int()
    
    a = get_next_ints()
    b = get_next_ints()
    
    a_offsets = []
    b_offsets = []
    for i in range(n):
        a_offsets.append(str(a[i] ^ a[i-1]))
        b_offsets.append(str(b[i] ^ b[i-1]))
    #print(a_offsets)
    #print(b_offsets)
    a_text = " ".join(a_offsets)
    b_text = " ".join(b_offsets)
    target_text = a_text + " " + a_text
    
    start = 0
    while target_text.find(b_text, start) >= 0 and start < len(a_text):
        start = target_text.find(b_text, start)
        #print(start)
        pos_diff = s[:start].count(" ")
        xor_diff = b[0] ^ a[pos_diff]
        print(pos_diff, xor_diff)        
        start = start + 2

if __name__ == '__main__':
    main()
    

### FIXED CODE ###

def get_next_int():
    return int(input().rstrip("\n"))


def get_next_ints(delim=" "):
    return tuple([int(x) for x in input().rstrip("\n").split(delim)])


def main():
    n = get_next_int()

    a = get_next_ints()
    b = get_next_ints()

    a_offsets = []
    b_offsets = []
    for i in range(n):
        a_offsets.append(str(a[i] ^ a[i - 1]))
        b_offsets.append(str(b[i] ^ b[i - 1]))
    #print(a_offsets)
    #print(b_offsets)
    a_text = " ".join(a_offsets)
    b_text = " ".join(b_offsets)
    target_text = a_text + " " + a_text
    start_pos = 0
    if target_text.find(b_text, start_pos) >= 0:
        fisrt_pos = target_text.find(b_text, start_pos)
        fisrt_pos_diff = target_text[:fisrt_pos].count(" ")
        fisrt_xor_diff = b[0] ^ a[fisrt_pos_diff]
        print(fisrt_pos_diff, fisrt_xor_diff)
        if target_text.find(b_text, fisrt_pos+1) >= 0:
            second_pos = target_text.find(b_text, fisrt_pos+1)
            second_pos_diff = target_text[:second_pos].count(" ")
            if second_pos_diff < len(a):
                second_xor_diff = b[0] ^ a[second_pos_diff]
                print(second_pos_diff, second_xor_diff)
                interval = (second_pos_diff - fisrt_pos_diff)
                remain = (n - second_pos_diff - 1) // (second_pos_diff - fisrt_pos_diff)
                for i in range(remain):
                    print(second_pos_diff + interval * (i + 1), [fisrt_xor_diff,second_xor_diff ][i % 2])

if __name__ == '__main__':
    main()
S = int(input())

dp = [0] * (S + 1)
dp[0] = 1
dp[1] = 0
dp[2] = 0
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))


### FIXED CODE ###

S = int(input())

dp = [0] * (S + 1)
dp[0] = 1
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))
n, m = map(int, input().split())
stu = []
check = []
for i in range(n):
    stu.append(list(map(int, input().split())))

for i in range(m):
    check.append(list(map(int, input().split())))


ans = []

for i in range(n):
    dist = []
    for j in range(m):
        tmp = abs(stu[i][0] - check[j][0]) + abs(stu[i][1] - check[j][1])
        dist.append(tmp)
    mi = dist.index(min(dist))
    ans.append(mi)


for i in range(len(ans)):
    print(ans[i] + 1)


### FIXED CODE ###

a, b = map(int, input().split())
c = (a + b) % 24
print(c)
import math
import sys
import collections
import bisect
import sympy
readline = sys.stdin.readline


def main():
    N = int(readline().rstrip())
    ans = 0
    for i in range(1, N+1):
        n = N // i
        ans += 0.5 * n * (2*i + i * (n-1))
    print(int(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    N = int(readline().rstrip())
    ans = 0
    for i in range(1, N+1):
        n = N // i
        ans += 0.5 * n * (2*i + i * (n-1))
    print(int(ans))


if __name__ == '__main__':
    main()
import numpy

N, M = map(int, input().split())
R = numpy.array([[int(r) for r in input().split()] for _ in range(M)]) - 1

size = [1] * N

groups = numpy.array([-1] * N)
gnum = 1
sameinfo = []

for p1, p2 in R:

    g1 = groups[p1]
    g2 = groups[p2]

    if g1 == -1 and g2 == -1:
        groups[p1] = gnum
        groups[p2] = gnum
        gnum += 1

    elif g1 != -1 and g2 == -1:
        groups[p2] = g1

    elif g1 == -1 and g2 != -1:
        groups[p1] = g2

    elif g1 != -1 and g2 != -1:
        sameinfo.append([min(g1, g2), max(g1, g2)])

for s1, s2 in sameinfo:
    groups[groups == s2] = s1


groups = groups[groups != -1]
maxgroup = numpy.argmax(numpy.bincount(groups))
print(numpy.count_nonzero(groups == maxgroup))

### FIXED CODE ###

import numpy

class UnionFind:
    def __init__(self, N):
        self.N = N

        # the parent of all node is itself
        # self.parent = list(range(N))
        self.parent = [-1] * N

    def root(self, i):
        if self.parent[i] < 0:
            return i

        r = self.root(self.parent[i])
        self.parent[i] = r
        return r

    def unite(self, i, j):
        # print('root {}, {} = '.format(i, j), end='')
        i = self.root(i)
        j = self.root(j)
        # print(i, j)

        if i == j:
            return

        if i > j:
            i, j = j, i

        self.parent[i] += self.parent[j]
        self.parent[j] = i
        # print(self.parent)

    def same(self, i, j):
        return self.root(i) == self.root(j)

    def size(self, i):
        return -self.parent[self.root(i)]

N, M = map(int, input().split())
R = numpy.array([[int(r) for r in input().split()] for _ in range(M)]) - 1

forest = UnionFind(N)
for p1, p2 in R:
    forest.unite(p1, p2)

s = [forest.size(i) for i in range(N)]
print(max(s))
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        breal
    for i in range(a):
        print("#"*b)
    print("")

### FIXED CODE ###

while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    for i in range(a):
        print("#"*b)
    print("")
import numpy as np
n,k=map(int,input().split())
s=list(input())
s[k]=s[k].lower()
for i in range(len(s)):
  print(s[i],end="")
print("")

### FIXED CODE ###

n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
s="".join(s)
print(s)
length = list(map(int,input().split()))	
string = input()
l_r = [list(map(int,input().split())) for i in range(length[1])]
answer = []

for i in range(length[1]):
  part_str = string[(l_r[i][0]-1):l_r[i][1]]
  for n in range(len(part_str)):
    answer.append(0)
    if part_str[n]=='A':
      if n != (len(part_str)-1):
        if part_str[n+1]=='C':
          answer[i] += 1
  print(answer[i])
          


### FIXED CODE ###

N, Q = map(int,input().split())
S = list(input())
lr = [list(map(int,input().split())) for i in range(Q)]
ans = ''
a = [0]
count = 0
for i in range(N-1):
  if S[i] + S[i+1] == 'AC':
    ans += '1'
  else:
    ans += '0'
  if i == N - 2:
    ans += '0'
else:
  for i in range(N):
    if ans[i] == '1':
      count += 1
      a.append(count)
    else:
      a.append(count)
  else:
    for i in range(Q):
      l = lr[i][0]
      r = lr[i][1]
      print(a[r-1]-a[l-1])
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = [list(map(int,stdin.readline().rstrip().split()))]

getV_num = min(N, K)

for i in range(getV_num//2+1, getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)*-1

        #print(leftn, rightn)

        if rightn == 0:
            data = V[:leftn]
        elif leftn == 0:
            data = V[rightn:]
        else:
            data = V[:leftn] + V[rightn:]
        #print(data)

        for _ in range(sute):
            data.sort()
            if data[0] < 0:
                del data[0]

        #print(data)

        ans = max(ans, sum(data))

print(ans)


### FIXED CODE ###

from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = list(map(int,stdin.readline().rstrip().split()))

getV_num = min(N, K)

ans = 0

for i in range(getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)

        data = []


        for k in range(leftn):
            data.append(V[k])

        for k in range(rightn):
            data.append(V[N-1-k])

        data.sort()
        for _ in range(sute):
            if data:
                if data[0] < 0:
                    del data[0]
                else:
                    break
            else:
                break

        ans = max(ans, sum(data))

print(ans)
import collections

n,m = map(int,raw_input().split(' '))
res = [-1] * n
flag = True
for _ in range(m):
	s,c = map(int, raw_input().split(' '))

	if res[s] == -1:
		res[s] = c
	else:
		flag = False

if flag is True:
	found = -1
	for i in range(len(s)):
		if s[i] == -1:
			s[i] = 0 if i else 1
	print ''.join(map(str, s))

else:
	print -1


### FIXED CODE ###

import collections

n,m = map(int,raw_input().split(' '))
operations = [map(int, raw_input().split(' ')) for _ in range(m)]
def f(operations, n):

	res = [-1] * n

	for s,c in operations:
		s -=1
		if res[s] == -1:
			res[s] = c
		elif res[s] != c:
			return (False, res)
	
	for i in range(len(res)):
		if res[i] == -1: 
			res[i] = 0 if (i or n == 1) else 1
	
	if res[0] == 0 and n > 1:
		return (False, res)
	return (True, res)
f,r = f(operations, n)
print ''.join(map(str,r)) if f else -1
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

dp=[0]*n
a = {"r":p, "s":r, "p":s}

for i in range(n):
    if i>=k and t[i]==t[i-k]: # どうせ得点できないので、次に影響しないように'x'
        dp[i]=0
        t[i]='x'
    else:
        dp[i]=d[t[i]]   
print(sum(dp))

### FIXED CODE ###

n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())

dp=[0]*n
a = {"r":p, "s":r, "p":s}

for i in range(n):
    if i>=k and t[i]==t[i-k]: # どうせ得点できないので、次に影響しないように'x'
        dp[i]=0
        t[i]='x'
    else:
        dp[i]=a[t[i]]   
print(sum(dp))
moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B":
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)

### FIXED CODE ###

moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B" and len(list) != 0:
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)
N = int(input())
A = list(map(int, input().split()) for _ in range(N))
B = sorted(A)
for i in range(N):
  if A[i-1] == B[0]:
    print(B[1])
  else:
    print(B[0])


### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A, reverse=True)
for i in range(N):
  if A[i] == B[0]:
    print(B[1])
  else:
    print(B[0])
import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(reversed(ans) if r else ))

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(reversed(ans) if r else ans))

if __name__ == "__main__":
  main()
from fractions import gcd

A,B=map(int,input().split())
print(A*B//fractions.gcd(A,B))

### FIXED CODE ###

import fractions
A,B=map(int,input().split())
print(A*B//fractions.gcd(A,B))
input()
l=list(map(int,input().split()))
print('Yes' if 2*max(l)< sum(l) else 'No')


### FIXED CODE ###

t,x = map(int,input().split())
print(t/x)
N = int(input())
A = [int(input()) for i in range(N) ]

for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    print(max(tmp))

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N) ]
left = []
right = []
left_max = 0
right_max = 0
for i in range(N):
    if i == 0:
        left.append(0)
    else:
        left.append(max(left_max, A[i-1]))
    
    if (A[i-1] > left_max) and i != 0:
        left_max = A[i-1]
        
for i in range(N-1, -1, -1):
    if i == N-1:
        right.append(0)
    else:
        right.append(max(right_max, A[i+1]))
    
    if i != N-1:
        if A[i+1] > right_max:
            right_max = A[i+1]
right.reverse()

for i in range(N):
    print(max(left[i],right[i]))
n,m = map(int,input().split())
li = [int(input()) for i in range(m)]

#連続する壊れていない階段の数を求める
li_new = [-1]*(m+1)
li_new[0] = li[0]
for i in range(1,m):
    li_new[i] = li[i] - (li[i-1]+1)
li_new[m] = n - li[m-1]
#print(li_new)

#必用な部分までのフィボナッチ数をリストに保存
fib = [0] * (max(li_new)+1)
fib[0] = 0
fib[1] = 1
fib[2] = 1
for i in range(3,max(li_new)+1):
    fib[i] = fib[i-2] + fib[i-1]
#print(fib)

#連続する壊れていない階段の数ごとのフィボナッチ数の積
ans = 1
for i in li_new:
    ans *= fib[i]
print(ans%1000000007)

### FIXED CODE ###

n,m = map(int,input().split())
if m > 0:
    li = [int(input()) for i in range(m)]
else:
    li = [0]

#連続する壊れていない階段の数を求める
li_new = [-1]*(m+1)
li_new[0] = li[0]
for i in range(1,m):
    li_new[i] = li[i] - (li[i-1]+1)
li_new[m] = n - li[m-1]
#print(li_new)

#必用な部分までのフィボナッチ数をリストに保存
fib = [0] * (max(max(li_new)+2,3))
fib[0] = 0
fib[1] = 1
fib[2] = 1
for i in range(3,max(li_new)+2):
    fib[i] = fib[i-2] + fib[i-1]
#print(fib)

#連続する壊れていない階段の数ごとのフィボナッチ数の積
ans = 1
if m > 0:
    for i in li_new:
        ans *= fib[i]
else:
    ans = fib[n+1]
print(ans%1000000007)
n=int(input())
g=[set() for _ in range(n*(n-1)//2+1)]
visit=[0]*(n*(n-1)//2+1)
d=[0]*(n*(n-1)//2+1)

for i in range(1,n+1):
    last=0
    for j in list(map(int,input().split())):
        mi,ma=(min(i-1,j-1),max(i-1,j-1))
        current=ma*(ma-1)//2+mi+1
        g[last].add(current)
        last=current

def dfs(u):
    if visit[u]==2:
        return d[u]
    
    ans=0
    visit[u]=1
    for v in g[u]:
        if visit[v]==1:
            print(-1)
            exit(0)
        
        d[u]=max(d[u],1+dfs(v))
    
    visit[u]=2
    return d[u]

print(dfs(0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n=int(input())
g=[set() for _ in range(n*(n-1)//2+1)]
visit=[0]*(n*(n-1)//2+1)
d=[0]*(n*(n-1)//2+1)

for i in range(1,n+1):
    last=0
    for j in list(map(int,input().split())):
        mi,ma=(min(i-1,j-1),max(i-1,j-1))
        current=ma*(ma-1)//2+mi+1
        g[last].add(current)
        last=current

def dfs(u):
    if visit[u]==2:
        return d[u]
    
    ans=0
    visit[u]=1
    for v in g[u]:
        if visit[v]==1:
            print(-1)
            exit(0)
        
        d[u]=max(d[u],1+dfs(v))
    
    visit[u]=2
    return d[u]

print(dfs(0))
f=open('in','r')
input=lambda:f.readline().strip()

s=input()
if s[-1]!='s':print(s+'s')
else:print(s+'es')

### FIXED CODE ###

s=input()
if s[-1]!='s':print(s+'s')
else:print(s+'es')
from collections import defaultdict

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

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)
  
value = [0]  * (N+1)
for p, x in PX:
  value[p] += x
  
def dfs(v, parent, add):
  value[v] += add
  for x in graph[v]:
    if x == parent:
      continue
    dfs(x, v, value[v])
dfs(1, 0, 0)    

answer = ' '.join(map(str,value[1:]))
print(answer)

  

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split())

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

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

value = [0] * (N+1)
for p, x in PX:
  value[p] += x

def dfs(v, parent):  
  for i in graph[v]:
    if i == parent:
      continue
    value[i] += value[v]
    dfs(i, v)

dfs(1, 0)    
ans = ' '.join(map(str, value[1:]))
print(ans)
s = input()
k = int(input())
lengh = 0
ans = '1'
for i in list(s):
    if i != '1':
        ans = i
        break
if k <= len(s) and s[k-1] == '1': ans = s['k-1']
print(ans)

### FIXED CODE ###

s = input()
k = int(input())
lengh = 0
ans = '1'
flag = True
for i in list(s):
    if i != '1':
        ans = i
        break
if k <= len(s):
    for i in list(s)[:k]:
        if i == '1': continue
        flag = False
        break
    if flag: ans = s[k-1]
print(ans)
N = input()
ans = 0
for i in range(1, N + 1):
    if lens(str(i)) % 2 is 1:
      ans += 1
      
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
        ans += 1
 
print(ans)
while True:
    try:
        a = raw_input().split()
        b = [i for i in a if len(i)==3 or len(i)==4]
        c = [i for i in b if ord(i[0])-ord(i[1]) == 12]
        s = [ord('t')-ord(c[0][0]),1] if c[0][0]<'t' else [ord(c[0][0])-ord('t'),0]
        q=''
        for g,i in enumerate(a):
            if g==0:pass
            else: q+=' '
            for j in i:
                if j=='.':
                    q+='.'
                elif s[1] == 0:
                    q+=chr(ord(j)-s[0])
                elif s[0] == 1:
                    q+=chr(ord(j)+s[0])
        print q
    except EOFError:
        break

### FIXED CODE ###

import sys
a=lambda x: [''.join([chr(97+(ord(i)-97+j)%26) if i.islower() else i for i in x]) for j in range(26)]
value=['this','that','the']
for s in sys.stdin:
    for i in a(s):
        if sum(map(i.count,value))>0:
            print(i[:-1])
a,b,c=map(int,input().split())
if a%2==0 or b%2==0 or c%2==0:
    print(0)
    exit()

print(min[a*b,b*c,c*a])

### FIXED CODE ###

a,b,c=map(int,input().split())
if a%2==0 or b%2==0 or c%2==0:
    print(0)
    exit()
x=[a*b,b*c,c*a]
print(min(x))
def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = raw_input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = raw_input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = raw_input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)                                                                                                                                                                                                              

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)

### FIXED CODE ###

def gen_switch(i, n):
    ret = []
    str_bin = format(i, '011b')
    for k in range(n):
        ret.append(int(str_bin[-k-1]))
    ret.reverse()
    return ret


input_line = input()
splitted_line = input_line.split(" ")
n = int(splitted_line[0])
m = int(splitted_line[1])


my_mtx = []

for i in range(m):
    my_list = [0] * n
    splitted_line = input().split(" ")

    for j in range(len(splitted_line)):
        if j != 0:
            my_list[int(splitted_line[j])-1] = 1

    my_mtx.append(my_list)

splitted_line = input().split(" ")
my_list = []

for item in splitted_line:
    my_list.append(int(item))


count = 0

# print(my_list)                                                                                                                                                                                                              

for i in range(2 ** n):
    my_switch = gen_switch(i, n)
    for j in range(m):
        my_sum = 0
        for k in range(len(my_switch)):
            my_sum = my_sum + (my_switch[k] * my_mtx[j][k])
        if my_sum % 2 != my_list[j]:
            break
        if j == m - 1:
            count = count + 1

print(count)
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

    n = len(S)
    d = defaultdict(list)
    for i, s in enumerate(S, start=1):
        d[s].append(i)

    cnt = 0
    pos = 0
    for t in T:
        if pos > max(d[t]):
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left < right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

    n = len(S)
    d = defaultdict(list)
    for i, s in enumerate(S, start=1):
        d[s].append(i)

    cnt = 0
    pos = 0
    for t in T:
        if pos >= d[t][-1]:
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left < right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())
Sum = input().split()
while ('+' in Sum) or ('-' in Sum) or ('*' in Sum) :
    for che in 2, 3 :
        if Sum[che] == '+' : 
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) + int(Sum.pop(che - 2))))
            del Sum[che - 1]
        elif Sum[che] == '-' :
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) - int(Sum.pop(che - 2))))
            del Sum[che - 1]
        elif Sum[che] == '*' : 
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) * int(Sum.pop(che - 2))))
            del Sum[che - 1]
        if ('+' not in Sum) and ('-' not in Sum) and ('*' not in Sum) : break
print(Sum[0])

### FIXED CODE ###

Sum = input().split()
cou = 1
while len(Sum) != 1 :
    cou += 1
    if Sum[cou] == '+' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '-' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '*' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
        cou -= 2

print(Sum[0])
a,b,h=map(int,input().split())
print((a+b)*h/2)


### FIXED CODE ###

a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)
H, W = map(int, raw_input().split())
while H | W != 0:
    for i in range(H):
        if i == 0 or i == H - 1:
            print '#' * W
        else:
            print '#' + '.' * W - 2 + '#'
    print ''
    H, W = map(int, raw_input().split())

### FIXED CODE ###

H, W = map(int, raw_input().split())
while H | W != 0:
    for i in range(H):
        if i == 0 or i == H - 1:
            print '#' * W
        else:
            print '#' + '.' * (W - 2) + '#'
    print ''
    H, W = map(int, raw_input().split())