Problem: 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.

Examples

Input

9 3 3
4 3 1
2 3 3


Output

15

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.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
bool Hash[2000005];
int T, i, a1, a2, a3, b1, b2, b3, c1, c2, c3, ans, aim;
void dfs(int A, int B, int C, int Am, int Bm, int Cm, int As, int Bs, int Cs,
         int Ah, int Bh, int Ch) {
  int hash =
      (((((((((((((((((((A * 45 + B) * 45 + C) * 2 + Am) << 1) + Bm) << 1) + Cm)
                  << 1) +
                 As)
                << 1) +
               Bs)
              << 1) +
             Cs)
            << 2) +
           Ah)
          << 2) +
         Bh)
        << 2) +
       Ch) %
      1000007;
  if (Hash[hash]) return;
  Hash[hash] = true;
  if (A > ans) ans = A;
  if (B > ans) ans = B;
  if (C > ans) ans = C;
  int i;
  if (Am && A != B && A != C) {
    for (i = 1; i <= a2; ++i) {
      if (A + i != B && A + i != C)
        dfs(A + i, B, C, 0, Bm, Cm, As, Bs, Cs, Ah, Bh, Ch);
      if (A - i != B && A - i != C && A >= i)
        dfs(A - i, B, C, 0, Bm, Cm, As, Bs, Cs, Ah, Bh, Ch);
    }
  }
  if (Bm && B != A && B != C) {
    for (i = 1; i <= b2; ++i) {
      if (B + i != A && B + i != C)
        dfs(A, B + i, C, Am, 0, Cm, As, Bs, Cs, Ah, Bh, Ch);
      if (B - i != A && B - i != C && B >= i)
        dfs(A, B - i, C, Am, 0, Cm, As, Bs, Cs, Ah, Bh, Ch);
    }
  }
  if (Cm && C != A && C != B) {
    for (i = 1; i <= c2; ++i) {
      if (C + i != A && C + i != B)
        dfs(A, B, C + i, Am, Bm, 0, As, Bs, Cs, Ah, Bh, Ch);
      if (C - i != A && C - i != B && C >= i)
        dfs(A, B, C - i, Am, Bm, 0, As, Bs, Cs, Ah, Bh, Ch);
    }
  }
  if (As && Bh != 1 && Ch != 1) {
    if (Ah) {
      for (i = 1; i <= a3; ++i) {
        if (Ah == 2) {
          if (A + i != C) {
            if (Bh)
              dfs(A, A + i, A + i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
            else
              dfs(A, A + i, C, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
          }
          if (A - i != C && A - i >= 0) {
            if (Bh)
              dfs(A, A - i, A - i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
            else
              dfs(A, A - i, C, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
          }
        } else {
          if (A + i != B) {
            if (Ch)
              dfs(A, A + i, A + i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
            else
              dfs(A, B, A + i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
          }
          if (A - i != B && A - i >= 0) {
            if (Ch)
              dfs(A, A - i, A - i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
            else
              dfs(A, B, A - i, Am, Bm, Cm, 0, Bs, Cs, 0, Bh, Ch);
          }
        }
      }
    } else {
      if ((B == A - 1 || B == A + 1) && Ch != 2) {
        if (Bh)
          dfs(A, A, A, Am, Bm, Cm, As, Bs, Cs, 2, Bh, Ch);
        else
          dfs(A, A, C, Am, Bm, Cm, As, Bs, Cs, 2, Bh, Ch);
      }
      if ((C == A - 1 || C == A + 1) && Bh != 3) {
        if (Ch)
          dfs(A, A, A, Am, Bm, Cm, As, Bs, Cs, 3, Bh, Ch);
        else
          dfs(A, B, A, Am, Bm, Cm, As, Bs, Cs, 3, Bh, Ch);
      }
    }
  }
  if (Bs && Ah != 2 && Ch != 2) {
    if (Bh) {
      for (i = 1; i <= b3; ++i) {
        if (Bh == 1) {
          if (B + i != C) {
            if (Ah)
              dfs(B + i, B, B + i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
            else
              dfs(B + i, B, C, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
          }
          if (B - i != C && B - i >= 0) {
            if (Ah)
              dfs(B - i, B, B - i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
            else
              dfs(B - i, B, C, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
          }
        } else {
          if (B + i != A) {
            if (Ch)
              dfs(B + i, B, B + i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
            else
              dfs(A, B, B + i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
          }
          if (B - i != A && B - i >= 0) {
            if (Ch)
              dfs(B - i, B, B - i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
            else
              dfs(A, B, B - i, Am, Bm, Cm, As, 0, Cs, Ah, 0, Ch);
          }
        }
      }
    } else {
      if ((A == B - 1 || A == B + 1) && Ch != 1) {
        if (Ah)
          dfs(B, B, B, Am, Bm, Cm, As, Bs, Cs, Ah, 1, Ch);
        else
          dfs(B, B, C, Am, Bm, Cm, As, Bs, Cs, Ah, 1, Ch);
      }
      if ((C == B - 1 || C == B + 1) && Ah != 3) {
        if (Ch)
          dfs(B, B, B, Am, Bm, Cm, As, Bs, Cs, Ah, 3, Ch);
        else
          dfs(A, B, B, Am, Bm, Cm, As, Bs, Cs, Ah, 3, Ch);
      }
    }
  }
  if (Cs && Ah != 3 && Bh != 3) {
    if (Ch) {
      for (i = 1; i <= c3; ++i) {
        if (Ch == 1) {
          if (C + i != B) {
            if (Ah)
              dfs(C + i, C + i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
            else
              dfs(C + i, B, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
          }
          if (C - i != B && C - i >= 0) {
            if (Ah)
              dfs(C - i, C - i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
            else
              dfs(C - i, B, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
          }
        } else {
          if (C + i != A) {
            if (Bh)
              dfs(C + i, C + i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
            else
              dfs(A, C + i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
          }
          if (C - i != A && C - i >= 0) {
            if (Bh)
              dfs(C - i, C - i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
            else
              dfs(A, C - i, C, Am, Bm, Cm, As, Bs, 0, Ah, Bh, 0);
          }
        }
      }
    } else {
      if ((A == C - 1 || A == C + 1) && Bh != 1) {
        if (Ah)
          dfs(C, C, C, Am, Bm, Cm, As, Bs, Cs, Ah, Bh, 1);
        else
          dfs(C, B, C, Am, Bm, Cm, As, Bs, Cs, Ah, Bh, 1);
      }
      if ((B == C - 1 || B == C + 1) && Ah != 2) {
        if (Bh)
          dfs(C, C, C, Am, Bm, Cm, As, Bs, Cs, Ah, Bh, 2);
        else
          dfs(A, C, C, Am, Bm, Cm, As, Bs, Cs, Ah, Bh, 2);
      }
    }
  }
}
int main() {
  while (scanf("%d%d%d%d%d%d%d%d%d", &a1, &a2, &a3, &b1, &b2, &b3, &c1, &c2,
               &c3) != EOF) {
    for (i = 0; i <= 1000007; ++i) Hash[i] = false;
    ans = 0;
    a1 += 2;
    b1 += 2;
    c1 += 2;
    dfs(a1, b1, c1, 1, 1, 1, 1, 1, 1, 0, 0, 0);
    printf("%d\n", ans - 2);
  }
}