#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 find_age(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *);
int main() {
  int d, r, t;
  scanf("%d %d %d", &d, &r, &t);
  int candle_transfers = 0;
  while (1) {
    int r_age = find_age(r--, 6);
    int t_age = find_age(t++, 3);
    if (r_age - t_age == d)
      break;
    candle_transfers++;
  }
  printf("%d\n", candle_transfers);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    %edi,%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    $0x6,%esi
call   1050 <find_age@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x3,%esi
call   1050 <find_age@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11a2 <main+0x72>
jmp    11b0 <main+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <main+0x2e>
mov    -0x14(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xec3(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <scanf@plt>
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
lea    -0x1(%rdi),%eax
mov    %eax,0x10(%rsp)
mov    $0x6,%esi
call   1050 <find_age@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0xc(%rsp)
mov    $0x3,%esi
call   1050 <find_age@plt>
sub    %eax,%ebp
add    $0x1,%ebx
cmp    0x14(%rsp),%ebp
jne    1160 <main+0x30>
lea    0xe6b(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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