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;
struct Player {
  int X, Y, P, Walk, Throw;
};
bool operator>(Player A, Player B) { return A.Y > B.Y; }
int Ans = 0;
int W0, W1, W2, T0, T1, T2;
set<int> Set;
int V(Player A) { return (A.X - 1) * 24 + A.Y * 8 + A.P; }
int Calculate(Player A, Player B, Player C) {
  Player D, E, F;
  if (A.Walk == W0 && A.Throw == T0 && B.Walk == W1 && B.Throw == T1 &&
      C.Walk == W2 && C.Throw == T2) {
    D = A;
    E = B;
    F = C;
  }
  if (A.Walk == W0 && A.Throw == T0 && C.Walk == W1 && C.Throw == T1 &&
      B.Walk == W2 && B.Throw == T2) {
    D = A;
    E = C;
    F = B;
  }
  if (B.Walk == W0 && B.Throw == T0 && A.Walk == W1 && A.Throw == T1 &&
      C.Walk == W2 && C.Throw == T2) {
    D = B;
    E = A;
    F = C;
  }
  if (B.Walk == W0 && B.Throw == T0 && C.Walk == W1 && C.Throw == T1 &&
      A.Walk == W2 && A.Throw == T2) {
    D = B;
    E = C;
    F = A;
  }
  if (C.Walk == W0 && C.Throw == T0 && A.Walk == W1 && A.Throw == T1 &&
      B.Walk == W2 && B.Throw == T2) {
    D = C;
    E = A;
    F = B;
  }
  if (C.Walk == W0 && C.Throw == T0 && B.Walk == W1 && B.Throw == T1 &&
      A.Walk == W2 && A.Throw == T2) {
    D = C;
    E = B;
    F = A;
  }
  return V(D) * 1440000 + V(E) * 1200 + V(F);
}
void DFS(Player A, Player B, Player C) {
  Ans = max(Ans, A.X);
  Ans = max(Ans, B.X);
  Ans = max(Ans, C.X);
  if (!A.P && !B.P && !C.P) return;
  if (A > B) swap(A, B);
  if (A > C) swap(A, C);
  if (B > C) swap(B, C);
  int Tmp = Calculate(A, B, C);
  if (Set.count(Tmp)) return;
  Set.insert(Tmp);
  if (A.Y == 0 && B.Y == 1 && C.Y == 2 && (A.P & 4))
    for (int i = max(A.X - A.Throw, 1); i <= A.X + A.Throw; i++)
      if (i != A.X) {
        Player D = A, E = B, F = C;
        D.P ^= 4;
        E.X = F.X = i;
        E.Y = 0;
        F.Y = 1;
        DFS(D, E, F);
      }
  if (A.Y == 0 && B.Y == 0 && C.Y == 1) {
    if (A.X == C.X) swap(A, B);
    if (A.P & 1)
      for (int i = max(A.X - A.Walk, 1); i <= A.X + A.Walk; i++)
        if (i != B.X) {
          Player D = A, E = B, F = C;
          D.P ^= 1;
          D.X = i;
          DFS(D, E, F);
        }
    if ((A.P & 2) && abs(A.X - B.X) == 1) {
      Player D = A, E = B, F = C;
      D.P ^= 2;
      E.X = F.X = A.X;
      E.Y = 1;
      F.Y = 2;
      DFS(D, E, F);
    }
    if (B.P & 4)
      for (int i = max(B.X - B.Throw, 1); i <= B.X + B.Throw; i++)
        if (i != A.X && i != B.X) {
          Player D = A, E = B, F = C;
          E.P ^= 4;
          F.X = i;
          F.Y = 0;
          DFS(D, E, F);
        }
  }
  if (A.Y == 0 && B.Y == 0 && C.Y == 0) {
    if (A.P & 1)
      for (int i = max(A.X - A.Walk, 1); i <= A.X + A.Walk; i++)
        if (i != B.X && i != C.X) {
          Player D = A, E = B, F = C;
          D.P ^= 1;
          D.X = i;
          DFS(D, E, F);
        }
    if (B.P & 1)
      for (int i = max(B.X - B.Walk, 1); i <= B.X + B.Walk; i++)
        if (i != A.X && i != C.X) {
          Player D = A, E = B, F = C;
          E.P ^= 1;
          E.X = i;
          DFS(D, E, F);
        }
    if (C.P & 1)
      for (int i = max(C.X - C.Walk, 1); i <= C.X + C.Walk; i++)
        if (i != A.X && i != B.X) {
          Player D = A, E = B, F = C;
          F.P ^= 1;
          F.X = i;
          DFS(D, E, F);
        }
    if (abs(A.X - B.X) == 1) {
      if (A.P & 2) {
        Player D = A, E = B, F = C;
        D.P ^= 2;
        E.X = D.X;
        E.Y = 1;
        DFS(D, E, F);
      }
      if (B.P & 2) {
        Player D = A, E = B, F = C;
        E.P ^= 2;
        D.X = E.X;
        D.Y = 1;
        DFS(D, E, F);
      }
    }
    if (abs(A.X - C.X) == 1) {
      if (A.P & 2) {
        Player D = A, E = B, F = C;
        D.P ^= 2;
        F.X = D.X;
        F.Y = 1;
        DFS(D, E, F);
      }
      if (C.P & 2) {
        Player D = A, E = B, F = C;
        F.P ^= 2;
        D.X = F.X;
        D.Y = 1;
        DFS(D, E, F);
      }
    }
    if (abs(B.X - C.X) == 1) {
      if (B.P & 2) {
        Player D = A, E = B, F = C;
        E.P ^= 2;
        F.X = E.X;
        F.Y = 1;
        DFS(D, E, F);
      }
      if (C.P & 2) {
        Player D = A, E = B, F = C;
        F.P ^= 2;
        E.X = F.X;
        E.Y = 1;
        DFS(D, E, F);
      }
    }
  }
}
int main() {
  Player A;
  cin >> A.X >> A.Walk >> A.Throw;
  A.Y = 0;
  A.P = 7;
  W0 = A.Walk;
  T0 = A.Throw;
  Player B;
  cin >> B.X >> B.Walk >> B.Throw;
  B.Y = 0;
  B.P = 7;
  W1 = B.Walk;
  T1 = B.Throw;
  Player C;
  cin >> C.X >> C.Walk >> C.Throw;
  C.Y = 0;
  C.P = 7;
  W2 = C.Walk;
  T2 = C.Throw;
  DFS(A, B, C);
  cout << Ans << endl;
  return 0;
}