Harryxun/stf_run huggingface dataset:
from collections import deque

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

print(A)

BC = [list(map(int, input().split())) for i in range(M)]
BC.sort(key=lambda x: x[1])
D = deque([])
for i in range(M):
        D.extend([BC[i][1]] * BC[i][0])

print(D)

sum = 0
for i in range(N):
        if A[-1] >= D[-1]:
                sum += A.pop()
        else:
                sum += D.pop()

print(sum)

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import combinations
def run():
    pri = []
    N, A, B, C = map(int, sysread().split())
    vals = {'A':A, 'B':B, 'C':C}
    S = [sysread() for _ in range(N)]

    pri = []
    for idx, s in enumerate(S):
        if vals[s[0]] == vals[s[1]] and vals[s[0]] == 1:
            if s[0] in S[idx+1]:
                vals[s[0]] += 1
                vals[s[1]] -= 1
                pri.append(s[0])
            else:
                vals[s[0]] -= 1
                vals[s[1]] += 1
                pri.append(s[1])
        else:
            if vals[s[0]] <= vals[s[1]]:
                vals[s[0]] += 1
                vals[s[1]] -= 1
                pri.append(s[0])
            else:
                vals[s[0]] -= 1
                vals[s[1]] += 1
                pri.append(s[1])

        if not check_vals(vals):
            print('No')
            return None
    print('Yes')
    for st in pri:
        print(st)

def check_vals(vals):
    for v in vals.values():
        if v < 0:
            return False
    return True

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
sysread = sys.stdin.readline
sys.setrecursionlimit(10**7)
def run():
    pri = []
    N, A, B, C = map(int, sysread().split())
    vals = {'A':A, 'B':B, 'C':C}
    S = [sysread() for _ in range(N)]

    pri = []
    for idx, s in enumerate(S):
        if vals[s[0]] == vals[s[1]] and vals[s[0]] == 1 and idx !=len(S)-1:
            if s[0] in S[idx+1]:
                vals[s[0]] += 1
                vals[s[1]] -= 1
                pri.append(s[0])
            else:
                vals[s[0]] -= 1
                vals[s[1]] += 1
                pri.append(s[1])
        else:
            if vals[s[0]] <= vals[s[1]]:
                vals[s[0]] += 1
                vals[s[1]] -= 1
                pri.append(s[0])
            else:
                vals[s[0]] -= 1
                vals[s[1]] += 1
                pri.append(s[1])

        if not check_vals(vals):
            print('No')
            return None
    print('Yes')
    for st in pri:
        print(st)

def check_vals(vals):
    for v in vals.values():
        if v < 0:
            return False
    return True

if __name__ == "__main__":
    run()
S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print('',join(dq))
else:
    print(''.join(dq)[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print(''.join(dq))
else:
    print(''.join(dq)[::-1])
n,k=map(int,input().split())
h=list(map(int,input().split()))
ans = [1234567890123]*n
ans[0]=0
for i in range(1,k+1):
    ans[i]=abs(h[i]-h[0])

for i in range(k+1,n):
    mini=1234567890123
    for j in range(1,k+1):
        mini=min(mini,ans[i-j]+abs(h[i]-h[i-j]))
    ans[i] = mini
print(ans[n-1])

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
ans = [1234567890123]*n
ans[0]=0
for i in range(1,n):
    for j in range(i-1,max(i-1-k,-1),-1):
        ans[i] = min(ans[i],ans[j]+abs(h[i]-h[j]))
    
print(ans[n-1])
n=list(map(int,input().split()))
score=list(map(int,input().split()))
s=input()

n[1]-=1

def rscore(ss):
  if ss=='r':
    return score[2]
  elif ss=='s':
    return score[0]
  elif ss=='p':
    return score[1]

result=0
flg=[]
for i in range(n[1]):
  result+=rscore(s[i])
  flg.append(True)
for i in range(n[1],len(s)):
  if(s[i-n[1]-1]==s[i] and flg[i-n[1]-1]):
    flg.append(False)
    continue
  else:
    flg.append(True)
    result+=rscore(s[i])
print(result)

### FIXED CODE ###

n=list(map(int,input().split()))
score=list(map(int,input().split()))
s=input()

def rscore(ss):
  if ss=='r':
    return score[2]
  elif ss=='s':
    return score[0]
  elif ss=='p':
    return score[1]

result=0
flg=[]
for i in range(n[1]):
  result+=rscore(s[i])
  flg.append(True)
for i in range(n[1],len(s)):
  if(s[i-n[1]]==s[i] and flg[i-n[1]]):
    flg.append(False)
    continue
  else:
    flg.append(True)
    result+=rscore(s[i])
print(result)
from collections import deque
import sys

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

mod = 10 ** 9 + 7
num = 0
Ans = 1

if A[-1] < 0 and K % 2 == 1:
    for i in range(K):
        Ans = Ans * A[i] % mod
    print(Ans)
    sys.exit()

while num < K:
    non_minus = A[-1] * A[-2]
    minus = A[0] * A[1]
    if num == K-1 or non_minus > minus:
        Ans = Ans * A.pop() % mod
        num += 1
    else:
        Ans = Ans * A.popleft() * A.popleft() % mod
        num += 2

print(Ans)
        

### FIXED CODE ###

mod = 10**9+7
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))

pi = 1
ni = 0
ans = 1
i = 0
while i < K-1:
  if A[ni]*A[ni+1] > A[-pi]*A[-pi-1]:
    ans = ans*A[ni]*A[ni+1]%mod
    ni += 2
    i += 2
    
  else:
    ans = ans*A[-pi]%mod
    pi += 1
    i += 1
    
if i == K-1:
  ans = ans*A[-pi]%mod
  
if A[-1]<0 and K%2==1:
  ans = 1
  for i in A[N-K:]:
    ans = ans*i%mod

print(ans)
import collections
N = int(input())
x = []
for i in range(N):
	x.append(list(map(int, input().split())))
if N == 1:
	print(1)
else:
	L = []
	for i in range(N):
		a, b = x[i][0], x[i][1]
		for j in range(N):
			if a > x[j][0] or b > x[j][1]:
				L.append((a - x[j][0], b - x[j][1]))
	c = collections.Counter(L)
	max = c.most_common(1)[0][1]
	print(N - max)

### FIXED CODE ###

N, K = map(int, input().split())
if K == 1:
	print(0)
else:
	print(N - K)
h, w= map(int, raw_input().split())
n = int(raw_input())
ais = map(int, raw_input().split())
ais.sort()
mat = [[-1 for _ in range(w)] for ii in range(h)]
import collections
color = 0
vis = set([])
def bfs(start, color, count, vis,mat):
	q = collections.deque([start])
	vis = set([start])
	while(count):
		count -=1
		cur = q.popleft()
		mat[cur[0]][cur[1]] = color + 1
		i,j = cur
		for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
			if 0 <= ni < len(mat) and 0<= nj < len(mat[0]):
				if mat[ni][nj] ==-1:
					vis.add((ni,nj))
					q.append((ni,nj))

for i in range(len(mat)):
	for j in range(len(mat[0])):
		if mat[i][j]==-1:
			bfs((i,j), color, ais[color], vis,mat)
			color +=1

for l in mat:
	print ' '.join(map(str,l))

### FIXED CODE ###


h, w= map(int, raw_input().split())
n = int(raw_input())
ais = map(int, raw_input().split())
mat = [[-1 for _ in range(w)] for ii in range(h)]
import collections
color = 0
vis = set([])
def bfs(start, color, count,mat):
	q = collections.deque([start])
	vis = set([start])
	while(q and count):
		count -=1
		cur = q.popleft()
		mat[cur[0]][cur[1]] = color + 1
		i,j = cur
		for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
			if 0 <= ni < len(mat) and 0<= nj < len(mat[0]):
				if (ni,nj) not in vis:
					vis.add((ni,nj))
					q.append((ni,nj))

for i in range(len(mat)):
	for j in range(len(mat[0]))[::(-1 if i % 2 else 1)]:
		mat[i][j] = color +1
		ais[color] -= 1
		if ais[color] == 0: color +=1
for l in mat:
	print ' '.join(map(str,l))
n = int(input())
ts = list(map(int, input().split())))
su = sum(ts)
m = int(input())
for _ in range(m):
  p, x = list(map(int, input().split())))
  ans = su - ts[p] + x
  print(ans)

### FIXED CODE ###

n = int(input())
ts = list(map(int, input().split()))
su = sum(ts)
m = int(input())
for _ in range(m):
  p, x = list(map(int, input().split()))
  ans = su - ts[p - 1] + x
  print(ans)
N,M = map(int,input().split())
p = [0]*M
S = [0]*M
pS = [[0,0] for i in range(M)]
for i in range(M):
  pS[i]= list(map(str,input().split()))
pS.sort()
for i in range(M):
  p[i] = pS[i,0]
  S[i] = PS[i,1]
AC = 0
WA = 0
p1 = '0'
i = 0
while i < M:
  if p[i] != p1 and S[i] != 'AC':
    WA = WA+1
    i = i+1
  elif p[i] != p1 and S[i] == 'AC':
    p1 = p[i]
    AC = AC+1
    i = i+1
  else:
    i = i+1
print(AC,WA)

### FIXED CODE ###

N,M = map(int,input().split())
p = ['0']*M
S = ['0']*M
for i in range(M):
  p[i],S[i]= map(str,input().split())
AC = [0]*(N+1)
WA = [0]*(N+1)
i = 0
for i in range(M):
  if S[i] == 'WA':
    if AC[int(p[i])] == 0:
      WA[int(p[i])] = WA[int(p[i])]+1
    else:
      None
  else:
    AC[int(p[i])]=1
count = 0
for i in range(N+1):
  if AC[i]==0:
    count = count+WA[i]
print(sum(AC),sum(WA)-count)
r, d, x = map(int, input().strip())
for i in range(10):
  x = r * x - d
  print(x)


### FIXED CODE ###

r, d, x = map(int, input().split())
for i in range(10):
  x = r * x - d
  print(x)
S=list(input())

n=len(S)
l=list("ACGT")
ans=[]

for i in range(7):
  count=0
  for j in range(i,7):
    if S[j] in l:
      count+=1
    else:
      break
  ans.append(count)
print(max(ans))

### FIXED CODE ###

S=list(input())

n=len(S)
l=list("ACGT")
ans=[]

for i in range(n):
  count=0
  for j in range(i,n):
    if S[j] in l:
      count+=1
    else:
      break
  ans.append(count)
print(max(ans))
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


pp = [None]*n
v = 1
for i in range(n):
    pp[i] = v
    v *= 2
    v %= M
    
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pp[i] + i*pp[i-1])*pp[n-i-1]
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pow(2, i, M) + i*pow(2,i-1,M))*pow(2,n-i-1,M)
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)
import io
import sys

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

d = {}

for i in range(1, n + 1):
    d[i] = None

for itm in sc:
    if (d[itm[0]] == None) | (d[itm[0]] == itm[1]):
        d[itm[0]] = itm[1]
    else:
        print(-1)
        sys.exit()

l = list(d.values())
if l == [0]:
    print(0)
elif l[0] == 0:
    print(-1)
else:
    l = [0 if x == None else x for x in l]
    l[0] = [1 if x == 0 else x for x in l]
    l = map(str, l)
    print("".join(l))


### FIXED CODE ###

n = int(input())
print((n+1)//2)
import math
a,b,c,d=map(int,input().split())

e=math.floor(b/c)
f=math.ceil(a/c)

ans=e-f+1

g=math.floor(b/d)
h=math.ceil(a/d)

ans=ans+g-h+1

i=(c*d)//math.gcd(c,d)

j=math.floor(b/i)
k=math.ceil(a/i)

ans=ans-(j-k+1)

print(b-a+1-ans)

### FIXED CODE ###

import fractions
a,b,c,d=map(int,input().split())

e=b//c
f=-(-a//c)

ans=e-f+1

g=b//d
h=-(-a//d)

ans=ans+g-h+1

i=(c*d)//fractions.gcd(c,d)

j=b//i
k=-(-a//i)

ans=ans-(j-k+1)

print(b-a+1-ans)
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()[::-1]
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

for i in range(N):
    c = S[i]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*(10**i) + j) % 13
            dp[i+1][amari] += dp[i][j] %= MOD

print(dp[N][5])



### FIXED CODE ###

import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

S = input()
N = len(S)

# dp[i][k]: i桁目までのkで割った余りの数
dp = create_grid(N+1, 13)

dp[0][0] = 1 # 0桁目

s = [1]
for i in range(N):
  s.append((s[-1]*10)%13)

for i in range(N):
    c = S[N-i-1]
    if c == "?":
        v = range(10)
    else:
        v = [int(c)]
    for vi in v:
        for j in range(13):
            amari = (vi*s[i] + j) % 13
            dp[i+1][amari] = (dp[i][j] + dp[i+1][amari]) % MOD

print(dp[N][5])
from copy import deepcopy
import itertools

A, B, C, D, E, F = map(int, input().split())

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)


### FIXED CODE ###

from copy import deepcopy
import itertools

A, B, C, D, E, F = map(int, input().split())

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
Ms = 0
Mw = A
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)
while True:
    n = int(input())
    if n == 0:
        break
    p = [10, 10]
    l = [list(map(int,input().split())) for _ in range(n)]
    for d,s in [input.split() for _ in range(int(input()))]:
        for _ in range(s):
            if d == 'N':
                p[1] += 1
            elif d == 'E':
                p[0] += 1
            elif d == 'W':
                p[0] -= 1
            elif d == 'S':
                p[1] -= 1
            if p in l:
                l.remove(p)
    if len(l) == 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

while True:
    n = int(input())
    if n == 0:
        break
    p = [10, 10]
    l = [list(map(int,input().split())) for _ in range(n)]
    for d,s in [input().split() for _ in range(int(input()))]:
        for _ in range(int(s)):
            if d == 'N':
                p[1] += 1
            elif d == 'E':
                p[0] += 1
            elif d == 'W':
                p[0] -= 1
            elif d == 'S':
                p[1] -= 1
            if p in l:
                l.remove(p)
    if len(l) == 0:
        print('Yes')
    else:
        print('No')
s = input()

check = 0
re = 0
t = 'keyence'
len = 0
ans = 0
for i in s:
    if t[len] == i and len < 7:
        len += 1
        re = 0
    else:
        if check == 0:
            check = 1
            re = 1
        elif re == 1:
            tmp = 1
        else:
            ans = 1

if ans == 0 and len == 7:
    print('YES')
else:
    print('NO')



    


### FIXED CODE ###

s = input()
t = 'keyence'
ans = 0
flag = False
for i in range(len(s)):
    for j in range(i,len(s)):
        tmp = s[:i] + s[j:]
        if tmp == t:
            ans = 1
            flag = True
            break
    if flag:
        break
if ans == 1:
    print('YES')
else:
    print('NO')
n=int(input())
num=[]
t=1
count=1
while n>t*26:
    t *= 26
    n -= t
    count += 1

for i in range(count-1,-1,-1):
    m=26**i
    a=n//m
    n %= m
    num.append(a)
a_list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans=[]
for i in range(count):
    s=num[i]
    if i==count-1:
        s -= 1
    ans.append(a_list[s])
print(''.join(ans))

### FIXED CODE ###

n=int(input())
num=[]
t=1
count=1
while n>t*26:
    t *= 26
    n -= t
    count += 1
n -= 1
for i in range(count-1,-1,-1):
    m=26**i
    a=n//m
    n %= m
    num.append(a)
a_list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans=[]
for i in range(count):
    s=num[i]
    ans.append(a_list[s])
print(''.join(ans))
N = input()
SN = sum([int(i) for i in N])

if N % SN == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = input()
SN = sum([int(i) for i in N])
 
if int(N) % SN == 0:
  print('Yes')
else:
  print('No')
import math
L = list(map(int,input().split()))
a = L[0]
b = L[1]
H = L[2]
M = L[3]

#angleshort = 360*(60*H+M)/720
#anglelong = 360*M/60

print(angleshort)
print(anglelong)
theta = math.radians((anglelong-angleshort))
ans = (a*a+b*b-2*a*b* math.cos(theta))**0.5
print(ans)

### FIXED CODE ###

import math
L = list(map(int,input().split()))
a = L[0]
b = L[1]
H = L[2]
M = L[3]

angleshort = 360*(60*H+M)/720
anglelong = 360*M/60

#print(angleshort)
#print(anglelong)
theta = math.radians((anglelong-angleshort))
ans = (a*a+b*b-2*a*b* math.cos(theta))**0.5
print(ans)
N = int(input())
list_a = list(map(int,input().split()))
list_b = list_a.sort()
alice = 0; bob = 0
for i in range(100):
    if i % 2 == 0:
        alice += list_b[i]
    else:
        bob += list_b[i]
print(alice-bob)
    

### FIXED CODE ###

N = int(input())
list_a = list(map(int,input().split()))
list_a.sort(reverse=True)
alice = 0; bob = 0
for i in range(len(list_a)):
    if i % 2 == 0:
        alice += list_a[i]
    else:
        bob += list_a[i]
print(alice-bob)
a=int(input())
b=int(input())
c=input()
c=c.replace(c[b-1],c[b-1].lower())
print(c)

### FIXED CODE ###

N, K = map(int, input().split())
S = input()
K -= 1
answer = S[:K] + S[K].lower() + S[K+1:]
print(answer)
while True:
    (H, W) = [int(x) for x in input().split()]
    if H == W == 0:
        break

    for hc in range(H):
        for wc in range(W):
            if hc == 0 or hc == H - 1 or wc == 0 or wc == W - 1:
                print('#' , end = ' ')
            else:
                    print('.',  end = ' ')
          print()
    print()

### FIXED CODE ###

while True:
    (H, W) = [int(x) for x in input().split()]
    if H == W == 0:
        break

    for hc in range(H):
        if hc == 0 or hc == H -1:
            print('#' * W)
        else:
            print('#' + '.' * (W -2) + '#')
    print()
N, M, K = map(int, input().split())
print("Yes" if (N+M)%K == 0 else "No")

### FIXED CODE ###

N, M, K = map(int, input().split())
Flg = "No"

for i in range(N+1):
    for j in range(M+1):
        if(i*(M-j)+(N-i)*j == K):
            Flg = "Yes"
            break
print(Flg)
a,b,c,= [int(x) for x in input()]
n = c -(a-b)
if n > 0:
    print(n)
else:
    print(0)

### FIXED CODE ###

a,b,c,= [int(x) for x in input().split()]
n = c -(a-b)
if n > 0:
    print(n)
else:
    print(0)
X = int(input())
Y = int(input())
Z = int(input())
A,B,C = X,Y,Z
A,B,C = C,A,B
print(A,B,C)

### FIXED CODE ###

X,Y,Z = map(int,input().split())
X,Y = Y,X
X,Z = Z,X
print(X,Y,Z)
s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
        
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += factorial(w) / (factorial(2)*factorial(w - 2))
    
print(int(cnt))

### FIXED CODE ###

s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += w*(w-1)/2
    
print(int(cnt))