Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,s=map(int,input().split())
  l.append([a,s])
l=sorted(l)
p=0
c=0
for i in l:
  if c+l[i][1]>m:
    p+=l[i][0]*(m-c)
    break
  else:
    p+=l[i][0]*l[i][1]
    c+=l[i][1]
print(p)

### FIXED CODE ###

n,m=map(int,input().split())
l=[]
for i in range(n):
  a,s=map(int,input().split())
  l.append([a,s])
l=sorted(l)
p=0
c=0
for i in range(len(l)):
  if c+l[i][1]>m:
    p+=l[i][0]*(m-c)
    break
  else:
    p+=l[i][0]*l[i][1]
    c+=l[i][1]
print(p)
a = [0 for i in range(26)]
while 1:
    s = input()
    if s == "-1":
        break
    print(s)
    for i in s:
        if i.isalnum():
            c = ord(i.lower())
            a[c-97] += 1

for i in range(26):
    print(chr(i+97) + " : " + str(a[i]))

### FIXED CODE ###

import sys
cnts = {}
for line in sys.stdin:
    for c in list(line.lower()): cnts[c] = cnts.get(c,0) + 1
  
for c in range(ord('a'),ord('z')+1): print(chr(c),':',cnts.get(chr(c),0))
N = int(input())
A = sorted([int(i) for i in input().split()])

if A[0] == A[N-1]:
    print(A[0])
elif all([a % A[0] == 0 for a in A]):
    print(A[0])
elif all([a % 2 == 0 for a in A]):
    print(2)
    exit()
a = sorted(list(set(A)))
a1 = a[0] 
a2 = a[1]
a = max(a1,a2)
b = min(a1,a2)
while a != b:
    t = a - b
    a = max(t, b)
    b = min(t, b)
if a != 0:
    print(a)
else:
    print(1)

### FIXED CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = sorted([int(i) for i in input().split()])
print(reduce(lambda a, b: gcd(a, b), A))
n=int(input())
p=input().split()  
p=list(map(int,p))          
cnt=0

for i in range(n-2):
  l=p[i:i+2]
  if l[0]>=l[1] and l[1]>=l[2]:
    cnt+=1
  if l[2]>=l[1] and l[1]>=l[0]:
    cnt+=1

print (cnt)



### FIXED CODE ###

n=int(input())
p=input().split()  
p=list(map(int,p))          
cnt=0

for i in range(n-2):
  l=p[i:i+3]
  if l[0]>=l[1] and l[1]>=l[2]:
    cnt+=1
  if l[2]>=l[1] and l[1]>=l[0]:
    cnt+=1

print (cnt)
n,m=[int(x) for x in input().split()]
if(n==m):
  print("Yes")
 else:
  orint("No")

### FIXED CODE ###

n,m=[int(x) for x in input().split()]
if(n==m):
  print("Yes")
else:
  print("No")
n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  if l.count(x) == x:
    continue
  elif l.count(x) > x:
    count += l.count(x) - x
  else:
    count += l.count(x)
print(count)

### FIXED CODE ###

import math
a,b = map(int,input().split())
print(math.ceil((a+b)/2))
N, K = map(int, input().split())

tree = []
for _ in range(n):
    tree.append(int(input()))

tree.sort()
ans = 10**9
for i in range(N-K+1):
    ans = min(ans, tree[i+K-1]-tree[i])
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())

tree = []
for _ in range(N):
    tree.append(int(input()))

tree.sort()
ans = 10**9
for i in range(N-K+1):
    ans = min(ans, tree[i+K-1]-tree[i])
print(ans)
q = int(input())
l = [list(map(int,input().split())) for _ in range(q)]

def prime_table(n):
    list = [True for _ in range(n+1)]
    for i in range(2,int(n**0.5)+1):
        if list[i]:
            j = i*2
            while j<=n:
                list[j] = False
                j += i
    table = [i for i in range(n+1) if list[i] and i>=2]
    return table

table = prime_table(10**5)
table = set(table)
sim_sum = [0]*(10**5+1)

for i in range(len(table)):
    if table[i]*2-1 in table:
        sim_sum[table[i]*2-1] += 1
for i in range(1,10**5+1):
    sim_sum[i] += sim_sum[i-1]
for l_ in l:
    print(sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])

### FIXED CODE ###

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

def prime_table(n):
    list = [True for _ in range(n+1)]
    for i in range(2,int(n**0.5)+1):
        if list[i]:
            j = i*2
            while j<=n:
                list[j] = False
                j += i
    table = [i for i in range(n+1) if list[i] and i>=2]
    return table

table = prime_table(10**5)
sim_sum = [0]*(10**5+1)

for i in range(len(table)):
    if table[i]*2-1 in table:
        sim_sum[table[i]*2-1] += 1
for i in range(1,10**5+1):
    sim_sum[i] += sim_sum[i-1]
for l_ in l:
    print(sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])
a=int(input())
b=0
c=0
list=list(map(int,input().split()))
for i in range(a-1):
    if list[i]-list[i+1]<=0:
        continue
    elif list[i]-list[i+1]==1:
        if i+2<=a-1:
            if list[i+1]-list[i+2]==1:
                c=1
                print("No")
                break
        continue
    elif list[i]-list[i+1]>=2:
        c=1
        print("No")
        break
if c==0:
    print("Yes")


### FIXED CODE ###

a,b,c=(int(x) for x in input().split())
d=c-a+b
if d<=0:
    print(0)
else:
    print(d)
h, w = map(int, input().split())

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=i+DX[k]<=w and 0<=j+DY[k]<=h):
                continue
            if s[i + DX[k]][j + DY[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")


### FIXED CODE ###

h, w = map(int, input().split())

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=j+DX[k]<=w-1 and 0<=i+DY[k]<=h-1):
                continue
            if s[i + DY[k]][j + DX[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")
import math
a, b = map(int, input().split())
print(int(a * b / math.gcd(a, b)))


### FIXED CODE ###

import fractions
a, b = map(int, input().split())
print(int(a * b / fractions.gcd(a, b)))
import sys

num = 0

while check == True:
 x = sys.stdin.readline().strip()
 if x == "0":
  check = False
 
 num = num + 1
 
 print("case " + str(num) + ": " + x")
 

### FIXED CODE ###

import sys
num = 0
while 1:
    x = sys.stdin.readline().strip()
    if x == "0":
        break
    num = num + 1
    print("Case " + str(num) + ": " + x)
A, B, X = map(int, raw_input().split(" "))
if (X-A)<=B and X>A: print("YES")
else: print("NO")

### FIXED CODE ###

A, B, X = map(int, input().split(" "))
if X==A: print("YES")
elif X<A: print("NO")
else:
  if (X-A)<=B: print("YES")
  else: print("NO")
assert N==1
print(114515)

### FIXED CODE ###

N = int(input())
ans = "Yes"
t_before = 0
x_before, y_before = 0, 0

for _ in range(N):
    ti, xi, yi = map(int, input().split())
    t_dist = abs(ti - t_before)
    x_dist = abs(xi - x_before)
    y_dist = abs(yi - y_before)
    xy_dist = x_dist + y_dist
    if xy_dist <= t_dist:
        if (t_dist % 2 == 0 and xy_dist % 2 == 0) or (t_dist % 2 == 1 and xy_dist % 2 == 1):
            t_before = ti
            x_before = xi
            y_before = yi
            continue
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break

print(ans)
cnt = 0
a_sum = []
i = 0
l = 0 
for i in range(n):
    a_sum.append(a[i])
    l += a(i)
    while l >= k:
      	l -= a_sum[0]
        cnt += n - i
        a_sum.pop(0)
        
print(cnt)

### FIXED CODE ###

x, a = map(int, input().split())
print("10") if x >= a else print("0")
a, b, c = map(int,input().split())
if a+b+c <= 21:
  print("win")
  else a+b+c >= 21:
    print("bust")
    

### FIXED CODE ###

a, b, c = map(int,input().split())
if a+b+c <= 21:
  print("win")
else:
    print("bust")
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

max_score = -float('inf')

for i in range(n):
    loop_score_array = []
    loop_score = 0
    loop_len = 0
    pos = i
    while True:
        pos = p[pos] - 1
        loop_score += c[pos]
        loop_score_array.append(loop_score)
        loop_len+=1
        if pos == i:
            break
    for i, score in enumerate(loop_score_array):
        if k-i-1 < 0:
            continue
        loop_num = (k-i-1)//loop_len
        score_sum = score + max(0, loop_score)*loop_num
        max_score = max(score_sum, max_score)
print(max_score)

### FIXED CODE ###

S = input()

day = 0
max_day = 0
for s in S:
    if s == 'R':
        day += 1
        max_day = max(day, max_day)
    else:
        day = 0

print(max_day)
n = list(input())
count = 0

for i in n:
    if i == "1":
        n[count] = "9"
    elif i == "9":
        n[count] = "1"
    count += 1

print("".job(n))

### FIXED CODE ###

n = list(input())
count = 0

for i in n:
    if i == "1":
        n[count] = "9"
    elif i == "9":
        n[count] = "1"
    count += 1

print("".join(n))
import math
a,b = map(float,input().split())
A = int(a)
print(math.floor(A*B))


### FIXED CODE ###

import math
a,b = map(str, input().split())
b = b.replace(".","")
a = int(a)
b = int(b)
print(a * b // 100)
N = input()
A = input()
print((N*N)-A)

### FIXED CODE ###

N = int(input())
A = int(input())
print(N*N - A)
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
isRoot = [True] * n
for _ in range(n - 1 + m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    isRoot[b] = False

for i in range(n):
    if isRoot[i]:
        root = i
        break
INF = 10 ** 20
stack = [(root, -1, 0)]
height = [-INF] * n
parent = [None] * n
def search(stack):
    node, par, score = stack.pop()
    if score > height[node]:
        height[node] = score
        parent[node] = par
        for to in edges[node]:
            stack.append((to, node, score + 1))

while stack:
    search(stack)

for i in range(n):
    print(parent[i] 

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

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

visited = [False] * n
lst = []
def search(x):
    if not visited[x]:
        visited[x] = True
        for to in edges[x]:
            search(to)
        lst.append(x)

for i in range(n):
    search(i)
lst.reverse()
dic = {}
for i in range(n):
    dic[lst[i]] = i

parent = [-1] * n
for i in lst:
    if not revEdges[i]:
        continue
    maxScore = -1
    index = -1
    for fr in revEdges[i]:
        if maxScore <= dic[fr]:
            maxScore = dic[fr]
            index = fr
    parent[i] = index

for i in range(n):
    print(parent[i] + 1)
H,W=[int(i) for i in input().split()
ans=[]
for i in range(H):
 lis =input()
 ans.append(lis)
 ans.append(lis)

print(ans)

### FIXED CODE ###

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

for i in range(H):
    line = input()
    print(line)
    print(line)
N=int(input())
INL=list(map(int,input().split()))

swp = 0
for i in range(0, N):
    if i+1 == INL[i]:
        INL[i] = INL[i] ^ INL[i+1]
        INL[i+1] = INL[i] ^ INL[i+1]
        INL[i] = INL[i] ^ INL[i+1]
        swp += 1

print(swp)


### FIXED CODE ###

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

swp = 0
for i in range(0, N-1):
    if i+1 == INL[i]:
        INL[i] = INL[i] ^ INL[i+1]
        INL[i+1] = INL[i] ^ INL[i+1]
        INL[i] = INL[i] ^ INL[i+1]
        swp += 1

if INL[N-1] == N:
    INL[N-1], INL[N-2] = INL[N-2], INL[N-1]
    swp += 1

print(swp)
X=int(input())
Y=int(X**(0.2))
for i in range(Y,-Y,-1):
    for t in (-Y//2,Y,1):
        if i**5-t**5==X:
            S=i
            Z=t
            break
print(S,Z)

### FIXED CODE ###

S=input()
print('ABC' if S=='ARC' else 'ARC')
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

cumsum=0
cnt=0
i=0
j=0
while cumsum<k:
    if i>len(a)-1:
        a_i=float('inf')
    else:
        a_i=a[i]

    if j>len(b)-1:
        a_i=float('inf')
    else: 
        b_i=b[j]   

    if a_i<=b_i:
        cumsum+=a[i]
        i+=1
    else:
        cumsum+=b[j]
        j+=1

    if cumsum<=k:
        cnt+=1
    else:
        break

    if i==len(a)-1 and j==len(b)-1:
        break
    
print(cnt)

### FIXED CODE ###

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if capa<0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+j)
            
print(ans)
S=input()
n=len(S)
a=0
b=0
for i in range((n-1)/2):
	if S[i]!=S[n-i]:
    	a=1
        print("No")
        break;
p=""
q=""
if a==0:
	for i in range((n-1)/2):
		p.append(S[i])
    	q.append(S[i+1+(n-1)/2])
	for i in range((len(p)-1)/2):
  		if p[i]!=p[len(p)-i] or q[i]!=q[len(p)-i]:
        	b=1
            print("No")
            break;
if a==0 and b==0:
	print("Yes")


### FIXED CODE ###

S=input()
n=len(S)
a=0
b=0
for i in range(1,int(n/2)+1):
    if S[i-1]!=S[n-i]:
        a=1
        print("No")
        break;
p=[]
q=[]
if a==0:
    for i in range(1,int(n/2)+1):
        p.append(S[i-1])
        q.append(S[i+int(n/2)])
    #print(p,q)
    for i in range(1,int((len(p))/2)+1):
        #print(p[i-1],p[len(p)-i],q[i-1],q[len(p)-i])
        if p[i-1]!=p[len(p)-i] or q[i-1]!=q[len(p)-i]:
            b=1
            print("No")
            break;
if a==0 and b==0:
    print("Yes")
from itertools import*
_, s = open(0)
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))

### FIXED CODE ###

from itertools import*
input();s = input()
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))
for i in range (1,6):
  if(x(i) == 0):
    print(i)

### FIXED CODE ###

*x, = map(int,input().split())
print(x.index(0)+1)
# D - Knight

X, Y = map(int, input().split())
####

a = (2*Y - X) / 3
b = (2*X - Y) / 3

import math

if a%1 != 0 or b%1 != 0:
    print(0)
else:
    a = int(a)
    b = int(b)
    # 最短経路の数 nCr
    ans = (math.factorial(a + b) // (math.factorial(a) * math.factorial(b))) % (10**9 + 7)

    print(ans)


### FIXED CODE ###

# D - Knight

X, Y = map(int, input().split())
####

a = (2*Y - X) / 3
b = (2*X - Y) / 3

# https://qiita.com/derodero24/items/91b6468e66923a87f39f
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] % mod * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
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 )

if a%1 != 0 or b%1 != 0:
    print(0)
else:
    ans = cmb(int(a+b), int(min(a,b)), mod)
    print(ans)
import sys
input = sys.stdin.readline
import math

def main():
    A, B, C, D = list(map(int, input().split()))
    lcm = C * D / math.gcd(C, D)

    Ac = int(A/C)
    if A % C == 0:
        Ac-=1

    Bc = int(B/C)
    cnum = Bc - Ac

    Ad = int(A/D)
    if A % D == 0:
        Ad-=1

    Bd = int(B/D)
    dnum =Bd - Ad

    Alcm = int(A/lcm)
    if A % lcm == 0:
        Alcm-=1

    Blcm = int(B/lcm)
    lcmnum = Blcm - Alcm

    print(B - A + 1 - (cnum + dnum - lcmnum))

main()

### FIXED CODE ###

import sys

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a



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



def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)

    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()
n=int(input())
l=[]
for i in range(n):
  m=int(input())
  l.append(m)
c=0
d=1
e=l[0]
l=sorted(l)
for i in range(1,n):
  if l[i]!=e:
    if d%2==1:
      c+=1
    e=l[i]
    d=1
  else:
    d+=1
if d%2==1:
  c+=1
print(c)


### FIXED CODE ###

n=list(input())
if "9" in n:
  print("Yes")
else:
  print("No")
from collections import deque

h, w = map(int, input().split())
p = [list(input()) for i in range(h)]

# メモ配列
INF = 10**7
# memo = [[INF]*w for i in range(h)]

# 探索用ベクトル
vx = (0, -1, 0, 1)
vy = (-1, 0, 1, 0)

# 幅探索用キューの準備
# 白マスをカウント
q = deque()
bcnt = 0
for i, vi in enumerate(p):
    for j, vj in enumerate(vi):
        if vj == '#':
            q.appendleft((j, i))
            bcnt+=1
            
qans = deque()
            
def bfs(q):
    for i in range(INF):
        # キューが空なら終了
        if len(q) == 0:
            return qans

        # キューから一つ取り出す
        x, y = map(int, q.pop())
#         print('xy', x, y)

        # 4方向のいずれかに白があれば、黒にする
        for j in range(4):
            nx, ny = x+vx[j], y+vy[j]

            # エリア外 or 黒色なら探索しない
            if nx < 0 or w <= nx or ny < 0 or h <= ny or p[ny][nx] == '#':
                continue

            p[ny][nx] = '#'
            memo[ny][nx] = 1
            qans.appendleft((nx, ny))

def printmap(a):
    for i in a:
        print(i)
        
# print(q)
# printmap(p)
for i in range(INF):
    qans = deque()
    q = bfs(q)
#     print(q)
#     printmap(p)
    # キューが空なら終了
    if len(q) == 0:
        ans = i
        break
    
print(ans)
# print(q)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
p = [list(input()) for i in range(h)]

# メモ配列
INF = 10**7
# memo = [[INF]*w for i in range(h)]

# 探索用ベクトル
vx = (0, -1, 0, 1)
vy = (-1, 0, 1, 0)

# 幅探索用キューの準備
# 白マスをカウント
q = deque()
bcnt = 0
for i, vi in enumerate(p):
    for j, vj in enumerate(vi):
        if vj == '#':
            q.appendleft((j, i))
            bcnt+=1
            
qans = deque()
            
def bfs(q):
    for i in range(INF):
        # キューが空なら終了
        if len(q) == 0:
            return qans

        # キューから一つ取り出す
        x, y = map(int, q.pop())
#         print('xy', x, y)

        # 4方向のいずれかに白があれば、黒にする
        for j in range(4):
            nx, ny = x+vx[j], y+vy[j]

            # エリア外 or 黒色なら探索しない
            if nx < 0 or w <= nx or ny < 0 or h <= ny or p[ny][nx] == '#':
                continue

            p[ny][nx] = '#'
            qans.appendleft((nx, ny))

def printmap(a):
    for i in a:
        print(i)
        
# print(q)
# printmap(p)
for i in range(INF):
    qans = deque()
    q = bfs(q)
#     print(q)
#     printmap(p)
    # キューが空なら終了
    if len(q) == 0:
        ans = i
        break
    
print(ans)
# print(q)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

### FIXED CODE ###

import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))
import math
A,B,H,M = map(int,input().split())
if (M/60)*12 == H:
    print(A+B)
elif (M/60)*12 == H + 6 or (M/60)*12 == H - 6:
    print("0")
elif H == 0:
    shita = math.radians(M*6)
        if shita > math.pi:
        shita = 2*math.pi - shita
    cos_shita = math.cos(shita)
    c_zizyou = A**2 + B**2 - 2 * A * B * cos_shita
    print(math.sqrt(c_zizyou))
elif M == 0:
    shita = math.radians(H*30)
        if shita > math.pi:
        shita = 2*math.pi - shita
    cos_shita = math.cos(shita)
    c_zizyou = A**2 + B**2 - 2 * A * B * cos_shita
    print(math.sqrt(c_zizyou))
else:
    H = H/12 * 60
    H = H + (1/12 * M)
    shita = math.radians(abs(H-M)*6)
        if shita > math.pi:
        shita = 2*math.pi - shita
    cos_shita = math.cos(shita)
    c_zizyou = A**2 + B**2 - 2 * A * B * cos_shita
    print(math.sqrt(c_zizyou))


### FIXED CODE ###

import math
A,B,H,M = map(int,input().split())


H = H/12 * 60
H = H + (1/12 * M)
shita = math.radians(abs(H-M)*6)
if shita > math.pi:
    shita = 2*math.pi - shita
cos_shita = math.cos(shita)
c_zizyou = A**2 + B**2 - 2 * A * B * cos_shita
print(math.sqrt(c_zizyou))
gohya, hya, goju = map(int, input('500,100,50').split())
total = int(input('total'))
count = 0
for gh in range(gohya+1):
	for hy in range(hya+1):
		for gj in range(goju+1):
			if 500*gh + 100*hy + 50*gj == total:
				count += 1
print(count)

### FIXED CODE ###

gohya =int(input())
hya = int(input())
goju = int(input())
total = int(input())
count = 0
for gh in range(gohya+1):
	for hy in range(hya+1):
		for gj in range(goju+1):
			if 500*gh + 100*hy + 50*gj == total:
				count += 1
print(count)
N, M = map(int, input().split())

sys.setrecursionlimit(10**9)
 
vertices = [[] for i in range(N+1)]
dp = [-1] * (N+1)
 
for _ in range(M):
    fro, to = map(int, input().split())
    vertices[fro].append(to)

def dfs(i):
    
    if dp[i] != -1:
        return dp[i]
    
    temp = 0
    for vertex in vertices[i]:
        temp = max(temp, dfs(vertex)+1)
        
    dp[i] = temp
    return temp

for i in range(1,N+1):
    dfs(i)
    
print(max(dp))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**9)

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

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

dp = [-1] * (n+1)
for _ in range(m):
    v1 , v2 = map(int,input().split())
    g[v1].append(v2)
    
# finding longest path for vertice i
def dfs(i):
    if dp[i]!=-1:
        return dp[i]
    temp = 0
    for nv in g[i]:
        temp = max(temp, dfs(nv)+1)

    dp[i]=temp
    return temp
  
# finding overall longest path  
res = 0  
for i in range(1,n+1):
    res = max(res, dfs(i))
print(res)
A,B,C,D = list(map(int,input().split()))
 
for num in range (A <= B):
    if num in range (C<=D):
        print("Yes")
        break
    else:
        print("No")

### FIXED CODE ###

K = int(input())
P = str("ACL")
D = print(P*K)
K = int(input())
S = raw_input()
if (len(S) == K):
  print(S)
else: print(S[0:K] + '...')

### FIXED CODE ###

K = int(input())
S = input()
if (len(S) <= K):
  print(S)
else: print(S[0:K] + '...')
moji = ["dream", "dreamer", "erase", "eraser"]

for i in range(len(moji)):
  moji[i] = moji[i][::-1]

s = input()[::-1]

for i in range(0, 3):
  tmp = s.replace(moji[i], "")
  if tmp != s:
    for j in range(1, 3):
      ans = tmp.replace(moji[j], "")
      if ans != tmp:
        flg = "YES"

if flg == "YES":
  print("YES")
else:
  print("NO")

### FIXED CODE ###

import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  x=a[i]
  y=bisect.bisect_right(x)
  z=bisect.bisect_right(b[y])
  ans+=n-z
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  x=b[i]
  y=bisect.bisect_left(a,x)
  z=bisect.bisect_right(c,x)
  ans+=(n-z)*y
print(ans)
4 3
1 4
4 5
2 3

### FIXED CODE ###

from queue import Queue
n, m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
def bfs():
    queue = Queue()
    queue.put(1)
    distance = [10**6]*(n+1)
    distance[1] = 0
    while not queue.empty():
        u = queue.get()
        if u == n and distance[u] == 2:
            print ("POSSIBLE")
            return
        for a in adj[u]:
            if distance[u] + 1 <= 2 and distance[a] > distance[u] + 1:
                distance[a] = distance[u] + 1
                queue.put(a)
    print ("IMPOSSIBLE")
    return
bfs()