##############################################
### http://w...content-available-to-author-only...f.com/problems/COINS ###
##############################################
conv = {0:0}
def exch(num):
if num in conv:
return conv[num]
else:
conv[num] = max(num, exch(num/4)+exch(num/3)+exch(num/2))
return conv[num]
while True:
try:
print exch(int(raw_input()))
except:
break
IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIwojIyMgaHR0cDovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmYuY29tL3Byb2JsZW1zL0NPSU5TICMjIwojIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCmNvbnYgPSB7MDowfQoKZGVmIGV4Y2gobnVtKToKICAgIGlmIG51bSBpbiBjb252OgogICAgICAgIHJldHVybiBjb252W251bV0KICAgIGVsc2U6CiAgICAgICAgY29udltudW1dID0gbWF4KG51bSwgZXhjaChudW0vNCkrZXhjaChudW0vMykrZXhjaChudW0vMikpCiAgICAgICAgcmV0dXJuIGNvbnZbbnVtXQp3aGlsZSBUcnVlOgogICAgdHJ5OgogICAgICAgIHByaW50IGV4Y2goaW50KHJhd19pbnB1dCgpKSkKICAgIGV4Y2VwdDoKICAgICAgICBicmVhaw==