He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
1 1 1 1 1 1
6
1 2 1 2 1 2
13
This is what Gerald's hexagon looks like in the first sample:
And that's what it looks like in the second sample:
题解:奇妙的做法。。。窝萌可以把它补成一个正三角形,然后减去三个小正三角形。。。
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<queue> 6 #include<cstring> 7 #define PAU putchar(' ') 8 #define ENT putchar(' ') 9 using namespace std; 10 int A[6]; 11 inline int read(){ 12 int x=0,sig=1;char ch=getchar(); 13 for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=0; 14 for(;isdigit(ch);ch=getchar())x=10*x+ch-'0'; 15 return sig?x:-x; 16 } 17 inline void write(int x){ 18 if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x; 19 int len=0,buf[15];while(x)buf[len++]=x%10,x/=10; 20 for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return; 21 } 22 void init(){ 23 for(int i=0;i<6;i++)A[i]=read(); 24 int L=A[0]+A[1]+A[2];int S=L*L; 25 S-=A[0]*A[0]+A[2]*A[2]+A[4]*A[4]; 26 write(S); 27 return; 28 } 29 void work(){ 30 return; 31 } 32 void print(){ 33 return; 34 } 35 int main(){init();work();print();return 0;}