#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<long long, long long> dp;
long long dfs(long long x) {
  if (dp[x]) return dp[x];
  return dp[x] = (dfs(x / 3) + dfs((x - 1) / 3) + dfs((x - 2) / 3) +
                  dfs((x - 3) / 3) + dfs((x - 4) / 3)) %
                 mod;
}
int main() {
  long long n;
  scanf("%lld", &n);
  dp[0] = 1ll;
  dp[1] = 2ll;
  dp[2] = 4ll;
  dp[3] = 5ll;
  dp[4] = 8ll;
  printf("%lld", dfs(n));
  return 0;
}
