Harryxun/stf_run huggingface dataset:
def main():
    cells, moves = [int(x) for x in input().split()]
    nexts = [int(x) - 1 for x in input().split()]
    scores = [int(x) for x in input().split()]

    ans = -10 ** 9 - 5
    # whole_break = False
    for start in range(cells):
        route = []
        seen = set()
        route_append = route.append
        seen_add = seen.add
        now = start
        for _step in range(cells):
            nex = nexts[now]
            # if nex < start:
            #     whole_break = True
            #     break
            if nex in seen:
                break
            route_append(scores[nex])
            seen_add(nex)
            now = nex

        length = len(route)
        total = sum(route)
        # if whole_break:
        #     whole_break = False
        #     if moves > length:
        #         break

        if total > 0 and moves > length:
            q, mod = divmod(moves, length)
            candidate = max(sum(route[:x + 1]) for x in range(mod)) + total * q
        else:
            candidate = max(sum(route[:x + 1]) for x in range(length))
        ans = max(ans, candidate)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import accumulate


def main():
    cells, moves = [int(x) for x in input().split()]
    jumps_from = [int(x) - 1 for x in input().split()]
    score_on = [int(x) for x in input().split()]

    ans = - 10**10
    for start in range(cells):
        route = []
        route_append = route.append
        position = start
        while True:
            route_append(score_on[position])
            position = jumps_from[position]
            if position == start:  # Looped
                break

        length = len(route)
        total = sum(route)
        accum_tmp = 0
        for i, score in enumerate(route):
            accum_tmp += score
            if i + 1 > moves:
                break
            accum = accum_tmp
            if total > 0:
                accum += total * ((moves - (i + 1)) // length)
            ans = max(ans, accum)

        # if total > 0:
        #     q, mod = divmod(moves, length)
        #     if mod == 0:
        #         candidate = total * q
        #     else:
        #         candidate = max(list(accumulate(route))[:mod]) + total * q
        # else:
        #     candidate = max(list(accumulate(route))[:min(moves, length)])
        # ans = max(ans, candidate)
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)
d = int(input())
c = list(map(int,input().split()))
s = []
p = [1]*d
for i in range(d):
    s.append(list(map(int,input().split())))
x = [1]*26
for i in range(d):
    q = 1
    m = -1
    for j in range(26):
        n = s[i][j] + (d-i)x[j]*c[j]
        x[j] += 1
        if(m < n):
            m = n
            q = j
    x[q] *= 0
    p[i] = q+1
for i in range(d):
    print(p[i])

### FIXED CODE ###

import random as rd
d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
    s.append(list(map(int,input().split())))
for i in range(d):
    print(rd.randint(1,26))
import math


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    mul = a[0]
    for i in range(1, n):
        mul = mul * a[i] // math.gcd(mul, a[i])
    ans = (m - mul / 2) // mul + 1
    print(int(ans))


if __name__ == '__main__':
    main()

### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def div_ceil(x, y): return (x + y - 1) // y
 
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
    L *= a // gcd(L, a)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(input().split())
count = 0
for i in range(A, B+1):
    if f(i):
        count += 1
print(count)


### FIXED CODE ###

def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(int, input().split())
count = 0
for i in range(A, B+1):
    if f(str(i)):
        count += 1
print(count)
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()
def fact(n):
  if n==0:
    return 1
  else:
    s=1
    for i in range(1,n+1):
      s=s*i
def comb(n,k,mod):
  return (fact(n)//fact(k)//fact(n-k))%mod

if k>1:
  s=0
  for i in range(0,n-k):
    for j in range(i+k-1,n-1):
      s+=((a[j]-a[i])*comb(j-i-1,k-2,mod))%mod
  print(s%mod)
else:
  print(0)


### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
fan=[1]*(N+1)
for i in range(2,N):
  fan[i]=fan[i-1]*(i)%mod
ans=0
def comb(a,b):
  return fan[a]*pow(fan[b],mod-2,mod)*pow(fan[a-b],mod-2,mod)
for i in range(N-K+1):
  ans+=comb(N-i-1,K-1)*(A[N-i-1]-A[i])
  ans%=mod
print(ans)
ABCD=list(map(int, list(input())))
for i in range(1<<3):
    tmp=list(map(int, list(str(bin(i))[2:].zfill(3))))
    print(tmp)
    a=ABCD[0]
    for j in range(3):
        if tmp[j]:
            a+=ABCD[j+1]
        else:
            a-=ABCD[j+1]
    if a==7:
        print(ABCD[0], end="")
        for j in range(3):
            print("+" if tmp[j] else "-", end="")
            print(ABCD[j+1], end="")
        print("=7")
        exit(1)


### FIXED CODE ###

ABCD=list(map(int, list(input())))
for i in range(1<<3):
    tmp=list(map(int, list(str(bin(i))[2:].zfill(3))))
    a=ABCD[0]
    for j in range(3):
        if tmp[j]:
            a+=ABCD[j+1]
        else:
            a-=ABCD[j+1]
    if a==7:
        print(ABCD[0], end="")
        for j in range(3):
            print("+" if tmp[j] else "-", end="")
            print(ABCD[j+1], end="")
        print("=7")
        exit(0)
S=str(input())
if S=="ABC":
  print("ARC")
else if S=="ARC":
  print("ABC")

### FIXED CODE ###

S=str(input())
if S=="ABC":
  print("ARC")
elif S=="ARC":
  print("ABC")
n,k=int(input().split());print(0--~-n//~-k)

### FIXED CODE ###

n,k,*_=map(int,open(0).read().split())
print(0--~-n//~-k)
a,b,c,d = map(input().split())

if a='+' b='+' c='+' d='+':
	print('4')
elif a='+' b='+' c='+' d='-':
	print('2')
elif a='+' b='+' c='-' d='+':
	print('2')
elif a='+' b='+' c='-' d='-':
	print('0')
elif a='+' b='-' c='+' d='+':
	print('2')
elif a='+' b='-' c='+' d='-':
	print('0')
elif a='+' b='-' c='-' d='+':
	print('0')
elif a='+' b='-' c='-' d='-':
	print('-2')
elif a='-' b='+' c='+' d='+':
	print('2')
elif a='-' b='+' c='+' d='-':
	print('0')
elif a='-' b='+' c='-' d='+':
	print('0')	
elif a='-' b='+' c='-' d='-':
	print('-2')
elif a='-' b='-' c='-' d='+':
	print('-2')
elif a='-' b='-' c='+' d='-':
	print('-2')
elif a='-' b='-' c='-' d='+':
	print('-2')
else a='-' b='-' c='-' d='-':
	print('-4')




### FIXED CODE ###

S = input()

ans = 0
for i in range(len(S)):
    if S[i]=="+":
        ans += 1
    else:
        ans -= 1
        
print(ans)
#n = 候補の数
n = int(input())
#t - h[i] * 0.006
#a = 基準温度
t,a = map(int,input().split())
h = list(map(int,input().split()))
#o = 計算結果格納
o = []

for i in range(n):
    o.append(t - h[i] * 0.006)

#p = 基準温度に最も近い場所の差
p = abs(a - o[0])
#q = 基準地点の番号
q = 0
for i in range(n)[1:]:
    if abs(a - o[i]) < p:
        p = abs(a - o[i])
        q = i

print(q + 1)

### FIXED CODE ###

x,y = map(int,input().split())
print(x + (y // 2))
s=input()
l=[]
for i in s:l.append((123-ord(i))%26)
k=int(input())
for i,j in enumerate(l):
    if j<=k:l[i],k=26,k-j
l[-1]=(l[-1]-k)+[0,26][l[-1]-k<1]
for i,j in enumerate(l):l[i]=chr(123-j)
print(''.join(map(str,l)))

### FIXED CODE ###

s=input()
l=[]
for i in s:l.append((123-ord(i))%26)
k=int(input())
for i,j in enumerate(l):
    if j<=k:l[i],k=26,k-j
l[-1]=(l[-1]-k%26)+[0,26][l[-1]-k%26<1]
for i,j in enumerate(l):l[i]=chr(123-j)
print(''.join(map(str,l)))
n = int(input())
num_list = list(map(int, input().split()))
ans = 1
cnt_list = [0] * n

for i in range(1,n):
    if num_list[i-1] > num_list[i]:
        cnt_list[i] = -1
    if num_list[i-1] < num_list[i]:
        cnt_list[i] = 1

for i in range(1,n-1):
    if cnt_list[i] == -1 * cnt_list[1]:
        if cnt_list[i+1] == cnt_list[1] or cnt_list[i-1] == cnt_list[1]:
            ans+=1
if cnt_list[n-1] == -1 * cnt_list[1] and cnt_list[n-2] == cnt_list[1]:
    ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
num_list = list(map(int, input().split()))
ans = 1
cnt_list = [0] * n
a = int()

for i in range(1,n):
    if num_list[i-1] > num_list[i]:
        cnt_list[i] = -1
    if num_list[i-1] < num_list[i]:
        cnt_list[i] = 1

while 1 in cnt_list and -1 in cnt_list:
    del cnt_list[:max(cnt_list.index(1),cnt_list.index(-1))]
    cnt_list[0] = 0
    ans += 1

print(ans)
n = input('整数を入力してください：')

while n.isdigit() == False or int(n) < 1 or int(n) > 20:
    print('Error')
    n = input('整数を入力してください：')
else:
    n = int(n)
n = int(n)


a = input('整数を入力してください：')

while a.isdigit() == False or int(a) < 1 or int(a) > 50:
    print('Error')
    a = input('整数を入力してください：')
else:
    a = int(a)
a = int(a)

b = input('整数を入力してください：')

while b.isdigit() == False or int(b) < 1 or int(b) > 50:
    print('Error')
    b = input('整数を入力してください：')
else:
    b = int(b)
b = int(b)

train = n * a
taxi = b

expense = [train,taxi]

print(min(expense))

### FIXED CODE ###

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

train = n * a
taxi = b

expense = [train,taxi]

print(min(expense))
import numpy as np
n, q = map(int, input().split())
e = np.eye(n + 1, dtype=int)
point = np.zeros(n+1, dtype=int)
for i in range(n - 1):
    a, b = map(int, input().split())
    e[a][b] = 1
for i in range(q):
    p, x = map(int, input().split())
    point[p] += x

for i in range(1, n):
    for j in range(i+1,n):
        if e[i][j] == 1:
            e[i][j+1:] += e[j][j+1:]
        else:
            continue
ans = np.dot(point[1:], e[1:, 1:])
print(*ans)

### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())
tree = [[] for _ in range(n+1)]
cnt = [0] * (n+1)

for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p] += x

queue = deque([1])
visited = {1}
while queue:
    now = queue.popleft()
    visited.add(now)
    for t in tree[now]:
        if t in visited:
            pass
        else:
            queue.append(t)
            cnt[t] += cnt[now]

print(*cnt[1:])
x = raw_input
print (x**3)

### FIXED CODE ###

x = raw_input()
print int(x)**3
N=int(input())
L=list(map(int,input().split()))
count=0
0<=a<=N-1,0<=b<=N-1,0<=c<=N-1,a!=b, b!=c, c!=a
for a in range(N):
    for b in range(N):
        for c in range(N):
            if L[a]>(L[b]+L[c]),L[b]>(L[a]+L[c]),L[c]>(L[b]+L[a]):
                count=count+1
            else:
                continue
print(count)

### FIXED CODE ###

N=int(input())
L=list(map(int,input().split()))
count=0
for a in range(N):
    for b in range(N):
        for c in range(N):
            if L[a]<(L[b]+L[c]) and L[b]<(L[a]+L[c]) and L[c]<(L[b]+L[a]) and L[a]!=L[b] and L[a]!=L[c] and L[c]!=L[b] and a<b<c:
                count=count+1
            else:
                continue
print(count)
a,b,c,k = map(int,input())
if k<a:
    print(k)
elif k < a+b:
    print(a)
else:
    print(2*a+b-k)

### FIXED CODE ###

a,b,c,k = map(int,input().split())
if k<a:
    print(k)
elif k < a+b:
    print(a)
else:
    print(2*a+b-k)
N,M = map(int,input().spkit())
arr = []

for i in range(N):
  a,b,c = map(int,input().spkit())
  arr.append(int(a+b+c))

arr.sort(reverse=True)

print(int(sum(arr[:M])))

### FIXED CODE ###

N,M = map(int,input().split())
arr1 = []
arr2 = []
arr3 = []
arr4 = []
arr5 = []
arr6 = []
arr7 = []
arr8 = []

for i in range(N):
  a,b,c = map(int,input().split())
  arr1.append(int(a+b+c))
  arr2.append(int(a-b+c))
  arr3.append(int(a+b-c))
  arr4.append(int(a-b-c))
  arr5.append(int(-a+b+c))
  arr6.append(int(-a-b+c))
  arr7.append(int(-a+b-c))
  arr8.append(int(-a-b-c))

arr1.sort(reverse=True)
arr2.sort(reverse=True)
arr3.sort(reverse=True)
arr4.sort(reverse=True)
arr5.sort(reverse=True)
arr6.sort(reverse=True)
arr7.sort(reverse=True)
arr8.sort(reverse=True)

print(max(sum(arr1[:M]),sum(arr2[:M]),sum(arr3[:M]),sum(arr4[:M]),sum(arr5[:M]),sum(arr6[:M]),sum(arr7[:M]),sum(arr8[:M])))
x = [int(x) for x in input().split()]

import math

print(math.ceil(x[0]/x[1])

### FIXED CODE ###

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

import math

print(math.ceil(x[0]/x[1]))
a = input()
a[3] = '8'
print(a)


### FIXED CODE ###

a = input()
print('2018' + a[4:])
def solve():
    n = int(input())
    ans = [-1] * (n + 1)
    li = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        li[u].append((v, w))
        li[v].append((u, w))
    def f(i, ans, c):
        for u, w in li[i]:
            if ans[u] == -1:
                if w % 2 == 0:
                    ans[u] = c
                    f(u, ans, c)
                else:
                    ans[u] = c ^ 1
                    f(u, ans, c ^ 1)
    for i in range(1, n):
        if li[i] != [] and ans[i] == -1:
            ans[i] = 0
            f(i, ans, 0)
    print(*ans[1:], sep="\n")
solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def solve():
    n = int(input())
    ans = [-1] * (n + 1)
    li = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        li[u].append((v, w))
        li[v].append((u, w))
    def f(i, ans, c):
        if li[i] == []:
            return
        for u, w in li[i]:
            if ans[u] == -1:
                if w % 2 == 0:
                    ans[u] = c
                    f(u, ans, c)
                else:
                    ans[u] = c ^ 1
                    f(u, ans, c ^ 1)
    for i in range(1, n):
        if li[i] != [] and ans[i] == -1:
            ans[i] = 0
            f(i, ans, 0)
    print(*ans[1:], sep="\n")
solve()
H,W = map(int,input().split())
li = [input() for i in range(H)]
num_lists = []
for i in range(H):
    if "#" in li[i]:
    else :
        num_lists.append(i)
for i in reversed(num_lists):
    li.pop(i)
print(li)

### FIXED CODE ###

H,W = map(int,input().split())
li = [input() for i in range(H)]
num_lists = []
num_lists2 = []
for i in range(H):
    if "#" in li[i]:
        print("") 
    else :
        num_lists.append(i)
for i in reversed(num_lists):
    li.pop(i)
n_H = len(li)
for i in range(W) :
    ch_li = []
    for j in range(n_H):
        ch_li.append(li[j][i])
    if "#" in ch_li:
        print("")
    else :
        num_lists2.append(i)
for i in reversed(num_lists2):
    for k in range(n_H) :
        li[k] = li[k][:i]+li[k][(i+1):]
        
for i in li:
    for j in i:
        print(j,end="")
    print()
while 1:
    m=input().split()
    h=int(m[0])
    w=int(m[1])
    if a==0 & b==0:
      break
    for i in range(h):
      for j in range(w)
         print("#"*w)
      print()
    print()
    
    


### FIXED CODE ###

while True:
    v=input().split()
    a=int(v[0])
    b=int(v[1])
    if a==0 and b==0:
       break
    for i in range (a):
        print('#'*b)
    print()
N = input()
l = list(map(int, input().split()))

count=0
for i in range(len(l)-1):
    if i == len(l)-1:
        break
    if l[i] == l[i+1]:
        if l[i+1]+l[i+2]< 10000:
            l[i+1] = l[i]+l[i+2]
        else:
            l[i+1] = l[i]-l[i+2]
        count=count+1
print(count)


### FIXED CODE ###

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

count=0
for i in range(len(l)-1):
    if i == len(l)-2:
        if l[i] == l[i+1]:
            l[i] = l[i]+1
            count=count+1
            break
    if l[i] == l[i+1]:
        if l[i+1]+l[i+2]< 10000:
            l[i+1] = l[i]+l[i+2]
        elif l[i+1] - l[i+2] > 0:
            l[i+1] = l[i]-l[i+2]
        else:
            l[i+1] = l[i]+1
        count=count+1
print(count)
N = int(input())
A = list(map(int, input().split()))

ans = 1
res = 0

for i in range(N):
    ans *= A[i]
    ans %= 10 ** 9 + 7

for i in range(N):
    res += ans * pow(A[i], -1, 10 ** 9 + 7)
    res %= 10 ** 9 + 7

print(res)

### FIXED CODE ###

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

mod = 10 ** 9 + 7
ans = 0

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

for i in range(1, N):
    ans += A[i] * A_sum[i-1]
    ans %= mod

print(ans)
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import functools
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,X = map(int, sys.stdin.readline().split())
    x = list(map(int, sys.stdin.readline().split()))
    l=[]
    for i in range(N):
        l.append(abs(X-x[i]))
    ans = functools.reduce(math.gcd,l)
    print(ans)

### FIXED CODE ###

from functools import reduce
from fractions import gcd
N,X=map(int,input().split())
x=[abs(X-int(i)) for i in input().split()]
print(reduce(gcd,x))
import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
N,M = map(int,input().split())

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

graph=[[0]*8 for _ in range(8)]
def dfs(v,visited):
    if sum(visited) == N:
        return 1
    ret =0
    for i in range(N):
        if graph[v][i] == 1 and visited[i] == 0:
            visited[i]=1
            ret += dfs(i,visited)
            visited[i]=0
    return ret
def main():
    """code here"""

    for i in range(N):
        a=ab[i][0]
        b=ab[i][1]
        graph[a-1][b-1]=1
        graph[b-1][a-1]=1

    visited=[0]*N
    visited[0]=1
    print(dfs(0,visited))




    
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
N,M = map(int,input().split())

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

graph=[[0]*8 for _ in range(8)]
def dfs(v,visited):
    if sum(visited) == N:
        return 1
    ret =0
    for i in range(N):
        if graph[v][i] == 1 and visited[i] == 0:
            visited[i]=1
            ret += dfs(i,visited)
            visited[i]=0
    return ret
def main():
    """code here"""

    for i in range(M):
        a=ab[i][0]
        b=ab[i][1]
        graph[a-1][b-1]=1
        graph[b-1][a-1]=1

    visited=[0]*N
    visited[0]=1
    print(dfs(0,visited))
    
if __name__ == '__main__':
    main()
n,k=map(int,input().split())
a=list(map(int,input().split()))

lst=[0]*35


for i in a:
  for j in range(35):
    if (i>>j)%2==1:
      lst[j]+=1

k=bin(k)[2:]

dp=[[0]*2 for i in range(len(k)+1)]


for i in range(len(k)):
  if k[i]=='1':
    dp[i+1][0]=dp[i][0]+(n-lst[len(k)-i-1])*2**(len(k)-i-1)
    dp[i+1][1]=dp[i][0]+lst[len(k)-i-1]*2**(len(k)-i-1)
  
  else:
    dp[i+1][0]=dp[i][0]+lst[len(k)-i-1]**(len(k)-i-1)

  
  dp[i+1][1]=max(dp[i+1][1],dp[i][1]+lst[len(k)-i-1]*2**(len(k)-i-1),dp[i][1]+(n-lst[len(k)-i-1])*2**(len(k)-i-1))


print(max(dp[-1][0],dp[-1][1]))

### FIXED CODE ###

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

lst=[0]*50


for i in a:
  for j in range(50):
    if (i>>j)%2==1:
      lst[j]+=1

k=bin(k)[2:]

dp=[[0]*2 for i in range(len(k)+1)]


for i in range(len(k)):
  if k[i]=='1':
    dp[i+1][0]=dp[i][0]+(n-lst[len(k)-i-1]*2)*(2**(len(k)-i-1))
    dp[i+1][1]=dp[i][0]
  else:
    dp[i+1][0]=dp[i][0]

  if i==0:
      continue
  
  dp[i+1][1]=max(dp[i+1][1],dp[i][1],dp[i][1]+(n-lst[len(k)-i-1]*2)*(2**(len(k)-i-1)))


print(sum(a)+max(dp[-1][0],dp[-1][1]))
import sys
sys.setrecursionlimit(10 ** 9)

N, M, Q, *ABCD = map(int, open(0).read().split())

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == M:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max((solve(A + [i]) for i in range(A[-1], M + 1)))

print(solve([1]))

### FIXED CODE ###

from itertools import combinations_with_replacement

N, M, Q, *ABCD = map(int, open(0).read().split())

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))
S = input()
T = input()

for i in range(len(S)):
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
        S = S[:i] + T
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print("UNRESTORABLE")


### FIXED CODE ###

S = input()
T = input()
ans = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        tmp = S[:i] + T + S[i+len(T):]
        ans.append(tmp.replace('?', 'a'))
if ans:
    print(ans[-1])
else:
    print("UNRESTORABLE")
mod=10**9+7
n=int(input())
l=list(map(int,input().split()))
ans=1
rgb=[0,0,0]
for i in range(n):
    c=0
    for j in range(3):
        if l[i]==rgb[j]:
            c+=1
    p=rgb.index(l[i])
    if not 0<=p<=2:
        print(0)
        exit()
    rgb[p]+=1
    ans*=c
    ans%=mod
print(ans)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
ans=1
rgb=[0]*3
for i in range(n):
    f=0
    for j in range(3):
        if l[i]==rgb[j]:
            if f==0:
                rgb[j]+=1
            f+=1
    ans*=f
    ans%=mod
print(ans)
N = int(input())
A = list(map(int, input().split()))

def up(i,pre):
  if i == len(A) - 1:
    return abs(A[pre] - A[i])
  res1 = res2 = 0
  if i + 2 <=len(A) -1:
    res1 = up(i + 1,i)
    res2 = up(i + 2,i)
    return min(abs(A[pre] - A[i]) + res1, abs(A[pre] - A[i]) + res2)
  elif  i + 1 <=len(A) -1:
    res1 = up(i + 1,i)
    return abs(A[pre] - A[i]) + res1
  
if N>2:
 print(min(up(1,0),up(2,0)))
else:
  print(up(1,0))
    


  

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
dp = [0 for _ in range(len(A))]
dp[0] = 0 
for i in range(1,N):
    if i - 2>=0:
        dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
    else:
        dp[i] =dp[i-1] + abs(A[i] - A[i-1])

print(dp[len(A)-1])
from fractions import gcd


MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
A.sort(reversed=True)

lcm = A[0]

for a in A:
    lcm = (lcm * a) // gcd(lcm, a)

ans = 0
for a in A:
    ans += lcm // a
    ans %= MOD

print(ans)


### FIXED CODE ###

from fractions import gcd


MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

lcm = A[0]

for a in A:
    lcm = (lcm * a) // gcd(lcm, a)

ans = 0
for a in A:
    ans += (lcm % MOD) * pow(a, MOD - 2, MOD)
    ans %= MOD

print(ans)
while True:	
	H,W = map(int, input().split())
	if H==0 and W==0: break
	for y in range(0,H):
		for x in range(0,W):
			print("#",end="")
	    print('\n')



### FIXED CODE ###

while True:	
	H,W = map(int, input().split())
	if H==0 and W==0: break
	for y in range(0,H):
		for x in range(0,W):
			print("#",end="")
			
		print()
	print()
from math import pi

r = float(input())
area = lambda r: r * r * pi
length = lambda r: r * 2 * pi

print("{} {}".format(length(r), area(r))


### FIXED CODE ###

from math import pi

r = float(input())
area = lambda x: r * r * pi
length = lambda x: r * 2 * pi

print("{} {}".format(area(r), length(r)))
n = int(input())
a = [int(i) for i in input().split()]
q = 0
for i in range(n):
 for j in range(i+1, n):
  t = a[i]
  a[i] = a[j]
  a[j] = t
  f = 1  
  lst = - 1100
  for k in a:
   f &= k > lst
   lst = k
  q |= f
  t = a[i]
  a[i] = a[j]
  a[j] = t
print("YES" if q else "NO")


### FIXED CODE ###

a, b = [int(i) for i in input().split(" ")]
print("IMPOSSIBLE" if (a+b)%2 else (a+b)//2)