You have an array of length N and need to process Q queries. The queries can either update a value in the array or calculate the sum of a range within the array. Constraints include the size of the array, the range of values, and the query indices. The input format includes N, Q, the array values, and the queries. The output should display the result of each query. For example, given an array [1, 2, 3, 4, 5] and the queries [1 0 5], [1 2 4], [0 3 10], [1 0 5], [1 0 3], the expected output is 15, 7, 25, 6.

# Buggy version:
class binaryindexedtree():
  def __init__(self,n):
    self.n=n
    self.tree=[0]*n
  def add(self,a,w):
    x=a
    while x<=self.n:
      self.tree[x-1]+=w
      x+=x&(-x)
  def sums(self,a):
    x=a
    S=0
    while x!=0:
      S+=self.tree[x-1]
      x-=x&(-x)
    return S
n,q=map(int,input().split())
a=list(map(int,input().split()))
bit=binaryindexedtree(n)
for i,x in enumerate(a,1):
  bit.add(i,x)
ans=[]
for _ in range(q):
  x,y,z=map(int,input().split())
  if x:ans+=[bit.sums(z)-bit.sums(y)]
  else:bit.add(y,z)
print(*ans,sep='\n')

# Fixed version:
class binaryindexedtree():
  def __init__(self,n):
    self.n=n
    self.tree=[0]*n
  def add(self,a,w):
    x=a
    while x<=self.n:
      self.tree[x-1]+=w
      x+=x&(-x)
  def sums(self,a):
    x=a
    S=0
    while x!=0:
      S+=self.tree[x-1]
      x-=x&(-x)
    return S
n,q=map(int,input().split())
a=list(map(int,input().split()))
bit=binaryindexedtree(n)
for i,x in enumerate(a,1):
  bit.add(i,x)
ans=[]
for _ in range(q):
  x,y,z=map(int,input().split())
  if x:ans+=[bit.sums(z)-bit.sums(y)]
  else:bit.add(y+1,z)
print(*ans,sep='\n')

# Buggy version:
n,q=map(int,input().split())
a=list(map(int,input().split()))
bit=[0]*(2*n+10)
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))

# Fixed version:
n,q=map(int,input().split())
a=list(map(int,input().split()))
size=2*n+1
bit=[0]*size
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))

# Buggy version:
N,Q=map(int,input().split())
alist=list(map(int,input().split()))

#A1～Aiまでの和 O(logN)
def BIT_query(idx):
  res_sum = 0
  while idx > 0:
    res_sum += BIT[idx]
    idx -= idx&(-idx)
  return res_sum
#Ai += x O(logN)
def BIT_update(idx,x):
  while idx <= N:
    BIT[idx] += x
    idx += idx&(-idx)
  return

BIT=[0]*(N+1)
for i in range(N):
  BIT_update(i+1,alist[i])

for _ in range(Q):
  q1,q2,q3=map(int,input().split())
  if q1==0:
    BIT_update(q2,q3)
  else:
    print(BIT_query(q3)-BIT_query(q2))

# Fixed version:
N,Q=map(int,input().split())
alist=list(map(int,input().split()))

#A1～Aiまでの和 O(logN)
def BIT_query(idx):
  res_sum = 0
  while idx > 0:
    res_sum += BIT[idx]
    idx -= idx&(-idx)
  return res_sum
#Ai += x O(logN)
def BIT_update(idx,x):
  while idx <= N:
    BIT[idx] += x
    idx += idx&(-idx)
  return

BIT=[0]*(N+1)
for i in range(N):
  BIT_update(i+1,alist[i])

for _ in range(Q):
  q1,q2,q3=map(int,input().split())
  if q1==0:
    BIT_update(q2+1,q3)
  else:
    print(BIT_query(q3)-BIT_query(q2))

# Buggy version:
import sys


class Bit:
    def __init__(self, n, arr):
        self.size = n
        self.tree = [0] + arr
        for i in range(1, n+1):
            if i + (i & -i) < n+1:
                self.tree[i + (i & -i)] += self.tree[i]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def range_sum(self, l, r):
        return self.sum(r) - self.sum(l)


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n)
    bit.build(map(int, sys.stdin.buffer.readline().split()))
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.range_sum(p, x))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()


# Fixed version:
import sys
import numpy as np


class Bit:
    def __init__(self, n, arr):
        self.size = n
        self.tree = np.array([0] + arr)
        for i in range(1, n+1):
            if i + (i & -i) < n + 1:
                self.tree[i + (i & -i)] += self.tree[i]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def range_sum(self, l, r):
        return self.sum(r) - self.sum(l)


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split())))
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.range_sum(p, x))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()

# Buggy version:
import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    # 使用例
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n+1)
    a = list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(1, n+1):
        bit.add(i, a[i])
    print(bit.tree)
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.sum(x) - bit.sum(p))
        else:
            bit.add(p, x)


if __name__ == "__main__":
    main()


# Fixed version:
import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i ^= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n)
    a = list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(n):
        bit.add(i+1, a[i])
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.sum(x) - bit.sum(p))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()

# Buggy version:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        if x == 0:
            return 0

        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1

    def __repr__(self):
        return str(self._container)


def main():
    N, Q = map(int, readline().split())
    a = list(map(int, readline().split()))
    bit = BinaryIndexTree(N + 1)

    for i, x in enumerate(a, 1):
        bit.add(i, x)

    for _ in range(Q):
        a, b, c = map(int, readline().split())
        if a == 0:
            bit.add(b, c)
        else:
            b += 1
            c += 1
            print(bit.sum(c - 1) - bit.sum(b - 1))


if __name__ == '__main__':
    main()


# Fixed version:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        if x == 0:
            return 0

        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1

    def __repr__(self):
        return str(self._container)


def main():
    N, Q = map(int, readline().split())
    a = list(map(int, readline().split()))
    bit = BinaryIndexTree(N + 1)

    for i, x in enumerate(a, 1):
        bit.add(i, x)

    for _ in range(Q):
        a, b, c = map(int, readline().split())
        if a == 0:
            b += 1
            bit.add(b, c)
        else:
            b += 1
            c += 1
            print(bit.sum(c - 1) - bit.sum(b - 1))


if __name__ == '__main__':
    main()

# Buggy version:
import sys
input = lambda: sys.stdin.readline().rstrip()
NN = 19
BIT = [0] * (2 ** NN + 1)

def addbit(i, x=1):
    while i <= 2**NN:
        BIT[i] += x
        i += i & (-i)

def getsum(i):
    ret = 0
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret

N, Q = map(int, input().split())
A = [int(a) for a in input().split()]
for i, a in enumerate(A):
    addbit(i+1, a)

for _ in range(Q):
    a, b, c = map(int, input().split())
    if a == 0:
        addbit(b, c)
    else:
        print(getsum(c) - getsum(b))

# Fixed version:
import sys
input = lambda: sys.stdin.readline().rstrip()
NN = 19
BIT = [0] * (2 ** NN + 1)

def addbit(i, x=1):
    i += 1
    while i <= 2**NN:
        BIT[i] += x
        i += i & (-i)

def getsum(i):
    ret = 0
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret

N, Q = map(int, input().split())
A = [int(a) for a in input().split()]
for i, a in enumerate(A):
    addbit(i, a)

for _ in range(Q):
    a, b, c = map(int, input().split())
    if a == 0:
        addbit(b, c)
    else:
        print(getsum(c) - getsum(b))