空瓶子-算法


import sys


def drink_soda(n):
    if n == 0:
        exit(0)

    total_drinks = 0
    empty_bottles = n

    while empty_bottles >= 3:
        drinks = empty_bottles // 3
        total_drinks += drinks
        empty_bottles = empty_bottles % 3 + drinks
    if empty_bottles == 2:
        total_drinks += 1

    return total_drinks

for line in sys.stdin:
    a = line.split()
    # print(a)
    # print(type(a))
    print(drink_soda(int(a[0])))