// File: zengfenfei[P]codility/src/GenomicRangeQuery.cpp
// Function: solution(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&)
vector<int> solution(string &S, vector<int> &P, vector<int> &Q) {
	// Calculate prefix counts
	int n = S.length();
	string types = "ACGT";
	int factors[4] = { 1, 2, 3, 4 }; // Ascending order and corresponds to order of types
	map<char, int> type2factorIdx;
	for (int i = 0; i < types.length(); i++) {
		type2factorIdx[types[i]] = i;
	}
	vector<vector<int> > prefixCounts(types.length() - 1,
			vector<int>(n + 1, 0));
	for (int i = 1; i < n + 1; i++) {
		for (int j = 0; j < prefixCounts.size(); j++) {
			prefixCounts[j][i] = prefixCounts[j][i - 1];
		}
		int facI = type2factorIdx[S[i - 1]];
		if (facI < prefixCounts.size()) {
			prefixCounts[facI][i]++;
		}
	}

	int m = P.size();
	vector<int> result(m);
	for (int i = 0; i < m; i++) {
		int f = P[i], t = Q[i] + 1;
		for (int j = 0; j < types.length(); j++) {
			if (j < prefixCounts.size()) {
				int count = prefixCounts[j][t] - prefixCounts[j][f];
				if (count > 0) {
					result[i] = factors[j];
					break;
				}
			} else {
				result[i] = factors[j];
			}
		}
	}
	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x120(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x21c0
movl %eax, -0x24(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x2220
movq -0x110(%rbp), %rdx
leaq 0x3c0e(%rip), %rsi      # 0x6004
leaq -0x48(%rbp), %rdi
callq 0x2ce0
jmp 0x2401
leaq -0x49(%rbp), %rdi
callq 0x2160
movq 0x3c5f(%rip), %rax      # 0x6070
movq %rax, -0x70(%rbp)
movq 0x3c5c(%rip), %rax      # 0x6078
movq %rax, -0x68(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2d90
movl $0x0, -0xa4(%rbp)
movslq -0xa4(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
jae 0x24eb
movl -0xa4(%rbp), %eax
movl %eax, -0x134(%rbp)
movslq %eax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x2250
movq %rax, -0x130(%rbp)
jmp 0x2481
movq -0x130(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x2db0
movq %rax, -0x140(%rbp)
jmp 0x249d
movq -0x140(%rbp), %rax
movl -0x134(%rbp), %ecx
movl %ecx, (%rax)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x2436
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x2160
jmp 0x29f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x29e1
leaq -0x48(%rbp), %rdi
callq 0x21c0
decq %rax
movq %rax, -0x158(%rbp)
movl -0x24(%rbp), %eax
incl %eax
cltq
movq %rax, -0x150(%rbp)
movl $0x0, -0xdc(%rbp)
leaq -0xdd(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x2e90
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rcx
leaq -0xd8(%rbp), %rdi
leaq -0xdc(%rbp), %rdx
callq 0x2eb0
jmp 0x254c
leaq -0xde(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x2f30
movq -0x158(%rbp), %rsi
movq -0x160(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x2f50
jmp 0x2582
leaq -0xde(%rbp), %rdi
callq 0x2fd0
leaq -0xd8(%rbp), %rdi
callq 0x2ff0
leaq -0xdd(%rbp), %rdi
callq 0x3050
movl $0x1, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x276e
movl $0x0, -0xe8(%rbp)
movslq -0xe8(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3070
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jae 0x26ab
movslq -0xe8(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
movl -0xe4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x30c0
movl (%rax), %eax
movl %eax, -0x16c(%rbp)
movslq -0xe8(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
movslq -0xe4(%rbp), %rsi
callq 0x30c0
movl -0x16c(%rbp), %ecx
movl %ecx, (%rax)
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x25ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x269a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xde(%rbp), %rdi
callq 0x2fd0
leaq -0xd8(%rbp), %rdi
callq 0x2ff0
leaq -0xdd(%rbp), %rdi
callq 0x3050
jmp 0x29e1
movq -0x10(%rbp), %rdi
movl -0xe4(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x2250
movq %rax, -0x178(%rbp)
jmp 0x26c8
movq -0x178(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x2db0
movq %rax, -0x180(%rbp)
jmp 0x26e4
movq -0x180(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xec(%rbp)
movslq -0xec(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3070
movq %rax, %rcx
movq -0x188(%rbp), %rax
cmpq %rcx, %rax
jae 0x2758
movslq -0xec(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
movslq -0xe4(%rbp), %rsi
callq 0x30c0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x2758
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x29d5
jmp 0x275a
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x25b0
movq -0x18(%rbp), %rdi
callq 0x30e0
movl %eax, -0xf0(%rbp)
movb $0x0, -0xf1(%rbp)
movslq -0xf0(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0xf2(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x2e90
movq -0x120(%rbp), %rdi
movq -0x198(%rbp), %rsi
movq -0x190(%rbp), %rdx
callq 0x3100
jmp 0x27c1
leaq -0xf2(%rbp), %rdi
callq 0x3050
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0xf0(%rbp), %eax
jge 0x2988
movq -0x18(%rbp), %rdi
movslq -0xf8(%rbp), %rsi
callq 0x30c0
movl (%rax), %eax
movl %eax, -0xfc(%rbp)
movq -0x20(%rbp), %rdi
movslq -0xf8(%rbp), %rsi
callq 0x30c0
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
movl $0x0, -0x104(%rbp)
movslq -0x104(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2972
movslq -0x104(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3070
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2930
movslq -0x104(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
movslq -0x100(%rbp), %rsi
callq 0x30c0
movl (%rax), %eax
movl %eax, -0x1ac(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
movslq -0xfc(%rbp), %rsi
callq 0x30c0
movq %rax, %rcx
movl -0x1ac(%rbp), %eax
subl (%rcx), %eax
movl %eax, -0x108(%rbp)
cmpl $0x0, -0x108(%rbp)
jle 0x292e
movq -0x120(%rbp), %rdi
movslq -0x104(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movl %eax, -0x1b0(%rbp)
movslq -0xf8(%rbp), %rsi
callq 0x30c0
movl -0x1b0(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x2972
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xf2(%rbp), %rdi
callq 0x3050
jmp 0x29d5
jmp 0x295c
movq -0x120(%rbp), %rdi
movslq -0x104(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
movl %eax, -0x1b4(%rbp)
movslq -0xf8(%rbp), %rsi
callq 0x30c0
movl -0x1b4(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x295e
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x2826
jmp 0x2974
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x27d7
movb $0x1, -0xf1(%rbp)
testb $0x1, -0xf1(%rbp)
jne 0x29a4
movq -0x120(%rbp), %rdi
callq 0x2ff0
leaq -0xc0(%rbp), %rdi
callq 0x3170
leaq -0xa0(%rbp), %rdi
callq 0x31d0
leaq -0x48(%rbp), %rdi
callq 0x20a0
movq -0x118(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0x3170
leaq -0xa0(%rbp), %rdi
callq 0x31d0
leaq -0x48(%rbp), %rdi
callq 0x20a0
movq -0x58(%rbp), %rdi
callq 0x2210
nop