#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;

    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }

    }
    for(int i=1;i<=n;i++)
    {
        string ::size_type loc=inv[i].find(s);
        if(loc!=string::npos)
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];
string coms[MAXN];
string comt[MAXN];
int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf)  //记录每一个串里面分歧的串
            coms[i]=inv[i].substr(dif[i][0],dif[i][1]-dif[i][0]+1),
            comt[i]=rev[i].substr(dif[i][0],dif[i][1]-dif[i][0]+1);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;    //找出有不同的串中总长度最小的串
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    int ma=dif[sta][0];  //记录分歧的开头在s中的下标
    int sl=dif[sta][1]-dif[sta][0]+1;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;

            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                    if(coms[i]!=coms[sta]||comt[i]!=comt[sta]) {flag=0;break;}   //i和sta分歧的地方不同

                    else  //相同的话，尽可能向前后延神
                    {
                        int sb,se;
                        for(j=ma-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)   //向前延神
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=ma+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)  //向后延神
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        ma-=sb;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }

            }

    }
    if(flag){
        for(int i=1;i<=n;i++)   //重新检查一遍答案s
        {

            string ::size_type loc=inv[i].find(s);
            if(dif[i][0]==-1)  //如果没有分歧的串里面找到s,说明不行
            {                  //因为s已经是满足所有分歧的最长的串了
                if(loc!=string::npos) {flag=0;break;}
            }
            else
            {   //如果找到的第一个串不是i串的分歧位置，说明有与分歧重复的串
                //那么也不行，因为s已经是满足所有分歧的最长的串了
                if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                {
                    flag=0;
                    break;
                }
            }

        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;

    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    int ma=dif[sta][0];
    int sl=dif[sta][1]-dif[sta][0]+1;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);
                //string ::size_type lo=s.find(tmp);

                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,ma,sl);
                    string olds(s,ma,sl);
                    /*while(oldt!=rtmp&&lo!=string::npos)
                        lo=s.find(tmp,lo+len),oldt=t.substr(lo,len);*/
                    if(oldt!=rtmp||olds!=tmp) {flag=0;break;}
                    //else if() {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=ma-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=ma+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        ma-=sb;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }

            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            //if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&rev[i].length()<rev[sta].length())
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }

    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


3
babaasdkm
zzabaasdkm
ccabaasdkm
babzwsxkm
zzabzwsxkm
wwabzwsxkm

3
babaasdkm
zzabaasdkm
ccabaasdkmww
babzwsxkm
zzabzwsxkm
ccabzwsxkmzz

3
babaasdkm
zzabaasdkm
ccbaasdk
babzwsxkm
zzabzwsxkm
ccbzwsxk


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;

    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else if(dif[sta][0]<lo||dif[sta][1]>lo+len-1) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;

    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);

                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    while(oldt!=rtmp&&lo!=string::npos)
                        lo=s.find(tmp,lo+len),oldt=t.substr(lo,len);
                    if(oldt!=rtmp||lo==string::npos) {flag=0;break;}
                    //else if() {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            //if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }

    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];
string coms[MAXN];
string comt[MAXN];
int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf)
            coms[i]=inv[i].substr(dif[i][0],dif[i][1]-dif[i][0]+1),
            comt[i]=rev[i].substr(dif[i][0],dif[i][1]-dif[i][0]+1);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    int ma=dif[sta][0];
    int sl=dif[sta][1]-dif[sta][0]+1;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;

            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;

                    /*while(oldt!=rtmp&&lo!=string::npos)
                        lo=s.find(tmp,lo+len),oldt=t.substr(lo,len);*/
                    if(coms[i]!=coms[sta]||comt[i]!=comt[sta]) {flag=0;break;}
                    //else if() {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=ma-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=ma+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        ma-=sb;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }

            }

        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            //if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(dif[i][0]==-1)
            {
                if(loc!=string::npos) {flag=0;break;}
            }
            else
            {
                if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                {
                    flag=0;
                    break;
                }
            }
            /*if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }*/
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;

    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);

                string ::size_type lo=s.find(tmp);
                if(lo==string::npos)
                {
                    flag=0;
                    break;
                }
                else
                {
                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,lo,len);
                    if(oldt!=rtmp) {flag=0;break;}
                    else if(dif[sta][0]<lo||dif[sta][1]>lo+len-1) {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=lo-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=lo+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }
                }
            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            //if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define lson l, mid, cur << 1
#define rson mid + 1, r, cur << 1 | 1
#define lowbit(x) ((x)&(-(x)))
#define bitcnt(x) __builtin_popcount(x)
#define bitcntll(x) __builtin_popcountll(x)
#define succ(x) (1LL<<x)
#define sqr(x) ((x)*(x))
#define Min(a,b) a>=b?b:a;
#define Max(a,b) a>=b?a:b;
#define debug puts("-------------");
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 3e3+100;;

const double pi=acos(-1);

string inv[MAXN];
string rev[MAXN];

int dif[MAXN][2];

bool Pre_cal(int x)
{
    int be,en;
    be=en=-1;
    for(int i=0;i<inv[x].length();i++)
    {
        if(inv[x][i]!=rev[x][i])
        {
            if(be==-1) be=i,en=i;
            else en=i;
        }
    }
    dif[x][0]=be;
    dif[x][1]=en;
    if(be==-1) return true;
    else return false;
}

int main()
{
    IO
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inv[i];
    }
    int sta=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>rev[i];
        int cf=Pre_cal(i);
        if(!cf&&(sta==-1||rev[i].length()<rev[sta].length()))
            sta=i;
    }
    string s=inv[sta];
    string t=rev[sta];
    int flag=1;
    int len,j,k;
    int ma=dif[sta][0];
    int sl=dif[sta][1]-dif[sta][0]+1;
    for(int i=1;i<=n;i++)
    {
        if(i==sta) continue;
        string ::size_type loc=inv[i].find(s);
        if(loc==string::npos)
        {
            if(dif[i][0]!=-1)
            {
                len=dif[i][1]-dif[i][0]+1;
                string tmp(inv[i],dif[i][0],len);
                //string ::size_type lo=s.find(tmp);

                    string rtmp(rev[i],dif[i][0],len);
                    string oldt(t,ma,sl);
                    /*while(oldt!=rtmp&&lo!=string::npos)
                        lo=s.find(tmp,lo+len),oldt=t.substr(lo,len);*/
                    if(oldt!=rtmp) {flag=0;break;}
                    //else if() {flag=0;break;}
                    else
                    {
                        int sb,se;
                        for(j=ma-1,k=dif[i][0]-1;j>=0&&k>=0;j--,k--)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        sb=j+1;
                        for(j=ma+len,k=dif[i][1]+1;j<s.length()&&k<inv[i].length();j++,k++)
                        {
                            if(s[j]==t[j]&&s[j]==inv[i][k]){}
                            else break;
                        }
                        se=j-1;
                        ma-=sb;
                        s=s.substr(sb,se-sb+1);
                        t=t.substr(sb,se-sb+1);
                    }

            }
        }
        /*else
        {
            string tmp(rev[i],loc,s.length());
            if(tmp!=t)  {flag=0;break;}
        }*/

    }
    if(flag){
        for(int i=1;i<=n;i++)
        {
            //if(i==sta) continue;
            string ::size_type loc=inv[i].find(s);
            if(loc!=string::npos)
            {
                string tmp(rev[i],loc,s.length());
                if(tmp!=t)  {flag=0;break;}
                if(dif[i][0]!=-1)
                {
                    if(dif[i][0]<loc||dif[i][1]>loc+s.length()-1)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl<<s<<endl<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n;
int l[3003], r[3003];
string S[3003], T[3003];
string a, b;

int A[3003];
void kmp(string &s, string t, int id)
{
	memset(A, 0, sizeof A);
	int idx = 0;
	// it start with i = 1
	for(int i = 1; i < t.size(); i++)
	{
		while(t[i] != t[idx] && idx) idx = A[idx-1];
		if(t[i] == t[idx]) ++idx;
		A[i] = idx;
	}
	// cout << "TES\n";

	idx = 0;
	for(int i = 0; i < s.size(); i++)
	{
		while(s[i] != t[idx] && idx) idx = A[idx-1];
		if(s[i] == t[idx]) idx++;
		if(idx == t.size())
		{
			int le = i-t.size()+1;
			l[id] = le, r[id] = le+t.size()-1;
			for(int i = 0; i < b.size(); i++)
				s[le+i] = b[i];
			return;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> S[i];
	for(int i = 1; i <= n; i++) cin >> T[i];
	for(int i = 1; i <= n; i++)
	{
		int le = -1, ri = -1;
		for(int j = 0; j < S[i].size(); j++)
		{
			if(S[i][j] != T[i][j])
			{
				le = (le == -1)? j : le;
				ri = j;
			}
		}
		if(le == -1 || a.size() > ri-le+1) continue;

		a = b = "";
		for(int j = le; j <= ri; j++)
			a += S[i][j], b += T[i][j];
	}

	for(int i = 1; i <= n; i++)
	{
		l[i] = r[i] = -1;
		if(S[i] == T[i]) continue;

		string temp = S[i];
		kmp(S[i],a,i);

		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
		S[i] = temp;
	}

	while(1)
	{
		bool bol = 1;
		int idx = -1;
		for(int i = 1; i <= n; i++)
		{
			if(r[i] == -1) continue;
			if(idx == -1) idx = i;
			if(r[idx] == S[idx].size()-1 || r[i] == S[i].size()-1 || S[idx][r[idx]+1] != S[i][r[i]+1])
				bol = 0;
		}
		if(!bol) break;
		a += S[idx][r[idx]+1];
		b += S[idx][r[idx]+1];
		for(int i = 1; i <= n; i++)
			if(r[i] != -1)
				r[i]++;
	}

	while(1)
	{
		bool bol = 1;
		int idx = -1;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] == -1) continue;
			if(idx == -1) idx = i;
			if(l[idx] == 0 || l[i] == 0 || S[idx][l[idx]-1] != S[i][l[i]-1])
				bol = 0;
		}
		if(!bol) break;
		a = S[idx][l[idx]-1]+a;
		b = S[idx][l[idx]-1]+b;
		for(int i = 1; i <= n; i++)
			if(l[i] != -1)
				l[i]--;
	}
	// cout << a << " " << b << "\n";

	for(int i = 1; i <= n; i++)
	{
		kmp(S[i], a, i);
		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
	}

	cout << "YES\n" + a + "\n" + b + "\n";
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n;
int fi;
int l[3003], r[3003];
string S[3003], T[3003];
string a, b;

int A[3003];
void kmp(string &s, string t, int id)
{
	memset(A, 0, sizeof A);
	int idx = 0;
	// it start with i = 1
	for(int i = 1; i < t.size(); i++)
	{
		while(t[i] != t[idx] && idx) idx = A[idx-1];
		if(t[i] == t[idx]) ++idx;
		A[i] = idx;
	}
	// cout << "TES\n";

	idx = 0;
	for(int i = 0; i < s.size(); i++)
	{
		while(s[i] != t[idx] && idx) idx = A[idx-1];
		if(s[i] == t[idx]) idx++;
		if(idx == t.size())
		{
			int le = i-t.size()+1;
			l[id] = le, r[id] = le+t.size()-1;
			for(int i = 0; i < b.size(); i++)
				s[le+i] = b[i];
			return;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> S[i];
	for(int i = 1; i <= n; i++) cin >> T[i];
	for(int i = 1; i <= n; i++)
	{
		l[i] = r[i] = -1;
		for(int j = 0; j < S[i].size(); j++)
		{
			if(S[i][j] != T[i][j])
			{
				l[i] = (l[i] == -1)? j : l[i];
				r[i] = j;
			}
		}
		if(l[i] == -1) continue;

		if(!fi) fi = i;
		a = S[i].substr(l[i], r[i]-l[i]+1);
		b = T[i].substr(l[i], r[i]-l[i]+1);

		if(a != S[fi].substr(l[fi], r[fi]-l[fi]+1) || b != T[fi].substr(l[fi], r[fi]-l[fi]+1))
		{

			cout << "NO\n";
			return 0;
		}
	}

	while(1)
	{
		bool bol = 1;
		for(int i = 1; i <= n; i++)
		{
			if(r[i] == -1) continue;
			if(r[fi] == S[fi].size()-1 || r[i] == S[i].size()-1 || S[fi][r[fi]+1] != S[i][r[i]+1])
				bol = 0;
		}
		if(!bol) break;

		for(int i = 1; i <= n; i++)
			if(r[i] != -1)
				r[i]++;
	}

	while(1)
	{
		bool bol = 1;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] == -1) continue;
			if(l[fi] == 0 || l[i] == 0 || S[fi][l[fi]-1] != S[i][l[i]-1])
				bol = 0;
		}
		if(!bol) break;
		for(int i = 1; i <= n; i++)
			if(l[i] != -1)
				l[i]--;
	}
	a = S[fi].substr(l[fi], r[fi]-l[fi]+1);
	b = T[fi].substr(l[fi], r[fi]-l[fi]+1);

	for(int i = 1; i <= n; i++)
	{
		kmp(S[i], a, i);
		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
	}

	cout << "YES\n" + a + "\n" + b + "\n";
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n;
string S[100003], T[100003];
string a, b;

int A[100003];
void kmp(string &s, string t)
{
	int idx = 0;
	// it start with i = 1
	for(int i = 1; i < t.size(); i++)
	{
		while(t[i] != t[idx] && idx) idx = A[idx-1];
		if(t[i] == t[idx]) ++idx;
		A[i] = idx;
	}
	// cout << "TES\n";

	idx = 0;
	for(int i = 0; i < s.size(); i++)
	{
		while(s[i] != t[idx] && idx) idx = A[idx-1];
		if(s[i] == t[idx]) idx++;
		if(idx == t.size())
		{
			int le = i-t.size()+1;
			for(int i = 0; i < b.size(); i++)
				s[le+i] = b[i];

			return;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> S[i];
	for(int i = 1; i <= n; i++) cin >> T[i];
	for(int i = 1; i <= n; i++)
	{
		int le = -1, ri = -1;
		for(int j = 0; j < S[i].size(); j++)
		{
			if(S[i][j] != T[i][j])
			{
				le = (le == -1)? j : le;
				ri = j;
			}
		}
		if(le == -1 || a.size() > ri-le+1) continue;

		a = b = "";
		for(int j = le; j <= ri; j++)
			a += S[i][j], b += T[i][j];
	}

	for(int i = 1; i <= n; i++)
	{
		kmp(S[i],a);

		// cout << "I : " << i << "\n";
		// cout << S[i] << "\n";

		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n" + a + "\n" + b + "\n";
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n;
int l[3003], r[3003];
string temp[3003];
string S[3003], T[3003];
string a, b;

int A[100003];
void kmp(string &s, string t, int id)
{
	int idx = 0;
	// it start with i = 1
	for(int i = 1; i < t.size(); i++)
	{
		while(t[i] != t[idx] && idx) idx = A[idx-1];
		if(t[i] == t[idx]) ++idx;
		A[i] = idx;
	}
	// cout << "TES\n";

	idx = 0;
	for(int i = 0; i < s.size(); i++)
	{
		while(s[i] != t[idx] && idx) idx = A[idx-1];
		if(s[i] == t[idx]) idx++;
		if(idx == t.size())
		{
			int le = i-t.size()+1;
			l[id] = le, r[id] = le+t.size()-1;
			for(int i = 0; i < b.size(); i++)
				s[le+i] = b[i];
			return;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> S[i];
	for(int i = 1; i <= n; i++) cin >> T[i];
	for(int i = 1; i <= n; i++)
	{
		int le = -1, ri = -1;
		for(int j = 0; j < S[i].size(); j++)
		{
			if(S[i][j] != T[i][j])
			{
				le = (le == -1)? j : le;
				ri = j;
			}
		}
		if(le == -1 || a.size() > ri-le+1) continue;

		a = b = "";
		for(int j = le; j <= ri; j++)
			a += S[i][j], b += T[i][j];
	}

	for(int i = 1; i <= n; i++)
	{
		l[i] = r[i] = -1;
		if(S[i] == T[i]) continue;

		temp[i] = S[i];
		kmp(S[i],a,i);

		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
		S[i] = temp[i];
	}

	while(1)
	{
		bool bol = 1;
		int idx = -1;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] == -1) continue;
			if(idx == -1 && r[i] != -1) idx = i;
			if(r[idx] == S[idx].size()-1 || r[i] == S[i].size()-1 || S[idx][r[idx]+1] != S[i][r[i]+1])
				bol = 0;
		}
		if(!bol) break;
		a += S[idx][r[idx]+1];
		b += S[idx][r[idx]+1];
		for(int i = 1; i <= n; i++)
		{
			if(r[i] != -1)
				r[i]++;
		}
	}

	while(1)
	{
		bool bol = 1;
		int idx = -1;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] == -1) continue;
			if(idx == -1) idx = i;
			if(l[idx] == 0 || l[i] == 0 || S[idx][l[idx]-1] != S[i][l[i]-1])
				bol = 0;
		}
		if(!bol) break;
		a = S[idx][l[idx]-1]+a;
		b = S[idx][l[idx]-1]+b;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] != -1)
				l[i]--;
		}
	}
	// cout << a << " " << b << "\n";

	for(int i = 1; i <= n; i++)
	{
		kmp(S[i], a, i);
		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
	}

	// for(int i = 1; i <= n; i++)
	// 	cout << l[i] << " " << r[i] << "\n";

	cout << "YES\n" + a + "\n" + b + "\n";
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n;
int fi;
int l[3003], r[3003];
string S[3003], T[3003];
string a, b;

int A[3003];
void kmp(string &s, string t, int id)
{
	memset(A, 0, sizeof A);
	int idx = 0;
	// it start with i = 1
	for(int i = 1; i < t.size(); i++)
	{
		while(t[i] != t[idx] && idx) idx = A[idx-1];
		if(t[i] == t[idx]) ++idx;
		A[i] = idx;
	}
	// cout << "TES\n";

	idx = 0;
	for(int i = 0; i < s.size(); i++)
	{
		while(s[i] != t[idx] && idx) idx = A[idx-1];
		if(s[i] == t[idx]) idx++;
		if(idx == t.size())
		{
			int le = i-t.size()+1;
			l[id] = le, r[id] = le+t.size()-1;
			for(int i = 0; i < b.size(); i++)
				s[le+i] = b[i];
			return;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> S[i];
	for(int i = 1; i <= n; i++) cin >> T[i];
	for(int i = 1; i <= n; i++)
	{
		l[i] = r[i] = -1;
		for(int j = 0; j < S[i].size(); j++)
		{
			if(S[i][j] != T[i][j])
			{
				l[i] = (l[i] == -1)? j : l[i];
				r[i] = j;
			}
		}
		if(l[i] == -1) continue;

		if(!fi) fi = i;
		a = S[i].substr(l[i], r[i]-l[i]+1);
		b = T[i].substr(l[i], r[i]-l[i]+1);

		if(a != S[fi].substr(l[fi], r[fi]-l[fi]+1) || b != T[fi].substr(l[fi], r[fi]-l[fi]+1))
		{

			cout << "NO\n";
			return 0;
		}
	}

	while(1)
	{
		bool bol = 1;
		for(int i = 1; i <= n; i++)
		{
			if(r[i] == -1) continue;
			if(r[fi] == S[fi].size()-1 || r[i] == S[i].size()-1 || S[fi][r[fi]+1] != S[i][r[i]+1])
				bol = 0;
		}
		if(!bol) break;

		for(int i = 1; i <= n; i++)
			if(r[i] != -1)
				r[i]++;
	}

	while(1)
	{
		bool bol = 1;
		int fi = -1;
		for(int i = 1; i <= n; i++)
		{
			if(l[i] == -1) continue;
			if(l[fi] == 0 || l[i] == 0 || S[fi][l[fi]-1] != S[i][l[i]-1])
				bol = 0;
		}
		if(!bol) break;
		for(int i = 1; i <= n; i++)
			if(l[i] != -1)
				l[i]--;
	}
	a = S[fi].substr(l[fi], r[fi]-l[fi]+1);
	b = T[fi].substr(l[fi], r[fi]-l[fi]+1);

	for(int i = 1; i <= n; i++)
	{
		kmp(S[i], a, i);
		if(S[i] != T[i])
		{
			cout << "NO\n";
			return 0;
		}
	}

	cout << "YES\n" + a + "\n" + b + "\n";
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1()
{
//	printf("np: %d %d %d\n",nl,a[1].second,a[2].second);
	for(register int i=1;i<=cnta;i++)
	{
		if(a[i].second==0)return 0;
	}
//	printf("rua1\n");
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second-1]!=S[0][a[1].first][a[1].second-1])return 0;
	}
//	printf("rua2\n");
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

//	printf("%d %d\n",fp,lp);

	L=lp-fp+1;
	while(hf(L+1))L++;
	while(hf1())L++,fp--;

//	printf("%d %d\n",fp,lp);

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i])-1;
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second-1;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1,tp;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)tp=n-1;else tp=st-1;
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

	L=lp-fp+1;
	while(hf(L+1))L++;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)if(i1!=p1)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1()
{
//	printf("np: %d %d %d\n",nl,a[1].second,a[2].second);
	for(register int i=1;i<=cnta;i++)
	{
		if(a[i].second==0)return 0;
	}
//	printf("rua1\n");
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second-1]!=S[0][a[1].first][a[1].second-1])return 0;
	}
//	printf("rua2\n");
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

//	printf("%d %d\n",fp,lp);

	L=lp-fp+1;
	while(hf(L+1))L++;
	while(hf1())L++,fp--;

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i])-1;
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second+L-2;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
bool init()
{
	int fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	printf("YES\n");
	for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
	for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		if(a[i].second<nl)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second-1]!=S[0][a[1].first][a[1].second-1])return 0;
	}
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

	L=lp-fp+1;
	while(hf(L+1))L++;
	int zy=0;
	while(hf1(zy+1))zy++,L++,fp--;

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i]);
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second-1;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1()
{
//	printf("np: %d %d %d\n",nl,a[1].second,a[2].second);
	for(register int i=1;i<=cnta;i++)
	{
		if(a[i].second==0)return 0;
	}
//	printf("rua1\n");
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second-1]!=S[0][a[1].first][a[1].second-1])return 0;
	}
//	printf("rua2\n");
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

//	printf("%d %d\n",fp,lp);

	L=lp-fp+1;
	while(hf(L+1))L++;
	while(hf1())L++,fp--;

//	printf("%d %d\n",fp,lp);

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i]);
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second-1;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=strlen(S[0][a[i].first]);
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1(int nl)
{
//	printf("np: %d %d %d\n",nl,a[1].second,a[2].second);
	for(register int i=1;i<=cnta;i++)
	{
		if(a[i].second<nl)return 0;
	}
//	printf("rua1\n");
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second-1]!=S[0][a[1].first][a[1].second-1])return 0;
	}
//	printf("rua2\n");
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

//	printf("%d %d\n",fp,lp);

	L=lp-fp+1;
	while(hf(L+1))L++;
	int zy=0;
	while(hf1(1))zy++,L++,fp--;

//	printf("%d %d\n",fp,lp);

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i]);
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second-1;

	if(chk())
	{
//		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
bool chk()
{
	L=lp-fp+1;
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int st=-1,tp;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)tp=n-1;else tp=st-1;
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}
	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char S[2][3005][3005];
int n;
int fp,lp,p1;
int cnta=0;
pair<int,int> a[1000005];
bool init()
{
	fp=-1,lp=-1,p1=0;
	for(register int i1=1;i1<=n;i1++)
	{
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)if(S[0][i1][i]!=S[1][i1][i])lp=i;
		for(register int i=l-1;i>=0;i--)if(S[0][i1][i]!=S[1][i1][i])fp=i;
		if(fp!=-1)
		{
			p1=i1;
			break;
		}
	}
	cnta++,a[cnta].first=p1,a[cnta].second=fp;
//	printf("%d %d %d\n",p1,fp,lp);
	for(register int i1=1;i1<=n;i1++)if(i1!=p1)
	{
		int st=-1;
		int l=strlen(S[0][i1]);
		for(register int i=0;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])
			{
				st=i;
				break;
			}
		}
		if(st==-1)continue;
		cnta++,a[cnta].first=i1,a[cnta].second=st;
		for(register int i=0;i<=lp-fp;i++)
		{
			if(S[0][i1][st+i]!=S[0][p1][fp+i])return 0;
			if(S[1][i1][st+i]!=S[1][p1][fp+i])return 0;
		}
		for(register int i=st+lp-fp+1;i<l;i++)
		{
			if(S[0][i1][i]!=S[1][i1][i])return 0;
		}
	}
	return 1;
}
char str[1000005];
int L=0;
int fr[1000005];
int anslen[1000005];
bool chk()
{
	for(register int i=1;i<=L;i++)
		str[i]=S[0][p1][fp+i-1];
	lp=fp+L-1;
	fr[1]=0;
	for(register int i=2;i<=L;i++)
	{
		int lp=fr[i-1];
		while(lp&&str[lp+1]!=str[i])
		{
			lp=fr[lp];
		}
		if(str[lp+1]==str[i])lp++;
		fr[i]=lp;
	}

	for(register int i1=1;i1<=n;i1++)
	{
		int tp=anslen[i1];
		int np=0;
		for(register int i=0;i<=tp;i++)
		{
			while(np&&str[np+1]!=S[0][i1][i])np=fr[np];
			if(str[np+1]==S[0][i1][i])np++;
			if(np==L)return 0;
		}
	}
	return 1;
}
int LL[10005];
bool hf(int nl)
{
	for(register int i=1;i<=cnta;i++)
	{
		int l=LL[a[i].first];
		if(a[i].second+nl-1>l-1)return 0;
	}
	for(register int i=2;i<=cnta;i++)
	{
		if(S[0][a[i].first][a[i].second+nl-1]!=S[0][a[1].first][a[1].second+nl-1])return 0;
	}
	return 1;
}

bool hf1()
{
//	printf("np: %d %d %d\n",nl,a[1].second,a[2].second);
	if(a[1].second==0)return 0;
	char nc=S[0][a[1].first][a[1].second-1];
	for(register int i=2;i<=cnta;i++)
	{
		if(a[i].second==0)return 0;
		if(S[0][a[i].first][a[i].second-1]!=nc)return 0;
	}
	for(register int i=1;i<=cnta;i++)a[i].second--;
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",S[0][i]);
	for(int i=1;i<=n;i++)scanf("%s",S[1][i]);
	for(int i=1;i<=n;i++)
		LL[i]=strlen(S[0][i]);
	if(!init())
	{
		printf("NO\n");
		return 0;
	}

//	printf("%d %d\n",fp,lp);

	L=lp-fp+1;
	while(hf(L+1))L++;
	while(hf1())L++,fp--;

	for(register int i=1;i<=n;i++)anslen[i]=strlen(S[0][i])-1;
	for(register int i=1;i<=cnta;i++)anslen[a[i].first]=a[i].second+L-2;

	if(chk())
	{
		printf("YES\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[0][p1][i]);printf("\n");
		for(register int i=fp;i<=lp;i++)printf("%c",S[1][p1][i]);printf("\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];
string s,t;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	rep(i,0,N) {
		int l=-1,r=-1;
		rep(j,0,sz(w[i])) {
			if (w[i][j]!=nw[i][j]) {
				if (l==-1) l=j;
				r=j;
			}
		}
		if (l!=-1 && r-l+1>sz(s)) {
			s=w[i].substr(l,r-l+1);
			t=nw[i].substr(l,r-l+1);
		}
	}

	assert(!s.empty());

	rep(i,0,N) {
		size_t p=w[i].find(s);
		if (p!=string::npos) {
			rep(j,0,sz(s)) w[i][p+j]=t[j];
		}

		if (w[i]!=nw[i]) {
			cout<<"NO\n";
			return 0;
		}
	}

	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] &&
		nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) &&
		w[0][r+k]==w[i][pos+k] &&
		nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	string A=w[0].substr(l,len);
	string B=nw[0].substr(l,len);

	rep(i,1,N) {
		string ns=w[i];

		int l2=kmp[l].find(sub[l],len,ns);
		if (l2==-1) {
			if (ns!=nw[i]) no();
			continue;
		}

		rep(j,0,len) ns[l2+j]=nw[0][l+j];

		if (ns!=nw[i]) continue;

		string a=w[i].substr(l2,len);
		string b=nw[i].substr(l2,len);

		if (A!=a || B!=b) no();

		int fl=find_l(l,l2,i);
		int fr=find_r(r,l2+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	rep(i,0,N) {
		int l=0;
		while (l<sz(w[i]) && w[i][l]==nw[i][l]) l++;

		int r=sz(w[i])-1;
		while (r>=0 && w[i][r]==nw[i][r]) r--;

		if (l<sz(w[i])) {
			if (i!=0) {
				swap(w[0],w[i]);
				swap(nw[0],nw[i]);
			}
			solve(l,r);
			break;
		}
	}
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];
string sub[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] &&
		nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) &&
		w[0][r+k]==w[i][pos+k] &&
		nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		size_t pos=ns.find(sub[l].substr(0, len));
		if (pos!=string::npos) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) sub[i]=w[0].substr(i);

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,0,N) {
		string ns=w[i];

		size_t pos=ns.find(sub[l].substr(0,len));
		if (pos==string::npos) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,int(pos),i);
		int fr=find_r(r,int(pos)+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	int best_i=-1,best_l=-1,best_r=-1;
	rep(i,0,N) {
		int l=-1,r=-1;
		rep(j,0,sz(w[i])) {
			if (w[i][j]!=nw[i][j]) {
				if (l==-1) l=j;
				r=j;
			}
		}

		if (l==-1) continue;

		if (best_i==-1 || r-l+1>best_r-best_l+1) {
			best_i=i;
			best_l=l;
			best_r=r;
		}
	}

	swap(w[0],w[best_i]);
	swap(nw[0],nw[best_i]);

	solve(best_l,best_r);
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];
string sub[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] && nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(w[0]) && pos+k<sz(w[i]) &&
		w[0][r+k]==w[i][pos+k] && nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		size_t pos=ns.find(sub[l].substr(0,len));
		if (pos!=string::npos) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}
		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) sub[i]=w[0].substr(i);

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,1,N) {
		string ns=w[i];

		size_t pos=ns.find(sub[l].substr(0,len));
		if (pos==string::npos) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,int(pos),i);
		int fr=find_r(r,int(pos)+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	rep(i,0,N) {
		int l=0;
		while (l<sz(w[i]) && w[i][l]==nw[i][l]) l++;

		int r=sz(w[i])-1;
		while (r>=0 && w[i][r]==nw[i][r]) r--;

		if (l<sz(w[i])) {
			if (i!=0) {
				swap(w[0],w[i]);
				swap(nw[0],nw[i]);
			}
			solve(l,r);
			break;
		}
	}
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] &&
		nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) &&
		w[0][r+k]==w[i][pos+k] &&
		nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	string A=w[0].substr(l,len);
	string B=nw[0].substr(l,len);

	rep(i,1,N) {
		string ns=w[i];

		int pos=kmp[l].find(sub[l],len,ns);
		if (pos==-1) {
			if (ns!=nw[i]) no();
			continue;
		}

		int l2=0;
		while (l2<sz(w[i]) && w[i][l2]==nw[i][l2]) l2++;

		int r2=sz(w[i])-1;
		while (r2>=0 && w[i][r2]==nw[i][r2]) r2--;

		if (l2==sz(w[i])) continue;

		int len2=r2-l2+1;
		string a=w[i].substr(l2,len2);
		string b=nw[i].substr(l2,len2);

		if (A!=a || B!=b) no();

		int fl=find_l(l,l2,i);
		int fr=find_r(r,r2,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	rep(i,0,N) {
		int l=0;
		while (l<sz(w[i]) && w[i][l]==nw[i][l]) l++;

		int r=sz(w[i])-1;
		while (r>=0 && w[i][r]==nw[i][r]) r--;

		if (l<sz(w[i])) {
			if (i!=0) {
				swap(w[0],w[i]);
				swap(nw[0],nw[i]);
			}
			solve(l,r);
			break;
		}
	}
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

bool check(int i,int l,int r) {
	int len=r-l+1;
	string ns=w[i];
	if (len>sz(ns)) return false;
	int pos=kmp[l].find(sub[l],len,ns);
	if (pos==-1) return false;
	rep(j,0,len) ns[pos+j]=nw[0][l+j];
	return ns==nw[i];
}

int find_l(int sl,int sr,int i) {
	int l=1,r=sl+1;
	while (l<r) {
		int m=(l+r)/2;
		if (check(i,sl-m,sr)) l=m+1; else r=m;
	}
	return sl-l+1;
}

int find_r(int sl,int sr,int i) {
	int l=1,r=sz(w[0])-sr;
	while (l<r) {
		int m=(l+r)/2;
		if (check(i,sl,sr+m)) l=m+1; else r=m;
	}
	return sr+l-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,0,N) {
		string ns=w[i];

		int pos=kmp[l].find(sub[l],len,ns);
		if (pos==-1) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,r,i);
		int fr=find_r(l,r,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	int best_i=-1,best_l=-1,best_r=-1;
	rep(i,0,N) {
		int l=-1,r=-1;
		rep(j,0,sz(w[i])) {
			if (w[i][j]!=nw[i][j]) {
				if (l==-1) l=j;
				r=j;
			}
		}

		if (l==-1) continue;

		if (best_i==-1 || r-l+1>best_r-best_l+1) {
			best_i=i;
			best_l=l;
			best_r=r;
		}
	}

// cerr<<best_i<<endl;
// cerr<<best_l<<endl;
// cerr<<best_r<<endl;

	swap(w[0],w[best_i]);
	swap(nw[0],nw[best_i]);

	solve(best_l,best_r);
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 && nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) && nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,0,N) {
		string ns=w[i];

		int pos=kmp[l].find(sub[l],len,ns);
		if (pos==-1) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,pos,i);
		int fr=find_r(r,pos+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	int best_i=-1,best_l=-1,best_r=-1;
	rep(i,0,N) {
		int l=-1,r=-1;
		rep(j,0,sz(w[i])) {
			if (w[i][j]!=nw[i][j]) {
				if (l==-1) l=j;
				r=j;
			}
		}

		if (l==-1) continue;

		if (best_i==-1 || r-l+1>best_r-best_l+1) {
			best_i=i;
			best_l=l;
			best_r=r;
		}
	}

// cerr<<best_i<<endl;
// cerr<<best_l<<endl;
// cerr<<best_r<<endl;

	swap(w[0],w[best_i]);
	swap(nw[0],nw[best_i]);

	solve(best_l,best_r);
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] &&
		nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) &&
		w[0][r+k]==w[i][pos+k] &&
		nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,0,N) {
		string ns=w[i];

		int pos=kmp[l].find(sub[l],len,ns);
		if (pos==-1) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,pos,i);
		int fr=find_r(r,pos+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	rep(i,0,N) {
		int l=0;
		while (l<sz(w[i]) && w[i][l]==nw[i][l]) l++;

		int r=sz(w[i])-1;
		while (r>=0 && w[i][r]==nw[i][r]) r--;

		if (l<sz(w[i])) {
			if (i!=0) {
				swap(w[0],w[i]);
				swap(nw[0],nw[i]);
			}
			solve(l,r);
			break;
		}
	}
}


#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int i1,int l1,int i2,int l2) {
	int k=0;
	while (l1-k>=0 && l2-k>=0 &&
		w[i1][l1-k]==w[i2][l2-k] && nw[i1][l1-k]==nw[i2][l2-k]) k++;
	return l1-k+1;
}

int find_r(int i1,int r1,int i2,int r2) {
	int k=0;
	while (r1+k<sz(nw[i1]) && r2+k<sz(nw[i2]) &&
		w[i1][r1+k]==w[i2][r2+k] && nw[i1][r1+k]==nw[i2][r2+k]) k++;
	return r1+k-1;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	int sel=-1,sell=-1,selr=-1,maxl=-1,minr=-1;
	string A,B;
	rep(i,0,N) {
		int l=0;
		while (l<sz(w[i]) && w[i][l]==nw[i][l]) l++;

		if (l==sz(w[i])) continue;

		int r=sz(w[i])-1;
		while (r>=0 && w[i][r]==nw[i][r]) r--;

		string a=w[i].substr(l,r-l+1);
		string b=nw[i].substr(l,r-l+1);

		if (A.empty()) {
			A=a;
			B=b;
			sel=i;
			sell=l;
			selr=r;
			maxl=0;
			minr=sz(w[i])-1;
			continue;
		}

		if (A!=a || B!=b) no();

		maxl=max(maxl,find_l(sel,sell,i,l));
		minr=min(minr,find_r(sel,selr,i,r));
	}

	int len=minr-maxl+1;
	string s=w[sel].substr(maxl,len);
	string t=nw[sel].substr(maxl,len);
	rep(i,0,N) {
		string ns=w[i];
		size_t pos=ns.find(s);
		if (pos!=string::npos) { rep(j,0,len) ns[pos+j]=nw[sel][maxl+j]; }
		if (ns!=nw[i]) no();
	}

	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}