jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
const long double pi=3.1415926535897;
 
ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];
 
ll ar[5000056];
ll br[5000056];
vector<int> adj[5000005];
set<vector<int> > st;
set<int> sets;
 
bool vis[520];
ll sum;
 
bool prime[10000006];
 
vector<int> primes,vec,pec;
 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
 
void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {
 
      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 
 
      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}
 
map<int,int> has[100008],occur[1000005];
bool flag;
 
 
void dfs0(int s)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			sum^=ar[*it];
			dfs0(*it);
		}
	}
	
}
 
 

int main() 
{
    int n,m,t,p,q,s,a,b,c,d,e,f,g,h,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm,pos,start,en;
    
    string str,ptr;
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
    	cin>>a>>b;
    	p=b-a+1;
    	ans=ans+p;
    	res=min(ans,100000);
	}
     
    cout<<res;
	return 0;
    
}
//  [c]
#include <stdio.h>
int main(void)
{
	int n;
	int l;
	int r;
	int a = 0;
	scanf("%d", &n);
	
	while(n != 0){
		scanf("%d %d", &l, &r);
		a = a + (r - l) + 1;
		
		n--;
		
	}
	
	printf("%d", a);
	
	return(0);
	
}
//  [c]
#include <stdio.h>
#define SIZE 1000
int main()
{
	unsigned int star[SIZE], stop[SIZE], diff[SIZE], sum = 0;
	int i, N;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &star[i], &stop[i]);
		diff[i] = stop[i] - star[i] + 1;
		sum += diff[i];
	}
	
	printf("%d", sum);
	
	return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int main(){
  int n,i,a,b,ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    ans += b-a+1;
  }
  printf("%d\n",ans);
}
//  [c]
#include<stdio.h>
int main(void)
{
  int flag=0,i,N,Snin=0,l[100000],r[100000];


  scanf("%d",&N);

  for(i=1; i<=N; i++){
    scanf("%d %d",&l[i],&r[i]);
  }

  for(i=1; i<=N; i++){
    Snin=Snin+r[i]-l[i]+1;
  }  
 
  printf("%d\n",Snin);
  
  return 0;
}
//  [c]
#include <stdio.h>
int main(void){
    
    int i,n,r[100000],l[100000],s=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&l[i],&r[i]);
    }
    for(i=0;i<n;i++){
        s+=r[i]-l[i]+1;
    }
    
    printf("%d\n",s);
    return 0;
}
//  [c]
#include <stdio.h>
int main(void){
    int N, i, ans = 0;
    int l[100000];
    int r[100000];
    
    scanf("%d", &N);
    
    for(i = 0; i < N; i++){
        scanf("%d %d", &l[i], &r[i]);
        //printf("%d\n %d\n", l[i], r[i]);
        ans = ans + (r[i] - l[i] + 1);
    }
    printf("%d\n", ans);
    
}
//  [javascript]
function Main(input) {
	input = input.split("\n");
	var n = input[0];
	var a = 0;
	for(i = 1; i <= n; i++){
		l = input[i].split(" ");
		a += l[1] - l[0] + 1;
	}
	console.log(a);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
	input = input.split("\n");
	var sum = 0;
	for(var i=1;i<input.length;i++){
		var mem = input[i].split(" ");
		sum += mem[1]-mem[0]+1;
	}
	console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
function Main(input) {
    input = input.split('\n');
    input = input.map(function(e) {
        return e.split(' ').map(function(e) {
            return parseInt(e, 10);
        });
    });
    var r = 0;
    for (var i = 1; i < input.length-1; i++) {
        r += (input[i][1] - input[i][0] + 1);
    }

    console.log('%d', r);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(s) {
	v = s.split("\n");
	x = 0;
	for (i = 1; i <= Number(v[0]); i++) {
		x += Number(v[i].split(" ")[1] - v[i].split(" ")[0] + 1)
	}
	console.log(x);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  var N = input[0]-0;
  var ans = input.filter((v,i)=>i>0).map(v=>v.split(" ")[1]-v.split(" ")[0]+1).reduce((a,b)=>a+b);
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
//  [javascript]
'use strict'

function main(s) {

  const seqs= s.split('\n').slice(1, -1).map(el => el.split(' ').map(num => Number(num)));

  const isSeated = Array(100001).fill(0);

  for (const seq of seqs) {
    for (let i = seq[0]; i <= seq[1]; i++) {
      isSeated[i] = 1;
    }
  }

  const ans = isSeated.filter(num => (num === 1)).length;
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ans := 0
	for i := 0; i < n; i++ {
		l, r := nextInt(), nextInt()
		ans += r - l + 1
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	ans := 0
	for i := 0; i < N; i++ {
		l, r := getInt(), getInt()
		ans += r - l + 1
	}
	out(ans)
}
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Theater
	var N int
	fmt.Scanf("%d", &N)

	var l, r int
	var ans int = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &l, &r)
		ans += r - l + 1
	}

	fmt.Println(ans)
}
//  [go]
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
)

func main() {
	var N int
	fmt.Scan(&N)
	lr := make([][]int, N)
	for i := range lr {
		lr[i] = NextIntArray()
	}

	count := 0
	for _, val := range lr {
		count += val[1] - val[0] + 1
	}

	fmt.Println(count)
}

// reader

var size = 100000
var rdr = bufio.NewReaderSize(os.Stdin, size)

func ReadLine() string {
	buf := make([]byte, 0, size)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func NextArray() []string {
	s := ReadLine()
	return strings.Split(s, " ")
}

func NextIntArray() []int {
	a := NextArray()
	na := make([]int, 0)

	for _, v := range a {
		if n, e := strconv.Atoi(v); e == nil {
			na = append(na, n)
		}
	}

	return na
}
//  [go]
package main

import "fmt"

func main() {
	var n, l, r, ans int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l, &r)
		ans += r - l + 1
	}
	fmt.Println(ans)
}
//  [ruby]
p [*$<][1..-1].map{|s|a,b=s.split;b.to_i-a.to_i+1}.reduce(:+)
//  [ruby]
n = gets.to_i
ans = 0

n.times do
  l, r = gets.split.map(&:to_i)
  ans += r-l+1
end

puts ans
//  [ruby]
$set = gets.chomp.to_i
$all = 0
$set.times do
  a,b=gets.split(" ").map(&:to_i)
  hm = b - a + 1
  $all += hm
end
puts $all
//  [ruby]
n = gets.to_i
ans = 0
n.times do
  l,r = gets.chomp.split(' ').map(&:to_i)
  ans += r - l + 1
end
puts ans
//  [ruby]
N = gets.to_i
num = 0
N.times do
  l, r = gets.split.map(&:to_i)
  num += (r-l+1)
end
puts num
//  [ruby]
N = gets.to_i
l, r = N.times.map{gets.split.map(&:to_i)}.transpose
sum = 0
N.times do |i|
  sum += r[i] - l[i] + 1
end
puts sum
//  [rust]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ans: i64 = 0;
    for _ in 0..n {
        let a: usize = read();
        let b: usize = read();
        ans += (b - a + 1) as i64;
    }
    println!("{}", ans);
}
//  [rust]
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n:usize = read();
    let mut cnt = 0;
    for _ in 0..n {
        let a:usize = read();
        let b:usize = read();
        cnt += b-a+1;
    }
    println!("{}", cnt);
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        lr: [[usize; 2]; n],
    }

    let mut sum = 0;
    for i in 0..n {
        sum += lr[i][1]-lr[i][0]+1;
    }

    println!("{}", sum);

}
//  [swift]
extension String:CollectionType{}
let n=Int(readLine()!)!;
var s=0;
for _ in 0..<n{
	let a=readLine()!.split(" ").map{Int($0)!}
	s+=a[1]-a[0]+1;
}
print(s)
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
var ans = 0
for _ in 0..<N {
    let person = readIntSplit(by: " ")
    ans += person[1] - person[0] + 1
}
print(ans)
//  [swift]
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let n = Int(readLine()!)!
var ans = 0
for _ in 0..<n {
  let (l, r) = toTuple(readInts())
  ans += r - l + 1
}
print(ans)
//  [swift]
//
//  main.swift
//  AtCoderSwift
//
//  Created by burita083 on 2020/08/25.
//  Copyright © 2020 burita083. All rights reserved.
//

import Foundation
func readInt() -> Int {
    return Int(readLine()!)!
}
 
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
 
func readTwoInts() -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: " ").map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

func abc080_b() {
    let N = readLine()!
    let sum = N.map { Int(String($0))! }.reduce(0, +)
    print(Int(N)! % sum == 0 ? "Yes" : "No")
}

//abc080_b()

func abc078_b() {
    let input = readInts()
    var X = input[0]
    let Y = input[1]
    let Z = input[2]
    var ans = 0
    X -= Y+Z*2
    ans += 1
    ans += X/(Y+Z)
    
    print(ans)
}

func abc085_b() {
    let N = readInt()
    var l: [Int] = []
    for _ in 0..<N {
        let d = readInt()
        l.append(d)
    }
    print(l.reduce([], { $0.contains($1) ? $0 : $0 + [$1] }).count)
}

func isSquare(n: Double) -> Bool {
    let sqrt = floor(n.squareRoot())
    return sqrt * sqrt == n
}

func abc077_b() {
    let N = readInt()
    for n in (1...N).reversed() {
        if isSquare(n: Double(n)) {
            print(n)
            return
        }
    }
}

func abc020_b () {
    let inputs = readInts()
    print(Int(String(inputs[0]) + String(inputs[1]))! * 2)
}

func abc073_b () {
    var ans = 0
    let N = readInt()
    for _ in 0..<N {
        let inputs = readInts()
        ans += inputs[1] - inputs[0] + 1
    }
    print(ans)
}



abc073_b()
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const gojo=(a:number,b:number):number=>{if(a%b===0)return b;return gojo(b,a%b)};
const main=()=>{
  let n=tn()
  let ans=0
  for(let i=0;i<n;i++)ans+=abs(tn()-tn())+1
  to(ans)
}
main()
//  [typescript]
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [[groupCount], ...groups] = input.trim().split("\n").map(s => s.split(" ").map(Number));

  const ans = groups.reduce((p, [from, to]) => (to - from + 1 + p), 0);
  console.log(ans);
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  let answer = 0;

  for (let i = 1; i <= N; i++) {
    const [l, r] = input[i].map(Number);

    answer += r - l + 1;
  }

  return answer;
};

console.log(main(read()));
//  [python]
N = input()
T = map(int, raw_input().split())
M = input()
P = []
X = []
for _ in range(M):
    p, x = map(int, raw_input().split())
    P.append(p)
    X.append(x)
res_normal = sum(T)
for i in range(M):
    print res_normal - T[P[i] - 1] + X[i]
//  [python]
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    t = read_int_list()
    m = read_int()
    p = [0] * m
    x = [0] * m
    for i in range(m):
        p[i], x[i] = read_int_list()
        p[i] -= 1

    s = sum(t)
    for i in range(m):
        j = p[i]
        res = s - t[j] + x[i]
        print(res)


main()
//  [python]
n = int(input())
t = list(map(int, input().split()))
T = sum(t)
m = int(input())
ans = []
for i in range(m):
    p, x = map(int, input().split())
    ans.append(T - t[p - 1] + x)
for a in ans:
    print(a)
//  [python]
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
T = list(map(int, sys.stdin.readline().split()))
M = int(sys.stdin.readline())
P, X = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

s = sum(T)
for p, x in zip(P, X):
    print(s - T[p-1] + x)
//  [python]
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
t = LI()
m = II()
drink = [LI() for _ in range(m)]
tsum = sum(t)
for p, x in drink:
    print(tsum - t[p-1] + x)
//  [python]
import numpy as np

N = int(input())
T = [int(i) for i in input().split()]

M = int(input())

P = np.ones(M)
X = np.ones(M)

for i in range(M):
    
    P[i],X[i] = [int(i) for i in input().split()]
    
ans = sum(T)

for i in range(M):
    ans_ = int(ans + X[i] - T[int(P[i])-1])
    print(ans_)
//  [java]

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] t = new int[n];
	for (int i = 0; i < n; i++)
	    t[i] = sc.nextInt();
	int m = sc.nextInt();
	int[] p = new int[m];
	int[] x = new int[m];
	for (int i = 0; i < m; i++) {
	    p[i] = sc.nextInt() - 1;
	    x[i] = sc.nextInt();
	}
	for (int i = 0; i < m; i++) {
	    int ans = 0;
	    for (int j = 0; j < n; j++) {
		if (j == p[i])
		    ans += x[i];
		else
		    ans += t[j];
	    }
	    System.out.println(ans);
	}
    }
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        String strT = sc.nextLine();
        int[] T = Arrays.stream(strT.split(" ")).mapToInt(Integer::valueOf).toArray();
        int M = sc.nextInt();
        for (int i = 0; i < M; i++) {
            int time = 0;
            int P = sc.nextInt() - 1;
            int X = sc.nextInt();
            for (int j = 0; j < N; j++) {
                if (j != P) {
                    time += T[j];
                } else {
                    time += X;
                }
            }
            System.out.println(time);
        }
    }

}
//  [java]
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int N = in.nextInt();
        int[] T = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            T[i] = in.nextInt();
            sum+= T[i];
        }
        int M = in.nextInt();
        int[] P = new int[M];
        int[] X = new int[M];
        for (int i = 0; i < M; i++) {
            P[i] = in.nextInt();
            X[i] = in.nextInt();
            System.out.println(sum - T[P[i] - 1] + X[i]);
        }
    }
}
//  [cpp]
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> t(n);
  int sum = 0;
  rep(i, n) {
    cin >> t.at(i);
    sum += t.at(i);
  }
  int m; cin >> m;
  rep(i, m) {
    int p, x; cin >> p >> x;
    p--;
    cout << sum - t.at(p) + x << '\n';
  }
}
//  [cpp]
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    int N, M;
    
    cin >> N;
    vector<int> sec(N);
    REP(i, N) cin >> sec[i];
    
    cin >> M;
    vector<int> drink(M), aft_drink_sec(M);
    REP(i, M) {
        cin >> drink[i] >> aft_drink_sec[i];
    }
    
    // calculation
    REP(i, M) {
        vector<int> cp_sec;
        COPY(sec, cp_sec);
        int idx = drink[i] - 1;
        cp_sec[idx] = aft_drink_sec[i];
        cout << SUM(cp_sec) << "\n";
    }
    
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll n,m,p,x,sum1,sum2,a[1005];
int main()
{
    scanf("%lld",&n);
    for(reg int i=1;i<=n;i++)
	{
        scanf("%lld",&a[i]);
        sum1+=a[i];
        sum2+=a[i];
    }
    scanf("%lld",&m);
    while(m--)
	{
        scanf("%lld%lld",&p,&x);
        sum1+=x>=a[p]?x-a[p]:-a[p]+x;
        printf("%lld\n",sum1);
        sum1=sum2;
    }
    return 0;
}
//  [cpp]
#include<stdio.h>
#include<string.h>

int main(void) {
	int N,T[100],M,P[100],X[100];
	int i, j, sum;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &T[i]);
	}
	scanf("%d", &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d", &P[i],&X[i]);
	}
	sum = 0;
	for (i = 0; i < N; i++) {
		sum = sum + T[i];
	}
	for (i = 0; i < M; i++) {
		printf("%d\n", sum - T[P[i] - 1] + X[i]);
	}

	return 0;
}
//  [cpp]
#include <iostream>
#include <vector>

#define REP(i,n) for( unsigned i = 0; i < (n); i++ )

using namespace std;

int main()
{
  int n, m, tmp;
  vector<int> t, p, x;

  cin >> n;
  REP( i, n ) {
    cin >> tmp;
    t.push_back( tmp );
  }

  cin >> m;
  REP( i, m ) {
    cin >> tmp;
    p.push_back( tmp );
    cin >> tmp;
    x.push_back( tmp );
  }

  int sum = 0;
  REP( i, n ) {
    sum += t[i];
  }

  REP( i, m ) {
    cout << sum - t[p[i]-1] + x[i] << endl;
  }

  return 0;
}
//  [cpp]
#include<bits/stdc++.h>
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> T(n);
  REP(i, n)
    cin >> T[i];
  int m;
  cin >> m;
  vector<int> P(m), X(m);
  REP(i, m)
    cin >> P[i] >> X[i];
  REP(i, m) {
    int ans = 0;
    REP(j, n) {
      if (j == P[i] - 1)
        ans += X[i];
      else
        ans += T[j];
    }
    cout << ans << endl;
  }
  return 0;
}
//  [c]
#include <stdio.h>

int main(){
  int n,t[100],m,p,x,i,j,result;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
  }
  
  scanf("%d",&m);

  for(i=0;i<m;i++){
    result=0;
    scanf("%d %d",&p,&x);
    for(j=0;j<n;j++){
      if(j!=(p-1)){
        result+=t[j];
      } else {
        result+=x;
      }
    }
    printf("%d\n",result);
  }
}
//  [c]
#include<stdio.h>
int main()
{
	int n,t[101],m,p[101],x[101],a=0,i;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&t[i]);
	scanf("%d",&m);
	for(i=0;i<m;i++)
		scanf("%d%d",&p[i],&x[i]);

	for(i=0;i<n;i++)
		a+=t[i];
	for(i=0;i<m;i++)
		printf("%d\n",a-t[p[i]-1]+x[i]);
	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	int N,M;

	scanf("%d",&N);

	int T[N];


	int sum[100] ={0};

	for(int i = 0; i < N; i++){
		scanf("%d",&T[i]);
	}

	scanf("%d",&M);

	int P[M];
	int X[M];

	for(int i = 0; i < M; i++){
		scanf("%d",&P[i]);
		scanf("%d",&X[i]);
		// printf("P[%d] = %d\nX[%d] = %d\n",i,P[i],i,X[i]);
	}

	for(int k = 0; k < M; k++){
		for(int i = 0; i < N; i++){
			if(i == P[k]-1){
				sum[k] += X[k];
			}
			else{
			sum[k] += T[i];
			}
			// printf("T[%d] = %d, sum[%d] = %d\n",i,T[i],k,sum[k]);
		}
		printf("%d\n",sum[k]);
	}	
	return 0;
}
//  [c]
#include <stdio.h>
int main(){
    int N, M, time=0;
    int T[101];
    int X[101];
    int P[101];
    int i, j;
    scanf("%d", &N);
    for(i = 1; i <= N; i++){
        scanf("%d", &T[i]);
    }
    scanf("%d", &M);
    for(i = 1; i <= M; i++){
        scanf("%d %d", &P[i], &X[i]);
    }
    for(i = 1; i <= M; i++){
        for(j =1; j <= N; j++){
            if(P[i] == j) time+=X[i];
            else time+=T[j];
        }
        printf("%d\n", time);
        time = 0;
    }
    return 0;
}
//  [c]

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int N;
	scanf("%d", &N);
	int T[100];
	for (int i = 0; i < N; i++) {
		scanf("%d", &T[i]);
	}
	int M;
	scanf("%d", &M);
	int P[100], X[100];
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &P[i], &X[i]);
	}

	for (int i = 0; i < M; i++) {
		int ans = 0;
		for (int i = 0; i < N; i++) {
			ans += T[i];
		}
		ans -= (T[P[i]-1] - X[i]);
		printf("%d\n", ans);
	}


#ifdef DEBUGF
	getch();
#endif
	return 0;
}
//  [c]
#include<stdio.h>
int main()
{
    int a[10000],b[100000],n,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    }scanf("%d",&m);
    for(int j=0;j<2*m;j++){
        scanf("%d",&b[j]);
    }
    for(int k=0;k<2*m;k=k+2){
            int sum=0,temp;
         temp=a[b[k]-1];
         a[b[k]-1]=b[k+1];
         for(int l=0;l<n;l++){
            sum=sum+a[l];
         }
         printf("%d\n",sum);
         a[b[k]-1]=temp;

    }


    return 0;

}
//  [javascript]
'use strict'

function main(s) {

  s = s.split('\n');

  const q = s[1].split(' ').map(n => Number(n));
  const drink = s.slice(3, -1).map(l => l.split(' ').map(n => Number(n)));

  const base_sum = q.reduce((a, b) => a + b);
  const ans = [];

  for (let i = 0; i < drink.length; i++) {
    const nsum = base_sum + (drink[i][1] - q[drink[i][0] - 1]);
    ans.push(nsum);
  }

  console.log(ans.join('\n'));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0]);
  var time = 0;
  var times = input[1].split(" ").map((a)=>Number(a));
  for(var i = 0; i < times.length; i++){
    time += times[i];
  }
  
  var M = parseInt(input[2]);
  var output = [];
  for(var i = 3; i < M + 3; i++){
    var tmp = input[i].split(" ").map((a)=>Number(a));
    output.push(time - (times[tmp[0] - 1] - tmp[1]));
  }
  myout(output.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
'use strict'

const main = arg => {
    arg = arg.trim().split("\n")
    const N = ~~arg[0];
    const T = arg[1].split(" ").map(n=>~~n);
    const M = ~~arg[2];
    const drinks = arg.slice(3, M + 3).map(n=>n.split(" ").map(l=>~~l));
    
    const baseTime = T.reduce((m,n)=>m+n);
    
    for(let i in drinks) {
        console.log((baseTime - T[drinks[i][0] - 1]) + drinks[i][1]);
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))
//  [javascript]
function Main(input) {
    input = input.split("\n");
    tmp = input[1].split(" ");
    var c = 0;
    for(i=0;i<tmp.length;i++){
      c += parseInt(tmp[i])
    }
    for(j=0;j<input[2];j++){
       tmp2 = input[3+j].split(" ");
       var d = c - tmp[parseInt(tmp2[0])-1] + parseInt(tmp2[1]);
       console.log('%s', d);
    }
}

function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(v => Number(v)))
  const N = input[0][0]
  const T = input[1]
  const M = input[2][0]
  const P = input.slice(3)

  // console.log(M, P)

  const total = T.reduce((a, b) => a + b)

  let ans = []
  for (let i = 0; i < M; i++) {
    const a = P[i][0]
    const b = P[i][1]

    ans.push(total - (T[P[i][0] - 1] - P[i][1]))
  }
  console.log(ans.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
	var N = parseInt(readLine());
	var s = readLine().split(" ");
	var T = [0];
	var sum=0;
	for (var i=1; i <= N; i++){
		T.push(parseInt(s[i-1]));
		sum += T[i];
	}
	var M = parseInt(readLine());
	for (var k=0; k < M; k++){
		s = readLine().split(" ");
		var i = parseInt(s[0]);
		var x = parseInt(s[1]);
		console.log(sum - T[i] + x);
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var N, M int
	var Tstr string

	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	Nstr := sc.Text()
	N, _ = strconv.Atoi(Nstr)
	sc.Scan()
	Tstr = sc.Text()
	T := make([]int, N)
	Tlist := strings.Split(Tstr, " ")
	for i := 0; i < N; i++ {
		T[i], _ = strconv.Atoi(Tlist[i])
	}

	sc.Scan()
	Mstr := sc.Text()
	M, _ = strconv.Atoi(Mstr)
	P := make([]int, M)
	X := make([]int, M)
	for i := 0; i < M; i++ {
		sc.Scan()
		str := sc.Text()
		strlist := strings.Split(str, " ")
		P[i], _ = strconv.Atoi(strlist[0])
		X[i], _ = strconv.Atoi(strlist[1])
	}

	total := 0
	for _, val := range T {
		total += val
	}

	for idx, val := range P {
		no := val - 1
		time := X[idx]
		fmt.Printf("%d\n", total-T[no]+time)
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, M int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	T := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		T[i] = nextInt()
		sum += T[i]
	}

	M = nextInt()
	for m := 0; m < M; m++ {
		i := nextInt() - 1
		x := nextInt()
		fmt.Println(sum - T[i] + x)
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc = initScanner(os.Stdin)
	n := scanInt(sc)
	t := scanIntSlice(sc, n)
	m := scanInt(sc)

	solve(t, n, m)
}

func solve(t []int, n, m int)  {
	p := make([]int, m)
	x := make([]int, m)

	for i:=0;i<m;i++ {
		p[i] = scanInt(sc)
		x[i] = scanInt(sc)
	}

	sum := 0
	for i:=0; i<m; i++ {
		sum = 0
		for j := 0 ; j < n; j++ {
			if p[i]-1 == j {
				sum += x[i]
			} else {
				sum += t[j]
			}
		}
		fmt.Println(sum)
	}
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Contest with Drinks Easy
	var N int
	fmt.Scanf("%d", &N)

	var sum int = 0
	T := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &T[i])
		sum += T[i]
	}

	var M int
	fmt.Scanf("%d", &M)
	var P, X int
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &P, &X)
		fmt.Println(sum - T[P-1] + X)
	}

}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n := scanInt(sc)
	ts := nextIntSlice(sc, n)
	sum := 0
	for i := range loop0(n) {
		sum += ts[i]
	}
	m := scanInt(sc)
	rs := []int{}
	for _ = range loop0(m) {
		p, x := scanInt(sc), scanInt(sc)
		rs = append(rs, sum-ts[p-1]+x)
	}
	for _, v := range rs {
		fmt.Println(v)
	}
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}
//  [ruby]
n = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)
m = gets.chomp.to_i
arr = Array.new
sum = t.inject(:+)
m.times do 
	arr = gets.chomp.split(" ").map(&:to_i)
	puts sum - t[arr[0] - 1] + arr[1]
end
//  [ruby]
_ = gets
t = gets.chomp.split.map(&:to_i)
sum_t = t.inject(:+)
m = gets.to_i
m.times do |_|
  c, x = gets.chomp.split.map(&:to_i)
  puts sum_t - t[c - 1] + x
end
//  [ruby]
N = gets.chomp.to_i
T = gets.chomp.split.map(&:to_i)
M = gets.chomp.to_i
D = []
M.times do
  D.push(gets.chomp.split.map(&:to_i))
end

sum_time = 0
T.each do |t|
  sum_time += t
end

D.each do |d|
  tmp = sum_time
  tmp += d[1] - T[d[0]-1]
  puts tmp
end
//  [ruby]
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end


n = gets_i
tlist = gets_i_list
m = gets_i
plist, xlist = [], []

total = tlist.sum

m.times do
  p, x = gets_i_list
  puts total - tlist[p-1] + x
end
//  [ruby]
N = gets.to_i
T = gets.split.map(&:to_i)
M = gets.to_i
P, X = M.times.map{gets.split.map(&:to_i)}.transpose

all=T.sum
M.times do |i|
    c_no=P[i]-1
    puts all-T[c_no]+X[i]
end
//  [ruby]
n = gets.to_i
t_arr = gets.split.map(&:to_i)
sum = t_arr.sum

m = gets.to_i
m.times do
  ind, t = gets.split.map(&:to_i)
  puts sum - (t_arr[ind - 1] - t)
end
//  [rust]
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let n:i32 = procon_read()[0];
	let t:Vec<i32> = procon_read();
	let mut sum:i32 = 0;
	let m:i32 = procon_read()[0];
	let mut p:Vec<i32> = Vec::new();
	let mut x:Vec<i32> = Vec::new();
	for i in 0..m {
		let v:Vec<i32> = procon_read();
		p.push(v[0]);
		x.push(v[1]);
	}
	for i in &t {
		sum += *i;
	}
	for i in 0..p.len() {
		println!("{}", sum - t[(p[i] - 1) as usize] + x[i as usize]);
	}
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        t: [i64; n],
        m: usize,
        px: [(usize1,i64); m],
    }
    for d in px {
        let mut sum: i64 = 0;
        for (i,y) in t.iter().enumerate() {
            if i == d.0 {
                sum += d.1
            } else {
                sum += *y
            }
        }
        println!("{}", sum);
    }
}
//  [rust]
use std::io::*;
use std::str::FromStr;

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let n: usize = read();
    let mut t: Vec<i64> = Vec::with_capacity(n);
    let mut sum: i64 = 0;
    for i in 0..n{
	t.push(read());
	sum += t[i as usize];
    }
    let m: usize = read();
    for _i in 0..m{
	let p: usize = read();
	let x: i64 = read();
	println!("{}",sum-t[p-1]+x);
    }
}
//  [rust]
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let t: Vec<u32> = parse_line().unwrap();
    let m: usize = parse_line().unwrap();

    let sum: u32 = t.iter().sum();
    for _ in 0..m {
        let (p, x): (usize, i64) = parse_line().unwrap();
        let diff = t[p - 1] as i64 - x;
        println!("{}", sum as i64 - diff);
    }
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        t_vec: [isize; n],
        m: usize,
        px_vec:[(usize, isize); m],
    }

    let sum: isize = t_vec.iter().sum();

    for (p, x) in px_vec.into_iter() {
        println!("{}", sum - t_vec[p-1] + x)
    }

    println!("", );
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;


fn main() {
    input! {
        a:usize,
        b:[isize;a],
        c:usize,
        d:[(usize,isize);c],
    }
    let e:isize=b.iter().sum();
    for i in 0..c {
        println!("{}",e-b[d[i].0-1]+d[i].1)
    }
}