Questions O in week 6 (number of equilateral triangles) and edges in week 6

Source: Internet
Author: User

Questions O in week 6 (number of equilateral triangles) and edges in week 6
O-countTime Limit:2000 MSMemory Limit:262144KB64bit IO Format:% I64d & % I64u

Description

Gerald got a very curious hexagon for his birthday. the boy found out that all the angles of the hexagon are equal. then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. there the properties of the hexagon ended and Gerald decided to draw on it.

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 much of them that Gerald lost the track of his counting. help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integersA1, bytes,A2, bytes,A3, bytes,A4, middle,A5 andA6 (1 digit ≤ DigitAILimit ≤ limit 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.

Output

Print a single integer-the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

Sample Input

Input
1 1 1 1 1 1
Output
6
Input
1 2 1 2 1 2
Output
13

Hint

This is what Gerald's hexagon looks like in the first sample:

And that's what it looks like in the second sample:

It is also a mathematical problem. input the length of each side of the hexagonal, draw an equi-edge triangle with the length of one side, count the number of triangles inside the hexagonal, and use the principle of rejection for statistics.

Steal a picture ..

The length of the side entered here is 3 4 2 6 1 5. by filling in a positive triangle, the side length of the positive triangle len is the first three sides a1 + a2 + a3 = 9, the number of triangles with a side length of 1 in this positive triangle is len * len = 81, and then minus the number of triangles with three corners. These three triangles are also normal triangles, therefore, the number of triangles subtracted is 3*3 + 2*2 + 1*1, therefore, the number of triangles with a side length of 1 in the hexagonal format is 81-(3*3 + 2*2 + 1*1) = 67

 

Code:

#include<iostream>using namespace std;int main(){    int a1,a2,a3,a4,a5,a6;    cin>>a1>>a2>>a3>>a4>>a5>>a6;    int len=a1+a2+a3;    cout<<len*len-a1*a1-a3*a3-a5*a5<<endl;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.