voidsol(){ map<ls, ls> mp; int n; cin >> n; ls tot = 0; for (int i = 1; i <= n; i++){ ls c, w; cin >> c >>w; mp[w] += c; tot += c; } ls sum = 0; while (tot > 1){ ls w = mp.begin() -> first; ls c = mp.begin() -> second; if (c % 2 == 0){ sum = (sum + 2 * w * c / 2) % MOD; mp.erase(w); mp[2*w] += c / 2; tot = tot - c / 2; } else{ if (c > 1){ sum = (sum + 2 * w * (c - 1) / 2) % MOD; mp[2*w] += (c-1)/2; tot = tot - (c-1)/2; } if (mp.size() > 1){ mp.erase(w); ls w1 = mp.begin() -> first; ls c1 = mp.begin() -> second; if (c1 >= 1){ mp[w1 + w]++; sum = (sum + w1 + w) % MOD; tot -= 1; mp[w1]--; if (mp[w1] == 0) mp.erase(w1); } } } } cout << sum << endl; }