#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, long long *);
int main() {
  long long int n, t, d, i;
  while (scanf("%lld", &n) == 1) {
    int ans = 0;
    t = n;
    while (t > 1) {
      if (t == 2) {
        ans++;
        break;
      }
      d = n % 3;
      t = n / 3;
      ans = t;
      t += d;
    }
    printf("%lld\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11cb <main+0xab>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jle    11b7 <main+0x97>
cmpq   $0x2,-0x18(%rbp)
jne    117b <main+0x5b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <main+0x37>
mov    -0x2c(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11be <main+0x9e>
movabs $0xaaaaaaaaaaaaaaab,%r12
aa aa aa
lea    0xeb4(%rip),%r14
lea    0xea8(%rip),%r15
mov    %rsp,%rbx
jmp    117b <main+0x5b>
nopl   (%rax)
add    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11be <main+0x9e>
mov    (%rsp),%rcx
xor    %esi,%esi
cmp    $0x2,%rcx
jl     1163 <main+0x43>
mov    %rcx,%rax
mul    %r12
xor    %esi,%esi
cmp    $0x2,%rcx
je     1160 <main+0x40>
shr    %rdx
lea    (%rdx,%rdx,2),%rax
sub    %rax,%rcx
mov    %edx,%esi
add    %rdx,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%rcx
jbe    1163 <main+0x43>
cmp    $0x2,%rcx
jne    11b0 <main+0x90>
jmp    1160 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %31, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %34
10: ; preds = %7
store i32 0, i32* %6
%11 = load i64, i64* %2
store i64 %11, i64* %3
br label %12
12: ; preds = %21, %10
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, 1
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %31
21: ; preds = %15
%22 = load i64, i64* %2
%23 = srem i64 %22, 3
store i64 %23, i64* %4
%24 = load i64, i64* %2
%25 = sdiv i64 %24, 3
store i64 %25, i64* %3
%26 = load i64, i64* %3
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
%28 = load i64, i64* %4
%29 = load i64, i64* %3
%30 = add nsw i64 %29, %28
store i64 %30, i64* %3
br label %12
31: ; preds = %18, %12
%32 = load i32, i32* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %7
34: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %27
5: ; preds = %0, %22
%6 = load i64, i64* %1
%7 = icmp sgt i64 %6, 1
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = urem i64 %6, 3
%10 = udiv i64 %6, 3
%11 = trunc i64 %10 to i32
%12 = add nuw nsw i64 %10, %9
%13 = icmp ugt i64 %12, 1
%14 = icmp eq i64 %6, 2
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = icmp eq i64 %12, 2
br label %21
17: ; preds = %21
br i1 %16, label %18, label %21
18: ; preds = %17, %8
%19 = phi i32 [ 0, %8 ], [ %11, %17 ]
%20 = add nsw i32 %19, 1
br label %22
21: ; preds = %15, %17
br i1 %13, label %17, label %22
22: ; preds = %21, %5, %18
%23 = phi i32 [ %20, %18 ], [ 0, %5 ], [ %11, %21 ]
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %5, label %27
27: ; preds = %22, %0
ret i32 0
}