/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 0 && lels.fs > 0) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        break;
                    } else {
                        lels.fs--;
                        mems.fs--;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        break;
                    } else {
                        mems.sc++;
                        lels.sc++;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }
        string mem = "";
        for (int i = keks.fs; i <= keks.sc; i++){
            mem.pb(a[x][i]);
        }
        for (int i = 0; i < n; i++) {
            size_t found = a[i].find(mem);
            if ((found == std::string::npos) != (pos[i] == mp(INF, -INF))){
                out << "NO";
                return;
            }
            if ((found == std::string::npos)){
                continue;
            }
            int found1 = found;
            for (int j = keks.fs; j <= keks.sc; j++){
                if (a[x][j] != a[i][j - keks.fs + found1] || b[x][j] != b[i][j - keks.fs + found1]){
                    out << "NO";
                    return;
                }
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 1 && lels.fs > 1) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        break;
                    } else {
                        lels.fs--;
                        mems.fs--;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        break;
                    } else {
                        mems.sc++;
                        lels.sc++;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }
        string mem = "";
        for (int i = keks.fs; i <= keks.sc; i++){
            mem.pb(a[x][i]);
        }
        for (int i = 0; i < n; i++) {
            size_t found = a[i].find(mem);
            if ((found == std::string::npos) != (pos[i] == mp(INF, -INF))){
                out << "NO";
                return;
            }
            if ((found == std::string::npos)){
                continue;
            }
            int found1 = found;
            for (int j = keks.fs; j <= keks.sc; j++){
                if (a[x][j] != a[i][j - keks.fs + found1] || b[x][j] != b[i][j - keks.fs + found1]){
                    out << "NO";
                    return;
                }
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 1 && lels.fs > 1) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        break;
                    } else {
                        lels.fs--;
                        mems.fs--;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        break;
                    } else {
                        mems.sc++;
                        lels.sc++;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }
        int anss = 0;
        int kl = 1;
        for (int i = keks.fs; i <= keks.sc; i++) {
            anss += kl * a[x][i];
            kl *= P;
            kl %= MOD;
            anss %= MOD;
        }
        for (int i = 0; i < n; i++) {
            vc<int> ans(len(a[i]) + 1);
            int kl = 1;
            for (int j = 0; j < len(a[i]); j++) {
                ans[j + 1] = (ans[j] + kl * a[i][j]) % MOD;
                kl *= P;
                kl %= MOD;
            }
            kl = 1;
            for (int j = 0; j + (keks.sc - keks.fs + 1) < min(pos[i].fs, len(a[i]) + 1); j++) {
                if ((anss * kl - (ans[j + (keks.sc - keks.fs + 1)] - ans[j])) % MOD == 0) {
                    out << "NO";
                    return;
                }
                kl *= P;
                kl %= MOD;
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 1 && lels.fs > 1) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        break;
                    } else {
                        lels.fs--;
                        mems.fs--;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        break;
                    } else {
                        mems.sc++;
                        lels.sc++;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }
        int sdv = pos[x].fs - keks.fs;
        for (int i = 0; i < n; i++){
            pos[i].fs -= sdv;
        }
        int anss = 0;
        int kl = 1;
        for (int i = keks.fs; i <= keks.sc; i++) {
            anss += kl * a[x][i];
            kl *= P;
            kl %= MOD;
            anss %= MOD;
        }
        for (int i = 0; i < n; i++) {
            vc<int> ans(len(a[i]) + 1);
            int kl = 1;
            for (int j = 0; j < len(a[i]); j++) {
                ans[j + 1] = (ans[j] + kl * a[i][j]) % MOD;
                kl *= P;
                kl %= MOD;
            }
            kl = 1;
            for (int j = 0; j + (keks.sc - keks.fs + 1) <= len(a[i]) && j < pos[i].fs; j++) {
                if ((anss * kl - (ans[j + (keks.sc - keks.fs + 1)] - ans[j])) % MOD == 0) {
                    out << "NO";
                    return;
                }
                kl *= P;
                kl %= MOD;
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, (n)) cerr << a[i] << " "; cerr << '\n'; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';

template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) { a = max(a, b); }
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) { a = min(a, b); }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }

typedef long long ll;
const int inf = 1e9 + 7;
const long long ll_inf  = 1ll * inf * inf;
const int MAX_N = 3000 + 7;
const int mod = inf;

class KMP {
private:
  static vector<int> pre_compute(string s) {
    vector<int> x(s.size());
    x[0] = -1;
    int last = -1;
    for (int i = 1, n = (int)x.size(); i < n; ++i) {
      while (last >= 0 && s[last + 1] != s[i]) // find previous matched
        last = x[last];
      if (s[last + 1] == s[i]) last++;        // if matched continue
      x[i] = last;
    }
    return x;
  }

public:
  static int compute(const string& s, const string& t) {
    vector<int> x = pre_compute(t);

    int last = -1, n = (int)t.size();
    int cnt = 0;
    rep(i, 0, (int)s.size()) {
      while (last >= 0 && t[last + 1] != s[i]) {
        last = x[last];
      }

      if (t[last + 1] == s[i]) {
        last++;
      }

      // found a match
      if (last == n - 1) {
        last = x[last]; // go to previous state
        return i - n + 1;
      }
    }
    return -1;
  }
};

int n;
string a[MAX_N], b[MAX_N];
bool check[MAX_N];
int lef[MAX_N], rig[MAX_N];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  string s = "", t = "";

  for (int i = 0; i < n; ++i) {
    lef[i] = rig[i] = -1;
    rep(j, 0, sz(a[i])) {
      if (a[i][j] != b[i][j]) {
        if (lef[i] == -1) lef[i] = rig[i] = j;
        else rig[i] = j;
      }
    }
    if (lef[i] == -1) continue;
    if (s.empty()) {
      s = a[i].substr(lef[i], rig[i] - lef[i] + 1);
      t = b[i].substr(lef[i], rig[i] - lef[i] + 1);
    } else {
      if (s != a[i].substr(lef[i], rig[i] - lef[i] + 1) || t != b[i].substr(lef[i], rig[i] - lef[i] + 1)) {
        cout << "NO";
        return;
      }
    }
  }

  int root = 0;
  while (lef[root] == -1) ++root;

  while (lef[root] > 0) {
    const char c = a[root][lef[root] - 1];
    const char c2 = b[root][lef[root] - 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= lef[i] > 0 && c == a[i][lef[i] - 1];
      check &= lef[i] > 0 && c2 == b[i][lef[i] - 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) --lef[i];
      s = c + s;
      t = c2 + t;
    } else break;
  }

  while (rig[root] + 1 < a[root].size()) {
    const char c = a[root][rig[root] + 1];
    const char c2 = b[root][rig[root] + 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= rig[i] + 1 < a[i].size() && c == a[i][rig[i] + 1];
      check &= rig[i] + 1 < b[i].size() && c == b[i][rig[i] + 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) ++rig[i];
      s += c;
      t += c2;
    } else break;
  }

  for (int i = 0; i < n; ++i) {
    int id = KMP::compute(a[i], s);
    if (id != lef[i]) {
      cout << "NO"; return;
    }
  }
  cout << "YES\n" << s << '\n' << t;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
#endif
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test)
    cin >> test;

  for(int i = 0; i < test; ++i) {
    //printf("Case #%d: ", i + 1);
    solve();
  }
#ifdef _LOCAL_
  cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


#include <bits/stdc++.h>

using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, (n)) cerr << a[i] << " "; cerr << '\n'; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';

template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) { a = max(a, b); }
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) { a = min(a, b); }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }

typedef long long ll;
const int inf = 1e9 + 7;
const long long ll_inf  = 1ll * inf * inf;
const int MAX_N = 3000 + 7;
const int mod = inf;

class KMP {
private:
  static vector<int> pre_compute(string s) {
    vector<int> x(s.size());
    x[0] = -1;
    int last = -1;
    for (int i = 1, n = (int)x.size(); i < n; ++i) {
      while (last >= 0 && s[last + 1] != s[i]) // find previous matched
        last = x[last];
      if (s[last + 1] == s[i]) last++;        // if matched continue
      x[i] = last;
    }
    return x;
  }

public:
  static int compute(const string& s, const string& t) {
    vector<int> x = pre_compute(t);

    int last = -1, n = (int)t.size();
    int cnt = 0;
    rep(i, 0, (int)s.size()) {
      while (last >= 0 && t[last + 1] != s[i]) {
        last = x[last];
      }

      if (t[last + 1] == s[i]) {
        last++;
      }

      // found a match
      if (last == n - 1) {
        last = x[last]; // go to previous state
        return i - n + 1;
      }
    }
    return -1;
  }
};

int n;
string a[MAX_N], b[MAX_N];
bool check[MAX_N];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  string rev = "";
  for (int i = 0; i < n; ++i) if (a[i] != b[i]) {
    int first = -1, last = -1;
    for (int j = 0; j < sz(a[i]); ++j) if (a[i][j] != b[i][j]) {
      if (first == -1) first = last = j;
      else last = j;
    }
    if (rev.size() > 0) {
      int id = KMP::compute(a[i], rev);
      if (id == -1) {
        cout << "NO"; return;
      }
      first = min(first, id);
      last = max(last, id + (int)rev.size() - 1);
    }
    rev = a[i].substr(first, last - first + 1);
  }

  string change = "";

  for (int i = 0; i < n; ++i) if (a[i] == b[i]) {
    int id = KMP::compute(a[i], rev);
    if (id != -1) {
      cout << "NO"; return;
    }
  } else {
    int id = KMP::compute(a[i], rev);
    if (id == -1) { cout << "NO"; return; }
    if (change.empty()) {
      change = b[i].substr(id, rev.size());
    }
  }

  cout << "YES\n";
  cout << rev << '\n';
  cout << change << '\n';
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
#endif
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test)
    cin >> test;

  for(int i = 0; i < test; ++i) {
    //printf("Case #%d: ", i + 1);
    solve();
  }
#ifdef _LOCAL_
  cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


#include <bits/stdc++.h>

using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, (n)) cerr << a[i] << " "; cerr << '\n'; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';

template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) { a = max(a, b); }
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) { a = min(a, b); }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }

typedef long long ll;
const int inf = 1e9 + 7;
const long long ll_inf  = 1ll * inf * inf;
const int MAX_N = 3000 + 7;
const int mod = inf;

class KMP {
private:
  static vector<int> pre_compute(string s) {
    vector<int> x(s.size());
    x[0] = -1;
    int last = -1;
    for (int i = 1, n = (int)x.size(); i < n; ++i) {
      while (last >= 0 && s[last + 1] != s[i]) // find previous matched
        last = x[last];
      if (s[last + 1] == s[i]) last++;        // if matched continue
      x[i] = last;
    }
    return x;
  }

public:
  static int compute(const string& s, const string& t) {
    vector<int> x = pre_compute(t);

    int last = -1, n = (int)t.size();
    int cnt = 0;
    rep(i, 0, (int)s.size()) {
      while (last >= 0 && t[last + 1] != s[i]) {
        last = x[last];
      }

      if (t[last + 1] == s[i]) {
        last++;
      }

      // found a match
      if (last == n - 1) {
        last = x[last]; // go to previous state
        return i - n + 1;
      }
    }
    return -1;
  }
};

int n;
string a[MAX_N], b[MAX_N];
bool check[MAX_N];
int lef[MAX_N], rig[MAX_N];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  string s = "", t = "";

  for (int i = 0; i < n; ++i) {
    lef[i] = rig[i] = -1;
    rep(j, 0, sz(a[i])) {
      if (a[i][j] != b[i][j]) {
        if (lef[i] == -1) lef[i] = rig[i] = j;
        else rig[i] = j;
      }
    }
    if (lef[i] == -1) continue;
    if (s.empty()) {
      s = a[i].substr(lef[i], rig[i] - lef[i] + 1);
      t = b[i].substr(lef[i], rig[i] - lef[i] + 1);
    } else {
      if (s != a[i].substr(lef[i], rig[i] - lef[i] + 1) || t != b[i].substr(lef[i], rig[i] - lef[i] + 1)) {
        cout << "NO";
        return;
      }
    }
  }

  int root = 0;
  while (lef[root] == -1) ++root;

  while (lef[root] > 0) {
    const char c = a[root][lef[root] - 1];
    const char c2 = b[root][lef[root] - 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= lef[i] > 0 && c == a[i][lef[i] - 1];
      check &= lef[i] > 0 && c2 == b[i][lef[i] - 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) --lef[i];
      s = c + s;
      t = c2 + t;
    } else break;
  }

  while (rig[root] + 1 < a[root].size()) {
    const char c = a[root][rig[root] + 1];
    const char c2 = b[root][rig[root] + 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= rig[i] + 1 < a[i].size() && c == a[i][rig[i] + 1];
      check &= rig[i] + 1 < b[i].size() && c == b[i][rig[i] + 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) ++rig[i];
      s += c;
      t += c2;
    } else break;
  }

  for (int i = 0; i < n; ++i) {
    int id = KMP::compute(a[i], s);
    if (id != lef[i]) {
      cout << "NO"; return;
    }
    id = KMP::compute(b[i], t);
    if (id != lef[i]) {
      cout << "NO"; return;
    }
  }
  cout << "YES\n" << s << '\n' << t;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
#endif
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test)
    cin >> test;

  for(int i = 0; i < test; ++i) {
    //printf("Case #%d: ", i + 1);
    solve();
  }
#ifdef _LOCAL_
  cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


#include <bits/stdc++.h>

using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, (n)) cerr << a[i] << " "; cerr << '\n'; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';

template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) { a = max(a, b); }
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) { a = min(a, b); }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }

typedef long long ll;
const int inf = 1e9 + 7;
const long long ll_inf  = 1ll * inf * inf;
const int MAX_N = 3000 + 7;
const int mod = inf;

class KMP {
private:
  static vector<int> pre_compute(const string& pattern) {
    vector<int> prev(pattern.size());
    prev[0] = -1;
    int last = -1;
    for (int i = 1, n = (int)prev.size(); i < n; ++i) {
      while (last >= 0 && pattern[last + 1] != pattern[i])
        last = prev[last];
      if (pattern[last + 1] == pattern[i]) last++;
      prev[i] = last;
    }
    return prev;
  }

public:
  static int compute(const string& query, const string& pattern) {
    vector<int> prev = pre_compute(pattern);

    int last = -1, n = (int)pattern.size();
    int cnt = 0;
    for (int i = 0, m = (int)query.size(); i < m; ++i) {
      while (last >= 0 && pattern[last + 1] != query[i])
        last = prev[last];

      if (pattern[last + 1] == query[i])
        last++;

      if (last == n - 1) {
        last = prev[last];
        return i - n + 1;
      }
    }
    return -1;
  }
};

int n;
string a[MAX_N], b[MAX_N];
bool check[MAX_N];
int lef[MAX_N], rig[MAX_N];

void solve() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  string s = "", t = "";

  for (int i = 0; i < n; ++i) {
    lef[i] = rig[i] = -1;
    rep(j, 0, sz(a[i])) {
      if (a[i][j] != b[i][j]) {
        if (lef[i] == -1) lef[i] = rig[i] = j;
        else rig[i] = j;
      }
    }
    if (lef[i] == -1) continue;
    if (s.empty()) {
      s = a[i].substr(lef[i], rig[i] - lef[i] + 1);
      t = b[i].substr(lef[i], rig[i] - lef[i] + 1);
    } else {
      if (s != a[i].substr(lef[i], rig[i] - lef[i] + 1) || t != b[i].substr(lef[i], rig[i] - lef[i] + 1)) {
        cout << "NO";
        return;
      }
    }
  }

  int root = 0;
  while (lef[root] == -1) ++root;

  while (lef[root] > 0) {
    const char c = a[root][lef[root] - 1];
    const char c2 = b[root][lef[root] - 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= lef[i] > 0 && c == a[i][lef[i] - 1];
      check &= lef[i] > 0 && c2 == b[i][lef[i] - 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) --lef[i];
      s = c + s;
      t = c2 + t;
    } else break;
  }

  while (rig[root] + 1 < a[root].size()) {
    const char c = a[root][rig[root] + 1];
    const char c2 = b[root][rig[root] + 1];
    bool check = true;
    for (int i = root + 1; i < n; ++i) if (lef[i] != -1) {
      check &= rig[i] + 1 < a[i].size() && c == a[i][rig[i] + 1];
      check &= rig[i] + 1 < b[i].size() && c == b[i][rig[i] + 1];
    }
    if (check) {
      for (int i = root; i < n; ++i) if (lef[i] != -1) ++rig[i];
      s += c;
      t += c2;
    } else break;
  }

  for (int i = 0; i < n; ++i) {
    int id = KMP::compute(a[i], s);
    if (id != lef[i]) {
      cout << "NO"; return;
    }
  }
  cout << "YES\n" << s << '\n' << t;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
  freopen("in.txt", "r", stdin);
#endif
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test)
    cin >> test;

  for(int i = 0; i < test; ++i) {
    //printf("Case #%d: ", i + 1);
    solve();
  }
#ifdef _LOCAL_
  cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


#include<bits/stdc++.h>
using namespace std;
struct node {
    char s[3005];
    char t[3005];

} str[3005];
int n;
int main() {
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++) {
        scanf("%s",str[i].s);
    }
    for(int i=0; i<n; i++) {
        scanf("%s",str[i].t);
    }

    int cntt=0;
    int poss;
    for(int i=0;i<n;i++){
        if(strcmp(str[i].s,str[i].t)!=0){
            cntt++;
            poss=i;
        }
    }
    if(cntt==1){
        cout<<"YES"<<endl<<str[poss].s<<endl<<str[poss].t<<endl;
        return 0;
    }
    int ansflag=1;
    string ans1,ans2;
    int anspos=0;
    for(int i=0; i<n; i++) {
        int len=strlen(str[i].s);
        int flag=1;

        for(int j=0; j<len; j++) {
            if(str[i].s[j]!=str[i].t[j]&&flag==1) {
                ans1+=str[i].s[j];
                ans2+=str[i].t[j];
                flag=0;//di yi ci bu xiang deng
            } else if(str[i].s[j]==str[i].t[j]&&flag==0) {
                flag=2;
            } else if(str[i].s[j]!=str[i].t[j]&&flag==2) {
                ansflag=0;
                break;
            } else if(str[i].s[j]!=str[i].t[j]&&flag==0) {
                ans1+=str[i].s[j];
                ans2+=str[i].t[j];
            }
        }

        if(ansflag==0) break;
        if(flag!=1) {
            anspos=i;
            break;
        }
    }
//    cout<<ans1<<endl;
//    cout<<ans1.size()<<endl;
    if(anspos!=n-1) {
        for(int i=anspos+1; i<n; i++) {
            string tmp1,tmp2;
            int len=strlen(str[i].s);
            int flag=1;
            for(int j=0; j<len; j++) {
                if(str[i].s[j]!=str[i].t[j]&&flag==1) {
                    tmp1+=str[i].s[j];
                    tmp2+=str[i].t[j];
                    flag=0;//di yi ci bu xiang deng
                } else if(str[i].s[j]==str[i].t[j]&&flag==0) {
                    flag=2;
                } else if(str[i].s[j]!=str[i].t[j]&&flag==2) {
                    ansflag=0;
                    break;
                } else if(str[i].s[j]!=str[i].t[j]&&flag==0) {
                    tmp1+=str[i].s[j];
                    tmp2+=str[i].t[j];
                }
            }
            if(flag==0&&(tmp1!=ans1||tmp2!=ans2)) ansflag=0;
            if(ansflag==0) break;
        }

    }
    if(ansflag==0) {
        cout<<"NO"<<endl;
    } else {
        cout<<"YES"<<endl<<ans1<<endl<<ans2<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
string str1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int check1(){
    for(int i=0;i<n;i++){
        if(str1[i]!=str2[i]){
            return i;
        }
    }
}
void find_str(int pos){
    int len=str1[pos].size();
    int l,r;
    for(int i=0;i<len;i++){
        if(str1[pos][i]!=str2[pos][i]){
            l=i;
            break;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(str1[pos][i]!=str2[pos][i]){
            r=i;
            break;
        }
    }
    int pos1=l;
    for(int i=l-1;i>=0;i--){
        if(str1[pos][i]==str2[pos][i]){
            pos1=i;
        }else{
            break;
        }
    }
    int pos2=r;
    for(int i=r+1;i<len;i++){
        if(str1[pos][i]==str2[pos][i]){
            pos2=i;
        }
    }
    if(n==2){
        pos1=l;
        pos2=r;
    }
    for(int i=pos1;i<=pos2;i++){
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
//    cout<<l<<" "<<r<<endl;
//    cout<<tmp1<<endl;
//    cout<<tmp2<<endl;
}
void Replace(){
    int t=tmp1.size();
    for(int i=0;i<n;i++){
        int pos=str1[i].find(tmp1);
        int len=str1[i].size();
        if(pos>=0&&pos<len){//在母串中找到了这个子串
            for(int j=pos;j<pos+t;j++){
                str1[i][j]=tmp2[j-pos];
            }
        }
    }
}
int check2(){
    for(int i=0;i <n;i++){
        if(str1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>str1[i];
    for(int i=0;i<n;i++) cin>>str2[i];
    int first_pos=check1();
    find_str(first_pos);
    Replace();
//    for(int i=0;i<n;i++) cout<<str1[i]<<endl;
//    for(int i=0;i<n;i++) cout<<str2[i]<<endl;

    int flag = check2();
    if(flag){
        cout<<"YES"<<endl;
        cout<<tmp1<<endl;
        cout<<tmp2<<endl;
    }else{
//        if(n==10){
//            cout<<tmp1<<endl;
//            cout<<tmp2<<endl;
//        }
        cout<<"NO"<<endl;
//                cout<<tmp1<<endl;
//        cout<<tmp2<<endl;
    }

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3+5;
string str1[maxn];
string tmpstr1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int pos;
int l,r;//l和r是最小匹配区间
int pos1,pos2;//pos1和pos2是最大匹配区间
int check1() {
    for(int i=0; i<n; i++) {
        if(str1[i]!=str2[i]) {
            return i;
        }
    }
}

void find_str() {
    int len=str1[pos].size();
    for(int i=0; i<len; i++) {
        if(str1[pos][i]!=str2[pos][i]) {
            l=i;
            break;
        }
    }
    for(int i=len-1; i>=0; i--) {
        if(str1[pos][i]!=str2[pos][i]) {
            r=i;
            break;
        }
    }
//    cout<<l<<" "<<r<<endl;
    pos1=l;
    for(int i=l-1; i>=0; i--) {
        if(str1[pos][i]==str2[pos][i]) {
            pos1=i;
        } else {
            break;
        }
    }
    pos2=r;
    for(int i=r+1; i<len; i++) {
        if(str1[pos][i]==str2[pos][i]) {
            pos2=i;
        }
    }
// cout<<l<<" "<<r<<endl;

}
void try1(int L,int R) {
    tmp1=str1[pos].substr(L,R);
    tmp2=str2[pos].substr(L,R);

}
void xx(){
    for(int i=0;i<n;i++){
        tmpstr1[i]=str1[i];
    }
}
void Replace() {
    int t=tmp1.size();
    xx();
    for(int i=0; i<n; i++) {
        if(t<=str1[i].size()) {
            int Pos=str1[i].find(tmp1);
//            cout<<Pos<<endl;
            int len=str1[i].size();
            if(Pos>=0&&Pos<len) { //在母串中找到了这个子串
                for(int j=Pos; j<Pos+t; j++) {
                    tmpstr1[i][j]=tmp2[j-Pos];
                }
            }
        }
    }
}
int check2() {
    for(int i=0; i <n; i++) {
        if(tmpstr1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main() {
    cin>>n;
    for(int i=0; i<n; i++) cin>>str1[i],tmpstr1[i]=str1[i];
    for(int i=0; i<n; i++) cin>>str2[i];
    pos=check1();
    find_str();
    int flag=1;
//    cout<<l<<" "<<r<<endl;
//    cout<<pos1<<" "<<pos2<<endl;
//    cout<<pos<<endl;

    for(int i=l; i>=pos1; i--) {
        for(int j=r; j<=pos2; j++) {
            try1(i,j);
            Replace();
            if(check2()) {
                cout<<"YES"<<endl;
                cout<<tmp1<<endl;
                cout<<tmp2<<endl;
                return 0;
            }
        }
    }

    cout<<"NO"<<endl;
    return 0;

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/
/*
5
ilonmaskmeforhelplolkekcheburek
ceilonmaskmeforhelplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
ilonmaskmyselfouplolkekcheburek
ceilonmaskmyselfouplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
*/


#include<bits/stdc++.h>
using namespace std;
struct node {
    char s[3005];
    char t[3005];

} str[3005];
int n;
int main() {
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++) {
        scanf("%s",str[i].s);
    }
    for(int i=0; i<n; i++) {
        scanf("%s",str[i].t);
    }
    if(n==1) {
        cout<<"YES"<<endl<<str[0].s<<endl<<str[0].t<<endl;
        return 0;
    }
    int ansflag=1;
    string ans1,ans2;
    int anspos=0;
    for(int i=0; i<n; i++) {
        int len=strlen(str[i].s);
        int flag=1;

        for(int j=0; j<len; j++) {
            if(str[i].s[j]!=str[i].t[j]&&flag==1) {
                ans1+=str[i].s[j];
                ans2+=str[i].t[j];
                flag=0;//di yi ci bu xiang deng
            } else if(str[i].s[j]==str[i].t[j]&&flag==0) {
                flag=2;
            } else if(str[i].s[j]!=str[i].t[j]&&flag==2) {
                ansflag=0;
                break;
            } else if(str[i].s[j]!=str[i].t[j]&&flag==0) {
                ans1+=str[i].s[j];
                ans2+=str[i].t[j];
            }
        }

        if(ansflag==0) break;
        if(flag!=1) {
            anspos=i;
            break;
        }
    }
//    cout<<ans1<<endl;
//    cout<<ans1.size()<<endl;
    if(anspos!=n-1) {
        for(int i=anspos+1; i<n; i++) {
            string tmp1,tmp2;
            int len=strlen(str[i].s);
            int flag=1;
            for(int j=0; j<len; j++) {
                if(str[i].s[j]!=str[i].t[j]&&flag==1) {
                    tmp1+=str[i].s[j];
                    tmp2+=str[i].t[j];
                    flag=0;//di yi ci bu xiang deng
                } else if(str[i].s[j]==str[i].t[j]&&flag==0) {
                    flag=2;
                } else if(str[i].s[j]!=str[i].t[j]&&flag==2) {
                    ansflag=0;
                    break;
                } else if(str[i].s[j]!=str[i].t[j]&&flag==0) {
                    tmp1+=str[i].s[j];
                    tmp2+=str[i].t[j];
                }
            }
            if(flag==0&&(tmp1!=ans1||tmp2!=ans2)) ansflag=0;
            if(ansflag==0) break;
        }

    }
    if(ansflag==0) {
        cout<<"NO"<<endl;
    } else {
        cout<<"YES"<<endl<<ans1<<endl<<ans2<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
string str1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int check1(){
    for(int i=0;i<n;i++){
        if(str1[i]!=str2[i]){
            return i;
        }
    }
}
void find_str(int pos){
    int len=str1[pos].size();
    int l,r;
    for(int i=0;i<len;i++){
        if(str1[pos][i]!=str2[pos][i]){
            l=i;
            break;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(str1[pos][i]!=str2[pos][i]){
            r=i;
            break;
        }
    }
    for(int i=l;i<=r;i++){
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
//    cout<<l<<" "<<r<<endl;
//    cout<<tmp1<<endl;
//    cout<<tmp2<<endl;
}
void Replace(){
    int t=tmp1.size();
    for(int i=0;i<n;i++){
        int pos=str1[i].find(tmp1);
        int len=str1[i].size();
        if(pos>=0&&pos<len){//在母串中找到了这个子串
            for(int j=pos;j<pos+t;j++){
                str1[i][j]=tmp2[j-pos];
            }
        }
    }
}
int check2(){
    for(int i=0;i <n;i++){
        if(str1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>str1[i];
    for(int i=0;i<n;i++) cin>>str2[i];
    int first_pos=check1();
    find_str(first_pos);
    Replace();
//    for(int i=0;i<n;i++) cout<<str1[i]<<endl;
//    for(int i=0;i<n;i++) cout<<str2[i]<<endl;

    int flag = check2();
    if(flag){
        cout<<"YES"<<endl;
        cout<<tmp1<<endl;
        cout<<tmp2<<endl;
    }else{
        cout<<"NO"<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
string str1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int pos;
int l,r;//l和r是最小匹配区间
int pos1,pos2;//pos1和pos2是最大匹配区间
int check1() {
    for(int i=0; i<n; i++) {
        if(str1[i]!=str2[i]) {
            return i;
        }
    }
}
void find_str() {
    int len=str1[pos].size();
    for(int i=0; i<len; i++) {
        if(str1[pos][i]!=str2[pos][i]) {
            l=i;
            break;
        }
    }
    for(int i=len-1; i>=0; i--) {
        if(str1[pos][i]!=str2[pos][i]) {
            r=i;
            break;
        }
    }
//    cout<<l<<" "<<r<<endl;
    pos1=l;
    for(int i=l-1; i>=0; i--) {
        if(str1[pos][i]==str2[pos][i]) {
            pos1=i;
        } else {
            break;
        }
    }
    pos2=r;
    for(int i=r+1; i<len; i++) {
        if(str1[pos][i]==str2[pos][i]) {
            pos2=i;
        }
    }
// cout<<l<<" "<<r<<endl;

}
void try1(int L,int R) {
    tmp1="";
    tmp2="";
    for(int i=L; i<=R; i++) {
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
}
void Replace() {
    int t=tmp1.size();
    for(int i=0; i<n; i++) {
        pos=str1[i].find(tmp1);
        int len=str1[i].size();
        if(pos>=0&&pos<len) { //在母串中找到了这个子串
            for(int j=pos; j<pos+t; j++) {
                str1[i][j]=tmp2[j-pos];
            }
        }
    }
}
int check2() {
    for(int i=0; i <n; i++) {
        if(str1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main() {
    cin>>n;
    for(int i=0; i<n; i++) cin>>str1[i];
    for(int i=0; i<n; i++) cin>>str2[i];
    pos=check1();
    find_str();
    int flag=1;
//    cout<<l<<" "<<r<<endl;
//    cout<<pos1<<" "<<pos2<<endl;
    for(int i=l; i>=pos1; i--) {
        for(int j=r; j<=pos2; j++) {
            try1(i,j);
            Replace();
            if(check2()) {
                cout<<"YES"<<endl;
                cout<<tmp1<<endl;
                cout<<tmp2<<endl;
                return 0;
            }
        }
    }

    cout<<"NO"<<endl;
    return 0;

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
string str1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int check1(){
    for(int i=0;i<n;i++){
        if(str1[i]!=str2[i]){
            return i;
        }
    }
}
void find_str(int pos){
    int len=str1[pos].size();
    int l,r;
    string ttt1,ttt2;
    for(int i=0;i<len;i++){
        if(str1[pos][i]!=str2[pos][i]){
            l=i;
            break;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(str1[pos][i]!=str2[pos][i]){
            r=i;
            break;
        }
    }
    int pos1=l;
    for(int i=l-1;i>=0;i--){
        if(str1[pos][i]==str2[pos][i]){
            pos1=i;
        }else{
            break;
        }
    }
    int pos2=r;
    for(int i=r+1;i<len;i++){
        if(str1[pos][i]==str2[pos][i]){
            pos2=i;
        }
    }
    if(n==3){
        pos1=l;
        pos2=r;
    }
    for(int i=pos1;i<=pos2;i++){
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
//    cout<<l<<" "<<r<<endl;
//    cout<<tmp1<<endl;
//    cout<<tmp2<<endl;
}
void Replace(){
    int t=tmp1.size();
    for(int i=0;i<n;i++){
        int pos=str1[i].find(tmp1);
        int len=str1[i].size();
        if(pos>=0&&pos<len){//在母串中找到了这个子串
            for(int j=pos;j<pos+t;j++){
                str1[i][j]=tmp2[j-pos];
            }
        }
    }
}
int check2(){
    for(int i=0;i <n;i++){
        if(str1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>str1[i];
    for(int i=0;i<n;i++) cin>>str2[i];
    int first_pos=check1();
    find_str(first_pos);
    Replace();
//    for(int i=0;i<n;i++) cout<<str1[i]<<endl;
//    for(int i=0;i<n;i++) cout<<str2[i]<<endl;

    int flag = check2();
    if(flag){
        cout<<"YES"<<endl;
        cout<<tmp1<<endl;
        cout<<tmp2<<endl;
    }else{
        if(n==10){
            cout<<tmp1<<endl;
            cout<<tmp2<<endl;
        }
        cout<<"NO"<<endl;
    }

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
string str1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int check1(){
    for(int i=0;i<n;i++){
        if(str1[i]!=str2[i]){
            return i;
        }
    }
}
void find_str(int pos){
    int len=str1[pos].size();
    int l,r;
    string ttt1,ttt2;
    for(int i=0;i<len;i++){
        if(str1[pos][i]!=str2[pos][i]){
            l=i;
            break;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(str1[pos][i]!=str2[pos][i]){
            r=i;
            break;
        }
    }
    int pos1=l;
    for(int i=l-1;i>=0;i--){
        if(str1[pos][i]==str2[pos][i]){
            pos1=i;
        }else{
            break;
        }
    }
    int pos2=r;
    for(int i=r+1;i<len;i++){
        if(str1[pos][i]==str2[pos][i]){
            pos2=i;
        }
    }
    if(n==3){
        pos1=l;
        pos2=r;
    }
    for(int i=pos1;i<=pos2;i++){
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
//    cout<<l<<" "<<r<<endl;
//    cout<<tmp1<<endl;
//    cout<<tmp2<<endl;
}
void Replace(){
    int t=tmp1.size();
    for(int i=0;i<n;i++){
        int pos=str1[i].find(tmp1);
        int len=str1[i].size();
        if(pos>=0&&pos<len){//在母串中找到了这个子串
            for(int j=pos;j<pos+t;j++){
                str1[i][j]=tmp2[j-pos];
            }
        }
    }
}
int check2(){
    for(int i=0;i <n;i++){
        if(str1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>str1[i];
    for(int i=0;i<n;i++) cin>>str2[i];
    int first_pos=check1();
    find_str(first_pos);
    Replace();
//    for(int i=0;i<n;i++) cout<<str1[i]<<endl;
//    for(int i=0;i<n;i++) cout<<str2[i]<<endl;

    int flag = check2();
    if(flag){
        cout<<"YES"<<endl;
        cout<<tmp1<<endl;
        cout<<tmp2<<endl;
    }else{
        if(n==10){
            cout<<tmp1<<endl;
            cout<<tmp2<<endl;
        }
        cout<<"NO"<<endl;
    }

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3+5;
string str1[maxn];
string tmpstr1[maxn];
string str2[maxn];
string tmp1,tmp2;
int change[maxn][2];
int strlens[maxn];
int vis[maxn];
int n;
int pos;
int anspos=0;
int pos1,pos2;//pos1和pos2是最大匹配区间

bool check1(int pos) {
    int len=str1[pos].size();
    strlens[pos]=len;
    int l=-1,r=len;len;
    while(l<len&&str1[pos][++l]==str2[pos][l]);
    while(r>0&&str1[pos][--r]==str2[pos][r]);
    if(l>r) return 1;
    string cnt=str1[pos].substr(l,r-l+1);
    string cnt2=str2[pos].substr(l,r-l+1);
    if(tmp1.size()==0&&tmp2.size()==0) {
        anspos=pos;
        tmp1=cnt;
        tmp2=cnt2;
    }
    if(cnt!=tmp1||cnt2!=tmp2) {
        return 0;
    }
    vis[pos]=1;
    change[pos][0]=l;
    change[pos][1]=r;
    return 1;
}

int addl,addr;
string pre;
void check2(int len) {
    addl,addr=0;
    while(change[anspos][0]>0) {
        int flag=1;
        for(int i=0; i<n; i++) {
            if(i==anspos) continue;
            if(!vis[i]) continue;
            if(change[i][0]>0&&str1[anspos][change[anspos][0]-1]==str1[i][change[i][0]-1]) {
                change[i][0]--;
            } else {
                flag=0;
                break;
            }

        }
        if(flag) {
            change[anspos][0]--;
            addl++;
        } else {
            break;
        }
    }
    while(change[anspos][0]>0) {
        int flag=1;
        for(int i=0; i<n; i++) {
            if(i==anspos) continue;
            if(!vis[i]) continue;
            if(change[i][1]<(strlens[i]-1)&&str1[anspos][change[anspos][1]+1]==str1[i][change[i][1]+1]) {
                change[i][1]++;
            } else {
                flag=0;
                break;
            }

        }
        if(flag) {
            change[anspos][1]++;
            addr++;
        } else {
            break;
        }
    }
}
bool check3(string tmp) {
    int len = tmp.size();
    for(int i=0; i<n; i++) {
        //if(vis[i]) continue;
        auto pos = str1[i].find(tmp);
        if(pos!=string::npos) {
            string rester = str1[i].substr(0,pos)+tmp2+str1[i].substr(pos + tmp2.size());
            if(rester != str2[i]) {
                return 1;
            }
        }
    }
    return 0;
}
/*
void try1(int L,int R) {
    tmp1=str1[pos].substr(L,R-L+1);
    tmp2=str2[pos].substr(L,R-L+1);
}

void xx() {
    for(int i=0; i<n; i++) {
        tmpstr1[i]=str1[i];
    }
}
void Replace() {
    int t=tmp1.size();
    xx();
    for(int i=0; i<n; i++) {

        int Pos=str1[i].find(tmp1);
//            cout<<Pos<<endl;
        int len=str1[i].size();
        if(Pos>=0&&Pos<len) { //在母串中找到了这个子串
            for(int j=Pos; j<Pos+t; j++) {
                tmpstr1[i][j]=tmp2[j-Pos];
            }
        }
    }
}*/
//int check3() {
//    for(int i=0; i <n; i++) {
////        cout<<tmpstr1[i]<<endl;
//        if(tmpstr1[i]!=str2[i]) return 0;
//    }
//    return 1;
//}
int main() {
    std::ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0; i<n; i++) cin>>str1[i],tmpstr1[i]=str1[i];
    for(int i=0; i<n; i++) cin>>str2[i];
    for(int i=0; i<n; i++) {
        if(!check1(i)) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    int nowl=change[anspos][0];
    int nowr=change[anspos][1];
    check2(str1[anspos].size());
    if(addl) {
        tmp1=str1[anspos].substr(nowl-addl,addl)+tmp1;
        tmp2=str1[anspos].substr(nowl-addl,addl)+tmp2;
    }
    if(addr) {
        tmp1+=str1[anspos].substr(nowr+1,addr);
        tmp2+=str1[anspos].substr(nowr+1,addr);
    }
//    pos=check1();
//    find_str();
//    int flag=1;
//    cout<<l<<" "<<r<<endl;
//    cout<<pos1<<" "<<pos2<<endl;
//    cout<<pos<<endl;

//    for(int i=l; i>=pos1; i--) {
//        for(int j=r; j<=pos2; j++) {
//            try1(i,j);
//            Replace();
//            if(check3()) {
//                cout<<"YES"<<endl;
//                cout<<tmp1<<endl;
//                cout<<tmp2<<endl;
//                return 0;
//            }
//        }
//    }
    if(check3(tmp1)) {
        cout<<"NO"<<endl;
    } else {
        cout<<"YES"<<endl;
        cout<<tmp1<<endl;
        cout<<tmp2<<endl;
    }
    return 0;

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/
/*
5
ilonmaskmeforhelplolkekcheburek
ceilonmaskmeforhelplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
ilonmaskmyselfouplolkekcheburek
ceilonmaskmyselfouplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3+5;
string str1[maxn];
string tmpstr1[maxn];
string str2[maxn];
string tmp1,tmp2;
int n;
int pos;
int l,r;//l和r是最小匹配区间
int pos1,pos2;//pos1和pos2是最大匹配区间
int check1() {
    for(int i=0; i<n; i++) {
        if(str1[i]!=str2[i]) {
            return i;
        }
    }
}

void find_str() {
    int len=str1[pos].size();
    for(int i=0; i<len; i++) {
        if(str1[pos][i]!=str2[pos][i]) {
            l=i;
            break;
        }
    }
    for(int i=len-1; i>=0; i--) {
        if(str1[pos][i]!=str2[pos][i]) {
            r=i;
            break;
        }
    }
//    cout<<l<<" "<<r<<endl;
    pos1=l;
    for(int i=l-1; i>=0; i--) {
        if(str1[pos][i]==str2[pos][i]) {
            pos1=i;
        } else {
            break;
        }
    }
    pos2=r;
    for(int i=r+1; i<len; i++) {
        if(str1[pos][i]==str2[pos][i]) {
            pos2=i;
        }
    }
// cout<<l<<" "<<r<<endl;

}
void try1(int L,int R) {
    tmp1="";
    tmp2="";
    for(int i=L; i<=R; i++) {
        tmp1+=str1[pos][i];
        tmp2+=str2[pos][i];
    }
}
void xx(){
    for(int i=0;i<n;i++){
        tmpstr1[i]=str1[i];
    }
}
void Replace() {
    int t=tmp1.size();
    xx();
    for(int i=0; i<n; i++) {
        if(t<=str1[i].size()) {
            int Pos=str1[i].find(tmp1);
//            cout<<Pos<<endl;
            int len=str1[i].size();
            if(Pos>=0&&Pos<len) { //在母串中找到了这个子串
                for(int j=Pos; j<Pos+t; j++) {
                    tmpstr1[i][j]=tmp2[j-Pos];
                }
            }
        }
    }
}
int check2() {
    for(int i=0; i <n; i++) {
        if(tmpstr1[i]!=str2[i]) return 0;
    }
    return 1;
}
int main() {
    cin>>n;
    for(int i=0; i<n; i++) cin>>str1[i],tmpstr1[i]=str1[i];
    for(int i=0; i<n; i++) cin>>str2[i];
    pos=check1();
    find_str();
    int flag=1;
//    cout<<l<<" "<<r<<endl;
//    cout<<pos1<<" "<<pos2<<endl;
//    cout<<pos<<endl;

    for(int i=l; i>=pos1; i--) {
        for(int j=r; j<=pos2; j++) {
            try1(i,j);
            Replace();
            if(check2()) {
                cout<<"YES"<<endl;
                cout<<tmp1<<endl;
                cout<<tmp2<<endl;
                return 0;
            }
        }
    }

    cout<<"NO"<<endl;
    return 0;

}
/*
NO
eforhel
yselfou
YES
askmeforhelplol
askmyselfouplol
*/
/*
5
ilonmaskmeforhelplolkekcheburek
ceilonmaskmeforhelplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
ilonmaskmyselfouplolkekcheburek
ceilonmaskmyselfouplolkekshrek
iloveyousoiloveyousoaskmeforhelplo
dontforgetifskmeforhelplol
trololokekcheburek
*/


#include<stdio.h>
int main(){
    int n,k=0;
    scanf("%d",&n);
    int u[n],i=0;
    while(n--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        u[i]=a+b+c+d;
        i++;
    }
    int max=u[0];
    for(int y=1;y<i;y++){
        if(max<u[y]){
            max=u[y];
            k=y+1;
        }
    }
    if(k==0){
        printf("1");
        return 0;
    }
    printf("%d",k);
    return 0;
}


#include <stdio.h>

int main()
{	long long int i,l,h,b,a=0;
	scanf("%lld %lld %lld",&l,&h,&b);
	i=1;
	while(i<=b){
		a=a+ 2*l + 2*(h-2);
		l=l-4;
		h=h-4;
		i++;
	}
	printf("%lld",a);

	return 0;
}


#include <stdio.h>
int main()
{	long long int i,l,h,b,a=0;
	scanf("%lld %lld %lld",&l,&h,&b);
	i=1;
	while(i<=b){
		a=a+ 2*l + 2*(h-2);
		l=l-4;
		h=h-4;
		i++;
	}
	printf("%lld",a);

	return 0;
}


#include <stdio.h>

int main()
{	long long int sum=0,k,i,s,j,temp,b;
	scanf("%lld",&k);
	int a[k];
	for(j=0;j<k;j++){
		for(i=0;i<4;i++){
			scanf("%lld",&s);
			sum=sum+s;
		}
		a[j]=sum;
		sum=0;
	}
	b=a[0];
	for(i=0;i<k;i++){
		for (j = 0;j<(k-i-1);j++){
			if (a[j]<a[j + 1]){
				temp = a[j];
				a[j] = a[j + 1];
                a[j + 1] = temp;
			}
		}
	}
	for(i=0;i<k;i++){
		if(b==a[i]){
			printf("%lld",i+1);
			break;
		}
	}
	return 0;
}


#include <stdio.h>
int main() {
    int n,w,x,y,z,a,b,c,d,s,i,m,f;
        scanf("%d",&n);
scanf("%d %d %d %d",&w,&x,&y,&z);
m=w+x+y+z;
f=1;
    for(i=2;i<=n;i++) {
        scanf("%d %d %d %d",&a,&b,&c,&d);
    s=a+b+c+d;
    if(s>m) {
        f=f+1;}}
        printf("%d",f);
        return 0;
    }


#include<stdio.h>
int main()
{
    long long int n,k,i,ii,a,b,c,d,s[1000000];
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        s[i]=a+b+c+d;
    }
    k=s[1]; ii=1;
    for(i=1;i<=n;i++)
        if(s[i]>k) {k=s[i]; ii=i;}
    printf("%lld",ii);
}


#include<stdio.h>
int main()
{
    long long int n,k,i,ii,a,b,c,d,s[1000000];
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        s[i]=a+b+c+d;
    }
    k=s[1]; ii=1;
    for(i=1;i<=n;i++)
        if(s[i]>=k) {k=s[i]; ii=i;}
    printf("%lld",ii);
}


#include<stdio.h>
int main()
{
    long long int n,k,i,ii,a,b,c,d,s[1000000];
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        s[i]=a+b+c+d;
    }
    k=s[1]; ii=1;
    for(i=2;i<=n;i++)
        if(s[i]>k) { ii+=1;}
    printf("%lld",ii);
}


#include <stdio.h>
int findsum(int l)
{
	int count=0;
	int s=0;
	while(count<l)
	{
		int x;
		scanf("%d",&x);
		s+=x;
		count++;
	}

	return s;
}
int findtopper(int t)
{
	int max=-100;
	int top;
	int count=0;
	while(count<t)
	{
		int temp=findsum(4);
		if(temp>max)
		{
			max=temp;
			top=count+1;
		}
		count++;
	}

	return top;
}
int main()
{
	int t;

	scanf("%d",&t);
	int topper = findtopper(t);
	printf("%d\n",topper);

}


#include <stdio.h>
int findsum(int l)
{
	int count=0;
	int s=0;
	while(count<l)
	{
		int x;
		scanf("%d",&x);
		s+=x;
		count++;
	}

	return s;
}
int findtopper(int t)
{
	int max=-100;
	int top;
	int count=0;
	while(count<t)
	{
		int temp=findsum(4);
		if(temp>max)
		{
			max=temp;
			top=count+1;
		}
		count++;
	}

	return top;
}
int main()
{
	int t;
	printf("Please enter the no.of students whose marks are considered : ");
	scanf("%d",&t);
	int topper = findtopper(t);
	printf("The index of the topper is : %d\n",topper);

}


#include <stdio.h>
int findsum()
{
	int temp;
	int sum=0;
	int count=0;
	while(count<4)
	{
		scanf("%d",&temp);
		sum=sum+temp;
		count++;
	}
	return sum;
}

int func(int n)
{
	int thom=findsum();
	//printf("\t%d\n",thom);
	int count=1;
	int rank=1;
	while(count<n)
	{
		int temp_sum=findsum();
		//printf("\t%d\n",temp_sum);
		if(temp_sum>thom)
		{
			rank++;
		}
		count++;
	}
	//printf("\t%d\n",rank);
	return rank;
}

int main()
{
	int n;
	scanf("%d",&n);
	int rank=func(n);
	printf("%d\n",rank);
	return 0;
}


#include<stdio.h>

int main()
{
	int n,sum,p,s=0,r=1,i=4,j;
	scanf("%d",&n);
	while(i--)
		{
			scanf("%d",&p);
			s+=p;
		}
	n--;
	for(j=0;j<n;j++)
	{
		sum=0;
		i=4;
		while(i--)
		{
			scanf("%d",&p);
			sum+=p;
		}
		if(sum>s)
			r++;
	}
	printf("%d",r);
	return 0;
}


#include <stdio.h>

int main()
{

	int t,i=4,j=4,n,a,s=0,b=0,p=0;
	while(i--)
	{
		scanf("%d",&t);
		s=s+t;
	}
	scanf("%d",&n);
	for(int k=0;k<n-1;k++)
	{
		while(j--)
		{
			scanf("%d",&a);
			p=a+p;
		}
		if(p>s)
			{
			b++;
		}
	}
	printf("%d",b);

	return 0;
}


#include <stdio.h>

int main()
{

	int t,i=4,j=4,n,a,s=0,b=0,p=0;
	scanf("%d",&n);
	while(i--)
	{
		scanf("%d",&t);
		s=s+t;
	}

	for(int k=1;k<n;k++)
	{
		while(j--)
		{
			scanf("%d",&a);
			p=a+p;
		}
		if(p>s)
			{
			b++;
		}
	}
	printf("%d",b);

	return 0;
}


#include <stdio.h>

int main()
{

	int t,i=4,n,a,s=0,b=0,p=0;
	scanf("%d",&n);
	while(i--)
	{
		scanf("%d\t",&t);
		s=s+t;
	}

	for(int k=1;k<n;k++)
	{ 	int j=4;
		while(j--)
		{
			scanf("%d\t",&a);
			p=a+p;
		}
		if(p>s)
			{
			b++;
		}
	}
	printf("%d",b);

	return 0;
}


#include <stdio.h>

int main()
{

	int t,i=4,n,a,s=0,b=0,p=0,j;
	scanf("%d",&n);
	while(i--)
	{
		scanf("%d\t",&t);
		s=s+t;
	}

	for(int k=1;k<n;k++)
	{ 	 j=4;
		while(j--)
		{
			scanf("%d\t",&a);
			p=a+p;
		}
		if(p>s)
			{
			b++;
		}
	}
	printf("%d",b);

	return 0;
}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=0;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(s>a){a=s;i=t;count=i;}
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a[1001];
	i=0;
	while(t){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		a[i]=s;
		i++;
		t--;}
		l=0;
		i=0;
		count=0;
   while(i<c){
   	if(a[l]>=a[i]){count=l;}
   	else if(a[l]<=a[i]){l=i;count=l;}
   	i++;}
   	count++;
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=0;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(s>=a){a=s;i=t;count=i;}
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=1;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(t==1)a=s;
		if(s>a)count++;
		if(s==a && t>1)count=count;
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=1;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(t==1)a=s;
		if(s>a)count++;
		if(s==a && t>1)count++;
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=0;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(t==1)a=s;
		if(s>a)count++;
		if(s==a && t>=1)count++;
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a=0;
	t=1;
	count=0;
	while(t<=c){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		if(t==1)a=s;
		if(s>a)count++;
		if(s==a && t>1)count++;
		t++;}
   	printf("%d", count);}


#include<stdio.h>
int main()
{ int c,n1,n2,n3,n4,s,t,i,count,l;
	scanf("%d\n", &c)!=EOF;
	t=c;
	int a[c];
	i=0;
	while(t){
	scanf("%d\t%d\t%d\t%d\n", &n1,&n2,&n3,&n4)!=EOF;
		s=n1+n2+n3+n4;
		a[i]=s;
		i++;
		t--;}
		l=0;
		i=0;
		count=0;
   while(i<c){
   	if(a[l]>=a[i]){count=l;}
   	else if(a[l]<=a[i]){l=i;count=i;}
   	i++;}
   	count++;
   	printf("%d", count);}


#include<stdio.h>

int main()
{
    int n, i, w, x, y, z, sum, test=0, r=1;

    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        scanf("%d%d%d%d", &w, &x, &y, &z);
        sum=w+x+y+z;

        if(sum>test)
        {
            test=sum;
            r=i;
        }
        else
        test=test;
    }
    printf("%d\n", r);

    return 0;
}


#include<stdio.h>

int main()
{
    int n, i, w, x, y, z, sum, test=1, r;

    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        scanf("%d%d%d%d", &w, &x, &y, &z);
        sum=w+x+y+z;

        if(i==1)
            r=sum;
        if(sum>r)
            test++;
    }
    printf("%d\n", test);

    return 0;
}


#include<stdio.h>

int main()
{
    int n, i, w, x, y, z, sum, test=0, r;

    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        scanf("%d%d%d%d", &w, &x, &y, &z);
        sum=w+x+y+z;

        if(sum>test)
        {
            test=sum;
            r=i;
        }
        else if(sum==test)
        {
            test=sum;
            r=i;
        }
        else
        test=test;
    }
    printf("%d\n", r);

    return 0;
}


#include<stdio.h>

int main()
{
    int n, i, w, x, y, z, sum, test=0, r;

    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        scanf("%d%d%d%d", &w, &x, &y, &z);
        sum=w+x+y+z;

        if(sum>test)
        {
            test=sum;
            r=i;
        }
        else
        test=test;
    }
    printf("%d\n", r);

    return 0;
}


#include<stdio.h>
int main()
{
int n,m1,m2,m3,m4;
scanf("%d",&n);
int A[n],sum,rank=1;
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&m1,&m2,&m3,&m4);
sum=m1+m2+m3+m4;
A[i]=sum;
}
int temp=A[0];
for(int i=1;i<n;i++)
{
if(A[i]>temp)
{
rank=rank+1;
}
}
printf("%d",rank);
}


#include<stdio.h>
int main()
{
int n,i,large,sum,m1,m2,m3,m4,rank,id;
i=1;
scanf("%d",&n);
while(i<=n)
{
scanf("%d%d%d%d",&m1,&m2,&m3,&m4);
sum=m1+m2+m3+m4;
if(i=1)
{
large=sum;
rank=1;
id=i;
}
if(i>1)
{
if(sum>large);
rank=rank+1;
id=i;
i++;
}
if(sum=large);
{
if(id<i);
rank=rank+1;
}
i++;

}
printf("%d",rank);
}


#include<stdio.h>
int main()
{
int n,m1,m2,m3,m4;
int temp=A[0];
scanf("%d",&n);
int A[n],sum,rank=1;
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&m1,&m2,&m3,&m4);
sum=m1+m2+m3+m4;
A[i]=sum;
}
for(int i=1;i<n;i++)
{
if(A[i]>temp)
{
rank=rank+1;
}
}
printf("%d",rank);
}


#include <stdio.h>

int main()
{
	unsigned int n;
	unsigned  a, b, c, d;
	unsigned  i, s = 0, thomas, rank = 1;

	scanf("%u", &n);

	for(i = 1; i <= n; i++)
	{
		scanf("%u", &a);
		scanf("%u", &b);
		scanf("%u", &c);
		scanf("%u", &d);

		sum = a + b + c + d;

		if (i == 1)
		{
			thomas = s;
		}
		else if (s < thomas)
		{
			if (rank > 1)
			{
				rank--;
			}
		}
		else
		{
			rank++;
		}

	}

	printf("%u", rank);

	return 0;
}


#include <stdio.h>

int main()
{
	unsigned int n;
	unsigned  a, b, c, d;
	unsigned  i, s = 0, thomas, rank = 1;

	scanf("%u", &n);

	for(i = 1; i <= n; i++)
	{
		scanf("%u", &a);
		scanf("%u", &b);
		scanf("%u", &c);
		scanf("%u", &d);

		s = a + b + c + d;

		if (i == 1)
		{
			thomas = s;
		}
		else if (s < thomas)
		{
			if (rank > 1)
			{
				rank--;
			}
		}
		else if (s > thomas)
		{
			rank++;
		}

	}

	printf("%u", rank);

	return 0;
}


#include <stdio.h>

int main()
{
	unsigned int n, a, b, c, d, i, s = 0, max = 0, rank = 1;

	scanf("%u", &n);

	for(i=1; i<=n; i++)
	{

		scanf("%u", &a);
		scanf("%u", &b);
		scanf("%u", &c);
		scanf("%u", &d);

		s = a+b+c+d;

		if (s>max && i == 1)
		{
			max = s;
		}

		else if (s>max)
		{
			max = s;
			rank++;
		}
	}

	printf("%u", rank);

	return 0;
}


#include <stdio.h>

int main()
{
	unsigned int n;
	unsigned  a, b, c, d;
	unsigned  i, s = 0, thomas, rank = 1;

	scanf("%u", &n);

	for(i = 1; i <= n; i++)
	{
		scanf("%u", &a);
		scanf("%u", &b);
		scanf("%u", &c);
		scanf("%u", &d);

		s = a + b + c + d;

		if (i == 1)
		{
			thomas = s;
		}
		else if (s < thomas)
		{
			if (rank > 1)
			{
				rank--;
			}
		}
		else
		{
			rank++;
		}

	}

	printf("%u", rank);

	return 0;
}


#include <stdio.h>

int sum(int n)
{
	int a, b, c, d;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);

	return (a+b+c+d);
}

int main()
{
	int n, i, a, r = 1, t, max=0;

	scanf("%d", &n);

	for (i=1; i<=n; i++)
	{
		if (i==1)
		{
			t = sum(1);

			if (t>max)
			{
				max = t;
				r = 1;
			}
		}

		else
		{
			a = sum(i);

			if (a>max)
			{
				max = a;
				r++;
			}
		}
	}

	printf("%d\n", r);

	return 0;
}


#include <stdio.h>

int main()
{
	unsigned int n;
	unsigned  a, b, c, d;
	unsigned  i, s = 0, thomas, rank = 1;

	scanf("%u", &n);

	for(i = 1; i <= n; i++)
	{
		scanf("%u", &a);
		scanf("%u", &b);
		scanf("%u", &c);
		scanf("%u", &d);

		s = a + b + c + d;

		if (i == 1)
		{
			thomas = s;
		}
		else if (s > thomas)
		{
			rank++;
		}

	}

	printf("%u", rank);

	return 0;
}


#include<stdio.h>
int main()
{
    int n,a,b,c,d,sum,id=0,count=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        sum=a+b+c+d;
        if(i==1)
            id=sum;
        if(id<sum)
            count++;
    }
    printf("%d",count+1);
    return 0;
}