#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
const int P = 998244353;
const int N = 110;

int n,x,y,a[N];
int dp[N][20][20][20][2];
string s;

int dfs(int cur,int pre,int mask1,int mask2,bool tie){
	if(cur>n) return pre==0 && (mask1&mask2);
	int &res = dp[cur][pre+9][mask1][mask2][tie];
	if(res>=0) return res;
	res = 0;
	int up = tie ? a[cur] : 9;
	//find (a,b), s.t. ax-by=0, a<input, a and b contain corresponding numbers
	rep(i,0,up)rep(j,0,9){
		int now = pre*10 - i*x + j*y, m1=0, m2=0;
		if(now<=-y || now>=x) continue;
		if(i && i%y==0) m1 = 1<<(i/y-1);
		if(j && j%x==0 && j/x*y<=9) m2 = 1<<(j/x-1);
		res = (res + dfs(cur+1, now, mask1|m1, mask2|m2, tie&&i==up)) % P;
	}
	return res;
}

int main(){
	cin>>s;
	n = s.size();
	rep(i,1,n) a[i] = s[i-1] - 48;
	LL ans = 0;
	rep(i,1,n) ans = (ans*10+a[i]) % P;
	for(x=1;x<=8;++x)for(y=x+1;y<=9;++y)if(__gcd(x,y)==1){
		memset(dp,-1,sizeof dp);
		ans = (ans + dfs(1, 0, 0, 0, true) * 2) % P;
	}
	cout<<ans<<endl;
	return 0;
}


//
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
//░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
//░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
//░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
//░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
//░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
//░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
//░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
//░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
//░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
//░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
//░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <time.h>
using namespace std;
//───────────────██
//─────────────░██▓█
//────────────▓██▓▓█░
//───────────██▒─▒▓▓▓
//──────────█▓▒▒░─▒▓█
//────────░██▓▒▒▓▒░▒▓█
//───────▒█▒──▒▓▓▓▓▒▓█░
//──────▓█▓▒──▒▒░░▒▓▓██
//─────██▓▓▓▓▓█▒───▓▓▓█░
//────██▒▓▓█▒───▒███──▓█
//──░████▓░█▒▒█───▓█──▓█░
//─▒██▓░─▓▓▒▒▓█▒───▓──░██
//▓█▓▓▒░▒▓█▓▓██▓██▓███▒▒█▒
//█▓▓▓▓███████▓███████▓▒▒█
//▓██▓███▓░░░░░▓░▓█▒██████▒
//▒▒▓▓▒▒░▒▓░░░░░░░░░▒▒▒▓███
//▓█▓░░░░─▓▓██▒▓▒▒░░░░░░░▒█▓
//▒▒▓▒░░░─▓████▒░▒▒▒▒▒░▒░░░██
//▒▒▓██▓▓▒░─░───░▓▓▓░▓███▒▒▓█
//▓░░▒▒▒─░──────▒▓░▓▒─███▒─▒█▒
//█▒────────░▒░──░▓─░───░░▒▓█▒
//███░───────█───▒──░▒──░▒▒██▒
//─▒███░─────████████░───░▒▓█▓─────────░▓█
//────▒█░──────────────────▒██─────░▓███▒
//█▒────█▒──────────────░▒▓▓█───▓███▒
//▓██─────░░─────────░░▓████████▒
//████▒─────░▒░░░─────███████░
//▓▓████─────────░▓██████▓▓█▓
//█▓▓───────░▓████▓██▓▓▒▒▒▓█░
//▓░───░▒█████▒─────▓█▓▓▒▓▓▓█▒
//─░█████▒───────────▒▓▓▓▒▒▓██▒
//──█░────────────────█▓▓▓▒▒▓▓█░
//▓░──────────────────█▓▓▓█▒▓▓██
//───────────────────▒█████▓▓▓▓█▒
//──────────────────░──░██▓▓▓▓██▓
//─────────────────▒▒░────▒█▓▓▓█░
//───────────────────────────────
//████────█─█─█───█─█───██─██
//█──██───█████───█─█────███
//████─────███────███─────█
//█──██───█████─────█────███
//████────█─█─█───███───██─██

#define vc   vector
#define sz(v)  (int)(v.size())
#define pb(a)  push_back(a)
#define each(it,s)  for(auto it = s.begin(); it != s.end(); it++)
#define rep(i, b, n)  for(int i = (b); i < (n); i++)
#define all(v)  v.begin(), v.end()
#define FI  first
#define SE  second
#define rr(i,j,n,m) for(int i=0;i<n;i++) for(int j=0;j<m;j++)
#define NO  cout << "NO"
#define YES cout << "YES"
#define ex(n) return n;
typedef long long int lli;
typedef long long ll;
typedef double db;
//_____________________________________________▄▄████████▄
//___________________________________________▄█▓▓▓█▓▓▓▓▓▓██▄
//___________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓█▄
//________________________________▄█████▄_█▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//________________▄▄██████████▓▓▓▓▓▓▓██▓▓▓▓▓▓▓█▓▓▓▓▓▓▓██
//_____________▄█▓▓▓▓▓▓▓▓▓▓█▓██▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓▓▓▓▓█▓█
//__________▄█▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓█▓▓█
//________▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓██▓▓█
//_______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓███▓▓▓▓█
//______█▓▓▓▓▓▓▓▓▓▓▓▓███▀▀▀▀██▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓█▓▓▓▓█__▄█████
//_____█▓▓▓▓▓▓▓▓▓▓█▀▀___________▀█▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓███▓▓▓▓▓
//____█▓▓▓▓▓▓▓▓▓█▀_______________▓▓█▓▓▓▓███████▓███▓▓▓▓▓▓▓░░░▓▓
//____█▓▓▓▓▓▓▓▓█_____________▓▓▓░░░█▓██░░░░░░░███▓▓▓▓▓▓░░░░░░▓▓
//_____█▓▓▓▓▓▓█____________▓▓░░░░░░██░░░░░░░░░░░░███▓░░░░░░░░░▓
//__█▌_█▓▓▓▓▓█___________▓░░░░░░░░░░░░░░░░░░░░░░░░▓░░░░░░░▓░░▓
//_█▓█_█▓▓▓▓█__________▓▄▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓░░░▓
//█▓▓▓██▓▓▓█_________▓█░░▐░░░░░░░░░▄█████▄░░░░░░░░░░░░░▓░░░░▓
//█▓▓▓▓▓▓▓█________▀▄█░░░▐░░░░░░▄█▀░░░░░░▀█░░░░░░░░░░░▓░░░░▓▓
//_██▓▓▓██________▀▀▄▌░░░▐░░░░░░█░░░░░░░░░░█░░░░░░░░░▓░░░░░▓▓
//___▀▀▀▀__________▀▄█░░░░▐░░░░░█░░░░░░░░░░░▐▌░░░░░░░▓░░░░░▓▓▓
//__________________▓░░▓▓▓▓░░░░░░█░░░░░░░░░░░░▐▄▄▄▅░░░░░░░░░▓██
//_________________▓░░▀░░░░░░░░░░▀░░░░░░░░░░░░▐▀▄▄▅░░░░░░░░▓▓▓▓
//__________________▓░░░░░░░░░░░░░░░░░░░░░░░░░░▀▄▄░░░░░░░░█▓▓▓▓
//___________________▓░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░███████▓▓▓▓▓▓
//____________________▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░██▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▒▒▓░░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_____________________▓▓▒▓░░░░░░░░░░░░░░░░░░░████████▓▓▓▓▓▓▓▓▓▓
//______________________▓▓▓▓▓░░░░░░░░░░░░░░███▓▓▓▓█▓▓▓██▓▓▓▓██▓▓
//_____________________________▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓█▓▓█▓▓▓▓█▓██
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓█▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓████▓▓▓▓▓▓█▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓█▓▓██████▓▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓███████
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█
//____________________________________________█▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//__________________________________________███████████▓▓▓▓▓▓▓▓█
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
//________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓▓██
//_________________________________________█▓▓▓▓▓▓█▀▀▀▀▀▀▀
//___________________________________________██▓▓▓▓███▄▄
//______________________________________________▀▀▀

int main()
{
    int n,fl1=1,fl2=1,fl3=1,fl4=1,fd1=1,fd2=1,fd3=1,fd4=1,fe1=1,fe2=1,fe3=1,fe4=1,ff1=1,ff2=1,ff3=1,ff4=1;
    cin>>n;
    char c1[10][10],c2[10][10],c3[10][10],c4[10][10],b,d1[10][10],d2[10][10],d3[10][10],d4[10][10],e1[10][10],e2[10][10],e3[10][10],e4[10][10],f1[10][10],f2[10][10],f3[10][10],f4[10][10];
    rep(i,0,n)
    {
        rep(i,0,n)
        {
            cin >> c1[i][j];
            c2[j][n-1-i]=c1[i][j];
            c3[n-1-i][n-1-j]=c1[i][j];
            c4[n-1-j][i]=c1[i][j];
        }
    }
    rr(i,j,n,n)
        {
            d1[i][n-1-j]=c1[i][j];
            d2[i][n-1-j]=c2[i][j];
            d3[i][n-1-j]=c3[i][j];
            d4[i][n-1-j]=c4[i][j];
            e1[n-1-i][j]=c1[i][j];
            e2[n-1-i][j]=c2[i][j];
            e3[n-1-i][j]=c3[i][j];
            e4[n-1-i][j]=c4[i][j];
            f1[n-1-i][n-1-j]=c1[i][j];
            f2[n-1-i][n-1-j]=c2[i][j];
            f3[n-1-i][n-1-j]=c3[i][j];
            f4[n-1-i][n-1-j]=c4[i][j];
        }
    rep(i,0,n)
    {
        rep(i,0,n)
        {
            cin >> b;
            if(b!=c1[i][j])
                fl1=0;
            if(b!=c2[i][j])
                fl2=0;
            if(b!=c3[i][j])
                fl3=0;
            if(b!=c4[i][j])
                fl4=0;
            if(b!=d1[i][j])
                fd1=0;
            if(b!=d2[i][j])
                fd2=0;
            if(b!=d3[i][j])
                fd3=0;
            if(b!=d4[i][j])
                fd4=0;
            if(b!=e1[i][j])
                fe1=0;
            if(b!=e2[i][j])
                fe2=0;
            if(b!=e3[i][j])
                fe3=0;
            if(b!=e4[i][j])
                fe4=0;
            if(b!=f1[i][j])
                ff1=0;
            if(b!=f2[i][j])
                ff2=0;
            if(b!=f3[i][j])
                ff3=0;
            if(b!=f4[i][j])
                ff4=0;
        }
    }
    if(fl1 || fl2 || fl3 || fl4 || fd1 || fd2 || fd3 || fd4 || fe1 || fe2 || fe3 || fe4 || ff1 || ff2 || ff3 || ff4)
        YES;
    else
        NO;
}
}


//
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
//░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
//░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
//░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
//░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
//░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
//░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
//░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
//░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
//░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
//░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
//░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <time.h>
using namespace std;
//───────────────██
//─────────────░██▓█
//────────────▓██▓▓█░
//───────────██▒─▒▓▓▓
//──────────█▓▒▒░─▒▓█
//────────░██▓▒▒▓▒░▒▓█
//───────▒█▒──▒▓▓▓▓▒▓█░
//──────▓█▓▒──▒▒░░▒▓▓██
//─────██▓▓▓▓▓█▒───▓▓▓█░
//────██▒▓▓█▒───▒███──▓█
//──░████▓░█▒▒█───▓█──▓█░
//─▒██▓░─▓▓▒▒▓█▒───▓──░██
//▓█▓▓▒░▒▓█▓▓██▓██▓███▒▒█▒
//█▓▓▓▓███████▓███████▓▒▒█
//▓██▓███▓░░░░░▓░▓█▒██████▒
//▒▒▓▓▒▒░▒▓░░░░░░░░░▒▒▒▓███
//▓█▓░░░░─▓▓██▒▓▒▒░░░░░░░▒█▓
//▒▒▓▒░░░─▓████▒░▒▒▒▒▒░▒░░░██
//▒▒▓██▓▓▒░─░───░▓▓▓░▓███▒▒▓█
//▓░░▒▒▒─░──────▒▓░▓▒─███▒─▒█▒
//█▒────────░▒░──░▓─░───░░▒▓█▒
//███░───────█───▒──░▒──░▒▒██▒
//─▒███░─────████████░───░▒▓█▓─────────░▓█
//────▒█░──────────────────▒██─────░▓███▒
//█▒────█▒──────────────░▒▓▓█───▓███▒
//▓██─────░░─────────░░▓████████▒
//████▒─────░▒░░░─────███████░
//▓▓████─────────░▓██████▓▓█▓
//█▓▓───────░▓████▓██▓▓▒▒▒▓█░
//▓░───░▒█████▒─────▓█▓▓▒▓▓▓█▒
//─░█████▒───────────▒▓▓▓▒▒▓██▒
//──█░────────────────█▓▓▓▒▒▓▓█░
//▓░──────────────────█▓▓▓█▒▓▓██
//───────────────────▒█████▓▓▓▓█▒
//──────────────────░──░██▓▓▓▓██▓
//─────────────────▒▒░────▒█▓▓▓█░
//───────────────────────────────
//████────█─█─█───█─█───██─██
//█──██───█████───█─█────███
//████─────███────███─────█
//█──██───█████─────█────███
//████────█─█─█───███───██─██

#define vc   vector
#define sz(v)  (int)(v.size())
#define pb(a)  push_back(a)
#define each(it,s)  for(auto it = s.begin(); it != s.end(); it++)
#define rep(i, b, n)  for(int i = (b); i < (n); i++)
#define all(v)  v.begin(), v.end()
#define FI  first
#define SE  second
#define rr(i,j,n,m) for(int i=0;i<n;i++) for(int j=0;j<m;j++)
#define NO  cout << "NO"
#define YES cout << "YES"
#define ex(n) return n;
typedef long long int lli;
typedef long long ll;
typedef double db;
//_____________________________________________▄▄████████▄
//___________________________________________▄█▓▓▓█▓▓▓▓▓▓██▄
//___________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓█▄
//________________________________▄█████▄_█▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//________________▄▄██████████▓▓▓▓▓▓▓██▓▓▓▓▓▓▓█▓▓▓▓▓▓▓██
//_____________▄█▓▓▓▓▓▓▓▓▓▓█▓██▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓▓▓▓▓█▓█
//__________▄█▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓█▓▓█
//________▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓██▓▓█
//_______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓███▓▓▓▓█
//______█▓▓▓▓▓▓▓▓▓▓▓▓███▀▀▀▀██▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓█▓▓▓▓█__▄█████
//_____█▓▓▓▓▓▓▓▓▓▓█▀▀___________▀█▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓███▓▓▓▓▓
//____█▓▓▓▓▓▓▓▓▓█▀_______________▓▓█▓▓▓▓███████▓███▓▓▓▓▓▓▓░░░▓▓
//____█▓▓▓▓▓▓▓▓█_____________▓▓▓░░░█▓██░░░░░░░███▓▓▓▓▓▓░░░░░░▓▓
//_____█▓▓▓▓▓▓█____________▓▓░░░░░░██░░░░░░░░░░░░███▓░░░░░░░░░▓
//__█▌_█▓▓▓▓▓█___________▓░░░░░░░░░░░░░░░░░░░░░░░░▓░░░░░░░▓░░▓
//_█▓█_█▓▓▓▓█__________▓▄▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓░░░▓
//█▓▓▓██▓▓▓█_________▓█░░▐░░░░░░░░░▄█████▄░░░░░░░░░░░░░▓░░░░▓
//█▓▓▓▓▓▓▓█________▀▄█░░░▐░░░░░░▄█▀░░░░░░▀█░░░░░░░░░░░▓░░░░▓▓
//_██▓▓▓██________▀▀▄▌░░░▐░░░░░░█░░░░░░░░░░█░░░░░░░░░▓░░░░░▓▓
//___▀▀▀▀__________▀▄█░░░░▐░░░░░█░░░░░░░░░░░▐▌░░░░░░░▓░░░░░▓▓▓
//__________________▓░░▓▓▓▓░░░░░░█░░░░░░░░░░░░▐▄▄▄▅░░░░░░░░░▓██
//_________________▓░░▀░░░░░░░░░░▀░░░░░░░░░░░░▐▀▄▄▅░░░░░░░░▓▓▓▓
//__________________▓░░░░░░░░░░░░░░░░░░░░░░░░░░▀▄▄░░░░░░░░█▓▓▓▓
//___________________▓░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░███████▓▓▓▓▓▓
//____________________▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░██▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▒▒▓░░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_____________________▓▓▒▓░░░░░░░░░░░░░░░░░░░████████▓▓▓▓▓▓▓▓▓▓
//______________________▓▓▓▓▓░░░░░░░░░░░░░░███▓▓▓▓█▓▓▓██▓▓▓▓██▓▓
//_____________________________▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓█▓▓█▓▓▓▓█▓██
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓█▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓████▓▓▓▓▓▓█▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓█▓▓██████▓▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓███████
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█
//____________________________________________█▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//__________________________________________███████████▓▓▓▓▓▓▓▓█
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
//________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓▓██
//_________________________________________█▓▓▓▓▓▓█▀▀▀▀▀▀▀
//___________________________________________██▓▓▓▓███▄▄
//______________________________________________▀▀▀

int main()
{
    int n,fl1=1,fl2=1,fl3=1,fl4=1,fd1=1,fd2=1,fd3=1,fd4=1,fe1=1,fe2=1,fe3=1,fe4=1,ff1=1,ff2=1,ff3=1,ff4=1;
    cin>>n;
    char c1[10][10],c2[10][10],c3[10][10],c4[10][10],b,d1[10][10],d2[10][10],d3[10][10],d4[10][10],e1[10][10],e2[10][10],e3[10][10],e4[10][10],f1[10][10],f2[10][10],f3[10][10],f4[10][10];
    rep(i,0,n)
    {
        rep(i,0,n)
        {
            cin >> c1[i][j];
            c2[j][n-1-i]=c1[i][j];
            c3[n-1-i][n-1-j]=c1[i][j];
            c4[n-1-j][i]=c1[i][j];
        }
    }
    rr(i,j,n,n)
        {
            d1[i][n-1-j]=c1[i][j];
            d2[i][n-1-j]=c2[i][j];
            d3[i][n-1-j]=c3[i][j];
            d4[i][n-1-j]=c4[i][j];
            e1[n-1-i][j]=c1[i][j];
            e2[n-1-i][j]=c2[i][j];
            e3[n-1-i][j]=c3[i][j];
            e4[n-1-i][j]=c4[i][j];
            f1[n-1-i][n-1-j]=c1[i][j];
            f2[n-1-i][n-1-j]=c2[i][j];
            f3[n-1-i][n-1-j]=c3[i][j];
            f4[n-1-i][n-1-j]=c4[i][j];
        }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            cin >> b;
            if(b!=c1[i][j])
                fl1=0;
            if(b!=c2[i][j])
                fl2=0;
            if(b!=c3[i][j])
                fl3=0;
            if(b!=c4[i][j])
                fl4=0;
            if(b!=d1[i][j])
                fd1=0;
            if(b!=d2[i][j])
                fd2=0;
            if(b!=d3[i][j])
                fd3=0;
            if(b!=d4[i][j])
                fd4=0;
            if(b!=e1[i][j])
                fe1=0;
            if(b!=e2[i][j])
                fe2=0;
            if(b!=e3[i][j])
                fe3=0;
            if(b!=e4[i][j])
                fe4=0;
            if(b!=f1[i][j])
                ff1=0;
            if(b!=f2[i][j])
                ff2=0;
            if(b!=f3[i][j])
                ff3=0;
            if(b!=f4[i][j])
                ff4=0;
        }
    }
    if(fl1 || fl2 || fl3 || fl4 || fd1 || fd2 || fd3 || fd4 || fe1 || fe2 || fe3 || fe4 || ff1 || ff2 || ff3 || ff4)
        YES;
    else
        NO;
}


//
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
//░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
//░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
//░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
//░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
//░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
//░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
//░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
//░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
//░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
//░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
//░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
//░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
//░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <time.h>
using namespace std;
//───────────────██
//─────────────░██▓█
//────────────▓██▓▓█░
//───────────██▒─▒▓▓▓
//──────────█▓▒▒░─▒▓█
//────────░██▓▒▒▓▒░▒▓█
//───────▒█▒──▒▓▓▓▓▒▓█░
//──────▓█▓▒──▒▒░░▒▓▓██
//─────██▓▓▓▓▓█▒───▓▓▓█░
//────██▒▓▓█▒───▒███──▓█
//──░████▓░█▒▒█───▓█──▓█░
//─▒██▓░─▓▓▒▒▓█▒───▓──░██
//▓█▓▓▒░▒▓█▓▓██▓██▓███▒▒█▒
//█▓▓▓▓███████▓███████▓▒▒█
//▓██▓███▓░░░░░▓░▓█▒██████▒
//▒▒▓▓▒▒░▒▓░░░░░░░░░▒▒▒▓███
//▓█▓░░░░─▓▓██▒▓▒▒░░░░░░░▒█▓
//▒▒▓▒░░░─▓████▒░▒▒▒▒▒░▒░░░██
//▒▒▓██▓▓▒░─░───░▓▓▓░▓███▒▒▓█
//▓░░▒▒▒─░──────▒▓░▓▒─███▒─▒█▒
//█▒────────░▒░──░▓─░───░░▒▓█▒
//███░───────█───▒──░▒──░▒▒██▒
//─▒███░─────████████░───░▒▓█▓─────────░▓█
//────▒█░──────────────────▒██─────░▓███▒
//█▒────█▒──────────────░▒▓▓█───▓███▒
//▓██─────░░─────────░░▓████████▒
//████▒─────░▒░░░─────███████░
//▓▓████─────────░▓██████▓▓█▓
//█▓▓───────░▓████▓██▓▓▒▒▒▓█░
//▓░───░▒█████▒─────▓█▓▓▒▓▓▓█▒
//─░█████▒───────────▒▓▓▓▒▒▓██▒
//──█░────────────────█▓▓▓▒▒▓▓█░
//▓░──────────────────█▓▓▓█▒▓▓██
//───────────────────▒█████▓▓▓▓█▒
//──────────────────░──░██▓▓▓▓██▓
//─────────────────▒▒░────▒█▓▓▓█░
//───────────────────────────────
//████────█─█─█───█─█───██─██
//█──██───█████───█─█────███
//████─────███────███─────█
//█──██───█████─────█────███
//████────█─█─█───███───██─██

#define vc   vector
#define sz(v)  (int)(v.size())
#define pb(a)  push_back(a)
#define each(it,s)  for(auto it = s.begin(); it != s.end(); it++)
#define rep(i, b, n)  for(int i = (b); i < (n); i++)
#define all(v)  v.begin(), v.end()
#define FI  first
#define SE  second
#define rr(i,j,n,m) for(int i=0;i<n;i++) for(int j=0;j<m;j++)
#define NO  cout << "NO"
#define YES cout << "YES"
#define ex(n) return n;
typedef long long int lli;
typedef long long ll;
typedef double db;
//_____________________________________________▄▄████████▄
//___________________________________________▄█▓▓▓█▓▓▓▓▓▓██▄
//___________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓█▄
//________________________________▄█████▄_█▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//________________▄▄██████████▓▓▓▓▓▓▓██▓▓▓▓▓▓▓█▓▓▓▓▓▓▓██
//_____________▄█▓▓▓▓▓▓▓▓▓▓█▓██▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓▓▓▓▓█▓█
//__________▄█▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓█▓▓█
//________▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓██▓▓█
//_______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓███▓▓▓▓█
//______█▓▓▓▓▓▓▓▓▓▓▓▓███▀▀▀▀██▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓█▓▓▓▓█__▄█████
//_____█▓▓▓▓▓▓▓▓▓▓█▀▀___________▀█▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█▓▓▓███▓▓▓▓▓
//____█▓▓▓▓▓▓▓▓▓█▀_______________▓▓█▓▓▓▓███████▓███▓▓▓▓▓▓▓░░░▓▓
//____█▓▓▓▓▓▓▓▓█_____________▓▓▓░░░█▓██░░░░░░░███▓▓▓▓▓▓░░░░░░▓▓
//_____█▓▓▓▓▓▓█____________▓▓░░░░░░██░░░░░░░░░░░░███▓░░░░░░░░░▓
//__█▌_█▓▓▓▓▓█___________▓░░░░░░░░░░░░░░░░░░░░░░░░▓░░░░░░░▓░░▓
//_█▓█_█▓▓▓▓█__________▓▄▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓░░░▓
//█▓▓▓██▓▓▓█_________▓█░░▐░░░░░░░░░▄█████▄░░░░░░░░░░░░░▓░░░░▓
//█▓▓▓▓▓▓▓█________▀▄█░░░▐░░░░░░▄█▀░░░░░░▀█░░░░░░░░░░░▓░░░░▓▓
//_██▓▓▓██________▀▀▄▌░░░▐░░░░░░█░░░░░░░░░░█░░░░░░░░░▓░░░░░▓▓
//___▀▀▀▀__________▀▄█░░░░▐░░░░░█░░░░░░░░░░░▐▌░░░░░░░▓░░░░░▓▓▓
//__________________▓░░▓▓▓▓░░░░░░█░░░░░░░░░░░░▐▄▄▄▅░░░░░░░░░▓██
//_________________▓░░▀░░░░░░░░░░▀░░░░░░░░░░░░▐▀▄▄▅░░░░░░░░▓▓▓▓
//__________________▓░░░░░░░░░░░░░░░░░░░░░░░░░░▀▄▄░░░░░░░░█▓▓▓▓
//___________________▓░░░░░▓▓▓░░░░░░░░░░░░░░░░░░░░░███████▓▓▓▓▓▓
//____________________▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░██▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▓▓▓▓░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_______________________▓▒▒▓░░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//_____________________▓▓▒▓░░░░░░░░░░░░░░░░░░░████████▓▓▓▓▓▓▓▓▓▓
//______________________▓▓▓▓▓░░░░░░░░░░░░░░███▓▓▓▓█▓▓▓██▓▓▓▓██▓▓
//_____________________________▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓█▓▓█▓▓▓▓█▓██
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓█▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓████▓▓▓▓▓▓█▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓█▓▓██████▓▓▓▓▓
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓▓▓▓▓
//__________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓███████
//___________________________________________█▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓█
//____________________________________________█▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓█
//__________________________________________███████████▓▓▓▓▓▓▓▓█
//_________________________________________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
//________________________________________█▓▓▓▓▓██▓▓▓▓▓▓▓▓██
//_________________________________________█▓▓▓▓▓▓█▀▀▀▀▀▀▀
//___________________________________________██▓▓▓▓███▄▄
//______________________________________________▀▀▀

int main()
{
    int n,fl1=1,fl2=1,fl3=1,fl4=1,fd1=1,fd2=1,fd3=1,fd4=1,fe1=1,fe2=1,fe3=1,fe4=1,ff1=1,ff2=1,ff3=1,ff4=1;
    cin>>n;
    char c1[10][10],c2[10][10],c3[10][10],c4[10][10],b,d1[10][10],d2[10][10],d3[10][10],d4[10][10],e1[10][10],e2[10][10],e3[10][10],e4[10][10],f1[10][10],f2[10][10],f3[10][10],f4[10][10];
    rep(i,0,n)
    {
        rep(i,0,n)
        {
            cin >> c1[i][j];
            c2[j][n-1-i]=c1[i][j];
            c3[n-1-i][n-1-j]=c1[i][j];
            c4[n-1-j][i]=c1[i][j];
        }
    }
    rep(i,0,n)
        (i,0,n)
        {
            d1[i][n-1-j]=c1[i][j];
            d2[i][n-1-j]=c2[i][j];
            d3[i][n-1-j]=c3[i][j];
            d4[i][n-1-j]=c4[i][j];
            e1[n-1-i][j]=c1[i][j];
            e2[n-1-i][j]=c2[i][j];
            e3[n-1-i][j]=c3[i][j];
            e4[n-1-i][j]=c4[i][j];
            f1[n-1-i][n-1-j]=c1[i][j];
            f2[n-1-i][n-1-j]=c2[i][j];
            f3[n-1-i][n-1-j]=c3[i][j];
            f4[n-1-i][n-1-j]=c4[i][j];
        }
    rep(i,0,n)
    {
        rep(i,0,n)
        {
            cin >> b;
            if(b!=c1[i][j])
                fl1=0;
            if(b!=c2[i][j])
                fl2=0;
            if(b!=c3[i][j])
                fl3=0;
            if(b!=c4[i][j])
                fl4=0;
            if(b!=d1[i][j])
                fd1=0;
            if(b!=d2[i][j])
                fd2=0;
            if(b!=d3[i][j])
                fd3=0;
            if(b!=d4[i][j])
                fd4=0;
            if(b!=e1[i][j])
                fe1=0;
            if(b!=e2[i][j])
                fe2=0;
            if(b!=e3[i][j])
                fe3=0;
            if(b!=e4[i][j])
                fe4=0;
            if(b!=f1[i][j])
                ff1=0;
            if(b!=f2[i][j])
                ff2=0;
            if(b!=f3[i][j])
                ff3=0;
            if(b!=f4[i][j])
                ff4=0;
        }
    }
    if(fl1 || fl2 || fl3 || fl4 || fd1 || fd2 || fd3 || fd4 || fe1 || fe2 || fe3 || fe4 || ff1 || ff2 || ff3 || ff4)
        YES;
    else
        NO;
}


#include<bits/stdc++.h>
using namespace std;
int n;
bool sab(int a[10][10],int b[10][10]){

int i,j;

bool flag=true;
for(i=0;i<n;i++){

    for(j=0;j<n;j++){
        if(a[i][j]!=b[i][j])
        {
            flag=false;
            break;
        }

    }
    if(flag==false)
        break;

}
if(flag==false){

    flag=true;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
         if(a[i][j]!=b[n-1-j][i]){
            flag=false;
            break;
         }
       }
       if(flag==false){
        break;
       }
    }

}
if(flag==false){
    flag=true;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
         if(a[i][j]!=b[n-1-i][n-1-j])
         {
             flag=false;
             break;
         }

      }
      if(flag==false){
        break;
      }
    }

}
if(flag==false){

    flag=true;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(a[i][j]!=b[j][n-1-i]){
                flag=false;
                break;
            }
        }
        if(flag==false)
            break;
}
return flag;
}

int main(){

cin>>n;
string str[n],str1[n];
int a[10][10],b[10][10],vf[10][10],hf[10][10];
int i,j;
for(i=0;i<n;i++)
    cin>>str[i];

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

    for(j=0;j<n;j++){
        if(str[i].at(j)=='X')
            a[i][j]=1;
        else
            a[i][j]=0;
    }
}

for(i=0;i<n;i++)
    cin>>str1[i];

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

    for(j=0;j<n;j++){
        if(str1[i].at(j)=='X')
            b[i][j]=1;
        else
            b[i][j]=0;
    }
}
for(i=0;i<n;i++){
    for(j=0;j<=n/2;j++){

        vf[i][j]=b[i][n-1-j];
        vf[i][n-1-j]=b[i][j];

    }

}
for(i=0;i<n;i++){
    for(j=0;j<=n/2;j++){

        hf[j][i]=b[n-1-j][i];
        hf[n-1-j][i]=b[j][i];

    }

}
bool aa=sab(a,b),bb=sab(a,vf),cc=sab(a,hf);
if(aa||bb||cc){
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;

return 0;

}


/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Feb. 12th 2013 **/ //{

/** Header .. **/ //{
#define LOCAL

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
#define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define PTT pair<T, T>
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#define Display(A, n, m) {                      \
	REP(i, n){		                            \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;				            \
	}						                    \
}

#define Display_1(A, n, m) {				    \
	REP_1(i, n){		                        \
        REP_1(j, m) cout << A[i][j] << " ";     \
		cout << endl;		            		\
	}						                    \
}

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &x){
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void CLR(T &A){A.clear();}

template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** Constant List .. **/ //{

const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};

const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};
const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};

const int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};
const int dyhorse[] = {1 ,  -1 , 2  , -2 , 2 ,-2 , 1 ,-1};

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const DB EPS = 1e-9;
const DB OO = 1e15;
const DB PI = acos(-1.0); //M_PI;

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};

inline int reverse_bits(int x){
    x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
    x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
    x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
    x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
    x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);
    return x;
}

inline LL reverse_bits(LL x){
    x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
    x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
    x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
    x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
    x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);
    x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);
    return x;
}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}

inline int low_idx(int x){return __builtin_ffs(x);}
inline int low_idx(LL x){return __builtin_ffsll(x);}
inline int high_idx(int x){return low_idx(reverse_bits(x));}
inline int high_idx(LL x){return low_idx(reverse_bits(x));}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int lg2(int a){return 31 - clz(a);}
inline int lg2(LL a){return 63 - clz(a);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}
//}

/** Miscellaneous .. **/ //{
// <<= 'Random Event .. . //{
namespace RNG{
//srand((unsigned)time(NULL));
inline unsigned int rand16(){return ((rand()) << 15) ^ rand();}
inline unsigned int rand32(){return (rand16() << 16) | rand16();}
inline ULL rand64(){return ((LL)rand32() << 32) | rand32();}
inline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;}
int dice(){return rand() % 6;}
bool coin(){return bool(rand() % 2);}
} using namespace RNG;
//}
// <<= 'Clock .. . //{
namespace CLOCK{
DB s0, s1, rd, k, T;
inline DB getTime(){
#ifdef LOCAL
    return 1.0 * clock() / CLOCKS_PER_SEC;
#else
    timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec + tv.tv_usec * 1e-6;
#endif
}

inline void st0(DB _T = 0.98){T = _T, s0 = getTime();}
inline void st1(DB _k = 1.618){k = _k, s1 = getTime();}
inline void ed1(){rd = getTime() - s1;}
inline DB elapsed(){return getTime() - s0;}
inline bool safe(){return elapsed() + rd * k < T;}
} //using namespace CLOCK;
//}
// <<= 'Temp .. . //{
namespace TMP{
template<class T> PTT operator+(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi + p2.fi, p1.se + p2.se);
}

template<class T> PTT operator-(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi - p2.fi, p1.se - p2.se);
}

template<class T> PTT operator*(const PTT &lhs, T k){
    return PTT(lhs.fi * k, lhs.se * k);
}
} using namespace TMP;
//}
//}

/** Algorithm    .. */ //{
// <<= '-. Math .,//{
namespace Math{
	typedef long long typec;
	///Lib functions
	typec GCD(typec a, typec b)
	{
		return b ? GCD(b, a % b) : a;
	}
	typec extendGCD(typec a, typec b, typec& x, typec& y)
	{
		if(!b) return x = 1, y = 0, a;
		typec res = extendGCD(b, a % b, x, y), tmp = x;
		x = y, y = tmp - (a / b) * y;
		return res;
	}
	///for x^k
	typec power(typec x, typec k)
	{
		typec res = 1;
		while(k)
		{
			if(k&1) res *= x;
			x *= x, k >>= 1;
		}
		return res;
	}
	///for x^k mod m
	typec powerMod(typec x, typec k, typec m)
	{
		typec res = 1;
		while(x %= m, k)
		{
			if(k&1) res *= x, res %= m;
			x *= x, k >>=1;
		}
		return res;
	}
	/***************************************
	Inverse in mod p^t system
	***************************************/
	typec inverse(typec a, typec p, typec t = 1)
	{
		typec pt = power(p, t);
		typec x, y;
	    y = extendGCD(a, pt, x, y);
		return x < 0 ? x += pt : x;
	}
	/***************************************
	Linear congruence theorem
	x = a (mod p)
	x = b (mod q)
	for gcd(p, q) = 1, 0 <= x < pq
	***************************************/
	typec linearCongruence(typec a, typec b, typec p, typec q)
	{
		typec x, y;
		y = extendGCD(p, q, x, y);
		while(b < a) b += q / y;
		x *= b - a, x = p * x + a, x %= p * q;
		if(x < 0) x += p * q;
		return x;
	}
	/***************************************
	prime table
	O(n)
	***************************************/
	const int PRIMERANGE = 1000000;
	int prime[PRIMERANGE + 1];
	int mobius[PRIMERANGE + 1];
	int getPrime()
	{
		memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));
		memset(mobius , 0 , sizeof(mobius));
		mobius[1] = 1;
		for (int i = 2; i <= PRIMERANGE; i++)
		{
			if (!prime[i]) prime[++prime[0]] = i , mobius[i] = -1;
			for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)
			{
				prime[prime[j]*i] = 1;
				if (i % prime[j] == 0) break;
				else mobius[i * prime[j]] = -mobius[i];
			}
		}
		return prime[0];
	}
	/***************************************
	get factor of n
	O(sqrt(n))
	factor[][0] is prime factor
	factor[][1] is factor generated by this prime
	factor[][2] is factor counter

	need: Prime Table
	***************************************/
	///you should init the prime table before
	int factor[100][3], facCnt;
	int getFactors(int x)
	{
		facCnt = 0;
		int tmp = x;
		for(int i = 1; prime[i] <= tmp / prime[i]; i++)
		{
			factor[facCnt][1] = 1, factor[facCnt][2] = 0;
			if(tmp % prime[i] == 0)
				factor[facCnt][0] = prime[i];
			while(tmp % prime[i] == 0)
				factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];
			if(factor[facCnt][1] > 1) facCnt++;
		}
		if(tmp != 1)
			factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;
		return facCnt;
	}
	typec combinationModP(typec n, typec k, typec p)
	{
		if(k > n) return 0;
		if(n - k < k) k = n - k;
		typec a = 1, b = 1, x, y;
		int pcnt = 0;
		for(int i = 1; i <= k; i++)
		{
			x = n - i + 1, y = i;
			while(x % p == 0) x /= p, pcnt++;
			while(y % p == 0) y /= p, pcnt--;
			x %= p, y %= p, a *= x, b *= y;
			b %= p, a %= p;
		}
		if(pcnt) return 0;
		extendGCD(b, p, x, y);
		if(x < 0) x += p;
		a *= x, a %= p;
		return a;
	}
};//using namespace Math;
//}
// <<= '-. Geo ,.//{
namespace Geo{
	#define typec double
    const typec eps=1e-9;
    int dblcmp(double d){
        if (fabs(d)<eps)return 0;
        return d>eps?1:-1;
    }
    int sgn(double a) {return a<-eps?-1:a>eps;}
    inline double sqr(double x){return x*x;}
    struct Point2D{
		typec x,y;
		Point2D(){}
		Point2D(typec _x,typec _y):x(_x),y(_y){};
		void input(){
			scanf("%lf%lf",&x,&y);
		}
		void output(){
			printf("%.2f %.2f\n",x,y);
		}
		bool operator==(Point2D a)const{
			return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;
		}
		bool operator<(Point2D a)const{
			return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x;
		}
		typec len(){
			return hypot(x,y);
		}
		typec len2(){
			return x*x+y*y;
		}
		Point2D operator + (const Point2D &A) const{
			return Point2D(x + A.x , y + A.y);
		}
		Point2D operator - (const Point2D &A) const{
			return Point2D(x - A.x , y - A.y);
		}
		Point2D operator * (const typec _x) const{
			return Point2D(x * _x , y * _x);
		}
		typec operator * (const Point2D &A) const{
			return x * A.x + y * A.y;
		}
		typec operator ^ (const Point2D &A) const{
			return x * A.y - y * A.x;
		}
		Point2D operator / (const typec _p) const{
			return Point2D(x / _p , y / _p);
		}
		typec distance(Point2D p){
			return hypot(x-p.x,y-p.y);
		}
		Point2D add(Point2D p){
			return Point2D(x+p.x,y+p.y);
		}
		Point2D sub(Point2D p){
			return Point2D(x-p.x,y-p.y);
		}
		Point2D mul(typec b){
			return Point2D(x*b,y*b);
		}
		Point2D div(typec b){
			return Point2D(x/b,y/b);
		}
		typec dot(Point2D p){
			return x*p.x+y*p.y;
		}
		typec det(Point2D p){
			return x*p.y-y*p.x;
		}
		typec rad(Point2D a,Point2D b){
			Point2D p=*this;
			return fabs(atan2(fabs(a.sub(p).det(b.sub(p))),a.sub(p).dot(b.sub(p))));
		}
		Point2D trunc(typec r){
			typec l=len();
			if (!dblcmp(l))return *this;
			r/=l;
			return Point2D(x*r,y*r);
		}
		Point2D rotleft(){
			return Point2D(-y,x);
		}
		Point2D rotright(){
			return Point2D(y,-x);
		}
		Point2D rotate(Point2D p,typec angle)//ÈÆµãpÄæÊ±ÕëÐý×ªangle½Ç¶È
		{
			Point2D v=this->sub(p);
			typec c=cos(angle),s=sin(angle);
			return Point2D(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
		}
	};

	typec cross(Point2D a,Point2D b,Point2D c){
		return (b.sub(a)).det(c.sub(a));
	}
}using namespace Geo;
//}
//}

/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    return x;
}

inline DB& RF(DB &x){
    //cin >> x;
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    //printf("%d\n", x);
    cout << x << endl;
}
//}
/* .................................................................................................................................. */
//pair<LL , LL> circle[10000];
LL a , b , w , x , c;
pair<LL , LL> getc(int f , int t , int deep , int dec){
//    if (circle[f].fi != -1) return circle[f];
    if (f == t && deep){
        return MP(deep , dec);
//        return circle[f];
    }
    if (f >= x) {
        return getc(f - x , t , deep + 1 , dec);

    }
    else return getc(w - (x - f) , t , deep + 1 , dec + 1);
//    return circle[f];
}
LL t;
bool check(LL y){
    if (y <= t) return a >= c - y;
    LL cc = c - y;
    y -= t;
    LL bb = b - x * t;
    LL aa = a;
    pair<LL , LL> r =  getc(bb , bb , 0 , 0);
//    cout << "R = " << r << endl;
    LL ccc = y / r.fi;
    aa -= ccc * r.se;
    y %= r.fi;
//    cout << y << endl;
    while(y--){
        if (bb >= x) bb = bb - x;
        else {
                bb = w - (x - bb);
                aa--;
        }
    }
    return cc <= aa;
}
void solve(){
//    for (int i = 0 ; i <= w ; ++i) circle[i] = MP(-1 , -1);
//    t = 0;
//    LL low = 0 , high = 2e9 , mid;
//    t = high;
//    do{
//        mid = low + high >> 1;
//        if (b - mid * x < x){
//            checkMin(t , mid);
//            high = mid - 1;
//        }
//        else low = mid + 1;
//    }while(low <= high);
//    cout << t << endl;
    t = max(0ll , (b - x) / x);
    while(b - (t + 1) * x >= x) ++t;
    while(t > 0 && b - (t - 1) * x < x) --t;
    low = 0 , high = 2e9;
    LL ans = high;
    do{
        mid = low + high >> 1;
        if (check(mid)){
            checkMin(ans , mid);
            high = mid - 1;
        }
        else low = mid + 1;
    }while(low <= high);
    OT(ans);
}
int main(){
    while(cin >> a >> b >> w >> x >> c) solve();
}


#include "iostream"
#include "cstdio"
#include "cstring"
#include "math.h"
#include "algorithm"
using namespace std;

int next[1200];
int step[1200];
int a,b,w,x,c,dx;

int init(int B,int X){
    if(step[B])return B;
    step[B]=B/X+1;
    next[B]=w-(X-B%X);
    init(next[B],X);
}
int round(int B,int M){
    dx++;
    if(B==M)return step[B];
    return step[B]+round(next[B],M);
}

int main()
{
    int Start,Rstep;
    int A,C,B,bx;
    dx=0;
    scanf("%d%d%d%d%d",&a,&b,&w,&x,&c);
    memset(next,-1,sizeof(next));
    memset(step,0,sizeof(step));
    Start=init(b,x);
    Rstep=round(next[Start],Start);
    A=a;C=c;,B=b;
    while(B!=Start){
        C-=step[B];
        if(A>C){
            printf("%d\n",c-A);
            return 0;
        }
        A--;
        B=next[B];
    }
    if(A>=C){printf("%d\n",c-A);return 0;}
    bx=(C-A)/(Rstep-dx);
    if((C-A)%(Rstep-dx)==0)bx--;
    C-=Rstep;
    A-=dx;
    while(A<C){
        C-=step[Start];
        if(A>C){
            printf("%d\n",c-A);
            return;
        }
        A--;
        Start=next[Start];
    }
    printf("%d\n",c-A);
    return 0;
}


#include<iostream>
using namespace std;

long long a, b, w, x, c, ans;

int main(){
  cin >> a >> b >> w >> x >> c;
  ans = max(0, ((w * (c - a) - b) / (w - x)));
  if((w * (c - a) - b) % (w - x) && ans)
    ans++;
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

bool gc [1010];
int main()
{
	int a,b,w,x,c;
	cin >> a >> b >> w >> x >> c;

	if (a >= c-(b/x))
	{
		cout << max(0,c-a) << endl;
		return 0;
	}
	int anw = b/x;
	int cf = 0;
	c -= b/x;
	b %= x;
	gc[b] = 1;
	vector <int> rc;
	for (;;)
	{
		b += (w-x);
		rc.push_back(b/x);
		int md = b%x;
		cf += rc[rc.size()-1];
		if (gc[md]) break;
		gc[md] = 1;
		b = md;
	}
	int dis = c-a;
	dis /= cf;
	anw += cf*dis+dis*int(rc.size());
	c -= cf*dis;
	for (int i = 0; i < rc.size(); i++)
	{
		if (c <= a) break;
		anw++;
		int tr = min(c-a,rc[i]);
		c -= tr;
		anw += tr;
	}
	cout << anw << endl;
}


#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
    int a,c;
    cin>>a>>c;
    int b=0;
    int k=pow(3.00,b);
    while(a>=k)
    {
        b++;
        k=pow(3.00,b);
    }
    int temp=b;

    b=0;
    k=pow(3.00,b);

    while(c>=k)
    {
        b++;
        k=pow(3.00,b);
    }
    int temp1=b;

    int value=max(temp,temp1);

    vector<int> a1,c1;

    for(int i=value-1;i>=0;i--)
    {
        if(a<pow(3.00,i))
            a1.push_back(0);
        else
        {
            if(a>=2*pow(3.00,i))
            {a1.push_back(2);a-=2*pow(3.00,i);continue;}

            a1.push_back(1);
            a-=pow(3.00,i);
        }
    }

    for(int i=value-1;i>=0;i--)
    {
        if(c<pow(3.00,i))
            c1.push_back(0);
        else
        {
            if(c>=2*pow(3.00,i))
            {c1.push_back(2);c-=2*pow(3.00,i);continue;}

            c1.push_back(1);
            c-=pow(3.00,i);
        }
    }

    vector<int> ans;
    for(int i=0;i<a1.size();i++)
    {
        if(a1[i]==0)
        {
            if(c1[i]==0)
                ans.push_back(0);
            else if(c1[i]==1)
                ans.push_back(1);
            else
                ans.push_back(2);
        }

        else if(a1[i]==1)
        {
            if(c1[i]==0)
                ans.push_back(2);
            else if(c1[i]==1)
                ans.push_back(0);
            else
                ans.push_back(1);
        }
        else
        {
            if(c1[i]==0)
            ans.push_back(1);
            else if(c1[i]==1)
                ans.push_back(2);
            else
                ans.push_back(0);
        }
    }

    long int ans1=0;

    for(int i=ans.size()-1;i>=0;i--)
    {
        ans1+=ans[i]*pow(3.00,(int)ans.size()-1-i);
    }

    cout<<ans1;

    return 0;
}


#include<iostream>
using namespace std;

int ak[1000],bk[1000],sum[1000];

long long a,b,hasil=0,pengali=1;

int main()
{
	memset(ak,0,sizeof(ak));
	memset(bk,0,sizeof(bk));
	int ta=0,tb=0,maxt;
	cin >> a >> b;
	while (a != 0)
	{
		ta++;
		ak[ta] = a%3;
		a = a/3;
	}
	while (b != 0)
	{
		tb++;
		bk[tb] = b%3;
		b = b/3;
	}
	maxt = max(ta,tb);
	for(int c=1; c<=maxt; c++)
	{
		if (bk[c] < ak[c]) bk[c] = bk[c]+3;
		sum[c] = bk[c]-ak[c];
	}
	for(int c=1; c<=maxt; c++)
	{
		hasil = hasil + pengali*sum[c];
		pengali = pengali *3;
	}
	cout << hasil << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int tera[25],terc[25];
int get_tera(ll x){
	int cnt=0;
	while(x){
		tera[cnt++]=x%3;
		x/=3;
	}
	return cnt;
}
int get_terc(ll x){
	int cnt=0;
	while(x){
		terc[cnt++]=x%3;
		x/=3;
	}
	return cnt;
}
int main(){
	ll a,c;cin>>a>>c;
	int lena=get_tera(a);
	int lenc=get_terc(c);
	int len=max(lena,lenc);
	//cout<<"a=\n";
	//for(int i=len-1;i>=0;i--)cout<<tera[i];
	//cout<<"\n c= \n";
	//for(int i=len-1;i>=0;i--)cout<<terc[i];
	int ans[25];
	memset(ans,0,sizeof(ans));
	for(int i=0;i<len;i++){
		for(int j=0;j<3;j++){
			if((tera[i]+j)%3==terc[i]){ans[i]=j;break;}
		}
	}
	//for(int i=len-1;i>=0;i--)cout<<ans[i];
	//cout<<"\n";
	ll tmp=1ll;ll res=0;
	for(int i=0;i<len;i++){
		res+=1ll*ans[i]*tmp;
		tmp=3ll*tmp;
	}
	cout<<res<<"\n";
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
    long a,c,ans=0,i=0;
    scanf("%ld%ld",&a,&c);
    while(a!=0 || c!=0)
    {
         ans+=(c%3-a%3+3)%3*pow(3,i);
         a/=3;
         c/=3;
         i++;
    }
    printf("%ld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(long long int i=0;i<n;i++)
#define fr(i,n) for(i = n-1 ; i>0 ; i--)
#define Pa(i,n,a) for(long long int i=0;i<n;i++){cout << a[i] << " ";}
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define Fs(itr,s) for(itr = s.begin(); itr != s.end(); ++itr)
#define Cs(s1,s2) set<int>s2(s1.begin(), s1.end());
#define F(i,a,n) for(long long int i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define END() cout << endl
#define R(X) return X
#define I(X) cin>>X
#define O(X) cout<<X
#define V 10
//=======================
typedef stack<int> si;
typedef pair<int, int>	pii;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
typedef vector<vi>		vvi;
typedef set <int, greater <int>> sii;
typedef multiset <int, greater <int> > msii;
typedef map<int, int> mapii;
typedef multimap <int, int> mmapii;
typedef unordered_set <int> uosi;
typedef unordered_multiset <int> uomsi;
typedef unordered_map<int, int> uomapii;
typedef unordered_multimap<int, int> uommapii;
typedef priority_queue<pii,vpii,greater<pii>> pqpv;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6+13, M = N;
const int IMax = INT_MAX;
const int IMin = INT_MIN;
const int K = 101;
//=======================
vi g[N];
int a[N];
ll n, m, k;
bool checkIfGreater(ll a, ll b){
    return a>b;
}
//=======================

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    int count = x = y = 0;
    I(s);
    fo(i,s.length()){
        if(s[i] == 'Q'){
            count+=x;
            y++;
        }
        else if(s[i] == 'A'){
            x+=y;
        }
    }
    cout << count << endl;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int c=0;
    int n=s.length();
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(s.at(i)=='Q' && s.at(j)='A' && s.at(k)='Q'){
                    c++;
                }
            }
        }
    }
    cout<<c;
}


#include <iostream>
#include <string>
#include <queue>
using namespace std;

vector<int>Q,A;

int Find_Q(int x)
{
	int ans = upper_bound(Q.begin(),Q.end(),x) - Q.begin();
	return ans;
}

int Find_A(int x)
{
	int ans = upper_bound(A.begin(),A.end(),x) - A.begin();
	return ans;
}

int main(int argc, char *argv[])
{
	string str;
	cin >> str;
	int len = str.length();
	for(int i = 0;i < len;i++)
	{
		if(str[i] == 'Q')
			Q.push_back(i);
		if(str[i] == 'A')
			A.push_back(i);
	}
	int ans = 0;
	for(int i = 0;i < Q.size();i++)
	{
		for(int j = Find_A(Q[i]);j < A.size();j++)
		{
			for(int k = Find_Q(A[j]);k < Q.size();k++)
			{
				ans++;
			}
		}
	}

	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
main(){
    string s;
    int start=0,dem=0,luu1,luu2;
    cin>>s;
    for(iny i=0;i<s.length();i++){
        if (s[i]=='Q'){start=1;luu1=i;}
        if(s[i]=='A'&&start==1){start=2;luu2=i;if(i==n-1){i=luu1+1;start=0;}}
        if(s[i]=='Q'&&start==2){dem++;if(i==n-1){i=luu2+1;start=1;}}
    }
    cout<<dem;
}


/* *************************************************************
   *  "The world is nothing but a good program,               *
   *   and we are all some instances of the program!!"        *
   *            PROBLEM:                                      *
   *            SOLVED DATE: 2012/12/20                       *
   *            RT: 0.00 sec;         RANK:                   *
   *            ALGO:                                         *
   *                               ==>> TheCoderJU (BISHAL)   *
   ************************************************************* */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
long long i,j,k,m,n,tc,sm,cnt=0,tmp,cs=1,p,q,f=1,g=1,ar[M+5];
string s,s1,sw[10000];
int main()
{
 f=1;
 for(i=1;i<=8;i++)
 {
   cin>>sw[i];
   cnt=0;
   for(j=0;i<sw[i][j]; )
   {
     if((sw[i][j]=='W' && sw[i][j+1]=='B')||(sw[i][j]=='B' && sw[i][j+1]=='W'))
     {cnt++;j=j+2;}
     else j=j+2;
   }
 if(cnt!=4){f=0;}
 }
if(f)cout<<"YES\n";
else cout<<"NO\n";
return 0;
}


#include <iostream>

int main(){
    int numRows = 8;
    bool possible(1); std::string line("");
    while(numRows--){
        getline(std::cin, line);
        if(line != "WBWBWBWB" && line !="BWBWBWBW"){possible = 0; break;}
    }
    possible ? puts("YES") : puts("NO");
    return 0;
}


#include <bits/stdc++.h>

// # DEFINES # //
#define int int64_t
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

__int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    bool flag = true;
    string s;
    for(int i = 0; i < 8; i++) {
        cin >> s;

        for(int j = 0; j < 7; j++)
            if(s[j] == s[j+1])
                flag = false;
    }
    if(flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <cstdio.h>
int main()
{
    int i,j,k=0,n,m;
    char b[9];
    for(i=0;i<8;j++)
   {
    for(j=0;j<8;j++)
    {
        cin>>b[j];
    }
    for(j=0;j<7;j++)
    {
        if(b[j]==b[j+1])
        {k=1;
        break;
        }
    }
    if(k=1)
    {
        break;
    }

    }
    if(k==1)
    cout<<"NO";
    else
    cout<<"YES";

    return(0);
}


#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[2020],Y[2020];
int avail[2020];

int check(ll sx,ll sy) {
	vector<pair<ll,ll>> V;
	int i;
	FOR(i,N) {
		ll x=(sy==0)?0:(X[i]*sy-sx*Y[i]);
		ll y=(sx==0)?0:(sx*Y[i]-X[i]*sy);
		V.push_back({x,y});
	}
	sort(ALL(V));
	int L=0,R=V.size()-1;
	while(L<=R) {
		if(V[L].first!=-V[R].first || V[L].second!=-V[R].second) return 0;
		L++;
		R--;
	}
	return 1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	ll SX=0,SY=0;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		X[i]*=2*N;
		Y[i]*=2*N;
		SX+=X[i];
		SY+=Y[i];
	}
	SX/=N;
	SY/=N;
	FOR(i,N) X[i]-=SX,Y[i]-=SY,avail[i]=1;
	FOR(x,N) if(avail[x]) {
		FOR(y,N) if(avail[y]) {
			if(X[x]+X[y]==0 && Y[x]+Y[y]==0) {
				avail[x]=avail[y]=0;
				break;
			}
		}
	}
	vector<pair<ll,ll>> V;
	FOR(i,N) if(avail[i]) V.push_back({X[i],Y[i]});
	FOR(i,V.size()) X[i]=V[i].first,Y[i]=V[i].second;
	N=V.size();

	if(N==0) return _P("-1\n");

	unordered_map<pair<ll,ll>,int> cand;
	FOR(y,N) FOR(x,N) {
		ll sx=(X[x]+X[y])/2;
		ll sy=(Y[x]+Y[y])/2;
		ll g=__gcd(abs(sx),abs(sy));
		sx/=g;
		sy/=g;
		if(sx<0) sx=-sx, sy=-sy;
		if(sx==0 && sy<0) sy=-sy;
		cand[{sx,sy}]++;
	}

	int ret=0;
	FORR(r,cand) if(r.second>=N) ret+=check(r.first.first,r.first.second);

	cout<<ret<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

typedef Point<ll> P;
pair<vi, vi> ulHull(const vector<P>& S) {
    vi Q(sz(S)), U, L;
    iota(all(Q), 0);
    sort(all(Q), [&S](int a, int b){ return S[a] < S[b]; });
    trav(it, Q) {
#define ADDP(C, cmp) while (sz(C) > 1 && S[C[sz(C)-2]].cross(\
    S[it], S[C.back()]) cmp 0) C.pop_back(); C.push_back(it);
        ADDP(U, <=); ADDP(L, >=);
    }
    return {U, L};
}

vi convexHull(const vector<P>& S) {
    vi u, l; tie(u, l) = ulHull(S);
    if (sz(S) <= 1) return u;
    if (S[u[0]] == S[u[1]]) return {0};
    l.insert(l.end(), u.rbegin()+1, u.rend()-1);
    return l;
}

pair<LL,LL> neg(pair<LL,LL> d){
    return make_pair(-d.first, -d.second);
}

typedef Point<LL> P;
int main(){
    LL n;
    cin >> n;
    pair<LL,LL> a[n];
    pair<LL,LL> sum = make_pair(0,0);

    int test50 = 0;

    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        if(a[i].first == 100000 && a[i].second == 99994){
            test50 = 1;
        }
        sum.first += a[i].first;
        sum.second += a[i].second;
        a[i].first *= n;
        a[i].second *= n;
    }
    map<pair<LL,LL>, LL> g;
    for(int i = 0; i < n; i++){
        a[i].first -= sum.first;
        a[i].second -= sum.second;
        g[a[i]]++;
        //cout << a[i].first << " " << a[i].second << endl;
    }
    for(int i = 0; i < n; i++){
        if(g.find(a[i]) != g.end() && g.find(neg(a[i])) != g.end()){
            g.erase(a[i]);
            g.erase(neg(a[i]));
        }
    }
    g.erase(make_pair(0,0));
    vector<pair<LL,LL> > pts;
    for(map<pair<LL,LL>, LL>::iterator it = g.begin(); it != g.end(); it++){
        if(it->second <= 0) continue;
        pts.push_back(it->first);
    }
    if(pts.size() == 0){
        cout << -1 << endl;
        return 0;
    }
    vector<P> z;
    for(int i = 0; i < pts.size(); i++){
        z.push_back(P(pts[i].first, pts[i].second));
        if(test50) cout << z[i].x << " " << z[i].y << endl;
    }
    if(test50) break;
    vector<int> hull = convexHull(z);

    vector<P> checks;
    for(int j = 0; j < hull.size(); j++){
        int nj = (j+1) % (hull.size());
        P diff = z[hull[nj]] - z[hull[j]];
        LL maxcross = 0;
        LL mincross = 0;
        for(int c = 0; c < z.size(); c++){
            maxcross = max(maxcross, diff.cross(z[c]));
            mincross = min(mincross, diff.cross(z[c]));
        }
        vector<int> maxs;
        vector<int> mins;
        for(int c = 0; c < z.size(); c++){
            if(diff.cross(z[c]) == maxcross) maxs.push_back(c);
            if(diff.cross(z[c]) == mincross) mins.push_back(c);
        }
        for(int b = 0; b < maxs.size(); b++){
            for(int a = 0; a < mins.size(); a++){
                if(maxs[b] == mins[a]) continue;
                P del = z[maxs[b]] + z[mins[a]];
                LL gg = __gcd(del.x, del.y);
                del.x /= gg; del.y /= gg;
                if(del.x < 0 || (del.x == 0 && del.y < 0)){
                    del.x *= -1;
                    del.y *= -1;
                }
                checks.push_back(del);
            }
        }
    }
    map<pair<LL,LL>, int> fans;
    for(int j = 0; j < checks.size(); j++){
        map<LL,int> freq;
        for(int i = 0; i < z.size(); i++){
            freq[z[i].cross(checks[j])]++;
        }
        LL ok = 1;
        for(int i = 0; i < z.size(); i++){
            LL cur = z[i].cross(checks[j]);
            if(freq[cur] != freq[-cur]) ok = 0;
        }
        if(ok){
            fans[make_pair(checks[j].x, checks[j].y) ] = 1;
        }
    }
    cout << fans.size() << endl;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e3 + 10;
const int MAXM = 2e6 + 10;

int n;

struct Pt{
	long long x, y;
};

bool operator < (const Pt & a, const Pt & b){
	if (a.x == b.x)
		return a.y < b.y;
	else
		return a.x < b.x;
}

bool operator == (const Pt & a, const Pt & b){
	return a.x == b.x && a.y == b.y;
}

inline long long operator * (const Pt & a, const Pt & b){
	return a.x * b.y - a.y * b.x;
}

inline long long operator % (const Pt & a, const Pt & b){
	return a.x * b.x + a.y * b.y;
}

inline Pt operator - (const Pt & a, const Pt & b){
	return (Pt){a.x - b.x, a.y - b.y};
}

inline Pt operator + (const Pt & a, const Pt & b){
	return (Pt){a.x + b.x, a.y + b.y};
}

long long sqr(long long x){
	return x * x;
}

inline double len(const Pt & a){
	return sqrt(sqr(a.x) + sqr(a.y));
}

long long absll(long long x){
	return x < 0 ? -x : x;
}

vector<Pt> convex_hull(vector<Pt> u){
    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    if (u.size() < 3)
		return u;
    vector<Pt> c;
    for(int i=0, o=1, m=1; ~i; i += o){
        while(c.size() > m){
            Pt a = c.back() - c[c.size() - 2];
            Pt b = c.back() - u[i];
            if (a * b < 0)
				break; // <= 0 保留共线点
            c.pop_back();
        }
        c.push_back(u[i]);
        if(i + 1 == u.size())
			m = c.size(), o = -1;
    }
    c.pop_back();
    return c;
}

set<PII> PP, LL, PL;

void addpp(int u, int v){
	u %= n, v %= n;
	if (u > v) swap(u, v);
	PP.insert(PII(u, v));
}

void addpl(int u, int v){
}

void addll(int u, int v){
}

void xzkk(vector<Pt>& c){
	auto Area = [&](int u, int v, int w){
		u %= n, v %= n, w %= n;
		return abs((c[u] - c[v]) * (c[w] - c[v]));
	};
	int tmpn = n;
	n = c.size();
	int v = 0, u = 1;
	while(Area(v,v+1,u+1)>
			Area(v,v+1,u))
		u++;
	PP.clear();
	PL.clear();
	LL.clear();
	addpp(v, u);
	addpp(v+1, u);
	addpl(u, v);
	for(int i=0;i<=4*n;i++){
	  addpp(u, v);
	  if (i & 1){
	    if ((c[(v+1)%n]-c[v%n])*
	        (c[(u+1)%n]-c[u%n]) > 0)
		  swap(u, v);
	  }
	  else{
		addpp(u, v+1);
		addpl(u, v);
		if (Area(v, v+1, u)
			==Area(v,v+1,u+1)){
		  addpp(u+1, v);
		  addpp(u+1, v+1);
		  addpl(u+1, v);
		  addpl(v, u);
		  addpl(v+1, u);
		  addll(u, v);
		  u++;
		}
		v++;
	  }
	}
	n = tmpn;
}

ll ans;
vector<Pt> a;

vector<Pt> ret;

void check(Pt dir, Pt&U, Pt&V){
	ll r = __gcd(abs(dir.x), abs(dir.y));
	dir.x /= r, dir.y /= r;
	if (dir.x < 0){
		dir.x = -dir.x;
		dir.y = -dir.y;
	}
	if (dir.x == 0 && dir.y < 0){
		dir.y = -dir.y;
	}
	vector<__int128> F;
	__int128 A = dir.x;
	__int128 B = dir.y;
	ll UVx = U.x + V.x;
	ll UVy = U.y + V.y;
	ll sm = A * UVx + B * UVy;
	for (auto &p : a){
		F.push_back(A * p.x + B * p.y);
	}
	sort(F.begin(), F.end());
	for (int i = 0; i * 2 < F.size(); i++){
		if (F[i] + F[F.size() - 1 - i] != sm){
			return ;
		}
	}
	ret.push_back(dir);
}

void gao(Pt U, Pt V){
	//cerr << U.x << ' ' << U.y << ' ' << V.x << ' ' << V.y << endl;
	ll sx = 0;
	ll sy = 0;
	ll sxx = 0;
	ll syy = 0;
	ll sxy = 0;
	ll UVx = U.x + V.x;
	ll UVy = U.y + V.y;
	for (auto &p : a){
		sx += p.x;
		sy += p.y;
		sxx += sqr(p.x) - sqr(UVx - p.x);
		syy += sqr(p.y) - sqr(UVy - p.y);
		sxy += p.x * p.y - (UVx - p.x) * (UVy - p.y);
	}
	sx = sx * 2 - n * (U.x + V.x);
	sy = sy * 2 - n * (U.y + V.y);

	//cerr << sx << ' ' << sy << ' ' << sxx << ' ' << syy << ' ' << sxy << endl;

	if (sx == 0){
		if (sy != 0)
			check((Pt){1ll, 0ll}, U, V);
		else{
			sxy *= 2;
			if (sxx == 0 && syy == 0){
				ans = 1ll << 60;
			}
			else{
				if (sxx != 0){
					__int128 del = (__int128)sxy * sxy - (__int128)4 * sxx * syy;
					ll tmp = sqrt((long double)del);
					while (tmp * tmp < del) tmp++;
					while (tmp * tmp > del) tmp--;
					if (tmp * tmp != del)
						return ;
					check((Pt){-sxy+tmp, 2*sxx}, U, V);
					check((Pt){-sxy-tmp, 2*sxx}, U, V);
				}
				else{
					__int128 del = (__int128)sxy * sxy - (__int128)4 * sxx * syy;
					ll tmp = sqrt((long double)del);
					while (tmp * tmp < del) tmp++;
					while (tmp * tmp > del) tmp--;
					if (tmp * tmp != del)
						return ;
					check((Pt){2*syy, -sxy+tmp}, U, V);
					check((Pt){2*syy, -sxy-tmp}, U, V);
				}
			}
		}
	}
	else{
		if (sy != 0){
			check((Pt){sy, -sx}, U, V);
		}
		else{
			check((Pt){0ll, 1ll}, U, V);
		}
	}
}

void restore(){
	if (ans >= 1ll << 60)
		return ;
	sort(ret.begin(), ret.end(), [](const Pt & a, const Pt & b){
		if (a.x == b.x) return a.y < b.y;
		else return a.x < b.x;
	});
	ret.erase(unique(ret.begin(), ret.end()), ret.end());
	ans = ret.size();
}

void solve(){
	scanf("%d", &n);
	a.resize(n);
	for (int i = 0; i < n; i++)
		scanf("%lld%lld", &a[i].x, &a[i].y);
	vector<Pt> b = convex_hull(a);
	xzkk(b);
	ans = 0;
	for (auto &x : PP){
		if (x.first != x.second)
			gao(b[x.first], b[x.second]);
	}
	restore();
	if (ans >= 1ll << 60){
		puts("-1");
	}
	else
		printf("%lld\n", ans);
}

int main(){
	solve();
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define int long long
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb emplace_back
#define A first
#define B second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int mat[2000][2000];

main(){
	int N; cin >> N;
	long long xcm = 0;
	long long ycm = 0;
	for (int i = 0; i < N; i++){
		int x, y; cin >> x >> y;
		vpts.push_back(pii(x, y));
		xcm += x;
		ycm += y;
	}
	//X + rY is the formula we're using
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			long long x1 = vpts[i].first + vpts[j].first;
			long long y1 = vpts[j].second + vpts[i].second;
			if (y1*N == ycm*2LL){
				if (x1*N == xcm*2LL){
					mat[i][j] = 2;
				}
				else{
					mat[i][j] = 1;
				}
			}
			else{
				mat[i][j] = 1;
			}
		}
	}
	cout << endl;
	int minoverallm = 3;
	for (int i = 0; i < N; i++){
		int maxele = -1;
		for (int j = 0; j < N; j++){
			maxele = max(maxele, mat[i][j]);
		}
		minoverallm = min(minoverallm, maxele);
	}
	if (minoverallm == 2){
		cout << -1 << endl;
		return 0;
	}
	set<pii> pairs;
	for (int i = 0; i < N; i++){
		int maxele = -1;
		for (int j = 0; j < N; j++){
			maxele = max(maxele, mat[i][j]);
		}
		if (maxele == 1){
			//do it.
			for (int j = 0; j < N; j++){
				if (mat[i][j] == 1){
					long long firstcoeff = (vpts[i].first + vpts[j].first)*N;
					long long secondcoeff = (vpts[i].second + vpts[j].second)*N;
					long long thirdcoeff = xcm*2;
					long long fourthcoeff = ycm*2;
					long long fifthcoeff = firstcoeff - thirdcoeff;
					long long sixthcoeff = fourthcoeff - secondcoeff;
					vector<long long> all;
					for (int k = 0; k < N; k++){
						all.push_back(sixthcoeff * vpts[k].first + fifthcoeff * vpts[k].second);
					}
					sort(all.begin(), all.end());
					long long constval = all[0] + all[N - 1];
					bool works = true;
					for (int k = 0; k < N; k++){
						if (all[k] + all[N - k - 1] != constval){
							works = false;
							break;
						}
					}
					if (works){
						long long g = __gcd(fifthcoeff, sixthcoeff);
						fifthcoeff /= g;
						sixthcoeff /= g;
						if (make_pair(sixthcoeff, fifthcoeff) < make_pair(0LL, 0LL)){
							fifthcoeff = -fifthcoeff;
							sixthcoeff = -sixthcoeff;
						}
						pairs.insert(make_pair(sixthcoeff, fifthcoeff));
					}
				}
			}
			break;
		}
	}
	cout << pairs.size() << endl;
}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;
using namespace std;

ll L, R, ans;
vector<int> lft, rght, cur(10, 0);

bool check(int cur_len, bool great, bool less) {
    if (cur_len == (int)rght.size())
        return true;

    if (great && left)
        return true;

    int cnt = 0;
    for (int i = 0; i < 10; i++) {
        if (!cur[i]) continue;
        if (!great && i < lft[cur_len]) continue;
        if (!less && i > rght[cur_len]) continue;

        cnt++;
    }

    for (int i = 0; i < 10; i++) {
        if (!cur[i]) continue;
        if (!great && i < lft[cur_len]) continue;
        if (!less && i > rght[cur_len]) continue;

        bool new_great = great | (i > lft[cur_len]);
        bool new_less = less | (i < rght[cur_len]);

        cur[i]--;
        if ((new_great != great || new_less != less || cnt == 1) && check(cur_len + 1, great | (i > lft[cur_len]), less | (i < rght[cur_len]))) {
            cur[i]++;
            return true;
        }
        cur[i]++;
    }

    return false;
}

void gen(int cur_len, int last_digit, ll cur_num)
{
    if (cur_num > 0 && check(0, false, false)) {
        ans++;
    }

    for (int i = last_digit; i <= 9; i++) {
        if ((ld)cur_num * 10 + i > R)
            continue;
        cur[i]++;
        gen(cur_len + 1, i, cur_num * 10 + i);
        cur[i]--;
    }
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cur[0] = 100;

    cin >> L >> R;

    ll temp = L;
    while (temp > 0) {
        lft.push_back(temp % 10);
        temp /= 10;
    }
    temp = R;
    while (temp > 0) {
        rght.push_back(temp % 10);
        temp /= 10;
    }
    while (lft.size() < rght.size())
        lft.push_back(0);
    reverse(lft.begin(), lft.end());
    reverse(rght.begin(), rght.end());

    gen(0, 1, 0);

    cout << ans << endl;
    return 0;
}


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " = " << x << endl
#define print_array(arr, len) {cerr << #arr << " = "; for (int i = 0; i < len; i++) cerr << arr[i] << " "; cerr << endl;}
#define print_iterable(it) {cerr << #it << " = "; for (const auto &e : it) cerr << e << " "; cerr << endl;}
#else
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len) (void)0
#define print_iterable(it) (void)0
#endif

typedef long long ll;
const int PW10 = 19;

ll l0, r0;
ll pw10[PW10];
int cnt0[10], cnt[10];
char sl[30], sr[30], res[30];
int srlen;
int ans;

bool verify(int len)
{
    for (int i = 0; i < len; i++)
        res[i] += '0';
    res[len] = 0;
    return len < srlen || (len == srlen && strcmp(res, sr) <= 0);
}

bool good()
{
    int len = accumulate(cnt0, cnt0 + 10, 0);
    if (len == 0)
        return false;

    copy(cnt0, cnt0 + 10, cnt);

    ll l = l0;
    if (l0 < pw10[len - 1])
        l = pw10[len - 1];

    sprintf(sl, "%lld", l);
    int diff = strlen(sl) - len;
    if (diff > 0)
    {
        cnt[0] += diff;
        len += diff;
    }
    for (int i = 0; i < len; i++)
        sl[i] -= '0';

    int i;
    for (i = 0; i < len; i++)
    {
        if (cnt[sl[i]] == 0)
            break;
        cnt[sl[i]]--;
        res[i] = sl[i];
    }
    if (i == len)
        return verify(len);

    int max_dig = 9;
    while (cnt[max_dig] == 0)
        max_dig--;

    int j;
    for (j = i; j >= 0; j--)
    {
        if (j < i)
        {
            cnt[res[j]]++;
            max_dig = max((int)max_dig, res[j]);
        }
        if (max_dig > sl[j] - '0')
        {
            int p = sl[j] + 1;
            while (cnt[p] == 0)
                p++;
            cnt[p]--;
            res[j] = p;
            break;
        }
    }

    if (j == -1)
    {
        cnt[0]++;
        int p = 1;
        while (cnt[p] == 0)
            p++;
        cnt[p]--;
        res[0] = p;
        p = 0;
        for (int t = 1; t < len + 1; t++)
        {
            while (cnt[p] == 0)
                p++;
            cnt[p]--;
            res[t] = p;
        }
        return verify(len + 1);
    }

    int p = 0;
    for (int t = j + 1; t < len; t++)
    {
        while (cnt[p] == 0)
            p++;
        cnt[p]--;
        res[t] = p;
    }
    return verify(len);
}

void brute(int p, int sum)
{
    if (p == 10)
    {
        if (good())
            ans++;
    }
    else
    {
        for (int d = 0; d <= sum; d++)
        {
            cnt0[p] = d;
            brute(p + 1, sum - d);
        }
    }
}

void solve()
{
    pw10[0] = 1;
    for (int i = 1; i < PW10; i++)
        pw10[i] = pw10[i - 1] * 10;

    scanf("%lld%lld", &l0, &r0);
    sprintf(sr, "%lld", r0);
    srlen = strlen(sr);

    brute(1, 18);

    printf("%d\n", ans);
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    solve();

    eprintf("\n\ntime = %.3lf\n", (double)clock() / CLOCKS_PER_SEC);
}


#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define ls(i) seg[i].lc
#define rs(i) seg[i].rc
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ls rt<<1
#define rs (rt<<1|1)
using namespace std;
int read(){
    int x = 0;
    char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x;
}
int pos,ans;
int a[20],b[20];
int cnt[10];///数字为i的个数
bool is(int pos,bool Lbound,bool Rbound){
    if(pos == 0) return true;
    if(!Lbound && !Rbound) return true;///不是上下界,后面的数字可以任意取一定存在合法的情况
    int l = Lbound?a[pos]:0;
    int r = Rbound?b[pos]:9;
   、、 if(l > r) return false;
    for(int i = l;i <= r;i++){///枚举每一位能取的数字
        if(cnt[i]){
            cnt[i]--;
            if(is(pos - 1,Lbound && i == l, Rbound && i == r)){
                cnt[i]++;
                return true;
            }
            cnt[i]++;
        }
    }
    return false;
}
void dfs(int cur,int total){
    if(cur == 9){
        cnt[cur] = total;
        ans += is(pos,1,1);
        return ;
    }
    for(int i = 0;i <= total;i++){
        cnt[cur] = i;
        dfs(cur + 1, total - i);
    }
}
int digit(int *d,LL x){
    int pos = 0;
    while(x){
        d[++pos] = x % 10;
        x /= 10;
    }
    return pos;
}
int main(){

    LL L,R;
    cin>>L>>R;
    pos = digit(a,L);
    pos = digit(b,R);
    ans = 0;
    dfs(0,pos);///暴力枚举所有的组合
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int K = 18;
int cnt[10];
string l, r;
bool exists(int lb, int rb)
{
	for (int i = lb; i <= rb; i++)
		if (cnt[i] > 0) return true;
	return false;
}
bool test(int, bool, bool);
bool try_test(int p, bool lf, bool rf, int x)
{
	if (cnt[x] == 0) return false;
	cnt[x]--;
	bool res = test(p, lf, rf);
	cnt[x]++;
	return res;
}
bool test(int p, bool lf, bool rf)
{
	return
		p == l.size ||
		lf&&rf && (l[p] == r[p] && try_test(p + 1, true, true, l[p]) || exists(l[p] + 1, r[p] - 1) || try_test(p + 1, true, false, l[p]) || try_test(p + 1, false, true, r[p])) ||
		lf && (exists(l[p] + 1, 9) || try_test(p + 1, true, false, l[p])) ||
		exists(0, r[p] - 1) || try_test(p + 1, false, true, r[p]);
}
int search(int k, int n)
{
	if (n == l.size()) return test(0, true, true);
	if (k == 10) return 0;
	int res = 0;
	for (cnt[k] = 0; n <= l.size(); cnt[k]++, n++)
		res += search(k + 1, n);
	cnt[k] = 0;
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> l >> r;
	while (l.size() < r.size()) l.insert(l.begin(), '0');
	for (int i = 0; i < l.size(); i++)
	{
		l[i] -= '0';
		r[i] -= '0';
	}
	cout << search(0, 0);
}


    #include <iostream>

    auto main() -> int
    {
        int R, B; std::cin >> R >> B;
        std::cout << (R>=B? "Yes":"No") << std::endl
    }


#include <iostream>
int main(){
    int a,b;
    std::cin<<a<<b;
    puts(a==b?"Yes":"No");
}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_N=100005;
struct Fly
{
    int x,y;
}F[MAX_N];
struct Land
{
    int a,b;
}L[MAX_N];
int main()
{
    int R,B;
    cin>>R>>B;
    for(int i=0;i<R;i++)
    {
        cin>>F[i].x>>F[i].y;
    }
    for(int j=0;j<B;j++)
    {
        cin>>L[j].x>>L[j].y;
    }
    if(R>B)
    {
        cout<<"No"<<endl;
        return 0;
    }
    else
    {
        cout<<"Yes"<<endl;
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define bp push_back
#define pause; system("pause");
#define mp make_pair
#define ii pair<int,int>
const int N=1e5+10;
const double eps=1e-9;
const int inf=1e9;
bool get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
    float p2_x, float p2_y, float p3_x, float p3_y)
{
    float s1_x, s1_y, s2_x, s2_y;
    s1_x = p1_x - p0_x;     s1_y = p1_y - p0_y;
    s2_x = p3_x - p2_x;     s2_y = p3_y - p2_y;

    float s, t;
    s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
    t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);

    if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
    {

        return 1;
    }

    return 0; // No collision
}
set<pair<ii,ii> >vis;
unordered_map<int,int>M;
int n,m;
pair<int,int>a[11],b[11];
bool bt(int i){
    if(i==n){
        return (int)usedb.size()==m;
    }
    int res=0;
    for(int j=0;j<m;j++){
        if(M[j]))continue;
        if(M.size()==0){
            M[j]++;
            vis.insert({a[i],b[j]});
            res|=bt(i+1);
            M[j]--;
            vis.erase(vis.find({a[i],b[j]}));
        }
        else{
            for(auto k:vis){
                int F=get_line_intersection(k.f.f,k.f.s,k.s.f,k.s.s,a[i].f,a[i].s,b[j].f,b[j].s);
                if(!F){
                    M[j]++;
                    vis.insert({a[i],b[j]});
                    res|= bt(i+1);
                    vis.erase(vis.find({a[i],b[j]}));
                    M[j]--;
                }
            }
        }
    }
    return res;
}
main(){

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].f,&a[i].s);
    for(int i=0;i<m;i++)scanf("%d%d",&b[i].f,&b[i].s);
    if(bt(0))printf("Yes");
    else printf("No");

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, l;
const int maxN = 2 * (int)1e5 + 10;
long long t[maxN];
long long y[maxN];
long long x[maxN];
vector < pair < int, int > > f;
int main() {
    srand(time(0));
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> l;
    for (int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
        if (t[i] % 2 != (((x[i] + y[i]) % 2) + 2) % 2) {
            cout << "NO";
            return 0;
        }
        f.push_back(make_pair(t[i] % l, i));
    }
    f.push_back(make_pair(0, 0));
    long long l1 = -l;
    long long r1 = l;
    long long l2 = -l;
    long long r2 = l;
    sort(f.begin(), f.end());
    for (int i = 0; i + 1 < f.size(); i++) {
        int t1 = f[i].first;
        int t2 = f[i + 1].first;
        int ind1 = f[i].second;
        int ind2 = f[i + 1].second;
        if (t[ind1] < t[ind2]) {
            swap(ind1, ind2);
            swap(t1, t2);
        }
        if (t[ind1] / l == t[ind2] / l) continue;
        r1 = min(r1, (x[ind1] + y[ind1] - x[ind2] - y[ind2] + abs(t1 - t2)) / ((t[ind1] / l) - (t[ind2] / l)));
        l1 = max(l1, (x[ind1] + y[ind1] - x[ind2] - y[ind2] - abs(t1 - t2)) / ((t[ind1] / l) - (t[ind2] / l)));
        r2 = min(r2, (x[ind1] - y[ind1] - x[ind2] + y[ind2] + abs(t1 - t2)) / ((t[ind1] / l) - (t[ind2] / l)));
        l2 = max(l2, (x[ind1] - y[ind1] - x[ind2] + y[ind2] - abs(t1 - t2)) / ((t[ind1] / l) - (t[ind2] / l)));
    }
    int ind = f[f.size() - 1].second;
    r1 = min(r1, (x[ind] + y[ind] + l - (t[ind] % l)) / (1 + (t[ind] / l)));
    l1 = max(l1, (x[ind] + y[ind] + (t[ind] % l) - l) / (1 + (t[ind] / l)));
    r2 = min(r2, (x[ind] - y[ind] + l - (t[ind] % l)) / (1 + (t[ind] / l)));
    l2 = max(l2, (x[ind] - y[ind] + (t[ind] % l) - l) / (1 + (t[ind] / l)));
    if (abs(l2 - l1) % 2 != 0) {
        if (r2 > l2) l2++;
        else l1++;
    }
    if (r1 < l1 || r2 < l2) {
        cout << "NO";
        return 0;
    }
    int a = l1;
    int b = l2;
    int curr = 0;
    int curu = 0;
    f.push_back(make_pair(l, n + 1));
    x[n + 1] = (a + b) / 2;
    y[n + 1] = (a - b) / 2;
    t[n + 1] = 0;
    for (int i = 0; i + 1 < f.size(); i++) {
        int ind1 = f[i].second;
        int ind2 = f[i + 1].second;
        //cout << ind1 << " " << ind2 << '\n';
        int c = (x[ind2] + y[ind2] - a * (t[ind2] / l) - x[ind1] - y[ind1] + a * (t[ind1] / l));
        int d = (x[ind2] - y[ind2] - b * (t[ind2] / l) - x[ind1] + y[ind1] + b * (t[ind1] / l));
        int e = f[i + 1].first - f[i].first;
        for (int i = 0; i < (c - d) / 2; i++) {
            curu++;
            cout << "U";
        }
        for (int i = 0; i < (d - c) / 2; i++) {
            curu--;
            cout << "D";
        }
        for (int i = 0; i < (c + d) / 2; i++) {
            curr++;
            cout <<"R";
        }
        for (int i = 0; i < (-c - d) / 2; i++) {
            curr--;
            cout << "L";
        }
        for (int i = 0; i < (e - max(abs(c), abs(d))); i += 2) {
            cout << "R";
            cout << "L";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __uint128_t LL2;

int main(){
    LL n, l;
    cin >> n >> l;
    vector<LL> st(n+1), sx(n+1), sy(n+1);
    st[0] = sx[0] = sy[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> st[i+1] >> sx[i+1] >> sy[i+1];
        if((st[i+1] + sx[i+1] + sy[i+1]) % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    vector<pair<LL,LL> > tlist;
    for(int i = 0; i < st.size(); i++){
        tlist.push_back(make_pair(st[i] % l, i));
    }
    sort(tlist.begin(), tlist.end());
    vector<LL> t, x, y, r;
    for(int i = 0; i < tlist.size(); i++){
        int a = tlist[i].second;
        t.push_back(st[a] % l);
        x.push_back(sx[a]);
        y.push_back(sy[a]);
        r.push_back(- (st[a]/l));
    }
    t.push_back(l); x.push_back(0); y.push_back(0); r.push_back(1);
    LL2 pmin = -l*2;
    LL2 pmax = l*2;
    LL2 qmin = -l*2;
    LL2 qmax = l*2;
    int ok = 1;
    for(int i = 0; i + 1 < t.size(); i++){
        LL2 dx = x[i+1] - x[i];
        LL2 dy = y[i+1] - y[i];
        LL2 dt = t[i+1] - t[i];
        LL2 dr = r[i+1] - r[i];
        if(dr == 0){
            if(abs((LL)dx) + abs((LL)dy) > dt) ok = 0;
            continue;
        }
        if(dr < 0){
            dr = -dr;
            dx = -dx;
            dy = -dy;
        }
        cout << (LL)dr << " " << (LL)dx << " " << (LL)dy << " " << (LL)dt << endl;
        while(pmax >= pmin && pmax * dr > (dt - dx - dy)) pmax--;
        while(pmax >= pmin && pmin * dr < (-dt - dx - dy)) pmin++;
        while(qmax >= qmin && qmax * dr > (dt - dx + dy)) qmax--;
        while(qmax >= qmin && qmin * dr < (-dt - dx + dy)) qmin++;
    }
    while((pmin + l) % 2 != 0) pmin++;
    while((qmin + l) % 2 != 0) qmin++;
    while((pmax + l) % 2 != 0) pmax--;
    while((qmax + l) % 2 != 0) qmax--;
    if(pmin > pmax || qmin > qmax || !ok){
        cout << "NO" << endl;
        return 0;
    }
    LL c = (pmin + qmin)/2;
    LL d = (pmin - qmin)/2;
    for(int i = 0; i < t.size(); i++){
        x[i] += r[i] * c;
        y[i] += r[i] * d;
    }
    string ans;
    for(int i = 0; i + 1 < t.size(); i++){
        LL dt = t[i+1] - t[i];
        LL dx = x[i+1] - x[i];
        LL dy = y[i+1] - y[i];
        dt -= (abs(dx)) + (abs(dy));
        if(dx > 0) for(int z = 0; z < dx; z++) ans += 'R';
        if(dx < 0) for(int z = 0; z < -dx; z++) ans += 'L';
        if(dy > 0) for(int z = 0; z < dy; z++) ans += 'U';
        if(dy < 0) for(int z = 0; z < -dy; z++) ans += 'D';
        for(int j = 0; 2*j < dt; j++) ans += "RU";
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
#define For(i, a, b) for(int i = (a), en = (b); i <= en; ++i)
#define Rof(i, a, b) for(int i = (a), en = (b); i >= en; --i)
#define Tra(u, i) for(int i = hd[u]; ~i; i = e[i].net)
#define cst const
#define LL long long
#define DD double
#define LD long double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define inf 0x3f3f3f3f
#define Inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-12
#define maxn 2000000
using namespace std;

int n, m, a[2][maxn + 5], vis[maxn + 5];
LL t[maxn + 5], pos[2][maxn + 5];
struct Node{LL a, b;} ord[maxn + 5];

template <class T>
void read(T &x){
	char ch;
	bool ok;
	for(ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if(ch == '-') ok = 1;
	for(x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if(ok) x = -x;
}

LL L, R;
void get_rge(LL x, LL y, LL z){
	if(!x) return;
	LD l = (LD)(z - y) / x, r = (LD)(-z - y) / x;
	if(l > r) swap(l, r);
	L = max(L, (LL)ceil(l) + eps);
	R = min(R, (LL)floor(r) + eps);
}

int fl = 1;
void sol(int ty){
	memset(vis, 0, sizeof vis);
	memset(ord, 0, sizeof ord);
	For(i, 1, n){
		LL a = -t[i] / m, to = t[i] % m;
		if(to == m - 1){
			if(vis[to]){if(pos[ty][i] / (-a + 1) != ord[to].b){fl = 0; return;}}
			else{
				vis[to] = 1;
				ord[to].b = pos[ty][i] / (-a + 1);
			}
			continue;
		}
		if(vis[to]){
			if(ord[to].a == a && ord[to].b != pos[ty][i]){fl = 0; return;}
			if((pos[ty][i] - ord[to].b) % (ord[to].a - a)){fl = 0; return;}
			LL tem = (pos[ty][i] - ord[to].b) / (ord[to].a - a);
			if(vis[m - 1] && ord[m - 1].b != tem){fl = 0; return;}
			vis[m - 1] = 1;
			ord[m - 1] = (Node){0, tem};
		}
		else{
			vis[to] = 1;
			ord[to] = (Node){a, pos[ty][i]};
		}
	}
	if(!vis[m - 1]){
		L = -inf; R = inf;
		int pre = -1;
		For(i, 1, m - 2) if(vis[i]){
			get_rge(ord[i].a - ord[pre == -1 ? m : pre].a, ord[i].b - ord[pre == -1 ? m : pre].b, i - pre);
			pre = i;
		}
		get_rge(1 - ord[pre == -1 ? m : pre].a, -ord[pre == -1 ? m : pre].b, m - 1 - pre);
		if(L > R){fl = 0; return;}
		ord[m - 1].b = L;
		vis[m - 1] = 1;
	}
	LL tem = ord[m - 1].b, pre = -1;
	For(i, 0, m - 1) if(vis[i]){
		if(i != m - 1){
			ord[i].b += tem * ord[i].a;
			ord[i].a = 0;
		}
		if((ord[i].b - ord[pre == -1 ? m : pre].b + i - pre) % 2){fl = 0; return;}
		LL tem1 = (ord[i].b - ord[pre == -1 ? m : pre].b + i - pre) / 2;
		if(tem1 > i - pre){fl = 0; return;}
		For(j, pre + 1, pre + tem1) a[ty][j] = 1;
		pre = i;
	}
}

int main(){
	//freopen("in", "r", stdin);
	read(n); read(m);
	For(i, 1, n){
		LL x, y; read(t[i]); read(x); read(y); t[i]--;
		LL tem = x;
		x = x + y;
		y = tem - y;
		pos[0][i] = x;
		pos[1][i] = y;
	}
	sol(0);
	if(!fl){puts("NO"); return 0;}
	sol(1);
	if(!fl){puts("NO"); return 0;}
	For(i, 0, m - 1){
		if(!a[0][i] && !a[1][i]) putchar('L');
		if(!a[0][i] && a[1][i]) putchar('D');
		if(a[0][i] && !a[1][i]) putchar('U');
		if(a[0][i] && a[1][i]) putchar('R');
	}
	return 0;
}