Module Main
    Sub Main(args As String())
        Dim S As Integer = Integer.Parse(Console.ReadLine)
        Dim X As Integer = 0
        Dim A As Integer = S \ 500
        Dim B As Integer = S Mod 500
        Dim C As Integer = B \ 5
        Dim D As Integer = C * 5
        Dim E As Integer = A * 1000
        X = D + E
        Console.WriteLine(X.ToString)
    End Sub
End Module
