#include<bits/stdc++.h>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define ff first
#define ss second
#define tc int t;cin>>t;while(t--)
#define FILE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define pb push_back
#define all(x) x.begin(),x.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x
const int mod = 1000000007;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;

const int INF = 0x3f3f3f3f3f3f3f3f;

const int N=1e5+5;
#define out(x) cout<<x<<"\n"
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define mod2 998244353

// template<typename T>
// using min_pq=priority_queue<T, std::vector<T>, greater<T>>;
#define pii pair<int,int>

int add(int x,int y,int m=mod){
  return (x%m + y%m)%m;
}
int sub(int x,int y,int m=mod){
  return (x%m - y%m +m)%m;
}
int mul(int x,int y,int m=mod){
  return ((x%m)*(y%m))%m;
}

int n;
int a[N];
int dp[N][2];
int dp1[N][2];

int power(int a, int b, int m = mod)
{
  long long ans = 1;
  while (b > 0)
  {
    if (b & 1LL)
    {
      ans = (ans * a) % m;
    }
    a = (a * a) % m;
    b = (b >> 1LL);
  }
  return ans;
}

int f2(int i,int last){
  if(i==n-1)
    return dp1[i][last]=dp1[i][last^1]=1;
  int &ans=dp1[i][last];
  if(ans!=-1)
    return ans;
  ans=0;
  if(last==0){
    ans=f2(i+1,1)%mod;
  }else{
    ans=add(f2(i+1,0),f2(i+1,1));
  }
  return ans;
}

int f(int i,int last){
  //f(i) gives the required sum from i...n
  if(i==n){
    return 0;
  }

  if(dp[i][last]!=-1)
    return dp[i][last];

  //two options
  int ans=0;
  int num=dp1[i][last];
  // num=power(2,num);
  if(last==0){
    //negative
    ans=sub(f(i+1,1),mul(num,a[i]));

  }else{

    ans=add(f(i+1,0),f(i+1,1));
    ans=add(ans,mul(num,a[i]));
  }
  // deb(num);
  // deb(ans);
  return dp[i][last]=ans;

}

inline void solve(){
  // int n;
  cin>>n;
  fr(i,n){
    cin>>a[i];
  }
  memset(dp,-1,sizeof(dp));
  memset(dp1,-1,sizeof(dp1));
  f2(0,1);
  int ans=0;
  ans=f(0,1);
  // deb(dp[2][0]);
  out(ans);
}

inline void solve2(){
  int n;
  cin>>n;
  out(n);
}

int32_t main() {
  fio;

  int t=1;
  // cin>>t;

  fr(j,t){
    // cout<<"Case #"<<j+1<<": ";
    solve();
  }
  printclock;
  return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

const ll p = 1e9 + 7;

ll a[ 100010 ];
ll f[ 100010 ][ 2 ];
ll g[ 100010 ][ 2 ];

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	int n;
	cin >> n;
	for( int i = 1; i <= n; ++i )
		cin >> a[ i ];
	f[ 1 ][ 0 ] = a[ 1 ];
	g[ 1 ][ 0 ] = 1;
	for( int i = 1; i < n; ++i ) {
		if( f[ i ][ 0 ] != MAX_INF_VAL_LL ) {
			if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 0 ] = f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 0 ] += f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 0 ] ) % p;
			if( f[ i + 1 ][ 1 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 1 ] = f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 1 ] += f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 1 ] = ( g[ i + 1 ][ 1 ] + g[ i ][ 0 ] ) % p;
		}
		if( f[ i ][ 1 ] != MAX_INF_VAL_LL ) {
			if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL )
				f[ i + 1 ][ 0 ] = f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p;
			else
				f[ i + 1 ][ 0 ] += f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p;
			g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 1 ] ) % p;
		}
		if( f[ i + 1 ][ 0 ] != MAX_INF_VAL_LL )
			f[ i + 1 ][ 0 ] = ( f[ i + 1 ][ 0 ] % p + p ) % p;
		if( f[ i + 1 ][ 1 ] != MAX_INF_VAL_LL )
			f[ i + 1 ][ 1 ] = ( f[ i + 1 ][ 1 ] % p + p ) % p;
	}
	cout << ( f[ n ][ 0 ] + f[ n ][ 1 ] ) % p;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#include <map>
#include <vector>
#include <cstdio>
#include <climits>
#define white 0
#define gray 1
#define black 2
#define LIMIT (1<<30)
#define MOD 1000000007
//#define MOD 998244353
#define ll long long
#define str string
using namespace std;

//const ll INF = LLONG_MAX;
//cout << fixed << setprecision(10) << ans << endl;
//pair<ll, ll> vec[4] = {make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0), make_pair(0, -1)};

char match(char x, char y){
    if(x == y) return x;
    if(x == 'R' && y == 'S') return 'R';
    if(x == 'R' && y == 'P') return 'P';
    if(y == 'R' && x == 'S') return 'R';
    if(y == 'R' && x == 'P') return 'P';
    return 'S';
}

int main(){
    int n, k;
    str s;
    cin >> n >> k >> s;

    for(int i=0; i<k; i++){
        if(s.length() % 2 != 0) s += s;
        str memo = "";
        for(ll i=0; i<s.length(); i+=2){
            memo += match(s[i], s[i + 1]);
        }
        s = memo;
    }

    cout << s[0] << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int sz = 1e5+1;
const int md = 1e9+7;

int A[sz];
int B[sz];

// int n;

void solve(){
	string a,b;cin>>a>>b;
	int p=0,q=0;
	for(auto c:a)
		p += (int)(c-'0');

	for(auto c:b)
		q += (int)(c-'0');

	p = max(p,q);
	cout<<p<<endl;
	return;
}

int32_t main()
{
	IOS;
	// int t;cin>>t;
	// while(t--)
		solve();
	return 0;
}

/**
*    author:  tomo0608
*    created: 18.02.2021 21:47:19
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

// Primality test
class Prime {
    public:
    const int N;
    vector<int> min_prime;
    vector<int> primes;
    Prime(int size): N(size), min_prime(N+1){
        rep(i,N+1)min_prime[i] = i;
        min_prime[0] = -1;
        min_prime[1] = -1;
        for(int i = 2;i<=N;i++){
            if(min_prime[i]!=i)continue;
            primes.push_back(i);
            int tmp = 2*i;
            while(tmp <= N){
                if(min_prime[tmp]==tmp)min_prime[tmp] = i;
                tmp += i;
            }
        }
    }
    bool check(int x){ return min_prime[x] == x;}
};

void solve(){
    ll n,x;cin >> n >> x;
    V<ll> a(n);cin >> a;
    map<pll, ll> memo;
    auto dp = [&](auto &&dp, ll now, ll X)->ll{
        if(now == n-1)return 1;
        if(memo.count({now, X}))return memo[{now, X}];
        ll nmax = a[now+1]/a[now];
        memo[{now, X}] = dp(dp, now+1, X/nmax) + (X%nmax != 0)*dp(dp, now+1, X/nmax + 1);
        return memo[{now, X}];
    };
    cout << dp(dp, 0, x) << endl;
    //cout << memo << endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    constexpr int Tmax = 1000;
    vv<bool> dp = vvec(N + 1, N * Tmax + 1, false);
    dp[0][0] = true;
    rep(i, N) {
        rep(t, 0, Tmax * i + 1) {
            if (dp[i][t]) {
                dp[i + 1][t] = true;
                dp[i + 1][t + T[i]] = true;
            }
        }
    }

    int tsum = accumulate(all(T), 0);

    int ans = INF;
    rep(t, N * Tmax + 1) {
        if (dp[N][t]) {
            ans = min(ans, max(t, tsum - t));
        }
    }
    write(ans);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define mod 1000000007

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

ll ncr(ll n,ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
	{
        for (j = 0; j <= min(i, k); j++)
		{
            if (j == 0 || j == i)
                C[i][j] = 1;
            else
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
    return C[n][k];
}

ll power(ll x, unsigned long long int y)
{
    if(y == 0)
        return 1;
    ll p = power(x, y / 2) % mod;
    p = (p * p) % mod;

    return (y % 2 == 0) ? p : (x * p) % mod;
}

ll modInverse(ll a)
{
    ll g = gcd(a, mod);
    if (g != 1)
        return -1;
    else
    {
        // If a and m are relatively prime, then modulo
        // inverse is a^(m-2) mode m
        return power(a, mod - 2);
    }
}

ll findMin(ll arr[], ll n)
{
    // Calculate sum of all elements
    ll sum = 0;
    for (ll i = 0; i < n; i++)
        sum += arr[i];

    bool dp[n+1][sum+1];

    for (ll i = 0; i <= n; i++)
        dp[i][0] = true;

    for (ll i = 1; i <= sum; i++)
        dp[0][i] = false;

    for (ll i=1; i<=n; i++)
    {
        for (ll j=1; j<=sum; j++)
        {

            dp[i][j] = dp[i-1][j];

            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }

    ll diff = INT_MAX;

    for (ll j=sum/2; j>=0; j--)
    {
        // Find the
        if (dp[n][j] == true)
        {
            return sum-j;
        }
    }
    return diff;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    ll t[101];
    for(ll i=0;i<n;i++)
    {
        cin>>t[i];
    }
    cout<<findMin(t,n)<<endl;
}


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

int main() {
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='6') s[i]='9';
		else if(s[i]=='9') s[i]='6';
	}
	cout<<s<<"\n";
	return 0;
}

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long t{1}, f{1};
    for(unsigned long i{0}; i < N; ++i)if([]{string s;cin >> s;return s;}()[0] == 'O'){
        (t *= 2) += f;
    }else{
        (f *= 2) += t;
    }
    cout << t << endl;
    return 0;
}


#include "bits/stdc++.h"
#include <random>
#include <chrono>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;--i)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
using namespace std; typedef unsigned long long _ulong; typedef int lint; typedef long double ld; typedef pair<lint, lint> plint; typedef pair<ld, ld> pld;
struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
template<class T> auto add = [](T a, T b) -> T { return a + b; };
template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); };
template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); };
template<class T> using V = vector<T>;
using Vl = V<lint>; using VVl = V<Vl>;
template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) {
	for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : "");
	return os;
}
template< typename T >istream& operator>>(istream& is, vector< T >& v) {
	for (T& in : v) is >> in;
	return is;
}
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; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
lint e_dist(plint a, plint b) { return abs(a.first - b.first) * abs(a.first - b.first) + abs(a.second - b.second) * abs(a.second - b.second); }
lint m_dist(plint a, plint b) { return abs(a.first - b.first) + abs(a.second - b.second); }
bool check_overflow(lint a, lint b, lint limit) { return a > limit / b; } // a * b > c => true
void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); }
const lint MOD1000000007 = 1000000007, MOD998244353 = 998244353, INF = 5e18;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
bool YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; }
struct Edge {
	lint from, to;
	lint cost;
	Edge() {

	}
	Edge(lint u, lint v, lint c) {
		cost = c;
		from = u;
		to = v;
	}
	bool operator<(const Edge& e) const {
		return cost < e.cost;
	}
};
struct WeightedEdge {
	lint to;
	lint cost;
	WeightedEdge(lint v, lint c = 1) {
		to = v;
		cost = c;
	}
	bool operator<(const WeightedEdge& e) const {
		return cost < e.cost;
	}
};
using WeightedGraph = V<V<WeightedEdge>>;
typedef pair<plint, lint> tlint;
typedef pair<plint, plint> qlint;
typedef pair<char, lint> valchar;

lint H, W, X, Y;
int main() {
	cin >> H >> W >> X >> Y; X--; Y--;
	V<string> arr(H);
	cin >> arr;
	lint ans = 1;
	REP(i, 4) {
		lint curr_x = X, curr_y = Y;
		lint nx = curr_x + dx[i], ny = curr_y + dy[i];
		while (nx >= 0 && nx < H && ny >= 0 && ny < W && arr[nx][ny] == '.') {
			ans++;
			nx = nx + dx[i], ny = ny + dy[i];
		}
	}
	cout << ans << endk;
}

#include <iostream>
#include <string>
#include <algorithm>

#define MAX_H (100)
#define MAX_W (100)
char map[MAX_H][MAX_W];

int main(void) {
  // input
  int H, W, X, Y;
  std::cin >> H >> W >> X >> Y;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      std::cin >> map[i][j];
    }
  }

  // process
  int res_cnt = 1;
  int add_x[4] = { 0,  0, -1,  1};
  int add_y[4] = {-1,  1,  0,  0};
  X -= 1;
  Y -= 1;
  for (int k = 0; k < 4; k++) {
    int xi = add_x[k];
    int yi = add_y[k];
    while (true) {
      if ((X+xi < 0) || (X+xi >= H) || (Y+yi < 0) || (Y+yi >= W)) {
        break;
      } else if (map[X+xi][Y+yi] == '#') {
        break;
      }
      xi += add_x[k];
      yi += add_y[k];
      res_cnt++;
    }
  }

  // output
  std::cout << res_cnt;

  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i <= 8; i++)
    {
        if (s[i] == 'Z' and s[i + 1] == 'O' and s[i + 2] == 'N' and s[i + 3] == 'e')
        {
            count++;
        }
    }
    cout << count;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST ios::sync_with_stdio(false); cin.tie(0),cout.tie(0);
//(a/b)%m =((a%m)*pow(b,m-2)%m)%m

void solve(){
    int n;
    cin>>n;
    cout<<(100 - (n%100))<<"\n";
    return;
}

int main(){
    FAST
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
//const int mod = 998244353;

vector<vector<int>> to;
vector<int> used, col, vs;
ll now;

void dfs(int v){
    used[v] = 1;
    vs.push_back(v);
    for(int u : to[v]){
        if(used[u]) continue;
        dfs(u);
    }
}

void dfs2(int i){
    if(i == vs.size()){
        now++;
        return;
    }
    int v = vs[i];
    rep(c, 0, 3){
        col[v] = c;
        bool flag = 0;
        for(int u : to[v]){
            if(col[u] == c){
                flag = 1;
            }
        }
        if(flag) continue;
        dfs2(i+1);
    }
    col[v] = -1;
}

int main()
{
    int n, m;
    cin >> n >> m;
    to = vector<vector<int>> (n);
    used = vector<int> (n);
    col = vector<int> (n, -1);
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ll ans = 1;
    rep(v, 0, n){
        if(used[v]) continue;
        vs = vector<int> ();
        dfs(v);
        col[vs[0]] = 0;
        now = 0;
        dfs2(1);
        ans *= 3*now;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int point = x;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == 'x' and point!=0) point--;
        if(s[i] == 'o') point++;
    }
    cout << point << endl;

    return 0;
}


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

int main() {
  cin.sync_with_stdio(false), cin.tie(nullptr);

  int n;
  cin >> n;

  int ans = 0;

  for (int i = 1; i <= n; i++) {
    bool ok = true;
    for (int x = i; x > 0; x /= 10) {
      if (x % 10 == 7) {
        ok = false;
      }
    }
    for (int x = i; x > 0; x /= 8) {
      if (x % 8 == 7) {
        ok = false;
      }
    }
    ans += (ok ? 1 : 0);
  }

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

#include <iostream>
#include <cstdio>
#include <new>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

//最小値を取り出す関数
template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
                a = b;
                return true;
        }
        return false;
}
//最大値を取り出す関数
template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
                a = b;
                return true;
        }
        return false;
}

int main() {
        ll N;

        cin >> N;

        ll sum=0;
        string S;
        ll size;

        ll owari;

        ll z;
        string S_n;
        string S_n_h;
        ll k=0;
        ll amari;

        for(ll i=1; i<=N; i++) {
                k=0;

                owari=0;
                z=i;

                S=to_string(z);
                size=S.size();//文字列Sの長さを整数型で取得

                //まずは10進法で7を含むか確認
                for(ll j=0; j<=size-1; j++) {
                        if(S[j]=='7') {
                                owari=1;
                                sum +=1;
                                //cout << "aaa " <<  i  << endl;
                                break;
                        }
                }

                if(owari==0) {
                        //7進数に変換
                        while(z>7) {
                                amari=z%8;
                                S_n_h=to_string(amari);

                                if(k==0) {
                                        S_n=S_n_h;

                                }else{
                                        S_n_h += S_n;
                                        S_n=S_n_h;
                                }
                                k +=1;

                                z = z/8;
                        }
                        S_n_h=to_string(z%8);
                        if(k==0) {
                                S_n=S_n_h;
                        }else{
                                S_n_h += S_n;
                                S_n=S_n_h;
                        }

                        size=S_n.size();//文字列Sの長さを整数型で取得

                        //まずは10進法で7を含むか確認
                        for(ll j=0; j<=size-1; j++) {
                                if(S_n[j]=='7') {

                                        sum +=1;
                                        //cout <<"bbb" << i << endl;
                                        break;
                                }
                        }

                }

        }

        cout << N-sum << endl;
        //終了
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define totori signed
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};

template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    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; }
    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;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

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

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 1000000007;
// const int mod = 998244353;
using mint = ModInt< mod >;

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

    int q;
    cin>>q;
    while(q--){
        ll n,a,b;
        cin>>n>>a>>b;
        if(a+b<=n){
            if(a<b)swap(a,b);
            mint ans = (n-a+1)*(n-a+1);
            ans *= (n-b+1)*(n-b+1);
            // kanzen ni naka
            mint sub = (a-b+1)*(a-b+1);
            sub *= (n-a+1)*(n-a+1);
            ans -= sub;

            // katahou dake naka
            mint ret = (n-a+1)*(a-b+1);
            mint sum = (n-a+1-1)*(n-a+1)/2;
            sum -=(n-a-b+1)*(n-a-b+2)/2;
            ret *= sum;
            ans -= ret*4;

            // ryouhou naka
            ret = 0;
            n -= a;
            n++;
            ret = (b-1)*(b-1);
            ret *= (b-2*n) * (b-2*n);
            ans -= ret;
            cout << ans << "\n";
        }
        else cout << 0 << "\n";
    }
}

#include <bits/stdc++.h>
using namespace std;
int N, W, S, T;
long long P, A[200001];
void SET(int S, int T, long long P) {
  A[S] += P;
  A[T] -= P;
}
void GET(int W) {
  long long foo = 0;
  for (int i = 0; i <= 2e5; i++) {
    foo += A[i];
    if (foo > W) {
      cout << "No";
      exit(EXIT_SUCCESS);
    }
  }
  cout << "Yes";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i <= 200000; i++) {
    A[i] = 0;
  }
  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> S >> T >> P;
    SET(S, T, P);
  }
  GET(W);
  return 0;
}


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

#define ll long long
#define print(a)          \
    for (auto x : a)      \
        cout << x << " "; \
    cout << endl
#define print_upto(a, n)        \
    for (ll i = 1; i <= n; i++) \
        cout << a[i] << " ";    \
    cout << endl
#define take(a, n)              \
    for (ll i = 1; i <= n; i++) \
        cin >> a[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"

#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(9) << ans << nl;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;

const ll N = 200009;

void solve()
{
    ll l, r;
    cin >> l >> r;

    ll n = (r - l) - l + 1;
    if (n < 0)
    {
        cout << 0 << nl;
        return;
    }
    ll ans = (n * (n + 1)) / 2;

    cout << ans << nl;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll t = 1;
    cin >> t;

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

    return 0;
}

#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>;
const int INF = (int)1e9;
const ll INFL = (ll)1e15;
const int MOD = 1e9 + 7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
  ll t;
  cin >> t;
  ll l, r;
  rep(i,t){
  cin >> l >> r;
  ll ans = 0;
  ll u = r - 2 * l;
  if (u >= 0)
  {
    ans = (u + 1) * (u + 2) / 2;
  }
  cout << ans << endl;
  }

  return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    vector <vector <int>> pos(n);

    rep (i, n) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }

    int ans = 0;
    rep (i, n) {
        if (pos[i].size() == 0) break;
        rep (j, pos[i].size()) {
            int tmp = j == 0 ? pos[i][j] - (-1)
                             : pos[i][j] - pos[i][j - 1];

            if (tmp > m) {
                cout << i << endl;
                return 0;
            }
        }
        if (n - pos[i].back() > m) break;
        ans += 1;
    }
    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#define rep(a,b,c) for(register int a=(b);a<=(c);++a)
#define dow(a,b,c) for(register int a=(b);a>=(c);--a)
using namespace std;
const int MaxN=1000000+5;
struct Connector
{
	int fa[MaxN];
	inline void Initalize(const register int len)
	{
		rep(i,1,len)
			fa[i]=i;
	}
	inline int getf(const register int u)
	{
		if(u!=fa[u])
			fa[u]=getf(fa[u]);
		return fa[u];
	}
	inline bool Merge(const register int u,const register int v)
	{
		const register int fu=getf(u),fv=getf(v);
		if(fu==fv)
			return false;
		fa[fu]=fv;
		return true;
	}
};
Connector con;
int arr[MaxN];
int main()
{
	register int n,m=0;
	scanf("%d",&n);
	rep(i,1,n)
		scanf("%d",&arr[i]),m=max(m,arr[i]);
	con.Initalize(m);
	register int Sum=0;
	rep(i,1,n>>1)
		if(con.Merge(arr[i],arr[n-i+1]))
			++Sum;
	printf("%d\n",Sum);
	return 0;
}


///*    ***Bismillahir Rahmanir Rahim***   */
/// bujsilam ar proti index value gcd ber korte hbe
///pore je oi gcd mod oita mathaia sen ni
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define	       MEM(a,b)         memset(a,(b),sizeof(a))
#define	       CLR(p)           memset(p,0,sizeof(p))
#define precision(a) fixed << setprecision(a)
#define rep(i,b) for(ll i=0;i<(b);i++)
#define rep1(i,b) for(int i=1;i<=(b);i++)
//#define rep(s,e)         for(i=s;i<e;i+=1)
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep2(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
#define	       ff               first
#define	       sc              second
#define     print(v)        for(ll i:v) cout<<i<<ss
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first != b.first) return a.first > b.first;
    else
    return a.second > b.second;
}
//ll minelementindex = min_element(v.begin(),v.end()) - v.begin();
//ll minelement = *min_element(v.begin(), v.end());
//ll maxelementindex = max_element(v.begin(),v.end()) - v.begin();
//ll maxelement = *max_element(v.begin(), v.end());
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
#define MAX 1000000
#define precision(a) fixed << setprecision(a)

#define mod 1000000007
 ll cheak(ll x)
 {

    string s =to_string(x);
     string x1;
     x1=s;
     s+=s;
      stringstream geek(s);

    // The object has the value 12345 and stream
    // it to the integer x
    ll y = 0;
    geek >> y;
   // ll y = stoi(s);
     return y;
 }

int main()
{
 //O_O ;
   ll t=1;
   //cin>>t;
   while(t--){
       ll n;cin>>n;
       ll c=0;
   for(ll i=1;i<=1000000;i++)
   {
       ll x2=cheak(i);
       if(x2<=n){
        c++;
      //  cout<<x2<<nn;
       }

   }
   cout<<c<<nn;

   }

    return 0;
}

//https://codeforces.com/contest/1371/problem/D korte hbe
//https://codeforces.com/contest/1256/problem/B implementation pari nai
/*****************  ALHAMDULILLAH  *****************/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 61;
//const ll mod = 1e9 + 7;
const ll mod = 998244353;

int main() {
	ll n, m;
	cin >> n >> m;
	VI x(m), y(m), z(m);
	REP(i, m) {
		cin >> x[i] >> y[i] >> z[i];
	}
	VLL dp((1 << n) + 1, 0);
	dp[0] = 1;

	REP(i, (1 << n)) {
		if (dp[i] == 0)continue;
		VI v;
		VI cand;
		REP(j, n) {
			if (i&(1 << j))v.push_back(j);
			else cand.push_back(j);
		}
		int v_size = v.size();

		for (int j : cand) {
			bool flag = true;
			REP(k, m) {
				if (x[k] <= v_size)continue;
				if (j >= y[k])continue;
				int cnt = upper_bound(ALL(v), y[k]-1) - v.begin();
				if (cnt == z[k])flag = false;
			}
			if (flag) {
				dp[(i ^ (1 << j))] += dp[i];
			}
		}
	}
	cout << dp[(1 << n)-1] << endl;

}


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

using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;

/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);

/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/

void print(vector <vector <ll>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}

ll solve(vector <ll> &A, ll a, ll x, ll n) {
	vector <vector<ll>> X(a,vector <ll>(n+1,0LL));
	for (ll i=0;i<n;i++) {
		for (ll k=n-1;k>=1;k--) {
			for (ll j=0;j<a;j++) {
				if (X[j][k]>0LL) {
				X[(j+A[i])%a][k+1]=max(X[j][k]+A[i],X[(j+A[i])%a][k+1]);
				}
				//cout<<a<<" "<<kiek<<" "<<Y[kiek%a][k+1]<<endl;
				}
			}
		X[A[i]%a][1]=max(X[A[i]%a][1],A[i]);
		//cout<<a<<" "<<i<<endl;
		//print(X);
		}
	ll did=X[x%a][a];
	//cout<<a<<" "<<did<<endl;
	if (did==0LL) {return x;}
	ll ats=(x-did)/a;
	//cout<<a<<" "<<did<<" "<<ats<<endl;
	return ats;
	}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    ll x;
    cin>>n>>x;
    vector <ll> A(n);
    for (ll i=0;i<n;i++) {cin>>A[i];}
    ll ats=x;
    for (ll i=1;i<=n;i++) {
		ll s=solve(A,i,x,n);
		ats=min(ats,s);
		}
	cout<<ats<<endl;
    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 500100
#define MOD 1000000007  //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;

int main() {
	int n;
	ll a[N];
	ll x;
	ll ans = 0;
	priority_queue<ll>pq;
	cin >> n;
	rep(i, (2*n))cin >> a[i];
	rep(i, n) {
		pq.push(-a[n + i]);
		pq.push(-a[n - 1 - i]);
		ans += a[n + i];
		ans += a[n - 1 - i];
		x = pq.top();
		ans += x;
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int md = 1000000007;
int n=0;
int a[100001];
set<int> Set;

signed main() {
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> a[i];
		Set.insert(a[i]);
	}
	int prev = 0;
	int res = 1;
	for (auto s : Set)
	{
		res*=((s-prev+1)%md);
		res%=md;
		prev = s;
	}
	cout << res;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>a;
vector<ll>v;
int main()
{
	ios::sync_with_stdio(false);
	ll n,num;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>num;
		if(a[num]==0)v.push_back(num);
		a[num]++;
	}
	ll res=((n-1)*n)/2;
	for(int i=0;i<v.size();i++)
	{
		if(a[v[i]]>1)res-=((a[v[i]]-1+1)*(a[v[i]]-1))/2;
	}
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,f[N],stk[N],top;
struct pt {
	int val,i;
}a[N];
bool cmp(pt p,pt q) {return p.val<q.val;}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;++i)scanf("%d",&a[i].val),a[i].i=i;
	sort(a+1,a+2*n+1,cmp);
	for(int i=2*n;i>n;--i)f[a[i].i]=1;
	for(int i=1;i<=2*n;++i) {
		if(!top||f[stk[top]]==f[i]) {
			printf("(");
			stk[++top]=i;
		}
		else --top,printf(")");
	}
	return 0;
}

#include <iostream>
using namespace std;

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		int N;
		cin >> N;
		string S1, S2, S3;
		cin >> S1 >> S2 >> S3;
		cout << 1;
		for (int i = 0; i < N; i++) cout << 0;
		for (int i = 0; i < N; i++) cout << 1;
		cout << endl;
	}
}


#include <bits/stdc++.h>

#define N 500005

#define pb push_back
#define mk make_pair
#define fi first
#define se second

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		int s = 0, x = i;
		for (int j = 2; j * j <= i; ++j)
		{
			while (x % j == 0) ++s, x /= j;
		}
		if (x > 1) ++s;
		printf("%d ", s + 1);
	}
}

// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int ans[101010];

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);

    // 2. i の 小さい順に, 数列を更新.
    rep(i, 101010) ans[i] = 1;
    repx(i, 1, N + 1) repex(j, i * 2, N + 1, i) if(ans[i] == ans[j]) ans[j]++;

    // 3. 出力.
    repx(i, 1, N + 1){
        printf("%d", ans[i]);
        printf("%s", (i < N) ? " " : "\n");
    }
    return 0;

}


#include<iostream>

#include<cstdio>

#include<vector>

#include<algorithm>

#include<cmath>

#include<chrono>

using namespace std;

/*unsigned int rnd()

{

	static unsigned int y=2463534242;	y^=y<<13;

	y^=y>>17;

	return y^=y<<5;

}*/

/*

unsigned int rnd()

{

    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;

    unsigned int t;

    t=x^(x<<11);

	x=y;

	y=z;

	z=w;

	return w^=(w>>19)^t^(t>>8);

}*/

unsigned long rnd(){

	static unsigned long x=88172645463325252UL;

	x^=x<<7;

	x^=x>>9;

	return x;

}

int N;

int X[200],Y[200],R[200];

int A[200][4];

int ch_mem[200];

int area(int id){return (A[id][2]-A[id][0])*(A[id][3]-A[id][1]);}

bool intersect(int i,int j)

{

	return !(A[i][2]<=A[j][0]

	||A[j][2]<=A[i][0]

	||A[i][3]<=A[j][1]

	||A[j][3]<=A[i][1]);

}

bool contain(int x,int y,int id)

{

	return A[id][0]<=x&&x<A[id][2]&&A[id][1]<=y&&y<A[id][3];

}

double point(int id)

{

	if(A[id][0]<=X[id]&&X[id]<A[id][2]

		&&A[id][1]<=Y[id]&&Y[id]<A[id][3])

	{

		int S=area(id);

		return 1-pow(1-(double)min(R[id],S)/max(R[id],S),2);

	}

	else return 0;

}

using score=double;

score contain_point(int id)

{

	long S=area(id),T=R[id];

	if(S>T)swap(S,T);

	return 1-(T-S)*(T-S)/(double)(T*T);

}

bool prob(score nxt,score prv,double temp)

{

	score x=(nxt-prv)/temp;

	return (1+x

		+x*x*.5

		+x*x*x*.166666666666

		//+x*x*x*x*.041666666666666

		//+x*x*x*x*x*.008333333333333

		)*(1<<30)>(rnd()&(1<<30)-1);

	//return exp(x)*(1<<30)>(rnd()&(1<<30)-1);

}

int main()

{

	scanf("%d",&N);

	for(int i=0;i<N;i++)scanf("%d%d%d",&X[i],&Y[i],&R[i]);

	for(int i=0;i<N;i++)

	{

		A[i][0]=X[i];

		A[i][1]=Y[i];

		A[i][2]=X[i]+1;

		A[i][3]=Y[i]+1;

	}

	chrono::system_clock::time_point start=chrono::system_clock::now();

	const long long TL=4.95*1e9;

	const double start_temp=0.025;

	const double end_temp=0.0000005;

	int iteration=0;

	while(true)

	{

		long long nowTime=chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now()-start).count();

		if(nowTime>TL)break;

		double temp=start_temp+(end_temp-start_temp)*nowTime/TL;

		for(int t=0;t<100;t++)

		{

			iteration++;

			int id=rnd()%N;

			int r=rnd()%4;

			int add=r<2?-1:1;

			score prv=contain_point(id);

			int prvA=A[id][r];

			A[id][r]+=add;

			if(A[id][r]<0||A[id][r]>10000)

			{

				A[id][r]-=add;

				continue;

			}

			score nxt=contain_point(id);

			if(prv>nxt)

			{

				A[id][r]-=add;

				continue;

			}

			int chr=0;

			bool ok=true;

			int vr=r^1;

			for(int i=0;i<N;i++)

			{

				if(i!=id&&A[i][r^2]==prvA&&!(A[i][vr|2]<=A[id][vr&1]||A[id][vr|2]<=A[i][vr&1]))

				{

					if((r<2?A[i][r^2]+add:A[i][r^2])==(r&1?Y:X)[i])

					{

						ok=false;

						break;

					}

					prv+=contain_point(i);

					A[i][r^2]+=add;

					nxt+=contain_point(i);

					ch_mem[chr++]=i;

				}

			}

			if(ok&&(nxt>prv||prob(nxt,prv,temp)))

			{

			}

			else

			{

				A[id][r]-=add;

				for(int j=0;j<chr;j++)A[ch_mem[j]][r^2]-=add;

			}

		}

	}

	cerr<<iteration<<endl;

	for(int id=0;id<N;id++)

	{

		for(int r=0;r<4;r++)

		{

			int X=area(id);

			int add=r<2?-1:1;

			A[id][r]+=add;

			if(A[id][r]<0||A[id][r]>10000)

			{

				A[id][r]-=add;

				continue;

			}

			int Y=area(id);

			if(R[id]<=X||R[id]<Y&&(long)X*Y>(long)R[id]*R[id])

			{

				A[id][r]-=add;

				continue;

			}

			bool ok=true;

			for(int i=0;i<N;i++)if(i!=id)

			{

				if(intersect(i,id))

				{

					ok=false;

					break;

				}

			}

			if(!ok)A[id][r]-=add;

		}

	}

	for(int i=0;i<N;i++)

	{

		//cerr<<i<<" : "<<point(i)<<endl;

		printf("%d %d %d %d\n",A[i][0],A[i][1],A[i][2],A[i][3]);

	}

}

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n), r(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];

    vector<vector<bool>> field(10000, vector<bool>(10000));
    vector<int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; i++) { a[i] = x[i]; b[i] = y[i]; c[i] = x[i] + 1; d[i] = y[i] + 1; }
    for (int i = 0; i < n; i++) field[a[i]][b[i]] = true;

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

        for (int j = a[i] - 1; j >= 0; j--) {
            if (field[j][b[i]]) { a[i] = j + 1; break; }
            //else if (j == 0) { field[0][b[i]] = true; a[i] = 0; }
            else field[j][b[i]] = true; a[i] = j;
        }

        for (int j = c[i]; j < 10000; j++) {
            if (field[j][b[i]]) { c[i] = j; break; }
            //else if (j == 9999) { field[9999][b[i]] = true; c[i] = 10000; }
            else field[j][b[i]] = true; c[i] = j + 1;
        }

    }

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

        for (int j = b[i] - 1; j >= 0; j--) {
            if (field[a[i]][j]) { b[i] = j + 1; break; }
            else for (int k = a[i]; k < c[i]; k++) field[k][j] = true; b[i] = j;
        }

        /*
        for (int j = d[i]; j < 10000; j++) {
            if (field[a[i]][j]) { d[i] = j; break; }
            else for (int k = a[i]; k < c[i]; k++) field[k][j] = true; d[i] = j + 1;
        }
        */

    }

    for (int i = 0; i < n; i++) {
        printf("%d %d %d %d\n", a[i], b[i], c[i], d[i]);
    }
    //cout << field[2297][9999] << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;

    vector <vector<int>> p(N, vector<int>(2));
    vector <double> store(N);
    rep(i, N)
        cin >> p[i][0] >> p[i][1];

    int x, y;
    double r;
    rep(i, N)
    {
        x = p[i][0];
        y = p[i][1];
        // cout << "xy" << x << y << endl;
        rep2(j, i + 1, N)
        {
            // cout << " xy" << p[j][0] << p[j][1] << endl;
            if (p[j][0] == x)
                r = INT_MAX;
            else
                r = double(p[j][1] - y) / double(p[j][0] - x);
            store[j] = r;
            for(int k = j-1; k > i; k--){
                if (store[k] == store[j]){
                    // cout << "jk" << j << k << " : " << store[j] << store[k] << endl;
                    // cout << p[j][0] << p[j][1] << " & " << p[k][0] << p[k][1] << endl;
                    // r = double(p[j][1] - y) / double(p[j][0] - x);
                    // cout << r <<endl;
                    // r = double(p[k][1] - y) / double(p[k][0] - x);
                    // cout << r <<endl;
                    // rep(n, N) cout << store[n] << ", ";
                    cout << "Yes" << endl;
                    exit(0);
                }
            }
        }
    }
    cout << "No" << endl;
}

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

double EPS = 1e-9;

double square(double x)
{
    return x * x;
}

int main()
{
    vector<array<double, 2>> set1;
    vector<array<double, 2>> set2;

    int n;
    cin >> n;

    if (n == 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        double x, y;
        cin >> x;
        cin >> y;
        array<double, 2> point = {x, y};
        set1.push_back(point);
    }

    for (int i = 0; i < n; i++)
    {
        double x, y;
        cin >> x;
        cin >> y;
        array<double, 2> point = {x, y};
        set2.push_back(point);
    }

    double set1_x_avg = 0, set1_y_avg = 0;
    for (auto point : set1)
    {
        set1_x_avg += point[0];
        set1_y_avg += point[1];
    }
    set1_x_avg /= set1.size();
    set1_y_avg /= set1.size();

    double set2_x_avg = 0, set2_y_avg = 0;
    for (auto point : set2)
    {
        set2_x_avg += point[0];
        set2_y_avg += point[1];
    }
    set2_x_avg /= set2.size();
    set2_y_avg /= set2.size();

    // now we have the centroids
    // cout << "centroid1 " << set1_x_avg << " " << set1_y_avg << endl;
    // cout << "centroid2 " << set2_x_avg << " " << set2_y_avg << endl;

    // normalize
    for (auto &point : set1)
    {
        point[0] -= set1_x_avg;
        point[1] -= set1_y_avg;
        // cout << point[0] << " " << point[1] << endl;
    }

    for (auto &point : set2)
    {
        point[0] -= set2_x_avg;
        point[1] -= set2_y_avg;
        // cout << point[0] << " " << point[1] << endl;
    }

    // loop over every pair
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            double d1 = sqrt(square(set1[i][0]) + square(set1[i][1]));
            double d2 = sqrt(square(set2[j][0]) + square(set2[j][1]));

            if (d1 < EPS || abs(d1 - d2) > EPS)
            {
                continue;
            }

            double t = atan2(set2[j][1], set2[j][0]) - atan2(set1[i][1], set1[i][0]);

            for (int k = (0); k < n; k++)
            {
                auto O3U4gd88 = ((set1[k][0] * cos(t) - set1[k][1] * sin(t)));
                auto H31bcJ8S = ((set1[k][0] * sin(t) + set1[k][1] * cos(t)));
                set1[k][0] = O3U4gd88;
                set1[k][1] = H31bcJ8S;
            }

            /*vector<array<double, 2>> rot_set1;
            for (int k = 0; k < n; k++)
            {
                double rotx = set1[k][0] * cos(t) - set1[k][1] * sin(t);
                double roty = set1[k][0] * sin(t) + set1[k][1] * cos(t);
                array<double, 2> a = {rotx, roty};
                rot_set1.push_back(a);
            } */

            bool polygons_identical = true;
            // for each point check if there is this identical point in the other set
            for (int k = 0; k < n; k++)
            {
                bool has_match = false;
                for (int l = 0; l < n; l++)
                {
                    if (abs(set1[k][0] - set2[l][0]) <= EPS && abs(set1[k][1] - set2[l][1]) <= EPS)
                    {
                        has_match = true;
                        break;
                    }
                }
                polygons_identical &= has_match;
                if (!has_match)
                    break;
            }
            if (polygons_identical)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


/*

Code for problem A by cookiedoth
Generated 10 Apr 2021 at 03.05 PM

█▒▒▒▒▒▒▒▒▒
10%
███▒▒▒▒▒▒▒
30%
█████▒▒▒▒▒
50%
███████▒▒▒
70%
██████████
100%

~_^
=_=
¯\_(ツ)_/¯

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#include <random>
#include <utility>
#include <tuple>
#include <chrono>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define length(a) (int)a.size()

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int mx = 110;
const int INF = 1e9 + 228;
int n, a[mx];
string s;

signed main() {
	fast_io();
	cin >> n;
	cin >> s;
	for (int i = 0; i <= n; ++i) {
		cin >> a[i];
	}
	int k = INF;
	for (int i = 0; i < n; ++i) {
		k = min(k, abs(a[i + 1] - a[i]));
	}
	cout << k << '\n';
	for (int i = 0; i < k; ++i) {
		for (int j = 0; j <= n; ++j) {
			int val = a[j] / k;
			if (i < (a[j] % k)) {
				val++;
			}
			cout << val << ' ';
		}
		cout << '\n';
	}
}

#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n), w(m);
  REP(i, n) cin >> h[i];
  REP(i, m) cin >> w[i];
  sort(ALL(h));

  vector<ll> left(n+1, 0), right(n+1, 0);
  for(ll i = 2; i < n; i += 2){
    //左側がi個残ったときの累積和
    left[i] = left[i-2] + h[i-1] - h[i-2];
    //右側がi個残ったときの累積和
    right[i] = right[i-2] + h[n-i+1] - h[n-i];
  }
  ll ans = INF;
  REP(i, m){
    //w[i]の身長の先生が入る場所を探す
    ll x = lower_bound(ALL(h), w[i]) - h.begin();
    //0->一番左 1->左から2番目 ... x=左に残る数
    //xが偶数->先生が左側 x番目の子とペアを組む
    if(x%2 == 0){
      chmin(ans, left[x] + right[n-1-x] + h[x]-w[i]);
    //ｘが奇数->先生が右側 x-1番目のことペアを組む
    }else{
      chmin(ans, left[x-1] + right[n-x] + w[i]-h[x-1]);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int x , y ;
    cin>> x >>y;
    if(x==y)
        cout<<x<<"\n";
    else
        cout<<abs(3-(x+y))<<"\n";
}

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

int main(){
double a, b;
cin >> a >> b;
b=100*(a-b)/a;
cout << fixed << setprecision(12) << b;
}


#include<iostream>
using namespace std;
int main(){
long long int i, n,s,p,count=0;
cin>>n>>s>>p;
//max1=max(y,w);
long long int a[n],b[n];
for(i=0;i<n;i++ ){

    cin>>a[i]>>b[i];
    if(a[i]<s && b[i]>p){

        count=1;
        cout<<"Yes";
        break;
    }
}
if(count==0){
        cout<<"No";

}
}

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<ll,Pi> Pli;
typedef pair<Pi,Pi> Pi2;
typedef pair<P1,ll>P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int t,x,y;
};
int main(){

	ll s,d;
	int n;
	cin>>n>>s>>d;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		if(x<s&&y>d){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;

	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define mod 1000000007ll
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(25);
using namespace std;

ll gcd(ll a, ll b) {if(a == 0) return b; return gcd(b % a, a);}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}
ll find_pow(ll a, ll b) {ll res = 1;while(b) {if(b & 1) res *= a;a *= a;b >>= 1;}return res;}
ll find_powmod(ll a, ll b) {ll res = 1; while(b) {if(b&1) (res *= a)%= mod; (a *= a)%=mod; b >>= 1;}return res%mod;}
ll invMod(ll n, ll y = mod){return find_pow(n, y-2);}

clock_t time_p=clock();
void Time(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

void solve() {
	string s;
	cin >> s;
	int n = s.length(), ans = -1;
	string t = "atcoder";
	for(int i = 0; i < n; ++i) {
		if(s[i] != 'a') {
			ans = i;
			break;
			}
		}
		if(ans == 0) cout << 0 << endl;
		else if(s > t) cout << 0 << endl;
		else if(ans == -1) cout << -1 << endl;
		else if(s[ans] > 't') cout << ans - 1 << endl;
		else cout << ans << endl;
		return;
	}

int main() {
	fastio();
	int t;
	cin >> t;
	while(t--)
	solve();

	Time();
	return 0;
}

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

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

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
typedef vector<vi> vvi;

const int M = 1e9+7;
const int N = 2e5;
int po(int,int);
int n;
bool check(int x){
    return ((n/x - x + 1)%2==0);
}

void solve(){
    cin>>n;
    n = 2*n;
    int ans = 0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(check(i)) ans++;
            if(check(n/i)) ans++;
        }
    }
    cout<<ans<<"\n";

}

int32_t main() {

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

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

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

    }

    return 0;

}

int po(int a,int b){
    if(b==0) return 1;
    int ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


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

int main() {
    int N;
    cin >> N;
    ll mod = 1e9+7;
    set<ll> st;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        st.insert(A);
    }
    ll pre = 0;
    ll ans = 1;
    for (ll n : st) {
        ans = ans*(n-pre+1)%mod;
        pre = n;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll ans = v[0] + 1;
        for(i = 1; i < n; i++){
            ans *= (v[i] - v[i - 1] + 1);
            ans %= MOD;
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<ll,ll>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define REP(i,s,e) for (int (i)=(s); (i)<(e);(i)++)
#define PI 3.14159265358979323846264338327950288
#define mod 1000000007
#define eps 0.00000001
#define Find(V,X) find(V.begin(),V.end(),X)
#define Sort(V) sort((V).begin(),(V).end())
// #define Reverse(V) sort((V).begin(),(V).end()),reverse((V).begin(),(V).end())
#define Reverse(V) sort((V).begin(),(V).end(),greater<int>())
//fixed << setprecision(10) <<

int main() {
  int N;
  cin >>N;
  cout<<N-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test lli t;cin>>t;while(t--)
#define vll vector<lli>
#define vpll vector<pair<lli,lli>>
#define prq priority_queue<lli>
#define psq priority_queue<lli,vector<lli>,greater<lli>>
#define pll pair<lli,lli>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define nl "\n"
#define ms0(s) memset(s,0,sizeof(s))
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio
  lli n, i, j;
  cin >> n;
  vll a, b, c;
  char ch;
  for (i = 0; i < 2 * n; i++)
  {
    cin >> j;
    cin >> ch;
    if (ch == 'R')
      a.pb(j);
    else if (ch == 'G')
      b.pb(j);
    else
      c.pb(j);
  }
  if (a.size() % 2 == 0 && b.size() % 2 == 0 && c.size() % 2 == 0)
  {
    cout << 0;
  }
  else if (a.size() % 2 == 0)
  {
    sort(b.begin(), b.end());

    sort(c.begin(), c.end());
    lli ans = ma;
    for (auto i : b)
    {
      j = upper_bound(c.begin(), c.end(), i) - c.begin();
      if (j < c.size())
        ans = min(ans, abs(i - c[j]));
      j--;
      if (j >= 0)
        ans = min(ans, abs(i - c[j]));
    }
    if (a.size() > 0)
    {
      sort(a.begin(), a.end());
      lli an1 = ma;
      for (auto i : a)
      {
        j = upper_bound(c.begin(), c.end(), i) - c.begin();
        if (j < c.size())
          an1 = min(an1, abs(i - c[j]));
        j--;
        if (j >= 0)
          an1 = min(an1, abs(i - c[j]));
      }
      lli an2 = ma;
      for (auto i : b)
      {
        j = upper_bound(a.begin(), a.end(), i) - a.begin();
        if (j < a.size())
          an2 = min(an2, abs(i - a[j]));
        j--;
        if (j >= 0)
          an2 = min(an2, abs(i - a[j]));
      }
      ans = min(ans, an1 + an2);
    }
    cout << ans;
  }
  else if (b.size() % 2 == 0)
  {
    sort(a.begin(), a.end());
    lli ans = ma;
    sort(c.begin(), c.end());
    for (auto i : a)
    {
      j = upper_bound(c.begin(), c.end(), i) - c.begin();
      if (j < c.size())
        ans = min(ans, abs(i - c[j]));
      j--;
      if (j >= 0)
        ans = min(ans, abs(i - c[j]));
    }
    if (b.size() > 0)
    {
      sort(b.begin(), b.end());
      lli an1 = ma;
      for (auto i : b)
      {
        j = upper_bound(c.begin(), c.end(), i) - c.begin();
        if (j < c.size())
          an1 = min(an1, abs(i - c[j]));
        j--;
        if (j >= 0)
          an1 = min(an1, abs(i - c[j]));
      }
      lli an2 = ma;
      for (auto i : b)
      {
        j = upper_bound(a.begin(), a.end(), i) - a.begin();
        if (j < a.size())
          an2 = min(an2, abs(i - a[j]));
        j--;
        if (j >= 0)
          an2 = min(an2, abs(i - a[j]));
      }
      ans = min(ans, an1 + an2);
    }
    cout << ans;
  }
  else if (c.size() % 2 == 0)
  {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    lli ans = ma;
    for (auto i : b)
    {
      j = upper_bound(a.begin(), a.end(), i) - a.begin();
      if (j < a.size())
        ans = min(ans, abs(i - a[j]));
      j--;
      if (j >= 0)
        ans = min(ans, abs(i - a[j]));
    }
    if (c.size() > 0)
    {
      sort(c.begin(), c.end());
      lli an1 = ma;
      for (auto i : a)
      {
        j = upper_bound(c.begin(), c.end(), i) - c.begin();
        if (j < c.size())
          an1 = min(an1, abs(i - c[j]));
        j--;
        if (j >= 0)
          an1 = min(an1, abs(i - c[j]));
      }
      lli an2 = ma;
      for (auto i : b)
      {
        j = upper_bound(c.begin(), c.end(), i) - c.begin();
        if (j < c.size())
          an2 = min(an2, abs(i - c[j]));
        j--;
        if (j >= 0)
          an2 = min(an2, abs(i - c[j]));
      }
      ans = min(ans, an1 + an2);
    }
    cout << ans;
  }

  return 0;
}

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

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int, int> > vii;
typedef   vector<long long> vl;
typedef   pair<int, int> pii;
typedef   pair<ll, ll> pll;
typedef   vector< pair<ll, ll> > vll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto dist = uniform_int_distribution<int>(l, r);
// int dx[] = {1, 0, -1, 0};
// int dy[] = {0, 1, 0, -1};
// int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1};
// int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0};

void omae_wa_mou_shindeiru(int tc) {
	ll n;
	cin >> n;
	n *= 2;
	vector<vl> v(3);
	fi(0, n) {
		ll temp;
		cin >> temp;
		char ch;
		cin >> ch;
		if (ch == 'R') v[0].push_back(temp);
		else if (ch == 'G') v[1].push_back(temp);
		else v[2].push_back(temp);
	}
	vl rem;
	bool check = 1;
	fi(0, 3) {
		sort(v[i].begin(), v[i].end());
		if (v[i].size() % 2) {
			rem.push_back(i);
		}
	}
	if (rem.size() == 0) {
		cout << 0 << endl;
		return;
	}
	vector<vl>arr(3, vl(3, 1e18));
	ll ans = 1e18;

	for (auto it : v[rem[0]]) {
		auto ind = lower_bound(v[rem[1]].begin(), v[rem[1]].end(), it) - v[rem[1]].begin();
		if (ind != v[rem[1]].size()) {
			ans = min(ans, abs(v[rem[1]][ind] - it));
		}
		if (ind != 0) {
			ans = min(ans, abs(v[rem[1]][ind - 1] - it));
		}
	}

	const ll INF = 1e18;
	int other = 3 - rem[1] - rem[0];
	int sz = v[other].size();
	vector<array<ll, 2>>dp(sz + 1, array<ll, 2>({INF, INF}));
	fi(0, sz) {
		ll it = v[other][i];
		auto ind = lower_bound(v[rem[1]].begin(), v[rem[1]].end(), it) - v[rem[1]].begin();
		ll temp1 = 1e18, temp2 = 1e18;
		if (ind != v[rem[1]].size()) {
			temp1 = abs(v[rem[1]][ind] - it);
		}
		if (ind != 0) {
			temp1 = min(temp1, abs(v[rem[1]][ind - 1] - it));
		}
		ind = lower_bound(v[rem[0]].begin(), v[rem[0]].end(), it) - v[rem[0]].begin();
		if (ind != v[rem[0]].size()) {
			temp2 = min(temp2, abs(v[rem[0]][ind] - it));
		}
		if (ind != 0) {
			temp2 = min(temp2, abs(v[rem[0]][ind - 1] - it));
		}
		ans = min(ans, temp2 + dp[i][1]);
		ans = min(ans, dp[i][0] + temp1);
		dp[i + 1][1] = min(dp[i][1], temp1);
		dp[i + 1][0] = min(dp[i][0], temp2);
	}
	cout << ans << endl;

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tc = 1;
	// cin >> tc;
	fi(1, tc + 1) {
		omae_wa_mou_shindeiru(i);
	}
}


//Common Header Simple over C++11
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using pset=__gnu_pbds ::tree<pair<ll, int>, __gnu_pbds::null_type, less<pair<ll, int> >,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MIE(x) min_element(all(x))
#define MAE(x) max_element(all(x))
#define make_unique(a) {sort(all(a));a.resize(unique(all(a))-a.begin());}
#define sz(x) ((int)(x).size())
#define clr(x) memset((x),0,sizeof(x));
//#define endl '\n'
#define count2(x) __builtin_popcount(x)
#define count2ll(x) __builtin_popcountll(x)
#define countleadingzero(x) __builtin_clz(x)
#define dd(x) cerr << #x << " = " << x << ' ';
#define de(x) cerr << #x << " = " << x << endl;
//inline char nc() {
//  static char buf[1000000], *p = buf, *q = buf;
//  return p == q && (q = (p = buf) + fread(buf, 1, 1000000, stdin), p == q)
//             ? EOF
//             : *p++;
//}
inline ll rd(){//LLONG_MIN LMAX=9,223,372,036,854,775,807
	ll 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*10+(ch&15),ch=getchar();
	return s*w;
}
inline int fpow(int a,int b,int p){//a^b mod p; assert(p!=0);
	int ans=1%p,base=a%p;
	for(;b>0;b/=2){
		if(b&1)ans=(long long)ans*base%p;
		base=(long long)base*base%p;
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);cin.exceptions(ios::badbit | ios::failbit);
	int n;cin>>n;
	set<int>s;
	for(int i=1,v;i<=n;++i){
		cin>>v;
		s.insert(v);
	}
	int c=1;
	for(int i=1;i<=n;++i){
		c=c&&s.count(i);
	}
	if(c){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <list>
#include <algorithm>
#include <string.h>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
    int n;
    cin >> n;
    vector<bool> a(n, false);
    for (int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        if (b > n)
        {
            cout << "No";
            return 0;
        }
        b--;
        if (a[b])
        {
            cout << "No";
            return 0;
        }
        a[b] = true;
    }

    cout << "Yes";

    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define pi pair<int, int>
#define ll long long int
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vppll vector<pair<ll, pll>>
#define vvll vector<vector<ll>>
#define vvpll vector<vector<pll>>
#define repi(i,a,n) for(ll i=a;i<n;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define pr(i,v) for(auto i:v)
static int row[4] = {-1, 0, 0, 1};
static int col[4] = {0, -1, 1, 0};
static int dagb[4] = {1, -1, 1, -1};
static int daga[4] = {1, -1, -1, 1};

using namespace std;
vll a[2001];
vll vis(2001,0);
vll d(2001,0);
ll dfs(ll u){
     vis[u]=1;
     int curr=0;
     for(auto i: a[u]){
        if(vis[i]==0){
            curr+=dfs(i);

        }
     }
     return curr+1;
}

int main( )
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r"  ,stdin);
        freopen("ott.txt" , "w" ,stdout);
        freopen("error.txt" , "w" ,stderr);
     #endif

      ll t=1;
     //cin>>t;
   while(t--){
    string s;
    ll l=1,n,m,w,flag=0,y=0,z=0,x=0,k, mn=1e9+7,d,e=0,f=INT_MAX,sum=0,ans=0,de=1,mx=0,g;
      cin>>n>>m;
      repi(i,0,m){
         cin>>x>>y;
         a[x].pb(y);
      }
      repi(i,1,n+1){
         vis.assign(n+1, 0);
         sum+=dfs(i);
      }
       cout<<sum<<endl;

       }
   return 0;
}

/* 	author : sgupta_2001 	*/

#include<bits/stdc++.h>

using namespace std;

using db = double;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

//containers
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

//pairs
#define mp make_pair
#define ff first
#define ss second

//loops
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = b - 1; i >= a; --i)
#define each(x, a) for(auto &x : a)

//popular constants
const int mod = 1e9 + 7; //998244353;
const ll inf = 1e18;
const ld pie = acos((ld) - 1);

//grid problems
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//modulo operations
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

#ifdef SGUPTA_2001
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n';
#else
#define deb(x);
#endif

//debug containers
template<class T> void __print(T x) {cerr<<x;}
template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

const int MAXN = 2002;

vector<int> gr[MAXN];
int t_in[MAXN], t_out[MAXN];
int vis[MAXN];
int timer;

void dfs(int u, int par) {

	t_in[u] = ++timer;

	vis[u] = 1;

	for(auto x : gr[u]) {
		if(x != par && !vis[x]) {
			dfs(x, u);
		}
	}

	t_out[u] = timer;
	return;
}

void solve() {

	int N, M;
	scanf("%d%d", &N, &M);

	rep(i, 0, M) {
		int X, Y;
		scanf("%d%d", &X, &Y);

		X--;Y--;

		gr[X].pb(Y);
	}

	ll ans = 0;

	rep(i, 0, N) {
		dfs(i, -1);
		fill(vis, vis + N + 1, 0);

		int p = t_in[i], q = t_out[i];
		deb(mp(p, q));
		int cnt = 0;
		rep(j, 0, N) {
			// printf("%d %d %d\n", j + 1, t_in[j], t_out[j]);
			if(p <= t_in[j] && q >= t_out[j]) {
				ans++;
			}
		}

		fill(t_in, t_in + N + 1, 0);
		fill(t_out, t_out + N + 1, 0);
		timer = 0;
		// ans += cnt*(cnt + 1) >> 1;
	}

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

	return;
}

int main() {

	#ifdef SGUPTA_2001
		freopen("input.txt", "r", stdin);
		freopen("error.txt", "w", stderr);
	#endif

	auto start = std::chrono::high_resolution_clock::now();

	int t;
	t=1;
	while(t--) solve();

  auto stop = std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n';

	 /*
	 		STUFF TO LOOK:
			1. Check the constraints
			2. Corner cases(n == 0 || n == 1)
			3. Variables in loops
			4. Make sure two ints aren’t multiplied to get a long long
	*/

	return 0;
}


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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(M);
    vector<int> B(M);
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
    }

    int K;
    cin>>K;
    vector<int> C(K);
    vector<int> D(K);
    for(int i=0;i<K;i++){
        cin>>C[i]>>D[i];
        C[i]--;D[i]--;
    }

    int MX=1<<K;
    int ans=0;
    for(int i=0;i<MX;i++){
        vector<int> V(N,0);
        for(int j=0;j<K;j++){
            if(1 & (i>>j)){
                V[C[j]]++;
            }else{
                V[D[j]]++;
            }
        }
        int cnt=0;
        for(int j=0;j<M;j++){
            if(V[A[j]] > 0 && V[B[j]] > 0){
                cnt++;
            }
        }
        if(ans < cnt){
            ans = cnt;
        }
    }
    cout<<ans<<endl;

    return 0;
}

/*                             हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे
                                  हरे राम हरे राम राम राम हरे हरे                                     */
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pob pop_back
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
#define ff first
#define ss second
#define F(n) for(lli i=0;i<n;i++)
#define pf pop_front
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define bs binary_search
#define all(x) x.begin(),x.end()
#define nl "\n"
#define loop(i,s,n) for(lli i=s;i<n;i++)
#define pp(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define mod 1000000007
#define inf 1e18
#define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x
lli solve(lli n)
{
 lli r,i;
 while(n!=0)
 {
     r=n%10;
     if(r==7) return -1;
     n/=10;
 }
 return 0;
}
lli decToOctal(lli n)
{
    lli octalNum[100];
    lli i = 0,f=0;
    while (n != 0) {
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }
    for (lli j = i - 1; j >= 0; j--)
        {
            if(octalNum[j]==7)
            {
                f=1;
                break;
            }
        }
        if(f) return -1;
        else return 0;
}
int main()
{
fast;
 	lli n,i,j,c,x=0;
 	cin>>n;
 	lli a[n],s=0;
 	loop(i,0,n) cin>>a[i];
 	sort(a,a+n);
 	loop(i,0,n)
 	{
 	    s+=(i*a[i])-((n-1-i)*a[i]);
 	}
 	cout<<s;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    string S;
    cin >> S;
    for (int i = 0; i < 12; i++){
        auto T = S;
        reverse(T.begin(), T.end());
        if (S == T){
            puts("Yes");
            return 0;
        }
        S = '0' + S;
    }

    puts("No");
}

#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    int n; cin>>n;
	auto f = [&](string s){
	string t= s;
	reverse(all(t));
	return s==t;
	};

	string s=to_string(n);
    if(f('0'+s) || f("00"+s) || f("000" + s) || f(s)|| f("0000"+s) || f("00000"+s) || f("000000"+s) ||f("0000000"+s)
       ||f("00000000"+s)||f("000000000"+s)){

        cout<<"Yes";
        return 0;
    }
    cout<<"No";
	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 lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

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?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int N=3e5+5;
int n,a[N];

struct BIT
{
	int c[N];
	inline void add(int x,int v)
	{
		for(;x<=n;x+=lowbit(x))
			c[x]+=v;
	}
	inline int getsum(int x)
	{
		int res=0;
		for(;x;x-=lowbit(x))
			res+=c[x];
		return res;
	}
	inline int query(int l,int r)
	{
		return getsum(r)-getsum(l-1);
	}
}sum;

signed main()
{
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		ans+=sum.query(a[i]+2,n);
		sum.add(a[i]+1,1);
	}
	printf("%lld\n",ans);
	for(int i=1;i<=n-1;++i)
	{
		ans-=a[i];
		ans+=n-a[i]-1;
		printf("%lld\n",ans);
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 1e9 + 7;

int ksm(int a, int b) { return (b % 2 == 1 ? a : 1) * (b ? ksm(a * a % M, b / 2) : 1) % M; }
int x, y, a[2333][2333], b[2333][3333], l[ff], r[ff], Ans, ss;
char s;
void init()
{
	cin >> x >> y;
	rep(i, 1, x)
		rep(j, 1, y)
			cin >> s, a[i][j] = (s != '#'), ss += a[i][j];
	rep(i, 1, x)
	{
		int las = 0, s = 0;
		rep(j, 1, y)
		{
			if(a[i][j]) b[i][j] += s, s ++;
			else s = 0;

		}
		s = 0;
		sep(j, y, 1)
		{
			if(a[i][j]) b[i][j] += s, s ++;
			else s = 0;

		}
	}
//	rep(i, 1, x) rep(j, 1, y) cout <<b[i][j] << " "; cout << "\n";
	rep(i, 1, y)
	{
		int las = 0, s = 0;
		rep(j, 1, x)
		{
		//	cout << j << " " << i << " " <<s << "\n";
			if(a[j][i]) b[j][i] += s, s ++;
			else s = 0;
		//
		}
		s = 0;
		sep(j, x, 1)
		{
			if(a[j][i]) b[j][i] += s, s ++;
			else s = 0;
		//	cout <<b[j][i] << "\n";
		}
	}
	rep(i, 1, x)
		rep(j, 1, y)
		{
			if(!a[i][j]) continue;
		//	cout <<b[i][j] << " ";
			int sum = b[i][j] + a[i][j];
		//	cout << sum <<"\n";
			Ans = Ans + ksm(2, ss) - ksm(2, ss - sum);
			Ans = (Ans % M + M) % M;
		}
	cout << Ans;
}
signed main()
{
//	freopen("1.out", "w", stdout);
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int maxn=500;
ll a[maxn+5][maxn+5];
int main()
{

    int n;
    cin>>n;
    rep(i,0,n)
    {
        rep(j,0,n)
        cin>>a[i][j];
    }
    bool flag=1;
    ll dif[n];
    rep(i,0,n)
    {
        dif[i]=a[i][0]-a[(i+1)%n][0];
    }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            ll tmp=a[i][j]-a[(i+1)%n][j];
            if(tmp!=dif[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    rep(i,0,n)
    {
        dif[i]=a[0][i]-a[0][(i+1)%n];
    }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            ll tmp=a[j][i]-a[j][(i+1)%n];
            if(tmp!=dif[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    ll min=0x3f3f3f3f3f3f3f3f;
    int minum=0;
    ll ans1[maxn+5];
    ll ans2[maxn+5];
    rep(i,0,n)
    {
        if(a[i][0]<min)
        {
            minum=i;
            min=a[i][0];
        }
    }
    rep(i,0,n)
    {
        ans2[i]=a[minum][i];
    }
    rep(i,0,n)
    {
        ans1[i]=a[i][0]-ans2[0];
    }
    rep(i,0,n)
    {
        cout<<ans1[i]<<" ";

    }
    cout<<endl;
    rep(i,0,n)
    {
        cout<<ans2[i]<<" ";
    }
    cout<<endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(int i=0;i<(n);i++)
#define f1(i,n) for(int i=1;i<=(n);i++)
#define f2(i,a,n) for(int i=(a);i<=(n);i++)
#define fr(i,n,a) for(int i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define nl "\n"

const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const ll LMXN = 1e14;
const int MOD = 1e9 + 7;
ll cs = 0;

void solve(){
    int v, t, s, d; cin >> v >> t >> s >> d;
    if(d >= v*t && d <= v*s) cout << "No" << nl;
    else cout << "Yes" << nl;
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    FIO;
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
 ll n;
 cin>>n;
 if(n<=6)
 cout<<n;
 else
 {
     int c=0;
 for(int i=7;i<=n;i++)
 {
   int te=i,r,f=0;
   while(te>0)
   {
       r=te%10;
       te/=10;
       if(r==7)
       {f=1;
       break;}
   }
   if(f==1)
   {c++;
   continue;}
   te=i;
   while(te>0)
   {
       r=te%8;
       te/=8;
       if(r==7)
       {
           f=1;
           break;
       }
   }
   if(f==1)
   c++;
 }
 cout<<n-c;
 }

}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N; cin >> N;
  rep(i,N) {
    ll a = i*2, b = i*2+1;
    ll tca = 0; while ((1<<tca)<=a) tca++;
    while (a>=N) { if (a&(1<<tca)) a ^= (1<<tca); tca--; }
    ll tcb = 0; while ((1<<tcb)<=b) tcb++;
    while (b>=N) { if (b&(1<<tcb)) b ^= (1<<tcb); tcb--; }
    a++; b++;
    cout << a << " " << b << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#include<string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#include<unordered_map>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, a, b) for(int i = (a); i <=(b); ++i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define RESET(a, v) memset(a, (v), sizeof(a))
#define SZ(a) (int(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define II pair<int, int>
#define X first
#define Y second
#define VI vector<int>
#define VII vector<II>
#define endl '\n'
#define ll long long int
#define mod 1000000007
#define mk(arr,n,type) type*arr=new type[n];

using namespace std;

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

}

long long int gcd(long long int a, long long int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;

	if (n % 2 == 0 || n % 3 == 0)
		return false;

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

	return true;
}

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

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

	if (m / 2 >= n)cout << m / 2;
	else {
		int range = m ;
		int ans = 1;
		for (int i = 1 ; i <= range ; i++) {
			int start = n / i;
			if (n % i == 0) {
				if ((start + 1)*i <= m)ans = max(ans , (int)gcd(i * (start + 1) , i * (start )));
			}
			else {
				if ((start + 2)*i <= m)ans = max(ans , (int)gcd(i * (start + 1) , i * (start + 2)));
			}

		}
		cout << ans << endl;
	}

	return 0;

}

#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    long long a, b;
    scanf("%lld%lld", &a, &b);
    if(b>=2*a)
    {
        printf("%lld", b / 2);
        return 0;
    }
    long long gcd = b - a;
    while(gcd)
    {
        int down, up;
        if(a%gcd==0)
            down = a;
        else
            down = (a / gcd + 1) * gcd;
        up = b / gcd * gcd;
        if(down<up)
        {
            printf("%lld", gcd);
            return 0;
        }
        gcd--;
    }
    return 0;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

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

#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define rrep(i,a,n) for (int i = a; i >= n; --i)
#define irep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define endl "\n"

typedef long long ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long

long long POW(long long a, long long b) {
	long long ans = 1;
	while (b) {
			if(b & 1) {
					ans = ans * a;
			}
			a = a * a;
			b /= 2;
	}
	return ans;
}

int32_t main() {
  IOS;
	int n, m, t; cin >> n >> m >> t;
	vector<pair<int,int>> a(m + 1);
	for (int i = 1; i <= m; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	int N = n;
	bool ans = 1;
	//debug(a, t);
	a.push_back({t, t});
	//debug(a, t);
	for (int i = 1; i < m + 2; ++i) {
		n -= a[i].first - a[i - 1].second	;
		if (n <= 0) {
			ans = 0;
		}
		//debug(a[i].first, a[i].second, n);
		n += a[i].second - a[i].first;
		n = min(n, N);
		//debug(n);
	}
	if (ans) {
		cout << "Yes";
	}else {
		cout << "No";
	}
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v))
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 1e5+10;

int N, M, K;
set<int> A;

ld dp[2*MAX];

bool check(ld p) {
    fill_n(dp, MAX, 0);
    ld s = 0;
    REPR (i, N) {
        if (A.find(i) == A.end()) dp[i] = 1 + s / M;
        else dp[i] = p;
        s += dp[i];
        s -= dp[i+M];
    }
    return dp[0] > p;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N >> M >> K;
    REP (i, K) {
        int a;
        cin >> a;
        A.insert(a);
        if (A.find(a-M+1) != A.end() && distance(A.find(a-M+1), A.find(a)) == M-1) {
            cout << -1 << endl;
            return 0;
        }
    }

    ld ub = 1;
    while (1) {
        ld ok = 1e-3, ng = ub;
        while (ng - ok > 1e-4) {
            ld mid = sqrtl(ok * ng);
            if (check(mid)) ok = mid;
            else ng = mid;
        }
        if (ub - ok > 1e3) {
            cout << ok << endl;
            return 0;
        }
        ub *= 4;
    }
}


#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <vector>//sort法  昇順 std::sort(v.begin(),v.end()); 降順 std::sort(v.begin(),v.end(),std::greater<int>());
#include <queue>//待ち行列 / 最大値から priority_queue<TYPE> 最小値から priority_queue<TYPE, vector<TYPE>, greater<TYPE>>
#include <stack>//積ん読

typedef long long ll;

#define REP(i, f, t) for(long i=(int)f;i<(int)t;i++)
#define rep(i,t) REP(i,0,t)

#define PInt std::pair<int ,int>
#define PDbl std::pair<double ,double>
#define PLng std::pair<long, long>
#define PLL std::pair<ll, ll>
#define PIDbl std::pair<int , double>
#define PDInt std::pair<double , int>
#define tIII std::tuple<int, int, int>
#define vInt std::vector<int>
#define vDbl std::vector<double>
#define vLng std::vector<long>
#define vLL std::vector<ll>
#define vPInt std::vector<PInt>
#define vPLL std::vector<PLL>

template<typename T1, typename  T2, typename  T3> bool rangeCheck(T1 min, T2 x, T3 max) { return min <= x && x < max; }

/*桁数の指定
//#include<iomanip>
//もう一度桁数を指定するまでこのまま固定される
cout << std::setprecision(3) << 3.1415 << endl;//3.14
*/

/*回転行列の公式
|cosθ, -sinθ||x| = | xcosθ - ysinθ |
|sinθ,  cosθ||y|   | xsinθ + ycosθ |
*/

/*集合の整数表現

空集合φ ................................... 0
i番目の要素のみからなる集合{i} ............. 1 << i
n個の要素すべてからなる集合{0,1,...,n-1} ... (1 << n) -1
要素iがSに含まれるかi∈S ................... if(S>>i & 1)
集合Sに要素iを加えるS∪{i} ................. S | 1<<i
集合Sから要素iを取り除くS＼{i} ............. S & ~(1<<i)
集合Sと集合Tの和集合/共通部分 ... S | T / S & T

-部分集合の列挙方法
std::bitset<sup.size()> sub = sup;
do {
  //部分集合に対する処理
  sub = (sub-1) & sup;
} while(sub != sup); // 0の次は-1&sup=supになる

-サイズkの部分集合の列挙方法
std::bitset<k> = comb((1 << k) -1);
while(comb < 1 << n){
	//ここで組み合わせに対して処理をする
	std::bitset<k> x = comb & -comb, y = comb + x;
	comb = ((comb & ~y) / x >> 1) | y;
}
*/

/*組み合わせ
vector<vLL> comb(int n) {
 vector<vLL> v(n + 1,vLL(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
	v[i][0] = 1;
	v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
	for (int k = 1; k < j; k++) {
	  v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
	}
  }
  return v;
}
*/

using namespace std;

int main(void) {
	int N;
	cin >> N;

	int res = INT_MAX;

	int a, p, x;
	rep(i, N) {
		cin >> a >> p >> x;
		if (a < x) {
			res = min(res, p);
		}
	}

	if (res == INT_MAX) {
		cout << -1 << endl;
	}
	else {
		cout << res << endl;
	}
	return 0;
}
/*
3
3 9 5
4 8 5
5 7 5
8

3
5 9 5
6 8 5
7 7 5
-1

10
158260522 877914575 602436426
24979445 861648772 623690081
433933447 476190629 262703497
211047202 971407775 628894325
731963982 822804784 450968417
430302156 982631932 161735902
880895728 923078537 707723857
189330739 910286918 802329211
404539679 303238506 317063340
492686568 773361868 125660016
861648772

*/

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

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

const ll INF=1e18;

int main(){
    ll n; cin>>n;
    vector<vector<ll>>c(n,vector<ll>(3));
    rep(i,n){
        cin>>c[i][1]>>c[i][0]>>c[i][2];
        c[i][2]-=c[i][1];
    }
    sort(all(c));
    rep(i,n){
        if(c[i][2]>0){
            cout<<c[i][0]<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
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 X,Y;
map<int,int> mp;
int Dfs(int x)
{
	if(x<=X) return X-x;
	if(mp[x]) return mp[x];
	int ans=x-X;
	if(x&1) ans=min(ans,Dfs(x-1)+1),ans=min(ans,Dfs(x+1)+1);
	else ans=min(ans,Dfs(x/2)+1);
	return mp[x]=ans;
}
signed main()
{
	X=read(),Y=read();
	cout<<Dfs(Y)<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
int rd(){
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f*x;
}

int main(){
	vector<int> v={6,10,12,15,18,20,24,30};
	int n;cin>> n;
	if(n==3) cout<<6<<" "<<10<<" "<<15<<'\n';
	else rep(i,1,n)cout<<v[(i-1)%v.size()]+(i-1)/v.size()*30<<" ";
	return 0;
}