Harryxun/stf_run huggingface dataset:
N=int(input())
A=list(map(int,input().split()))
I=2*N
D=[[-I]*(N+1)for _ in range(N+1)]
M=0
r=[-I]*(N+1)
def c(i,j,k):
    DP[i][j]=max(k,D[i][j])
    DP[j][i]=max(k,D[j][i])
    r[i]=max(r[i],D[i][j])
    r[j]=max(r[j],D[i][j])
    global M
    M=max(M,k)
a=0
D[A[0]][A[1]]=0
D[A[1]][A[0]]=0
r[A[0]]=0
r[A[1]]=0
for i in range(N-1):
    n=A[3*i+2:3*i+5]
    C=[]
    if len(set(n))==1:
        a+=1
        continue
    if len(set(n))==2:
        for j in range(3):
            if n.count(n[j])==2:
                X=n[j]
            else:
                Y=n[j]
        for j in range(1,N+1):
            C.append((j,Y,D[X][j]+1))
    X,Y,Z =n
    C.append((X,Y,D[Z][Z]+1))
    C.append((Y,Z,D[X][X]+1))
    C.append((X,Z,D[Y][Y]+1))
    C.append((X,Y,M))
    C.append((X,Z,M))
    C.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            C.append((j,n[k],r[j]))
    for j,k,l in change:
        c(j,k,l)
M=max(M,D[A[-1]][A[-1]]+1)
print(a+M)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
INF = 2*N
DP = [[-INF]*(N+1) for _ in range(N+1)]
M = 0
rowM = [-INF]*(N+1)

def chmax(i,j,k):
    DP[i][j] = max(k,DP[i][j])
    DP[j][i] = max(k,DP[j][i])
    rowM[i] = max(rowM[i],DP[i][j])
    rowM[j] = max(rowM[j],DP[i][j])
    global M
    M = max(M,k)

ans = 0
DP[A[0]][A[1]] = 0
DP[A[1]][A[0]] = 0
rowM[A[0]] = 0
rowM[A[1]] = 0
for i in range(N-1):
    new = A[3*i+2:3*i+5]
    change = []
    if len(set(new)) == 1:
        ans += 1
        continue
    if len(set(new)) == 2:
        for j in range(3):
            if new.count(new[j]) == 2:
                X = new[j]
            else:
                Y = new[j]
        for j in range(1,N+1):
            change.append((j,Y,DP[X][j]+1))
    X,Y,Z = new
    change.append((X,Y,DP[Z][Z]+1))
    change.append((Y,Z,DP[X][X]+1))
    change.append((X,Z,DP[Y][Y]+1))
    change.append((X,Y,M))
    change.append((X,Z,M))
    change.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            change.append((j,new[k],rowM[j]))
    for j,k,l in change:
        chmax(j,k,l)
M = max(M,DP[A[-1]][A[-1]]+1)
print(ans+M)
#n = int(input())
n, m = map(int, input().split())
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

fgroup = {i: 0 for i in range(1, n+1)}
g_id = 0
for i in range(m):
    a, b = map(int, input().split())
    if fgroup[a] != 0:
        fgroup[b] = fgroup[a]
    elif fgroup[b] != 0:
        fgroup[a] = fgroup[b]
    else:
        g_id += 1
        fgroup[a] = g_id
        fgroup[b] = g_id

gid_num = {}
for person, gid in fgroup.items():
    gid_num[gid] = gid_num.get(gid, 0)+1
mx = 1
for i in range(1, g_id+1):
    mx = max(mx, gid_num[i])
print(mx)


### FIXED CODE ###

#n = int(input())
import random
import sys
sys.setrecursionlimit(10 ** 7)
n, m = map(int, input().split())
#n=200000
#m=200000
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
adjl = [[] for _ in range(n+1)]
NIL = -1
appear = {}
isalone = {}
for i in range(m):
    a, b = map(int, input().split())
    #a=random.randrange(1,n+1)
    #b=random.randrange(1,n+1)
    #while a==b:
    #    b=random.randrange(1,n+1)
    #print(a,b)
    if appear.get((a, b), False) or appear.get((a, b), False):
        continue
    appear[(a, b)] = True
    appear[(b, a)] = True
    isalone[a] = False
    isalone[b] = False
    adjl[a].append(b)
    adjl[b].append(a)

color = [NIL for i in range(n+1)]
color_id = 0


def dfs(u, color_id):
    global color
    color[u] = color_id
    for v in adjl[u]:
        if color[v] == NIL:  # 未到達なら再起呼び出し
            color[v] = color_id
            dfs(v, color_id)


for u in range(1, n+1):
    if color[u] == NIL:
        color_id += 1
        dfs(u, color_id)

group = {}
for i in range(1, n+1):
    if isalone.get(i, True):
        continue
    group[color[i]] = group.get(color[i], 0)+1

mx = 1
for k, v in group.items():
    mx = max(mx, v)

print(mx)
__MATCH = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6, ]


def __select_use_num(N: int, A: list) -> list:
    if N == 0:
        return []

    for a in A:
        if N < __MATCH[a]:
            continue

        l = __select_use_num(N-__MATCH[a], A)
        if l is None:
            continue

        return [a] + l

    return None


def match_matching(N: int, M: int, A: list) -> int:
    _A = sorted(A, key=lambda x: __MATCH[x])
    nums = sorted(__select_use_num(N, _A), reverse=True)
    ans = ''.join(map(str, nums))
    return int(ans)


if __name__ == "__main__":
    N, M = [int(s) for s in input().split()]
    A = [int(s) for s in input().split()]

    ans = match_matching(N, M, A)

    print(ans)


### FIXED CODE ###

__MATCH = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6, ]
__INF = float('inf')


def match_matching(N: int, M: int, A: list) -> int:
    # dp で最大桁数を求める
    dp = [-__INF] * (N+1)
    dp[0] = 0
    for i in range(1, N+1):
        dp[i] = max([-__INF] +
                    [dp[i - __MATCH[a]] for a in A if i >= __MATCH[a]]) + 1

    # 各桁の数字を決める
    _A = sorted(A, reverse=True)
    used_matches = 0
    ans = 0
    for n in range(dp[N], 0, -1):
        for a in _A:
            used_matches += __MATCH[a]
            if used_matches <= N and dp[N-used_matches] == n - 1:
                ans = ans * 10 + a
                break
            used_matches -= __MATCH[a]

    return ans


if __name__ == "__main__":
    N, M = [int(s) for s in input().split()]
    A = [int(s) for s in input().split()]

    ans = match_matching(N, M, A)

    print(ans)
N = input()
T, A = map(int, input.split())
H = list(map(int, input.split()))

num = 0
for i in range(0, N):
  deff = abs(T-H[i]*0.006-A)
  if deff < abs(T-H[num]*0.006-A):
    num = i

print(num)

### FIXED CODE ###

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

num = 0
for i in range(N):
  deff = abs(T-H[i]*0.006-A)
  if deff < abs(T-H[num]*0.006-A):
    num = i

print(num+1)
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
%        i = (i+1)%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
"""

def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
    
def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data

fifo_size = 100000
fifo = [0 for _ in range(fifo_size)]
head = 0
tail = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    data = [s[0], int(s[1])]
    fifo_enque(data)
    
current_time = 0
finished = []
fin_time = []

while True:
    data = fifo_deque()
    if data[1] > q:
        current_time += q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
N,M=map(int,input().split())
A=[-1]*N
k=0
for i in range(M):
  L=list(map(int,input().split()))
  if A[L[0]-1]==-1:
    A[L[0]-1]=L[1]
  else:
    if A[L[0]-1]!=L[1]:
      k=1
      break
    else:
      continue
if (k==1) or (N!=1 and A[0]==0):
  print(-1)
else:
  S=""
  if A[0]==-1:
    A[0]=1
  if N!=1:
    for i in range(N):
      if A[i]==-1:
        A[i]=0
      S+=str(A[i])
  print(int(S))

### FIXED CODE ###

n,m = map(int,input().split())
s = list(list(map(int,input().split())) for i in range(m))
x = [-1]*n
b = True
for i in range(m):
    if x[s[i][0]-1] == -1 or x[s[i][0]-1] == s[i][1]:
        x[s[i][0]-1] = s[i][1]
    else:
        b = False
for j in range(n):
    if x[j] == -1:
        if len(x) != 1 and j == 0:
            x[j] = 1
        else:
            x[j] = 0
if len(x) != 1 and x[0] == 0:
    b = False

if b:
  S=""
  for o in range(n):
    S+=str(x[o])
  print(int(S))
else:
  print(-1)
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

def func(arr, b):
	return([i-b for i in arr])

def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	for i in range(1, a): a_[i] += a_[i-1]
	for i in range(1, b): b_[i] += b_[i-1]
	ans = 0
	while k > 0:
		inda = bisect(a_, k); indb = bisect(b_, k)
		# print(k, inda, indb, a_[inda-1], b_[indb-1])
		if inda > indb:
			k -= a_[inda-1];
			ans += inda
			a_ = func(a_[inda:], a_[inda-1])
		elif inda == indb:
			if a_[inda-1] < b_[indb-1]:
				k -= a_[inda-1];
				ans += inda
				a_ = func(a_[inda:], a_[inda-1])
			else:
				k -= b_[indb-1];
				ans += indb
				b_ = func(b_[indb:], b_[indb-1])
		else:
			k -= b_[indb-1];
			ans += indb
			b_ = func(b_[indb:], b_[indb-1])


	print(ans)





		

if __name__ == "__main__":
	solve()

### FIXED CODE ###

import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = [0]+read(); arr2 = [0]+read()
	for i in range(1, n+1):arr1[i] += arr1[i-1]
	for i in range(1, m+1):arr2[i] += arr2[i-1]

	i = 0; ans = 0
	while i < n+1 and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])-1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()
n=input()
l=[1,9]
for i in n:
    print(l[l.index(i)-1],end='')
print()
    

### FIXED CODE ###

#!/usr/bin/env python3
n=input()
l=['1','9']
for i in n:
    print(l[l.index(i)-1], end = '')
print()
n, m = map(int, input().split())
temp = [0] * (n + 1)
temp[0] = 0
temp[1] = 1
temp[2] = 2
for i in range(3, n + 1):
  temp[i] = temp[i-1] + temp[i-2]

mod = 10 ** 9 + 7
start = 0
cnt = 1
for i in range(m):
  ko = int(input())
  if ko == 1:
    start = ko + 1
    continue
  end = ko - 1
  diff = end - start
  if diff < 0:
    diff = 0
  if diff == 0:
    start = ko + 1
    continue
  cnt = cnt * temp[diff]
  start = ko + 1

if n - start != 0:
  cnt = cnt * temp[n - start]
print(cnt % mod)

### FIXED CODE ###

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

fact=[0,1]
fact_inv=[0]*(n+1)
for i in range(2,n+1):
  fact.append(fact[-1]*i % MOD)

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

def comb(n,r):
  return fact[n]*fact_inv[r]*fact_inv[n-r]%MOD

def sigmaComb(dis):
  ans=0
  if dis == 1 or dis == 0:
    return 1
  end=dis//2+1
  for i in range(end):
    t=comb(dis-i,i)
    #print(dis-i,i,t)
    ans+=t
  return ans

hole=[0]
ans=1
for i in range(m):
  t = int(input())
  availLeft=hole[-1]
  availRight=t-1
  dis=availRight-availLeft
  if dis <0:
    ans=0
    break

  ans=ans*sigmaComb(dis)%MOD
  #print("dis=",dis,t,ans)
  hole.append(t+1)
else:
  availLeft=hole[-1]
  availRight=n
  dis=availRight-availLeft
  #print("dis=",dis,hole[-1],ans)
  ans=ans*sigmaComb(dis)%MOD

print(ans%MOD)
I = [int(input()) for _ in range(6)]

I[0] = a
I[4] = e
I[5] = k

if e-a <= k:
	print(":(")
else :
	print("Yay!")

### FIXED CODE ###

I =[int(input())for i in range(6)]

if I[4] - I[0] > I[5] :
	print(":(")
else :
	print("Yay!")
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K+1-l):
            if l + r > K:
                continue
            D = K - l - r
            S = []
            now = 0
            for i in range(l):
                now += V[i]
                S.append(V[i])
            for j in range(N-1, N-1-r, -1):
                now += V[j]
                S.append(V[j])

            sort_S = sorted(S)
            for d in range(min(D,len(S))):
                if sort_S[d] < 0:
                    now += abs(sort_S[d])

            ans = max(ans, now)

    print(ans)
            

main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K+1-l):
            if l + r > N:
                continue
            D = K - l - r
            S = []
            now = 0
            for i in range(l):
                now += V[i]
                S.append(V[i])
            for j in range(N-r,N):
                now += V[j]
                S.append(V[j])

            sort_S = sorted(S)
            for d in range(min(D,len(S))):
                if sort_S[d] < 0:
                    now += abs(sort_S[d])

            ans = max(ans, now)

    print(ans)
            

main()
S_list = list(map(int,input("入力：").split()))

if  (S_list[1] - S_list[0] ) / (S_list[2] - S_list[1]) == 1:
    result = "YES"
else:
    result = "No"
print(result)


### FIXED CODE ###

S_list = list(map(int,input().split()))
 
if  S_list[1] - S_list[0] == S_list[2] - S_list[1]:
    result = "YES"
else:
    result = "NO"
print(result)
n, q = map(int, input().split())

tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp.clear()
    for bbb in tmp2:
        tree[bbb].remove(bbb)
        tmp.extend(tree[bbb])


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

ans = [0]*n
for p, x in cnt:
    tmp = [p]
    while len(tmp) != 0:
        for i in tmp:
            ans[i-1] += x
        tmp2 = tmp
        tmp.clear()
        for aaa in tmp2:
            tmp.extend(tree[aaa])
    print(ans)

print(" ".join(map(str, ans)))

### FIXED CODE ###

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

tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

check = [0]*n

tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)


print(" ".join(map(str, cnt)))
from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def successors(x, y):
    locations = []
    # 下に行けるかの判定
    if (x + 1 < H) and (maze[x + 1][y] != '#'):
        locations.append((x + 1, y))
    # 上に行けるかの判定
    if (x - 1 >= 0) and (maze[x - 1][y] != '#'):
        locations.append((x - 1, y))
    # 右に行けるかの判定
    if (y + 1 < W) and (maze[x][y + 1] != '#'):
        locations.append((x, y + 1))
    # 左に行けるかの判定
    if (y - 1 >= 0) and (maze[x][y - 1] != '#'):
        locations.append((x, y - 1))
    return locations


def bfs(initial, goal, successors):
    frontier = deque()
    frontier.append((initial, None))
    # tuple
    explored = {initial}

    while len(frontier):
        current_node = frontier.popleft()
        current_state = current_node[0]
        if current_state == goal:
            return current_node
        for child in successors(*current_state):
            if str(child) in [str(i) for i in explored]:
                continue
            explored.add(child)
            frontier.append((child, current_node))
    return None


def node_to_path_count(node):
    path = [node[0]]
    counter: int = 0
    while node[1] is not None:
        counter += 1
        node = node[1]
        path.append(node[0])
    path.reverse()
    #return path, counter
    return counter


ans = 0
for x in range(H):
    for y in range(W):
        for gx in range(H):
            for gy in range(W):
                if (x != gx and y != gy) and maze[x][y] == '.' and maze[gx][gy] == '.':
                    solution = bfs((x, y), (gx, gy), successors)
                    counter = node_to_path_count(solution)
                    if ans < counter:
                        ans = counter

print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def bfs(initial):
    # goal判定はなく、一番遠いところで返す
    distance = [[-1] * W for _ in range(H)]
    frontier = deque()
    frontier.append(initial)
    distance[initial[0]][initial[1]] = 0
    while len(frontier):
        current_node = frontier.popleft()
        x, y = current_node
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_x, new_y = x + i, y + j
            if 0 <= new_x < H and 0 <= new_y < W:
                if maze[new_x][new_y] == '.' and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    frontier.append((new_x, new_y))
    return distance[x][y]


ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        solution = bfs((i, j))
        if ans < solution:
            ans = solution

print(ans)
N = int(input(""))
A = list(map(int, input("").split()))

limit = 1000000000000000000

result = 1
for i in A:
  if result >= limit:
    result = -1
  	break
  result = result * i

print(result)

### FIXED CODE ###

N = int(input(""))
A = list(map(int, input("").split()))

limit = 1000000000000000000

result = 1
if 0 not in A:
  for i in A:
    result = result * i
    if result > limit:
      result = -1
      break
else:
  result = 0

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

sum_reverse = 0
for i in range(1,n):
	sum_reverse += 1/float(a[i])

print(1/sum_reverse)

### FIXED CODE ###

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

sum_reverse = 0
for i in range(n):
	sum_reverse += 1/float(a[i])

print(1/sum_reverse)
import sys
input = sys.stdin.readline
A, B, K = [int(x) for x in input().rstrip().split()]
import numpy as np
x = np.arange(A, B + 1, np.int64)
left = x[:K]
right = x[::-1][:K]
ans = []
for i in left:
    if i not in ans:
        ans.append(i)
for j in right:
    if j not in ans:
        ans.append(j)
ans.sort()
for k in ans:
    print(k)

### FIXED CODE ###

import sys
input = sys.stdin.readline
A, B, K = [int(x) for x in input().rstrip().split()]
left = [int(x) for x in range(A, A+K)]
right = [int(x) for x in range(B, B-K, -1)]
ans = []
for i in left:
    if i not in ans and i <= B:
        ans.append(i)
for j in right:
    if j not in ans and j >= A:
        ans.append(j)
ans.sort()
for k in ans:
    print(k)
S = input()
if S[-1:] = s:
  print(S+"es")
else:print(S+"s")

### FIXED CODE ###

S = input()
if S[-1:] == "s":
  print(S+"es")
else:print(S+"s")
H,W,M = list(map(int, input().split()))

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add([h_i-1, w_j-1])
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not([i,j] in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)

### FIXED CODE ###

H,W,M = list(map(int, input().split()))

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

left = 1
right = W
up = 1
down = H

for i in reversed(range(N)):
    if i != N - 1:
        if T[i] == "U":
            if down != H:
                down -= 1
        elif T[i] == "D":
            if up != 1:
                up += 1
        elif T[i] == "L":
            if right != W:
                right += 1
        else:
            if left != 1:
                left -= 1
    if S[i] == "U":
        up -= 1
    elif S[i] == "D":
        down += 1
    elif S[i] == "L":
        left += 1
    else:
        right -= 1
    if left == right or up == down:
        print("NO")
        exit()
if left <= sr <= right and up <= sc <= down:
    print("YES")
else:
    print("NO")


### FIXED CODE ###

def main():
    from collections import deque
    H, W = map(int, input().split())
    grid = [["#"] * (W + 2)] + [list("#" + input() + "#")
                                for i in range(H)] + [["#"]*(W+2)]
    # print(grid)
    stack = deque()
    for h in range(1, H+1):
        for w in range(1, W+1):
            # 黒ならスタックにpush
            if grid[h][w] == "#":
                stack.append([h, w])

    for i in range(h + w + 3):
        tmp = deque()
        while stack:
            h, w = stack.pop()
            for dh, dw in ([0, 1], [0, -1], [1, 0], [-1, 0]):
                if grid[h + dh][w + dw] == ".":
                    grid[h + dh][w + dw] = "#"
                    tmp.append([h + dh, w + dw])
        stack = tmp
        if not stack:
            print(i)
            break


if __name__ == '__main__':
    main()
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b[(n/2)-1]=b[(n/2)+1]:
  print(0)
else:
  c=b[(n/2)-1]
  d=b[(n/2)+1]
  e=count(range(c,d))
  print(e+1)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b[(int(n/2)-1)]==b[int((n/2))]:
  print(0)
else:
  c=b[int((n/2)-1)]
  d=b[int((n/2))]
  e=len(list(range(c,d)))
  print(e)
R =  float(input())
C = 3.14159*2*R
print(c)


### FIXED CODE ###

R =  float(input())
print(3.14159*2*R)
from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        if p[tmp] == 1:
            continue
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()
X = int(input())import math
X = int(input())
A = X/500
A=math.floor(A)
Q=1000*A
D=A*500
Y=X-D
B = Y/5
B = math.floor(B)
B= 5*B
print(Q+B)

### FIXED CODE ###

import math
X = int(input())
A = X/500
A=math.floor(A)
Q=1000*A
D=A*500
Y=X-D
B = Y/5
B = math.floor(B)
B= 5*B
print(int(Q+B))