#include <bits/stdc++.h>
#include "molecules.h"
#define ff first
#define ss second
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
int N =w.size();
vector< pair<int,int> > ws;
for(int i =0; i < N; i++) ws.push_back(make_pair(w[i],i));
sort(begin(ws),end(ws));
vector<long long> sums(N+1,0);
for(int i =0; i < N; i++) sums[i+1] =sums[i]+ws[i].ff;
if(sums[N] < l) return vector<int>();
int a =0;
while(a < N && sums[a] < l) a++;
for(int i =N; i > 0; i--) {
while(a > 0 && sums[N]-sums[i]+sums[a] > u) a--;
if(sums[N]-sums[i]+sums[a] >= l && sums[N]-sums[i]+sums[a] <= u) {
vector<int> ans;
for(int j =0; j < a; j++) ans.push_back(ws[j].ss);
for(int j =i; j < N; j++) ans.push_back(ws[j].ss);
return ans;}
}
return vector<int>();}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlICJtb2xlY3VsZXMuaCIKI2RlZmluZSBmZiBmaXJzdAojZGVmaW5lIHNzIHNlY29uZAp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD4gZmluZF9zdWJzZXQoaW50IGwsIGludCB1LCB2ZWN0b3I8aW50PiB3KSB7CglpbnQgTiA9dy5zaXplKCk7Cgl2ZWN0b3I8IHBhaXI8aW50LGludD4gPiB3czsKCWZvcihpbnQgaSA9MDsgaSA8IE47IGkrKykgd3MucHVzaF9iYWNrKG1ha2VfcGFpcih3W2ldLGkpKTsKCXNvcnQoYmVnaW4od3MpLGVuZCh3cykpOwoJdmVjdG9yPGxvbmcgbG9uZz4gc3VtcyhOKzEsMCk7Cglmb3IoaW50IGkgPTA7IGkgPCBOOyBpKyspIHN1bXNbaSsxXSA9c3Vtc1tpXSt3c1tpXS5mZjsKCWlmKHN1bXNbTl0gPCBsKSByZXR1cm4gdmVjdG9yPGludD4oKTsKCWludCBhID0wOwoJd2hpbGUoYSA8IE4gJiYgc3Vtc1thXSA8IGwpIGErKzsKCWZvcihpbnQgaSA9Tjsg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