Source Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define forr(_a, _b, _c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a, _b, _c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a, _b, _c) for(_a = (_b); _a < (_c); ++_a)
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define sz(_v) _v.begin(), _v.end()
#define mask(_x) (1ll << (_x))
#define bit(_x,_y) (((_x) >> (_y)) & 1)

string yes[2] = {"NO\n","YES\n"};
const ld eps = ld(1e-7);
const ll inf = ll(1e16) + 1;
const ll mod = ll(1e9) + 7;

const int N = 3e5 + 5;
int n, i, x, y, z, o[N];
string s[4];

void solve() {
	cin >> n >> x >> y >> z;
	forr(i,1,3) {
		cin >> s[i];
		s[i] = ' ' + s[i];
	}
	forr(i,1,n) {
		if(s[1][i] > s[2][i]) swap(s[1][i],s[2][i]);
		if(s[3][i] == '0') {
			if(s[2][i] == '1') {
				if(s[1][i] == '0') {
					--x;
					o[i] = 1;
				} else {
					--z;
					o[i] = 3;
				}
			}
		}
	}
	forr(i,1,n) {
		if(s[3][i] == '1') {
			if(x && s[1][i] == '1' && s[2][i] == '1') {
				--x;
				o[i] = 1;
			}
			if(z && s[1][i] == '0' && s[2][i] == '1') {
				--z;
				o[i] = 3;
			}
		}
	}
	forr(i,1,n) {
		if(s[1][i] == '0' && s[2][i] == '0' && s[3][i] == '0') {
			if(x) {
				--x;
				o[i] = 1;
			} else if(z) {
				--z;
				o[i] = 3;
			}
		}
	}
	forr(i,1,n) {
		if(s[1][i] == '0' && s[2][i] == '0' && s[3][i] == '1') {
			cout << "NO";
			return;
		}
		if(!o[i]) {
			o[i] = 2;
			--y;
		}
	}
	if(!x && !y && !z) {
		cout << "YES\n";
		forr(i,1,n) {
			if(o[i] == 1) cout << "&";
			else if(o[i] == 2) cout << "|";
			else cout << "^";
		}
	} else cout << "NO";
}

void precalc() {
	/*
		000 &|^
		010 &
		110 ^
		011 |^
		111 &|

		000 &|^
		011 |^
		111 &|

		000 &|^
	*/
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#ifdef umf
		freopen("test.inp","r",stdin);
		freopen("test.out","w",stdout);
	#endif

	int tc = 1;
	// cin >> tc;
	precalc();
	while(tc --> 0) {
		solve();
	}

	return 0;
}
Copy
Binary String thqdothabit
GNU G++17
13 ms
2.3 MB
Accepted