Question of the week O (number of equilateral triangle)

Source: Internet
Author: User

OCountTime limit:2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i64u

Description

Gerald got a very curious hexagon for his birthday. The boy found the angles of the hexagon is equal to . Then he measured the length of their sides, and found that each of the them are 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 had got. But there were so many of them, Gerald lost the track of he counting. Help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integers a1, a2, C6>a3, a4, a5 and a6 (1≤ a i ≤1000)-the lengths of the sides of the hexagons in the centimeters order. It is guaranteed , 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, to 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's it looks like in the second sample:

The problem is a mathematical question, the length of each side of the input hexagon, and then the edge length of 1 draw equilateral triangle, statistics of the number of hexagon internal triangles, statistical use of the principle of tolerance.

Steal a picture.

Here the input of the side length is 3 4 2 6 1 5, through the fill to a positive triangle, the triangle of side length Len is the first three edge a1+a2+a3=9, the triangle containing the edge length of 1 is the number of triangles is len*len=81, and then subtract three corners of the number of triangles can be, These three triangles are also positive triangles, so the number of triangles subtracted is 3*3+2*2+1*1, so the hexagon contains 1 triangles with a length of 81-(3*3+2*2+1*1) =67

Code:

#include <iostream>usingnamespace  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;}

Question of the week O (number of equilateral triangle)

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.