def main():

    n = int(eval(input()))

    print((n//500*1000+(n%500)//5*5))



if __name__ == "__main__":

    main()
x = int(eval(input()))

print((x//500*1000+(x%500//5)*5))

def main():
    n = int(eval(input()))
    print((n // 500 * 1000 + (n % 500) // 5 * 5))


if __name__ == "__main__":
    main()

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

-def main(): -    n = int(eval(input())) -    print((n // 500 * 1000 + (n % 500) // 5 * 5)) - - -if __name__ == "__main__": -    main() +x = int(eval(input())) +print((x // 500 * 1000 + (x % 500 // 5) * 5))