Harryxun/stf_run huggingface dataset:
import sys
N, L, T = [int(x) for x in input().strip().split(" ")]

xys = []
candidates = []
for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    xys.append((x,y))
    candidates.append((x + (1 if y == 1 else -1) * T)%L)

x0, y0 = xys[0]

dxs = []
pr_x = None
counter = 0
for x, y in xys[1:]:
    if y != y0:
        if pr_x == None:
            if y0 == 1:
                a = (x - x0)
        else:
            dxs.append(x - pr_x)
        pr_x = x
        counter += 1
if y0 == 2:
    a = (L - pr_x) + x0

ree = (2*T)%L
num_round = (2*T)//L
ree = ree - a
if ree < 0:
    max_i = 0
else:
    for i, dx in enumerate(dxs if y0 == 1 else dxs[::-1]):
        ree = ree - dx
        if ree < 0:
            max_i = i + 1
            break
    else:
        max_i = counter

c_n = num_round * counter + max_i - 1

rep = ( 
        ((1 if y0 == 1 else -1) * (c_n % N) % N) + 1,
        ((x0 + (1 if y0 == 1 else -1) * (T % L)) % L)
        )
result = []
for i in range(N):
    i = i + 1
    if ree != 0:
        print(candidates[(rep[0] + i) % N])
    else:
        print(candidates[(rep[0] + i - 1) % N])



### FIXED CODE ###


import sys
N, L, T = [int(x) for x in input().strip().split(" ")]

xys = []
candidates = []
for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    xys.append((x,y))
    candidates.append((x + (1 if y == 1 else -1) * T)%L)

x0, y0 = xys[0]

dxs = []
pr_x = None
counter = 0
for x, y in xys[1:]:
    if y != y0:
        if pr_x == None:
            if y0 == 1:
                a = (x - x0)
        else:
            dxs.append(x - pr_x)
        pr_x = x
        counter += 1

if pr_x == None:
    for x in candidates:
        print(x)
    sys.exit()
if y0 == 2:
    a = (L - pr_x) + x0

ree = (2*T)%L
num_round = (2*T)//L
ree = ree - a
if ree <= 0:
    max_i = 0
else:
    for i, dx in enumerate(dxs if y0 == 1 else dxs[::-1]):
        ree = ree - dx
        if ree <= 0:
            max_i = i + 1
            break
    else:
        max_i = counter

if ree == 0 and y0 == 2:
    max_i += 1

c_n = num_round * counter + max_i

rep = ( 
        ((1 if y0 == 1 else -1) * (c_n % N) % N),
        ((x0 + (1 if y0 == 1 else -1) * (T % L)) % L)
        )


candidates = sorted(candidates)

for i, c in enumerate(candidates):
    if c == rep[1]:
        start = i - rep[0]
        break

for j in range(N):
    print(candidates[(start + j) % N])
a, b, c = map(int, input().split())

a = a[0]
b = b[0]
c = c[0]

print(a + b + c)

### FIXED CODE ###

a, b, c = input().split()
 
a = a[0]
b = b[0]
c = c[0]
 
print(a + b + c)
import math

X = int(input())

i = 0
j = 0
while True:
   i += 1
   a = math.pow((X + math.pow(i, 5)), float(1/5))
   if a.is_integer():
      print("%d %d" % (a, i))
      exit()
   j -= 1
   a = math.pow((X + math.pow(j, 5)), float(1/5))
   if a.is_integer():
      print("%d %d" % (a, j))
      exit()

### FIXED CODE ###

import sys
x = int(input())

for i in range(-1000, 1001):
    for j in range(-1000, 1001):
        if i**5-j**5 == x:
            print(i, j)
            sys.exit()
s=input()
s[5]=' '
s[13]=' '
print(s)

### FIXED CODE ###

s=input()
print(s[0:5]+' '+s[6:13]+' '+s[14:19])
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
N = I()
A = readInts()
import collections
dic = collections.Counter(A)
A = set(A)
is_prime = [True] * (2*10**5+1)
for a in A:
    if is_prime[a]:
        for v in range(a*2,2*10**5+1,a):
            is_prime[v] = False
cnt = 0
for a in A:
    if is_prime[a]:
        cnt += 1
for k,v in dic.items():
    if v >= 2 and is_prime[k]:
        cnt -= 1
print(cnt)


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = sorted(readInts())
dic = defaultdict(int)
cnt = 0
for i in A:
   dic[i] += 1
A = list(set(A))
# ------------
is_prime = [True] * (10**6+1)
#print('a')
for i in range(len(A)):
    #ll += 1
    #print(i)
    #print(A[i])
    if is_prime[A[i]] == True:
        for j in range(2*A[i], 10**6+1,A[i]):
            is_prime[j] = False # その素数の倍数のやつ

 # -----------
cnt = 0
if A[0] == 1:
    if dic[1] >= 2:
        print(0)
        exit()
    else:
        print(1)
        exit()
for a in A:
    if is_prime[a] and not dic[a] >= 2:
        #print(a)
        cnt += 1
print(cnt)
import numpy as np

mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = np.triu(np.outer(a, a), k=1).sum()

print(ans % mod)


### FIXED CODE ###

mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
dp = [0]

def calc(A, n, dp):
    dp += [A[0] * A[1]]
    rsum = A[0] + A[1]
    for i in range(2, n):
        dp += [dp[-1] + rsum * A[i]]
        rsum += A[i]

    i = dp.index(max(dp))
    rsum = 0
    for j in range(i + 1):
        rsum += A[j]
    res = max(dp)
    dp2 = max(dp)
    for j in range(0, i):
        rsum -= A[j]
        dp2 -= A[j] * rsum
        res = max(dp2, res)
    return res

ans = calc(a, n, dp) % mod
print(ans)
import numpy as np
import scipy.linalg as linalg

n = int(input())
b = [[int(i)] for i in input().split()]

diag = [.5 for i in range(n)]

A = np.diag(diag)
for i in range(n-1):
  A[i][i+1] = .5

A[n-1][0] = .5

LU = linalg.lu_factor(A)
x = linalg.lu_solve(LU, b)

tmp = [str(int(round(i[0], 0))) for i in x]
print(' '.join(tmp))


### FIXED CODE ###

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

all_ = sum(a)

x1 = all_ - 2 * (sum([a[i] for i in range(1, n, 2)]))
x = [x1]

for i in range(1, n):
  x_i = 2 * a[i-1] - x[i-1]
  x.append(x_i)

print(' '.join(list(map(str, x))))
N, A, B = map(int, input().split())
ans = []
for i in range(1, N):
    ans.append(A * i + B / N * (N - i))
print(min(ans))


### FIXED CODE ###

N, A, B = map(int, input().split())
if A * N < B:
    print(A * N)
else:
    print(B)
a=int(input())
c=a+1
for i in range(10000000000,2,-1):
	if a%i==0:
       b=a/i
       if i+b<c:
       	c=i+b
print(int(c-2))

### FIXED CODE ###

a=int(input())
c=a+1
for i in range(1,10000000,1):
    if a%i==0:
        b=a/i
        if i+b<=c:
            c=i+b
print(int(c-2))
n=int(input())
dat = list(map(int, input().split()))
dan = []
for e in dat:
    e = list(str(bin(e)))
    e.reverse()

re = 0
for e in dat:
     w=e.index('1')
     
     
print(re)
     

 
      
      
             


    
    
     
                

         
           




### FIXED CODE ###

import sys

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

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

main()
s=list(map(int,input()))
for i in range(10):
  s[2]=s[0]*s[2]-s[1]
  print(s[2])


### FIXED CODE ###

x={}
i=list(map(int,input().split()))
for s in range(10):
  x[s]=int((i[2]-(i[1]/(i[0]-1)))*i[0]**(s+1)+(i[1]/(i[0]-1)))
  print(x[s])
def solution(x):
  p = sum([a[i]//x for i in range(N)])
  return p
def solvance(y,z):
  if z-y <= 1:
    if solution(y) == K:
      return y
    else:
      return z
  else:
    w = (y+z)//2
    #print(y,w,z)
    if solution(w) > K:
      return solvance(w,z)
    else:
      return solvance(y,w)

N,K = map(int,input().split())
a = list(map(int,input().split()))
if K == 0:
  print(max(a))
else:
  ansM = sum(a)//K
  ansm = sum(a)//(K+N)
  ans = solvance(ansm,ansM)
  print(ans)

### FIXED CODE ###

import math
def solution(x):
  p = sum([math.ceil(a[i]/x)-1 for i in range(N)])
  return p
def solvance(y,z):
  if z-y <= 1:
    return z
  else:
    w = (y+z)//2
    #print(y,w,z)
    if solution(w) > K:
      return solvance(w,z)
    else:
      return solvance(y,w)

N,K = map(int,input().split())
a = list(map(int,input().split()))
if K == 0:
  print(max(a))
else:
  ansM = (sum(a)//K)+1
  ansm = sum(a)//(K+N)
  ans = solvance(ansm,ansM)
  print(ans)
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

@lru_cache
def combination(n, k):
    if k == 0:
        return 1
    else:
        return ((combination(n, k-1) * (n-k+1) % MOD) * pow(k, MOD-2, MOD)) % MOD

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

s = 0
for m in range(0, min(k+1, n)):
    s += combination(n, min(m, n - m)) * combination(n - 1, min(m, n - m - 1))
    s %= MOD

print(s)

### FIXED CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

@lru_cache(None)
def combination(n, k):
    if k == 0:
        return 1
    else:
        return ((combination(n, k-1) * (n-k+1) % MOD) * pow(k, MOD-2, MOD)) % MOD

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

s = 0
for m in range(0, min(k+1, n)):
    s += combination(n, min(m, n - m)) * combination(n - 1, min(m, n - m - 1))
    s %= MOD

print(s)
#coding:utf-8

li = input("lkdfkgkfg").split()
t = 0
s = int(li.pop(5))
for i in li:
    for k in li:
        if int(k) - int(i) >= s:
            t = 1

if t == 0:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

li = []
for l in range(6):
    li.append(input())

t = 0
s = li.pop()
for i in li:
    for k in li:
        if int(k) - int(i) > int(s):
            t = 1
        elif int(i) - int(k) > int(s):
            t = 1

if t == 0:
    print("Yay!")
else:
    print(":(")
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if d2 = 1:
    print(1)
else:
    print(0)

### FIXED CODE ###

m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if d2 == 1:
    print(1)
else:
    print(0)
if N==2:
    print(max(A))
else:
    gcds = []
    for i in range(len(A)-1):
        if i == 0:
            gcds.append(gcd(A[0],A[1]))
        else:
            gcds.append(gcd(gcds[-1],A[i]))
    gcds = np.asarray(gcds)
    
    index = []
    for idx,n in enumerate(gcds.min() == gcds):
        if n==True:
            index.append(idx)
    a = []
    for i in index:
        if i+1 in index:
            None
        else:
            a.append(i+1)
    for i in a:
        index.append(i)
    gcds = []
    for idx in index:
        A_temp = copy.deepcopy(A)
        A_temp.pop(idx)
        gcds_temp = []
        for i in range(len(A_temp)-1):
            if i ==0:
                gcds_temp.append(gcd(A_temp[0],A_temp[1]))
            else:
                gcds_temp.append(gcd(gcds_temp[-1],A_temp[i]))
        gcds.append(min(gcds_temp))
    print(max(gcds))


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a  
lgcds = [A[0]]
rgcds = [A[N-1]]
for n in range(N-2):
    lgcds.append(gcd(lgcds[-1],A[n+1]))
    rgcds.append(gcd(rgcds[-1],A[-2-n]))
gcds = [lgcds[-1],rgcds[-1]]
for i in range(N-2):
    gcds.append(gcd(lgcds[i],rgcds[-2-i]))
print(max(gcds))
N, M = map(int, input().split())
P = [0] * (N + 1)
p = 10 ** 9 + 7
B = int(input())
M -= 1
P[0] = 1
P[1] = 1
if B == 1:
  P[1] = 0
  if M > 0:
    B = int(input())
    M -= 1
for i in range(2, N + 1):
  P[i] = (P[i - 1] + P[i - 2]) % p
  if i == B:
    P[i] = 0
    if M > 0:
      B = int(input())
      M -= 1
print(P[N])

### FIXED CODE ###

N, M = map(int, input().split())
P = [0] * (N + 1)
p = 10 ** 9 + 7
B = 0
if M > 0:
  B = int(input())
  M -= 1
P[0] = 1
P[1] = 1
if B == 1:
  P[1] = 0
  if M > 0:
    B = int(input())
    M -= 1
for i in range(2, N + 1):
  P[i] = (P[i - 1] + P[i - 2]) % p
  if i == B:
    P[i] = 0
    if M > 0:
      B = int(input())
      M -= 1
print(P[N])
inputs = map(int, input.split(" "))

is_denied = False

for i in inputs:
  if i % 2 ==0:
    if i % 3 != 0 or i % 5 == 0:
      is_denied = True
      

if is_denied:
  print("DENIED")
else:
  print("APPROVED")

### FIXED CODE ###

input()
inputs = map(int, input().split(" "))

is_denied = False
for i in inputs:
  if i % 2 ==0 and ( i % 3 != 0 and i % 5 != 0):
      is_denied = True
      
if is_denied:
  print("DENIED")
else:
  print("APPROVED")
a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else
  print("NO")


### FIXED CODE ###

a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else:
  print("NO")
a=int(input())
import math
b=int(math.sqrt(a))
c=1
for i in range(b):
  c=max(c,(int(a**(1/i)))**i)
print(c)

### FIXED CODE ###

X = int(input())
if X != 1:
  A =[]
  for b in range(1,int(X**0.5)+1):
    for p in range(2,X):
      if b**p > X:
        A.append(b**(p-1))
        break
  print(max(A))
else:
  print(1)
n = int(input())
p = list(map(int, input().split()))
for i in range(n)
  if p[i] < p[i+1]:
    p.pop(i+1)
print(p.count())

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
ans = 0
min_p = p[0]
for i in p:
  if i <= min_p:
    ans += 1
    min_p = i
print(ans)
from math import gcd
print(360//gcd(360,int(input()))

### FIXED CODE ###

from math import gcd
print(360//gcd(360,int(input())))
V = list(map(int, input().split()))
V = sorted(V, reversed=True)
ans = V[0] * 10 + V[1] + V[2]
print(ans)

### FIXED CODE ###

V = list(map(int, input().split()))
V = sorted(V, reverse=True)
ans = V[0] * 10 + V[1] + V[2]
print(ans)
a = input()
s = list(a)
n = 0

for i in s:
  n += int(i)

print("Yes" if int(a)%n == 0 else "No")


### FIXED CODE ###

s = input()
print(s.count("+") - s.count("-"))
n=int(input())
ls=list(map(int,input().split()))
ls.sort(reserved=True)
ans=ls[0]
pls=[ls.pop(0),ls.pop(0)]#入った人を突っ込む
cnt=0#plsの隣使いきりカウント
scnt=0#2人行けるからそこのカウント

for i in ls:
  pls.append(i)
  ans+=pls[cnt+1]
  if scnt==0:
    scnt=1
  else:
    scnt=0
    cnt+=1
print(ans)

### FIXED CODE ###

n=int(input())
ls=list(map(int,input().split()))
ls.sort(reverse=True)
ans=ls[0]
pls=[ls.pop(0),ls.pop(0)]#入った人を突っ込む
cnt=0#plsの隣使いきりカウント
scnt=0#2人行けるからそこのカウント

for i in ls:
  pls.append(i)
  ans+=pls[cnt+1]
  if scnt==0:
    scnt=1
  else:
    scnt=0
    cnt+=1
print(ans)
import sys;sys.setrecursionlimit(100000);n,k=map(int,input().split());x,t=10**9+7,[set()for _ in range(n)]
for i in range(n-1):a,b=map(int,input().split());t[a-1].add(b);t[b-1].add(a)
c=k
def b(o):
  for i,j in enumerate(t[o-1]):c=(c*(k-2-i))%x;t[j-1].discard(o);b(j)
for i,j in enumerate(t[0]):c=(c*(k-1-i))%x;t[j-1].discard(1);b(j)
print(c)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
n,k=map(int,input().split())
ans=k
t=[set()for i in range(n)]
dp=[k]+[0]*(n-1)
for i in range(n-1):
  a,b=map(int,input().split())
  t[a-1].add(b)
  t[b-1].add(a)
no=1
w=k
b=True
def a(noo):
  global ans
  w=k
  for i in t[noo-1]:
    t[i-1].discard(noo)
    if w==0:print(0);exit()
    dp[i-1]=w-2;ans=(ans*(w-2))%(10**9+7)
    w-=1
    a(i)
for i in t[no-1]:
  t[i-1].discard(no)
  w-=1
  dp[i-1]=w;ans=(ans*w)%(10**9+7)
  a(i)
print(ans)
n,m = input().split()
add = 0
n = int(n)
m = int(m)
lst = list(map(int,input().split()))
for i in lst:
  add += i
if add>n :
  print(-1)
elif(add = n):
  print(0)
else:
  print(n-add)

### FIXED CODE ###

n,m = input().split()
add = 0
n = int(n)
m = int(m)
lst = list(map(int,input().split()))
for i in lst:
  add += i
if add>n :
  print(-1)
elif(add == n):
  print(0)
else:
  print(n-add)
h,n = map(int,input().split())
a = list(map(int,input().split()))
x = max(a)
a.remove(x)
y = max(a)
if x+y >= h:
         print("Yes")
else:
         print("No")

### FIXED CODE ###

h,n = map(int,input().split())
a = list(map(int,input().split()))
if sum(a)>= h:
         print("Yes")
else:
         print("No")
print(''.join([1,2]))

### FIXED CODE ###

#!python3.8
# -*- coding: utf-8 -*-
# abc173/abc173_a
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    a = math.ceil(N / 1000)
    ans = a * 1000 - N
    print(ans)
    return

main()
N = int(input())
T_before =int(input())

for i in range(1,N):
    T =int(input())
    f=fractions.gcd(T,T_before)
    T_before=T*T_before//f
    
print(T_before)

### FIXED CODE ###

import fractions
N = int(input())
T_before =int(input())

for i in range(1,N):
    T =int(input())
    f=fractions.gcd(T,T_before)
    T_before=T*T_before//f
    
print(T_before)
import collections
def f(s):
  h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G', }
  for k in h:
    h[k[::-1]] = h[k]
  c = collections.Counter()
  cc = [None] * (len(s)+1)
  cc[-1] = c
  for jj in range(len(s)-1,-1,-1):
    c[s[jj]]+=1
    cc[jj] = c
    res = 0
    for i in range(len(s)):
      for j in range(i+1, len(s)):
        if s[j] != s[i]:
          res += cc[j+1][h[(s[i],s[j])]]

  return res
raw_input()
print f(raw_input())


### FIXED CODE ###

import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())
a1, b1 = (int(i) for i in raw_input().split(' '))
a2, b2 = (int(i) for i in raw_input().split(' '))
a3, b3 = (int(i) for i in raw_input().split(' '))


def func():
    count_1 = 0
    count_2 = 0
    count_3 = 0
    count_4 = 0
    for x in [a1,a2,a3,b1,b2,b3]:
        if x == 1:
            count_1 += 1
        elif x == 2:
            count_2 += 1
        elif x ==3:
            count_3 += 1
        elif x ==4:
            count_4 += 1
        else:
            print('error')

    for count in [count_1, count_2,count_3,count_4]:
        if count == 0 or count >= 3:
            print('NO')
            return
    print('YES')

func()


### FIXED CODE ###

a1, b1 = (int(i) for i in raw_input().split(' '))
a2, b2 = (int(i) for i in raw_input().split(' '))
a3, b3 = (int(i) for i in raw_input().split(' '))


def func():
    count_1 = 0
    count_2 = 0
    count_3 = 0
    count_4 = 0
    for x in [a1,a2,a3,b1,b2,b3]:
        if x == 1:
            count_1 += 1
        elif x == 2:
            count_2 += 1
        elif x ==3:
            count_3 += 1
        elif x ==4:
            count_4 += 1
        else:
            print('error')

    for count in [count_1, count_2,count_3,count_4]:
        if count == 0 or count >= 3:
            print('NO')
            return
    print('YES')

func()
N,M=map(int,input().split())
n=['0']*N
for i in range(M):
    s,c=map(str,input().split())
    S.append(s)
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        print(-1)
        exit()
    if s=='1' and c=='0':
        print(-1)
        exit()
    n[int(s)-1]=c
if n[0]=='0':
    n[0]='1'
print(''.join(n))

### FIXED CODE ###

N,M=map(int,input().split())
n=['0']*N
a=0
for i in range(M):
    s,c=map(str,input().split())
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        a=1
    if s=='1' and c=='0' and N!=1:
        a=1
    n[int(s)-1]=c
if n[0]=='0' and N!=1:
    n[0]='1'
if a==0:
    print(''.join(n))
else:
    print(-1)
import math
a,b,c,d = map(int,input().split())

#A-1
A1 = (a-1) - (a-1)//c -(a-1)b//d +c*d//(gcd(c,d))*(a-1)

#Bまで
B = b - b//c - b//d +c*d//(gcd(c,d)) *b

print(B-A1)

### FIXED CODE ###

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

#A-1
A1 = (a-1) - (a-1)//c -(a-1)//d +(a-1)//(c*d//cd)
 
#Bまで
B = b - b//c - b//d +b//(c*d//cd)
 
print(B-A1)
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)


### FIXED CODE ###

r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 3*10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def is_prime(num):
    for i in range(2, num):  # 第二引数は sqrt(num)+1 でも良い
        if num % i == 0:
            return False

    return True

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

g = math.gcd(A, B)

# print(g)
div = make_divisors(g)
# print(div)
p = [i for i in div if is_prime(i)]
# print(p)
print(len(p))

### FIXED CODE ###

import math
import fractions
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def is_prime(p):
    if p == 1:
        return False
    for i in range(2,int(p ** .5) + 1):
        if p % i == 0:
            return False
    return True

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

g = fractions.gcd(A, B)

div = make_divisors(g)
ans = 1
for i in div:
    if is_prime(i):
        ans += 1
print(ans)
import sys
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x,y= (int(_) for _ in input().split()) 
if (x+y)%3!=0:
    print(0)
    sys.exit()
else:
    n=(x+y)/3
    n=int(n)
    if x<n or y<n:
         print(0)
         sys.exit()
    else:
        x=x-n
        y=y-n
        ans=int(combinations_count(x+y, min[x,y])
        print(ans%1000000007)

### FIXED CODE ###

import sys
import math
from operator import mul
from functools import reduce
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

mod = 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 )

x,y= (int(_) for _ in input().split()) 
if (x+y)%3!=0:
    print(0)
    sys.exit()
else:
    n=(x+y)/3
    n=int(n)
    if x<n or y<n:
         print(0)
         sys.exit()
    else:
        x=x-n
        y=y-n
        ans=int(cmb(x+y, x,mod))
        print(ans%1000000007)
x=input()
a=x//500
b=a//5
print(1000*a+5*b)

### FIXED CODE ###

x=int(input())
a=x//500
b=(x%500)//5
print(1000*a+5*b)