/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2e5+10;
typedef long long llong;

int dv[N],prm[N],nprm;

void init(){
	for(int i=2;i<N;i++){
		if(!dv[i]){
			dv[i]=i;
			prm[++nprm]=i;
		}
		for(int j=1;j<=nprm && prm[j]*i<N;j++){
			dv[prm[j]*i]=prm[j];
			if(i%prm[j]==0) break;
		}
	}
}
int main(){
	init();
	int n;scanf("%d",&n);
	llong ans=0;
	for(int i=1;i<=n;i++){
		int tmp=i,las=dv[i],ncnt=0;
		llong now=1;
		while(tmp>1){
			if(las==dv[tmp]) ncnt++;
			else{
				now*=(ncnt+1ll)*(ncnt+2ll)/2;
				las=dv[tmp];
				ncnt=1;
			}
			tmp/=dv[tmp];
		}
		now*=(ncnt+1ll)*(ncnt+2ll)/2;
		ans+=now;
	}
	printf("%lld\n",ans);
	return 0;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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; };

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

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

  int N, M; cin >> N >> M;
  vi mem(1005);
  rep(i,0,N) {
    int a; cin >> a; mem[a]++;
  }
  rep(i,0,M) {
    int b; cin >> b; mem[b]--;
  }

  vi ans;
  rep(i,0,1005) {
    if (mem[i] != 0) ans.pb(i);
  }
  rep(i,0,ans.size()) {
    cout << ans[i];
    if (i < ans.size()-1) cout << " ";
  }
  cout << endl;

  return 0;
};


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

// #define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }
int ceilInt(int a, int b) {
    if(!b) return 0;
    if(a%b) return a/b + 1;
    return a/b;
}

int INF = 1e18;
int MOD = 998244353;

void solve()
{
    int a, b; cin>>a>>b;
    int negs = 0, poss = 0;
    vi pos, neg;
    rep(i, 1, a+1) negs += i, pos.pb(i);
    rep(i, 1, b+1) poss += i, neg.pb(i);
    if(negs > poss) {
        neg[neg.size()-1] += abs(negs-poss);
    } else {
        pos[pos.size()-1] += abs(negs-poss);
    }
    for(int i: pos) cout<<i<<" ";
    for(int i: neg) cout<<-i<<" ";
    cout<<endl;
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin>>t;
    rep(i, 0, t)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
    }
    return 0;
}

#include<iostream>
#include<string.h>
using namespace std;
int main(){
    long long h,w;
    long long a[3000][3000];
    long long s[3000][3000];
    long long smax; //Takahashi - Aoki
    long long posx = 0, posy = 0;
    long long mode = 1; //1 xx　2 xy　3 yx　4 yy 5 xのaoki最適解 6 yのaoki最適解
    long long temp[50];
    long long pt=0;
    long long mode5,mode6;
    string buf;
    cin >> h>> w;
    for (int i = 0; i < (h+5); i++){
        for (int j = 0; j < (w + 5); j++){
            a[i][j] = 0;
        }
    }
    s[1][1] = 0;
    for (int i = 1; i <= h; i++){
        cin >> buf;
        for (int j = 1; j <= w;j++){
            if (buf[j-1] == '+'){
                a[i][j] = 1;
            } else{
                a[i][j] = -1;
            }
        }
    }
    s[h][w] = 0;
    for(int i = h; i >=1; i--){
        for (int j = w; j >= 1; j--){
            if ((i == h) && (j == w)){
            } else {
                if (((i + j) % 2) == 0) { //高橋
                    if (i == h){
                        s[i][j] = s[i][j+1] + a[i][j+1];
                    } else if (j == w){
                        s[i][j] = s[i+1][j] + a[i+1][j];
                    } else{
                        s[i][j] = max(s[i+1][j]+a[i+1][j],s[i][j+1]+a[i][j+1]);
                    }
                } else{ //青木
                    if (i == h){
                        s[i][j] = s[i][j+1] - a[i][j+1];
                    } else if (j == w){
                        s[i][j] = s[i+1][j] - a[i+1][j];
                    } else{
                        s[i][j] = min(s[i+1][j]-a[i+1][j],s[i][j+1]-a[i][j+1]);
                    }
                }
            }
        }
    }
    if (s[1][1] == 0){
        cout << "Draw";
    } else if(s[1][1] > 0){
        cout << "Takahashi";
    } else{
        cout << "Aoki";
    }
}


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

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  unsigned int v=s.size();
  for(unsigned int i=0;i<v;i++){
    if(s[i]=='6'){
      s[i]='9';
      continue;
    }
    if(s[i]=='9'){
      s[i]='6';
      continue;
    }
  }
  cout<<s<<endl;
  return 0;
}

#include <iostream>
#include <stdio.h>
#include <climits>
#include <string>

//martin02

using namespace std;

int main() {
	string s;
	cin >> s;
	string s2;

	for (int i = s.length() - 1; i >= 0; i--) {
		if (s.at(i) == '0') {
			s2 += '0';
		}
		else if (s.at(i) == '1') {
			s2 += '1';
		}
		else if (s.at(i) == '6') {
			s2 += '9';
		}
		else if (s.at(i) == '8') {
			s2 += '8';
		}
		else {
			s2 += '6';
		}
	}

	cout << s2 << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define pf push_front
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll mod=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
ll llpow(ll n,ll i){if(i==0){return 1;}ll cnt=n;for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};
mint f2(ll n) {if (n == 0) return 1;mint x = f2(n/2);x *= x;if (n%2 == 1) x *= 2;return x;}
mint choose(int n,int a){mint x=1,y=1;rep(i,a){x*=n-i;y*=i+1;}return x/y;}
ll xs/*xorsum nまでのxorの和*/(ll n){ll cnt=(n+1)/2;ll ans=cnt%2;if(n%2==0) ans^=n;return ans;}
ll Fa/*Factorial nの階乗*/(ll n){ll ans=1;rrep(i,n){ans*=i;}return ans;}

int main() {
    int m,h;cin>>m>>h;
    if(h%m==0) yn;
}

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

int main() {
  int m,h;
  cin >> m >> h;
  if(h % m == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define LL __int128
long long T,t;
long long X,Y,P,Q;
long long mod1,mod2;
long long a1,a2,b1,b2;
inline long long qr(){
	char a=0;long long w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return w*x;
}
LL exgcd(LL a,LL b,LL &x,LL &y){
	if(!b){x=1,y=0;return a;}
	LL d=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return d;
}
LL mul(LL a,LL b,LL p){
	LL ans=0;
	for(;b;b>>=1){
		if(b&1)ans=(ans+a)%p;
		a=(a+a)%p;
	}
	return ans%p;
}
LL excrt(){
    LL x,y,M=b1,ans=a1;
    LL a=M,b=b2,c=(a2-ans%b+b)%b;
    LL gcd=exgcd(a,b,x,y);
    LL bg=b/gcd;
    if(c%gcd!=0) return -1;
    x=mul(x,c/gcd,bg);
    ans+=x*M;M*=bg;
    ans=(ans%M+M)%M;
    return (ans%M+M)%M;
}
int main(){
	T=qr();
	while(T--){
		X=qr();Y=qr();P=qr();Q=qr();
		b1=(X+Y)<<1ll;b2=P+Q;
		LL ans=2e18;
		long long opl=0;
		for(long long i=0;i<Y;i++)
			for(long long j=P;j<P+Q;j++){
				a1=i+X;a2=j;
				LL ans1=excrt();
				if(ans1==-1) continue;
				opl=1;
				ans=min(ans1,ans);
			}
		if(opl)printf("%lld\n",(long long)ans);
		else printf("infinity\n");
	}
	return 0;
}

//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int N = 2441;

using namespace std;
int  n , m , value;
ll a[ N ][ N ] , ro[ N ] , col[ N ] , mod = 1e9+7 ;

map <ll,ll> dia;

char ch;

int main(){
fcin;
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++) {
		for(int j = 0 ; j < m ; j++) {
			cin >> ch;
			a[i][j] = (ch == '.');
		}
	}

	ll ans = 0;

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){

			if(!a[i][j]) {
				dia[i-j] = 0;
				ro[i] = 0;
				col[j] = 0;
				continue;
			}
			if(!i && !j) {
				dia[0] = 1;
				col[j] = 1;
				ro[i] = 1;
			}
			else {
				value = dia[ i - j ] % mod;
				value += col[j] % mod; value %= mod;
				value += ro[i] % mod; value %= mod;
				dia[i - j] += value; dia[i-j] %= mod;
				col[j] += value; col[j] %= mod;
				ro[i] += value; ro[i] %= mod;
				if(i == n - 1 && j == m - 1) ans = value;
			}
		}
	}

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


#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back((a))
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
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; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll n;
	scan(n);
	ll mink=0,maxk=2*INF;
	while(mink+1<maxk){
		ll midk=(mink+maxk)/2+(mink+maxk)%2;
		if((midk-1)*midk<=2*(n+1)){
			mink=midk;
		}
		else{
			maxk=midk;
		}
	}
	prin(n-mink+2);
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
using ll=long long;
using namespace std;

ll n;

ll bs(ll st, ll ed){
    //cout<<st<< " "<<ed<<endl;
    if(ed-st<=1){
        return st;
    }
    ll md=(st+ed)/2;
    if(md*(md+1)/2<=n+1){
        return bs(md,ed);
    }else{
        return bs(st,md);
    }

}

int main(){
    cin>>n;

    ll ans=bs(1,1420000000);
    cout<<n-ans+1<<endl;
    return 0;
}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n, m; cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    cin >> m;
    vector<int> r(m + 1, 0);
    vector<int> sx(m + 1, 1), sy(m + 1, 1);
    vector<int> nx(m + 1, 0), ny(m + 1, 0);
    rep(i, m) {
        int op; cin >> op;
        r[i + 1] = r[i];
        sx[i + 1] = sx[i], sy[i + 1] = sy[i];
        nx[i + 1] = nx[i], ny[i + 1] = ny[i];
        if(op == 1) {
            r[i + 1] ^= 1;
            swap(sx[i + 1], sy[i + 1]);
            swap(nx[i + 1], ny[i + 1]);
            sy[i + 1] *= (-1); //?
            ny[i + 1] *= (-1); //?
        } else if(op == 2) {
            r[i + 1] ^= 1;
            swap(sx[i + 1], sy[i + 1]);
            swap(nx[i + 1], ny[i + 1]);
            sx[i + 1] *= (-1); //?
            nx[i + 1] *= (-1); //?
        } else if(op == 3) {
            sx[i + 1] *= (-1);
            nx[i + 1] *= (-1);
            int p; cin >> p;
            nx[i + 1] += 2 * p;
        } else {
            sy[i + 1] *= (-1);
            ny[i + 1] *= (-1);
            int p; cin >> p;
            ny[i + 1] += 2 * p;
        }
    }
    int q; cin >> q;
    rep(_, q) {
        int a, b; cin >> a >> b;
        -- b;
        int X = x[b], Y = y[b];
        if(r[a]) swap(X, Y);
       // cerr << a << " " << sy[a] << " " << ny[a] << "\n";
        cout << X * sx[a] + nx[a] << " " << Y * sy[a] + ny[a] << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
vector <vector<int> > multi(vector<vector<int> >&a,vector<vector<int> >&b,vector<vector<int> >&ans)
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
			{
				ans[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--)
    {
    	int n;
    	cin>>n;
    	pair<int,int> co[n];
    	for(int i=0;i<n;i++)
    	{
    		cin>>co[i].first>>co[i].second;
    	}
    	int m;
    	cin>>m;
    	vector<vector<vector<int> > > op(m+100,vector<vector<int> >(3,vector<int>(3,0)));
    	op[0][0][0]=1;
    	op[0][1][1]=1;
    	op[0][2][2]=1;
    	for(int i=1;i<=m;i++)
    	{
    		int k;
    		cin>>k;
    		if(k==1)
    		{
    			vector<vector<int> > temp(3,vector<int>(3,0));
    			temp[0][1]=1;
    			temp[1][0]=-1;
    			temp[2][2]=1;
    			multi(temp,op[i-1],op[i]);
    		}
    		if(k==2)
    		{
    			vector<vector<int> > temp(3,vector<int>(3,0));
    			temp[0][1]=-1;
    			temp[1][0]=1;
    			temp[2][2]=1;
    			multi(temp,op[i-1],op[i]);
    		}
    		if(k==3)
    		{
    			int p;
    			cin>>p;
    			vector<vector<int> > temp(3,vector<int>(3,0));
    			temp[0][0]=-1;
    			temp[1][1]=1;
    			temp[2][2]=1;
    			temp[0][2]=2*p;
    			multi(temp,op[i-1],op[i]);
    		}
    		if(k==4)
    		{
    			int p;
    			cin>>p;
    			vector<vector<int> > temp(3,vector<int>(3,0));
    			temp[0][0]=1;
    			temp[1][1]=-1;
    			temp[2][2]=1;
    			temp[1][2]=2*p;
    			multi(temp,op[i-1],op[i]);
    		}
       	}
    	int q;
    	cin>>q;
    	while(q--)
    	{
    		int a,b;
    		cin>>a>>b;
    		b--;
    		int x,y;
    		x=op[a][0][0]*co[b].first+op[a][0][1]*co[b].second+op[a][0][2];
    		y=op[a][1][0]*co[b].first+op[a][1][1]*co[b].second+op[a][1][2];
    		cout<<x<<' '<<y<<endl;
    	}
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define space ' '
#define kick(t) cout << "Case #" << t << ":" << endl;

typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}

template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}

int divisible(string num)
{
    int n = num.length();

    int sum = accumulate(begin(num), end(num), 0) - '0' * 1;

    if (sum % 3 == 0)
        return 0;

    if (n == 1)
        return -1;

    for (int i = 0; i < n; i++)
        if (sum % 3 == (num[i] - '0') % 3)
            return 1;

    if (n == 2)
        return -1;

    return 2;
}

void solve(){
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  	string s;
	cin >> s;
	cout << divisible(s);
}

#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <list>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 500005;
const int mod = 998244353;

int c[3];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  int sum = 0;
  for(int i=0;i<s.size();i++){
    int tt = s[i] - '0';
    sum = (sum + tt)%3;
    c[tt%3]++;
  }
  if(sum==0){
    cout<<0<<endl;
  } else if(sum==1){
    if(s.size()>1&&c[1]>0) {
      cout<<1<<endl;
    } else if(s.size()>2&&c[2]>1){
      cout<<2<<endl;
    } else cout<<-1<<endl;
  } else {
    if(s.size()>1&&c[2]>0) {
      cout<<1<<endl;
    } else if(s.size()>2&&c[1]>1){
      cout<<2<<endl;
    } else cout<<-1<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#include<tuple>
typedef long long ll;
#define INF 99999999999999
#define mod 1000000007
#define eps 1e-9
using namespace std;
typedef pair<ll,ll>du;
ll a,b,can=1,ans=0;
ll cnt[200],now[205];
string s,cmp;
vector<string>mut;
void chan(ll x){
    string res;
    while(x!=0){
        res+=(char)(x%10+'0');
        x/=10;
    }
    reverse(res.begin(),res.end());
    while(res.size()<3)res="0"+res;
    mut.push_back(res);
    return ;
}
int main(){
    ios::sync_with_stdio(0);
    cin>>s;
    if(s=="84"||s=="27"||s=="29"||s=="65"){
        cout<<"Yes\n";
        return 0;
    }
    cmp=s;
    while(cmp.size()<3)cmp="0"+cmp;
    for(ll i='0';i<='9';i++)
        cnt[i]=0;
    for(ll i=0;i<1000;i+=8){
        chan(i);
    }
    for(auto k:s)
        cnt[k]++;
    for(auto k:mut){
        can=1;
        for(ll i='0';i<='9';i++)
            now[i]=0;
        for(auto g:k)
            now[g]++;
        for(ll i='0';i<='9';i++)
            if(now[i]>cnt[i])
                can=0;
        if(k==cmp)
            can=1;
        ans=ans|can;
    }
    if(ans)
        puts("Yes");
    else
        puts("No");
    return 0;
}

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

const int maxn = 1e2+10;
int n[10];

int main(){
    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++){
        n[s[i]-'0']++;
    }

    if(s.size() < 2){
        if((s[0]-'0')%8 == 0){
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
        return 0;
    }

    if(s.size() == 2){
        int a = (s[0]-'0')+10*(s[1]-'0');
        int b = (s[1]-'0')+10*(s[0]-'0');
        if(a%8 == 0 || b%8 == 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
    }

    for(int i = 104; i < 999; i+=8){
        int w[10];
        for(int j = 0; j < 10; j++){
            w[j] = n[j];
        }
        bool q = true;
        int a = i;
        while(a!=0){
            int b = a%10;
            if(!w[b]){
                q = false;
                break;
            }
            w[b]--;
            a/=10;
        }
        if(q){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {

  long long A[3];
  cin >> A[0];
  cin >> A[1];
  cin >> A[2];

  sort(A, A+3);

  cout << A[1] + A[2] << endl;

}

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

int main(int argc, char* argv[]) {

    int a, b, c;
    cin >> a >> b >> c;

    if(c==0) {
        if(a==0) {
            cout << "Aoki" << endl;
        } else {
            while(a!=0 && b!=0) {
                a--;
                if(a==0) {
                    cout << "Aoki" << endl;
                    break;
                }
                b--;
                if(b==0) {
                    cout << "Takahashi" << endl;
                    break;
                }
            }
        }
    }
    else
    {
        if(b==0) {
            cout << "Takahashi" << endl;
        } else {
            while(a!=0 && b!=0) {
                b--;
                if(b==0) {
                    cout << "Takahashi" << endl;
                    break;
                }
                a--;
                if(a==0) {
                    cout << "Aoki" << endl;
                    break;
                }
            }
        }
    }

    return 0;
}


#include "bits/stdc++.h"
#pragma GCC target("avx,avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#define FOR(a, b, c) for(a = b; a <=c; a++)
#define ROF(a, b, c) for(a = b;a >= c; a--)
#define mem0(A) memset(A,0,sizeof(A))
#define mem1(A) memset(A,-1,sizeof(A))
#define memf(A) memset(A,false,sizeof(A))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define GEN(T) template<typename T>
#define EB emplace_back
#define SORT(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define newl '\n'
#define IOF ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using UL  =  unsigned long int;
using UI  =  unsigned int;
using ULL =  unsigned long long int;
using LI  =  long int;
using LL  =  long long;
using LF  =  double;
using LLF =  long double;
const int mod1 = 1000000007;
const int mod2 = 998244353;
const double PI = acos(-1);
typedef vector<vector<int>> adjList;

LL ans ;

adjList graph;
int vis[200001];
inline void dfs(int v,int par){
    vis[v] = 1;
    for(auto child : graph[v]){
        if(vis[child]==0){
            dfs(child,v);
        }
        else if(vis[child]==1){
            ans++;
        }
    }
    vis[v] = 2;
}

LL solver(LL a,LL x){
    LL res = 1;
    LL mods = mod2 * 1ll;
    while(x>0){
        if(x&1){
            res = (res * a)%mods;
        }
        a = (a*a)%mods;
        x >>= 1;
    }
    return res;
}

int main(){
        IOF
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        int ntc=1,tc,n,i,j;

        //cin>>ntc;
        //cout<<fixed<<setprecision(16);
        FOR(tc,1,ntc){
            //cout<<"Case #"<<tc<<": ";
            cin>>n;
            graph.resize(n);
            FOR(i,0,n-1){
                cin>>j;
                j--;
                graph[i].PB(j);
            }

            FOR(i,0,n-1){
                if(vis[i]==0){
                    dfs(i,-1);
                }
            }

            cout<<(solver(2ll,ans)-1)%mod2;

        }
}

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

#define ll long long int
#define pb(a) push_back(a)
#define vll vector<ll>
#define loop(i, n) for(ll i=1;i<=n;i++)
#define loop0(i, n) for(ll i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define mp(i, j) make_pair(i, j)
const ll mod = 1000000007;
const ll big = 2999999999999999999;
const ll small = -2999999999999999999;
void in2(ll& a, ll& b) { in(a); in(b); }
void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); }
void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; }
void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); }

ll n;
vll r, g, b;

ll getAns(vll& a, vll& b)
{
  ll ans = big;
  for(ll e : b)
  {
    vll::iterator itr = lower_bound(a.begin(), a.end(), e);
    if(itr == a.end())
      continue;
    ll na = *itr;
    ans = min(ans, na-e);
  }
  for(ll e : a)
  {
    vll::iterator itr = lower_bound(b.begin(), b.end(), e);
    if(itr == b.end())
      continue;
    ll nb = *itr;
    ans = min(ans, nb-e);
  }
  return ans;
}

ll anotherWay(vll& a, vll& b, vll& c)
{
  return getAns(a, c) + getAns(b, c);
}

void solve()
{
  cin>>n;
  char c;
  ll ip;
  loop0(i, 2*n)
  {
    cin>>ip>>c;
    if(c == 'R')
      r.pb(ip);
    if(c == 'G')
      g.pb(ip);
    if(c == 'B')
      b.pb(ip);
  }
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(b.begin(), b.end());
  if(r.size()%2 == 0 && g.size()%2 == 0 && b.size()%2 == 0)
  {
    cout<<"0\n";
    return;
  }
  ll ans = 0;
  if(r.size()%2 == 0)
  {
    ans = getAns(g, b);
    if(r.size())
      ans = min(ans , anotherWay(g, b, r));
  }
  else if(g.size()%2 == 0)
  {
    ans = getAns(r, b);
    if(g.size())
      ans = min(ans, anotherWay(r, b, g));
  }
  else
  {
    ans = getAns(r, g);
    if(b.size())
      ans = min(ans, anotherWay(r, g, b));
  }
  cout<<ans<<"\n";
}

int main()
{
  solve();
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<bool,bool> fP;
typedef pair<ll,P> iP;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
const int SEGLEN=1<<19;

vector<int> segtree(SEGLEN*2);

void add(int ind, int num){
    ind+=SEGLEN;
    while(ind){
        segtree[ind]+=num;
        ind/=2;
    }
}

ll get(int l, int r){
    l+=SEGLEN;
    r+=SEGLEN;
    ll res=0;
    while(r>l){
        if(l%2){
            res+=segtree[l];
            l++;
        }
        l/=2;
        if(r%2){
            res+=segtree[r-1];
        }
        r/=2;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll rev=0;
    for(int j=0;j<n;j++){
        rev+=j-get(0,a[j]);
        add(a[j],1);
    }
    vector<ll> ans(n);
    ans[0]=rev;
    for(int i=0;i<n-1;i++){
        ans[i+1]=ans[i]+n-1-2*a[i];
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }

}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int tt; cin>>tt; while(tt--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++)
#define for1(i,low,high) for(int i=low;i<high;i++)
#define for2(i,low,high) for(int i=low;i<=high;i++)
#define rev(i,high,low)  for(int i=high;i>=low ;i--)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
void i_o() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
#endif
}
const int N=3e5+6;
ll bit[N];

void add(int idx,ll val){
	for(;idx<N;idx+=idx&-idx) bit[idx]+=val;
}

ll sum(int idx){
	ll res=0;
	for(;idx>0;idx-=idx&-idx)
			res+=bit[idx];
	return res;
}

int main()
{
    boost; i_o();
    int n;
    cin>>n;
    vector<ll>v(2*n);
    vector<ll>ans(n);
    for(int i=0;i<n;i++){cin>>v[i]; v[i]++;}
    for1(i,n,2*n) v[i]=v[i-n];
	ll tot=0;
	for(int i=2*n-1;i>=n;i--){
		tot+=sum(v[i]-1);
		add(v[i],1LL);
	}
	ans[0]=tot;
	for(int i=n-1;i>0;i--){
		tot-=(sum(n+1)-sum(v[i]));
		tot+=sum(v[i]-1);
		ans[i]=tot;
	}
	for1(i,0,n) cout<<ans[i]<<endl;
	cout<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define drep(i,b,a) for(int i = (b)-1; i >= (a); i--)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(v) sort(v.begin(),v.end());
#define RSORT(v) sort(v.rbegin(),v.rend());
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool  odd(T x) { return x & 1; }
template<class T> inline bool even(T x) { return !(x & 1); }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill( (T*)array, (T*)(array+N), val );
}
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; }
//----------------------------------------------------------------------------------------------

template< typename T >
struct edge {
  int to;
  T cost;
  edge(int to, T cost) : to(to), cost(cost) {}
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);
    using P = pair< T, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        auto [cost, v] = que.top();
        que.pop();
        if(dist[v] < cost) continue;
        for(auto &e : g[v]) {
            auto next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main()
{
    int a,b,x,y;
    cin >> a >> b >> x >> y;
    a--; b--;
    WeightedGraph<int> g(200);
    rep(i,0,100) {
        g[2*i].emplace_back(2*i+1, x);
        g[2*i+1].emplace_back(2*i, x);
        if(i > 0) {
            g[2*i].emplace_back(2*i-1, x);
            g[2*i-1].emplace_back(2*i, x);
        }
    }

    rep(i,0,99) {
        g[2*i].emplace_back(2*i+2, y);
        g[2*i+2].emplace_back(2*i, y);
        g[2*i+1].emplace_back(2*i+3, y);
        g[2*i+3].emplace_back(2*i+1, y);
    }

    auto dis = dijkstra(g,2*a);
    cout << dis[2*b+1] << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x,y,ans;
    cin>>a>>b>>x>>y;
    int d=fabs(a-b),mn=min(2*x,y);
    if(a==b) cout<<x<<endl;
    else if (a>b)
    {
        cout<<x+(d-1)*mn<<endl;
    }
    else cout<<x+(d)*mn<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

int main(){
  int t;
  cin >> t;
  while(t--) {
    ll l, r;
    cin >> l >> r;
    if(r < 2*l) cout << 0 << endl;
    else cout << (r-2*l+1)*(r-2*l+2)/2 << endl;
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

i64 simulate(vector<int> ops) {

	i64 x = 0;
	i64 y = 0;

	for(auto op : ops) {
		if(op == 1) {
			x += 1;
		} else if(op == 2) {
			y += 1;
		} else if(op == 3) {
			x = x + y;
		} else if(op == 4) {
			y = x + y;
		} else {
			assert(false);
		}
	}

	return x;
}

int main() {

	const i64 N = read_item();

	if(N < 100) {
		printf("%lld\n", N);
		for(auto i : range((int)N)) {
			printf("1\n");
		}
		return 0;
	}

	vector<i64> fib = {0, 1};

	while(true) {

		const int s = fib.size();
		i64 last1 = fib[s - 1];
		i64 last2 = fib[s - 2];

		dbg(last1, last2);

		if(last1 + last2 > N) {
			break;
		}

		i64 p = last1 + last2;
		fib.push_back(p);
		fib.push_back(p + last1);
		assert(p > 0);
		assert(p + last1 > 0);
	}

	const int len = fib.size();
	const int rounds = fib.size() / 2 - 1;
	i64 y = N;

	vector<pair<pair<int, int>, int>> ops;

	for(auto i : range(rounds)) {
		ops.push_back({{i, 0}, 4});
		ops.push_back({{i, 1}, 3});
	}

	for(auto i : revrange(rounds)) {

		i64 p = fib[2 + i * 2];
		i64 q = fib[3 + i * 2];

		if(y >= q) {
			ops.push_back({{rounds - 1 - i - 1, 2}, 1});
			y = y - q;
			dbg(i, q, 1);
		}
		if(y >= p) {
			ops.push_back({{rounds - 1 - i - 1, 2}, 2});
			y = y - p;
			dbg(i, q, 2);
		}
	}

	dbg(y);
	assert(y == 0);

	sort(ops.begin(), ops.end());
	vector<int> ans;

	for(auto& op : ops) {
		// dbg(op.first.first, op.first.second, op.second);
		ans.push_back(op.second);
	}

	i64 true_x = simulate(ans);
	assert(true_x == N);

	printf("%d\n", (int)ans.size());
	for(auto& op : ans) {
		printf("%d\n", op);
	}

	return 0;
}

/* wafdayo~~~ */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define BE(x) x.begin(), x.end()

int main() {
    ll n;
    string t;
    cin >> n >> t;

    ll m = 10000000000;
    if (t == "1") {
        cout << m * 2LL << endl;
        return 0;
    }

    if (t[0] == '0') t = "11" + t, n += 2;
    else if (t.substr(0, 2) == "10") t = "1" + t, n++;

    string s = "";
    while (s.size() < t.size()) s += "110";

    if (s.substr(0, n) == t) cout << m - (n+2)/3 + 1 << endl;
    else cout << 0 << endl;
}

#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 tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e9 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> par;
typedef vector<par> parv;
typedef vector<vi> vvi;
// Author : Koushal Bhat
#define forr(i,p,n) for( ll i=p; i<n; i++)
#define forn(i,p,n) for(ll i=p; i<=n; i++)
#define rev(i,n,p) for(ll i=n; i>=p; i--)
#define PI 3.14159265358979323846
#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void solve() {
    ll n=0;
    cin>>n;
    forr(i,1,MAX_N)
    {
        ll op=(i*(i+1))/2;
        if(op>=n)
        {
            cout<<i<<"\n";
            return;
        }

    }

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c, d;
    cin >> a >> b >> c >> d ;

    cout << b - c << endl;

}

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

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define oset_find(k) find_by_order(k)
#define oset_order(k) order_of_key(k)*/

using ll = long long;
using db = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define ROF(i, a, n) for(int i=(n)-1;i>=(a);--i)

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
constexpr int pct(int x) { return __builtin_popcount(x); }

template<typename T> bool fmin(T& a, const T& b) { return b<a?a=b,1:0; }
template<typename T> bool fmax(T& a, const T& b) { return a<b?a=b,1:0; }

#define ts to_string
string ts(char c) { return '\'' + string(1, c) + '\''; }
string ts(const char* s) { return (string)s; }
string ts(const string& s) { return '"' + s + '"'; }
string ts(bool b) { return (b ? "true" : "false"); }

string ts(vector<bool> v) {
    string res = "{";
    FOR(i, 0, sz(v))
        res += char('0' + v[i]);
    res += "}";
    return res;
}

template <size_t SZ> string ts(bitset<SZ> b) {
    string res = "";
    FOR(i, 0, SZ)
        res+=char('0'+b[i]);
    return res;
}

template <typename A, typename B> string ts(pair<A, B> p);
template <typename A> string ts(A v) {
    bool first = 1; string res = "{";
    for (const auto& x: v) {
        if (!first) res += ", ";
        first = 0; res += ts(x);
    }
    res += "}"; return res;
}

template <typename A, typename B> string ts(pair<A, B> p) {
    return "(" + ts(p.fi) + ", " + ts(p.se) + ")";
}

void dbg_out() { cerr << "]" << endl; }
template <typename H, typename... T> void dbg_out(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    dbg_out(t...);
}
#ifdef LOCAL
    #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
#else
    #define dbg(...) 0
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//const ll MOD = 1000000007; //998244353;
//const ll INF = LLONG_MAX;
//const db PI = 3.14159265358979323846;

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    dbg(b - c);
    cout << b - c;
}

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

    int tc = 1;
    //cin >> tc;
    while (tc--)
        solve();
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#define rep(i,n) for (int i=0;i<n;i++)

#define DENOM 1000000007

using namespace std;
using ll = long long;

char win_rps(char a, char b) {
  if (a==b) {
    return a ;
  }
  if ((a=='R' && b=='S') || (a=='S' && b=='R')) {
    return 'R' ;
  } else if ((a=='S' && b=='P') || (a=='P' && b=='S')) {
    return 'S' ;
  } else {
    return 'P' ;
  }
}

int main(){
  int n, k ;
  string prev_s, s;
  size_t s_length;
  cin >> n >> k ;
  cin >> prev_s;
  for (int i = 0 ; i< k ; ++i) {
    prev_s += prev_s ;
    s_length = prev_s.size() ;
    if (s_length == 1) {
      cout << prev_s[0] << endl ;
      return 0 ;
    }
    s = "" ;
    for (int j = 0 ; j < s_length ; j+=2) {
      s += win_rps(prev_s[j], prev_s[j+1]) ;
    }
    prev_s = s ;
    cerr << i << ": " << prev_s << endl ;
  }
  cout << prev_s[0] << endl ;
  return 0 ;
}

#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i,j,n) for(long long i = j ; i < n ; ++i)
#define fr(i,n,j) for(long long i = n ; i >= j ; --i)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long>> vpll;
const ll N = 2e5 + 100;
const ll M = 1e6 + 100;
const ll mod =  998244353;
const ll inf = 1e17 +100;
ll n,a[N],dp[N],ct = 0;

ll mul(ll a,ll b){
	return (a*b)%mod;
}

ll sum(ll a,ll b){
	return (a+b)%mod;
}

ll res(ll a,ll b){
	ll x = (a-b)%mod;
	if(x >= 0) return x;
	return (x+2*mod)%mod;
}

void solve(){
	cin >> n;
	f(i,1,n+1) cin >> a[i];
	sort(a+1,a+n+1);
	dp[0] = 0;
	f(i,1,n+1){
		ct = sum(ct,a[i]);
		dp[i] = sum(dp[i-1],mul(ct,a[i]));
		// cout << ct << " " << a[i] << endl;
		ct = res(ct,a[i]);
		// cout << ct << " " << 0 << endl;
		ct = mul(2,ct);
		ct = sum(ct,a[i]);
		// cout << ct << endl;
	}
	cout << dp[n] << endl;
}

int main(){
	fastio;
	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define fi first
#define se second
#define max Max
#define min Min
#define abs Abs
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define fan(x) (((x-1)^1)+1)
#define mp(x,y) make_pair(x,y)
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;}
template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;}

const int N=2e5+5;
int n,A,B,C,a[N],b[N],c[N],p1[N],p2[N],pre[N],suc[N],ans=1e18;

signed main()
{
	n=read();
	for(int i=1;i<=n*2;++i)
	{
		int x=read();
		char opt[5];
		scanf("%s",opt+1);
		if(opt[1]=='R')
			a[++A]=x;
		else if(opt[1]=='G')
			b[++B]=x;
		else c[++C]=x;
	}
	if(A%2==0&&B%2==0&&C%2==0)
	{
		printf("0\n");
		return 0;
	}
	if(A%2==0&&C%2==1)
		swap(a,c),swap(A,C);
	if(B%2==0&&C%2==1)
		swap(b,c),swap(B,C);
	sort(a+1,a+1+A);
	sort(b+1,b+1+B);
	for(int i=1;i<=A;++i)
	{
		int pos=lower_bound(b+1,b+1+B,a[i])-b;
		if(pos>=1&&pos<=B) ans=min(ans,abs(a[i]-b[pos]));
		if(pos>=2&&pos<=B+1) ans=min(ans,abs(a[i]-b[pos-1]));
	}
	for(int i=1;i<=C;++i)
	{
		int pos=lower_bound(a+1,a+1+A,c[i])-a;p1[i]=1e18;
		if(pos>=1&&pos<=A) p1[i]=min(p1[i],abs(c[i]-a[pos]));
		if(pos>=2&&pos<=A+1) p1[i]=min(p1[i],abs(c[i]-a[pos-1]));

		pos=lower_bound(b+1,b+1+B,c[i])-b;p2[i]=1e18;
		if(pos>=1&&pos<=B) p2[i]=min(p2[i],abs(c[i]-b[pos]));
		if(pos>=2&&pos<=B+1) p2[i]=min(p2[i],abs(c[i]-b[pos-1]));
	}
	pre[0]=1e18;suc[C+1]=1e18;
	for(int i=1;i<=C;++i) pre[i]=min(pre[i-1],p2[i]);
	for(int i=C;i>=1;--i) suc[i]=min(suc[i+1],p2[i]);
	for(int i=1;i<=C;++i) ans=min(ans,p1[i]+min(pre[i-1],suc[i+1]));
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e15;

void solve()
{
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    vector<ll> cutenesses;
    vector<string> colors;
    ll cute;
    string last_color = "U";
    string color;
    int red = 0, blue = 0, green = 0;
    bool rb = false, rg = false, bg = false;
    ll min_rb = INF, min_rg = INF, min_bg = INF;
    for (int t = 1; t <= 2 * N; t++)
    {
        cin >> cute;
        cin >> color;

        cutenesses.push_back(cute);
        colors.push_back(color);
        if (color.compare("R") == 0)
        {
            red += 1;
        }
        else if (color.compare("B") == 0)
        {
            blue += 1;
        }
        else
        {
            green += 1;
        }
        // cout << cute << " " << color << endl;
        // solve();
    }
    if ((red % 2 == 0) && (blue % 2 == 0) && (green % 2 == 0))
    {
        cout << 0;
    }
    else
    {

        vector<size_t> idx(cutenesses.size());
        iota(idx.begin(), idx.end(), 0);

        // sort indexes based on comparing values in v
        // using std::stable_sort instead of std::sort
        // to avoid unnecessary index re-orderings
        // when v contains elements of equal values
        stable_sort(idx.begin(), idx.end(),
                    [&cutenesses](size_t i1, size_t i2)
                    { return cutenesses[i1] < cutenesses[i2]; });
        for (int i = 0; i < 2 * N - 1; i++)
        {
            // cout << idx[i] << " " << idx[i + 1] << endl;
            // cout << colors[idx[i]] << " " << colors[idx[i + 1]] << endl;
            if (((colors[idx[i]].compare("R") == 0) && ((colors[idx[i + 1]].compare("B") == 0))) || (((colors[idx[i]].compare("B") == 0) && ((colors[idx[i + 1]].compare("R") == 0)))))
            {
                rb = true;
                min_rb = min(min_rb, abs(cutenesses[idx[i]] - cutenesses[idx[i + 1]]));
            }
            else if (((colors[idx[i]].compare("R") == 0) && ((colors[idx[i + 1]].compare("G") == 0))) || (((colors[idx[i]].compare("G") == 0) && ((colors[idx[i + 1]].compare("R") == 0)))))
            {
                rg = true;
                min_rg = min(min_rg, abs(cutenesses[idx[i]] - cutenesses[idx[i + 1]]));
            }
            else if (((colors[idx[i]].compare("G") == 0) && ((colors[idx[i + 1]].compare("B") == 0))) || (((colors[idx[i]].compare("B") == 0) && ((colors[idx[i + 1]].compare("G") == 0)))))
            {
                bg = true;
                min_bg = min(min_bg, abs(cutenesses[idx[i]] - cutenesses[idx[i + 1]]));
            }
        }
        // cout << red << " " << blue << " " << green << endl;
        // cout << rb << " " << rg << " " << bg << endl;
        // cout << min_rb << " " << min_rg << " " << min_bg << endl;
        if (red % 2 == 0)
        {
            cout << min(min_bg, min_rg + min_rb);
        }
        else if (blue % 2 == 0)
        {
            cout << min(min_rg, min_rb + min_bg);
        }
        else
        {
            cout << min(min_rb, min_rg + min_bg);
        }
    }
}


#include <iostream>
long long a[1000000]={0};
long long b[1000000]={0};
using namespace std;
int main(){
	long long n,a,b;
	cin>>n;
	long long sum=0;
	while(n>0){
		cin>>a>>b;
		sum+=(a+b)*(b-a+1)/2;
		n--;
	}
	cout<<sum;
	return 0;
}

#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;
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll t,n;
    cin>>t>>n;
    ld val,x,y;
    val=(ld)t/(ld)100;
    ll l,r,mid,ans;
    l=1,r=1e18;
    y=n-1;
    while(l<=r)
    {
        mid=(l+r)/2;
        x=floor(val*(ld)mid);
        if(x<n)
        {
            l=mid+1;
        }
        else{
            ans=mid;
            r=mid-1;
        }
    }
    cout<<ans+(ll)y<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int dp[105][105];
int n;
string s;
int p[105];

int dfs(int l, int w){
    char c = s[l];
    int t;
    if(c == 'R') t = 0;
    if(c == 'P') t = 1;
    if(c == 'S') t = 2;
    if(w == 0){
        dp[0][l] = t;
        return t;
    }

    if(dp[w][l] != -1) return dp[w][l];
    int k = l + p[w-1];
    k %= n;
    int a = dfs(k, w-1);
    int b = dfs(l, w-1);
    int res;
    if(a == b) res = a;
    if(a == 0 && b == 1) res = b;
    if(a == 0 && b == 2) res = a;
    if(a == 1 && b == 0) res = a;
    if(a == 1 && b == 2) res = b;
    if(a == 2 && b == 0) res = b;
    if(a == 2 && b == 1) res = a;

    dp[w][l] = res;
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    cin >> n >> k;
    cin >> s;
    rep(i,105) rep(j,105) dp[i][j] = -1;
    p[0] = 1;
    rep(i,100) p[i+1] = p[i]*2, p[i+1] %= n;
    int ans = dfs(0, k);
    if(ans == 0) cout << 'R' << endl;
    if(ans == 1) cout << 'P' << endl;
    if(ans == 2) cout << 'S' << endl;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

ll N, K;
vll T;
ll ans = 0;

void disp(vl arr){
    rep(i, arr.size()){
        cout << arr[i] << " ";
    }
    cout << '\n';
}

void f(vl p){
    ll tmp = 0;
    rep(i, N-1){
        tmp += T[p[i]][p[i+1]];
    }
    tmp += T[p[N-1]][p[0]];
    if(tmp == K){
        ans++;
    }
    return;
}

void dfs(vl now, ll n, ll m){
    if(n == 0){
        // 生成された順列に対して処理を行う関数(要定義)
        f(now);
        return;
    }
    for(ll v = 0; v < m; v++){
        bool con = false;
        for(auto nowv : now){
            if(nowv == v){
                con = true;
                break;
            }
        }
        if(con) continue;
        vl next = now;
        next.push_back(v);
        dfs(next, n-1, m);
    }
}

int main() {
    cin >> N >> K;
    T.resize(N, vl(N));
    rep(i, N){
        rep(j, N){
            cin >> T[i][j];
        }
    }
    vl arg = {0};
    dfs(arg, N-1, N);
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define SZ(x) int(x.size())
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void YES(bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
inline void assertNO(bool condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
inline void assertNo(bool condition){ if(!condition){ cout << "No" << endl; exit(0); } }
inline void assertm1(bool condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class T> string to_string(complex<T> x){ return to_string(make_pair(x.real(), x.imag())); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
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; }
inline int at(lint i, int j){ return (i >> j) & 1; }
random_device rnd;
bool is_in_board(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

int main(){
    int N;
    cin >> N;
    lint x[N];
    cins(x, x + N);
    lint a = 0, b = 0, c = 0;
    for(lint i: x){
        a += abs(i);
        b += i * i;
        c = max(c, abs(i));
    }
    cout << a << endl;
    fcout << sqrt(b) << endl;
    cout << c << endl;
}

#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class L, class R>
ostream& operator<<(ostream &os, const pair<L,R> &input) {
    os << "(";
	os << input.first << "," << input.second;
	return os << ")";
}

template<class T>
ostream& operator<<(ostream &os, const vector<T> &input) {
    os << "[ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "]";
}

template<class T>
ostream& operator<<(ostream &os, const set<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const unordered_set<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const multiset<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class T>
ostream& operator<<(ostream &os, const unordered_multiset<T> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R>
ostream& operator<<(ostream &os, const map<L,R> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << "(" << elem.first << " , " << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R>
ostream& operator<<(ostream &os, const unordered_map<L,R> &input) {
    os << "{ ";
    for(auto elem : input) {
		os << "(" << elem.first << " , " << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 200005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

class TaskC {
private:

public:
	void solveOne(int it){
		int n;
		cin >> n;
		vector<int> weight(n), baggage(n), p(n);
		for (int i = 0; i < n; i++) {
			cin >> weight[i];
		}
		for (int i = 0; i < n; i++) {
			cin >> baggage[i];
		}
		unordered_map<int,int> where;
		for (int i = 0; i < n; i++) {
			cin >> p[i];
			p[i]--;
			where[p[i]] = i;
			if (baggage[p[i]] >= weight[i] && i != p[i]) {
				cout << -1 << endl;
				return;
			}
		}

		vector<bool> vis(n, false);
		vector<pair<int,int>> ans;
		for (int i = 0; i < n; i++) {
			if (vis[i]) {
				continue;
			}
			vector<pair<int,int>> vertices;
			int curr = i;
			while(!vis[curr]) {
				vertices.push_back({weight[curr], curr});
				vis[curr] = true;
				curr = p[curr];
			}
			sort(vertices.begin(), vertices.end());
			for (int k = 0; k + 1 < vertices.size(); k++) {
				int f = vertices[k].second;
				int s = where[f];
				ans.push_back({f, s});
				where[p[f]] = s;
				p[s] = p[f];
			}
		}
		cout << ans.size() << endl;
		for (auto item : ans) {
			cout << item.first+1<< " " << item.second+1 << endl;
		}
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;

ll gcd (ll a, ll b) {
	ll c = a % b;
	if (c==0)
		return b;
	return gcd (b, c);
}

int main () {
	ll L;
	cin >> L;
	ll ans = 1;
	ll n[11];
	ll d[11];
	for (int i=0; i<11; i++) {
		n[i] = L-i-1;
		d[i] = i+1;
	}
	for (int i=0; i<11; i++) {
		for (int j=0; j<11; j++) {
			if (d[j] != 1) {
				ll g = gcd (n[i], d[j]);
				n[i] /= g;
				d[j] /= g;
			}
		}
		ans *= n[i];
	}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define hell 100000000000000007 //10e18+7
#define mod 1000000007//10e9+7
#define pi  3.141592653589793238
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)    substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x)    cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[201][13];

// int mod_exp(int x, int y, int mm)
// {
//   x %= mm;
//   if (y == 0)
//     return (1);
//   else if (y % 2 == 0)
//     return (mod_exp((x * x) % mm, y / 2, mm));
//   else
//     return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
// }
// int modInverse(int n, int p)
// {
//   return mod_exp(n, p - 2, p);
// }
//remember the approach of suming up the element
// and when it exceeds from our radar
// try removing from the staring part
//priority queue max heap imp!!
// void buildSegtree(ll s1, ll e1, ll p1)
// {
//   if (s1 == e1)
//   {
//     segtree[p1] = (arr[s1]);
//     return;
//   }
//   ll mid = ((s1 + e1) / 2);
//   buildSegtree(s1, mid, 2 * p1 + 1);
//   buildSegtree(mid + 1, e1, 2 * p1 + 2);
//   segtree[p1] = ((segtree[2 * p1 + 1])+segtree[2 * p1 + 2]) ;
// }

// ll rangeQuery(ll q1, ll q2, ll s1, ll e1, ll p1)
// {
//   if (q1 <= s1 && q2 >= e1)
//     return (segtree[p1]);
//   if (q2 < s1 || q1 > e1)
//     return (0);//it varies BE CAREFULL!!
//   ll mid = (s1 + e1) / 2;
//   ll l1 = rangeQuery(q1, q2, s1, mid, 2 * p1 + 1);
//   ll l2 = rangeQuery(q1, q2, mid + 1, e1, 2 * p1 + 2);
//   return ((l1+l2));
// }
// void updateQuery(ll q1, ll q2, ll id, ll p1, ll val)
// {
//   if (q1 == q2)
//   {
//     segtree[p1] = val;
//     return;
//   }
//   ll mid = (q1 + q2) / 2;
//   if (id > mid)
//     updateQuery(mid + 1, q2, id, 2 * p1 + 2, val);
//   else
//     updateQuery(q1, mid, id, 2 * p1 + 1, val);
//   segtree[p1] = (segtree[2 * p1 + 1]+segtree[2 * p1 + 2]);
// }
// ll binpow(ll a, ll b, ll m)
// {
//   a %= m;
//   ll res = 1;
//   while (b > 0) {
//     if (b & 1)
//       res = res * a % m;
//     a = a * a % m;
//     b >>= 1;
//   }
//   return res;
// }
// ll inv(ll a) {
//   a %= mod;
//   if (a < 0) a += mod;
//   ll b = mod, u = 0, v = 1;
//   while (a) {
//     ll t = b / a;
//     b -= t * a; swap(a, b);
//     u -= t * v; swap(u, v);
//   }
//   if (u < 0) u += mod;
//   return u;
// }

int32_t main()
{
#ifndef ONLINE_JUDGE
  freopen("i1.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < 201; i++)
  {
    for (int j = 0; j <= (min(i, 12LL)); j++)
    {
      if (i == j || j == 0)
        dp[i][j] = 1;
      else
        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j ];
    }
  }
  cout << dp[n - 1][11];
}


#include<bits/stdc++.h>
using namespace std;
int Nx,Ny;
const bool debug=false;
struct tile_map{
  private:

  int m[50][50];
  int c[50][50];
  bool visited[50][50];
  public:
  int64_t score=0;
  string ans="";
  int get(int x,int y){
    if(x>=0&&x<50&&y>=0&&y<50){
      return m[x][y];
    }else{
      if(debug)puts("Mindex errer");
      return -1;
    }
  }
  void init(){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cin>>m[i][j];
    }
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cin>>c[i][j];
    }
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)visited[i][j]=false;
    }
    visited[Nx][Ny]=true;
    int t=get(Nx,Ny);
    if(get(Nx+1,Ny)==t)visited[Nx+1][Ny]=true;
    if(get(Nx-1,Ny)==t)visited[Nx-1][Ny]=true;
    if(get(Nx,Ny+1)==t)visited[Nx][Ny+1]=true;
    if(get(Nx,Ny-1)==t)visited[Nx][Ny-1]=true;
  }
  int cost(int x,int y){
    if(x>=0&&x<50&&y>=0&&y<50){
      if(visited[x][y])return -1;
      else return c[x][y];
    }else{
      if(debug)puts("Cindex errer");
      return -1;
    }
  }
  map<char,array<int,3>> next(){
    map<char,array<int,3>>mv;
    if(Nx+1<50&&!visited[Nx+1][Ny]){
      mv['D']={Nx+1,Ny,cost(Nx+1,Ny)};
    }
    if(Nx-1>=0&&!visited[Nx-1][Ny]){
      mv['U']={Nx-1,Ny,cost(Nx-1,Ny)};
    }
    if(Ny+1<50&&!visited[Nx][Ny+1]){
      mv['R']={Nx,Ny+1,cost(Nx,Ny+1)};
    }
    if(Ny-1>=0&&!visited[Nx][Ny-1]){
      mv['L']={Nx,Ny-1,cost(Nx,Ny-1)};
    }
    return mv;
  }
  bool go(int x,int y){
    if(abs(x-Nx)+abs(y-Ny)!=1){
      if(debug)puts("can not go");
      return false;
    }
    if(visited[x][y]){
      return false;
    }else{
      if(x==Nx+1)ans+='D';
      if(x==Nx-1)ans+='U';
      if(y==Ny+1)ans+='R';
      if(y==Ny-1)ans+='L';
      score+=cost(x,y);
      visited[x][y]=true;
      int t=get(x,y);
      if(get(x+1,y)==t)visited[x+1][y]=true;
      if(get(x-1,y)==t)visited[x-1][y]=true;
      if(get(x,y+1)==t)visited[x][y+1]=true;
      if(get(x,y-1)==t)visited[x][y-1]=true;
      Nx=x,Ny=y;
      return true;
    }
  }
  void print(){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cout<<(visited[i][j]?'x':'o');puts("");
    }
  }
};
int main(){
  cin>>Nx>>Ny;
  tile_map M;
  M.init();
  if(debug)M.print();
  auto t=M.next();
  while(!t.empty()){
    if(Nx<25&&Ny<25){
      if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }
    }else if(Nx<25){
      if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }
    }else if(Ny<25){
      if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }
    }else{
      if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }
    }
    t=M.next();
  }
  cout<<M.ans<<'\n';
  if(debug)cout<<M.score<<'\n';
  if(debug){
    M.print();
    cout<<Nx<<' '<<Ny<<'\n';
    for(auto [x,y]:M.next()){
      cout<<y[0]<<' '<<y[1]<<'\n';
    }
  }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(x)  cerr << #x << " = " << (x) << endl;

constexpr int mod = (1<<30)-1;
inline int xor128() {
    static int x = 123456789;
    static int y = 362436069;
    static int z = 521288629;
    static int w = 88675123;
    int t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

inline int randInt(int l,int r){
    return l+xor128()%(r-l);
}

inline double getprob(){
    return (xor128()%mod)/(double) mod;
}

class TimeCheck {
private:
    chrono::system_clock::time_point start, end;

public:
    TimeCheck(){start = chrono::system_clock::now();}

    double nowTime() {
        end = chrono::system_clock::now();
        double ti = static_cast<double>(
            chrono::duration_cast<chrono::microseconds>(end-start).count()/1000.0);
        return ti;
    }
};

constexpr int N = 50;
vec<int> dx = {-1,0,1,0},dy = {0,-1,0,1};
string D = "ULDR";
vvec<int> T(N,vec<int>(N)),P = T;

bool in(int x,int y){
    return 0<=x && x<N && 0<=y && y<N;
}

struct state{
    int px,py;
    int score;
    string S;
    unordered_set<int> vis;
    state(){}
    state(int sx,int sy):px(sx),py(sy){
        score = P[sx][sy];
        vis.insert(T[sx][sy]);
        S = "";
    }
    bool is_valid_move(int nx,int ny){
        return in(nx,ny) && !vis.count(T[nx][ny]);
    }
    void move(int id){
        S += D[id];
        px += dx[id];
        py += dy[id];
        vis.insert(T[px][py]);
        score += P[px][py];
    }
    bool operator<(const state& r) const{
        return score>r.score;
    }
};

vec<state> generate_move(state& s,int len){
    vec<state> res;
    auto dfs = [&](auto&& self,int x,int y,int t)->void{
        if(t==len){
            res.push_back(s);
            return ;
        }
        rep(i,4){
            int nx = x+dx[i],ny = y+dy[i];
            if(!s.is_valid_move(nx,ny)) continue;
            s.move(i);
            self(self,nx,ny,t+1);
            s.S.pop_back();
            s.score -= P[nx][ny];
            s.vis.erase(T[nx][ny]);
            s.px = x,s.py = y;
        }
    };
    dfs(dfs,s.px,s.py,0);
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy;
    cin >> sx >> sy;
    rep(i,N) rep(j,N){
        cin >> T[i][j];
    }
    rep(i,N) rep(j,N) cin >> P[i][j];
    state init(sx,sy);
    const int width = 50;
    vec<state> que;
    que.push_back(init);
    state ans = init;
    rep(t,2500) if(!que.empty()){
        vec<state> nq;
        for(auto& s:que){
            auto res = generate_move(s,4);
            sort(all(res));
//            if(res.size()>5) res.resize(5);
            for(auto& ns:res) nq.push_back(ns);
        }
        sort(all(nq));
        if(nq.size()>width) nq.resize(width);
        if(nq.empty()) break;
        que.swap(nq);

    }
    sort(all(que));
    ans = que[0];
    cerr << "ok\n";
    cout << ans.S << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
using ll = long long;
int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    int i = 1;
    while(sum < n){
        sum += i;
        i++;
    }
    cout << i-1 << endl;

    return 0;
}

/*
 * @Date         : 2021-03-28 20:23:44
 * @Author       : ssyze
 * @Description  :
 */
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r)
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}

int t;
ll x;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> x;
        int cnt = 0;
        while (x % 2 == 0)
            x /= 2, cnt++;
        if (cnt >= 2) cout << "Even\n";
        else if (cnt == 1) cout << "Same\n";
        else cout << "Odd\n";
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	ll sum= 0;
	vector<ll> vod, vev;
	rep(i, n) {
		sum += b[i];
		if (i % 2)vod.push_back(a[i] - b[i]);
		else vev.push_back(a[i] - b[i]);
	}
	ll ans = sum;
	sort(all(vod), greater<ll>());
	sort(all(vev), greater<ll>());
	rep(i, n / 2) {
		sum += vod[i] + vev[i];
		ans = max(ans, sum);
	}
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

#include<bits/stdc++.h>
#define MAX 200000
using namespace std;
long long trianglesum[MAX+10],linesum[MAX+10];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	long long x;
	for(int i=1;i<=n;++i)
	{
		cin>>x;
		linesum[i] = linesum[i-1]+x;
		trianglesum[i] = trianglesum[i-1]+linesum[i];
	}
	long long ans = max(0LL,trianglesum[1]), maxlinesum = linesum[1];
	for(int i=2;i<=n;++i)
	{
		maxlinesum = max(maxlinesum,linesum[i]);
		ans = max(ans,trianglesum[i-1]+maxlinesum);
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
#else
	//freopen("groups.in", "r", stdin);
#endif
}

const int N = 2e5 + 9, M = 18;
const int mod = 998244353;
ll fact[N];
ll inv[N];
ll invfact[N];
void factInverse() {
	fact[0] = inv[1] = fact[1] = invfact[0] = invfact[1] = 1;
	for (long long i = 2; i < N; i++) {
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = mod - (inv[mod % i] * (mod / i) % mod);
		invfact[i] = (inv[i] * invfact[i - 1]) % mod;
	}
}

ll nCr(int n, int r) {
	if (r > n)
		return 0;
	return (((fact[n] * invfact[r]) % mod) * invfact[n - r]) % mod;
}

void add(ll &a, ll b) {
	if ((a += b) >= mod)
		a -= mod;
}

int n, m;
ll dp[13][5009];
int solve(int idx, int cnt) {
	if (idx < 0)
		return cnt == 0;
	cnt += ((m >> idx) & 1);
	ll &rt = dp[idx][cnt];
	if (~rt)
		return rt;
	rt = 0;
	for (int i = 0; i <= cnt; i += 2)
		add(rt, (solve(idx - 1, (cnt - i) * 2) * nCr(n, i)) % mod);
	return rt;
}
int main() {
	run();
	factInverse();
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	cout << solve(12, 0) << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 998244353;
ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; }

const int MAXN = 5005;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

template<class T> class Math
{
public:
    vector<T>fact,invfact;
    Math( int n )
    {
        fact.resize(n);
        invfact.resize(n);
        fact[0] = invfact[0] = 1;
        for(int i=1;i<n;i++)
        {
            fact[i] = mod( i * fact[i-1] );
            invfact[i] = modinv( fact[i] );
        }
    }
    T modinv( T x, T m = MOD )
    {
        return expo(x,m-2,m);
    }
    T expo( T base, T exp, T m = MOD )
    {
        T res = 1;
        while( exp )
        {
            if( exp&1 )
                res = mod( res*base, m );
            base = mod( base*base, m );
            exp >>= 1;
        }
        return res;
    }
    T choose( T n, T k )
    {
        if( k < 0 || k > n ) return 0;
        T ans = fact[n];
        ans = mod( ans * invfact[n-k] );
        ans = mod( ans * invfact[k] );
        return ans;
    }
};

Math<ll> mat(MAXN);

ll dp[5005];

int main()
{
    // #ifdef gupta_samarth
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    // #endif
    fastio();

    int n,m; cin>>n>>m;

    dp[0] = 1;
    // dp[i] = no of sum

    for(int bit=15; bit>=0; bit--)
    {
        ll now = 1LL<<bit;
        vector<int> ndp(5005,0);
        for(int sum=0; sum<=m; sum++)
        {
            for(int times=0; times<=n; times += 2)
            {
                ll adds = times*now;
                if(sum + adds <= m)
                {
                    add(ndp[sum+adds], mod(dp[sum] * mat.choose(n,times)));
                }
            }
        }
        for(int sum=0; sum<=m; sum++)
            dp[sum] = ndp[sum];
    }

    cout<<dp[m],nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

char judge(char a, char b){
  if(a=='R'){
    if(b=='R'){
      return 'R';
    }else if(b=='P'){
      return 'P';
    }else if(b=='S'){
      return 'R';
    }
  }else if(a=='P'){
    if(b=='R'){
      return 'P';
    }else if(b=='P'){
      return 'P';
    }else if(b=='S'){
      return 'S';
    }
  }else if(a=='S'){
    if(b=='R'){
      return 'R';
    }else if(b=='P'){
      return 'S';
    }else if(b=='S'){
      return 'S';
    }
  }
}

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  for(int i=0;i<k;i++){
    string tmp="";
    if(s.size()%2!=0){
      s+=s;
    }
    for(int j=0;j<s.size();j+=2){
      tmp+=judge(s.at(j),s.at(j+1));
    }
    s=tmp;
  }
  cout << s.front() << endl;
  return 0;
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 300005;
const int inf = 1e9 + 5;

int n, q;
ll niz[maxn];

ll bor[4*maxn][35];
void build(int v, int tl, int tr, int k){
    if(tl == tr){
//        bor[v][k] = ((niz[tl] & (1 << k)) == 1 ? 1 : 0);
        if(niz[tl] & (1LL << k))bor[v][k] = 1;
        else bor[v][k] = 0;
        return;
    }
    int mid = (tl + tr)/2;
    build(v*2, tl, mid, k);
    build(v*2+1, mid+1, tr, k);
    bor[v][k] = bor[v*2][k] + bor[v*2+1][k];
}
void update(int v, int tl, int tr, int poz, int vre, int k){
    if(tl == tr){
        bor[v][k] += vre;
        return;
    }
    int mid = (tl+tr)/2;
    if(poz <= mid)update(v*2,tl,mid,poz,vre,k);
    else update(v*2+1,mid+1,tr,poz,vre,k);
    bor[v][k] = bor[v*2][k] + bor[v*2+1][k];
}
int kveri(int v, int tl, int tr, int l, int r, int k){
    if(tl > r | l > tr)return 0;
    if(l <= tl && r >= tr)return bor[v][k];
    int mid = (tl + tr)/2;
    return kveri(v*2,tl,mid,l,r,k) + kveri(v*2+1,mid+1,tr,l,r,k);
}

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> q;
    ff(i,1,n)cin >> niz[i];
    ff(mask,0,30)build(1,1,n,mask);
//    build(1,1,n,2);
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int poz;
            ll x;
            cin >> poz >> x;
            ff(mask,0,30){
                if(!(x & (1 << mask)))continue;
                int koji = kveri(1,1,n,poz,poz,mask);
//                cout << "mask: " << mask << endl;
//                cout << "koji: " << koji << endl;
                if(koji == 0)update(1,1,n,poz,1,mask);
                if(koji == 1)update(1,1,n,poz,-1,mask);
//                cout << endl;
            }
        }
        if(t == 2){
            int l, r;
            cin >> l >> r;
            ll ans = 0;
            ff(mask,0,30){
                int kol = kveri(1,1,n,l,r,mask);
//                cout << "kol: " << kol << endl;
                ans += (kol % 2 == 1) * (1LL << mask);
            }
            cout << ans << endl;
        }
    }
    return 0;
}
/**

**/


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;

int main(){
    FAST
    int t=1;
    while(t--){
        int x; cin >> x;
        if(x>=0){
            cout << x;
        }
        else{
            cout << 0;
        }

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define rep(i,n) for(int i=0;i<(n);i++)
#define drep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    ll sum = 0;
    rep(i,N) sum += A[i]*B[i];
    cout << (sum? "No\n":"Yes\n");
}


/**
 *    author:  otera
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<array>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    vector<int> a(n), b(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
        sum += b[i] * 1LL;
    }
    vector<int> odd, even;
    rep(i, n) {
        if(i % 2 == 0) {
            even.push_back(a[i] - b[i]);
        } else {
            odd.push_back(a[i] - b[i]);
        }
    }
    ll ans = sum;
    sort(all(even));
    reverse(all(even));
    sort(all(odd));
    reverse(all(odd));
    rep(i, n / 2) {
        sum += even[i];
        sum += odd[i];
        chmax(ans, sum);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char str[200005];
int freq[26];
int main()
{
    scanf("%s", str);
    vector<int>vec, let;

    for(int i=0; str[i]; i++)
    {
        int x= str[i], cnt= 0;
        while(str[i] && str[i]==x)i++, cnt++;i--;
        vec.push_back(cnt);
        let.push_back(x-'a');
    }

    ll res= 0, c= 0;
    while(!vec.empty())
    {
        if(vec.back()>1)
        {
            res+= (c-freq[ let.back() ]);
            memset(freq, 0, sizeof freq);
            c+= vec.back();
            freq[ let.back() ]= c;
        }
        else c++, freq[ let.back() ]++;

        vec.pop_back();
        let.pop_back();
    }

    printf("%lld\n", res);

    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 998244353;

signed main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<pair<int, int> > p(m);
    rep(i,m) {
        int x,y;
        cin>>x>>y;
        x--; y--;
        p[i] = make_pair(x,y);
    }
    sort(p.begin(),p.end());
    vector<int> b(n,inf);
    rep(i,m) {
        int x = p[i].first;
        int y = p[i].second;
        b[y]=min(b[y],min(b[x], a[x]));
        // cout<< x<<" "<<y<<endl;
    }
    int ans = -inf;
    rep(i,n) {
        if(b[i]==inf)continue;
        ans = max(a[i]-b[i],ans);
        // cout<< b[i]<<endl;
    }
    cout<<ans<<endl;
   return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int N,M,K;
vector<vector<int>> d(17,vector<int>(17,1e9));
vector<vector<int>> dp(1<<17, vector<int>(17, 1e9));

int rec(int S,int v){
  if((S&(1<<v))==0) return 1e9;
  int &ret = dp[S][v];
  if(ret<5*1e8) return ret;
  rep(u,K){
    chmin(ret,rec(S^(1<<v),u)+d[u][v]);
  }
  return ret;
}

int main(){
  cin >> N >> M;
  vector<pair<int,int>> AB(M); rep(i,M) cin >> AB[i].first >> AB[i].second;
  cin >> K;
  vector<int> C(K);
  rep(i,K) cin >> C[i];
  rep(i,K) C[i]--;

  vector<vector<int>> G(N);
  rep(i,M){
    int a = AB[i].first-1;
    int b = AB[i].second-1;
    G[a].pb(b);
    G[b].pb(a);
  }

  const int inf = 1e9;

  rep(i,K){
    vector<int> D(N,-1);
    queue<int> q;
    q.push(C[i]); D[C[i]] = 0;
    while(!q.empty()){
      int now = q.front(); q.pop();
      rep(x,sz(G[now])){
        int nxt=G[now][x];
        if(D[nxt]>=0) continue;
        q.push(nxt);
        D[nxt] = D[now]+1;
      }
    }
    rep(j,K){
      if(D[C[j]]!=-1) chmin(d[i][j], D[C[j]]);
    }
  }

  rep(i,K) d[i][i] = 0;
  rep(k,K) rep(i,K) rep(j,K) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

  rep(i,K){
    int now=(1<<i);
    dp[now][i]=1;
  }
  int ans = 1e9;
  /*
  rep(i,K){
    chmin(ans, rec((1<<K)-1, i));
  }*/

  for(int bit=1;bit<(1<<K);bit++){
    rep(i,K){
      if(bit&(1<<i)){
        int bit2=bit^(1<<i);
        rep(j,K) if(bit2&(1<<j)) chmin(dp[bit][i], dp[bit2][j]+d[i][j]);
      }
    }
  }

  rep(i,K) chmin(ans, dp[(1<<K)-1][i]);
  if(ans>5*1e8){
    cout << -1 << endl;
  }
  else cout << ans << endl;

  return 0;
}