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;
int dp[45][45][45][8][4][4][4];
int init[3], thr[3], walk[3];
queue<int> pos1, pos2, pos3, stat1, stat2, stat3, stat;
int p1, p2, p3, s1, s2, s3, sp;
int pt1, pt2, pt3, st1, st2, st3, stp;
int ans;
inline void refresh() {
  pt1 = p1;
  pt2 = p2;
  pt3 = p3;
  stp = sp;
  st1 = s1;
  st2 = s2;
  st3 = s3;
}
inline void input() {
  if (dp[pt1][pt2][pt3][stp][st1][st2][st3] == 0) {
    dp[pt1][pt2][pt3][stp][st1][st2][st3] = 1;
    pos1.push(pt1);
    pos2.push(pt2);
    pos3.push(pt3);
    stat.push(stp);
    stat1.push(st1);
    stat2.push(st2);
    stat3.push(st3);
  }
}
inline void wal() {
  if ((sp & 1) == 0 && (s1 == 0 || s1 == 3) && s2 != 1 && s3 != 1) {
    stp = sp + 1;
    for (int i = -walk[0]; i <= walk[0]; i++) {
      pt1 = p1 + i;
      if (pt1 > 0 && pt1 != pt2 && pt1 != pt3) {
        input();
      }
    }
    pt1 = p1;
    stp = sp;
  }
  if ((sp & 2) == 0 && (s2 == 0 || s2 == 3) && s1 != 1 && s3 != 2) {
    stp = sp + 2;
    for (int i = -walk[1]; i <= walk[1]; i++) {
      pt2 = p2 + i;
      if (pt2 > 0 && pt1 != pt2 && pt2 != pt3) {
        input();
      }
    }
    pt2 = p2;
    stp = sp;
  }
  if ((sp & 4) == 0 && (s3 == 0 || s3 == 3) && s2 != 2 && s1 != 2) {
    stp = sp + 4;
    for (int i = -walk[2]; i <= walk[2]; i++) {
      pt3 = p3 + i;
      if (pt3 > 0 && pt3 != pt2 && pt1 != pt3) {
        input();
      }
    }
    pt3 = p3;
    stp = sp;
  }
}
inline void jump() {
  if (s1 == 0 && s2 != 1 && s3 != 1) {
    if ((p2 - p1 == 1 || p1 - p2 == 1) && s3 != 2) {
      pt2 = p1;
      st1 = 1;
      if (s2 == 2) {
        pt3 = p1;
      }
      input();
    }
    refresh();
    if ((p3 - p1 == 1 || p1 - p3 == 1) && s2 != 2) {
      pt3 = p1;
      st1 = 2;
      if (s3 == 2) {
        pt2 = p1;
      }
      input();
    }
    refresh();
  }
  if (s2 == 0 && s1 != 1 && s3 != 2) {
    if ((p2 - p1 == 1 || p1 - p2 == 1) && s3 != 1) {
      pt1 = p2;
      st2 = 1;
      if (s1 == 2) {
        pt3 = p2;
      }
      input();
    }
    refresh();
    if ((p3 - p2 == 1 || p2 - p3 == 1) && s1 != 2) {
      pt3 = p2;
      st2 = 2;
      if (s3 == 2) {
        pt1 = p2;
      }
      input();
    }
    refresh();
  }
  if (s3 == 0 && s1 != 2 && s2 != 2) {
    if ((p3 - p1 == 1 || p1 - p3 == 1) && s2 != 1) {
      pt1 = p3;
      st3 = 1;
      if (s1 == 1) {
        pt2 = p3;
      }
      input();
    }
    refresh();
    if ((p3 - p2 == 1 || p2 - p3 == 1) && s1 != 2) {
      pt2 = p3;
      st3 = 2;
      if (s2 == 1) {
        pt1 = p3;
      }
      input();
    }
    refresh();
  }
}
inline void thro() {
  if (s1 == 1) {
    st1 = 3;
    if (s2 == 2) {
      for (int i = -thr[0]; i <= thr[0]; i++) {
        pt2 = p1 + i;
        pt3 = pt2;
        if (pt2 > 0) input();
      }
    } else {
      for (int i = -thr[0]; i <= thr[0]; i++) {
        pt2 = p1 + i;
        if (pt2 > 0 && pt2 != p3) input();
      }
    }
    refresh();
  }
  if (s1 == 2) {
    st1 = 3;
    if (s3 == 2) {
      for (int i = -thr[0]; i <= thr[0]; i++) {
        pt2 = p1 + i;
        pt3 = pt2;
        if (pt2 > 0) input();
      }
    } else {
      for (int i = -thr[0]; i <= thr[0]; i++) {
        pt3 = p1 + i;
        if (pt3 > 0 && pt3 != p2) input();
      }
    }
    refresh();
  }
  if (s2 == 1) {
    st2 = 3;
    if (s1 == 2) {
      for (int i = -thr[1]; i <= thr[1]; i++) {
        pt1 = p2 + i;
        pt3 = pt1;
        if (pt1 > 0) input();
      }
    } else {
      for (int i = -thr[1]; i <= thr[1]; i++) {
        pt1 = p2 + i;
        if (pt1 > 0 && pt1 != p3) input();
      }
    }
    refresh();
  }
  if (s2 == 2) {
    st2 = 3;
    if (s3 == 1) {
      for (int i = -thr[1]; i <= thr[1]; i++) {
        pt1 = p2 + i;
        pt3 = pt1;
        if (pt1 > 0) input();
      }
    } else {
      for (int i = -thr[1]; i <= thr[1]; i++) {
        pt3 = p2 + i;
        if (pt3 > 0 && pt3 != p1) input();
      }
    }
    refresh();
  }
  if (s3 == 1) {
    st3 = 3;
    if (s1 == 1) {
      for (int i = -thr[2]; i <= thr[2]; i++) {
        pt1 = p3 + i;
        pt2 = pt1;
        if (pt2 > 0) input();
      }
    } else {
      for (int i = -thr[2]; i <= thr[2]; i++) {
        pt1 = p3 + i;
        if (pt1 > 0 && pt1 != p2) input();
      }
    }
    refresh();
  }
  if (s3 == 2) {
    st3 = 3;
    if (s2 == 1) {
      for (int i = -thr[2]; i <= thr[2]; i++) {
        pt2 = p3 + i;
        pt1 = pt2;
        if (pt2 > 0) input();
      }
    } else {
      for (int i = -thr[2]; i <= thr[2]; i++) {
        pt2 = p3 + i;
        if (pt2 > 0 && pt2 != p1) input();
      }
    }
    refresh();
  }
}
inline void bfs() {
  pos1.push(init[0]);
  pos2.push(init[1]);
  pos3.push(init[2]);
  stat.push(0);
  stat1.push(0);
  stat2.push(0);
  stat3.push(0);
  dp[init[0]][init[1]][init[2]][0][0][0][0] = 1;
  while (!pos1.empty()) {
    p1 = pos1.front();
    pos1.pop();
    pt1 = p1;
    p2 = pos2.front();
    pos2.pop();
    pt2 = p2;
    p3 = pos3.front();
    pos3.pop();
    pt3 = p3;
    ans = max(ans, max(p1, max(p2, p3)));
    s1 = stat1.front();
    stat1.pop();
    st1 = s1;
    s2 = stat2.front();
    stat2.pop();
    st2 = s2;
    s3 = stat3.front();
    stat3.pop();
    st3 = s3;
    sp = stat.front();
    stat.pop();
    stp = sp;
    wal();
    jump();
    thro();
  }
}
int main() {
  scanf("%d %d %d", &init[0], &walk[0], &thr[0]);
  scanf("%d %d %d", &init[1], &walk[1], &thr[1]);
  scanf("%d %d %d", &init[2], &walk[2], &thr[2]);
  bfs();
  printf("%d\n", ans);
  return 0;
}