Under construction

Still being built. Things may change

DS Team Selection

Time limit18sMemory limit1024 MB

Summary
Each update adds a square pyramid of weights centered at (x, y), and each query asks for the weight sum over a rectangle modulo 2^30.
Level

Hard9 of 10

Topics
Segment tree, Math, Implementation
Solved
No attempts yet

Problem

The 34th International Olympiad in Data Structures will take place soon. In order to qualify, you need to pass the team selection contest in your country. As a member of the Cat team, you have to solve this problem in the Cat Team Selection contest.

There are infinitely many points with integer coordinates on an infinite plane, each of which can be represented as (x,y)(x, y). Initially, the weights of all points are 00. You need to perform qq operations, each of which takes the form:

  • 1 xx yy dd ww: For all points (X,Y)(X,Y) that satisfy ∣X−x∣<d|X-x| < d and ∣Y−y∣<d|Y-y| < d, increase their point weights by w⋅(d−max⁡(∣X−x∣,∣Y−y∣))w \cdot (d - \max(|X-x|,|Y-y|)).
  • 2 x1x_1 x2x_2 y1y_1 y2y_2: Print the sum of the weights of points (x,y)(x,y) that satisfy x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2. Since the sum can be large, output it modulo 2302^{30}.

Input

The first line contains a single integer mm (1≤m≤1051 \le m \le 10^5), the number of operations.

The next mm lines each contain several integers in one of the following forms:

  • 1 xx yy dd ww (1≤x,y,d,w≤1081 \le x,y,d,w \le 10^8)
  • 2 x1x_1 x2x_2 y1y_1 y2y_2 (1≤x1≤x2≤1081 \le x_1 \le x_2 \le 10^8, 1≤y1≤y2≤1081 \le y_1 \le y_2 \le 10^8)

Output

For each operation of type 2, print a single line containing the requested sum of the weights. Print it modulo 2302^{30}.

Examples1

  1. Example 1

    Input
    4
    1 3 4 5 1
    2 1 4 3 5
    1 2 4 2 2
    2 4 5 3 5
    
    Expected output
    46
    21