Problem:
Range Add Query (RAQ)

Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:

add(s, t, x): add x to as, as+1, ..., at.

get(i): output the value of ai.

Note that the initial values of ai (i = 1, 2, . . . , n) are 0.

Input

n q
query1
query2
:
queryq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:

0 s t x

or

1 t

The first digit represents the type of the query. '0' denotes add(s, t, x) and '1' denotes get(i).

Output

For each get operation, print the value.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

1 ≤ s ≤ t ≤ n

1 ≤ i ≤ n

0 ≤ x ≤ 1000

Sample Input 1

3 5
0 1 2 1
0 2 3 2
0 3 3 3
1 2
1 3

Sample Output 1

3
5

Sample Input 2

4 3
1 2
0 1 4 1
1 2

Sample Output 2

0
1

Solution in Ruby (judge verdict: Accepted)

class LazySegmentTree
  attr_reader :n, :dat, :lazy

  # @param [Integer] len 区間の長さ
  def initialize(len)
    @n = 1

    @n *= 2 while @n < len
    @dat = Array.new(2 * @n - 1, 0)
    @lazy = Array.new(2 * @n - 1, 0)
  end

  # @param [Integer] l 更新範囲の左端
  # @param [Integer] r 更新範囲の右端
  # @param [Integer] x 更新する値
  def update(l, r, x)
    add(l, r, x, 0, 0, n - 1)
  end

  # @param [Integer] idx 取得したい値の箇所
  def find(idx)
    sum(idx, idx, 0, 0, n - 1)
  end

  def sum(a, b, idx, l, r)
    return 0 if r < a || b < l

    evaluate(idx, l, r)

    if a <= l && r <= b
      dat[idx]
    else
      vl = sum(a, b, idx * 2 + 1, l, (l + r) / 2)
      vr = sum(a, b, idx * 2 + 2, (l + r) / 2 + 1, r)

      vl + vr
    end
  end

  private

  # @param [Integer] a 探索範囲の左端
  # @param [Integer] b 探索範囲の右端
  # @param [Integer] x 更新する値
  # @param [Integer] idx 現在位置
  # @param [Integer] l 現在の探索範囲の左端
  # @param [Integer] r 現在の探索範囲の右端
  def add(a, b, x, idx, l, r)
    return if r < a || b < l

    if a <= l && r <= b
      @lazy[idx] += (r - l + 1) * x
      evaluate(idx, l, r)
    else
      add(a, b, x, idx * 2 + 1, l, (l + r) / 2)
      add(a, b, x, idx * 2 + 2, (l + r) / 2 + 1, r)
      @dat[idx] = dat[2 * idx + 1] + dat[2 * idx + 2]
    end
  end

  def evaluate(idx, l, r)
    return if lazy[idx] == 0

    @dat[idx] += lazy[idx]

    if r - l > 0
      @lazy[2 * idx + 1] += lazy[idx] / 2
      @lazy[2 * idx + 2] += lazy[idx] / 2
    end

    lazy[idx] = 0
  end
end

N, Q = gets.split.map(&:to_i)
lst = LazySegmentTree.new(N + 1)

Q.times do
  query = gets.split.map(&:to_i)

  if query.first == 0
    _, s, t, x = *query
    lst.update(s, t, x)
  else
    _, i = *query
    puts lst.find(i)
  end
end