Knight's Shield
Time limit2sMemory limit512 MB
Two triangles are glued along a common side; find the minimum possible perimeter of the resulting shape.
- Level
Medium5 of 10
- Topics
- Geometry, Brute force, Math, Implementation
- Solved
- No attempts yet
Statement
After spending a couple of weeks with the Dark Lord and hearing stories of all his adventures over the past years, Sir Petrein realized that he had not performed any feats for a long time. Over a cup of tea, they carefully discussed the feat ahead and decided that Petrein should defeat the terrible dragon that had long been terrorizing the western outskirts of the Personal Kingdom. So he set off to prepare for the great campaign.
But what knight goes against a dragon without a knight's equipment? Petrein needs armor, a shield, and a sword. Everyone knows that the larger the shield, the more effective it is in battle. Petrein currently has two triangular shields, but he considers them insufficiently reliable and wants to make one out of them.
The royal armorer who took on the job of making the shield proposed the following method: the two existing shields are placed side by side so that they touch along a side and are fixed in that position. Sir Petrein noticed that no matter how the armorer tried, the resulting shield always has the same area, which means its effectiveness in battle with the dragon depends only on which shields Petrein gave the armorer, and not on how they are fastened together.
But he needs not just a piece of metal, but a shield bearing the emblem of his family: a golden border along the perimeter. Gold is expensive now, so Petrein wants the perimeter of the resulting shield to be as small as possible. Help him find out what minimum perimeter the shield can have.
Input
The first line contains three numbers , , and , the side lengths of the first shield. The second line contains three numbers , , and , the side lengths of the second shield. Both lines define valid nondegenerate triangles. All numbers in the input file do not exceed .
Output
Output a single number: the minimum perimeter of a shield that can be made from them by the described method.