#include using namespace std; using ll = long long; #define all(a) a.begin(),a.end() #define reps(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) reps(i, 0, n) #define rreps(i, a, n) for (int i = (a); i > (int)(n); i--) const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; ll myceil(ll a, ll b) {return (a+b-1)/b;} template using vc = vector; template using vv = vc>; template using vvv = vv>; using pii = pair; using pll = pair; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define debug(var) do { cout << #var << " :\n"; view(var); } while(0) templatevoid view(const T& e) {cout << e;} templatevoid view(const pair& p) {cout << "{" << p.first << ", " << p.second << "}";} templatevoid view(const vc& v) {for (const auto& e : v) {view(e);cout << " ";} cout << endl;} templatevoid view(const vv& vv) {for (const auto& v : vv) {view(v);} cout << endl;} templatevoid view(const set& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const multiset& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const unordered_set& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const unordered_multiset& s) {for (const auto& e : s) {view(e);cout << " ";} cout << endl;} templatevoid view(const map& mp){for (const auto& e : mp) {view(e);cout << " ";} cout << endl;} # pragma GCC target("avx2") # pragma GCC optimize("O3") # pragma GCC optimize("unroll-loops") #include using namespace atcoder; void solve() { ll n; cin >> n; unsigned long long ans = 0; rep(i,n+1) { for (int j = i; j <= n; j++) { int ip = popcount((unsigned int)i); int jp = popcount((unsigned int)j); if (ip == jp) { ans += i&j; } } } cout << ans%998244353 << endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t = 1; // cin >> t; rep(i,t) solve(); return 0; }