Triple | 프로그래밍의 벗 PivotOJ
PivotOJ

Triple

시간 제한: 2000ms메모리 제한: 1024MB출처: NOI 2000BOJ 9923

문제

An ordered triple of ordered pairs is written as <(a,b),(c,d),(e,f)><(a,b), (c,d), (e,f)>.

Rule 1.  A triple vanishes if two of its three ordered pairs are identical. That is

<(a,b),(a,b),(a,b)>=0<(a,b),(a,b),(e,f)>=0<(a,b),(c,d),(a,b)>=0<(a,b),(c,d),(c,d)>=0\begin{align*}< (a,b), (a,b), (a,b) > = 0 \\ < (a,b), (a,b), (e,f) > = 0 \\ < (a,b), (c,d), (a,b) > = 0 \\ < (a,b), (c,d), (c,d) > = 0 \end{align*}

A triple that vanishes is called a zero triple.

Rule 2.  Two triples differ in sign if one can be transformed to another with an odd number of adjacent swaps.  Two triples are equal if one can be transformed to another with an even number of adjacent swaps.  Let “\rightarrow” mean the operation of adjacent swap.  Since

<(1,2),(3,4),(5,6)><(1,2), (3,4), (5,6)> \downarrow <(3,4),(1,2),(5,6)><(3,4),(1,2),(5,6)> \downarrow <(3,4),(5,6),(1,2)><(3,4),(5,6),(1,2)> \downarrow <(5,6),(3,4),(1,2)><(5,6),(3,4),(1,2)> \downarrow <(5,6),(1,2),(3,4)><(5,6),(1,2),(3,4)> \downarrow <(1,2),(5,6),(3,4)><(1,2),(5,6),(3,4)>

we have

<(1,2),(3,4),(5,6)=<(3,4),(1,2),(5,6)>=<(3,4),(5,6),(1,2)>=<(5,6),(3,4),(1,2)>=<(5,6),(1,2),(3,4)>=<(1,2),(5,6),(3,4)>\begin{align*} <(1,2),(3,4),(5,6) & = -<(3,4), (1,2), (5,6)> \\ & = <(3,4), (5,6), (1,2)> \\ & = -<(5,6), (3,4), (1,2)> \\ & = <(5,6), (1, 2), (3,4)> \\ & = -<(1,2), (5,6), (3,4)>\end{align*}

Consider summing all the triples <(a,b),(c,d),(e,f)>< (a,b), (c,d), (e,f) > where

a_1 &le; a &le; a_2 , b_1 &le; b &le; b_2; \, c_1 &le; c &le; c_2 , d_1 &le; d &le; d_2 ; \, e_1 &le; e &le; e_2 , f_1 &le; f &le; f_2 \text{.}

and all the values are integers.  After discarding zero triples (Rule 1) and cancelling pairs of triples that differ in sign (Rule 2), you are to determine the number of distinct non-zero triples in the sum.

Example 1.  Let 1 &le; a &le; 1, 2 &le; b &le; 2, 3 &le; c &le; 3, 4 &le; d &le; 4, 5 &le; e &le; 5, 6 &le; f &le; 8.  There are only 33 triples in these ranges and none is zero and no two differ in sign, so there are 33 distinct non-zero triples if we sum them:

<(1,2),(3,4),(5,6)>+<(1,2),(3,4),(5,7)>+<(1,2),(3,4),(5,8)>.< (1,2), (3,4), (5,6) > + < (1,2), (3,4), (5,7) > + < (1,2), (3,4), (5,8) > \text{.}

Example 2.  Now consider 1 &le; a &le; 1, 2 &le; b &le; 2, 4 &le; c &le; 5, 7 &le; d &le; 8, 5 &le; e &le; 5, 6 &le; f &le; 8.  There are 1212 triples in these ranges.  The 22 triples <(1,2),(5,7),(5,7)>< (1,2),(5,7),(5,7) > and <(1,2),(5,8),(5,8)>< (1,2), (5,8), (5,8) > are zero by Rule 1.  The 22 triples <(1,2),(5,7),(5,8)>< (1,2),(5,7),(5,8) > and <(1,2),(5,8),(5,7)>< (1,2), (5,8), (5,7) > cancel each other (they sum to zero) by Rule 2.  Thus the sum of the original 1212 triples has 88 distinct non-zero triples:

<(1,2),(4,7),(5,6)>+<(1,2),(4,7),(5,7)>+<(1,2),(4,7),(5,8)>+< (1,2), (4,7), (5,6) > + < (1,2), (4,7), (5,7) > + < (1,2), (4,7), (5,8) > + <(1,2),(4,8),(5,6)>+<(1,2),(4,8),(5,7)>+<(1,2),(4,8),(5,8)>+< (1,2), (4,8), (5,6) > + < (1,2), (4,8), (5,7) > + < (1,2), (4,8), (5,8) > + <(1,2),(5,7),(5,6)>+<(1,2),(5,8),(5,6)>.< (1,2), (5,7), (5,6) > + < (1,2), (5,8), (5,6) > \text{.}

Example 3.  Let the ranges be 0 &le; a &le; 0, 0 &le; b &le; 0, 0 &le; c &le; 0, 0 &le; d &le; 1, 0 &le; e &le; 1, 0 &le; f &le; 1.  The six triples

<(0,0),(0,0),(0,0)>,<(0,0),(0,0),(0,1)>,<(0,0),(0,0),(1,0)>,< (0,0), (0,0), (0,0) >, < (0,0), (0,0), (0,1) >, < (0,0), (0,0), (1,0) >, <(0,0),(0,0),(1,1)>,<(0,0),(0,1),(0,0)>,<(0,0),(0,1),(0,1)>< (0,0), (0,0), (1,1) >, < (0,0), (0,1), (0,0) >, < (0,0), (0,1), (0,1) >

are zero by Rule 1.  Thus the sum of the original eight triples has 22 distinct non-zero triples:

<(0,0),(0,1),(1,0)>+<(0,0),(0,1),(1,1)>< (0,0), (0,1), (1,0) > + < (0,0), (0,1), (1,1) >

  1. Read the input to obtain the ranges of aa, bb, cc, dd, ee, ff.  For each of aa, bb, cc, dd, ee, ff, the lowest value is 00 and the highest value is 100100.
  2. Sum all the triples <(a,b),(c,d),(e,f)>< (a,b), (c,d), (e,f) > within the given ranges using Rule 1 and Rule 2.  Determine the number of non-zero distinct triples in the sum.  This number is between 00 and 10001000 inclusively.
  3. Write the number of non-zero distinct triples in the sum to the output.

입력

The input contains 1212 integers (there is a space between two adjacent integers) for the ranges on a single line.  The integers are given in the order of a1a2b1b2c1c2d1d2e1e2f1f2 a_1 \, a_2 \, b_1 \, b_2 \, c_1 \, c_2 \, d_1 \, d_2 \, e_1 \, e_2 \, f_1 \, f_2

출력

The output contains one integer which is the number of non-zero distinct triples in the sum of the original triples within the given ranges.

예제

예제 1

입력
1 1 2 2 3 3 4 4 5 5 6 8
출력
3

예제 2

입력
1 1 2 2 4 5 7 8 5 5 6 8
출력
8

예제 3

입력
0 0 0 0 0 0 0 1 0 1 0 1
출력
2
코드를 제출하려면 로그인하세요.