#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);
int /*<<< orphan*/ scanf(char *, int *);
int search(int *, int /*<<< orphan*/, int, int);
int sum(int *, int);
int main() {
  int len;
  scanf("%d", &len);
  int arr[len];
  for (int i = 0; i < len; ++i)
    scanf("%d", &arr[i]);
  int cases;
  scanf("%d", &cases);
  while (cases--) {
    int pow;
    scanf("%d", &pow);
    if (pow >= arr[len - 1]) {
      printf("%d %d\n", len, sum(arr, len));
      continue;
    }
    int pos = search(arr, 0, len - 1, pow) + 1;
    printf("%d %d\n", pos, sum(arr, pos));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c2 <main+0x82>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe51(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <main+0x4d>
lea    0xe37(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1279 <main+0x139>
lea    0xe13(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x30(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jl     1237 <main+0xf7>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%esi
call   1050 <sum@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0x92>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
mov    -0x24(%rbp),%ecx
xor    %esi,%esi
call   1040 <search@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%esi
call   1050 <sum@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
lea    0xd94(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11ac <main+0x6c>
xor    %r15d,%r15d
lea    0xe73(%rip),%r14
mov    %r13,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r15
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r15
jl     1190 <main+0x50>
lea    0xe4d(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jae    11d7 <main+0x97>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe22(%rip),%r14
lea    -0x34(%rbp),%r15
lea    0xe1a(%rip),%r12
jmp    120c <main+0xcc>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebx,%esi
call   1050 <sum@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
subl   $0x1,-0x30(%rbp)
jb     11c2 <main+0x82>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    -0x34(%rbp),%ecx
movslq -0x2c(%rbp),%rbx
cmp    -0x4(%r13,%rbx,4),%ecx
jge    11f0 <main+0xb0>
add    $0xffffffffffffffff,%rbx
mov    %r13,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <search@plt>
mov    %eax,%ebx
add    $0x1,%ebx
jmp    11f0 <main+0xb0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
store i32 0, i32* %5
br label %14
14: ; preds = %23, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %13, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %14
26: ; preds = %14
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %28
28: ; preds = %46, %41, %26
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
%31 = icmp ne i32 %29, 0
br i1 %31, label %32, label %56
32: ; preds = %28
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%34 = load i32, i32* %7
%35 = load i32, i32* %2
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %13, i64 %37
%39 = load i32, i32* %38
%40 = icmp sge i32 %34, %39
br i1 %40, label %41, label %46
41: ; preds = %32
%42 = load i32, i32* %2
%43 = load i32, i32* %2
%44 = call i32 @sum(i32* %13, i32 %43)
%45 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %44)
br label %28
46: ; preds = %32
%47 = load i32, i32* %2
%48 = sub nsw i32 %47, 1
%49 = load i32, i32* %7
%50 = call i32 @search(i32* %13, i32 0, i32 %48, i32 %49)
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = load i32, i32* %8
%54 = call i32 @sum(i32* %13, i32 %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %54)
br label %28
56: ; preds = %28
store i32 0, i32* %1
%57 = load i8*, i8** %3
%58 = load i32, i32* %1
ret i32 %58
}

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