CSES - Shared codeLink to this code:
https://cses.fi/paste/1ea2ecdcdcc46e54190a53/
#include <bits/stdc++.h>
using namespace std;
// start policy based data structures
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// end policy based data structures
// start debugging helpers
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << "\t|";
__f(comma + 1, args...);
}
#define print(x) \
for (auto it : x) \
cout << it << ' '; \
cout << '\n';
// end debugging helpers
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define int long long
#define count_bits(x) __builtin_popcountll(x)
int ceil(int a, int b) {
int c = a / b;
if (a % b != 0) c++;
return c;
}
// typedef long long ll;
typedef unsigned long long ull;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
void solve() {
int n;
cin >> n;
int mod = 1e9 + 7;
int sum = n * (n + 1) / 2;
if (sum % 2) {
cout << "0\n";
return;
}
int target = sum / 2;
vector<vector<int>> dp(n + 1, vector<int>(target + 1, 0));
// treating this as coin change with coins 1, 2 .... n
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= target; j++) {
dp[i][j] = dp[i - 1][j];
// i represents the coin with value i
if (j >= i)
dp[i][j] = (dp[i][j] + dp[i - 1][j - i]) % mod;
}
}
cout << dp[n][target] / 2 << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}