fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define mod 1000000007
  5.  
  6. int main()
  7. {
  8. ll n, fd, tmp_fd, fa, tmp_fa, fb, tmp_fb, fc, tmp_fc;
  9. fd = 0, fa = fb = fc = 1;
  10. cin >> n;
  11.  
  12. for (ll i = 2; i <= n; i++)
  13. {
  14.  
  15. tmp_fd = fd;
  16. fd = (fa + fb + fc) % mod;
  17. tmp_fa = fa;
  18. fa = (tmp_fd + fb + fc) % mod;
  19. tmp_fb = fb;
  20. fb = (tmp_fa + tmp_fd + fc) % mod;
  21. tmp_fc = fc;
  22. fc = (tmp_fa + tmp_fb + tmp_fd) % mod;
  23. }
  24. cout << fd;
  25. }
Success #stdin #stdout 0s 4932KB
stdin
2
stdout
3