#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int t, k, a[500001], i;
  char b[4000000] = {0};
  a[0] = 0;
  b[0] = 1;
  for (i = 1; i <= 500000; i++) {
    int x = a[i - 1] - i;
    if (x < 0 || b[x] == 1)
      a[i] = a[i - 1] + i;
    else
      a[i] = x;
    b[a[i]] = 1;
  }
  while (1) {
    scanf("%d", &k);
    if (k == -1)
      break;
    printf("%d\n", a[k]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5b8db0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x5b8da0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3d0900,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1e8490(%rbp)
movb   $0x1,-0x5b8da0(%rbp)
movl   $0x1,-0x1e8494(%rbp)
cmpl   $0x7a120,-0x1e8494(%rbp)
jg     122d <main+0xfd>
mov    -0x1e8494(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1e8490(%rbp,%rax,4),%eax
sub    -0x1e8494(%rbp),%eax
mov    %eax,-0x5b8da4(%rbp)
cmpl   $0x0,-0x5b8da4(%rbp)
jl     11c3 <main+0x93>
movslq -0x5b8da4(%rbp),%rax
movsbl -0x5b8da0(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jne    11ee <main+0xbe>
mov    -0x1e8494(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1e8490(%rbp,%rax,4),%ecx
add    -0x1e8494(%rbp),%ecx
movslq -0x1e8494(%rbp),%rax
mov    %ecx,-0x1e8490(%rbp,%rax,4)
jmp    1202 <main+0xd2>
mov    -0x5b8da4(%rbp),%ecx
movslq -0x1e8494(%rbp),%rax
mov    %ecx,-0x1e8490(%rbp,%rax,4)
movslq -0x1e8494(%rbp),%rax
movslq -0x1e8490(%rbp,%rax,4),%rax
ff
movb   $0x1,-0x5b8da0(%rbp,%rax,1)
01
mov    -0x1e8494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1e8494(%rbp)
jmp    1170 <main+0x40>
jmp    1232 <main+0x102>
lea    0xdc7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1251 <main+0x121>
jmp    126d <main+0x13d>
movslq -0xc(%rbp),%rax
mov    -0x1e8490(%rbp,%rax,4),%esi
lea    0xda0(%rip),%rdi
call   1030 <printf@plt>
jmp    1232 <main+0x102>
xor    %eax,%eax
add    $0x5b8db0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x5b8da0,%rsp
lea    0x1e84a0(%rsp),%rdi
xor    %ebx,%ebx
mov    $0x3d0900,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,0x10(%rsp)
movb   $0x1,0x1e84a0(%rsp)
01
mov    $0x1,%eax
mov    $0xffffffff,%ecx
jmp    1191 <main+0x61>
xchg   %ax,%ax
add    %eax,%ebx
mov    %ebx,0x10(%rsp,%rax,4)
movslq %ebx,%rdx
movb   $0x1,0x1e84a0(%rsp,%rdx,1)
01
add    $0x1,%rax
add    $0xffffffffffffffff,%rcx
cmp    $0x7a121,%rax
je     11aa <main+0x7a>
mov    %ebx,%edx
add    %rcx,%rdx
test   %edx,%edx
js     1170 <main+0x40>
mov    %edx,%edx
cmpb   $0x1,0x1e84a0(%rsp,%rdx,1)
01
je     1170 <main+0x40>
sub    %eax,%ebx
jmp    1172 <main+0x42>
lea    0xe4f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     1202 <main+0xd2>
lea    0xe38(%rip),%r14
lea    0xe2e(%rip),%r15
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
cltq
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
jne    11e0 <main+0xb0>
xor    %eax,%eax
add    $0x5b8da0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%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 [500001 x i32]
%5 = alloca i32
%6 = alloca [4000000 x i8]
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [4000000 x i8]* %6 to i8*
%9 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 0
store i32 0, i32* %9
%10 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %6, i64 0, i64 0
store i8 1, i8* %10
store i32 1, i32* %5
br label %11
11: ; preds = %54, %0
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 500000
br i1 %13, label %14, label %57
14: ; preds = %11
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %14
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %6, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %42
31: ; preds = %24, %14
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %40
store i32 %38, i32* %41
br label %47
42: ; preds = %24
%43 = load i32, i32* %7
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %45
store i32 %43, i32* %46
br label %47
47: ; preds = %42, %31
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %6, i64 0, i64 %52
store i8 1, i8* %53
br label %54
54: ; preds = %47
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %11
57: ; preds = %11
br label %58
58: ; preds = %57, %63
%59 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %63
62: ; preds = %58
br label %69
63: ; preds = %58
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [500001 x i32], [500001 x i32]* %4, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %67)
br label %58
69: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500001 x i32]
%3 = alloca [4000000 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast [500001 x i32]* %2 to i8*
%6 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [500001 x i32], [500001 x i32]* %2, i64 0, i64 0
store i32 0, i32* %7
store i8 1, i8* %6
br label %12
8: ; preds = %25
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, -1
br i1 %11, label %41, label %32
12: ; preds = %0, %25
%13 = phi i32 [ 0, %0 ], [ %26, %25 ]
%14 = phi i64 [ 1, %0 ], [ %30, %25 ]
%15 = trunc i64 %14 to i32
%16 = sub nsw i32 %13, %15
%17 = icmp slt i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = zext i32 %16 to i64
%20 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %18, %12
%24 = add nsw i32 %13, %15
br label %25
25: ; preds = %18, %23
%26 = phi i32 [ %24, %23 ], [ %16, %18 ]
%27 = getelementptr inbounds [500001 x i32], [500001 x i32]* %2, i64 0, i64 %14
store i32 %26, i32* %27
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds [4000000 x i8], [4000000 x i8]* %3, i64 0, i64 %28
store i8 1, i8* %29
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, 500001
br i1 %31, label %8, label %12
32: ; preds = %8, %32
%33 = phi i32 [ %39, %32 ], [ %10, %8 ]
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [500001 x i32], [500001 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %32
41: ; preds = %32, %8
ret i32 0
}