import sys defw_b(a): result = [] defwater_bottle(a,result): if a==2: result.append(1) return if a==1or a==0: return water,bottle = a//3,a%3 result.append(water) water_bottle(water+bottle,result) return result returnsum(water_bottle(a,result)) for line in sys.stdin: a = line.split() a = int(a[0]) if a==0: break else: result = w_b(a) print(result)