// File: sharmaeklavya2[P]ddos-on-anycast/src/segtree.cpp
// Function: main
int main(int argc, char* argv[]) {
    if(argc == 1) {
        fprintf(stderr, "usage: %s space_separated_list_of_numbers\n", argv[0]);
        return 2;
    }

    int n = argc - 1;
    vector<double> v(n);
    for(int i=1; i<argc; ++i) {
        v[i-1] = std::atof(argv[i]);
    }

    SegTree segtree(v);

    printf("commands: print, query i, update i x, cumsum_search x;  Ctrl+D to quit\n");

    char command[10];
    while(true) {
        printf(">> ");
        if(scanf("%s", command) == EOF) {
            printf("\r");
            break;
        }
        if(command[0] == 'p') {
            segtree.print(stdout);
        }
        else if(command[0] == 'u') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%d%lf", &i, &x);
#pragma GCC diagnostic pop
            segtree.update(i, x);
        }
        else if(command[0] == 'q') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%d", &i);
#pragma GCC diagnostic pop
            x = segtree.query(i);
            printf("%lf\n", x);
        }
        else if(command[0] == 'c') {
            int i; double x;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
            scanf("%lf", &x);
#pragma GCC diagnostic pop
            i = segtree.cumsum_search(x);
            printf("%d\n", i);
        }
        else {
            printf("Invalid command\n");
        }
    };
    return 0;
}

// Assembly:
subq $0xd8, %rsp
movl $0x0, 0xd4(%rsp)
movl %edi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
cmpl $0x1, 0xd0(%rsp)
jne 0x195e
movq 0x36a6(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq 0xc8(%rsp), %rax
movq (%rax), %rdx
leaq 0x16d0(%rip), %rsi      # 0x3017
movb $0x0, %al
callq 0x10e0
movl $0x2, 0xd4(%rsp)
jmp 0x1c55
movl 0xd0(%rsp), %eax
decl %eax
movl %eax, 0xc4(%rsp)
movslq 0xc4(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x1c80
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x1c90
jmp 0x19a6
leaq 0xa7(%rsp), %rdi
callq 0x1d10
movl $0x1, 0x90(%rsp)
movl 0x90(%rsp), %eax
cmpl 0xd0(%rsp), %eax
jge 0x1a4a
movq 0xc8(%rsp), %rax
movslq 0x90(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10d0
movsd %xmm0, 0x20(%rsp)
movl 0x90(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq 0xa8(%rsp), %rdi
callq 0x18c0
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x19be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xa7(%rsp), %rdi
callq 0x1d10
jmp 0x1c64
leaq 0x70(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x1d20
jmp 0x1a5e
leaq 0x15dd(%rip), %rdi      # 0x3042
xorl %eax, %eax
callq 0x1030
jmp 0x1a6e
jmp 0x1a70
jmp 0x1a72
leaq 0x1611(%rip), %rdi      # 0x308a
xorl %eax, %eax
callq 0x1030
jmp 0x1a82
leaq 0x1605(%rip), %rdi      # 0x308e
xorl %eax, %eax
leaq 0x66(%rsp), %rsi
callq 0x10c0
movl %eax, 0x1c(%rsp)
jmp 0x1a9b
movl 0x1c(%rsp), %eax
cmpl $-0x1, %eax
jne 0x1af5
leaq 0x15e6(%rip), %rdi      # 0x3091
xorl %eax, %eax
callq 0x1030
jmp 0x1ab4
jmp 0x1c22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x1c46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x1ed0
jmp 0x1c46
movsbl 0x66(%rsp), %eax
cmpl $0x70, %eax
jne 0x1b1a
movq 0x34ba(%rip), %rax      # 0x4fc0
movq (%rax), %rsi
leaq 0x70(%rsp), %rdi
callq 0x1df0
jmp 0x1b15
jmp 0x1c1d
movsbl 0x66(%rsp), %eax
cmpl $0x75, %eax
jne 0x1b59
leaq 0x1568(%rip), %rdi      # 0x3093
xorl %eax, %eax
leaq 0x60(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x10c0
jmp 0x1b3e
movl 0x60(%rsp), %esi
movsd 0x58(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x1e30
jmp 0x1b54
jmp 0x1c1b
movsbl 0x66(%rsp), %eax
cmpl $0x71, %eax
jne 0x1bb2
leaq 0x152f(%rip), %rdi      # 0x3099
xorl %eax, %eax
leaq 0x54(%rsp), %rsi
callq 0x10c0
jmp 0x1b78
movl 0x54(%rsp), %esi
leaq 0x70(%rsp), %rdi
callq 0x1e70
movsd %xmm0, 0x10(%rsp)
jmp 0x1b8e
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
leaq 0x146b(%rip), %rdi      # 0x3012
movb $0x1, %al
callq 0x1030
jmp 0x1bb0
jmp 0x1c19
movsbl 0x66(%rsp), %eax
cmpl $0x63, %eax
jne 0x1c05
leaq 0x14d2(%rip), %rdi      # 0x3095
xorl %eax, %eax
leaq 0x38(%rsp), %rsi
callq 0x10c0
jmp 0x1bd1
movsd 0x38(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x1ea0
movl %eax, 0xc(%rsp)
jmp 0x1be7
movl 0xc(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %esi
leaq 0x14a2(%rip), %rdi      # 0x309c
xorl %eax, %eax
callq 0x1030
jmp 0x1c03
jmp 0x1c17
leaq 0x1494(%rip), %rdi      # 0x30a0
xorl %eax, %eax
callq 0x1030
jmp 0x1c15
jmp 0x1c17
jmp 0x1c19
jmp 0x1c1b
jmp 0x1c1d
jmp 0x1a70
movl $0x0, 0xd4(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x1ed0
leaq 0xa8(%rsp), %rdi
callq 0x1ef0
jmp 0x1c55
leaq 0xa8(%rsp), %rdi
callq 0x1ef0
jmp 0x1c64
movl 0xd4(%rsp), %eax
addq $0xd8, %rsp
retq
movq 0x98(%rsp), %rdi
callq 0x1100
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)