#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
template <class T1, class T2>
bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; }
template <class T1, class T2>
bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
void _co() { cout << '\n'; }
template <class Head, class... Tail>
void _co(Head&& head, Tail&&... tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) { cout << head; _co(forward<Tail>(tail)...); }
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); }
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t LINF = 1000000000000000001;
constexpr int64_t MOD = 1000000007;
constexpr int64_t MOD_N = 998244353;
constexpr long double EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n;
    cin >> n;
    rep(i, n) {
        co((i * 2) % n + 1, (i * 2 + 1) % n + 1);
    }

    return 0;
}

#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(1)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

ll GCD(ll a, ll b) {
    if(b == 0) return a;
    else return GCD(b, a%b);
}

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    LCIN(N);
    vl fib(92, 1);
    for(int i = 2; i < 92; i++) {
        fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
    }
    vl fibs(92, 1);
    ll memo = N;
    for(int i = 0; i < 92; i++) {
        int j = 91 - i;
        fibs.at(j) = N/fib.at(j);
        N %= fib.at(j);
    }
    vl fibsc(30, 1);
    for(int i = 0; i < 30; i++) {
        fibsc.at(i) = i;
    }
//    VECCOUT(fibsc);
//    VECCOUT(fibs);
    queue<int> ans;
    bool c = 0;
    int KKK = 1;
    for(int i = 1; i < 92 - KKK; i++) {
        int j = 91 - i;
        if(fibs.at(j) && c) {
            ans.push(2 - (i)%2);
        }
        if(c) {
            ans.push(4 - (i + 1)%2);
        }
        if(fibs.at(j) && !c) {
            ans.push(1);
            ans.push(2);
            c = 1;
        }
    }
    cout << ans.size() << endl;
    while(ans.size()) {
        ll tmp = ans.front();
        ll res = tmp;
        cout << res << endl;
        ans.pop();
    }

}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int a=0, i;
long long ans=0, n, s=1;
int main(){
cin>>n;
while(true){
  s*=10;
  a++;
  if(n>=s)
    ans+=(s-s/10)*((a-1)/3);
  else{
    ans+=(n-s/10+1)*((a-1)/3);
    break;
  }
}
cout<<ans<<endl;
}

// どこが間違っているか分からない時は,簡単なミス(型,スペル,入力or出力など)をしていたり問題文の見落としがあったりする. 一度落ち着いて頭をリセットしよう.
// 計算途中のオーバーフローに注意しよう

#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define PP(val, pre) cout<<fixed<<setprecision(pre)<<val<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll N, ans=0;
    ll first = 999;
    ll second = 999999;
    ll third = 999999999;
    ll fourth = 999999999999;
    ll fifth = 999999999999999;
    cin >> N;
    if(N>first){
        ans += N-first;
    }
    if(N>second){
        ans += N-second;
    }
    if(N>third){
        ans += N-third;
    }
    if(N>fourth){
        ans += N-fourth;
    }
    if(N>fifth){
        ans += N-fifth;
    }
    P(ans);
}


//#include<i_am_noob_orz>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcountll((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define jimmy_is_kind false
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;

//#define LOCAL
#ifdef LOCAL
#define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif

int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);}
int sub(int a,int b){return(a<b?a+mod-b:a-b);}
int po(int a,int b){
	if(b==0)return 1;
	if(b==1)return(a%mod);
	int tem=po(a,b/2);
	if(b&1)return(((tem*tem)%mod)*a)%mod;
	else return(tem*tem)%mod;
}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

signed main(){
	IOS();
	int n;
	cin>>n;
	int lg=__lg(n)+1;
	F(n){
		int x=(i+1)*2;
		if((x%n)==0)x=n;
		else x=(x%n);
		cout<<x<<" ";
		x=(i+1)*2+1;
		if((x%n)==0)x=n;
		else x=(x%n);
		cout<<x<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define SZ(v) ((int)(v).size())
using namespace std;
typedef long long ll;

const int MAXN = 1001;
int N;
int a[MAXN], b[MAXN];

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

	cin >> N;
	for (int i(1); i <= N; ++i)
		cout << 1 + (2 * i)%N << ' '<< 1 + (2 * i + 1) % N << '\n';
}


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

const int N = 2e5 + 5, mod = 1e9 + 7;
char s[N];
int a[N], k;
int add (int a, int b) {
	return ((a += b) >= mod) ? (a - mod) : a;
}
int dp[N][20], K;
int f (int l, int k) {
	if (~dp[l][k]) return dp[l][k];
	if (l == 0) return k == K;
	dp[l][k] = (ll)k * f(l - 1, k) % mod;
	if (k)
		dp[l][k] = add(dp[l][k], (ll)f(l - 1, k + 1) * (16 - k) % mod);
	return dp[l][k];
}
int main() {
	memset (dp, -1, sizeof (dp));
	cin >> (s + 1) >> K;
	int len = strlen(s + 1);
	for (int i = 1; i <= len; ++i) {
		if (isdigit(s[i])) a[i] = s[i] - '0';
		else a[i] = s[i] - 'A' + 10;
	}

	int ans = 0;
	for (int i = len; i >= 2; --i) {
		for (int j = 1; j < 16; ++j) ans += f (len - i, 1), ans %= mod;
		ans %= mod;
	}

//	cerr << ans << '\n';
	int st = 0;
	for (int i = 1; i <= len; ++i) {
		for (int j = ((i == 1) ? 1 : 0); j < a[i]; ++j) {
			int newst = st | (1 << j), cnt = __builtin_popcount(newst);
		//	cerr << len - i << " " << cnt << ":" << f(len - i, cnt) << '\n';
			ans = add(ans, f(len - i, cnt));
		}
		st |= (1 << a[i]);
	}
	if (__builtin_popcount(st) == K) ans = add(ans, 1);
	cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
#define maxn 2000010
using namespace std;
typedef long long LL;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int n,m,a[maxn],s[maxn<<2],c[maxn<<2];
void ins(int k,int l,int r,int p,int vl)
{
	if(l==r) return c[k]+=vl,s[k]=(c[k]?1:0),void(0);int mid=l+r>>1;
	p>mid?ins(k<<1|1,mid+1,r,p,vl):ins(k<<1,l,mid,p,vl),s[k]=s[k<<1]+s[k<<1|1];
}
int ask(int k,int l,int r)
{
	if(l==r) return l;int mid=l+r>>1;
	if(s[k<<1]==mid-l+1) return ask(k<<1|1,mid+1,r);
	else return ask(k<<1,l,mid);
}
signed main()
{
	int ans=0x7fffffff;
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read()+1;
	for(int i=1;i<=m;i++) ins(1,1,n+1,a[i],1);
	ans=min(ans,ask(1,1,n+1));
	for(int i=m+1;i<=n;i++) ins(1,1,n+1,a[i-m],-1),ins(1,1,n+1,a[i],1),ans=min(ans,ask(1,1,n+1));
	cout<<ans-1<<'\n';
	return 0;
}


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

int main(){
    int x;
    int k;
    cin >> x >> k;
    int num = x;
    for(int j = 0; j < k; ++j){
        int n = 0;
        vector<int> v;
        while(num != 0){
            v.push_back(num%10);
            num /= 10;
            n++;
        }
        sort(v.begin(), v.end());
        int ans =0;
        for(int i = 0; i < n; i++){
            ans += (v[n-1-i]-v[i])*pow(10,n-i-1);
        }
        num = ans;
    }
    cout << num << endl;
}

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

int inc(int n){

    string s = to_string(n);
    sort(s.begin(), s.end());

    int val = stoi(s);
    return val;
}

int dec(int n){

    string s = to_string(n);

    sort(s.begin(),s.end(), greater<char>());

    int val = stoi(s);
    return val;
}

int solve(int n){

    int x= inc(n);
    int y= dec(n);

    return y-x;
}

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

    ll n,k;
    cin>>n>>k;

    while(k){
        n= solve(n);
        k--;
    }

    cout<<n<<endl;

    return 0;
}


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

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

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";

int main(){
    //input
    int n,q,t,a,b;
    string s;
    cin >> n >> s >> q;
    //input-計算
    int flip = 0;//正常
    for(int i=0;i<q;i++){
        cin >> t >> a >> b;
        --a;--b;
        if(t==1){
            if(flip==0){//正常
                char s1 = s[a],s2 = s[b];
                s[b] = s1;s[a] = s2;
            }
            else{//反転
                if(a<n&&b<n){
                    char s1 = s[n+a],s2 = s[n+b];
                    s[n+b] = s1;s[n+a] = s2;
                }
                else if(a<n&&n<=b){
                    char s1 = s[n+a],s2 = s[b-n];
                    s[b-n] = s1;s[n+a] = s2;
                }
                else{
                    char s1 = s[a-n],s2 = s[b-n];
                    s[b-n] = s1;s[a-n] = s2;
                }
            }
        }
        else{
            if(flip==0)flip = 1;
            else flip = 0;
        }
    }
    if(flip)cout << s.substr(n,n) << s.substr(0,n) << endl;
    else COUT(s);
}

// for(int i = 0; i < n; i++) {cin >> a[i];}

#include <bits/stdc++.h>

using namespace std;

#define pb	push_back
#define mp	make_pair
#define gcd __gcd
#define F   first
#define S   second
#define pii pair<int,int>

using ll = long long;

bool isSubsequence(string s, string t) {
	int index = 0;
	if(s.length() == 0) {
		return true;
	}
	for(int i = 0; i < t.length(); i++) {
		if(s.at(index) == t.at(i)){
			index++;
		}
		if(index == s.length()) {
			return true;
		}
	}
	return false;
}

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

bool isInt(double n) {
	if(floor(n) == ceil(n)) {
		return true;
	}
	return false;
}

bool isPalindrome(string s) {
	int n = s.length();
	for(int i = 0; i < n/2; i++) {
		if(s.at(i) != s.at(n-i-1)) {
			return false;
		}
	}
	return true;
}

bool distinctDigits(int n) {
	string s = to_string(n);
	for(int i = 0; i < s.length(); i++) {
		for(int j = i+1; j < s.length(); j++) {
			if(s.at(i)==s.at(j)) {
				return false;
			}
		}
	}
	return true;
}

bool distinctDigits(string s) {
	for(int i = 0; i < s.length(); i++) {
		for(int j = i+1; j < s.length(); j++) {
			if(s.at(i)==s.at(j)) {
				return false;
			}
		}
	}
	return true;
}

int digitSum(int n) {
	int ans = 0;
	string s = to_string(n);
	for(int i = 0; i < s.length(); i++) {
		ans += stoi(s.substr(i, 1));
	}
	return ans;
}

int swapBits(int n, int p1, int p2) {
	int bit1 = (n >> p1) & 1;
	int bit2 = (n >> p2) & 1;

	int x = bit1 ^ bit2;
	x = (x << p1) | (x << p2);

	return n ^ x;
}

void display(vector<int> a) {
	for(auto element : a) {
		cout << element << ' ';
	}
	cout << endl;
}

void display(vector<ll> a) {
	for(auto element : a) {
		cout << element << ' ';
	}
	cout << endl;
}

void display(vector<string> a) {
	for(auto element : a) {
		cout << element << ' ';
	}
	cout << endl;
}

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int q;
	cin >> q;

	int flips = 0;
	for(int i = 0; i < q; i++) {
		int t, a, b;
		cin >> t >> a >> b;

		if(flips%2 == 1) {
			if(a > n) {
				a -= n;
			} else {
				a += n;
			}
			if(b > n) {
				b -= n;
			} else {
				b += n;
			}
		}

		if(t==1) {
			// cout << a << ' ' << b << endl;
			swap(s[a-1], s[b-1]);
		} else {
			flips++;
		}
		// cout << s << endl;
	}
	if(flips%2 == 1) {
		s = s.substr(n, n) + s.substr(0, n);
	}
	cout << s;
}

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

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

	solve();

	cout.flush();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define K 600001

int a[K], b[K], n, l;
int c[K], d[K];

vector<int> v;

int main() {
	scanf("%d%d", &n, &l);
	FOE(i, 1, n) scanf("%d", &a[i]);
	FOE(i, 1, n) scanf("%d", &b[i]);

	FOE(i, 1, n) {
		c[i] = a[i] - (i > 1 ? a[i - 1] : 0) - 1;
		d[i] = b[i] - (i > 1 ? b[i - 1] : 0) - 1;
	}

	c[n + 1] = l - a[n];
	d[n + 1] = l - b[n];

	int ptr = 1;
	LL tot = 0;
	LL ret = 0;

	while (ptr <= n + 1 && d[ptr] == 0) ptr++;

	FOE(i, 1, n + 1) {
		tot += c[i];
		if (c[i]) v.pb(i);

		if (tot > d[ptr]) {
			puts("-1");
			return 0;
		}

		if (ptr <= n + 1 && tot == d[ptr]) {
			int l = v[0];
			int r = v[v.size() - 1];

			if (l < ptr) ret += (ptr - l);
			if (ptr < r) ret += (r - ptr);

			ptr++;
			while (ptr <= n + 1 && d[ptr] == 0) ptr++;
			tot = 0;

			v.clear();
		}
	}

	if (v.size() >= 1) {
		puts("-1");
	} else {
		printf("%lld\n", ret);
	}
}

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
#include <utility>

using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,n,L;cin>>n>>L;
	llint ans=0;
	vector<int>A(n+2);
	vector<int>B(n+2);
	for(i=1;i<=n;i++){cin>>A[i];A[i]-=i;}
	for(i=1;i<=n;i++){cin>>B[i];B[i]-=i;}
	A[n+1]=L-n;B[n+1]=L-n;
	for(i=1;i<=n;i++){
		if(A[i]<B[i]){
			int bas=LBI(A,B[i]);
			if(A[bas]!=B[i]){cout<<-1<<endl;return 0;}
			if(B[i]==B[i+1]){ans++;}
			else{ans+=bas-i;}
		}
		if(A[i]>B[i]){
			int bas=UBI(A,B[i])-1;
			if(A[bas]!=B[i]){cout<<-1<<endl;return 0;}
			if(B[i]==B[i-1]){ans++;}
			else{ans+=i-bas;}
		}
		//cerr<<"ok";
	}
	cout<<ans<<endl;
	return 0;
}


#define ll long long
#define dd long double
#define pb push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define fo(i ,a, n) for(ll i =a ; i < n ; i++)
//#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)//traverse through a dataset
//#define sortx(x) sort(all(x))
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll,vector<ll>,greater<ll>>
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>
ll fact[200001] ;
ll inf=1e18;
ll z=1e9+7;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
dd pi = acos(-1) ;
ll pow(ll a ,ll b ){if(b == 0) return 1 ; ll c = pow(a , b/2) ; if(b%2 == 0) return (c*c) ; else return ((c*c)*a);}

using namespace std ;
const int N = 2e5+7;
const int M=1e6+7;
//vector<ll>adj[N];
//int mat[N][N];
//vector<bool>used(N,false);
//vector<ll>d(N,-1);
//vector<ll>p(N,-1);

bool cmp(ll a,ll b){
   return a>b;
}

struct S
{
    int m_n1;
    int m_n2;
    int m_n3;

    S(int n1, int n2, int n3) : m_n1(n1), m_n2(n2), m_n3(n3)
    {
    }

    bool operator<(const struct S& other) const
    {
        if(m_n1!=other.m_n1)
        return m_n1 < other.m_n1;
        else
        return m_n2 > other.m_n2;
    }
};

void solve(){
  ll n;
  cin>>n;
  ll votes[n][2];
  ll s[2]={0};
  vector<pair<ll,pair<ll,ll>>>v;
  fo(i,0,n){
    ll x,y;
    cin>>x>>y;
    votes[i][0]=x;
    votes[i][1]=y;
    s[1]+=x;
    v.pb({y+2*x,{x,y}});
  }
ll cnt=0;
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
 fo(i,0,n){
    if(s[0]>s[1]){
       break;
    }
    else{
      s[0]+=(v[i].S.F+v[i].S.S);
      s[1]-=v[i].S.F;

      cnt++;
    }
 }

 cout<<cnt<<endl;
}

int main()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
      ios_base::sync_with_stdio(false);
     cin.tie(NULL);

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

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<ll> a(n),b(n); rep(i,n) cin >> a[i] >> b[i];
  ll sum = 0;
  vector<pair<ll,int>> s(n);
  rep(i,n){
    ll k = 0;
    k = a[i]+b[i];
    sum += k;
    k += a[i];
    s[i] = make_pair(k,i);
  }
  sort(s.begin(),s.end());

  ll t = 0;
  int m = 0;
  rep(i,n){
    ll aa;
    ll ss = s[i].first-a[s[i].second];
    aa = ss-b[s[i].second];

    if(sum-ss <= t+aa) break;
    sum -= ss;
    t += aa;
    m++;
  }

  int ans = n-m;

  cout << ans << endl;

  return 0;
}


#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, m, a, b, c, u, v, p, q, k;

int main()
{
  ll t;
  t = 1;
  while(t--)
  {
    in3(a, b, c);
    cout<<21-a-b-c<<"\n";
  }
}

#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int main(){
	int x=-1;
	for(int T=read;T--;){
		int a=read,b=read,c=read;
		if(c>a&&(b<x||!~x))x=b;
	}cout<<x;
	return 0;
}


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

int main(void){
    int n,x;
    string s;
    cin>>n>>x>>s;
    rep(i,s.size()){
        if(s[i]=='o'){
            x++;
        }else if(x>0){
            x--;
        }else{
            x=0;
        }
    }
    cout<<x<<endl;
    return 0;
}

                                ///−In the name of God −///

//In mathematics, an unordered pair or pair set is a set of the form {a, b},
//i.e. a set having two elements a and b with no particular relation between them.
//In contrast, an ordered pair (a, b) has a as its first element and b as its second element.
//So, (a,b)!=(b,a) in ordered pair but it is in case of unordered pair.
#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   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   eb(x)   emplace_back(x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   MAX 1000000
#define   eps 1e-8
#define   nl  cout<<'\n'
#define   ump unordered_map
#define   mp  map
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
//Taking input by EOF
//while(scanf("%lld",&x)!=-1){ }
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
//S.order_of_key(x)[Give me the position of x]
//S.find_by_order(x)[Give me the x th element in set]
//pair can no te used as index in Unordered_map
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//Knight moves
ll dx[8]={-2,-2,2,2,-1,-1,1,1};
ll dy[8]={1,-1,1,-1,2,-2,2,-2};
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c = 0, d, e, f = 0, g, h, i, j = 0, k, m, n, o, p, s, t, v, w, x = 0, y, z, l, res = 0;
  ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = inf;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2, str3 = "", str4 = "";
  ll ide = 0, idx = 0, Q;
  ll xa, xy;

     scll(a);
     scll(b);
    cin>>str;

    for(i=0;i<str.length();i++)
    {
    	if(str[i]=='x'&&b>0)
    		b--;
    	else if(str[i]=='o')
    		b++;
    }

     cout<<b;

return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vpl = vc<pll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

int main() {
  ll n;
  cin >> n;
  ll res = (ld)(n)*1.08;
  if (res == 206) cout << "so-so" << endl;
  else if (res < 206) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(v,n) for(ll i=0;i<n;i++){ll var;cin>>var;v.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod = 1e9+7;
const ll inf = LLONG_MAX;
#define mod2 998244353
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; } cout << endl
#define con continue

bool prime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return 1;
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return 1;
}
bool isPerfectSquare(ll x1) {
  long double sr = sqrt(x1);
  return ((sr - floor(sr)) == 0);
}
bool isPowerOfTwo(ll n) {
    return n > 0 && !(n&(n-1));
}
bool subsequence_checker(string str1, string str2, ll m, ll n)
{
    if (m == 0) return 1;
    if (n == 0) return false;
    if (str1[m-1] == str2[n-1])
        return subsequence_checker(str1, str2, m-1, n-1);
    return subsequence_checker(str1, str2, m, n-1);
}
bool cmp(const pair<ll,ll> &a,  const pair<ll,ll> &b)
{
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff);
}
ll gcd(ll p, ll q){
if(p % q == 0)return q;
return gcd(q, p % q);
}
ll countDigit(ll n)
{
    return floor(log10(n) + 1);
}
ll power(ll a,ll n)
{
  if(n==0)
    return 1;
  if(n%2)
    return (a*power((a*a)%mod,n/2))%mod;
  return power((a*a)%mod,n/2);
}
ll fast_pow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p % 2 == 0) {
            a = (a * a) % mod;
            p /= 2;
        } else {
            res = (res * a) % mod;
            p--;
        }
    }
    return res;
}
ll setBitNumber(ll n)
{
    n |= n >> 1;
    n |= n >> 2;

    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n = n + 1;

    return (n >> 1);
}
ll ncr(ll n , ll row)
{
    if(n<row) return 0;
    if(row==1) return n;
    if(row==2) return (n*(n-1))/2;
    return (n*(n-1)*(n-2))/6;
}
ll countDivisors(ll n) {
    ll count =0 ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0)
            count++;
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0)
            count++;
    return count;
}
vector<ll> printDivisors(ll n){
    vector<ll> d ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0){
            d.push_back(i);
            //cout<<i<<" ";
        }
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0){
            d.push_back(n/i);
            //cout<<n/i<<" ";
        }
    return d;
}
///////////////////////////////////Lets Do It///////////////////////////////////

void solve()
{

    int n;
    cin>>n;

    int d = n*108;
    d /= 100;

    if(d<206)
    {
        cout<<"Yay!";
    }
    else if(d==206)
    {
        cout<<"so-so";
    }
    else{
        cout<<":(";
    }

}

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "row", stdin);
  freopen("output.txt", "w", stdout);
#endif

    ll t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }

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

    return 0;
}


#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<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
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 Per(i,sta,n) for(int i=n-1;i>=sta;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 long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<int mod>
struct ModInt {
    long long x;
    static constexpr int MOD = mod;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    explicit operator int() const {return x;}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    ModInt operator%(const ModInt &p) const { return ModInt(0); }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt power(long long n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1)
            ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    ModInt power(const ModInt p) const{
        return ((ModInt)x).power(p.x);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

using modint = ModInt<mod>;

int n,k;
modint dp[3010][3010];
bool visited[3010][3010];

modint get_dp(int i,int j){
    //cout << i << " " << j << endl;
    if(i<j) return 0;
    if(min(i,j)<0) return 0;
    if(visited[i][j]) return dp[i][j];
    visited[i][j]=true;
    dp[i][j]=get_dp(i-1,j-1)+get_dp(i,2*j);
    return dp[i][j];
}

void solve(){
    cin >> n >> k;
    visited[0][0]=true;
    dp[0][0]=1;
    cout << get_dp(n,k) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define lli long long int
#define br cout<<"\n";
#define plli pair<lli,lli>
#define vlli vector<lli>
#define vplli vector<plli>
#define pqlli priority_queue <lli>
#define pqplli priority_queue <plli>
#define mplli map<lli,lli>
#define pb push_back
#define mp make_pair
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define arr(a,n) lli a[n]; fr(i,n){ cin>>a[i]; }
#define arr1(a,n) lli a[n+5]; fr1(i,n){ cin>>a[i]; }
#define print(a,n) fr(i,n) {cout<<a[i]<<" ";} br
#define print1(a,n) fr1(i,n) {cout<<a[i]<<" ";} br
#define printv(vec) for(lli qq=0;qq<vec.size();qq++) {cout<<vec[qq]<<" ";}
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define MAXN 100001
#define mset(a) memset(a,0,sizeof a);
#define init(a) memset(a,-1,sizeof a);
#define MAXNN 200005
#define mod 1000000007
using namespace std;
const lli inf = 1e10;
int main()
{
    ios_base::sync_with_stdio(false);
    lli i,j,n,k,m,t,d,l,w,r,x,y;
    cin>>x>>y>>l>>r;
  	n=(x*r)-(l*y);
  cout<<n<<'\n';

   return 0;
}


#include <bits/stdc++.h>

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

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

// BIT
// Binary Indexed Tree
// https://scrapbox.io/pocala-kyopro/%E8%BB%A2%E5%80%92%E6%95%B0
// 1-index
struct BIT {
private:
  vector<int> bit;
  int N;

public:
  BIT(int size) {
    N = size;
    bit.resize(N + 1);
  }

  // 一点更新
  void add(int a, int w) {
    for (int x = a; x <= N; x += x & -x) bit[x] += w;
  }

  // 1~Nまでの和を求める。
  int sum(int a) {
    int ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
};

void solve()
{
  ll n;
  cin >> n;
  rep(i, n)
  {
    cout << i * 2 % n + 1 << " " << (i * 2 + 1) % n + 1 << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const long double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const ll INF = 1e9;
ll gcd(ll a, ll b) {if(a%b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

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

  ll a = 1;
  for(ll i = 1; i < 100; i++) {
    a *= 3;
    if(a > 1e18) break;
    ll b = 1;
    for(ll j = 1; j < 100; j++) {
      if(b*5 > 1e18) break;
      b *= 5;
      if(b > n-a || b > 1e18) break;
      if(b == n-a) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
    if(a*3 > 1e18) break;
  }
  cout << -1 << endl;
}


/*/ Author : Abhishek Chauhan /*/

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

// a+b = a^b + 2*(a&b)
// According to Fermat's little theorem, (a^b)%mod = ((a^(b%(mod - 1)))%mod) if mod is a prime number and not the other way round.
// whenever using a comparator return true only if a<b
// make it forward first if it doesnt work do the reverse
// vector a = ax + ay b = bx + by then dot porduct is |a||b|cos@ //and also for eas you can use (ax*bx)+(ay*by);

#define rep(i,n)             for(int i=0;i<n;i++)
#define int                  long long
#define pb                   push_back
#define mp                   make_pair
#define all(x)               x.begin(),x.end()
#define mod                  1000000007
#define bpop(x)              __builtin_popcountll((x))
#define fastio               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl                 '\n'

template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

template<class T>
T power(T x, T y){T res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
template<class T>
T powermod(T x, T y, T p){T res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}

const int N = 20;
vector<int>g[N];
int vis[N],col[N];
vector<int>order;
void get(int node){
  vis[node] = 1;
  order.pb(node);
  for(auto x:g[node]){
    if(vis[x]==0){
      get(x);
    }
  }
}

int recur(int i){
  if(i>=order.size()){
    return 1;
  }
  int res = 0;
  vis[order[i]] = 1;
  vector<int>can(4,1);
  for(auto x:g[order[i]]){
    if(col[x]!=0){
      can[col[x]] = 0;
    }
  }
  for(int c=1;c<4;c++){
    if(can[c]){
      col[order[i]] = c;
      res+=recur(i+1);
      col[order[i]] = 0;
    }
  }
  return res;
}

void snow(){

   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++){
    vis[i] = 0;
    col[i] = 0;
   }
   for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;a--;b--;
    g[a].pb(b);
    g[b].pb(a);
   }
   int ans = 1;
   for(int i=0;i<n;i++){
    if(!vis[i]){
     order.clear();
     get(i);
     col[order[0]] = 1;
     vis[order[0]] = 1;
     if(order.size()==1){
      ans = ans*3;
     }
     else{
      ans=ans*3*recur(1);
     }
    }
   }
   cout<<ans<<endl;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fastio;
    int _;
    _=1;
    for(int i=1;i<=_;i++){
     // cout<<"Case #"<<i<<": ";
        snow();
    }
    return 0;
}

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

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define yes(x) ((x) ? "yes" : "no")
#define Yes(x) ((x) ? "Yes" : "No")

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double_t;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 N, M;
    cin >> N >> M;
    vector<p64> conds(M);
    for (auto& [ A, B ] : conds) cin >> A >> B;

    i64 K;
    cin >> K;
    vector<p64> poss(K);
    for (auto& [ C, D ] : poss) cin >> C >> D;

    bitset<128> bs;
    i64 ans = 0;
    for (i64 i = 0; i < (1 << K); i++) {
        i64 can = 0;
        for (i64 j = 0; j < K; j++) {
            auto& [ C, D ] = poss[j];
            bs[(i >> j) & 1 ? C : D] = 1;
        }
        for (i64 j = 0; j < M; j++) {
            auto& [ A, B ] = conds[j];
            can += bs[A] && bs[B];
        }
        ans = max(ans, can);
        bs.reset();
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


// Problem:
// 			D - Orientation
//
//
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

const int N = 105,M = N * N;
int g[N][N],a[M],b[M],c[N];
bool st[N];
int n,m;

void dfs(int u)
{
	st[u] = 1;
	forn(i,1,n)
	{
		if(!g[u][i])	continue;
		g[i][u] = 0;
		if(!st[i])	dfs(i);
	}
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
    forn(i,1,m)	cin >> a[i] >> b[i];
    forn(i,1,n)	cin >> c[i];

    vector<string> ans(m + 1,"");
    forn(i,1,m)
    {
    	if(c[a[i]] > c[b[i]])	ans[i] = "->";
    	else if(c[a[i]] < c[b[i]])	ans[i] = "<-";
    	else
    	{
    		g[a[i]][b[i]] = 1;
    		g[b[i]][a[i]] = 1;
    	}
    }

	forn(i,1,n)	if(!st[i])    dfs(i);
	forn(i,1,m)
	{
		if(ans[i] != "")	continue;
		if(g[a[i]][b[i]])	ans[i] = "->";
		else				ans[i] = "<-";
	}

	forn(i,1,m)	cout << ans[i] << endl;
    return 0;
}

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

ll n,m,k,x,y,p=1e9+7,invm;

void mult(vector<vector<ll>>& a, vector<vector<ll>>& b){
	vector<vector<ll>> c(n,vector<ll>(n));
	forn(i,0,n)
		forn(j,0,n)
			forn(k,0,n)
				c[i][j]+=a[i][k]*b[k][j], c[i][j]%=p;
	swap(a,c);
}

vector<vector<ll>> power(vector<vector<ll>>& F, int N){
	vector<vector<ll>> res(n,vector<ll>(n));
	forn(i,0,n)
		res[i][i]=1;
	while(N){
		if(N%2)
			mult(res,F);
		mult(F,F);
		N/=2;
	}
	return res;
}

int inv(ll m){
	ll res=1, n=p-2;
	while(n){
		if(n%2)
			res*=m, res%=p;
		m*=m, m%=p;
		n/=2;
	}
	return res;
}

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

    cin>>n>>m>>k;
    invm = inv(2ll*m);
    vector<vector<ll>> adj(n,vector<ll>(n)), a(n,vector<ll>(1));
    vector<int> deg(n);
    forn(i,0,n)
    	cin>>a[i][0];
    forn(_,0,m){
    	cin>>x>>y, x--, y--;
    	adj[x][y]=adj[y][x]=invm, deg[x]++, deg[y]++;
    }
    forn(i,0,n)
    	adj[i][i]=(p*p+1-deg[i]*invm)%p;
    adj = power(adj,k);
    mult(adj,a);
    forn(i,0,n)
    	cout<<adj[i][0]<<'\n';

    return 0;
}


// Problem: F - Rook on Grid
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 186)
// URL: https://atcoder.jp/contests/abc186/tasks/abc186_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define F(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()

using ld = long double;
using vi = vector <int>;
using mi = map <int, int>;
using pii = pair <int, int>;

const int N = 200005;
const int MOD = 1e9 + 7;

#define show(arr) { for (auto x: arr) cout << x << " "; cout << '\n'; }
#define show_(arr, n) F(i, n) show(arr[i])
/*
~Segment tree~
use v=1, tl=0, tr=n-1
*/
int t[4*N];
int operation(int a,int b) {return a+b;}

void build(vi &a, int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = operation(t[v*2],t[v*2+1]);
    }
}
int sum(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return operation(sum(v*2, tl, tm, l, min(r, tm))
           ,sum(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = operation(t[v*2],t[v*2+1]);
    }
}
vi rr[N], cc[N];
int r[N], c[N];
void solve() {
	int rows,colmn,k, ans = 0; cin>>rows>>colmn>>k;
	vi a(rows,0);
	F(i,N){
		r[i] = colmn;
		c[i] = rows;
	}
   	F(i, k){
   		int x,y; cin >> x >> y; x--; y--;
   		r[x] = min(r[x],y);
   		c[y] = min(c[y],x);
   		rr[x].pb(y);
   		cc[y].pb(x);
   	}
   	bool ok=1;
	F(i,rows){
		if(r[i]==0) ok=0;
		if(ok)
			ans += r[i];
		else
			a[i]=1;
	}
	build(a, 1, 0, rows-1);
	F(i,colmn){
		int bound = c[i];
		if(bound == 0) break;
		ans += sum(1, 0, rows-1,0,bound-1);
		for(int x: cc[i]) update(1, 0, rows-1,x,1);
	}
   	cout << ans << '\n';
}
int32_t main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);

   int32_t t=1;
   // cin >> t;
   while (t--) solve();

   return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
void update(int bit[],int n,int x, int val)
{
      for(; x <= n; x += x&-x)
        bit[x] += val;
}
int sum1(int bit[],int n)
{
     int sum = 0; int x=n;
     for(; x > 0; x -= x&-x)
        sum += bit[x];
     return sum;
}
int main()
{
    int h,w,m; cin>>h>>w>>m;
    map<int,int>mp,mp1;
    map<pair<int,int>,int>mp3;
    map<int,vector<int>>v;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(mp[x]==0) mp[x]=y;
        else
        mp[x]=min(mp[x],y);
        if(mp1[y]==0) mp1[y]=x;
        else
        mp1[y]=min(mp1[y],x);
        mp3[{x,y}]=1;
        v[y].push_back(x);
    }
    ll cnt=0;
    for(int i=1;i<=w;i++)
    {
        if(mp3[{1,i}]==0){

            if(mp1[i]==0) cnt+=h;
            else cnt+=mp1[i]-1;
            //cout<<cnt<<endl;
        }
        else break;
    }
    //cout<<cnt<<endl;
    int bit[h+1]={0}; bool has[h+1]={0}; bool flag=0;
    if(mp1[1]!=0)
    for(int i=mp1[1];i<=h;i++) update(bit,h,i,1),has[i]=1;
    for(int i=2;i<=w;i++)
    {
                for(auto it: v[i])
                {
                    if(has[it]==0){
                        update(bit,h,it,1);
                        has[it]=1;
                    }
                }
                if(flag==0){
                    if(mp1[i]!=0)
                    cnt+=h-(sum1(bit,h)-sum1(bit,mp1[i]-1))-(mp1[i]-1);
                }
                else
                    cnt+=h-sum1(bit,h);
                if(mp3[{1,i}]>=1) flag=1;

    }
    cout<<cnt<<endl;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m);
    vector<ll> h(n),w(m);
    in(h,w);
    vector<ll> oddsum(1,0),evensum(1,0),odd(1,0),even(1,0);
    sort(all(h));
    for(int i=0;i<n;i++){
        if(i%2==0){
            odd.push_back(h[i]);
            oddsum.push_back(oddsum[oddsum.size()-1]+h[i]);
        }else{
            even.push_back(h[i]);
            evensum.push_back(evensum[evensum.size()-1]+h[i]);
        }
    }
    int insert_index,oindex,eindex;
    ll fsum,bsum,ans=INF2;
    for(int i=0;i<m;i++){
        insert_index=(int)(upper_bound(all(h),w[i])-h.begin());
        oindex=(int)(upper_bound(all(odd),w[i])-odd.begin())-1;
        eindex=(int)(upper_bound(all(even),w[i])-even.begin())-1;
        fsum=oddsum[oindex];
        bsum=evensum[eindex];
        fsum+=evensum[evensum.size()-1]-evensum[eindex];
        bsum+=oddsum[oddsum.size()-1]-oddsum[oindex];
        if(insert_index%2==1){
            bsum+=w[i];
        }else{
            fsum+=w[i];
        }
        chmin(ans,bsum-fsum);
    }
    out(ans);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;

#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;

const ll MAXN = 2e5 + 100;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353;

bool used[MAXN];
string s;
ll fans, k, fact[MAXN], inv[MAXN], cval = 0;

inline ll poww(ll a, ll b, ll m = MOD) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

inline int F(char c) {
	if (c <= '9' && c >= '0') return int(c - '0');
	return int(c - 'A') + 10;
}

inline ll C(int r, int n) {
	if (r > n || r < 0) return 0;
	return fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}
inline int Check() {
	memset(used, false, sizeof used);
	for (char c : s) used[F(c)] = true;
	int ans = 0;
	for (int i = 0; i < 16; i++) if (used[i]) ans++;
	return ans;
}

inline ll solve(ll k) {
	memset(used, false, sizeof used);
	ll n = s.size(), ans = 0;
	for (int d = 1; d < n; d++) ans += 15 * C(k - 1, 15) % MOD * poww(k, d - 1, MOD) % MOD;

	ans += (F(s.front()) - 1) * C(k - 1, 15) % MOD * poww(k, n - 1, MOD) % MOD;
	ans %= MOD;
	used[F(s.front())] = true;
	for (int i = 1; i < n; i++) {
		char c = s[i];
		ll P2 = 0, P = 0;
		for (int j = 0; j < 16; j++) {
			if (used[j]) {
				P++;
				if (j < F(c)) P2++;
			}
		}

		ans += P2 * C(k - P, 16 - P) % MOD * poww(k, n - i - 1) % MOD;
		ans += (F(c) - P2) * C(k - P - 1, 16 - P - 1) % MOD * poww(k, n - i - 1) % MOD;
		ans %= MOD;
		used[F(c)] = true;
	}

	ans += C(k - cval, 16 - cval);
	return ans % MOD;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= 100; i++) fact[i] = i * fact[i - 1] % MOD, inv[i] = poww(fact[i], MOD - 2, MOD);
	cin >> s >> k;

	cval = Check();
	for (int i = 1; i <= k; i++) {
		ll tans = solve(i) * C(k - i, 16 - i) % MOD;
		if ((k - i) & 1) tans = -tans;
		fans += tans;
		fans += 2 * MOD;
		fans %= MOD;
	}

	cout << fans << endl;
	return 0;
}


#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
llong N;
int main() {
	cin >> N;
	llong zero = 0;
	llong ANS = 0;
	ANS += max(N - 999, zero);
	ANS += max(N - 999999, zero);
	ANS += max(N - 999999999, zero);
	ANS += max(N - 999999999999, zero);
	ANS += max(N - 999999999999999, zero);

	cout << ANS << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;
int main() {
    ll n;
    cin >> n;
    ll ans = 0, l = 1, r = 10, num = 0;
    for (int i = 0;; i++) {
        if (r <= n) ans += num * (r - l);
        if (l <= n && n < r) {
            ans += num * (n - l + 1);
            break;
        }
        if (i % 3 == 2) num++;
        l *= 10;
        r *= 10;
    }
    cout << ans << endl;
    return 0;
}