#include <bits/stdc++.h>
int compare(const void *a, const void *b) {
  if (*(long long *)a > *(long long *)b) return 1;
  return -1;
}
long long Max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long Min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
int main() {
  int i, n;
  char s[100001];
  scanf("%s", s);
  int l = strlen(s);
  int a[100001] = {0}, j = 0;
  a[0] = 1;
  int b = s[0] - '0';
  for (i = 1; i < l; i++) {
    if (s[i] == s[i - 1]) {
      a[j]++;
    } else {
      j++;
      a[j]++;
    }
  }
  long long ans = 0;
  if (j == 1) {
    printf("%d", Min(a[0], a[1]));
    return 0;
  }
  i = 0;
  int flag = 0;
  while (1) {
    flag = 0;
    while (a[i] == 0 && i + 1 <= j) {
      i++;
    }
    int k = i + 1;
    while (a[k] == 0 && k + 2 <= j) {
      if (a[k + 1] > 0)
        k += 2;
      else
        break;
    }
    if (k + 2 <= j && a[i] > 0 && a[k] > 0) {
      ans += Min(a[k], a[i]) * 2;
      a[i] -= Min(a[k], a[i]);
      a[k] -= Min(a[k], a[i]);
      flag = 1;
    }
    if (flag == 0) {
      printf("%lld", ans);
      return 0;
    }
  }
  return 0;
}
