#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cmath>
#include <deque>

using ll=long long;
using namespace std;

int main(){
    int R,C;
    cin>>R>>C;

    vector<vector<int>> A(R,vector<int>(C-1));
    vector<vector<int>> B(R-1,vector<int>(C));

    for(int i=0;i<R;i++){
        for(int j=0;j<C-1;j++){
            cin>>A[i][j];
        }
    }

    for(int i=0;i<R-1;i++){
        for(int j=0;j<C;j++){
            cin>>B[i][j];
        }
    }

    ll INF = 1e15;
    vector<vector<ll>> dp(R,vector<ll>(C,INF));
    dp[0][0] = 0;
    priority_queue<pair<ll, pair<int,int>>> q;
    q.push({0,{0,0}});
    while(!q.empty()){
        auto recv = q.top();
        ll nowc = recv.first*-1;
        int nx = recv.second.first;
        int ny = recv.second.second;
        q.pop();
        //cout<<nowc<<" "<<nx<<" "<<ny<<endl;
        /*
        if(dp[nx][ny] <= nowc){
            continue;
        }else{
            dp[nx][ny] = nowc;
        }
        //*/
        if(nx == R-1 && ny == C-1){
            break;
        }

        if(ny < C-1){
            ll cos = nowc+A[nx][ny];
            if(dp[nx][ny+1] > cos){
                dp[nx][ny+1] = cos;
                q.push({-1*cos, {nx, ny+1}});
            }
        }
        if(ny > 0){
            ll cos = nowc+A[nx][ny-1];
            if(dp[nx][ny-1] > cos){
                dp[nx][ny-1] = cos;
                q.push({-1*(nowc+A[nx][ny-1]), {nx,ny-1}});
            }
        }
        if(nx < R-1){
            ll cos = nowc+B[nx][ny];
            if(dp[nx+1][ny] > cos){
                dp[nx+1][ny] = cos;
                q.push({-1*(nowc+B[nx][ny]), {nx+1,ny}});
            }
        }
        //*
        for(int i=1;i<=nx;i++){
            if(nowc+1+i > dp[nx-i][ny]){
                break;
            }
            dp[nx-i][ny] = nowc+1+i;
            q.push({-1*(nowc+1+i), {nx-i,ny}});
        }
        //*/
        /*
        if(nx != 0){
            q.push({-1*(nowc)})
        }
        //*/
    }
    cout<<dp[R-1][C-1]<<endl;

    return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
    priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
    dist[s] = 0;
    que.push(make_pair(0,s));
    while (!que.empty()) {
        pair<ll,int> p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (pair<int,T>& e : edges[v]) {
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(make_pair(dist[e.first],e.first));
            }
        }
    }
}

int r,c;
int coord(int i,int j) {
    return i*c+j;
}

int main() {
    cin >> r >> c;
    vector<vector<pair<int,ll>>> edges(r*c*2);
    for (int i = 0;i < r;++i) for (int j = 0;j < c-1;++j) {
        int a;
        scanf("%d",&a);
        edges[coord(i,j)].push_back(make_pair(coord(i,j+1),a));
        edges[coord(i,j+1)].push_back(make_pair(coord(i,j),a));
    }

    for (int i = 0;i < r-1;++i) for (int j = 0;j < c;++j) {
        int a;
        scanf("%d",&a);
        edges[coord(i,j)].push_back(make_pair(coord(i+1,j),a));
    }
    for (int i = 0;i < r;++i) for (int j = 0;j < c;++j) {
        edges[coord(i,j)].push_back(make_pair(coord(i,j)+r*c,0));
        edges[coord(i,j)+r*c].push_back(make_pair(coord(i,j),1));
    }
    for (int i = 1;i < r;++i) for (int j = 0;j < c;++j) {
        edges[coord(i,j)+r*c].push_back(make_pair(coord(i-1,j)+r*c,1));
    }
    vector<ll> dist(2*r*c,1e18);
    dijkstra(0,edges,dist);
    cout << dist[coord(r-1,c-1)] << newl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <functional>
#include <map>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
using Interval = pair<ll,ll>;
using Graph = vector<vector<ll> >;

template<class T> void chmax(T& a, T b){
    if (a < b){
        a=b;
    }
}

template<class T> void chmin(T& a, T b){
    if (a > b){
        a=b;
    }
}

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    ll ans;
    ll maxnum = 0;
    repi(i,2,1001){
        ll num = 0;
        rep(j,N){
            if (a[j] % i == 0) num++;

        }
        if (num >= maxnum){
            maxnum = num;
            ans = i;
        }

    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

#define ll                 long long
#define sf                 scanf
#define pf                 printf
#define nl                 printf("\n")
#define endl               '\n'
#define pb                 push_back
#define rep(i,a,b)         for(int i=a; i<b; i++)
#define repr(i,a,b)        for(int i=a; i>=b; i--)
#define TEST               int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)
#define isValid(a,b,A,B)   (0<=a&&a<A) and (0<=b&&b<B)

using namespace std;

template <typename... T> void read(T &... args){ ((cin >> args), ...); }

void yes(){ pf("Yes\n"); }
void no() { pf("No\n"); }

typedef pair<int,int> Pr;

int main()
{
	int n,x;
	vector<Pr> vec,temp;
	read(n);
	n = pow(2,n);
	rep(i,0,n) read(x), vec.pb(Pr(x,i+1));
	while(vec.size()>2){
		for(int i=0; i<(int)vec.size(); i+=2){
			if(vec[i].first>vec[i+1].first)
				temp.pb(vec[i]);
			else temp.pb(vec[i+1]);
		}
		vec.clear();
		for(auto w : temp) vec.pb(w);
		temp.clear();
	}
	int ans;
	if(vec[0].first<vec[1].first) ans = vec[0].second;
	else ans = vec[1].second;
	pf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(7-a)+(7-b)+(7-c);

    return 0;
}

//多练，就是多练
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//记得初始化和clear
//记得取模
//数组开够
//边界情况不要想当然
//特判记得return
const int maxn=100010;
const int mod=1e9+7;
int a[1010];
void solve(int T)
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(c%2==0)
    {
        if(c==0)
        {
            cout<<"="<<endl;
            return;
        }
        a=abs(a);b=abs(b);
        if(a>b) cout<<">"<<endl;
        else if(a==b) cout<<"="<<endl;
        else cout<<"<"<<endl;
    }
    else
    {
        if(a<0&&b<0)
        {
            if(a>b) cout<<">"<<endl;
            else if(a==b) cout<<"="<<endl;
            else cout<<"<"<<endl;
        }
        else if(a>=0&&b>=0)
        {
            if(a>b) cout<<">"<<endl;
            else if(a==b) cout<<"="<<endl;
            else cout<<"<"<<endl;
        }
        else if(a>=0&&b<0) cout<<">"<<endl;
        else if(a<0&&b>=0) cout<<"<"<<endl;
    }

}
//#define ONLINE_JUDGE
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("lotato.in","r",stdin);
    freopen("lotato.out","w",stdout);
    #endif
    int t=1;
    //scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}

signed main()
{
	int n=read(),ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;i*j<=n;j++)
		{
			ans+=n/i/j;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int countConsecutive(int N)
{
    int count = 0;
    for (int L = 1; L * (L + 1) < 2 * N; L++)
    {
        double a = (1.0 * N-(L * (L + 1)) / 2) / (L + 1);
        if (a-(int)a == 0.0)
            count++;
    }
    return count;
}

int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

    int N;
    cin >> N;
    cout << 2+2*countConsecutive(N) << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
#define DD double
using namespace std;
const int pri[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
int main() {
	int n;
	scanf("%d", &n);
	LL ans = 1;
	for (int i = 0; i < 10 && pri[i] <= n; i++) {
		int xans = pri[i];
		while (xans * pri[i] <= n) xans *= pri[i];
		ans *= xans;
	}
	printf("%lld", ans + 1);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  cin>>a;
  a=a*1.08;
 // cout<<a<<" ";
  if(a<206)
   cout<<"Yay!";
  else if(a==206)
    cout<<"so-so";
  else
    cout<<":(";
 return 0;
}


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

void solve() {
    int n;
    cin>>n;
    ll a, sum=0, high=0, ans=0;
    for(int i=0; i<n; i++) {
        cin>>a;
        sum+=a;
        ans+=sum;
        high=max(high, a);
        cout<<ans+(i+1)*high<<endl;
    }
    return;
}

int main() {
#ifdef bipinpathak
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    auto start=clock();
    int t = 1;
    //cin>>t;
    for(int i=0; i<t; i++) {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    double used= (double) (clock()-start);
    used=(used*1000)/CLOCKS_PER_SEC;
    cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
    return 0;
}

// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll a (n);
F (i,0,n,1) cin>>a[i];
vll pr (n); pr[0]=a[0];
vll pri (n);
F (i,1,n,1) pr[i]=pr[i-1]+a[i];
pri[0]=pr[0];
F (i,1,n,1) pri[i]=pri[i-1]+pr[i];

ll mx = a[0];
F (i,0,n,1) {
	mx = max (mx, a[i]);
	cout<<mx*(i+1)+pri[i]<<endl;
}
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/


#include<bits/stdc++.h>
using namespace std;
#define ints(...)			int __VA_ARGS__; vin(__VA_ARGS__)
#define dbls(...)			double __VA_ARGS__; vin(__VA_ARGS__)
#define ulls(...) 			unsigned long long __VA_ARGS__; vin(__VA_ARGS__)
#define strs(...) 			string __VA_ARGS__; vin(__VA_ARGS__)
#define vifin(x, y)			vi x(y); fin(x, y)
#define vvis(x, y, z, p)	vvi x(y, vi(z, p))
#define deb 				cout << "<deb> DEB" << endl
#define debi(x) 			cout << "<deb> " << #x << " == " << x << endl
#define rep(x, y) 			for(int x = 0; x < y; x++)
#define reps(x, y, z)		for(int x = y; x < z; x++)
#define rev(x, y)			for(int x = y; x >= 0; x--)
#define revs(x, y, z)		for(int x = y; x >= z; x--)
#define syz(x) 				(int)x.size()
#define euc(x, y)			(sqrt((x*x)+(y*y)))
#define all(x) 				x.begin(), x.end()
#define will(x) 			do{cout << x << endl; return 0;}while(0)
using ll 	= long long;
using ull	= unsigned long long;
using str	= string;
using vi 	= vector<int>;
using vc 	= vector<char>;
using vs	= vector<str>;
using vvi	= vector<vector<int>>;
using vvc	= vector<vector<char>>;
using pi	= pair<int, int>;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using pq = priority_queue<T>;
void vin(){return;}
template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};}
void lout(){cout<<"=============================================="<<endl;}
template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;}
template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;}
template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}}
template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();}
template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);}
template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;}
template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;}
constexpr ull LINF	= 4500000000000000000;
constexpr int INF 	= 2000000000;
constexpr int four	= 10007		;
constexpr int five	= 100007	;
constexpr int six	= 1000007	;
constexpr int seven	= 10000007	;
constexpr int eight	= 100000007	;
constexpr int nine	= 1000000007;

signed main() {
	dbls(a, b, w);
	w *= 1000.0;
	int min = INF, max = 0;
	double ans;
	rep(i, eight) {
		ans = w / i;
		if(a <= ans&&b >= ans) {
			chmax(max, i);
			chmin(min, i);
		}
	}
	if(min == INF) will("UNSATISFIABLE");
	cout << min << ' ' << max << endl;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int a, b, w;
    cin >> a >> b >> w;

    w *= 1000;

    int minn = (w + b - 1) / b, maxx = w / a;

    if (minn > maxx)
        cout << "UNSATISFIABLE\n";
    else
        cout << minn << " " << maxx << "\n";

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
ll md = 1000000007;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define pb push_back
#define g(v, i, j) get<i>(v[j])
#define vi vector<int>
#define vll vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define fi(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
using namespace std;
//using namespace std::chrono;
template <typename T>
T pw(T a, T b)
{
    T c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m);
        m = (m * m), b /= 2;
    }
    return c;
}
template <typename T>
T ceel(T a, T b)
{
    if (a % b == 0)
        return a / b;
    else
        return a / b + 1;
}
template <typename T>
T my_log(T n, T b)
{
    T i = 1, ans = 0;
    while (1)
    {
        if (i > n)
        {
            ans--;
            break;
        }
        if (i == n)
            break;
        i *= b, ans++;
    }
    return ans;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
template <typename T>
T mysqt(T a)
{
    T ans = 1;
    while (ans * ans <= a)
        ans++;
    ans--;
    return ans;
}
ll pwmd(ll a, ll b)
{
    ll c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}
ll modinv(ll n)
{
    return pwmd(n, md - 2);
}
ll inverse(ll i)
{
    if (i == 1)
        return 1;
    return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
bool sortbysec(const pair<ll, ll> &a,
               const pair<ll, ll> &b)
{
    return (a.second < b.second);
}
/* auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr << "Time taken: "
         << duration.count()<< "ms" <<"\n";*/
vector<char> capl = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> sml = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template <typename T>
string conv(T a)
{
    string b;
    T e = 2;
    T c = my_log(a, e);
    c++, b = '1';
    for (T i = 0; i < c - 1; i++)
    {
        T k = a >> (c - 2 - i);
        if (k & 1)
            b += '1';
        else
            b += '0';
    }
    if (a == 0)
        return "0";
    return b;
}
int main()
{
    fast;
    ll n, m, q, l, r;
    cin >> n >> m >> q;
    ll w[n], val[n], x[m];
    fll(i, 0, n) cin >> w[i] >> val[i];
    fll(i, 0, m) cin >> x[i];
    while (q--){
        vector<pair<int, int>> vp;
        fll(i, 0, n) vp.pb({w[i], val[i]});
        vll vis(n);
        vll xs;
        cin >> l >> r;
        l--, r--;
        fll(i, 0, m){
            if (i >= l && i <= r) continue;
            xs.pb(x[i]);
        }
        srt(xs);
        ll ans = 0;
        fll(i, 0, xs.size()){
            ll ind = -1, mx = 0;
            fll(j, 0, n){
                if (vis[j]) continue;
                if (vp[j].first <= xs[i]){
                   // cout << vp[j].second << "a\n";
                    if (vp[j].second > mx) mx = vp[j].second, ind = j;
                }
            }
            if (ind == -1) continue;
            ans += mx, vis[ind] = 1;
        }
        cout << ans << "\n";
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long   ll;
typedef long double ld;
#define MAXN 1000005
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define endl '\n'
ll cc=0;

void boost()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1) {
        // q is quotient
        ll q = a / m;
        ll t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

int main()
{
    boost();

    ll i,j,k,n,t,c=0,l,r,d=0;
    ll ans,h,z,m,u,q,mm,w,mx,x,y;
    ld f;

    cin>>t;

    while(t--)
    {
        cin>>n>>z>>k;
        y=__gcd(n,z);
        y=__gcd(y,k);

        n=n/y;
        z=z/y;
        k=k/y;
        ans=-1;

        l=n-z;
        r=__gcd(n,k);

        if(r!=1)
        {
            cout<<ans<<endl;
        }

        else
        {
            r=inv(k,n);
            ans=r*l;
            ans=ans%n;

            cout<<ans<<endl;
        }

    }
return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=998244353; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%lld%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%lld %lld%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=6e3+5;
int a[MN],f[MN][MN],n,K;
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read(),K=read();
	For(i,0,MN-5) f[0][i]=1;
	For(i,1,n-K) {
//		f[i][0]=1;
		For(j,1,i) {
			f[i][j]=add(f[i][j-1],f[i-j][min(2*j,i-j)]);
		}
//		For(j,1,K) cerr<<f[i][j]<<' ';
//		cerr<<endl;
	}
	printf("%lld\n",f[n-K][min(K,n-K)]);
	return FastIO::Fflush(),0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e6 + 10;
const int mod = 998244353;
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        x = (x << 1) + (x << 3) + c - '0', c = getchar();
    return x * f;
}
int main()
{
    int n = read(), k = read();
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    for (int i = 1; i <= n; i++)
    {
        dp[i][i] = 1;
        for (int j = i - 1; j >= 1; j--)
        {
            if (j)
                dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
            if (2 * j <= i)
                dp[i][j] = (dp[i][j] + dp[i][2 * j]) % mod;
        }
    }
    cout << dp[n][k] << endl;
}


#include<iostream>
#include<vector>
#include<map>
using namespace std;
int _C3(int n, int k)
{
	if(k > n)
		return 0;
	else if(n==2 && k==1)
		return 2;
	else
		return 1;
}
int C(int n, int k)
{
	int ans = 1;
	while(n > 0 || k > 0)
	{
		ans = (ans*_C3(n%3, k%3))%3;
		n /= 3;
		k /= 3;
	}
	return ans;
}
int main()
{
	string x = "RWB";
	map<char,int> conv;
	for(int i = 0; i < 3; i++)
		conv[x[i]] = i;

	/***
		R W B
	R   R B W
	W   B W R
	B   W R B
	***/
	vector<vector<char>> huh = {{'R','B','W'},{'B','W','R'},{'W','R','B'}};

	int n; cin >> n;
	string orig; cin >> orig;

	string s;
	if(n&1)
		s = orig;
	else
	{
		s = "";
		n--;
		for(int i = 0; i < n; i++)
			s += huh[conv[orig[i]]][conv[orig[i+1]]];
	}

	int ans = 0;
	for(int i = 0; i <= n; i++)
		ans += C(n-1, i)*conv[s[i]];
	ans %= 3;

	cout<<x[ans]<<endl;

	return 0;
}

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <functional>
template <typename T>
inline void hash_combine(std::size_t &seed, const T &val) {
    seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename T> inline void hash_val(std::size_t &seed, const T &val) {
    hash_combine(seed, val);
}
template <typename T, typename... Types>
inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {
    hash_combine(seed, val);
    hash_val(seed, args...);
}
template <typename... Types>
inline std::size_t hash_val(const Types &... args) {
    std::size_t seed = 0;
    hash_val(seed, args...);
    return seed;
}
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator()(const std::pair<T1, T2> &p) const {
        return hash_val(p.first, p.second);
    }
};
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define G 3
#define MAX_N 300005
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef complex<double> E;
ll pow_mod(ll x,ll n){
    ll ret=1;
    while(n>0){
        if(n&1)ret=ret*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ret;
}
ll n,p;
int main(){
    cin>>n>>p;
    cout<<(p-1)*pow_mod(p-2,n-1)%mod;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAX =1000000000000000000;
ll mod= 1000000000;
long double pi=3.141592653589793238;
void pls()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
}
ll n,m,k;
vector<pair<ll,ll>> p,temp;
ll recursion(int i,vector<int> &visi){
   if(i==k)
   {
        ll tot=0;
        for(i=0;i<p.size();i++){
            if(visi[p[i].first] && visi[p[i].second])
              tot++;

        }
        return tot;
    }

        visi[temp[i].first]+=1;
        ll val=recursion(i+1,visi);
        visi[temp[i].first]-=1;
        visi[temp[i].second]+=1;
        ll val1=recursion(i+1,visi);
        visi[temp[i].second]-=1;
        return max(val,val1);

}
void solve()
{
          cin>>n>>m;
          for(int i=0;i<m;i++){
            ll x,y; cin>>x>>y;
            p.push_back({x,y});
          }
          cin>>k;
          for(int i=0;i<k;i++){
            ll x,y; cin>>x>>y;
            temp.push_back({x,y});
          }
          vector<int> visi(n+1,0);
          cout<<recursion(0,visi)<<endl;

}
int main(){pls(); solve(); return 0;}
/*
  Mostly wrong answer form base case or overflow or runtime
  Debug--> check overflow---> check varible name---> check logic implementation----> check logic

*/

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

int ara[262150],n,two[23],tra[23][23],dp[262150],sz,bits[23],tz;

int on(int val,int pos)
{
    return (val|two[pos]);
}

bool ck(int val,int pos)
{
    return (bool)(val&two[pos]);
}

int off(int val,int pos)
{
    return (val^two[pos]);
}

void subsets(int mask,int idx)
{

    if(idx==n){  ara[mask]=1;  }
    else
    {

        subsets(mask,idx+1);

        int flg=1;

        for(int lp=0;lp<=n-1;lp++)
        {
            if(ck(mask,lp)==true)
            {
                if(tra[idx][lp]==0){ flg=0; break;  }
            }

        }

        if(flg==1)
        {
            int t;  t=on(mask,idx);  subsets(t,idx+1);
        }

    }

}

void work(int mask,int start,int idx)
{

    if(idx==tz)
    {
         int remain;
         if(mask!=0){  remain=start^mask;  dp[start]=min(dp[start],dp[mask]+dp[remain]); }
    }
    else
    {
        work(mask,start,idx+1);

        int q,r,s;  q=bits[idx];

        r=off(mask,q);

        work(r,start,idx+1);

    }

}

int main()
{

    two[0]=1;

    for(int lp=1;lp<=20;lp++)
    {
        two[lp]=two[lp-1]*2;

    }

    int m,i,j,k,a,b,c,fn,mask,x,y,z;

    scanf("%d %d",&n,&m);

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

        scanf("%d %d",&a,&b); tra[a-1][b-1]=1;  tra[b-1][a-1]=1;
    }

    subsets(0,0); fn=two[n]-1;

    for(mask=1;mask<=fn;mask++)
    {

        if(ara[mask]==1){  dp[mask]=1;  }
        else
        {

           tz=0;  dp[mask]=99999;

           for(i=0;i<=n-1;i++)
           {
               if(ck(mask,i)==true){  bits[tz]=i;  tz++;  }
           }

           work(mask,mask,0);

        }

    }

    printf("%d\n",dp[fn]);

    return 0;
}


// #define ONLINE_JUDGE
//                 _
//                (_)
// _ __ ___   __ _ _  ___  _ __ _ __ ___
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \
//| | | | | | (_| | | (_) | |  | | | (_) |
//|_| |_| |_|\__,_| |\___/|_|  |_|  \___/
//               _/ |
//              |__/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef tree<
    pll,//
    null_type,
    less<pll>,//
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;

#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
#define sz(something) (ll)something.size()

struct pair_hash
{
    template <class T1, class T2>
    size_t operator() (const pair<T1, T2>& pair) const
    {
        return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
    }
};

const ld EPS = 1e-8;
const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1e18;
const ld pi = 2.0*acos(0.0);
ll n, m, k, p, q, t, sum=0, cnt=0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
string s = "", s1, s2;
char c;

void solve()
{
    cin >> n >> k;
    vector<pll> v;
    forn(i,n)
    {
        cin >> p >> q;
        v.pb({p,q});
    }
    sort(all(v));
    p = 0;
    q = 0;
    while(k)
    {
        p += k;
        k = 0;
        while(q<n&&v[q].first<=p) k += v[q++].second;
    }
    cout << p;
}

int main()
{
#if defined ACMP
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#elif !defined ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    majorro
    solve();
    return 0;
}

#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
typedef unsigned long long ull;
typedef long double lld;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//-------------------------------------------------------------------------------

const ll N = 2e5+7;
vll g[N];
ll st[N],en[N];
vll d[N];
ll timer=0;

void dfs(ll v,ll depth=0){

	st[v] = timer++;
	d[depth].pb(st[v]);

	for(auto x:g[v]){
		dfs(x, depth+1);
	}

	en[v] = timer;

}
void solve(){

	int n;cin>>n;

	for(int i=2;i<=n;++i){
		int x;cin>>x;
		g[x].pb(i);
	}

	dfs(1);

	int q;
	cin>>q;
	while(q--){
		int u,D;cin>>u>>D;

		ll r = en[u], l= st[u];

		ll ans = lower_bound(d[D].begin(),d[D].end(),r) - lower_bound(d[D].begin(),d[D].end(),l);
		cout<<ans<<'\n';
	}

}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("E:\\input-output\\input.txt","r",stdin);
	freopen("E:\\input-output\\output.txt","w",stdout);
	freopen("E:\\input-output\\Error.txt", "w", stderr);
	#endif
	int t=1;

	while(t--){
		solve();
	}

}


#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#else
#include "Debug.hpp"
#endif

class Task {
 public:
  void Perform() {
    Read();
    Solve();
  }

 private:
  int n;
  vector<pair<int, int>> intervals;

  void Read() {
    cin >> n;
    intervals.resize(n);
    for (auto &[l, r] : intervals) {
      int typ;
      cin >> typ >> l >> r;
      l *= 2, r *= 2;
      if (typ == 2) {
        --r;
      } else if (typ == 3) {
        ++l;
      } else if (typ == 4) {
        ++l, --r;
      }
    }
  }

  void Solve() {
    int res = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        int intersect = min(intervals[i].second, intervals[j].second) - max(intervals[i].first, intervals[j].first) + 1;
        res += intersect > 0;
      }
    }
    cout << res << '\n';
  }
};

int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  Task t;
  t.Perform();
  return 0;
}

/* BABA JAGAAAAAA  */

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define PI 3.1415926535897932384626
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
/*
vector<int>parent;
vector<int>rank;
   int find(int x)

   {
         if(parent[x]==x)
              return x;
        return parent[x]= find(parent[x]);  // path compression// O(log n)

   }

    void merge(int a, int b)
    {
         int x1= find(a);
         int x2= find(b);

        if(rank[x1]<rank[x2])
            parent[x1]=x2;
        else if(rank[x2]<rank[x1])  //(lon n)
            parent[x2]=x1;          // union by rank//
        else
        {
            parent[x1]=x2;
            rank[x2]++;
        }

    }

ll pri[10000002];  // for precomputing
ll primes[10000002];

void seive()
{

    primes[0]=primes[1]=-1;

    for(ll i=2; i<10000002; i++)
    {
        if(primes[i]==0)
        {
             for(ll j=i*i; j<10000002; j+=i)
             {
                 primes[j]=-1;
             }
        }
    }

}
*/

 inline void solve()
 {

   ll n;
    cin>>n;
     vector<ll>a,b;
      for(ll i=0; i<n; i++)
      {
          ll x;
          cin>>x;
          a.pb(x);
      }
      for(ll i=0; i<n; i++)
      {
          ll x;
          cin>>x;
          b.pb(x);
      }
       sort(a.begin(), a.end());
       sort(b.begin(), b.end());
       un<ll,ll>mp;
        for( ll i=0; i<n; i++)
        {
            ll mini= min(a[i],b[i]);
            ll maxi= max(a[i],b[i]);
            for(ll j=mini; j<=maxi; j++)
            {
                mp[j]++;
            }
        }

          ll count=0;
           for(auto it=mp.begin(); it!=mp.end(); it++)
           {
               if(it->second==n)
               count++;
           }
            cout<<count;
             return;
 }
 int main()
 {
     fast;
     int t=1;
      //cin>>t;
     // seive();
      while(t--)
      {
        solve();
         cout<<"\n";
      }
       return 0;

 }


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

#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define ALL(obj) begin(obj), end(obj)
#define cinv(a) rep(i,(int)a.size()) cin>>a[i]
#define pb push_back
#define eb emplace_back
typedef pair<int, int> Pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

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

int main()
{
	int n; cin >> n;
	vl a(n), b(n);
	rep(i, n) scanf("%lld", &a[i]);
	rep(i, n) scanf("%lld", &b[i]);

	reps(i, 1, n)
		a[i] = max(a[i-1], a[i]);

	ll ans;
	rep(i, n)
	{
		if (i == 0)
			ans = a[0] * b[0];
		else
			ans = max(ans, a[i] * b[i]);
		printf("%lld\n", ans);
	}
}

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i = a;i < (ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SHOW(str,val) cout<<(str)<<" : "<<(val)<<endl;

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// using P = pair<int, int>;
void YN(bool a) { cout << (a ? "Yes" : "No"); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void solve()
{
  ll n;
  cin >> n;
  ll thr = 3;
  ll cnt_3 = 0;
  for(thr; thr <= n; thr *= 3)
  {
    cnt_3++;
    ll cnt_5 = 0;
    for(ll fiv = 5; thr + fiv <= n; fiv *= 5)
    {
      cnt_5++;
      if (thr + fiv == n)
      {
        cout << cnt_3 << " " << cnt_5 << endl;
        return;
      }
    }
  }
  cout << -1;
}

int main()
{
  fastio;
  solve();

  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 410, offset = 200;
int a[N];

int main(){
    int n;
    cin >> n;
    while(n--){
        int x;
        cin >> x;
        a[x + offset]++;
    }
    long long ans = 0;
    for(int i = 0; i <= 400; i++){
        for(int j = i; j <= 400; j++){
            int c1 = a[i], c2 = a[j];
            if(c1 && c2) ans += (i - j) * (i - j) * c1 * c2;
        }

    }
    printf("%lld", ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void DAU(const string &task = "") {
    if (!task.empty())
        freopen((task + ".in").c_str(), "r", stdin),
        freopen((task + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
void PLEC() {
    exit(0);
}
#define int long long
int n, s1, s2, x, res;
signed main() {
    DAU();
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        s1 += x * x;
        s2 += x;
    }
    res = n * s1 - s2 * s2;
    cout << res;
    PLEC();
}


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

char a[10];
int st[10];
vector<int> v;
vector<int> m;
int ans[5];
int len ;
int le;
int out;

void dfs(int x)
{
    if(x == 4){

        int cnt =0 ;
        for(int i = 0 ; i < le; i++){
            for(int j = 0; j < 4 ; j++){
                if( ans[j] == m[i]){
                    cnt++;
                    break;
                }
            }
        }
        if(cnt == le){
            out++;
        }

    }
    else{

        for(int i =0 ; i < len ; i++){
            if( ans[x] == -1){
                ans[x] = v[i];
                dfs(x+1);
                ans[x] = -1;
            }
        }

    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fill(ans,ans+5,-1);
    int cnt_x=0,cnt_o=0,cnt_q= 0;
    for(int i =0 ; i < 10 ; i++){
        cin >> a[i];
        if( a[i] == 'o' ){
            cnt_o++;
            v.push_back(i);
            m.push_back(i);
        }
        else if(a[i]=='x'){
            cnt_x++;
        }
        else{
            cnt_q++;
            v.push_back(i);
        }
    }
    len = v.size();
    le = m.size();
    if( cnt_o > 4 ){
        cout << 0 << endl;
    }
    else{
        dfs(0);
        cout << out << endl;
    }

    return 0;
}

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

int64_t kai(int n){
    if(n==0)return 1;
    return n*kai(n-1);
}

int main(){
    string S;
    cin>>S;
    int maru=0;
    int batsu=0;
    for(int i=0;i<10;i++) {
        if(S.at(i)=='o') maru++;
        if(S.at(i)=='x') batsu++;
    }
    if(maru>4) {cout<<0<<endl;return 0;}
    int ans=0;
    for(int i=0;i<=maru;i++){
        ans+=pow(-1,i)*pow(10-batsu-i,4)*kai(maru)/(kai(i)*kai(maru-i));
    }
    cout<<ans<<endl;
    return 0;
}


/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(25);
    }
} setup_io;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    int n;
    cin >> n;
    vl a(n), b(n), p(n);
    rep (i, n) {
        cin >> a[i];
    }
    rep (i, n) cin >> b[i];
    vi q(n);
    rep (i, n) {
        cin >> p[i];
        p[i]--;
        q[p[i]] = i;
    }

    vector<pii> ai(n);
    rep (i, n) {
        ai[i] = pii(a[i], i);
    }
    sort(all(ai));

    vector<pii> op;
    rep (idx, n) {
        int i = ai[idx].second;
        if (p[i] == i) continue;
        if (b[p[i]] >= a[i]) {
            cout << -1 << endl;
            return 0;
        }

        int j = q[i];
        if (b[p[j]] >= a[j]) {
            cout << -1 << endl;
            return 0;
        }

        op.push_back(pii(i, j));
        p[j] = p[i];
        p[i] = i;
        q[p[i]] = i;
        q[p[j]] = j;
    }

    cout << op.size() << endl;
    rep (i, op.size()) {
        cout << op[i].first + 1 << " " << op[i].second + 1 << endl;
    }
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=5e5+5;
int n,a[MN],b[MN],p[MN],v[MN],vis[MN],vis2[MN],r[MN];
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=read();
	For(i,1,n) p[i]=read();
	For(i,1,n) r[p[i]]=i;
	For(i,1,n) {
		v[i]=b[p[i]];
		if(v[i]>=a[i]) {
			if(r[i]==i) continue;
			return printf("-1\n"),0;
		}
	}
	vector<pii>ans;
	For(i,1,n) {
		int u=i,mnv=a[u],mnp=u;
		if(vis[i]) continue;
		while(!vis[u]) {
			vis[u]=i; u=r[u];
			if(mnv>a[u]) {
				mnv=a[u],mnp=u;
			}
		}
		u=mnp; do {
			if(r[u]!=mnp) ans.pb(mkp(u,r[u]));
			u=r[u];
		} while(u!=mnp);
	}

	printf("%d\n",(int)ans.size());
	for(auto it:ans) {
		printf("%d %d\n",it.first,it.second);
	}
	return FastIO::Fflush(),0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 10007;
int main() {
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    vector<ll>ss(n),tt(n);
    for(ll i=0;i<n;i++){
        ss[i]=s[i]-'0';
        tt[i]=t[i]-'0';
    }
    ll ans=0;
    ll j=0;
    for(ll i=0;i<n;i++){
        if(ss[i]!=tt[i]){
            j=max(j,i+1);
            while((j<n)&&ss[j]!=1){
                j++;
            }
            if(j==n)break;
            ans+=j-i;
            ss[i]=(ss[i]+1)%2;
            ss[j]=(ss[j]+1)%2;
        }
    }
    bool ok=false;
    for(ll i=0;i<n;i++){
        if(ss[i]!=tt[i]){
            ok=true;
        }
    }
    if(ok){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=500005;
int n,S[N],T[N],ans,tot,st[N];
char s[N],t[N];
queue<int>q;
signed main()
{
    scanf("%lld%s%s",&n,s+1,t+1);
    for(int i=1;i<=n;i++)S[i]=(s[i]^48),T[i]=(t[i]^48);
    for(int i=1;i<=n;i++)if(S[i])q.push(i);
    for(int i=1;i<=n;i++){
        if(!T[i])continue;
        while(!q.empty()){
            if(q.front()<i||tot&1){
                st[++tot]=q.front();q.pop();
            }else break;
        }if(q.empty()){puts("-1");return 0;}
        ans+=q.front()-i;q.pop();
    }while(!q.empty())st[++tot]=q.front(),q.pop();
    if(tot&1){puts("-1");return 0;}
    for(int i=1;i<tot;i+=2)ans+=st[i+1]-st[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define MOD_10_9_7 1000000007
#define MOD 998244353;
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
template <typename T>
void update_max(T& a, T b) {
    if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
    if (b < a) a = b;
}

class DisjointSet {
    int size;
    int components;
    vector<int> parents;

   public:
    DisjointSet(int size) {
        this->size = size;
        this->parents = vector<int>(size);
        for (int i = 0; i < size; i++) {
            parents[i] = i;
        }
        components = size;
    };
    int find(const int index) {
        vector<int> path;
        int current = index;
        while (current != parents[current]) {
            path.push_back(current);
            current = parents[current];
        }
        for (int parent : path) {
            parents[parent] = current;
        }
        return current;
    };
    bool merge(const int index1, const int index2) {
        int parent1 = find(index1), parent2 = find(index2);
        if (parent1 != parent2) {
            parents[parent1] = parent2;
            components -= 1;
            return true;
        };
        return false;
    };
};

vector<long long> factorials;

int main() {
#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    factorials = vector<long long>(N + 1, 1);
    for (int i = 2; i < N + 1; i++) {
        factorials[i] = (i * factorials[i - 1]) % MOD;
    }
    vector<vector<int>> a(N, vector<int>(N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }
    DisjointSet column_ds(N);  //= new DisjointSet(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            bool lower_than_k = true;
            for (int r = 0; r < N; r++) {
                if (a[r][i] + a[r][j] > K) {
                    lower_than_k = false;
                    break;
                }
            }
            if (lower_than_k) column_ds.merge(i, j);
        }
    }
    unordered_map<int, int> column_counter;
    for (int i = 0; i < N; i++) {
        column_counter[column_ds.find(i)] += 1;
    }

    DisjointSet row_ds(N);  //= new DisjointSet(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            bool lower_than_k = true;
            for (int r = 0; r < N; r++) {
                if (a[i][r] + a[j][r] > K) {
                    lower_than_k = false;
                    break;
                }
            }
            if (lower_than_k) row_ds.merge(i, j);
        }
    }
    unordered_map<int, int> row_counter;
    for (int i = 0; i < N; i++) {
        row_counter[row_ds.find(i)] += 1;
    }

    long long answer = 1;
    for (auto it : column_counter) {
        answer = (answer * factorials[it.second]) % MOD;
    }
    for (auto it : row_counter) {
        answer = (answer * factorials[it.second]) % MOD;
    }
    cout << answer;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

class UnionFind{
    public:
        ll size;
        vll v;

        UnionFind(ll n){
            this->v = vll(n);
            rep(i, n) this->v[i] = i;
        }

        ll root(ll n){
            if(n!=v[n]) return v[n] = root(v[n]);
            return n;
        }

        void unite(ll l, ll r){
            ll lroot = root(l);
            ll rroot = root(r);
            if(lroot!=rroot) this->v[rroot] = lroot;
        }
};

ll fac(ll n, ll mod=998244353){
    static const ll N_MAX = 200001;
    static vll fac(N_MAX+1, -1);

    if(fac[0]<0){
        fac[0] = 1;
        rep(i, N_MAX){
            fac[i+1] = fac[i] * (i+1) % mod;
        }
    }

    return fac[n] % mod;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vvll a(N, vll(N, 0));
    rep(i, N) rep(j, N){
        cin >> a[i][j];
    }

    UnionFind ufx(N), ufy(N);
    rep(i, N) REP(j, i+1, N){
        bool okx = true, oky = true;
        rep(k, N){
            okx &= a[k][i]+a[k][j] <= K;
            oky &= a[i][k]+a[j][k] <= K;
        }
        if(okx) ufx.unite(i, j);
        if(oky) ufy.unite(i, j);
    }

    unordered_map<ll, unordered_set<ll>> mx, my;
    rep(i, N){
        ll rx = ufx.root(i);
        ll ry = ufy.root(i);
        mx[rx].insert(i);
        my[ry].insert(i);
    }

    ll cx = 1, cy = 1;
    for(auto p : mx){
        cx = cx*fac(p.second.size()) % 998244353;
    }
    for(auto p : my){
        cy = cy*fac(p.second.size()) % 998244353;
    }
    ll ans = cx*cy % 998244353;
    cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int K = 16;
const int MOD = 1e9 + 7;

int add(int a, int b) {
    if (a + b < MOD) {
        return a + b;
    }
    return a + b - MOD;
}

int sub(int a, int b) {
    if (a >= b) {
        return a - b;
    }
    return a - b + MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int binpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int divv(int a, int b) {
    return mul(a, binpow(b, MOD - 2));
}

int c[K + 1][K + 1];

void init() {
    for (int i = 0; i <= K; i++) {
        c[i][0] = 1;
        c[i][i] = 1;
        for (int j = 1; j < i; j++) {
            c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]);
        }
    }
}

int C(int n, int k) {
    if (k < 0 || k > n) return 0;
    return c[n][k];
}

vector<int> parse() {
    string s;
    cin >> s;
    vector<int> ans;
    for (auto x : s) {
        if (x <= '9') {
            ans.push_back(x - '0');
        } else {
            ans.push_back(10 + (x - 'A'));
        }
    }
    return ans;
}

int solve(int len, int cnt) {
    vector<int> tmp(cnt + 1);
    for (int i = 1; i <= cnt; i++) {
        tmp[i] = binpow(i, len);
        for (int j = 1; j < i; j++) {
            tmp[i] = sub(tmp[i], mul(tmp[j], C(i, j)));
        }
    }
    return tmp[cnt];
}

int solve(int n, int k, vector<int> cnt) {
    int alr = 0;
    int s = 0;
    for (int i = 0; i < 16; i++) {
        alr += (cnt[i] > 0);
        s += cnt[i];
    }
    if (alr > k) {
        return 0;
    }
    vector<int> tmp(k + 1);
    tmp[alr] = binpow(alr, n - s);
    for (int i = alr + 1; i <= k; i++) {
        // tmp[i] = mul(C(16 - alr, i - alr), binpow(i, n - s));
        // cerr << i << ' ' << tmp[i] << endl;
        tmp[i] = binpow(i, n - s);
        for (int j = alr; j < i; j++) {
            tmp[i] = sub(tmp[i], mul(tmp[j], C(i - alr, j - alr)));
        }
    }
    return mul(tmp[k], C(16 - alr, k - alr));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    init();

    int k;
    vector<int> a;
    a = parse();
    cin >> k;
    int n = (int)a.size();
    int ans = 0;
    for (int len = 1; len < n; len++) {
        {
            int cr = mul(C(15, k), solve(len, k));
            ans = add(ans, cr);
        }
        {
            int cr = mul(C(15, k - 1), solve(len, k));
            cr = mul(cr, divv(k - 1, k));
            ans = add(ans, cr);
        }
    }
    {
        vector<int> cnt(16);
        for (int pref = 0; pref <= n; pref++) {
            if (pref == n) {
                ans = add(ans, solve(n, k, cnt));
            } else {
                for (int j = 0; j < a[pref]; j++) {
                    if (pref == 0 && j == 0) continue;
                    cnt[j]++;
                    ans = add(ans, solve(n, k, cnt));
                    cnt[j]--;
                }
                cnt[a[pref]]++;
            }
        }
    }
    cout << ans << endl;
}

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

#define llong long long
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#ifdef testing/*{{{*/
mt19937 rng(177013);
#else
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#endif
#define rand() (int)(rng() >> 1)
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#define SPEC(name) CONCAT(name, __LINE__)
#ifdef LOCAL_DEBUG
int __db_level = 0;
#define clog cerr << string(__db_level * 2, ' ')
struct debug_block {
    string msg;
    debug_block(const string& s): msg(s) { clog << "{ " << msg << endl; ++__db_level; }
    ~debug_block() { --__db_level; clog << "} " << msg << endl; }
};
#define DB(args...) stringstream SPEC(ss); SPEC(ss)<< args; debug_block SPEC(dbbl)(SPEC(ss).str())
#else
#define clog if (0) cerr
#define DB(...)
#endif
#define db(val) "[" #val " = " << val << "]; "
template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
    if constexpr(i == tuple_size<T>::value) return out << ")";
    else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U>
ostream& operator<<(ostream& out, const tuple<U...>& tup) { return print_tuple_utils<0, tuple<U...>>(out, tup); }
template<class, typename = void> struct has_const_iterator : false_type {};
template<class T> struct has_const_iterator<T, void_t<typename T::const_iterator>> : true_type {};
template<class T>
typename enable_if<has_const_iterator<T>::value && !is_same<T, string>::value, ostream&>::type
operator<<(ostream& out, const T& container) {
    auto beg = container.begin(), end = container.end();
    out << "(" << container.size() << ") {";
    if (beg != end) out << *(beg++);
    while (beg != end) out << ", " << *(beg++);
    return out << "}";
}
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/
// ACTUAL SOLUTION START HERE ////////////////////////////////////////////////////////////////

void inv(string& a) {
    for (auto& ch: a) ch ^= 'A' ^ 'B';
}

void inv(list<string>& u) {
    for (auto& s: u) inv(s);
}

list<string> concat(list<string> u, const list<string>& v) {
    auto iu = u.begin();
    auto iv = v.begin();
    for (; iu != u.cend(); ++iu, ++iv)
        *iu += *iv;
    return u;
}

int main(void) {
#ifdef LOCAL
    freopen("main.inp", "r", stdin);
    freopen("main.out", "w", stdout);
    freopen(".log", "w", stderr);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    list<string> ans = {"AB"};
    for (int i = 2; i <= n; ++i) {
        auto a1 = concat(ans, ans);
        auto x = ans; inv(x);
        auto a2 = concat(ans, x);
        ans = a1;
        ans.splice(ans.end(), a2);
        ans.push_back(string((1 << i >> 1), 'A') + string((1 << i >> 1), 'B'));
    }
    cout << len(ans) << '\n';
    for (auto& s: ans) cout << s << '\n';

    return 0;
}

// vim: foldmethod=marker


// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  vector<int> p;
  for (int i = 2; i <= 50; ++i) {
    if (is_prime(i)) p.push_back(i);
  }
  trace(p, SZ(p));
  int n, m = SZ(p);
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    for (int j = 0; j < SZ(p); ++j) {
      if (x % p[j] == 0) a[i] |= 1 << j;
    }
  }
  trace(a);
  int64 ret = inf<int64>;
  for (int k = 1; k < (1 << m); ++k) {
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      if ((k & a[i]) == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      int64 cur = 1;
      for (int i = 0; i < m; ++i) {
        if ((k >> i) & 1) cur *= p[i];
      }
      // trace(k, cur);
      ret = min(ret, cur);
    }
  }
  cout << ret << '\n';
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define dbg(x) cout << (#x) << " is " << (x) << endl;
#define dbg2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << y << endl;
#define dbgarr(x, sz)                                             \
  for (int asdf = 0; asdf < (sz); asdf++) cout << x[asdf] << ' '; \
  cout << endl;
#define dbgarr2(x, rose, colin)                \
  for (int asdf2 = 0; asdf2 < rose; asdf2++) { \
    dbgarr(x[asdf2], colin);                   \
  }
#define dbgitem(x)                                                           \
  for (auto asdf = x.begin(); asdf != x.end(); asdf++) cout << *asdf << ' '; \
  cout << endl;

const int mod = 3, MAXN = 2e5 + 1;

int n, diam_kid[MAXN];
vi adj[MAXN];
struct Solution {
  vi res;
  int t = 1;
  pii diam;
  void solve() {
    res.resize(n), memset(diam_kid, -1, sizeof(diam_kid));
    diam = get_diameter(0);
    // dbg2(diam.first, diam.second);
    dfs(diam.first, -1);
    walk(diam.first, -1);
  }
  void walk(int i, int p) {
    res[i] = t++;
    for (int j : adj[i]) {
      if (j == p || j == diam_kid[i]) continue;
      walk(j, i);
    }
    if (diam_kid[i] != -1) walk(diam_kid[i], i);
    t++;  // revisit
  }
  bool dfs(int i, int p) {  // track which kid leads to the other endpoint of the diameter
    if (i == diam.second) return true;
    for (int j : adj[i]) {
      if (j == p) continue;
      if (dfs(j, i)) diam_kid[i] = j;  // j leads to diam.second
    }
    return diam_kid[i] != -1;
  }
  pii get_diameter(int i) {  // returns diam from the region i is in
    auto p = farthest(i, 0, -1);
    return {farthest(p.second, 0, -1).second, p.second};
  }
  pii farthest(int i, int d, int p) {  // returns {dist, node} farthest from i; d= dist from source node
    pii res = {d, i};
    for (int j : adj[i]) {
      if (j == p) continue;
      res = max(res, farthest(j, d + 1, i));
    }
    return res;
  }
};
void print(vector<int>& nums) {
  for (auto num : nums) cout << num << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution test;
  int a, b;
  cin >> n;
  REP(i, n - 1)
  cin >> a >> b,
      adj[--a].push_back(--b), adj[b].push_back(a);
  test.solve();
  print(test.res);
}


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

template <typename T>
struct Dijkstra {
    struct Edge {
        int to;
        T cost;
    };

    vector<int> prev;
    vector<vector<Edge>> g;

    Dijkstra(int n) : prev(n, -1), g(n) {}

    void add_edge(int u, int v, T w) { g[u].push_back({v, w}); }
    vector<T> build(int s) {
        using Node = pair<T, int>;
        vector<T> dist(g.size(), -1);
        priority_queue<Node, vector<Node>, greater<Node>> pq;
        pq.push({dist[s] = 0, s});
        while (!pq.empty()) {
            T d = pq.top().first;
            int u = pq.top().second;
            pq.pop();
            if (dist[u] < d) continue;
            for (auto&& v : g[u]) {
                if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
                    pq.push({dist[v.to] = dist[u] + v.cost, v.to});
                    prev[v.to] = u;
                }
            }
        }
        return dist;
    }
    vector<int> get_path(int t) {
        vector<int> path;
        for (int i = t; i != -1; i = prev[i]) path.push_back(i);
        reverse(begin(path), end(path));
        return path;
    }
};

int main() {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    a--;
    b--;
    Dijkstra<int> g(200);
    for (int i = 0; i < 100; i++) {
        g.add_edge(i, i + 100, x);
        g.add_edge(i + 100, i, x);
    }
    for (int i = 0; i < 99; i++) {
        g.add_edge(i + 1, i + 100, x);
        g.add_edge(i + 100, i + 1, x);
        g.add_edge(i, i + 1, y);
        g.add_edge(i + 1, i, y);
        g.add_edge(i + 100, i + 101, y);
        g.add_edge(i + 101, i + 100, y);
    }
    auto d = g.build(a);
    cout << d[b + 100] << endl;
}

#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;

bool check(auto &light, auto &grid, int i, int j, bool OK) {
    if (grid[i][j] == 0) OK = false;
    else if (grid[i][j] == 1) OK = true;
    light[i][j] |= OK;
    return OK;
}

int main() {
    int H, W, N, M;
    scanf("%d %d %d %d", &H, &W, &N, &M);
    vector<vector<int>> grid(H, vector<int>(W, -1));
    vector<vector<int>> light(H, vector<int>(W, 0));
    for (int i = 0; i < N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--, b--;
        grid[a][b] = 1;
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--, b--;
        grid[a][b] = 0;
    }
    for (int i = 0; i < H; i++) {
        bool OK = false;
        for (int j = 0; j < W; j++)
            OK = check(light, grid, i, j, OK);
        OK = false;
        for (int j = W - 1; j >= 0; j--)
            OK = check(light, grid, i, j, OK);
    }
    for (int c = 0; c < W; c++) {
        bool OK = false;
        for (int r = 0; r < H; r++)
            OK = check(light, grid, r, c, OK);
        OK = false;
        for (int r = H - 1; r >= 0; r--)
            OK = check(light, grid, r, c, OK);
    }
    int ans = 0;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) {
            ans += light[i][j];
            //printf("i = %d j = %d l = %d\n", i, j, light[i][j]);
        }
    printf("%d\n", ans);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


#include <bits/stdc++.h>

using namespace std;

#define MAX 1e9

int main(){
    int n,m,a,b,c;
    pair<int,int> x;
    cin>>n>>m;
    vector<pair<int,int>> lst[n];
    for(int i=0; i<m; i++){
        cin>>a>>b>>c;
        lst[a-1].push_back({-c,b-1});
    }

    bool visited[n],exists;
    for(int i=0; i<n; i++){
        priority_queue<pair<int,int>> pr;

        memset(visited,false,n);
        for(int j=0; j<lst[i].size(); j++) pr.push(lst[i][j]);

        exists=false;
        while(!pr.empty()){
            if(pr.top().second==i){
                exists=true;
                break;
            }
            x=pr.top();
            //cout<<x.second<<" ";
            pr.pop();
            if(visited[x.second])continue;
            else visited[x.second]=true;
            for(int j=0; j<lst[x.second].size(); j++) pr.push({x.first+lst[x.second][j].first,lst[x.second][j].second});
        }

        if(exists)cout<<(-pr.top().first)<<"\n";
        else cout<<"-1\n";
        //cout<<endl;
    }
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }

template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

// const i64 INF = 2e18;
const int INF = 2e9;
const __int128_t M = 1000000;
const int MXB = 20;
using bin = bitset<MXB + 1>;
const double EPS = 1e-8;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());

    int n, m;
    while (read(n, m)) {
        vec<vec<iip>> g(n);
        vec<vec<iip>> ing(n);

        forn(i, m) {
            int a, b, c;
            read(a, b, c);
            a--; b--;
            g[a].emplace_back(b, c);
            ing[b].emplace_back(a, c);
        }

        auto check_city = [&](int s) {
            int ans = 1e9;

            priority_queue<iip, vec<iip>, greater<iip>> q;
            ivec dist(n, 1e9);
            dist[s] = 0;
            q.emplace(0, s);

            while (!q.empty()) {
                auto [d, v] = q.top();
                q.pop();

                if (d != dist[v]) {
                    continue;
                }

                for (auto [u, w] : g[v]) {
                    if (uin(dist[u], dist[v] + w)) {
                        q.emplace(dist[u], u);
                    }
                }
            }

            for (auto [v, w] : ing[s]) {
                uin(ans, dist[v] + w);
            }

            return ans;
        };

        ivec ans(n);
        forn(i, n) {
            ans[i] = check_city(i);
            if (ans[i] == 1e9) {
                ans[i] = -1;
            }
        }

        forn(i, n) {
            cout << ans[i] << "\n";
        }
    }
}


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

int main(){
  int64_t N;
  cin>>N;
  int64_t cnta=1,cntb=1;
  int64_t i=3,j=5;

  while(i<=N){
    int64_t M=N-i;
    while(j<=M){
      if(j==M){
        cout<<cnta<<' '<<cntb<<endl;
        return 0;
      }
      cntb++;
      j*=5;
    }
    cntb=1;j=5;
    cnta++;i*=3;
  }
  cout<<-1<<endl;

}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

void func(std::string S, std::string T){

}

int main() {
    string A, B;
    cin >> A >> B;

    if(A=="Y"&&B=="a"){
        cout << "A" << endl;
    }

    else if(A=="Y"&&B=="b"){
        cout << "B" << endl;
    }

    else if(A=="Y"&&B=="c"){
        cout << "C" << endl;
    }

    else if(A=="N"&&B=="a"){
        cout << "a" << endl;
    }

    else if(A=="N"&&B=="b"){
        cout << "b" << endl;
    }

    else if(A=="N"&&B=="c"){
        cout << "c" << endl;
    }
}

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll>>
#define iint int
#define f(i,a,b)        for(ll i=a;i<b;i++)
#define f0(i,n)         f(i,0,n)
#define fr(i,a,b)       for(ll i=a;i>=b;i--)
#define for1(i,n)       for(ll i=1;i<=n;i++)
#define pb              push_back
#define tc(t)           int t;cin >>t;while(t--)
#define lol             std::ios::sync_with_stdio(false); cin.tie(NULL);
#define endl            "\n"
#define ss              second
#define ff              first
#define ll              long long
#define lld             long double
#define int             long long
#define pii             pair< int,int >
#define pll             pair< ll,ll >
#define sz(a)           a.size()
const long long  inf = 1e18;
#define all(a)          a.begin(),a.end()
#define arr(a,n)        int a[n];f0(i, n) cin >> a[i];
#define ini(a,n)        memset(a,n,sizeof(a))
#define printArr(a,n)   f0(i,n) cout<<a[i]<<" ";
// #define in              cin>>
#define rr              return 0;
#define vi              vector< int >
#define vs              vector<string>
#define l_b             lower_bound
#define u_b             upper_bound
#define mod             1000000007
#define pi              3.141592653589793238
#define fmap(m)         for(auto it:m)
#define deb(args...)    { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl;
#define long_max        numeric_limits<ll>::max()
vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1};

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

int dx2[2] = {0, 1};
int dy2[2] = {1, 0};

const int N = 1e6 + 1;

int nc2(int n )
{
    return n * (n - 1) / 2;
}

void solve()
{
    int a, b;
    cin >> a >> b;
    // 0 rock  1 scissor 2 paper;
    if ( a == b)
        cout << a << '\n';
    // if (a > b) swap(a, b);
    else
        cout << 3 - (a + b) << "\n";

}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    lol;

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=510; //check the limits, dummy
int a[N];
int n, m;
char c[N];
set<char> s[N+N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; ++i){
		scanf("%s",c);
		for(int j=0; j<m; ++j){
			if(c[j]!='.')
				s[i+j].insert(c[j]);
		}
	}
	ll ans = 1, mod = 998244353;
	for(int i=0; i<=n+m-2; ++i){
		if(s[i].size()==2){
			ans = 0;
			break;
		}
		else if(s[i].size()==0){
			ans *= 2;
			ans %= mod;
		}
	}
	printf("%lld\n",ans) ;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll mod = 998244353;
const ll inf = 1e18;

vector<ll> factorial;
void fill_factorial(ll n) {
    factorial.resize(n+1);
    factorial[0] = 1;
    for(ll i=1; i<=n; i++) factorial[i] = (factorial[i-1]*i)%mod;
}
ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
ll binpow(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a%mod;
        a = a * a%mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll a) {
	ll x, y;
	ll g = gcd(a, mod, x, y);
	x = (x % mod + mod) % mod;
	return x;
}
ll CC(ll n, ll k) {
    if(k>n) return 0LL;
    return factorial[n] * inv(factorial[k]) % mod * inv(factorial[n - k]) % mod;
}

void solve() {
    ll n; cin>>n;
    ll ans = 0;
    FOR(i,n) {
        ll a,b; cin>>a>>b;
        ans += (b*(b+1))/2 - (a*(a-1))/2;
    }
    cout<<ans<<"\n";
}

int main() {
	IOS;
    #ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
    #endif

    //ll no_of_test_cases; cin>>no_of_test_cases;
    ll no_of_test_cases = 1;
	while(no_of_test_cases--) {
      solve();
    }
    return 0;
}


/**
*    author: zakhio (mttk1528)
*    created: 13.03.2021 21:04:51
**/
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;

#define dump(x) cout << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define len(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(x) __builtin_popcount(x)
#define ctz(x) __builtin_ctz(x)
#define rup(x, y) ((x + y - 1) / (y))

using str = string;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pldld = pair<ld,ld>;
// using bint = boost::multiprecision::cpp_int;

constexpr ld PI = M_PI;
constexpr ld EPS = 1e-10;
constexpr ll LINF = 1e18;
constexpr int INF = 1e9;
constexpr int MAX = 2000020;
constexpr int MOD1 = 1000000007;
constexpr int MOD2 = 998244353;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
const int di2[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj2[8] = {1, 0, -1, 0, 1, -1, 1, -1};

constexpr ld radian_to_degree(ld r) { return (r * 180.0 / PI); }
constexpr ld degree_to_radian(ld d) { return (d * PI / 180.0); }
inline bool eq(ld lhs, ld rhs) { return std::fabs(lhs - rhs) < EPS; }
inline void print() { cout << endl; return; }

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail)) cout << " "; print(forward<Tail>(tail)...); }
template <typename T, typename U> inline bool chmax(T &lhs, U rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; }
template <typename T, typename U> inline bool chmin(T &lhs, U rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; }
template <typename T> inline T gcd_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return gcd(x, y); }); }
template <typename T> inline T lcm_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return lcm(x, y); }); }
template <typename T> inline T bpow(T a, int n) { T r(1); while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
template <typename T> inline auto comp(vector<T> v) { sort(all(v)); v.erase(unique(all(v)), v.end()); return v; }
template <typename T> inline string join(string s, vector<T> v) { string t = ""; rep(i, len(v)) { if (i) t += s; t += to_string(v[i]); } return t; }
template <typename T> inline ld eucdist(pair<T,T> x, pair<T,T> y) { return hypotl(x.first - y.first, x.second - y.second); }

template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) { return os << p.first << " " << p.second;}
template <typename T, typename U> istream &operator>>(istream &is, pair<T,U> &p) { return is >> p.first >> p.second; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, len(v)) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { int c(0); for (auto &x : st) { if (c) os << " "; os << x; c++; } return os;}

void solve() {

    ll a, b, x; cin >> a >> b >> x;
    ll as = a, bs = b;
    x *= 1000;
    bool ok = false;
    while (true) {
        if (as <= x  && x <= bs) ok = true;
        as += a, bs += b;
        if (as > x) break;
    }
    if (ok) print(rup(x, b), x / a);
    else print("UNSATISFIABLE");

    return;
}

int main() {

    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);

    solve();

    return 0;
}

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <math.h>
//#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define MAX (1LL<<63)-1
#include <algorithm>
//#pragma GCC optimize ("-O3")
using namespace std;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;

#define PI 3.14159265358979323846
#define NIL -1

int main(){
  float A,B;
  cin >> A >> B;
  float C=B*A/100;
  cout << C << endl;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
using namespace std;

bool check(ll l,ll r,vector<vector<ll>> &p,vector<ll> &b) {
	ll n=p.size();
	lop(i,l,r+1) b[i]=0;
	lop(i,0,n) {
		ll x=p[i][0],y=p[i][1];
		if(x!=-1 and y!=-1) {
			if(y<l or x>r) continue;
			if(y-x!=(r-l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x!=-1 and y==-1) {
			if(x>r or x<l) continue;
			if(x>=(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x==-1 and y!=-1) {
			if(y<l or y>r) continue;
			x=y-((r-l+1)/2);
			if(y<(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
	}
	return true;
}

void solve() {
	ll n;
	cin>>n;
	vector<vector<ll>> p(n,vector<ll>(2,0));
	vector<bool> dp(2*n+1,false);
	vector<ll> b(2*n+1);
	lop(i,0,n) cin>>p[i][0]>>p[i][1];
	dp[0]=true;
	for(int i=0 ; i<(2*n)+1 ; i+=2) {
		for(int j=i+2 ; j<=(2*n)+1 ; j+=2) {
			//cout<<check(i+1,j,p,b)<<endl;
			dp[j]=dp[j]or(dp[i] and check(i+1,j,p,b));
		}
	}
	//atout(dp);
	cout<<((dp[2*n])?"Yes":"No")<<endl;
	return;
}

int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	ll t=1;
	while(t--) {
		solve();
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/all>
using namespace atcoder;*/
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma endregion
#pragma region macros
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define RREP(i, a, b) for(int i = b - 1; i >= a; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (r).rend()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	ll n; cin >> n;
	bool ok = false;
	ll a = 1, b = 1;
	for(int i = 1; i < 100; i++){
		a *= 3;
		b = 1;
		if(a > n) break;
		for(int j = 1; j < 100; j++){
			b *= 5;
			if(n < a + b) break;
			if(a + b == n){
				ok = true;
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	if(!ok) cout << -1 << endl;
}
/*
	* int overflow, array bounds
	* special cases (n=1?)
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char arr[101][101];
    int i,n,m,x,y,count=0;
    char ch;
    cin>>n>>m>>x>>y;
    for(i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>arr[i][j];
        }
    }
    if(arr[x][y]=='.')
        count++;
    else if(arr[x][y]=='#')
    {
        cout<<"0"<<endl;
        return 0;
    }
    for(i=x+1;i<=n;i++)
    {
        if(arr[i][y]=='.')
            count++;
        else
            break;
    }
    for(i=x-1;i>=1;i--)
    {
        if(arr[i][y]=='.')
            count++;
        else
            break;
    }
    for(i=y+1;i<=m;i++)
    {
        if(arr[x][i]=='.')
            count++;
        else
            break;
    }
    for(i=y-1;i>=1;i--)
    {
        if(arr[x][i]=='.')
            count++;
        else
            break;
    }
    cout<<count<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    x--;
    y--;
    vector<string> mp(h);
    for (int i = 0; i < h; i++) cin >> mp[i];
    int ans = 0;
    for (int i = x; i < h; i++) {
        if (mp[i][y] == '#') break;
        ans++;
    }
    for (int i = x - 1; i >= 0; i--) {
        if (mp[i][y] == '#') break;
        ans++;
    }
    for (int j = y + 1; j < w; j++) {
        if (mp[x][j] == '#') break;
        ans++;
    }
    for (int j = y - 1; j >= 0; j--) {
        if (mp[x][j] == '#') break;
        ans++;
    }
    cout << ans << endl;

    return 0;
}