Harryxun/stf_run huggingface dataset:
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  print(sum([combinations_count(t, 2) for t in  c.values()]))
 
if __name__ == '__main__':
  main()

### FIXED CODE ###

import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()
a = int(input())
b = int(input())
print(max(a+b, a-b, a*b))

### FIXED CODE ###

a, b = map(int, input().split())
print(max(a+b, a-b, a*b))
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    dist = [-1 for _ in range(N)]  # 前処理
    dist[S] = 0
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            dist[i] = dist[q] + 1
            que.append(i), frag.add(i)
    return dist


n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

near = nearlist(n, ab)
tkdist, akdist = bfs(near, u - 1, n), bfs(near, v - 1, n)

node = [i for i in range(n) if tkdist[i] <= akdist[i]]
ans = max(akdist[i] for i in node)
print(ans[0] - 1)


### FIXED CODE ###

from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    dist = [-1 for _ in range(N)]  # 前処理
    dist[S] = 0
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            dist[i] = dist[q] + 1
            que.append(i), frag.add(i)
    return dist


n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

near = nearlist(n, ab)
tkdist, akdist = bfs(near, u - 1, n), bfs(near, v - 1, n)

node = [i for i in range(n) if tkdist[i] <= akdist[i]]
ans = max((akdist[i], i) for i in node)
print(ans[0] - 1)
b,c=map(input().split())
  
  if (b//2+b%2)>=c:
    print("YES")
  else : print("NO")

### FIXED CODE ###

b,c=map(int,input().split())
  
if (b//2+b%2)>=c:
    print("YES")
else : print("NO")
x = input()

def Combination(x):
  if x[0] = x[1]:
    if x[2] = x[3]:
      return "Yes"
  elif x[0] = x[2]:
    if x[1] = x[3]:
      return "Yes"
  elif x[0] = x[3]:
    if x[1] = x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))


### FIXED CODE ###

x = input()
 
def Combination(x):
  if x[0] == x[1] and x[2] == x[3] and x[0] != x[2]:
      return "Yes"
  elif x[0] == x[2] and x[1] == x[3] and x[0] != x[1]:
      return "Yes"
  elif x[0] == x[3] and x[1] == x[2] and x[0] != x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))
N=input()
f=0
for i in range(len(N)):
  f+=int(N[i])
if N%f==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=input()
f=0
n=int(N)
for i in range(len(N)):
    f+=int(N[i])
if n%f==0:
    print("Yes")
else:
    print("No")
def search(table, visited, i, j, c):
    visited[i][j] = True

    if table[i-1][j] == c and visited[i-1][j] == False:
        search(table, visited, i-1, j, c)
    if table[i+1][j] == c and visited[i+1][j] == False:
        search(table, visited, i+1, j, c)
    if table[i][j-1] == c and visited[i][j-1] == False:
        search(table, visited, i, j-1, c)
    if table[i][j+1] == c and visited[i][j+1] == False:
        search(table, visited, i, j+1, c)

    return

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

    visited = [[False for i in range(W+2)] for j in range(H+2)]
    table = [["." for i in range(W+2)] for j in range(H+2)]

    for i in range(1, H+1):
        s = input()
        for j in range(1, W+1):
            table[i][j] = s[j-1]

    ans = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if visited[i][j] == False:
                ans = ans + 1
                search(table, visited, i, j, table[i][j])
    print(ans)




### FIXED CODE ###

import sys

sys.setrecursionlimit(20000)

def search(table, visited, i, j, c):
    visited[i][j] = True

    if table[i+1][j] == c and visited[i+1][j] == False:
        search(table, visited, i+1, j, c)
    if table[i-1][j] == c and visited[i-1][j] == False:
        search(table, visited, i-1, j, c)
    if table[i][j+1] == c and visited[i][j+1] == False:
        search(table, visited, i, j+1, c)
    if table[i][j-1] == c and visited[i][j-1] == False:
        search(table, visited, i, j-1, c)


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

    visited = [[False for i in range(W+2)] for j in range(H+2)]
    table = [["." for i in range(W+2)] for j in range(H+2)]

    for i in range(1,H+1):
        s = input()
        for j in range(1,W+1):
            table[i][j] = s[j-1]

    ans = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            if visited[i][j] == False:
                ans += 1
                search(table, visited, i, j, table[i][j])

    print(ans)
n = int(input())
s = input()

ans = 0
for i in range(1,s):
  if s[i] != s[i-1]:
    ans += 1
    
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

ans = 0
for i in range(1,n):
  if s[i] != s[i-1]:
    ans += 1
    
print(ans+1)
a=input().split()
b=[]
for i in range(len(a)):

	if a[i]=="+":

		b[len(b)-2]=b[len(b)-2]+b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="-":

		b[len(b)-2]=b[len(b)-2]-b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="*":

		b[len(b)-2]=b[len(b)-2]*b[len(b)-1];
		del b[len(b)-1]

	else:
		b.append(int(a[i]))

		
print(b[len(b)-1])


### FIXED CODE ###

a=input().split()
b=[]
for i in range(len(a)):

	if a[i]=="+":

		b[len(b)-2]=b[len(b)-2]+b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="-":

		b[len(b)-2]=b[len(b)-2]-b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="*":

		b[len(b)-2]=b[len(b)-2]*b[len(b)-1];
		del b[len(b)-1]

	else:
		b.append(int(a[i]))

		
print(b[len(b)-1])
a = input()
if "RRR" in a:
  print(3)
elif "RR" in a:
  print(2)
elif "R" in a:
  print(1)
else:
  primt(0)

### FIXED CODE ###

a = input()
if "RRR" in a:
  print(3)
elif "RR" in a:
  print(2)
elif "R" in a:
  print(1)
else:
  print(0)
n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = 1

for i in range(n):
  if a[i] == tmp:
    tmp += 1
  else:
    ans += 1

if ans = 0:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = 1

for i in range(n):
  if a[i] == tmp:
    tmp += 1
  else:
    ans += 1

if ans != 0 and tmp ==1:
  print(-1)
else:
  print(ans)
import numpy as np
n = int(input())
dif = np.array(list(map(int, input().split())))
divide = 0
for k in range(min(dif), max(dif)+1):
    count_over = 0
    count_under = 0
    for i in range(len(dif)):
        if dif[i] >= k:
            count_over += 1
        else:
            count_under += 1
    if count_over == count_under:
        divide += 1
print(divide)

### FIXED CODE ###

s = input()

if s[0] == s[1] and s[2] == s[3] and s[1] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[1] != s[2]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2] and s[1] != s[3]:
    print('Yes')
else:
    print('No')
# *-* coding=utf-8 *-*


n = input()
print(3*n*n)






### FIXED CODE ###

# *-* coding=utf-8 *-*


n = int(input())
print(3*n*n)
import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())
# n, q = 3, 2
# arr = [(1, 3), (2, 3)]

graph = defaultdict(list)
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

visited =set()
def dfs(src):
	global graph, lazy, visited
	visited.add(src)
	for neighbour in graph[src]:
		if neighbour not in visited:
			lazy[neighbour] += lazy[src]
			dfs(neighbour)

lazy = [0]*(n+1)
queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])

### FIXED CODE ###

import sys
from collections import defaultdict

n , q = map(int, sys.stdin.readline().split())

lazy = [0]*(n+1)

graph = defaultdict(lambda:list([]))
for i in range(n-1):
	x, y = map(int, sys.stdin.readline().split())
	# x, y = arr[i]
	graph[x].append(y)
	graph[y].append(x)

def dfs(src):
	visited ={src, }
	stack = [src]

	while stack:
		v = stack.pop()
		for next_v in graph[v]:
			if not next_v in visited:
				visited.add(next_v)
				lazy[next_v] += lazy[v]
				stack.append(next_v)

# queries = [(1, 1), (2, 2)]
for i in range(q):
	idx, val = map(int, sys.stdin.readline().split())
	# idx, val = queries[i]
	lazy[idx] += val
dfs(1)
print(*lazy[1:])
A,B,C,D,E,F = (int(i) for i in input().split())

water_list = []
suger_list = []

for i in range(F):
  for j in range(F):
    if 100*A*i + 100*B*j <= F:
      water_list.append(100*A*i + 100*B*j)

for i in range(F):
  for j in range(F):
    if C*i + D*i <= F:
      suger_list.append(C*i+D*j)

ans = 0
ans_list = []

for water in water_list:
  for suger in suger_list:
    if water != 0 and suger != 0:
      if suger/(water + suger) > ans and water+suger <= F and suger <= (water/100)*E:
        ans = suger/(water + suger)
        ans_list = [water,suger]

print(str(ans_list[0]+ans_list[1]) + " " + str(ans_list[1]))


### FIXED CODE ###

A,B,C,D,E,F = (int(i) for i in input().split())

water_list = []
suger_list = []

for i in range(F):
  if 100*A*i <= F:
    for j in range(F):
      if 100*B*j <= F:
        if 100*A*i + 100*B*j <= F:
          water_list.append(100*A*i + 100*B*j)
        else:
          break
      else:
        break
  else:
    break

for i in range(F):
  if C*i <= F:
    for j in range(F):
      if D*j <= F:
        if C*i + D*i <= F:
          suger_list.append(C*i+D*j)
        else:
          break
      else:
        break
  else:
    break

ans = 0
ans_list = []

for water in water_list:
  for suger in suger_list:
    if water != 0 and suger != 0:
      if suger/(water + suger) >= ans and water+suger <= F and suger <= (water/100)*E:
        ans = suger/(water + suger)
        ans_list = [water,suger]

if ans != 0:
  print(str(ans_list[0]+ans_list[1]) + " " + str(ans_list[1]))
else:
  print(str(A*100) + " 0")
a,b,x = map(int,input().split())
keta = 0
for i in range(1,24):
    cx = x - b*(i)
    if cx < a*(10**(i-1)):
        keta = i-1
        break
if keta == 0:
    print(0)
elif keta >= 10:
    t = len(cx//a)
    print(10**9)
else:
    cx = x - keta*b
    if cx//a >= 10**9:
        print(10**9)
    else:
        if len(cx//a) > keta:
            print(10**(keta)-1)
        else:
            print(cx//a)

### FIXED CODE ###

S = input()
l = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-l.index(S))
import sys
input = sys.stdin.readline

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

mean = sum(a) / n

ans = [200, 200]

for i in range(n):
    if abs(mean - a[i]) < ans[1]:
        ans = [i, abs(mean - a[i])]

print(ans[0])


### FIXED CODE ###

import sys
input = sys.stdin.readline

x, y = [int(x) for x in input().split()]
ans = 0

for i in [x, y]:
    if i == 1:
        ans += 300000
    elif i == 2:
        ans += 200000
    elif i == 3:
        ans += 100000
    
if x == 1 and y == 1:
    ans += 400000

print(ans)
def main():
    N = int(input())
    A = [int(input()) for a in range(N)]
    L = [0 for i in range(10**4)]

    for i in range(N):
        if L[A[i]-1] == 0:
            L[A[i]-1] = 1
        elif L[A[i]-1] == 1:
            L[A[i]-1] = 0

    print(sum(L))
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = [int(input()) for a in range(N)]
    S = set()

    for i in range(N):
        if A[i] in S:
            S.remove(A[i])
        else:
            S.add(A[i])
    print(len(S))
if __name__ == "__main__":
    main()
import numpy as np

n=int(input())
A=np.array(list(map(int,input().split())))
a=np.prod(A)

if a>10**18:
    print("-1")
else:
    print(a)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
prod=1
if 0 in A:
    prod=0
for i in A:
    prod*=i
    if prod>10**18:
        prod=-1
        break
print(prod)
from scipy.special import comb
N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=int(comb(v,2))
print(ans)

### FIXED CODE ###

N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=v*(v-1)//2
print(ans)
import math
N = int(input())

if (N % 2) == 1:
  print(0)
  exit()

total = 0

for i in range(1, 2+int(math.log(N, 5))):
  t = 5 ** i * 2
  total += N // t

print(total)


### FIXED CODE ###

import math
N = int(input())

if (N % 2) == 1:
  print(0)
  exit()

total = 0

for i in range(1, 2+int(math.log(10**18, 5))):
  t = 5 ** i * 2
  total += N // t

print(total)
A = int(input())

B = int(input())

T = int(input())

i = int((T + 0.5) // A)

print(int(B * i))




### FIXED CODE ###

A, B, T = map(int, input().split())

i = int((T + 0.5) // A)

print(int(B * i))
def resolve():
    R = int(input())

    print(R * 2 * math.pi)


resolve()

### FIXED CODE ###

import math

from decimal import Decimal, getcontext

getcontext().prec = 99


def resolve():
    R = int(input())

    print(R * 2 * math.pi)


resolve()
num = list(map(int,input().split))
 
circle_px = num[2] + num[4]
circle_mx = num[2] - num[4]

circle_py = num[3] + num[4]
circle_my = num[3] - num[4]

if(circle_px <= num[0] and circle_mx >= 0 and circle_py <= num[1] and circle_py >= 0): print("Yes")
else: print("No")


### FIXED CODE ###

num = list(map(int,input().split()))
 
circle_px = num[2] + num[4]
circle_mx = num[2] - num[4]

circle_py = num[3] + num[4]
circle_my = num[3] - num[4]

if(circle_px <= num[0] and circle_mx >= 0 and circle_py <= num[1] and circle_py >= 0): print("Yes")
else: print("No")
if input()="1":
    print("Hello World")
else:
    print(int(input())+int(input()))

### FIXED CODE ###

if input()=="1":
    print("Hello World")
else:
    print(int(input())+int(input()))
import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box,box2 = [],[]
acnt = dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
a_val = [acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
for i in range(len(a_val)):
	if a_val[i] >= 4:
		box2.append(a_key[i]**2)
	if 2 <= a_val[i]:
		box.append(a_key[i])
box.sort(reverse=True)
ans = max(box2)
if len(box) >= 2:
    print(max(ans,(box[0]*box[1])))
    sys.exit()
print(0)

### FIXED CODE ###

import sys
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
box,box2,ans = [],[],0
acnt = dict(Counter(a))
acnt = sorted(acnt.items(), key=lambda x:x[0],reverse=True)
a_val = [acnt[x][1] for x in range(len(acnt))]
a_key = [acnt[y][0] for y in range(len(acnt))]
for i in range(len(a_val)):
	if a_val[i] >= 4:
		box2.append(a_key[i]**2)
	if 2 <= a_val[i]:
		box.append(a_key[i])
box.sort(reverse=True)
if len(box2) >= 2:	
	ans = max(box2)
if len(box) >= 2:
    print(max(ans,(box[0]*box[1])))
    sys.exit()
print(0)
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp) + 1
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

### FIXED CODE ###

N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))
s = input()

slist = s.split(" ")

left = int(slist[0]) + int(slist[1])

right = slist[2] + slist[3]

if left > right:
	print("left")
	
elif left == right:
	print("Balanced")
	
else:
	print("right")


### FIXED CODE ###

s = input()

slist = s.split(" ")

left = int(slist[0]) + int(slist[1])

right = int(slist[2]) + int(slist[3])

if left > right:
	print("Left")
	
elif left == right:
	print("Balanced")
	
else:
	print("Right")
a,b,c,x,y=map(int,input().split())
if x>=y:
    if c*2<=min(a,b):
        print(c*2*x)
    elif c*2<=max(a,b):
        if a>=b:
            print(c*2*x)
        else:
            print(c*2*y+a(x-y))
    elif c*2<=a+b:
        print(c*2*y+a*(x-y))
    else:
        print(a*x+b*y)
else:
    if c*2<=min(a,b):
        print(c*2*y)
    elif c*2<=max(a,b):
        if a<=b:
            print(c*2*y)
        else:
            print(c*2*y+b(y-x))
    elif c*2<=a+b:
        print(c*2*x+b*(y-x))
    else:
        print(a*x+b*y)

### FIXED CODE ###

a,b,c,x,y=map(int,input().split())
l=sorted([a,b,c*2])
if l[0]==c*2:
    print(max(x,y)*c*2)
elif l[1]==c*2:
    if l[0]==a:
        print(y*c*2+max((x-y),0)*a)
    else:
        print(x*c*2+max((y-x),0)*b)
else:
    if a+b>=c*2:
        if x>=y:
            print(y*2*c+(x-y)*a)
        else:
            print(x*2*c+(y-x)*b)
    else:
        print(x*a+y*b)
from bisect import *
N,M=map(int,input().split())
kagi=[]
for i in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    for i in range(b):
        C[i]-=1
    kagi.append([a,set(C)])

value=10**7
idx=-1
for i in range(M):
    if 0 in kagi[i][1] and kagi[i][0]<value:
        value=kagi[i][0]
        idx=i
if idx==-1:
    print(-1)
    exit()
kagilst=[idx]

takara=[set() for i in range(N)]
for m in range(M):
    for k in kagi[m][1]:
        takara[k].add(m)

for n in range(1,N):
    if [k for k in kagilst if n in kagi[k][1]]:
        continue
    tempvalue=10**7
    for k in takara[n]:
        lst=[0 for i in range(n)]
        for z in kagilst+[k]:
            for m in kagi[z][1]:
                if m<len(lst):
                    lst[m]=1
        for i in range(len(kagilst)**2):
            A=bin(i)[:2]
            A=list(reversed(list(A)))
            for a in range(len(kagilst)):
                if A[a]=="1":
                    for h in kagi[kagilst[a]][1]:
                        lst[h]=1
            if not 0 in lst:
                temptempvalue=value+sum([kagi[a][0] for a in range(len(kagilst)) if A[a]=="1"])+kagi[k][0]
                if temptempvalue<tempvalue:
                    tempvalue=temptempvalue
                    tempkagi=k
    if tempvalue==10**7:
        print(-1)
        exit()
    value=tempvalue
    kagilst.append(k)
print(value)


### FIXED CODE ###

from bisect import *
N,M=map(int,input().split())
kagi=[]
for i in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    value=0
    for i in range(b):
        C[i]-=1
        value+=2**C[i]

    kagi.append([a,value])


dp=[[10**8 for i in range(2**N)] for m in range(M+1)]
dp[0][0]=0
for i in range(M):
    for s in range(2**N):
        dp[i+1][s]=min(dp[i][s],dp[i+1][s])
        dp[i+1][s|kagi[i][1]]=min(dp[i+1][s|kagi[i][1]],dp[i][s]+kagi[i][0])
if 10**8==dp[M][-1]:
    print(-1)
else:
    print(dp[M][-1])
A,B,K = map(int,input().split())
i = 1
c = 1
while i <= K:
    if c % 2 == 1:
        if A % 2 == 0:
            A_ = A // 2
            A = A_
            B = B + A_
        else:
            A -= 1
            A_ = A // 2
            A = A_
            B = B + A_

        i += 1
        c += 1
    else:
        if B % 2 == 0:
            B_ = B //2
            A = A + B_
            B = B_
        else:
            B -= 1
            B_ = B //2
            A = A + B_
            B = B_

        i += 1
        c += 1
print(A,B)


### FIXED CODE ###

S = str(input())
if len(S) == 3:
    print(S[::-1])
else:
    print(S)
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
import math
import fractions
from heapq import heappush, heappop


sys.setrecursionlimit(10 ** 7)

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

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

MAGIC = sorted(MAGIC, key=lambda x: x[0]//x[1])
dp = [[10**9] * (H+1) for _ in range(N+1)]

for i in range(N):
    dp[i][0] = 0


for i in range(N):
    for h in range(H+1):
        if h < MAGIC[i][0]:
            dp[i+1][h] = dp[i][h]
        elif h == H:
            m = min(dp[i+1][h-MAGIC[i][0]:])
            #print("num", h-MAGIC[i][0], dp[i][h-MAGIC[i][0]:])
            # print(m)
            dp[i+1][h] = min(dp[i][h], m+MAGIC[i][1])
        else:
            #print("ok", h)
            dp[i+1][h] = min(dp[i][h], dp[i+1][h-MAGIC[i][0]]+MAGIC[i][1])

    # print(dp[i+1])

# print(dp)
print(dp[N][H])


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)

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

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

INF = 10 ** 10
dp = [INF] * 20000
dp[0] = 0

for i in range(N):
    for h in range(H):
        a, b = MAGIC[i]

        if dp[h+a] > (dp[h] + b):
            dp[h+a] = dp[h] + b

print(min(dp[H:]))
def printer(n):
    if n%10 in [2,4,5,7,9]:print"hon"
    elif n%10 in[0,1,6,8]:print"pon"
    else:print"bon"
printer(int(input()))

### FIXED CODE ###

def printer(n):
    if n%10 in [2,4,5,7,9]:print("hon")
    elif n%10 in[0,1,6,8]:print("pon")
    else:print("bon")
printer(int(input()))
r=input()
g=input()
b=input()

x=int(r*100+g*10+b)
if(x%4==0):
    print('YES')
else:
    print("NO")

### FIXED CODE ###

a=input()
a=a.split()

r=int(a[0])
g=int(a[1])
b=int(a[2])

x=100*r+10*g+b

if(x%4==0):
    print('YES')
else:
    print('NO')
X,Y,Z=map(int(input().split()))
print(Z,X,Y)

### FIXED CODE ###

X,Y,Z=map(int,input().split())
print(Z,X,Y)
def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]
    B.sort()
    selected = set()
    for b in B:
        r_lst = []
        for i in range(len(R)):
            r = R[i]
            if r[0] < b[0] and r[1] < b[1]:
                r_lst.append(i)
        if len(r_lst) == 0:
            continue
        rym = -1
        rym_i = -1
        for i in len(r_lst):
            if rym < r_lst[i][1]:
                rym = r_lst[i][1]
                rym_i = i
        selected.add(i)
    return len(selected)
if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]
    B.sort()
    selected = set()
    for b in B:
        r_lst = []
        for i in range(len(R)):
            if i in selected: continue
            r = R[i]
            if r[0] < b[0] and r[1] < b[1]:
                r_lst.append(i)
        if len(r_lst) == 0:
            continue
        rym = -1
        rym_i = -1
        for i in r_lst:
            if rym < R[i][1]:
                rym = R[i][1]
                rym_i = i
        selected.add(rym_i)
    return len(selected)
if __name__ == '__main__':
    print(solve())
S = input()
T = input()
flag = 1
for i in S:
    if not 96<ord(s) and ord(s)<122:
        flag=0

    if T[len(t)-1]:
        flag=0
    if not len(T)-len(S)==1:
        flag=0
    if not T[:-1]==S:
        flag=0
print(Yes if flag==1 else No)


### FIXED CODE ###

S = input()
T = input()
flag = 1
for i in range(0,len(T)):
    if not 96<ord(T[i]) and ord(T[i])<122:
        flag=0

if not len(T)-len(S)==1:
    flag=0

if not T[:-1]==S:
    flag=0
print("Yes" if flag==1 else "No")