Harryxun/stf_run huggingface dataset:
def main():
  S_=input()
  T=input()
  U=[]
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S_[k]!='?':
          S[k]=S_[k]
      if ans=='':
        ans=''.join(S)
      elif ans>''.join(S):
        ans=''.join(S)
  if ans=='':
    print('UNRESTORABLE')
  else:
    print(ans)
  return

main()


### FIXED CODE ###


def main():
  S_=input()
  T=input()
  ans=''
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S_[k]!='?':
          S[k]=S_[k]
      if ans=='':
        ans=''.join(S)
      elif ans>''.join(S):
        ans=''.join(S)
  if ans=='':
    print('UNRESTORABLE')
  else:
    print(ans)
  return

main()
s, t = input().split(" ")
print(f"{t+s}")

### FIXED CODE ###

s, t = input().split(" ")
print(t+s)
arrayNM = list(map(int, input().split()))
array = list(map(int, input().split()))
route = [array[0] + arrayNM[0] - array[arrayNM[1] - 1]]
for i in range(1,arrayNM[1]):
  route.append(array[i] - array[i-1])
  
Max = max(route)
maxIndex = route.index(Max)
distance = 0

for i in range(0,maxIndex):
  distance += route[i]

for i in range(maxIndex + 1, array[1]):
  distance += route[i]

print(distance)
print(route)



### FIXED CODE ###

arrayNM = list(map(int, input().split()))
array = list(map(int, input().split()))
route = [array[0] + arrayNM[0] - array[arrayNM[1] - 1]]
for i in range(1,arrayNM[1]):
  route.append(array[i] - array[i-1])
  
Max = max(route)
maxIndex = route.index(Max)
distance = 0

for i in range(0,maxIndex):
  distance += route[i]

for i in range(maxIndex + 1, arrayNM[1]):
  distance += route[i]

print(distance)
n=int(input())
a=list(input().split(' '))
total=0
S_i=0
for i in range(n-1):
    S_i+=int(a[n-1-i])
    S_i=S_i%(7+10**9)
    total+=S_i*int(a[n-2-i])
    total=total%(7+10**9)
print(total)

### FIXED CODE ###

A=list(input().split())

if int(A[0])<=int(A[1])*int(A[2]):
  print('Yes')
else:
  print('No')
# -*- coding:utf-8 -*-
import sys

a=[int(i)-1 for i in sys.stdin]
N=l[0]+1
a=a[1:]

done=[False]*N

ans=0
i=0

while True:
  if done[i]==False:
    done[i]=True
    ans+=1
    if a[i]==1:
      break
    i=a[i]

  
  else:
    ans=-1
    break
    
print(ans)
    

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys

a=[int(i)-1 for i in sys.stdin]
N=a[0]+1
a=a[1:]

done=[False]*N

ans=0
i=0

while True:
  if done[i]==False:
    done[i]=True
    ans+=1
    if a[i]==1:
      break
    i=a[i]

  
  else:
    ans=-1
    break
    
print(ans)
a,b,c = map(int, input().split())
x,y,z = map(int, input().split())
print(c,a,b)
print(z,y,x)

### FIXED CODE ###

a, b, c = map(int, input().split())
print(c, a, b)
n,x,m = map(int,input().split())

def f(x,m):
    return x%m

ans = 0

for i in range(n):
    ans += x
    x = f(x**2,m)

print(ans)


### FIXED CODE ###

a = input()
if(a[-1]=="s"):
    a+="es"
else:
    a+="s"
print (a)
S=input()
T=input()

s_len =len(S)
t_len =len(T)

for head in range(len(S)-t_len,0,-1):
    flg=True
    for s,t in zip(S[head:head+t_len],T):
        if not(s==t or "?"==s):
            flg=False
    if flg:
        break


if flg:
    S=list(S)
    S[head:head+t_len] = T
    S="".join(S)
    S=S.replace("?","a")
    print(S)
else:
    print("UNRESTORABLE")

### FIXED CODE ###

S=input()
T=input()

s_len =len(S)
t_len =len(T)

flg=False

if s_len >= t_len:
    for head in range(len(S)-t_len,-1,-1):
        flg=True
        for s,t in zip(S[head:head+t_len],T):
            if not(s==t or "?"==s):
                flg=False
        if flg:
            break


if flg:
    S=list(S)
    S[head:head+t_len] = T
    S="".join(S)
    S=S.replace("?","a")
    print(S)
else:
    print("UNRESTORABLE")
N = int(input())
S = input()
K = int(input())

e = S[K-1]
for i in range(N):
  if S[i] != e:
    S[i] = '*'
print(S)

### FIXED CODE ###

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

Slist = list(S) 
e = Slist[K-1]
for i in range(N):
  if Slist[i] != e:
    Slist[i] = '*'
print("".join(Slist))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,m,k = map(int,input().split())

ans = 0
a= m*pow(m-1,n-1-k-1,mod)

for i in range(k,-1,-1):
  a =a*(m-1)%mod
  
  ans += a*cmb(n-1,i,mod)
  ans %= mod
  
print(ans)

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,m,k = map(int,input().split())

if k==n-1:
  print(pow(m,n,mod))
  exit()

ans = 0
a= m*pow(m-1,n-1-k-1,mod)

for i in range(k,-1,-1):
  a =a*(m-1)%mod
  
  ans += a*cmb(n-1,i,mod)
  ans %= mod
  
print(ans)
import sys
input = sys.stdin.readline
n = int(input())
abd = [list(map(int,input().split())) for i in range(n-1)]
if n == 2:
  print(abd[2])
  exit()
graph = [[] for i in range(n+1)]
deg = [0 for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
  graph[b].append((a,d))
  deg[a] += 1
  deg[b] += 1
stack = []
root = 0
dp = [1 for i in range(n+1)]
for i in range(1,n+1):
  if deg[i] == 1:
    stack.append(i)
  elif root == 0:
    root = i
    deg[i] += 1
ans = 0
flg = 0
while stack:
  x = stack.pop()
  for y,d in graph[x]:
    if deg[y] > 1:
      dp[y] += dp[x]
      if dp[x] == n-dp[x]:
        flg = 1
        ans += (dp[x]*2-1)*d
      else:
        ans += min(dp[x],n-dp[x])*2*d
      deg[y] -= 1
      if deg[y] == 1:
        stack.append(y)
if not flg:
  dmn = min(list(zip(*abd))[2])
  ans -= dmn
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
abd = [list(map(int,input().split())) for i in range(n-1)]
if n == 2:
  print(abd[0][2])
  exit()
graph = [[] for i in range(n+1)]
deg = [0 for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
  graph[b].append((a,d))
  deg[a] += 1
  deg[b] += 1
stack = []
root = 0
dp = [[] for i in range(n+1)]
sm = [1 for i in range(n+1)]
mx = [0 for i in range(n+1)]
for i in range(1,n+1):
  if deg[i] == 1:
    stack.append(i)
  elif root == 0:
    root = i
    deg[i] += 1
ans = 0
flg = 0
while stack:
  x = stack.pop()
  if dp[x]:
    sm[x] += sum(dp[x])
  if sm[x]*2 == n:
    flg = 1
  for y,d in graph[x]:
    if deg[y] > 1:
      dp[y].append(sm[x])
      if sm[x] == n-sm[x]:
        ans += (sm[x]*2-1)*d
      else:
        ans += min(sm[x],n-sm[x])*2*d
      deg[y] -= 1
      if deg[y] == 1:
        stack.append(y)
dmn = 10**18
if not flg:
  for a,b,d in abd:
    for v in (a,b):
      if not mx[v]:
        if dp[v]:
          mx[v] = max(max(dp[v]),n-1-sm[v])
        else:
          mx[v] = n-2
    if min(mx[a],mx[b])*2 < n:
      dmn = min(dmn,d)
  ans -= dmn
print(ans)
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def light_length(a:int, b:int) -> int:
    if a == b:
        return a

    return 2*a + light_length(min(a,b-a), max(a,b-a))

n,x = li()

print(n + light_length(x,n-x))  

### FIXED CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def light_length(a:int, b:int) -> int:
    if a > b:
        a,b = b,a
    
    if b%a == 0:
        return 2 * a * (b//a) - a

    return 2 * (b//a) * a + light_length(a, b%a)

n,x = li()

print(n + light_length(x,n-x))
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0185

"""
import sys
from sys import stdin
from bisect import bisect_left
input = stdin.readline


def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    nums = [x for x in range(2, limit+1)]
    while nums[0] <= x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x % current_prime != 0]
    primes.extend(nums)
    return primes


def main(args):
    primes = create_prime_list(500000)

    while True:
        # n = 98792
        n = int(input())
        if n == 0:
            break

        ans = 0                 #  ????????????????????????????????°
        for i in range(n):
            a = primes[i]
            if a > n/2:
                break
            i = bisect_left(primes, n - a)
            if i != len(primes) and primes[i] == n-a:
                ans += 1
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0185

"""
import sys
from sys import stdin
from bisect import bisect_left
input = stdin.readline


def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    nums = [x for x in range(2, limit+1)]
    while nums[0] <= x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x % current_prime != 0]
    primes.extend(nums)
    return primes


def main(args):
    primes = create_prime_list(1000000)

    while True:
        n = int(input())
        if n == 0:
            break

        ans = 0                 #  ????????????????????????????????°
        for i in range(n):
            a = primes[i]
            if a > n/2:
                break
            i = bisect_left(primes, n - a)
            if i != len(primes) and primes[i] == n-a:
                ans += 1
        print(ans)



if __name__ == '__main__':
    main(sys.argv[1:])
import itertools
for i in range(m):
  a,b=map(int,input().split())
  link[a-1].append(b-1)
  link[b-1].append(a-1)
s=list(range(1,n))
res=0
for perm in list(itertools.permutations(s)):
  last=0
  ok=True
  for i in range(n-1):
    if perm[i] not in link[last]:
      ok=False
      break
    else:
      last=perm[i]
  if ok==True:
    res=res+1
print(res)

### FIXED CODE ###

import itertools
n,m=map(int,input().split())
link=[[]for j in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  link[a-1].append(b-1)
  link[b-1].append(a-1)
s=list(range(1,n))
res=0
for perm in list(itertools.permutations(s)):
  last=0
  ok=True
  for i in range(n-1):
    if perm[i] not in link[last]:
      ok=False
      break
    else:
      last=perm[i]
  if ok==True:
    res=res+1
print(res)
N, M=map(int, input().split())
mat = [[0 for m in range(M)]for n in range(N)]
vec = [0 for m in range(M)]

for n in range(N):
  mat[n] = list(map(int , input().split()))
for m in range(m):
  vec[m] = int(input())

c = 0
for n in range(N):
 for m in range(M):
  c += mat[n][m] * vec[m]
 print(c)
 c = 0

### FIXED CODE ###

N, M=map(int, input().split())
mat = [[0 for m in range(M)]for n in range(N)]
vec = [0 for m in range(M)]

for n in range(N):
  mat[n] = list(map(int , input().split()))
for m in range(M):
  vec[m] = int(input())

c = 0
for n in range(N):
 for m in range(M):
  c += mat[n][m] * vec[m]
 print(c)
 c = 0
n=int(input())
dat=list(map(int, input().split()))
      
re = 0

while (True):
       for e in dat:
            if e%2==1:
                break
                return re
            else:
                e = e/2
         re = re+1

print(re)

### FIXED CODE ###

import sys

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1
 
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None
 
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)
 
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])
 
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
 
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


n,Q=map(int,input().split())

N=1000000
INF = 2**31-1
 
LV = (N-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
 

a=[list(map(int,input().split())) for i in range(n)]
a.sort(key=lambda x:x[2],reverse=True)

a=[ [ max(0,a[i][0]-a[i][2]) , max(0,a[i][1]-a[i][2]) , a[i][2] ] for i in range(n)]

for i in range(n):
    l,r,x=a[i][0],a[i][1],a[i][2]
    update(l,r,x)

for i in range(Q):
    dp=int(input())
    ans=query(dp,dp+1)
    print(-1 if ans==INF else ans)

### FIXED CODE ###

def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

    n,q=map(int,input().split())

    event=[]
    for _ in range(n):
        s,t,x=map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(input()),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
N = int(input())
S = list(set(map(int, input().split())))
S.sort()
Q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in range(Q):
    OK = 0
    NG = N
    while abs(OK-NG)>1:
        mid = (OK+NG)//2
        if S[mid]<=T[i]:
            OK = mid
        else:
            NG = mid
    if S[OK] == T[i]:
        ans += 1

print(ans)


### FIXED CODE ###

N = int(input())
S = list(set(map(int, input().split())))
S.sort()
Q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in range(Q):
    OK = 0
    NG = len(S)
    while abs(OK-NG)>1:
        mid = (OK+NG)//2
        if S[mid]<=T[i]:
            OK = mid
        else:
            NG = mid
    if S[OK] == T[i]:
        ans += 1

print(ans)
import sys
input = sys.stdin.readline

l,r,d = map(int,input().split())
cnt=0
for i in range(l,r+1):
    if i%d=0:
        cnt+=1
print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline

l,r,d = map(int,input().split())
cnt=0
for i in range(l,r+1):
    if i%d==0:
        cnt+=1
print(cnt)
h, w, m = map(int, input().split())
HW = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]

# print(h,w,m)
HW.sort()
# print(*HW,sep='\n')
# print('---')

sum_h = [[0,0] for _ in range(h)] # [sum, index]
sum_w = [[0,0] for _ in range(w)]


for i in range(m):
    # print(h,w)
    h,w = HW[i]
    sum_h[h][0] += 1
    sum_w[w][0] += 1
    sum_h[h][1] = h
    sum_w[w][1] = w

# # print('---')
# # print(sum_h)
# # print(sum_w)
# # print('---')
sum_h.sort(reverse=True)
sum_w.sort(reverse=True)
# print(sum_h)
# print(sum_w)
# print('---')

from bisect import *

# print(HW)

max_bombs = 0
if sum_h[0][0] > sum_w[0][0]:
    h_bombs, h_index = sum_h[0]
    for w_bombs, w_index in sum_w:
        bombs = h_bombs + w_bombs
        ix = bisect_left(HW, [h_index, w_index])
        # print('ix {}'.format(ix))
        # if [h_index, w_index] in HW:
        if [h_index, w_index] ==  HW[ix]:
            bombs -= 1
        if max_bombs < bombs:
            max_bombs = bombs

else:
    for h_bombs, h_index in sum_h:
        bombs = sum_w[0][0] + h_bombs
        if [h_index, sum_w[0][1]] in HW:
            bombs -= 1
        if max_bombs < bombs:
            max_bombs = bombs

print(max_bombs)


### FIXED CODE ###

h, w, m = map(int, input().split())
HW = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]

sum_h = [[0,0] for _ in range(h)] # [sum, index]
sum_w = [[0,0] for _ in range(w)]
for i in range(m):
    h,w = HW[i]
    sum_h[h][0] += 1
    sum_w[w][0] += 1
    sum_h[h][1] = h
    sum_w[w][1] = w

h_num_ix = {}
for num,ix in sum_h:
    if not num in h_num_ix:
        h_num_ix[num] = set()
    h_num_ix[num].add(ix)

w_num_ix = {}
for num,ix in sum_w:
    if not num in w_num_ix:
        w_num_ix[num] = set()
    w_num_ix[num].add(ix)

max_h_num = max(h_num_ix)
max_w_num = max(w_num_ix)

# print(sorted(HW))
# print('---')
# print(h_num_ix)
# print(w_num_ix)
# print(max_h_num)
# print(max_w_num)
# print('====')

SHW = set()
for h,w in HW:
    SHW.add((h,w))
# print(SHW)

max_num = max_h_num + max_w_num - 1
for h_ix in h_num_ix[max_h_num]:
    for w_ix in w_num_ix[max_w_num]:
        num = max_h_num + max_w_num
        # if [h_ix, w_ix] in HW: continue
        if (h_ix, w_ix) in SHW: continue
        max_num += 1
        print(max_num)
        exit()
print(max_num)
s=input()
K=int(input())
p=set()
for i in range(len(s)):
  for j in range(1,6):
    if i+j<=len(s)-1:
      p.add(s[i:j+i])
p=sorted(p)
print(p[K-1])

### FIXED CODE ###

s=input()
s=s+'0'
K=int(input())
p=set()
for i in range(len(s)):
  for j in range(1,6):
    if i+j<=len(s)-1:
      p.add(s[i:j+i])
p=sorted(p)
print(p[K-1])
S = list(input())
N, = list(map(int,input().split()))

ans = 1

for i in range(len(S)):
    if  not S[i] == '1':
        ans = int(S[i])
        break

if  len(S) == 1:
    ans = int(S[1])
        
print(ans)


### FIXED CODE ###

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

ans = 1
num_1 = 0

for i in range(len(S)):
    if  not S[i] == '1':
        ans = int(S[i])
        break
    else:
        num_1 += 1

if  len(S) == 1:
    ans = int(S[0])
if  num_1 >= N:
    ans = 1
        
print(ans)
import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * round(math.cos(deg_a),10)
    x_a = a * round(math.sin(deg_a),10)

    y_b = b * round(math.cos(deg_b),10)
    x_b = b * round(math.sin(deg_b),10)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input()]
    print(solve(a, b, h, m))

### FIXED CODE ###

import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * math.cos(deg_a)
    x_a = a * math.sin(deg_a)

    y_b = b * math.cos(deg_b)
    x_b = b * math.sin(deg_b)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input().split()]
    print(solve(a, b, h, m))
H,N = map(int,input().split())

AB = []

for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [0]*(H+1)

for i in range(1,H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(dp[H])

### FIXED CODE ###

H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))
n,k=map(int, input().split())
s=input()

s_list=[]
for i in s:
    if i=="L":s_list.append(0)
    else:s_list.append(1)
start_num=s_list[0]
i=0
while k>0:
    if s_list[i]!=start_num:
        k-=1
        while i<n and s_list[i]!=start_num:
            s_list[i]=start_num
            i+=1
    i+=1
ans=0
for i in range(n):
    if i+1<n and s_list[i]==1 and s_list[i+1]==1:
        ans+=1
    if i-1>=0 and s_list[i]==0 and s_list[i-1]==0:
        ans+=1
print(ans)

### FIXED CODE ###

n,k=map(int, input().split())
s=input()

s_list=[]
for i in s:
    if i=="L":s_list.append(0)
    else:s_list.append(1)
start_num=s_list[0]
i=0
while k>0:
    if i>=n:break
    if s_list[i]!=start_num:
        k-=1
        while i<n and s_list[i]!=start_num:
            s_list[i]=start_num
            i+=1
    i+=1
ans=0
for i in range(n):
    if i+1<n and s_list[i]==1 and s_list[i+1]==1:
        ans+=1
    if i-1>=0 and s_list[i]==0 and s_list[i-1]==0:
        ans+=1
print(ans)
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

n,q = LI()

v = [[] for i in range(n)]
for i in range(n-1):
  a,b = LI()
  a -= 1 # listのindex参照をそのまま使いたいので頂点id(1から始まっている)を-1しておく
  b -= 1 # aと同様
  v[a].append(b)
  v[b].append(a)

f = [0]*n
for i in range(q):
  p,x = LI()
  p -= 1 # aと同様
  f[p] += x

def dfs(x,d,s): # x:計算する頂点（上側）, d:計算済み(0)か否か(1), s:頂点xの値
  for y in v[x]: # 頂点xとつながる各頂点yの計算を行う
    if d[y]: # 頂点yが計算未了の場合
      s += f[y] # 頂点xの値sに頂点yの値を足す
      ans[y] = s # 頂点yの値はsに確定
      d[y] = 0 # 頂点yの計算は終わったのでd[y]=0とする
      dfs(y,d,s) # 頂点yの下層についても再帰的に計算
      s -= f[y] # 頂点yの下層の計算が終わったので、sを頂点xの値に戻す

ans = [0]*n
d = [1]*n
d[0] = 0
ans[0] = f[0]
s = f[0]
dfs(0,d,s)
print(*ans)

### FIXED CODE ###

n, q = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a - 1].append(b-1)
    connect[b - 1].append(a - 1)
    
values = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    values[p - 1] += x

from collections import deque
que = deque([[-1, 0]])
while que:
    parent, child = que.popleft()
    for num in connect[child]:
        if num == parent:
            continue
        values[num] += values[child]
        que.append([child, num])
print(*values)