// File: /workspace/github_cpp_makefile_star2_O1/aydarbiktimirov[P]data-structures/src/main.cpp
// Function: main
int main()
{
	std::cout << "array size: ";
	size_t n;
	std::cin >> n;
	std::vector<int> a(n);
	std::cout << "array: ";
	for (size_t i = 0; i < a.size(); ++i)
	{
		std::cin >> a[i];
	}

	CPersistentSegmentTree<int, std::plus<int> > tree(a.begin(), a.end(), 0);
	for (std::string cmd; !std::cin.eof(); )
	{
		std::cout << "> ";
		std::cin >> cmd;
		if (cmd == "help")
		{
			std::cout << "\tprint\t\tprint current version of a" << std::endl;
			std::cout << "\tversion count\tprint number of versions" << std::endl;
			std::cout << "\tversion show\tprint current version" << std::endl;
			std::cout << "\tversion set i\tselect i'th version of segment tree" << std::endl;
			std::cout << "\tchange i x\tchange i'th element to x" << std::endl;
			std::cout << "\tsum i j\t\tprint sum from i'th element to j'th" << std::endl;
			std::cout << "\texit\t\texit" << std::endl;
		} else if (cmd == "print") {
			std::cout << "\t";
			for (size_t i = 0; i < a.size(); ++i)
			{
				std::cout << tree(i, i) << " ";
			}
			std::cout << std::endl;
		} else if (cmd == "version") {
			std::cin >> cmd;
			if (cmd == "count")
			{
				std::cout << "\t" << tree.GetVersionCount() << std::endl;
			} else if (cmd == "set") {
				size_t v;
				std::cin >> v;
				tree.SetVersion(v);
			} else if (cmd == "show") {
				std::cout << tree.GetCurrentVersion() << std::endl;
			} else {
				std::cout << "\tincorrect command" << std::endl;
			}
		} else if (cmd == "change") {
			size_t i;
			int v;
			std::cin >> i >> v;
			tree.Change(i, v);
		} else if (cmd == "sum") {
			size_t i, j;
			std::cin >> i >> j;
			std::cout << "\t" << tree(i, j) << std::endl;
		} else if (cmd == "exit") {
			break;
		} else {
			std::cout << "\tincorrect command" << std::endl;
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq 0x3bec(%rip), %rbx      # 0x5fc0
leaq 0x1c7d(%rip), %rsi      # 0x4058
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2140
movq 0x3bf1(%rip), %rdi      # 0x5fe0
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x2090
movq (%r14), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x2a54
leaq 0x1c50(%rip), %rsi      # 0x4065
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2140
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
cmpq %rsi, %rdx
je 0x2469
xorl %r14d, %r14d
movq 0x3ba5(%rip), %r15      # 0x5fe0
xorl %r12d, %r12d
addq %r14, %rsi
movq %r15, %rdi
callq 0x20b0
incq %r12
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rdx, %rax
subq %rsi, %rax
sarq $0x2, %rax
addq $0x4, %r14
cmpq %rax, %r12
jb 0x243e
leaq 0x28(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0x50(%rsp), %rdi
callq 0x2ade
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x3b47(%rip), %rcx      # 0x5fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
jne 0x2961
leaq 0x28(%rsp), %r12
leaq 0x50(%rsp), %rbp
leaq 0x1ba7(%rip), %r15      # 0x4063
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x1ba2(%rip), %rsi      # 0x406d
callq 0x2140
movq 0x3b09(%rip), %rdi      # 0x5fe0
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
leaq 0x1b87(%rip), %rsi      # 0x4070
callq 0x2050
testl %eax, %eax
je 0x257b
movq %r12, %rdi
leaq 0x1c76(%rip), %rsi      # 0x4176
callq 0x2050
testl %eax, %eax
je 0x26f7
movq %r12, %rdi
leaq 0x1bc5(%rip), %rsi      # 0x40dc
callq 0x2050
testl %eax, %eax
je 0x27ae
movq %r12, %rdi
leaq 0x1c72(%rip), %rsi      # 0x41a0
callq 0x2050
testl %eax, %eax
je 0x283e
movq %r12, %rdi
leaq 0x1c62(%rip), %rsi      # 0x41a7
callq 0x2050
testl %eax, %eax
je 0x2870
movq %r12, %rdi
leaq 0x1c15(%rip), %rsi      # 0x4171
callq 0x2050
movl $0x12, %r13d
leaq 0x1c1f(%rip), %rsi      # 0x418d
testl %eax, %eax
jne 0x26ea
jmp 0x2961
movl $0x22, %edx
movq %rbx, %rdi
leaq 0x1aeb(%rip), %rsi      # 0x4075
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl $0x27, %edx
movq %rbx, %rdi
leaq 0x1ad3(%rip), %rsi      # 0x4098
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl $0x23, %edx
movq %rbx, %rdi
leaq 0x1ac0(%rip), %rsi      # 0x40c0
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl $0x32, %edx
movq %rbx, %rdi
leaq 0x1aa9(%rip), %rsi      # 0x40e4
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl $0x24, %edx
movq %rbx, %rdi
leaq 0x1aa1(%rip), %rsi      # 0x4117
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl $0x2d, %edx
movq %rbx, %rdi
leaq 0x1a8b(%rip), %rsi      # 0x413c
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movl $0xb, %r13d
movq %rax, %rdi
callq 0x20d0
leaq 0x1a80(%rip), %rsi      # 0x416a
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2140
jmp 0x2766
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x1a76(%rip), %rsi      # 0x417c
callq 0x2140
movq 0x10(%rsp), %rax
cmpq 0x8(%rsp), %rax
je 0x2766
xorl %r13d, %r13d
movq 0x50(%rsp), %rax
movq %rbp, %rdi
callq *0x20(%rax)
movq %rbp, %rdi
movq %r13, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x3140
movq %rbx, %rdi
movl %eax, %esi
callq 0x2190
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2140
incq %r13
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
sarq $0x2, %rax
cmpq %rax, %r13
jb 0x271a
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movq %rbx, %r13
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x3849(%rip), %rcx      # 0x5fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
je 0x24bc
jmp 0x2961
movq 0x382b(%rip), %rdi      # 0x5fe0
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
leaq 0x19b7(%rip), %rsi      # 0x417e
callq 0x2050
testl %eax, %eax
je 0x28fe
movq %r12, %rdi
leaq 0x19a6(%rip), %rsi      # 0x4184
callq 0x2050
testl %eax, %eax
je 0x2941
movq %r12, %rdi
leaq 0x1993(%rip), %rsi      # 0x4188
callq 0x2050
movl $0x12, %r13d
leaq 0x1986(%rip), %rsi      # 0x418d
testl %eax, %eax
jne 0x26ea
movq %rbp, %rdi
callq 0x239c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x20c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x277d
movq 0x379b(%rip), %rdi      # 0x5fe0
movq %rsp, %rsi
callq 0x2090
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x20b0
movq (%rsp), %rsi
movq %rbp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x2bec
jmp 0x2790
movq 0x3769(%rip), %rdi      # 0x5fe0
movq %rsp, %rsi
callq 0x2090
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2090
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x18e1(%rip), %rsi      # 0x417c
callq 0x2140
movq (%rsp), %r13
movq 0x20(%rsp), %r14
movq 0x50(%rsp), %rax
movq %rbp, %rdi
callq *0x20(%rax)
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x3140
movq %rbx, %rdi
movl %eax, %esi
callq 0x2190
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
jmp 0x2790
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x186f(%rip), %rsi      # 0x417c
callq 0x2140
movq %rbp, %rdi
callq 0x2396
movq %rbx, %rdi
movq %rax, %rsi
callq 0x20c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x277d
movq 0x3698(%rip), %rdi      # 0x5fe0
movq %rsp, %rsi
callq 0x2090
movq (%rsp), %rsi
movq %rbp, %rdi
callq 0x2338
jmp 0x2790
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x297d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2130
leaq 0x333c(%rip), %rax      # 0x5cc0
movq %rax, 0x50(%rsp)
leaq 0x3378(%rip), %rax      # 0x5d08
movq %rax, 0x68(%rsp)
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x29b2
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x29cf
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x29e6
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a04
jmp 0x2a04
jmp 0x2a0b
jmp 0x2a0b
jmp 0x2a0b
movq %rax, %rbx
jmp 0x2a34
jmp 0x2a0b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2a2a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2130
leaq 0x50(%rsp), %rdi
callq 0x2c92
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2a4b
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq %rbx, %rdi
callq 0x21a0
nop