Problem:
Problem E
Village of Lore
Icpca village, said to lie in a deep jungle, is known by strange, contradictory lore.
Some say there lies a epitome of happiness while others say it is a terrible fortress of horror.
An old soothsayer, who is a precious source of information, reported that Icpca village has a rectangular form with streets of a grid pattern.
n
west-east straight streets and
m
north-south straight streets pass through the village.
n
and
m
are both even.
To investigate the reality of the lore, a team of
n
+
m
researchers were sent to Icpca village. The plan of the investigation was as follows.
The
i
-th of the first
n
researchers walks from the western end to the eastern end on the
i
-th street from the north.
The
j
-th of the remaining
m
researchers walks from the northern end to the southern end on the
j
-th street from the west.
Some of the researchers returned from Icpca village as planned. However, nothing has been heard from the rest...
According to the pseudopsia of the old soothsayer, there stands exactly one statue on each of the
nm
intersections of west-east and north-south streets in Icpca village.
Each statue is either beautiful or horrible.
Each researcher has a value called sanity. All the researchers have the sanity of 0 before they start the investigation.
When a researcher comes to an intersection with a beautiful statue, his/her sanity is increased by 1. 
When a researcher comes to an intersection with a horrible statue, his/her sanity is decreased by 1. 
Since the horrible statues are extraordinarily horrible, if the sanity of a researcher becomes negative, he/she cannot move anymore because of the fear, and will never return from the village.
Since the beautiful statues are extraordinarily beautiful, if the sanity of a researcher is positive on going out of the village, the euphoria prevents him/her from leaving the village.
The rest of the researchers, those who keep non-negative sanity and have the sanity of 0 on exiting the village, will return.
The investigation is over, regrettably with many missing persons.  Now you have the list of returned researchers.
Your task is to decide whether there exist any arrangements of beautiful and horrible statues not conflicting with the list, and, if any, show one of such arrangements.
Input
The input consists of multiple datasets, each in the following format.
n
m
A
B
n
and
m
are the numbers of west-east and north-south streets, respectively.
n
and
m
are both positive even numbers at most 100.
A
and
B
are strings representing whether each researcher has returned from the village.
A
has the length
n
and
B
has the length
m
.
Each string consists only of
0
s and
1
s.
The
i
-th character of
A
represents whether the
i
-th of the first
n
researchers has returned from the village;
1
means the researcher has returned, and
0
means he/she has not.
The
j
-th character of
B
represents whether the
j
-th of the remaining
m
researchers has returned from the village in the same manner.
The numbe
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
// using mint = modint1000000007;
//*/

using ll = long long;
using i128 = __int128_t;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
using ld = long double;
const int INF = 1000100100;
const ll INFF = 1000100100100100100LL;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (ll i = 0; i < ll(n); i++)
#define rep2(i, l, r) for (ll i = ll(l); i < ll(r); i++)
#define rep3(i, l, r, d) for (ll i = ll(l); (d) > 0 ? i < ll(r) : i > ll(r); i += d)
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define per(i, n) for (int i = (n) - 1; i >= 0; --i)
#define yesno(f) cout << (f ? "Yes" : "No") << endl;
#define YESNO(f) cout << (f ? "YES" : "NO") << endl;
#define all(a) (a).begin(), (a).end()
#define popc(x) __builtin_popcountll(ll(x))

template <typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
    return os << p.first << ' ' << p.second;
}

template <typename T>
void printvec(const vector<T> &v) {
    int n = v.size();
    rep(i, n) cout << v[i] << (i == n - 1 ? "" : " ");
    cout << '\n';
}

template <typename T>
void printvect(const vector<T> &v) {
    for (auto &vi : v) cout << vi << '\n';
}

template <typename T>
void printvec2(const vector<vector<T>> &v) {
    for (auto &vi : v) printvec(vi);
}

template <typename S, typename T>
bool chmax(S &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template <typename S, typename T>
bool chmin(S &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

#ifdef LOCAL  // https://zenn.dev/sassan/articles/19db660e4da0a4
#include "cpp-dump-main/dump.hpp"
#define dump(...) cpp_dump(__VA_ARGS__)
CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(val());
#else
#define dump(...)
#endif

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;
bool check(string a, string b, vector<vector<char>> ans) {
    int n = ans.size(), m = ans[0].size();
    bool ok = true;
    rep(i, n) rep(j, m) {
        if (ans[i][j] == '?') return false;
    }
    rep(i, n) {
        int cnt = 0;
        bool flag = true;
        rep(j, m) {
            if (ans[i][j] == '+') cnt++;
            else cnt--;
            if (cnt < 0) flag = false;
        }
        if (cnt != 0) flag = false;
        if ((a[i] == '1') ^ flag) ok = false;
    }
    rep(j, m) {
        int cnt = 0;
        bool flag = true;
        rep(i, n) {
            if (ans[i][j] == '+') cnt++;
            else cnt--;
            if (cnt < 0) flag = false;
        }
        if (cnt != 0) flag = false;
        if ((b[j] == '1') ^ flag) ok = false;
    }
    return ok;
}
void solve() {
    int n, m;
    cin >> n >> m;
    if (n == 0) exit(0);
    string a, b;
    cin >> a >> b;
    vector<vector<char>> ans(n, vector<char>(m, '?'));
    rep(i, n) {
        if (a[i] == '1') {
            ans[i][0] = '+';
            ans[i][m - 1] = '-';
        }
    }
    rep(i, m) {
        if (b[i] == '1') {
            ans[0][i] = '+';
            ans[n - 1][i] = '-';
        }
    }
    // いけるか
    bool ok = true;
    if (a[0] == '1') {
        int cnt = 0;
        int cntp = 0;
        rep(i, m) {
            if (ans[0][i] == '+') cntp++;
        }
        rep(i, m) {
            if (ans[0][i] == '+') cnt++;
            else if (ans[0][i] == '-') cnt--;
            else {
                if (cntp < m / 2) {
                    cntp++;
                    cnt++;
                    ans[0][i] = '+';
                } else {
                    cnt--;
                    ans[0][i] = '-';
                }
            }
            if (cnt < 0) ok = false;
        }
        if (cnt != 0) ok = false;
    }

    if (a[n - 1] == '1') {
        int cnt = 0;
        int cntp = 0;
        rep(i, m) {
            if (ans[n - 1][i] == '+') cntp++;
        }
        rep(i, m) {
            if (ans[n - 1][i] == '+') cnt++;
            else if (ans[n - 1][i] == '-') cnt--;
            else {
                if (cntp < m / 2) {
                    cntp++;
                    cnt++;
                    ans[n - 1][i] = '+';
                } else {
                    cnt--;
                    ans[n - 1][i] = '-';
                }
            }
            if (cnt < 0) ok = false;
        }
        if (cnt != 0) ok = false;
    }

    if (b[0] == '1') {
        int cnt = 0;
        int cntp = 0;
        rep(i, n) {
            if (ans[i][0] == '+') cntp++;
        }
        rep(i, n) {
            if (ans[i][0] == '+') cnt++;
            else if (ans[i][0] == '-') cnt--;
            else {
                if (cntp < n / 2) {
                    cntp++;
                    cnt++;
                    ans[i][0] = '+';
                } else {
                    cnt--;
                    ans[i][0] = '-';
                }
            }
            if (cnt < 0) ok = false;
        }
        if (cnt != 0) ok = false;
    }

    if (b[m - 1] == '1') {
        int cnt = 0;
        int cntp = 0;
        rep(i, n) {
            if (ans[i][m - 1] == '+') cntp++;
        }
        rep(i, n) {
            if (ans[i][m - 1] == '+') cnt++;
            else if (ans[i][m - 1] == '-') cnt--;
            else {
                if (cntp < n / 2) {
                    cntp++;
                    cnt++;
                    ans[i][m - 1] = '+';
                } else {
                    cnt--;
                    ans[i][m - 1] = '-';
                }
            }
            if (cnt < 0) ok = false;
        }
        if (cnt != 0) ok = false;
    }

    rep(i, 1, n - 1) rep(j, 1, m - 1) {
        if (a[i] == '1' || b[j] == '1') {
            if ((i + j) % 2 == 0) ans[i][j] = '+';
            else ans[i][j] = '-';
        }
    }

    dump(ans);
    auto ran = [&]() -> char {
        if (rand() % 2 == 0) return '+';
        else return '-';
    };
    rep(_, 1000) {
        auto res = ans;
        rep(i, n) rep(j, m) {
            if (res[i][j] == '?') {
                if (i == 0 && j != m - 1) res[i][j] = '-';
                else if (i != n - 1 && j == 0) res[i][j] = '-';
                else if (i == n - 1 && j != 0) res[i][j] = '+';
                else if (i != 0 && j == m - 1) res[i][j] = '+';
                else res[i][j] = ran();
            }
        }
        if (check(a, b, res)) {
            ans = res;
            break;
        }
    }
    if (ok & check(a, b, ans)) {
        cout << "Yes" << endl;
        rep(i, n) {
            rep(j, m) cout << ans[i][j];
            cout << endl;
        }
    } else {
        cout << "No" << endl;
    }
}
int main() {
    int t;
    // cin >> t;
    t = 1;
    while (1) {
        solve();
    }
}
accuracy: 1
time_ms: 910
memory_kb: 3460
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
using ull = unsigned long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqmax = priority_queue<T>;
const ll inf=LLONG_MAX/3;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define si(x) ll(x.size())
#define rept(n) for(ll _ovo_=0;_ovo_<n;_ovo_++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rng(i,l,r) for(ll i=l;i<r;i++)
#define gnr(i,l,r) for(ll i=r-1;i>=l;i--)
#define fore(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
template<class T> bool chmin(T& a, const T& b){ if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, const T& b){ if(a >= b) return 0; a = b; return 1; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define VLL(name,size) vector<ll>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>> name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>> name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>> name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SUM(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
template<class T, class F = less<>> map<T,vector<ll> > ivm(vector<T>& a, F b = F{}){ map<T,vector<ll> > ret; rep(i,si(a))ret[a[i]].push_back(i); return ret;}
template<class T, class F = less<>> map<T,ll> ivc(vector<T>& a, F b = F{}){ map<T,ll> ret; rep(i,si(a))ret[a[i]]++; return ret;}
template<class T, class F = less<>> vector<T> ivp(vector<T> a){ vector<ll> ret(si(a)); rep(i,si(a))ret[a[i]] = i; return ret;}
template<class T, class F = less<>> vector<ll> rev(vector<T> a){ reverse(all(a)); return a;}
template<class T, class F = less<>> vector<ll> sortby(vector<T> a, F b = F{}){vector<ll> w = a; sor(w,b); vector<pll> v; rep(i,si(a))v.eb(a[i],i); sor(v); if(w[0] != v[0].first)reverse(all(v)); vector<ll> ret; rep(i,si(v))ret.pb(v[i].second); return ret;}
template<class T, class P> vector<T> filter(vector<T> a,P f){vector<T> ret;rep(i,si(a)){if(f(a[i]))ret.pb(a[i]);}return ret;}
template<class T, class P> vector<ll> filter_id(vector<T> a,P f){vector<ll> ret;rep(i,si(a)){if(f(a[i]))ret.pb(i);}return ret;}
ll monotone_left(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_left(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_right(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
ll monotone_right(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
double monotone_double_left(double l,double r,function<bool(double)> f){assert(f(l) >= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return l;}
double monotone_double_right(double l,double r,function<bool(double)> f){assert(f(l) <= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return r;}
template<class S> S unimodal_max(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) < f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmax(ret,f(k)); return ret;}
template<class S> S unimodal_min(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) > f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmin(ret,f(k)); return ret;}
vector<pll> neighbor4(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,4){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};
vector<pll> neighbor8(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,8){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};

void outb(bool x){cout<<(x?"Yes":"No")<<"\n";}
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
ll gcd(ll a,ll b){return (b?gcd(b,a%b):a);}
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); per(i,ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
vll prime_table(ll n){vec(ll,isp,n+1,1);vll res;rng(i,2,n+1)if(isp[i]){res.pb(i);for(ll j=i*i;j<=n;j+=i)isp[j]=0;}return res;}
ll powll(lll x,ll y){lll res = 1; while(y){ if(y & 1)res = res * x; x = x * x; y >>= 1;} return res;}
ll powmod(lll x,ll y,lll mod){lll res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1;} return res; }
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0)u+=m;return u;}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <class T> vector<T> &operator++(vector<T> &v) {
		fore(e, v) e++;
		return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e++;
		return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
		fore(e, v) e--;
		return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e--;
		return res;
}
template <class T> vector<T> &operator+=(vector<T> &l, const vector<T> &r) {
		fore(e, r) l.eb(e);
		return l;
}

template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack
bool solve(){
	ll n,m;
	cin>>n>>m;
	if(n + m == 0)return false;
	vll a(n);
	vll b(m);
	{
		string s,t;
		cin>>s>>t;
		rep(i,n)a[i] = s[i] - '0';
		rep(j,m)b[j] = t[j] - '0';
	}
	if(a[0] && b[m - 1]){
		cout<<"No"<<endl;
		return true;
	}
	if(a[n - 1] && b[0]){
		cout<<"No"<<endl;
		return true;
	}
	rep(r,16){
		vector<string> s(n);
		rep(i,n){
			s[i] = "";
			rep(j,m){
				char c = '#';
				if(0 < i && i < n - 1 && 0 < j && j < m - 1){
					if((i + j) % 2 == 1)c = '+';
					else c = '-';
				}
				s[i].pb(c);
			}
		}
		for(ll i = 1;i < n - 1;i++){
			if(a[i]){
				s[i][0] = '+';
				s[i][m - 1] = '-';
			}
		}
		for(ll j = 1;j < m - 1;j++){
			if(b[j]){
				s[0][j] = '+';
				s[n - 1][j] = '-';
			}
		}

		s[0][0] = (r >> 0 & 1) ? '+' : '-';
		s[0][m - 1] = (r >> 1 & 1) ? '+' : '-';
		s[n - 1][0] = (r >> 2 & 1) ? '+' : '-';
		s[n - 1][m - 1] = (r >> 3 & 1) ? '+' : '-';

		for(ll k = 0;k < n; k += n - 1){
			if(a[k]){
				ll rem = m / 2;
				rep(j,m)rem -= s[k][j] == '+';
				rep(j,m)if(s[k][j] == '#'){
					if(rem > 0)s[k][j] = '+';
					else s[k][j] = '-';
					rem--;
				}
			}else{
				rep(j,m)if(s[k][j] == '#'){
					if(b[j] == 0){
						s[k][j] = k ? '+' : '-';
					}
				}
			}
		}

		for(ll k = 0;k < m; k += m - 1){
			if(b[k]){
				ll rem = n / 2;
				rep(i,n)rem -= s[i][k] == '+';
				rep(i,n)if(s[i][k] == '#'){
					if(rem > 0)s[i][k] = '+';
					else s[i][k] = '-';
					rem--;
				}
			}else{
				rep(i,n)if(s[i][k] == '#'){
					if(a[i] == 0){
						s[i][k] = k ? '+' : '-';
					}
				}
			}
		}

		// rep(i,n){
		// 	cout<<s[i]<<endl;
		// }
		// cout<<endl;

		bool judge = true;
		{
			rep(i,n){
				ll rui = 0;
				bool ok = true;
				rep(j,m){
					rui += s[i][j] == '+' ? +1 : -1;
					ok &= rui >= 0;
				}
				ok &= rui == 0;
				judge &= a[i] == ok;
			}
			rep(j,m){
				ll rui = 0;
				bool ok = true;
				rep(i,n){
					rui += s[i][j] == '+' ? +1 : -1;
					ok &= rui >= 0;
				}
				ok &= rui == 0;
				judge &= b[j] == ok;
			}
		}
		if(judge){
			cout<<"Yes"<<endl;
			rep(i,n){
				cout<<s[i]<<endl;
			}
			return true;
		}
	}
	cout<<"No"<<endl;
	return true;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	while(solve()){}
}
accuracy: 1
time_ms: 10
memory_kb: 3424
final_rank: 1

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

bool check(vvi &S, string &A, string &B){
    int n = len(S), m = len(S[0]);
    bool flag = true;
    for (auto i : {0, n - 1}){
        int cnt = 0;
        bool correct = true;
        rep(j, m){
            cnt += S[i][j];
            if (cnt < 0) correct = false;
        }
        if (cnt != 0) correct = false;
        if (correct != (A[i] - '0')) flag = false;
    }
    for (auto j : {0, m - 1}){
        int cnt = 0;
        bool correct = true;
        rep(i, n){
            cnt += S[i][j];
            if (cnt < 0) correct = false;
        }
        if (cnt != 0) correct = false;
        if (correct != (B[j] - '0')) flag = false;
    }
    srep(i, 1, n - 1) if ((S[i][0] == 1 && S[i][m - 1] == -1) != (A[i] - '0')) flag = false;
    srep(j, 1, m - 1) if ((S[0][j] == 1 && S[n - 1][j] == -1) != (B[j] - '0')) flag = false;
    return flag;
}

void solve(int n, int m){
    string A, B; cin >> A >> B;
    vvi ans(n, vi(m, 0));
    srep(i, 1, n - 1) srep(j, 1, m - 1) ans[i][j] = ((i + j) % 2 ? -1 : 1);
    rep(i, n) if (A[i] == '1'){
        ans[i][0] = 1;
        ans[i][m - 1] = -1;
    }
    rep(j, m) if (B[j] == '1'){
        ans[0][j] = 1;
        ans[n - 1][j] = -1;
    }
    for (auto i : {0, n - 1}) if (A[i] == '1'){
        int one = m / 2;
        rep(j, m) if (ans[i][j] == 1) one--;
        rep(j, m) if (ans[i][j] == 0){
            if (one){
                ans[i][j] = 1;
                one--;
            }else ans[i][j] = -1;
        }
    }
    for (auto j : {0, m - 1}) if (B[j] == '1'){
        int one = n / 2;
        rep(i, n) if (ans[i][j] == 1) one--;
        rep(i, n) if (ans[i][j] == 0){
            if (one){
                ans[i][j] = 1;
                one--;
            }else ans[i][j] = -1;
        }
    }
    rep(_, 1000){
        vvi na = ans;
        rep(i, n){
            if (na[i][0] == 0) na[i][0] = (rand() % 2 ? 1 : -1);
            if (na[i][m - 1] == 0) na[i][m - 1] = (rand() % 2 ? 1 : -1);
        }
        rep(j, m){
            if (na[0][j] == 0) na[0][j] = (rand() % 2 ? 1 : -1);
            if (na[n - 1][j] == 0) na[n - 1][j] = (rand() % 2 ? 1 : -1);
        }
        if (check(na, A, B)){
            cout << "Yes\n";
            rep(i, n){
                for (auto x : na[i]) cout << (x == 1 ? '+' : '-');
                cout << "\n";
            }
            return;
        }
    }
    for (int k = -1; k < 2; k += 2){
        vvi na = ans;
        rep(i, n){
            if (na[i][0] == 0) na[i][0] = k;
            if (na[i][m - 1] == 0) na[i][m - 1] = k;
        }
        rep(j, m){
            if (na[0][j] == 0) na[0][j] = k;
            if (na[n - 1][j] == 0) na[n - 1][j] = k;
        }
        if (check(na, A, B)){
            cout << "Yes\n";
            rep(i, n){
                for (auto x : na[i]) cout << (x == 1 ? '+' : '-');
                cout << "\n";
            }
            return;
        }
    }
    cout << "No\n";
}

int main(){
    while (true){
        int n, m; cin >> n >> m;
        if (n == 0) break;
        solve(n, m);
    }
}
accuracy: 1
time_ms: 150
memory_kb: 3516
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (int i = 0; i < (int) (n); i++)

pair<string,string> check(vvll &A){
    ll N=A.size();
    ll M=A[0].size();
    string S="",T="";
    rep(i,N){
        ll k=0;
        bool OK=1;
        rep(j,M){
            k+=A[i][j];
            if(k<0)OK=0;
        }
        if(k!=0)OK=0;
        S.push_back(OK?'1':'0');
    }
    rep(j,M){
        ll k=0;
        bool OK=1;
        rep(i,N){
            k+=A[i][j];
            if(k<0)OK=0;
        }
        if(k!=0)OK=0;
        T.push_back(OK?'1':'0');
    }
    return {S,T};
} 


void solve(ll N,ll M) {
    string S,T;
    cin>>S>>T;
    vvll AN(N,vll(M,0));
    rep(i,N){
        if(S[i]=='1'){
            if(AN[i][0]==-1||AN[i][M-1]==1){
                cout<<"No"<<endl;
                return;
            }
            AN[i][0]=1;
            AN[i][M-1]=-1;
        }
    }
    rep(i,M){
        if(T[i]=='1'){
            if(AN[0][i]==-1||AN[N-1][i]==1){
                cout<<"No"<<endl;
                return;
            }
            AN[0][i]=1;
            AN[N-1][i]=-1;
        }
    }
    ll cnt=0;
    for(ll i=1;i<N-1;i++){
        if(S[i]=='1'){
            cnt++;
            ll dnt=0;
            for(ll j=1;j<M-1;j++){
                if(T[j]=='1'){
                    dnt++;
                    if((cnt+dnt)%2==0)AN[i][j]=1;
                    else AN[i][j]=-1;
                }
            }
        }
    }

    rep(i,N){
        if(S[i]=='1'){
            ll p=0;
            rep(j,M)if(AN[i][j]==1)p++;
            rep(j,M){
                if(AN[i][j]==0){
                    if(p<M/2)AN[i][j]=1;
                    else AN[i][j]=-1;
                    p++;
                }
            }
        }
    }
    rep(i,M){
        if(T[i]=='1'){
            ll p=0;
            rep(j,N)if(AN[j][i]==1)p++;
            rep(j,N){
                if(AN[j][i]==0){
                    if(p<N/2)AN[j][i]=1;
                    else AN[j][i]=-1;
                    p++;
                }
            }
        }
    }
    rep(i,N){
        // if(AN[i][0]==0)AN[i][0]=-1;
        // if(AN[i][M-1]==0)AN[i][M-1]=1;
    }
    rep(i,M){
        // if(AN[0][i]==0)AN[0][i]=-1;
        // if(AN[N-1][i]==0)AN[N-1][i]=1;
    }
    auto BN=AN;
    srand(time(NULL));
    rep(k,100){
        rep(i,N)rep(j,M){
            
            if(BN[i][j]==0){
                if(k==0)AN[i][j]=1;
                else if(k==1)AN[i][j]=-1;
                else AN[i][j]=(rand()%2==1?1:-1);
            }
        }
        auto C=check(AN);
        if(C.first==S&&C.second==T){
            cout<<"Yes"<<endl;
            rep(i,N){
                rep(j,M)cout<<(AN[i][j]==1?"+":"-");
                cout<<endl;
            }
            return;
        }
    }cout<<"No"<<endl;
    
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    ll N,M;
    while (cin >> N>>M) {
        if (N == 0)return 0;
        solve(N,M);
    }


}
accuracy: 1
time_ms: 30
memory_kb: 3676
final_rank: 4

code_snippet: #include <bits/stdc++.h>

#define rep(i, s, n) for (int i = int(s); i < int(n); i++)
#define rrep(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template <class T> bool chmin(T &a, T b) {
    if (a <= b) return false;
    a = b;
    return true;
}

template <class T> bool chmax(T &a, T b) {
    if (a >= b) return false;
    a = b;
    return true;
}

using namespace std;

template <ll m> struct modint {
    using mint = modint;
    ll a;
    modint(ll x = 0) : a((x%m + m)%m){}
    static ll mod() {
        return m;
    }
    ll& val(){
        return a;
    }
    mint pow(ll n){
        mint res = 1;
        mint x = a;
        while(n){
            if (n&1) res*= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    mint inv(){
        return pow(m-2);
    }
    mint& operator+=(const mint rhs){
        a += rhs.a;
        if (a >= m) a-=m;
        return *this;
    }
    mint& operator-=(const mint rhs){
        if (a < rhs.a) a+=m;
        a -= rhs.a;
        return *this;
    }
    mint& operator*=(const mint rhs){
        a = a * rhs.a %m;
        return *this;
    }
    mint& operator/=(mint rhs){
        *this *= rhs.inv();
        return *this;
    }
    friend mint operator+(const mint& lhs, const mint& rhs){
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs){
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs){
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs){
        return mint(lhs) /= rhs;
    }
    mint operator+() const{
        return *this;
    }
    mint operator-() const {
        return mint() - *this;
    }  
};

using modint998244353 = modint<998244353>;
using mint = modint998244353;

template<typename T>
struct Binom{
    Binom(int lim = 300000){
        if (kaijo.empty()){
            kaijo = {1, 1};
            kainv = {1, 1};
        }
        kaijo.resize(lim+1), kainv.resize(lim+1);
        for (int i=2; i<=lim; i++){
            kaijo[i] = kaijo[i-1] * T(i);
        }
        kainv[lim] = kaijo[lim].inv();
        for (int i=lim-1; i>=2; i--){
            kainv[i] = kainv[i+1] * T(i+1);
        }
    }
    static T fact(int x){
        if (x < 0){
            return T(0);
        }
        return kaijo[x];
    }
    static T ifact(int x){
        if (x < 0){
            return T(0);
        }
        return kainv[x];
    }
    static T C(int n, int r){
        if (n < 0 || n < r || r < 0) return T(0);
        return kaijo[n] * kainv[r] * kainv[n-r];
    }
    static T inv(int n){
        return ifact(n) * fact(n-1);
    }
    T operator()(int n, int r){ return C(n, r);}
    private:
        static vector<T> kaijo, kainv;
};

template<typename T>
vector<T>Binom<T>::kaijo = vector<T>(2, T(1));

template<typename T>
vector<T>Binom<T>::kainv = vector<T>(2, T(1));


bool checkAD(int n, int m, int i, vector<vector<char>> &r){
    int hp = 0;
    rep(j,0,m){
        if (r[i][j] == '+') hp++;
        if (r[i][j] == '-') hp--;
        if (hp < 0) return false;
    }
    if (hp == 0) return true;
    return false;
}

bool checkWS(int n, int m, int i, vector<vector<char>> &r){
    int hp = 0;
    rep(j,0,n){
        if (r[j][i] == '+') hp++;
        if (r[j][i] == '-') hp--;
        if (hp < 0) return false;
    }
    if (hp == 0) return true;
    return false;
}

bool checkALL(int n, int m, vector<vector<char>> &r, vector<int> &a, vector<int> &b){
    rep(i,0,n){
        if (a[i] != checkAD(n, m, i, r)){
            return false;
        }
    }
    rep(j,0,m){
        if (b[j] != checkWS(n, m, j, r)){
            return false;
        }
    }
    return true;
}

void solve(int n, int m, uniform_int_distribution<int> &dist, mt19937 &engine){
    vector<int> a(n), b(m);
    rep(i,0,n){
        char c; cin >> c;
        a[i] = c - '0';
    }
    rep(i,0,m){
        char c; cin >> c;
        b[i] = c - '0';
    }

    // make O the head and tail
    vector<vector<char>> r(n, vector<char>(m, '?'));
    
    rep(i,0,n){
        if (a[i] == 1){
            r[i][0] = '+';
            r[i][m-1] = '-';
        }
    }

    rep(i,0,m){
        if (b[i] == 1){
            r[0][i] = '+';
            r[n-1][i] = '-';
        }
    }

    // ICHIMATSU MOYOU
    rep(i,1,n-1){
        rep(j,1,m-1){
            if ((i+j)%2 == 0){
                r[i][j] = '+';
            }else{
                r[i][j] = '-';
            }
        }
    }


    // make O great
    for (int i: {0, n-1}){
        if (a[i] == 1){
            int pos = 0, neg = 0;
            rep(j,0,m){
                if (r[i][j] == '+') pos++;
                if (r[i][j] == '-') neg++;
            }
            rep(j,0,m){
                if (r[i][j] == '?'){
                    if (pos < m/2){
                        r[i][j] = '+';
                        pos++;
                    }else{
                        r[i][j] = '-';
                        neg++;
                    }
                }
            }
        }
    }

    
    for (int j: {0, m-1}){
        if (b[j] == 1){
            int pos = 0, neg = 0;
            rep(i,0,n){
                if (r[i][j] == '+') pos++;
                if (r[i][j] == '-') neg++;
            }
            rep(i,0,n){
                if (r[i][j] == '?'){
                    if (pos < n/2){
                        r[i][j] = '+';
                        pos++;
                    }else{
                        r[i][j] = '-';
                        neg++;
                    }
                }
            }
        }
    }

    rep(i,0,n){
        rep(j,0,m){
            if (a[i] == 0 && b[j] == 0){
                r[i][j] = '?';
            }
        }
    }

/*
    rep(i,0,n){
        rep(j,0,m){
            cout << r[i][j];
        }
        cout << endl;
    }
*/

    // RANTAKU
    vector<int> x,y;

    rep(i,0,n){
        rep(j,0,m){
            if (r[i][j] == '?'){
                x.push_back(i);
                y.push_back(j);
            }
        }
    }

    int k = x.size();

    rep(NUMBER, 0, 1000){
        vector<vector<char>> nr = r;
        rep(i,0,k){
            if (dist(engine)) nr[x[i]][y[i]] = '+';
            else nr[x[i]][y[i]] = '-';
        }
        if(checkALL(n,m,nr,a,b)){
            cout << "Yes" << endl;
            rep(i,0,n){
                rep(j,0,m){
                    cout << nr[i][j];
                }
                cout << endl;
            }
            return;
        };
    }

    {
        vector<vector<char>> nr = r;
        rep(i,0,k){
            nr[x[i]][y[i]] = '+';
        }
        if(checkALL(n,m,nr,a,b)){
            cout << "Yes" << endl;
            rep(i,0,n){
                rep(j,0,m){
                    cout << nr[i][j];
                }
                cout << endl;
            }
            return;
        };
    }

    {
        vector<vector<char>> nr = r;
        rep(i,0,k){
            nr[x[i]][y[i]] = '-';
        }
        if(checkALL(n,m,nr,a,b)){
            cout << "Yes" << endl;
            rep(i,0,n){
                rep(j,0,m){
                    cout << nr[i][j];
                }
                cout << endl;
            }
            return;
        };
    }

    cout << "No" << endl;
    
    return;
}

int main() {
    random_device seed_gen;
    mt19937 engine(seed_gen());
    uniform_int_distribution<int> dist(0, 1);

    while(true){
        int n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        solve(n, m, dist, engine);
    }
}
accuracy: 1
time_ms: 1120
memory_kb: 3556
final_rank: 5