Codeforces Beta Round 81
E
Lift and Throw
Codeforces
2500
原题
← D→
翻译中…

You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with $1$ from the end of half-line, i. e. $1$, $2$, $3$ and so on. The distance between the positions is the absolute difference between the respective numbers.

翻译中…

Laharl, Etna and Flonne occupy some positions on the half-line and they want to get to the position with the largest possible number. They are originally placed in different positions.

翻译中…

Each of the characters can perform each of the following actions no more than once:

翻译中…
  • Move a certain distance.
  • Grab another character and lift him above the head.
  • Throw the lifted character a certain distance.
翻译中…

Each character has a movement range parameter. They can only move to free positions, assuming that distance between those positions doesn't exceed the movement range.

翻译中…

One character can lift another character if the distance between the two characters equals $1$, and no one already holds that another character. We can assume that the lifted character moves to the same position as the person who has lifted him, and the position in which he stood before becomes free. A lifted character cannot perform any actions and the character that holds him cannot walk.

翻译中…

Also, each character has a throwing range parameter. It is the distance at which this character can throw the one lifted above his head. He can only throw a character to a free position, and only when there is a lifted character.

翻译中…

We accept the situation when one person grabs another one who in his turn has the third character in his hands. This forms a "column" of three characters. For example, Laharl can hold Etna while Etna holds Flonne. In this case, Etna and the Flonne cannot perform any actions, and Laharl can only throw Etna (together with Flonne) at some distance.

翻译中…

Laharl, Etna and Flonne perform actions in any order. They perform actions in turns, that is no two of them can do actions at the same time.

翻译中…

Determine the maximum number of position at least one of the characters can reach. That is, such maximal number $*x*$ so that one of the characters can reach position $*x*$.

翻译中…

Input

翻译中…

The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between $1$ and $10$, inclusive.

翻译中…

Output

翻译中…

Print a single number — the maximum ordinal number of position which either Laharl, Etna or Flonne can reach.

翻译中…

Note

翻译中…

Let us explain how to reach position $15$ in the sample.

翻译中…

Initially Laharl occupies position $9$, Etna — position $4$ and Flonne — position $2$.

翻译中…

First Laharl moves to position $6$.

翻译中…

Then Flonne moves to position $5$ and grabs Etna.

翻译中…

Laharl grabs Flonne and throws to position $9$.

翻译中…

Flonne throws Etna to position $12$.

翻译中…

Etna moves to position $15$.

翻译中…

样例

Input #1
9 3 3
4 3 1
2 3 3
Output #1
15
InputCopy OutputCopy
题目信息
题号
105E
时间限制
1.5 s
内存限制
256 MB
标签
暴力

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。