#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define sp ' '
#define assert(x,a) if(x){cout << a << endl;return;}
#define sortv(x)sort(x.begin(),x.end())
#define revev(x)reverse(x.begin(),x.end())
inline void fast(){
std::ios_base::sync_with_stdio(0);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
}
vector<vector<int>>graph;
vector<bool>vis(100001,false);
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second < b.second);
}
inline void answer(int c){assert(c==0,"NO")cout << "YES" << endl;}
void solve()
{
int a,b,c,d;cin >>a >> b >> c >> d;
string s1;
string s2;
string s3;cin >> s1 >> s2 >> s3;
int AND = 0;
int or1 = 0;
int xor1 = 0;
map<int,int>l;
for(int i = 0;i < a;i++)
{
string temp = "";
temp+=s1[i];
temp+=s2[i];
sort(temp.begin(),temp.end(),greater<int>());
if(temp[0] == '1' && temp[1] == '1')
{
if(s3[i] == '1')
{
l[2]++;
AND++;
or1++;
}
else
{
xor1++;
}
}
else if(temp[0] == '1' && temp[1] == '0')
{
if(s3[i] == '1')
{
l[1]++;
or1++;
xor1++;
}
else
{
AND++;
}
}
else
{
if(s3[i] == '1')
{
answer(0);
return;
}
else
{
l[0]++;
AND++;
or1++;
xor1++;
}
}
}
string ans(a,'?');
for(int i = 0;i < a;i++)
{
if(s1[i] == '1' && s2[i] == '1' && s3[i] == '0')
{
if(xor1 != 0)
{
ans[i] = '^';
xor1--;
d--;
}
else
{
answer(0);return;
}
}
else if(s1[i] == '0' && s2[i] == '1' && s3[i] == '0' || s1[i] == '1' && s2[i] == '0' && s3[i] == '0')
{
if(AND != 0)
{
ans[i] = '&';
AND--;
b--;
}
else
{
answer(0);return;
}
}
}
vector<pair<int,int>>all_v(2);
if(AND + or1 >= l[2] && or1 + xor1 >= l[1] && AND >= b && or1 >= c && xor1 >= d)
{
while(l[2] != 0)
{
if(AND != 0 && b != 0)
{
AND--;
all_v[0].first++;
b--;
}
else
{
or1--;
all_v[0].second++;
c--;
}
l[2]--;
}
while(l[1] != 0)
{
if(xor1 != 0 &&d != 0)
{
xor1--;
all_v[1].first++;
d--;
}
else
{
or1--;
all_v[1].second++;
c--;
}
l[1]--;
}
}
else
{
answer(0);return;
}
for(int i = 0;i < a;i++)
{
if(ans[i] != '?')
continue;
if(s1[i] == '1' && s2[i] == '1')
{
if(all_v[0].first != 0)
{
ans[i] = '&';
all_v[0].first--;
}
else
{
ans[i] = '|';
all_v[0].second--;
}
}
else if(s1[i] == '1' || s2[i] == '1')
{
if(all_v[1].first != 0)
{
ans[i] = '^';
all_v[1].first--;
}
else
{
ans[i] = '|';
all_v[1].second--;
}
}
else
{
if(AND != 0 && b != 0)
{
ans[i] = '&';
AND--;
b--;
}
else if(or1 != 0 && c != 0)
{
ans[i] = '|';
or1--;
c--;
}
else
{
ans[i] = '^';
xor1--;
d--;
}
}
}
if(b == 0 && c == 0 && d == 0)
{
answer(1);
cout << ans << endl;
}
else
answer(0);
}
int main()
{
fast();
ll t{ 1 };//cin >> t;
// cin.ignore();
while (t--)
{
solve();
}
}
Copy