// File: /workspace/github_cpp_makefile_star2_O2/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 0x4c14(%rip), %rbx      # 0x6fc0
leaq 0x1cbd(%rip), %rsi      # 0x4070
movq %rbx, %rdi
callq 0x2120
movq 0x4c1e(%rip), %rdi      # 0x6fe0
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x20c0
movq (%r14), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x27a2
leaq 0x1c95(%rip), %rsi      # 0x407d
movq %rbx, %rdi
callq 0x2120
xorl %r15d, %r15d
movq 0x4be6(%rip), %r14      # 0x6fe0
xorl %r12d, %r12d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rdx, %rax
subq %rsi, %rax
sarq $0x2, %rax
cmpq %rax, %r12
jae 0x242a
addq %r15, %rsi
movq %r14, %rdi
callq 0x20d0
incq %r12
addq $0x4, %r15
jmp 0x23fd
leaq 0x28(%rsp), %rcx
andl $0x0, (%rcx)
leaq 0x50(%rsp), %rdi
callq 0x27f4
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x28(%rsp), %r12
leaq 0x50(%rsp), %rbp
leaq 0x1c1d(%rip), %r15      # 0x407b
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%r14,%rax)
jne 0x2736
movq %rbx, %rdi
leaq 0x1c0a(%rip), %rsi      # 0x4085
callq 0x2120
movq %r14, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
leaq 0x1bf3(%rip), %rsi      # 0x4088
callq 0x28b2
testb %al, %al
je 0x2540
movq %rbx, %rdi
leaq 0x1be1(%rip), %rsi      # 0x408d
callq 0x2120
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x1bed(%rip), %rsi      # 0x40b0
callq 0x2120
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x1bfe(%rip), %rsi      # 0x40d8
callq 0x2120
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x1c0b(%rip), %rsi      # 0x40fc
callq 0x2120
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x1c27(%rip), %rsi      # 0x412f
callq 0x2120
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x1c35(%rip), %rsi      # 0x4154
callq 0x2120
movq %rax, %rdi
callq 0x2090
leaq 0x1c4f(%rip), %rsi      # 0x4182
movq %rbx, %rdi
callq 0x2120
jmp 0x2729
movq %r12, %rdi
leaq 0x1c44(%rip), %rsi      # 0x418e
callq 0x28b2
testb %al, %al
je 0x25a0
movq %rbx, %rdi
leaq 0x1c37(%rip), %rsi      # 0x4194
callq 0x2120
xorl %r13d, %r13d
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x2, %rax
cmpq %rax, %r13
jae 0x25f4
movq %rbp, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0x28c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x21b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x2120
incq %r13
jmp 0x2565
movq %r12, %rdi
leaq 0x1b4a(%rip), %rsi      # 0x40f4
callq 0x28b2
testb %al, %al
je 0x25fc
movq %r14, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
leaq 0x1bce(%rip), %rsi      # 0x4196
callq 0x28b2
testb %al, %al
je 0x26a6
movq %rbx, %rdi
leaq 0x1bb5(%rip), %rsi      # 0x4194
callq 0x2120
movq %rax, %r13
movq %rbp, %rdi
callq 0x2370
jmp 0x271e
movq %rbx, %rax
jmp 0x2729
movq %r12, %rdi
leaq 0x1bb2(%rip), %rsi      # 0x41b8
callq 0x28b2
testb %al, %al
je 0x263d
movq %r14, %rdi
movq %rsp, %rsi
callq 0x20c0
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x20d0
movq (%rsp), %rsi
movq %rbp, %rdi
leaq 0x8(%rsp), %rdx
callq 0x28ea
jmp 0x245e
movq %r12, %rdi
leaq 0x1b78(%rip), %rsi      # 0x41bf
callq 0x28b2
testb %al, %al
je 0x26d5
movq %r14, %rdi
movq %rsp, %rsi
callq 0x20c0
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x20c0
movq %rbx, %rdi
leaq 0x1b1e(%rip), %rsi      # 0x4194
callq 0x2120
movq %rax, %r13
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rdi
callq 0x28c0
movq %r13, %rdi
movl %eax, %esi
callq 0x21b0
movq %rax, %rdi
callq 0x2090
jmp 0x245e
movq %r12, %rdi
leaq 0x1aec(%rip), %rsi      # 0x419c
callq 0x28b2
testb %al, %al
je 0x26f5
movq %r14, %rdi
movq %rsp, %rsi
callq 0x20c0
movq (%rsp), %rsi
movq %rbp, %rdi
callq 0x2314
jmp 0x245e
movq %r12, %rdi
leaq 0x1aaa(%rip), %rsi      # 0x4189
callq 0x28b2
leaq 0x1aba(%rip), %rsi      # 0x41a5
testb %al, %al
je 0x2533
jmp 0x2736
movq %r12, %rdi
leaq 0x1aa1(%rip), %rsi      # 0x41a0
callq 0x28b2
leaq 0x1a9a(%rip), %rsi      # 0x41a5
testb %al, %al
je 0x2533
movq %rbp, %rdi
callq 0x2376
movq %rbx, %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x20e0
movq %rax, %rdi
callq 0x2090
jmp 0x245e
leaq 0x28(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x296a
leaq 0x10(%rsp), %rdi
callq 0x2a84
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2772
jmp 0x2772
jmp 0x2779
jmp 0x2779
jmp 0x2779
movq %rax, %rbx
jmp 0x2790
jmp 0x2779
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x296a
leaq 0x10(%rsp), %rdi
callq 0x2a84
movq %rbx, %rdi
callq 0x21c0