Harryxun/stf_run huggingface dataset:
N, X, M = map(int, input().split())

ans = X
x = X

C = [0, x]
Xd = [-1] * (M+1)
Xd[x] = 0
Xl = [x]

for i in range(1, N):
    x = x**2 % M

    if Xd[x] > -1:
        break
    Xd[x] = i
    Xl.append(x)
    ans += x
    C.append(ans)

# print(Xl)
# print(C)
# print(Xd[x], i)
S = C[i] - C[Xd[x]]
# print(S)
loop_len = i - Xd[x]
# print(loop_len)
if loop_len > 0:
    loop_num = (N - i) // loop_len
    # print(loop_num)
    ans += loop_num * S
    m = N - loop_num * loop_len - i
    # print(ans)
    # print(m)
    ans += C[Xd[x]+m] - C[Xd[x]]

# print(S)

print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())

ans = X
x = X

C = [0, x]
Xd = [-1] * (M+1)
Xd[x] = 0
i = 1

for i in range(1, N):
    x = x**2 % M

    if Xd[x] > -1:
        break
    Xd[x] = i
    ans += x
    C.append(ans)

loop_len = i - Xd[x]
if loop_len > 0:
    S = C[i] - C[Xd[x]]
    loop_num = (N - i) // loop_len
    ans += loop_num * S
    m = N - loop_num * loop_len - i
    ans += C[Xd[x]+m] - C[Xd[x]]

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

query = [""]*q

rev=1

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        rev*=-1
    else:
        r = query[i].split()
        if rev=1:
            if r[1]=="1":
                s = r[2]+s
            else:
                s += r[2]
        else:
            if r[1]=="2":
                s = r[2]+s
            else:
                s += r[2]

if rev=-1:
    s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)
N, K = int(input().split())
if N % K == 0:
  print(0)
else :
  print(1)

### FIXED CODE ###

N, K = map(int, input().split())
if N % K == 0:
  print(0)
else :
  l = [(N + i) // K for i in range(K)]
  print(max(l) - min(l))
n, k, q = map(int, input().split())
alist = [int(input()) for i in range(n)]

for i in range(1, n + 1):
    if n - alist.count(i) >= k:
        print('No')
    else:
        print('Yes')


### FIXED CODE ###

n, k, q = map(int, input().split())
alist = [int(input()) for i in range(q)]
ans = [k - q] * n

for Ai in alist:
    ans[Ai - 1] += 1

for Ai in ans:
    print('Yes') if Ai > 0 else print('No')
N = int(input())
As = list(map(int, input().split()))
ans = [0 for _ in range(N)]
 
for a in As
    ans[a-1] += 1

print(ans, sep="\n")

### FIXED CODE ###

# coding: utf-8
# Your code here!

N = int(input())
As = list(map(int, input().split()))
ans = [0 for _ in range(N)]
 
for a in As:
    ans[a-1] += 1

print(*ans, sep="\n")
#キューを使っている。ところどころマイナスにしているのはキューの性質のため。実行時間が全然違うのはソートが早いから
n,m = map(int,input().split())
a = list(map(lambda x: -int(x) ,input().split()))
print(a)
import heapq
heapq.heapify(a)
for _ in range(m):
  tmp = -heapq.heappop(a)
  tmp //= 2
  heapq.heappush(a,-tmp)
print(-sum(a))

### FIXED CODE ###

from sys import stdin

a = stdin.readline().rstrip()
if a == "Sunny":
  print("Cloudy")
elif a== "Cloudy":
   print("Rainy")
else:
   print("Sunny")
def f(x):
    if flag[x]:
        return dp[x]
    flag[x] = 1
    p = 0
    for y in glaph[x]:
        p = max(p,f(y)+1)
    dp[x] = p
    return dp[x]
n,m = map(int,input().split())
glaph = [[] for i in range(n+1)]
for _ in range(m):
    x,y = map(int,input().split())
    glaph[x].append(y)
flag = [0]*(n+1)
dp = [0]*(n+1)
for i in range(1,n+1):
    f(i)
print(max(dp))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def f(x):
    if flg[x]:
        flg[x] = 0
        p = 0
        for y in glaph[x]:
            p = max(p,f(y)+1)
        dp[x] = p
    return dp[x]
n,m = map(int,input().split())
flg = [1]*(n+1)
dp = [0]*(n+1)
glaph = [[] for i in range(n+1)]
for _ in range(m):
    x,y = map(int,input().split())
    glaph[x].append(y)
ans = 0
for i in range(1,n+1):
    ans = max(ans,f(i))
print(ans)
while True:
    x,y = map(int, input().split())
    if x == 0 and y == 0:
        break
    elif x <= y:
        print (x,y)
    else x > y
        print (y,x)

### FIXED CODE ###

while True:
    x,y = map(int, input().split())
    if x == 0 and y == 0 :
        break
    elif x <= y :
        print (x,y)
    else :
        print (y,x)
import collections

n, m = map(int, input().split())
list_ac = set()
dic = collections.defaultdict(lambda:0)

ac = 0
wa = 0

for _ in range(m):
    p, s = input().split()
    if s == "WA" and p not in list_ac:
        dic[p] += 1
    elif s =="AC" and p not in list_ac:
        list_ac.append(p)
        ac += 1
        if p in dic:
            wa += dic[p]
            
print(ac, wa)

### FIXED CODE ###

import collections

n, m = map(int, input().split())
list_ac = set()
dic = collections.defaultdict(lambda:0)

ac = 0
wa = 0

for _ in range(m):
    p, s = input().split()
    if s == "WA" and p not in list_ac:
        dic[p] += 1
    elif s =="AC" and p not in list_ac:
        list_ac.add(p)
        ac += 1
        if p in dic:
            wa += dic[p]
            
print(ac, wa)
L,N=(int(i) for i in input().split())
X = []
for i in range(0,N):
    a = int(input())
    X.append(a)
import math
result=0
if X[math.ceil(N/2)]<L/2:
  for i in range (1,N/2):
    for j in range (N,L/2,-1):
      result+=abs(X[j]-X[i])
else:
   for i in range (1,N/2):
    for j in range (N,N/2,-1):
      result+=abs(X[i]-X[j])
print(result)

### FIXED CODE ###

a,b,c=(int(i) for i in input().split())
if b+1>=c:
  print(b+c)
else:
  if a+1>=c-b:
    print(b+c)
  else:
    print(2*b+a+1)
a=[list(map(int,input().split()))]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')


### FIXED CODE ###

a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')
n = int(input())
data = input().split()

ans = "APPROVED"

for i in range(n):
  num = int(data[i])
  if !(num % 6 == 0 or num % 10 == 0):
    ans = "DENIED"
    break

print(ans)


### FIXED CODE ###

n = int(input())
data = input().split()
 
ans = "APPROVED"
 
for i in range(n):
  num = int(data[i])
  if num % 2 == 0:
    if num % 3 != 0 and num % 5 != 0:
      ans = "DENIED"
      break  
 
print(ans)
N, M = map(int, input().split())

_number = []
P = []
Y = []
yp = [[] for i in range(N+1)]
_yp = []

for i in range(M):
    p, y = map(int, input().split())
    yp[p].append([y, i])

# print(yp)

_l_yp = len(yp)

for i in range(_l_yp):
    yp[i].sort()


ans_yp = [[] for i in range(N+1)]

for i in range(_l_yp):
    nga_yp = len(yp[i])

    for j in range(nga_yp):
    #    print(i, j)
    #    print(yp[i][j][1])
       ans_yp[yp[i][j][1]].append(i)
       ans_yp[yp[i][j][1]].append(j+1)


__len = len(ans_yp)

for i in range(__len):
    buff = ''
    for d in range(2):
        ans = ''
        for j in range((6-len(str(ans_yp[i][d])))):
            ans += '0'

        buff += ans + str(ans_yp[i][d])

    print(buff)



### FIXED CODE ###

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

_number = []
P = []
Y = []
yp = [[] for i in range(N+1)]
_yp = []

for i in range(M):
    p, y = map(int, input().split())
    yp[p].append([y, i])

# print(yp)

_l_yp = len(yp)

for i in range(_l_yp):
    yp[i].sort()


ans_yp = [[] for i in range(M)]

for i in range(_l_yp):
    nga_yp = len(yp[i])

    for j in range(nga_yp):
    #    print(i, j)
    #    print(yp[i][j][1])
       ans_yp[yp[i][j][1]].append(i)
       ans_yp[yp[i][j][1]].append(j+1)


__len = len(ans_yp)

for i in range(__len):
    buff = ''
    for d in range(2):
        ans = ''
        for j in range((6-len(str(ans_yp[i][d])))):
            ans += '0'

        buff += ans + str(ans_yp[i][d])

    print(buff)
from collections import deque
s=deque(input())
A=deque()
for i in range(len(s)):
  a=s.popleft()
  if a=="B":
    A.pop()
  else:
    A.append(a)
print("".join(A))

### FIXED CODE ###

from collections import deque
s=deque(input())
A=deque()
for i in range(len(s)):
  a=s.popleft()
  if a=="B":
    if len(A)>0:
      A.pop()
  else:
    A.append(a)
print("".join(A))
S = int(input() S >= 10000)
s = int(input())
a = int(h = (S / 3600), m = ((S % 3600) / 60), for s in range(0, 60):.split )
print[a(h, m, s)]

### FIXED CODE ###

S = int(input())

s = S % 60
m = S // 60 % 60
h = S // 60 // 60

print("{0}:{1}:{2}".format(h,m,s))
S = list(input())
if S[0］== S[1] == S[2]:
     print("No")
else:
     print("Yes")

### FIXED CODE ###

s = list(input())
if s[0] == s[1] == s[2]:
    print('No')
else:
    print('Yes')
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 99999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            d = ii
    ans.append(d)
    
for i in range(a[0]):
    print(ans[i])


### FIXED CODE ###

a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 9999999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1])
            d = ii
    ans.append(d+1)
    
for i in range(a[0]):
    print(ans[i])
import bisect
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i+1)
	elif s[i] == "G":
		g.append(i+1)
	else:
		b.append(i+1)
ans = 0
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k < b[-1] and k > b[0]:
			x = bisect.bisect_left(b,k)
			if b[x] == k:
				ans -= 1
		if m < b[-1] and m > b[0]:
			x = bisect.bisect_left(b,m)
			if b[x] == m:
				ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if b[x] == l:
				ans -= 1
print (ans)

### FIXED CODE ###

import bisect
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i+1)
	elif s[i] == "G":
		g.append(i+1)
	else:
		b.append(i+1)
ans = 0
if len(r) == 0 or len(g) == 0 or len(b) == 0:
	print (0)
	exit()
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k <= b[-1] and k >= b[0]:
			x = bisect.bisect_left(b,k)
			if x >= 0 and x < len(b):
				if b[x] == k:
					ans -= 1
		if m <= b[-1] and m >= b[0]:
			x = bisect.bisect_left(b,m)
			if x >= 0 and x < len(b):
				if b[x] == m:
					ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if x >= 0 and x < len(b):
				if b[x] == l:
					ans -= 1
print (ans)
a,b,k = map(int,input().split())

ans=[]

for i in range(1,max(a,b)):
  if a%i ==0 and b%i ==0:
    ans.append(i)

    
ans.sort(reverse=True)
print(ans[k-1])

### FIXED CODE ###

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

ans=[]

for i in range(1,max(a,b)+1):
  if a%i ==0 and b%i ==0:
    ans.append(i)

    
ans.sort(reverse=True)
print(ans[k-1])
s1 = raw_input()
s2 = raw_input()
s2 = s2.split(" ")
f = 0
for a,b in enumerate(s2):
    if str(s2[int(b)-1]) == str(a+1):
        f = f+1
print str(f/2)

### FIXED CODE ###

s1 = input()
s2 = input()
s2 = s2.split(" ")
f = 0
for a,b in enumerate(s2):
    if str(s2[int(b)-1]) == str(a+1):
        f = f+1
print (int(f/2))
N,X=list(map(int,input().split()))
p=[]
a=[]
def search(N):
    if N==0:
        p.append(1)
        a.append(1)
        return 1,1
    else:
        search(N-1)
        p.append(2*p[N-1]+1)
        a.append(2*a[N-1]+3)
search(N)
def bug(N,X):#p,a
    if X==1:return 0
    if 1<X<=1+a[N-1]:
        return bug(N-1,X-1)
    elif X==a[N-1]+2:
        return p[N-1]+1
    elif a[N-1]+2<X<=2+2*a[N-1]:
        return p[N-1]+1+bug(N-1,X-2-a[N-1]-1)
    elif X==3+2*a[N-1]:
        return 2*p[N-1]-1
print(bug(N,X))

### FIXED CODE ###

N,X=list(map(int,input().split()))
p=[]
a=[]
def search(N):
    if N==0:
        p.append(1)
        a.append(1)
        return 1,1
    else:
        search(N-1)
        p.append(2*p[N-1]+1)
        a.append(2*a[N-1]+3)
search(N)
def bug(N,X):#p,a
    if N==0 and X>=1:return 1
    if X==1:return 0
    if 1<X<=1+a[N-1]:
        return bug(N-1,X-1)
    elif X==a[N-1]+2:
        return p[N-1]+1
    elif a[N-1]+2<X<=2+2*a[N-1]:
        return p[N-1]+1+bug(N-1,X-2-a[N-1])
    elif X==3+2*a[N-1]:
        return 2*p[N-1]+1
print(bug(N,X))
s = input()
listA = ["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"]
for i in range(27):
  if s.count(listA[i])==0:
    print(listA[i])
    break

### FIXED CODE ###

s = input()
x=0
listA = ["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"]
for i in range(26):
  if s.count(listA[i])==0:
    print(listA[i])
    x=1
    break
if x==0:
  print("None")
import math
N, x = map(int, input().split())
L = [int(x) for x in input().split()]
ans = 0
for i in L[1:]:
    if L[i-1] + L[i] > x:
        if L[i-1] > x:
            ans += L[i-1] - x
            ans += L[i]
            L[i] = 0
        else:
            ans += L[i] + L[i-1] - x
            L[i] = x - L[i-1]
print(ans)


### FIXED CODE ###

import math
N, x = map(int, input().split())
L = [int(x) for x in input().split()]
ans = 0
for i in range(1,N):
    if L[i-1] + L[i] > x:
        if L[i-1] > x:
            ans += L[i-1] - x
            ans += L[i]
            L[i] = 0
        else:
            ans += L[i] + L[i-1] - x
            L[i] = x - L[i-1]
print(ans)
list1 = [int(i) for i in input().split()]
print(list[0])

### FIXED CODE ###

item = [int(i) for i in input().split()]
print(item[0]*item[1],2*(item[0]+item[1]))
H, N = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H + 1):
    for a, b in AB:
        h_new = min(h + a, H)
        dp[h_new] = min(dp[h] + b, dp[h_new])
print(dp[-1])

### FIXED CODE ###

import math

H, A = map(int, input().split())
print(math.ceil(H / A))
N = int(input())
H = list(map(int, input().split()))
ok = True
for i in range(N - 2):
    if (H[i] > H[i + 1] and H[i + 1] > H[i + 2]) or H[i]-H[i+1]>1:
        ok = False
if H[-2] - H[-1] > 1:
    of = False
if ok:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

for i in range(1,N):
    if H[i-1] > H[i]:
        print("No")
        exit()

    if H[i-1] < H[i]:
        H[i] -= 1

print("Yes")
a,b,c=map(int, input().split())
l =sorted([a,b,c])

s = sum(l[:2])
print(s)

### FIXED CODE ###

n = int(input())
a = n%1000

if a == 0 :
  print(0)
if a != 0 :
  print(1000 - a)
D=[]
for i in range(5):
  D.append(int(input()))

D_mod_max = 9
for i in range(5):
  if (D[i]%10 != 0) & (D[i]%10 < D_mod_max):
    D_remove = D[i]
    D_mod_max = D[i]%10
    
D.remove(D_remove)

sum=0
for i in range(len(D)):
  if D[i]%10 !=0:
    sum=sum+D[i]+(10-D[i]%10)
  else:
    sum=sum+D[i]

sum=sum+D_remove

print(sum)

### FIXED CODE ###

D=[]
for i in range(5):
  D.append(int(input()))

D_mod_max = D[0]%10
D_remove = D[0]

for i in range(1,5):
  if D_mod_max==0:
    D_remove = D[i]
    D_mod_max = D[i]%10
    
  elif (D[i]%10 != 0) & (D[i]%10 < D_mod_max):
    D_remove = D[i]
    D_mod_max = D[i]%10
    
D.remove(D_remove)

sum=0
for i in range(len(D)):
  if D[i]%10 !=0:
    sum=sum+D[i]+(10-D[i]%10)
  else:
    sum=sum+D[i]

sum=sum+D_remove

print(sum)
import math
n = int(input())
ans=[0]*n
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            ans[x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x] += 1
print(ans,sep="\n")

### FIXED CODE ###

n = int(input())
ans=[0]*(n+1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x * x + y * y + z * z + x * y + y * z + z * x
            if n >= a >= 1:
                ans[a] += 1
print(*ans[1:],sep="\n")
S = input()
if(S[0] != S[1] && S[1] != S[2] && S[2] != S[0]):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = input()
if (S[0] == S[1]) or (S[1] == S[2]) or (S[2] == S[0]):
    print("No")
else:
    print("Yes")
import static org.hamcrest.CoreMatchers.is;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Assert;
import org.junit.Test;

public class MainTest {

	@Test
	public void 入力例_1() throws Exception {
		String input = 
			"1900";
		String output = 
			"100";

		assertIO(input, output);
	}

	@Test
	public void 入力例_2() throws Exception {
		String input = 
			"3000";
		String output = 
			"0";

		assertIO(input, output);
	}

	private void assertIO(String input, String output) throws Exception {
		ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
		System.setIn(in);

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		System.setOut(new PrintStream(out));

		Main.main(new String[0]);

		Assert.assertThat(out.toString(), is(output + System.lineSeparator()));
	}
}
n=int(input())
print(n)


### FIXED CODE ###

n=int(input())
print(1000-n%1000 if n%1000!=0 else 0)
class BTree:
    def __init__(self):
        self.value = "ZZZ"
        self.left = None
        self.right = None

    def insert(self, s):
        if self.value is None:
            self.value = s
        else:
            if self.value < s:
                if self.right is None:
                    self.right = BTree().insert(s)
                else:
                    self.right = self.right.insert(s)
            elif s < self.value:
                if self.left is None:
                    self.left = BTree().insert(s)
                else:
                    self.left = self.left.insert(s)
        return self

    def find(self, s):
        if self.value == s:
            return True
        elif self.value < s:
            if self.right is None:
                return False
            else:
                return self.right.find(s)
        else:
            if self.left is None:
                return False
            else:
                return self.left.find(s)


n = int(input())
tree = BTree()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        tree = tree.insert(command[1])
    elif command[0] == "find":
        if tree.find(command[1]):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

n = int(input())
data = set()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data.add(command[1])
    elif command[0] == "find":
        if command[1] in data:
            print("yes")
        else:
            print("no")
S = int(input))
h = int(S / (60 * 60))
m = int(S / 60) % 60
s = S % 60

print('{}:{}:{}:.format(h,m,s))

### FIXED CODE ###

S = int(input())
h = (S // 3600)
m = ((S % 3600) // 60)
s = (S % 60)
  
print("{}:{}:{}".format(h,m,s))
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from heapq import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
3 4
4 3
4 1
2 2
'''

def solve(l,m):
	n = len(l)
	L = [[] for i in range(5)]
	for i in l:
		d,r = i
		L[d].append(r)
	ans = 0
	hp = []
	for i in range(1,m+1):
		for j in L[i]:
			heappush(hp,-j)
		if(hp):
			ans -= heappop(hp)
	return ans

N,M = list(map(int, stdin.readline().rstrip().split()))
l = []
for _ in range(N):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	l.append([a,b])
ans = solve(l,M)
print(ans)



### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from heapq import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
3 4
4 3
4 1
2 2
'''

def solve(l,m):
	n = len(l)
	L = [[] for i in range(10**5+1)]
	for i in l:
		d,r = i
		L[d].append(r)
	ans = 0
	hp = []
	for i in range(1,m+1):
		for j in L[i]:
			heappush(hp,-j)
		if(hp):
			ans -= heappop(hp)
	return ans

N,M = list(map(int, stdin.readline().rstrip().split()))
l = []
for _ in range(N):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	l.append([a,b])
ans = solve(l,M)
print(ans)
import math
n,k = map(int,input().split())
def com(x,y):
  return math.factorial(x)//math.factorial(x-y)*math.factorial(y)

for i in range(1,k-1):
  t = com(n-k+i,i)
  s = com(k+i-1,i)
  u = int(s*t(10**9+7))
  print(u)

### FIXED CODE ###

import math
 
def combination_count(n,k):
    if k > n or k < 0:
        return 0
    if n == 0 or k == 0:
        return 1
    
    s = math.factorial(n)
    t = math.factorial(k)
    u = math.factorial(n-k)
    
    return s//(t*u)
    
n,k = map(int,input().split())
 
mod = 10**9 + 7
 
for i in range(1,k+1):
    x = combination_count(n-k+1,i) * combination_count(k-1, i-1)
    print(x%mod)
import numpy as np

N = int(input())
S = []
for i in range(N):
  S.append(list(input()))

S = np.array(S)

s = list('abcdefghijklmnopqrstuvwxyz')

T = np.zeros([N, 26])

for i, a in enumerate(s):
  T[:, i] = np.sum(S == a, axis=1)

T3 = np.atleast_3d(T)

print(int((np.sum(np.prod(T3 == T3.T, axis=1)) - N) / 2))



### FIXED CODE ###

def number(x):
  return int((1 + (1 + 8*x)**0.5) / 2)


N = int(input())
d = {}
for i in range(N):
  s = ''.join(sorted(input()))
  if s in d.keys():
    d[s] += number(d[s])
  else:
    d[s] = 0


print(sum(d.values()))
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  
  if i < 0 or j < 0 or k < 0 or i < j:
    return 0
  
  dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
  return dp[(i, j, k)]

print(perm(n, 0, k))

### FIXED CODE ###

r = int(input())

print(3*r*r)