#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, mo = 1e9 + 7;
char s[N];
int n;
long long ksm(long long x, long long y) {
  long long ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = ret * x % mo;
    x = x * x % mo;
  }
  return ret;
}
long long f[N][3];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int m = 0;
  for (int i = 1; i <= n; i++) m = (m + s[i] - '0') % 3;
  int can = 0;
  for (int i = 2; i <= n; i++)
    if (s[i] == s[i - 1]) can = 1;
  if (can == 0)
    printf("0\n");
  else {
    long long ans = 0;
    f[0][0] = 1;
    for (int i = 1; i < n; i++) {
      f[i][0] = (f[i - 1][2] + f[i - 1][1]) % mo;
      f[i][1] = (f[i - 1][0] + f[i - 1][2]) % mo;
      f[i][2] = (f[i - 1][0] + f[i - 1][1]) % mo;
      ans = (ans + f[i][m]) % mo;
    }
    cout << (ans + 1 + mo) % mo << endl;
  }
}
