#include <bits/stdc++.h>
#include "message.h"
#define task "TEST"
#define task2 "A"
#define pl pair<ll, ll>
#define VI vector<int>
#define VL vector<ll>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (int i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (int i=a; i>=b; i+=c)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int Mod = 1e9+7;
const int maxn = 2e5;
const ll Inf = 1e16;
ll n, q, dp[maxn+1];
const int check = 25;
void send_message(vector<bool> M, vector<bool> C)
{
vector<bool> F(0, 31), F2(1, 31);
vector<int> V;
int n = M.size();
for (auto p : V) {
if (n % 2 == 1) F2[p] = 1;
else F2[p] = 0;
n /= 2;
}
while (M.size() < 1024) M.pb(0);
FOR(i, 1, check, 1) send_packet(F);
send_packet(F2);
int c = 0;
FOR(i, 1, 64, 1) {
vector<bool> V2(0, 31);
if (c == M.size()) break;
FOR(j, 0, 30, 1) {
if (!C[j]) continue;
if (c < M.size()) V2[j] = M[c++];
}
send_packet(V2);
}
}
vector<bool> receive_message(vector<vector<bool>> R)
{
vector<bool> res, safe(32, 1);
int num = 1, s = 0;
FOR(i, 0, check-1, 1) {
FOR(j, 0, 30, 1) {
if (R[i][j] == 0) safe[j] = 0;
}
}
FOR(j, 0, 30, 1) {
if (!safe[j]) continue;
s += num * R[check][j]; num *= 2;
}
FOR(i, check+1, R.size()-1, 1) {
FOR(j, 0, 30, 1) {
if (!safe[j]) continue;
res.pb(R[i][j]);
}
}
return res;
}
/*void Read()
{
//15 12 2 10 21
//4 2 3 3 1
}
void Solve()
{
for (auto p : calculate_costs({1, 100, 200, 300, 400}, {5, 4, 5, 6, 10}, {1, 2, 2, 3, 2}, {99, 100, 200})) cout << p << '\n';
}
int main()
{
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
for (t=1; t--;)
{
Read(); Solve();
}
}*/