Under construction

Still being built. Things may change

Three Dimensions

Time limit1sMemory limit256 MB

Summary
Sum the strange distance d(a,b) over all integer point pairs a and b inside two origin-anchored boxes, output modulo 2^30.
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation, Math
Solved
No attempts yet

Problem

Define a strange distance between two points a=(xa,ya,za)a=(x_a,y_a,z_a) and b=(xb,yb,zb)b=(x_b,y_b,z_b) in three-dimensional space as follows.

d(a,b)=max⁡{∣xa−xb∣,∣ya−yb∣,∣za−zb∣}⊕xa⊕ya⊕za⊕xb⊕yb⊕zb,d(a,b)=\max\{|x_a-x_b|,|y_a-y_b|,|z_a-z_b|\} \oplus x_a \oplus y_a \oplus z_a \oplus x_b \oplus y_b \oplus z_b,

Here max⁡{S}\max\{S\} is the maximum value in SS, ∣x∣|x| is the absolute value of xx, and ⊕\oplus is the bitwise exclusive-or operator.

Given 6 non-negative integers mxa,mya,mza,mxb,myb,mzbmx_a, my_a, mz_a, mx_b, my_b, mz_b, find the sum of d(a,b)d(a,b) over all integer points with xa∈[0,mxa]x_a \in [0, mx_a], ya∈[0,mya]y_a \in [0, my_a], za∈[0,mza]z_a \in [0, mz_a], xb∈[0,mxb]x_b \in [0, mx_b], yb∈[0,myb]y_b \in [0, my_b], and zb∈[0,mzb]z_b \in [0, mz_b]. Since the sum may be very large, output it modulo 2302^{30}.

Input

The input contains 6 non-negative integers mxa,mya,mza,mxb,myb,mzbmx_a, my_a, mz_a, mx_b, my_b, mz_b, each not larger than 10910^9.

Output

Output the sum modulo 2302^{30} as a single integer.

Examples1

  1. Example 1

    Input
    3 2 1 2 1 3
    
    Expected output
    778