Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 5e3 + 5;
const double eps = 1e-9;

int dp[N][N][2][2];

inline int add(int& x, int y) { return x = x+y < mod ? x+y : x+y-mod; }
inline int sub(int& x, int y) { return x = x-y >= 0 ? x-y : x-y+mod; }
inline int mul(int x, int y) { return x * 1ll * y % mod; }
inline int pw(int x, int y) {
  int r = 1;
  for (; y; y /= 2, x = mul(x, x))
    if (y & 1)
      r = mul(r, x);
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b; cin >> n >> a >> b;
  if (a > b)
    swap(a, b);
  if (a == 1) {
    printf("%d\n", pw(2, n));
    return 0;
  }
  dp[0][0][0][0] = 1;
  dp[0][0][0][1] = 1;

  dp[1][1][0][0] = mod-1;
  dp[1][1][0][1] = mod-1;
  for (int i = 0; i <= n; i++) {
    int sm[2] = {0, 0};
    for (int j = 0; j <= i; j++) {
      if (i > 0 && j > 0)
        for (int ii = 0; ii < 2; ii++)
   for (int jj = 0; jj < 2; jj++)
            add(dp[i][j][ii][jj], dp[i-1][j-1][ii][jj]);
      if (a + i <= n) {
        if (j+a >= b) {
          add(dp[i+a][j+a][1][0], dp[i][j][0][1]);
          sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][0][1]);
        } else {
          add(dp[i+a][j+a][0][0], dp[i][j][0][1]);
          sub(dp[min(N-1,i+b-j)][j+b-j][0][0], dp[i][j][0][1]);
          add(dp[min(N-1,i+b-j)][j+b-j][1][0], dp[i][j][0][1]);
          sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][0][1]);
        }
        add(dp[i+a][j+a][1][0], dp[i][j][1][1]);
        sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][1][1]);
      }
      if (j+1 >= b) {
        add(dp[i+1][j+1][1][1], dp[i][j][0][0]);
        sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][0][0]);
      } else {
        add(dp[i+1][j+1][0][1], dp[i][j][0][0]);
        sub(dp[min(N-1,i+b-j)][j+b-j][0][1], dp[i][j][0][0]);
        add(dp[min(N-1,i+b-j)][j+b-j][1][1], dp[i][j][0][0]);
        sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][0][0]);
      }
      add(dp[i+1][j+1][1][1], dp[i][j][1][0]);
      sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][1][0]);
      for (int k = 0; k < 2; k++)
        add(sm[k], dp[i][j][k][1]);
    }
    for (int nj = 1; nj + i <= n && nj < a; nj++) {
      for (int k = 0; k < 2; k++) {
        add(dp[i+nj][0][k][0], sm[k]);
        sub(dp[i+nj+1][1][k][0], sm[k]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 2; j++)
      add(ans, dp[n][i][1][j]);
  printf("%d\n", ans);
  return 0;
}
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 5e3 + 5;
const double eps = 1e-9;

int dp[N][N][2][2];

inline int add(int& x, int y) { return x = x+y < mod ? x+y : x+y-mod; }
inline int sub(int& x, int y) { return x = x-y >= 0 ? x-y : x-y+mod; }
inline int mul(int x, int y) { return x * 1ll * y % mod; }
inline int pw(int x, int y) {
  int r = 1;
  for (; y; y /= 2, x = mul(x, x))
    if (y & 1)
      r = mul(r, x);
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b; cin >> n >> a >> b;
  if (a > b)
    swap(a, b);
  if (a == 1) {
    printf("%d\n", pw(2, n));
    return 0;
  }
  dp[0][0][0][0] = 1;
  dp[0][0][0][1] = 1;

  dp[1][1][0][0] = mod-1;
  dp[1][1][0][1] = mod-1;
  for (int i = 0; i <= n; i++) {
    int sm[2] = {0, 0};
    for (int j = 0; j <= i; j++) {
      if (i > 0 && j > 0)
        for (int ii = 0; ii < 2; ii++)
          for (int jj = 0; jj < 2; jj++)
            add(dp[i][j][ii][jj], dp[i-1][j-1][ii][jj]);
      if (a + i <= n) {
        if (j+a >= b) {
          add(dp[i+a][j+a][1][0], dp[i][j][0][1]);
          sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][0][1]);
        } else {
          add(dp[i+a][j+a][0][0], dp[i][j][0][1]);
          sub(dp[min(N-1,i+b-j)][j+b-j][0][0], dp[i][j][0][1]);
          add(dp[min(N-1,i+b-j)][j+b-j][1][0], dp[i][j][0][1]);
          sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][0][1]);
        }
        add(dp[i+a][j+a][1][0], dp[i][j][1][1]);
        sub(dp[i+n-i+1][j+n-i+1][1][0], dp[i][j][1][1]);
      }
      if (j+1 >= b) {
        add(dp[i+1][j+1][1][1], dp[i][j][0][0]);
        sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][0][0]);
      } else {
        add(dp[i+1][j+1][0][1], dp[i][j][0][0]);
        sub(dp[min(N-1,i+b-j)][j+b-j][0][1], dp[i][j][0][0]);
        add(dp[min(N-1,i+b-j)][j+b-j][1][1], dp[i][j][0][0]);
        sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][0][0]);
      }
      add(dp[i+1][j+1][1][1], dp[i][j][1][0]);
      sub(dp[i+n-i+1][j+n-i+1][1][1], dp[i][j][1][0]);
      for (int k = 0; k < 2; k++)
        add(sm[k], dp[i][j][k][1]);
    }
    for (int nj = 1; nj + i <= n && nj < a; nj++) {
      for (int k = 0; k < 2; k++) {
        add(dp[i+nj][0][k][0], sm[k]);
        sub(dp[i+nj+1][1][k][0], sm[k]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 2; j++)
      add(ans, dp[n][i][1][j]);
  printf("%d\n", ans);
  return 0;
}

Compiler output:
a.cc:144:14: error: redefinition of 'const double pi'
  144 | const double pi = acos(-1);
      |              ^~
a.cc:31:14: note: 'const double pi' previously defined here
   31 | const double pi = acos(-1);
      |              ^~
a.cc:145:11: error: redefinition of 'const int mod'
  145 | const int mod = 1e9 + 7;
      |           ^~~
a.cc:32:11: note: 'const int mod' previously defined here
   32 | const int mod = 1e9 + 7;
      |           ^~~
a.cc:146:11: error: redefinition of 'const int inf'
  146 | const int inf = 1e9 + 7;
      |           ^~~
a.cc:33:11: note: 'const int inf' previously defined here
   33 | const int inf = 1e9 + 7;
      |           ^~~
a.cc:147:11: error: redefinition of 'const int N'
  147 | const int N = 5e3 + 5;
      |           ^
a.cc:34:11: note: 'const int N' previously defined here
   34 | const int N = 5e3 + 5;
      |           ^
a.cc:148:14: error: redefinition of 'const double eps'
  148 | const double eps = 1e-9;
      |              ^~~
a.cc:35:14: note: 'const double eps' previously defined here
   35 | const double eps = 1e-9;
      |              ^~~
a.cc:150:5: error: redefinition of 'int dp [5005][5005][2][2]'
  150 | int dp[N][N][2][2];
      |     ^~
a.cc:37:5: note: 'int dp [5005][5005][2][2]' previously declared here
   37 | int dp[N][N][2][2];
      |     ^~
a.cc:152:12: error: redefinition of 'int add(int&, int)'
  152 | inline int add(int& x, int y) { return x = x+y < mod ? x+y : x+y-mod; }
      |            ^~~
a.cc:39:12: note: 'int add(int&, int)' previously defined here
   39 | inline int add(int& x, int y) { return x = x+y < mod ? x+y : x+y-mod; }
      |            ^~~
a.cc:153:12: error: redefinition of 'int sub(int&, int)'
  153 | inline int sub(int& x, int y) { return x = x-y >= 0 ? x-y : x-y+mod; }
      |            ^~~
a.cc:40:12: note: 'int sub(int&, int)' previously defined here
   40 | inline int sub(int& x, int y) { return x = x-y >= 0 ? x-y : x-y+mod; }
      |            ^~~
a.cc:154:12: error: redefinition of 'int mul(int, int)'
  154 | inline int mul(int x, int y) { return x * 1ll * y % mod; }
      |            ^~~
a.cc:41:12: note: 'int mul(int, int)' previously defined here
   41 | inline int mul(int x, int y) { return x * 1ll * y % mod; }
      |            ^~~
a.cc:155:12: error: redefinition of 'int pw(int, int)'
  155 | inline int pw(int x, int y) {
      |            ^~
a.cc:42:12: note: 'int pw(int, int)' previously defined here
   42 | inline int pw(int x, int y) {
      |            ^~
a.cc:163:5: error: redefinition of 'int main()'
  163 | int main() {
      |     ^~~~
a.cc:50:5: note: 'int main()' previously defined here
   50 | int main() {
      |     ^~~~