#import <stdio.h>
int main() {
    int n,m;
    int T[200] = {0};
    int P[200] = {0};
    int X[200] = {0};
    scanf("%d", &n);
    for(int i=0;i<n;i++) {
        int t;
        scanf("%d", &t);
        T[i] = t;
    }
    scanf("%d", &m);
    for(int j=0;j<m;j++) {
        int p, x;
        scanf("%d %d", &p,&x);
        P[j] = p;
        X[j] = x;
    }
    for(int j=0;j<m;j++) {
        int count = 0;
        for(int i=0;i<n;i++) {
            count += i==P[j]-1 ? X[j] : T[i];
        }
        printf("%d\n", count);
    }
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_860/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_860/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@.str.1 = private unnamed_addr constant [6 x i8] c"%d %d\00", align 1
@.str.2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1

; Function Attrs: minsize nofree nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %n = alloca i32, align 4
  %m = alloca i32, align 4
  %T = alloca [200 x i32], align 16
  %P = alloca [200 x i32], align 16
  %X = alloca [200 x i32], align 16
  %t = alloca i32, align 4
  %p = alloca i32, align 4
  %x = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %n) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %m) #5
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %T) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) %T, i8 0, i64 800, i1 false)
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %P) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) %P, i8 0, i64 800, i1 false)
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %X) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800) %X, i8 0, i64 800, i1 false)
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n) #6
  br label %for.cond

for.cond:                                         ; preds = %for.body, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  %0 = load i32, ptr %n, align 4, !tbaa !5
  %1 = sext i32 %0 to i64
  %cmp = icmp slt i64 %indvars.iv, %1
  br i1 %cmp, label %for.body, label %for.cond.cleanup

for.cond.cleanup:                                 ; preds = %for.cond
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %m) #6
  br label %for.cond3

for.body:                                         ; preds = %for.cond
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %t) #5
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %t) #6
  %2 = load i32, ptr %t, align 4, !tbaa !5
  %arrayidx = getelementptr inbounds [200 x i32], ptr %T, i64 0, i64 %indvars.iv
  store i32 %2, ptr %arrayidx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %t) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %for.cond

for.cond3:                                        ; preds = %for.body6, %for.cond.cleanup
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %for.body6 ], [ 0, %for.cond.cleanup ]
  %3 = load i32, ptr %m, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %cmp4 = icmp slt i64 %indvars.iv52, %4
  br i1 %cmp4, label %for.body6, label %for.cond16

for.body6:                                        ; preds = %for.cond3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %p) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %x) #5
  %call7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %p, ptr noundef nonnull %x) #6
  %5 = load i32, ptr %p, align 4, !tbaa !5
  %arrayidx9 = getelementptr inbounds [200 x i32], ptr %P, i64 0, i64 %indvars.iv52
  store i32 %5, ptr %arrayidx9, align 4, !tbaa !5
  %6 = load i32, ptr %x, align 4, !tbaa !5
  %arrayidx11 = getelementptr inbounds [200 x i32], ptr %X, i64 0, i64 %indvars.iv52
  store i32 %6, ptr %arrayidx11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %x) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %p) #5
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  br label %for.cond3

for.cond16:                                       ; preds = %for.cond3, %for.cond.cleanup23
  %7 = phi i32 [ %.pre, %for.cond.cleanup23 ], [ %3, %for.cond3 ]
  %indvars.iv58 = phi i64 [ %indvars.iv.next59, %for.cond.cleanup23 ], [ 0, %for.cond3 ]
  %8 = sext i32 %7 to i64
  %cmp17 = icmp slt i64 %indvars.iv58, %8
  br i1 %cmp17, label %for.cond21.preheader, label %for.cond.cleanup18

for.cond21.preheader:                             ; preds = %for.cond16
  %9 = load i32, ptr %n, align 4, !tbaa !5
  %arrayidx26 = getelementptr inbounds [200 x i32], ptr %P, i64 0, i64 %indvars.iv58
  %arrayidx29 = getelementptr inbounds [200 x i32], ptr %X, i64 0, i64 %indvars.iv58
  %smax = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %wide.trip.count = zext i32 %smax to i64
  br label %for.cond21

for.cond.cleanup18:                               ; preds = %for.cond16
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %X) #5
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %P) #5
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %T) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %m) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %n) #5
  ret i32 0

for.cond21:                                       ; preds = %for.cond21.preheader, %for.body24
  %indvars.iv55 = phi i64 [ 0, %for.cond21.preheader ], [ %indvars.iv.next56, %for.body24 ]
  %count.0 = phi i32 [ 0, %for.cond21.preheader ], [ %add, %for.body24 ]
  %exitcond.not = icmp eq i64 %indvars.iv55, %wide.trip.count
  br i1 %exitcond.not, label %for.cond.cleanup23, label %for.body24

for.cond.cleanup23:                               ; preds = %for.cond21
  %call35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %count.0) #6
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %.pre = load i32, ptr %m, align 4, !tbaa !5
  br label %for.cond16

for.body24:                                       ; preds = %for.cond21
  %10 = load i32, ptr %arrayidx26, align 4, !tbaa !5
  %sub = add nsw i32 %10, -1
  %11 = zext i32 %sub to i64
  %cmp27 = icmp eq i64 %indvars.iv55, %11
  %arrayidx31 = getelementptr inbounds [200 x i32], ptr %T, i64 0, i64 %indvars.iv55
  %cond.in = select i1 %cmp27, ptr %arrayidx29, ptr %arrayidx31
  %cond = load i32, ptr %cond.in, align 4, !tbaa !5
  %add = add nsw i32 %cond, %count.0
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  br label %for.cond21
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

attributes #0 = { minsize nofree nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { minsize nofree nounwind optsize "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { minsize optsize }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
