#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 2e5 + 5;
const long long limit1 = 1e6 + 5;
const long long limit2 = 1e3 + 5;
string s;
string s1, s2;
long long a[limit];
bool check[limit];
long long ans = maxN;
long long t2, t3, t, t1;
bool ok = false;
void process() {
  t = t2, t1 = t3;
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 1) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 1LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 2) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 2LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 3) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 3LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 4) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 4LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 5) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 5LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 6) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 6LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
}
void backtrack(long long i) {
  for (int j = (1); j <= (6); ++j) {
    if (!check[j]) {
      a[i] = j;
      check[j] = true;
      if (i == 6)
        process();
      else
        backtrack(i + 1);
      check[j] = false;
    }
  }
}
void solveProblem() {
  t = s[0] - '0' + s[1] - '0' + s[2] - '0';
  t1 = s[3] - '0' + s[4] - '0' + s[5] - '0';
  s1 = "", s2 = "";
  for (int i = (0); i < (3); ++i) s1 += s[i], s2 += s[i + 3];
  if (t == t1) {
    cout << 0 << '\n';
    return;
  }
  if (t < t1) ok = true;
  t2 = t, t3 = t1;
  backtrack(1);
  cout << ans << '\n';
}
void fastInput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void readInput() { cin >> s; }
int main() {
  fastInput();
  readInput();
  solveProblem();
}

### Prompt

Generate a CPP solution to the following problem:

Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.

The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

Input

You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

Output

Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

Examples

Input

000000


Output

0


Input

123456


Output

2


Input

111000


Output

1

Note

In the first example the ticket is already lucky, so the answer is 0.

In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.

In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 2e5 + 5;
const long long limit1 = 1e6 + 5;
const long long limit2 = 1e3 + 5;
string s;
string s1, s2;
long long a[limit];
bool check[limit];
long long ans = maxN;
long long t2, t3, t, t1;
bool ok = false;
void process() {
  t = t2, t1 = t3;
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 1) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 1LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 2) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 2LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 3) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 3LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 4) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 4LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 5) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 5LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 6) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 6LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
}
void backtrack(long long i) {
  for (int j = (1); j <= (6); ++j) {
    if (!check[j]) {
      a[i] = j;
      check[j] = true;
      if (i == 6)
        process();
      else
        backtrack(i + 1);
      check[j] = false;
    }
  }
}
void solveProblem() {
  t = s[0] - '0' + s[1] - '0' + s[2] - '0';
  t1 = s[3] - '0' + s[4] - '0' + s[5] - '0';
  s1 = "", s2 = "";
  for (int i = (0); i < (3); ++i) s1 += s[i], s2 += s[i + 3];
  if (t == t1) {
    cout << 0 << '\n';
    return;
  }
  if (t < t1) ok = true;
  t2 = t, t3 = t1;
  backtrack(1);
  cout << ans << '\n';
}
void fastInput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void readInput() { cin >> s; }
int main() {
  fastInput();
  readInput();
  solveProblem();
}

```