#include #include using namespace std; using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; using ll = long long; using P = pair; using T = tuple; templatebool chmax(T_& a, const T_& b) { if (a < b) { a = b;return true; } else { return false; } } templatebool chmin(T_& a, const T_& b) { if (a > b) { a = b;return true; } else { return false; } } #ifdef LOCAL template ostream& operator<<(ostream& o, const pair& p) { return o << "(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& o, const tuple& t) { o << "("; apply([&o](auto&&... a) { int c = 0; (((o << (c++ ? ", " : "") << a)), ...); }, t); return o << ")"; } template auto operator<<(ostream& o, const V& v) -> std::enable_if_t && !std::is_same_v, decltype(v.begin(), o)> { o << "{"; int c = 0; for (auto& x : v) o << (c++ ? ", " : "") << x; return o << "}"; } #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"]: ",([](auto&&... a){((cerr<> n; if (n <= 3000) { vector a(n, 0); mint ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; // mint sum = 0; // ll pw = 1; // while (pw <= n) { // pw *= 2; // ll cnt = (n + 1) / pw; // sum += cnt * (n - cnt) * pw / 2; // dbg(sum.val()); // } // ans += sum * a[i]; mint sum = 0; for (int j = 0; j < n; j++) { sum += i ^ j; } ans += a[i] * sum; } cout << ans.val() << "\n"; return; } vector a(n, 0); mint ans = 0; vector xx(32, 0); for (int i = 0; i < n; i++) { int lim = 1; for (int j = 0; j < 32; j++) { lim *= 2; if (lim > n)break; if ((i >> j) & 1) { xx[j]++; } dbg(j, xx[j]); } } for (int i = 0; i < n; i++) { cin >> a[i]; mint sum = 0; int lim = 1; mint pw = 1; for (int j = 0; j < 32; j++) { lim *= 2; if (lim > n)break; if ((i >> j) & 1) { sum += (n - xx[j]) * pw; } else { sum += xx[j] * pw; } pw *= 2; dbg(i, xx[j], sum.val()); } ans += sum * a[i]; } cout << ans.val() << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } }