#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<double> CMP;
class SurveillanceSystem { public:
string getContainerInfo(string containers, vector <int> reports, int L)
{
const int N = containers.size();
map< int, vector<int> > seen_to_pos;
for(int s=0; s+L<=N; ++s)
seen_to_pos[count(containers.begin()+s, containers.begin()+s+L, 'X')].push_back(s);
map<int,int> seen_to_cnt;
for(int i=0; i<reports.size(); ++i)
seen_to_cnt[reports[i]]++;
string result(N, '-');
for(map<int,int>::iterator it=seen_to_cnt.begin(); it!=seen_to_cnt.end(); ++it)
{
int s = it->first;
int c = it->second;
vector<int>& p = seen_to_pos[s];
mask(N, L, p, c, result);
}
return result;
}
// May/must choose |K| ranges out of |p|. Update |result|.
void mask(int N, int L, vector<int>& p, int K, string& result)
{
assert(K > 0);
sort(p.begin(), p.end());
// Any range can be watched.
for(int i=0; i<p.size(); ++i) {
for(int x=p[i]; x<p[i]+L; ++x)
if(result[x] == '-')
result[x] = '?';
}
// Do "always" check.
for(int x=0; x<N; ++x) {
int cover = 0;
for(int i=0; i<p.size(); ++i)
if(p[i]<=x && x<p[i]+L)
++cover;
// If |x| is covered by some range but avoiding them leaves <K...
if(cover && (p.size()-cover) < K)
result[x] = '+';
}
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, SurveillanceSystem().getContainerInfo(containers, reports, L));}
int main(){
CASE(0)
string containers = "-X--XX";
int reports_[] = {1, 2};
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = 3;
string _ = "??++++";
END
CASE(1)
string containers = "-XXXXX-";
int reports_[] = {2};
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = 3;
string _ = "???-???";
END
CASE(2)
string containers = "------X-XX-";
int reports_[] = {3, 0, 2, 0};
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = 5;
string _ = "++++++++++?";
END
CASE(3)
string containers = "-XXXXX---X--";
int reports_[] = {2, 1, 0, 1};
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = 3;
string _ = "???-??++++??";
END
CASE(4)
string containers = "-XX--X-XX-X-X--X---XX-X---XXXX-----X";
int reports_[] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = 7;
string _ = "???++++?++++++++++++++++++++??????--";
END
/*
CASE(5)
string containers = ;
int reports_[] = ;
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = ;
string _ = ;
END
CASE(6)
string containers = ;
int reports_[] = ;
vector <int> reports(reports_, reports_+sizeof(reports_)/sizeof(*reports_));
int L = ;
string _ = ;
END
*/
}
// END CUT HERE