#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
int main(void){
    int n;
    cin >> n;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        ll c = b - 2*a + 1;
        cout << (c >=0 ? c*(c+1)/2 : 0) << endl;
    }
    return 0;
}

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

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input();
  vector< int > as(2 * n);
  cin >> as;

  vector< pair<int, int> > vs;
  range(i, 0, 2 * n) {
    vs.emplace_back(as[i], i);
  }

  whole(sort, vs);
  vector< int > bs(2 * n, 1);
  range(i, 0, n) {
    auto [a, idx] = vs[i];
    bs[idx] = -1;
  }

  string ans;
  int s = 0;
  range(i, 0, 2 * n) {
    if (s * bs[i] >= 0) ans += '(';
    else ans += ')';

    s += bs[i];
  }

  cout << ans << endl;
}

signed main() {
  solve();
}


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

#define int long long

int chk(int x) {
	int cur = 1;
	for(int i = 1; true; i++) {
		if(cur > x / 3) return -1;
		cur *= 3;
		if(cur == x) return i;
	}
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	int cur = 1;
	for(int i = 1; true; i++) {
		if(cur > n / 5) {
			cout << -1 << endl;
			return 0;
		}
		cur *= 5;
		if(chk(n - cur) > 0) {
			cout << chk(n - cur) << " " << i << endl;
			return 0;
		}
	}
}

#include "bits/stdc++.h"

#define all_of(x) std::begin(x), std::end(x)
#ifdef _GLIBCXX_DEBUG
    #define debug(x) cerr << #x << ": " << x << endl
#else
    #define debug(x)
#endif

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}
template<typename T>
istream& operator >> (istream& in, vector<T>& v) {
    for(auto& x : v) {
        in >> x;
    }
    return in;
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

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

    unsigned long long N;
    cin >> N;
    vector<unsigned long long> p3 = {1}, p5 = {1};
    while(p3.back() < N) {
        p3.push_back(p3.back() * 3);
    }
    while(p5.back() < N) {
        p5.push_back(p5.back() * 5);
    }
    for(int i = 1; i < int(p3.size()); ++i) {
        for(int j = 1; j < int(p5.size()); ++j) {
            if(p3[i] + p5[j] == N) {
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    cout << "-1\n";

    return 0;
}


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

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
//mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,T y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,T y){if(x>y)x=y;}
inline int read(){
  #define nc getchar()
  bool f=0;int x=0;char c=nc;
  while(c<48)f|=c=='-',c=nc;
  while(c>47)x=x*10+(c^48),c=nc;
  return f?-x:x;
  #undef nc
}

typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll N;int M;

int qp(int a,ll k,int P){
  int res=1;
  for(;k;k>>=1,a=1ll*a*a%P)if(k&1)res=1ll*res*a%P;
  return res;
}

void solve(){
  cin>>N>>M;
  int tp=qp(10%M,N,M);
//  printf("#%d\n",tp);
  int val=qp(10%(M*M),N,M*M);
//  printf("#%d\n",val);
  val=(val-tp+M*M)%(M*M);
  if(val==0){
    puts("0");
  }else{
    cout<<(val/M)%M<<endl;
  }
//  ((10^n-tp)/M)%M;
}

signed main(){
//  int T=read();
//  while(T--)solve();
  solve();
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const ll MAX = 50000000000000;
ll MOD = 1000000007;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll N,M,a;
    cin >> N >> M;
    a = modpow(10,N,M * M);
    a /= M;
    cout << a % M << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s;
    cin>>s;
    ll flag=0;
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if((s[i]>='A'&&s[i]<='Z'))
            {

                flag=1;
                break;
            }
        }
        else
        {
            if((s[i]>='a'&&s[i]<='z'))
            {

                flag=1;
               break;
            }

        }
    }
    if(flag)
    {
        cout<<"No";
    }
    else cout<<"Yes";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(p,n) for(int i=p;i<n;i++)
#define test() int t;cin>>t;while(t-->0)
#define speed ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main()
{

    string s;
    cin>>s;
   bool ans=true;
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]>='A'&&s[i]<='Z')
            ans=false;
        }
        else
        {
             if(s[i]>='a'&&s[i]<='z')
            ans=false;
        }

    }

    if(ans)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  int C[n][n];
  vector<ll> A;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> C[i][j];

  for (int i = 0; i < n; i++) A.push_back(C[0][i]);
  vector<ll> B;
  B.push_back(0);

  ll Bmin = 1000000001;
  bool state = true;
  for (int i = 1; i < n; i++) {
    int j = 0;
    ll sa = C[i][j] - C[i - 1][j];
    while (j < n) {
      if (C[i][j] != C[i - 1][j] + sa) {
        state = false;
        break;
      }
      C[i][j] = C[i - 1][j];
      j++;
    }
    if (state == false) break;
    B.push_back(sa);
    Bmin = min(Bmin, sa);
  }

  if (state) {
    cout << "Yes" << endl;
    if (Bmin < 0) {
      ll absmin = (ll)abs(Bmin);

      for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << B[i] + absmin;
      }

      cout << endl;
      for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << A[i] - absmin;
      }

      cout << endl;
    } else {
      for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << B[i];
      }

      cout << endl;
      for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << A[i];
      }

      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n;cin >> n;
  string s;cin >> s;
  vl a(n+1);rep(i,n+1)cin >> a[i];
  ll k=inf;rep(i,n)chmin(k,abs(a[i+1]-a[i]));
  cout << k <<endl;
  vvl mat(k,vl(n+1));
  vl use(n+1);
  rep(i,k){
    rep(j,n+1){
      mat[i][j]=a[j]/k;
      use[j]+=a[j]/k;
    }
  }
  rep(i,n+1)a[i]-=use[i];
  rep(i,n+1){
    rep(j,a[i]){
      mat[j][i]++;
    }
  }
  rep(i,k){
    rep(j,n+1)cout << mat[i][j] <<" ";cout << endl;
  }
}


#include<bits/stdc++.h>
typedef long long ll;
#define V(a) vector
#define P(a,b) pair
#define A(a) set
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define in insert
#define bp __builtin_popcount
#define ppb pop_back
#define FOR(a,b,c) for(ll(a) = b; a < c; a++)
#define FORN(a,b,c) for(ll(a) = b; a <= c; a++)
#define FOREV(a,b,c) for(ll(a)=b; a > c; a--)
#define FOREVN(a,b,c) for(ll(a)=b; a >= c; a--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;

bool cprime(int x)
{
    if (x == 1)
        return false;
    if (x <= 3)
        return true;
    if (x % 2 == 0 || x % 3 == 0)
        return false;
    for (int i = 5; i <= sqrt(x); i += 6)
        if (x % i == 0 || x % (i + 2) == 0)
            return false;
    return true;
}

bool cpalin(string s)
{
    int n = s.length(), l;
    if (n == 1)
        return true;
    if (n % 2 == 0)
        l = n / 2 - 1;
    else
        l = (n - 1) / 2 - 1;
    for (int i = 0; i <= l; i++)
        if (s[i] != s[n - i - 1])
            return false;
    return true;
}
void sieveOfEratosthenes(int n)
{
    bool arr[n + 1];
    FOR(i, 0, n + 1)
    arr[i] = true;
    for (int i = 2; i * i <= n; i++)
    {
        if (arr[i] == true)
        {
            for (int j = i * i ; j <= n; j += i)
            {
                if (arr[j] == true)
                    arr[j] = false;
            }
        }
    }
}

ll ndivs(ll n)
{
    int N = 1000;
    bool arr[N];
    FOR(i, 0, N)
    arr[i] = true;
    for (int i = 2; i * i <= N; i++)
    {
        if (arr[i] == true)
        {
            for (int j = i * i ; j <= N; j += i)
            {
                if (arr[j] == true)
                    arr[j] = false;
            }
        }
    }

    ll p = 1;
    FOR(i, 2, N)
    {
        if (arr[i] == true && n % i == 0)
        {
            ll m = 0; ll cp = n;
            while (cp % i == 0)
            {
                cp /= i;
                m++;
            }
            p *= (m + 1);
        }
    }
    return p;
}
bool compare( ll a,  ll b) // false return swap
{
    return a > b;
}

ll power( ll a, ll b)
{
    ll p = 1;
    while (b > 0)
    {
        if (b & 1)
            p *= a;
        a *= a;
        b >>= 1;
    }
    return p;
}

string dtobin(ll n)
{
    string s;
    while (n)
    {
        s = to_string((n % 2)) + s;
        n /= 2;
    }
    return s;
}

ll bintod(string s)
{
    ll n = 0;
    FOR(i, 0, s.length())
    if (s[i] == '0')
        continue;
    else
        n += pow(2, (s.length() - 1 - i));
    return n;
}

ll sdigs(ll n)
{
    int s = 0;
    while (n)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

ll fact(ll p)
{
    int x = 1;
    FORN(i, 1, p)
    x *= i;

    return x;
}
ll ncr(ll n , ll r)
{
    ll ans = (fact(n) ) / (fact(r) * fact(n - r));
    return ans;
}

int main() {

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

    ll n;
    cin >> n;
    ll c = 0;
    A(ll) a;
    ll i = 2;
    while (i * i <= n)
    {
        ll p = i * i;
        while (p <= n)
        {
            a.in(p);
            p *= i;
        }
        i++;
    }

    cout << n - a.size();
    return 0;
}

/*  **    ** ******    ****** ****** **     ******    ***
    **    ** **  **    **  ** **  ** **     **  ** *********
    **\../** ******    ****** **  ** ****** **  **    ***
    **    ** ** **     ** **  **  ** **  ** **  **    *****
    **    ** **  ** ** **  ** ****** ****** ******    *****
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define vt vector
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)2e5+5;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	for(auto& a:x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	for(auto& a:x)
		read(a);
}
int n,m;
vector<pair<int,int>>adj[N];
int vis[N];
int label[N];
void dfs1(int u,int pre,int l){
	vis[u]=1;
	label[u]=l;
	if(l==-1){
		label[u]=1;
	}else{
		if(pre==l){
			if(pre==1){
				label[u]=2;
			}else{
				label[u]=1;
			}
		}else{
			label[u]=l;
		}
	}
	for(auto child:adj[u]){
			if(!vis[child.fr]){
				dfs1(child.fr,label[u],child.sc);
			}
	}

}

void _run(){
	read(n,m);
	lp(i,m){
		int x,y,l;
		read(x,y,l);
		adj[x].pb({y,l});
		adj[y].pb({x,l});
	}
	int cnt = 0;
		range(i,1,n){
			vis[i]=0;
		}
		dfs1(1,0,-1);
		range(i,1,n){
			cout<<label[i]<<endl;
		}

}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
	init();
    int t=1;
    // read(t);
    while(t--)_run();

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
// #define int long long

const int MXN = 2e5 + 5, INF = 1e9 + 5;
vector<int> g[MXN], level[MXN];
int timer;
int tin[MXN], tout[MXN];

void dfs(int u, int p, int depth) {
    tin[u] = timer++;
    level[depth].push_back(tin[u]);

    for (const auto &v : g[u]) {
        if (v == p) continue;
        dfs(v, u, depth + 1);
    }

    tout[u] = timer - 1;
}

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

    for (int i = 1; i < N; i++) {
        int p;
        cin >> p;
        p--;

        g[i].push_back(p);
        g[p].push_back(i);
    }

    dfs(0, -1, 0);

    int Q;
    cin >> Q;

    while (Q--) {
        int u, d;
        cin >> u >> d;
        u--;

        auto l = lower_bound(all(level[d]), tin[u]);
        auto r = upper_bound(all(level[d]), tout[u]);

        cout << r - l << "\n";
    }
}

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

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

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
void randinit(){srand((unsigned)time(NULL));}
template <typename T>
struct BIT {
    int n;          // 配列の要素数(数列の要素数+1)
    vector<T> bit;  // データの格納先
    BIT(int n_) : n(n_ + 1), bit(n, 0) {}
    void add(int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[idx] += x;
        }
    }
    T sum(int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[idx];
        }
        return s;
    }
    T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
};
int main(){
    ll N;
    cin >> N;
    vector<vector<ll>> G(N);
    for(ll i = 1;i < N;i++){
        ll a;
        cin >> a;
        G[a - 1].emplace_back(i);
    }
    stack<tuple<ll,ll>> que;
    que.push(make_tuple(0,0));
    ll c = 3;
    vector<ll> Dis(N,-1),S(N),T(N);
    while(!que.empty()){
        ll a = get<0>(que.top());
        ll b = get<1>(que.top());
        que.pop();
        if(Dis[a] != -1) T[a] = c;
        else{
            que.push(make_tuple(a,-1));
            Dis[a] = b;
            S[a] = c;
            for(ll i = 0;i < G[a].size();i++) que.push(make_tuple(G[a][i],b + 1));
        }
        c++;
    }
    ll q;
    cin >> q;
    vector<tuple<ll,ll,ll>> Q(q);
    for(ll i = 0;i < q;i++){
        ll u,d;
        cin >> u >> d;
        Q[i] = make_tuple(d,u - 1,i);
    }
    BIT<ll> tree(N * 2 + 10);
    sort(Q.begin(),Q.end());
    vector<vector<ll>> AAA(N);
    vector<ll> ans(q,0);
    for(ll i = 0;i < N;i++) AAA[Dis[i]].emplace_back(i);
    ll kari = 0;
    for(ll i = 0;i < N;i++){
        for(ll j = 0;j < AAA[i].size();j++){
            tree.add(S[AAA[i][j]],1);
        }
        while(kari < q && get<0>(Q[kari]) == i){
            ans[get<2>(Q[kari])] = tree.query(S[get<1>(Q[kari])],T[get<1>(Q[kari])]);
            //cout<<get<2>(Q[kari])+1<<endl;
            kari++;
        }
        for(ll j = 0;j < AAA[i].size();j++){
            tree.add(S[AAA[i][j]],-1);
        }
    }
    for(ll i = 0;i < q;i++) cout << ans[i] << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;

int main() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vll V(N + 1);
    rep(i,N + 1) {cin >> V[i];}
    ll k = INF;
    rep(i,N) {
        k = min(k,abs(V[i + 1] - V[i]));
    }
    cout << k << endl;
    vector<vll> W(k,vll(N + 1));
    rep(i,N + 1) {
        ll a = V[i]/k;
        rep(j,V[i]%k) {
            W[j][i] = a + 1;
        }
        rep2(j,V[i]%k,k) {
            W[j][i] = a;
        }
    }
    rep(i,k) {
        rep(j,N + 1) {
            cout << W[i][j];
            if (j == N) {cout << endl;}
            else {cout << " ";}
        }
    }
}

#include <bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define ff              first
#define ss              second
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define FOR(i,a)        for(int i=0;i<a;i++)
//#pragma                 GCC optimize("Ofast,no-stack-protector")
//#pragma                 GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma                 GCC optimize("unroll-loops")
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define sss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

//--------------------------code starts here---------------------------------------
const int maxn=1e5+5;
LL arr[maxn];
vector<LL> v,v1;
map<LL,LL> mp;

int main()
{
	int t;
	t=1;
    int test=0;
	//si(t);
	while(t--)
	{
        int n,q;
        sii(n,q);
        Rep(i,1,n)
        {
            sl(arr[i]);
        }
        LL x;
        Rep(i,1,q)
        {
            sl(x);
            v.pb(x);
        }

        v1=v;

        sort(arr+1,arr+n+1);
        sort(v.begin(),v.end());
        LL l,r,cnt=0;
        int idx=0;
        Rep(i,1,n)
        {
            if(idx>=v.size())
                break;
            while(mp[v[idx]]!=0 && idx<v.size())
                idx++;
            if(idx>=v.size())
                break;
            if(i==1)
            {
                if(arr[i]!=1)
                {
                    l=1;
                    r=arr[i]-1;
                }
                else
                    continue;
            }
            else
            {
                l=arr[i-1]+1;
                r=arr[i]-1;
            }
            if(l>r)
                continue;
            cnt+=(r-l+1);

            while(l<=r)
            {
                if(v[idx]<=cnt)
                    l=v[idx]+i-1;
                else
                    break;

                if(l>r)
                    break;
                if(idx>=v.size())
                    break;
                mp[v[idx]]=l;
                idx++;
            }
        }

        while(idx<v.size())
        {
            while(mp[v[idx]]!=0 && idx<v.size())
                idx++;
            l=v[idx]+n;
            mp[v[idx]]=l;
        }
        for(int i=0;i<v1.size();i++)
        {
            printf("%lld\n",mp[v1[i]]);
        }
	}

	return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#define inf 2147483647
#define IosF ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
#define N 1000010
#define PNO cout<<"NO\n";
#define PYES cout<<"YES\n"
#define lowbit(x) (x&(-x))

int main() {
    IosF;
    string a, b;
    cin >> a >> b;
    if( a[0] == 'Y' ) cout << (char)(b[0] - 32) << endl;
    else cout << b << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std ;
int main() {
    int n , y;
    cin>> n >> y  ;

    cout<< n/y ;

    return 0;
}


#pragma GCC optimization ("O3")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define ll long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll M = 1e9 + 7;

int main()
{
    fast

    string s;
    deque<char> v;
    cin >> s;
    int c = 0;
    for(auto x : s)
    {
        if(x == 'R')c ^= 1;
        else
        {
            if(c == 1)v.push_front(x);
            else v.push_back(x);
        }
    }
    if(v.empty())return 0;
    if(c)reverse(v.begin(), v.end());
    vector<char> t;
    for(int i = 0; i < v.size(); i++)
    {
        int cnt = 0;
        char cc = v[i];
        while(i < v.size() && v[i] == cc)i++, cnt++;
        i--;
        if(cnt % 2)t.push_back(cc);
        while(t.size() > 1 && t.back() == t[t.size() - 2])t.pop_back(), t.pop_back();
    }

    for(auto x : t)cout << x;
}

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

int main() {
    using ll = long long;
    int n;
    cin >> n;
    n *= 2;
    vector<pair<ll, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(a.begin(), a.end());

    vector<int> color(n);

    for (int i = 0; i < n; i++) {
        color[a[i].second] = i < n / 2;
    }

    vector<char> s(n);
    stack<pair<int, int>> st;

    for (int i = 0; i < n; i++) {
        if (st.size() == 0) {
            st.push({i, color[i]});
        } else {
            auto p = st.top();
            if (p.second != color[i]) {
                st.pop();
                s[p.first] = '(';
                s[i] = ')';
            } else {
                st.push({i, color[i]});
            }
        }
    }

    for (int i = 0; i < n; i++) cout << s[i];
    cout << endl;
}


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

struct STATE{

};

void init(STATE& state){

}

void modify(STATE& state){

}

int main(){
    rep(i,1000){
        int si,sj,ti,tj;
        cin>>si>>sj>>ti>>tj;
        string path;
        if(si<=ti) rep(j,ti-si) path+='D';
        else rep(j,si-ti) path+='U';
        if(sj<=tj) rep(j,tj-sj) path+='R';
        else rep(i,sj-tj) path+='L';
        cout<<path<<endl;
        flush(cout);
        int a;
        cin>>a;
    }
}


///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           nd(a,b,c)                   mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=2e18;
const int mod=1e9+7;
const int M=3005;

inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n;
int a[M],pre[M];

int dp[M][M];

int sum[M],nxt[M];

 main()

{
    fast
    cin>>n;
    f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1];

    rf(k,n,1)
    {
        f(pos,1,n)
        {
            int val=pre[pos-1]%k;

            sum[val]=sub(sum[val],dp[pos][k+1]);

            dp[pos][k]=sum[val];

            int z=pre[n]-pre[pos-1];
            z=z%k;

            if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod;

            if(k!=1){

            val=pre[pos-1]%(k-1);
            nxt[val]=ad(nxt[val],dp[pos][k]);

            }
        }

        f(j,0,k+1)
        {
            sum[j]=nxt[j];
            nxt[j]=0;
        }
    }

    cout<<dp[1][1]<<"\n";
    return 0;

}

#include<cstdio>
#define MOD 1000000007
#define MAXK 3000

int n;
long long a[MAXK + 5];
long long s;
int dp[MAXK + 5][MAXK + 5];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (int j = n; j >= 2; j--) {
      dp[s % j][j] += dp[s % (j - 1)][j - 1];
      dp[s % j][j] %= MOD;
    }
    dp[0][1] = 1;
    s += a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[s % i][i];
    ans %= MOD;
  }
  printf("%d\n", ans);
}


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

ll mod = 998244353;

//Unionfind
struct unionfind {
	//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
	//そうでなければ親のid
	  vector<int> r;
	  unionfind(int N) {
		    r = vector<int>(N, -1);
	  }
	  int root(int x) {
		    if (r[x] < 0) return x;
		    return r[x] = root(r[x]);
	  }
	  bool unite(int x, int y) {
		    x = root(x);
		    y = root(y);
		    if (x == y) return false;
		    if (r[x] > r[y]) swap(x, y);
		    r[x] += r[y];
		    r[y] = x;
		    return true;
	  }
	  int size(int x) {
		    return max(-r[root(x)],0);
	  }

  // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll N; cin >> N;
    //main関数内で
    unionfind pts(N+2);
  //などと宣言し  friends.unite(a,b);
  //のように使う
    ll x[N],y[N];
    rep(i,N){
        cin >> x[i] >> y[i];
    }
    vector<tuple<double,int,int>> dist;
    rep(i,N){
        dist.push_back(make_tuple(100-y[i],i,N));
        dist.push_back(make_tuple(y[i]+100,i,N+1));
    }
    rep(i,N){
        for(int j=1+i;j<N;j++){
            double d = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            dist.push_back(make_tuple(d,i,j));
        }
    }
    sort(dist.begin(),dist.end());
    double ans = 0;
    for(auto q:dist){
        double s = get<0>(q);
        int i = get<1>(q); int j = get<2>(q);
        pts.unite(i,j);
        if(pts.same(N,N+1)){
            ans = s/2; break;
        }
    }
    cout << setprecision(15) << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
template <typename T> using triple = std::tuple<T, T, T>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(17);

  int n;
  cin >> n;
  vector<int> X(n), Y(n);
  for(int i = 0; i < n; i++) {
    cin >> X[i] >> Y[i];
  }

  vector<triple<int>> edges;
  int st = n, en = n + 1;

  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      int dx = X[i] - X[j], dy = Y[i] - Y[j];
      int d = dx * dx + dy * dy;
      edges.emplace_back(d, i, j);
    }
    int top = Y[i] + 100, bottom = 100 - Y[i];
    top *= top, bottom *= bottom;
    edges.emplace_back(top, st, i);
    edges.emplace_back(bottom, i, en);
  }
  sort(edges.begin(), edges.end());

  vector<int> p(n + 2), si(n + 2, 1);
  iota(p.begin(), p.end(), 0);

  auto trace = [&](int u) {
    while(u != p[u]) u = p[u] = p[p[u]] = p[p[p[u]]] = p[p[p[p[u]]]];
    return u;
  };

  auto unite = [&](int u, int v) {
    if((u = trace(u)) != (v = trace(v))) {
      if(si[u] > si[v]) swap(u, v);
      p[u] = v;
      si[v] += si[u];
    }
  };

  for(auto [d, x, y] : edges) {
    unite(x, y);
    if(trace(st) == trace(en)) {
      cout << sqrt(d) / 2 << '\n';
      return 0;
    }
  }
  assert(false);
}


#include <bits/stdc++.h>

#define ll long long
#define rep(j,i,n) for(int i=j;i<n;i++)

using namespace std;

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

	int n,k; cin>>n>>k;

	vector<vector<ll>> v(n,vector<ll>(n));
	rep(0,i,n)rep(0,j,n) cin>>v[i][j];

	ll l = -1, r = 1e9 + 10;
	while (r - l > 1)
	{
		ll mid = (r + l) / 2;

		vector<vector<ll>> csum(n+1,vector<ll>(n+1, 0));
		rep(0,i,n)rep(0,j,n)
			csum[i+1][j+1] = csum[i+1][j] + csum[i][j+1] - csum[i][j] + (v[i][j] > mid);

		int cnt;
		rep(0,i,n-k+1)rep(0,j,n-k+1)
		{
			cnt = csum[k+i][k+j] - csum[k+i][j] - csum[i][j+k] + csum[i][j];
			if (cnt < ((k * k) / 2 + 1))
				r = mid;
		}
		if (r != mid)
			l = mid;
	}
	cout << r << "\n";
}

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PI 3.14159265358979323846

int arr[801][801];
int dp[801][801];

int main()
{
	int n, k, left, right, mid, ans, temp;
	bool check;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &arr[i][j]);
	temp = k * k / 2;
	ans = 1e9;
	left = 0;
	right = 1e9;
	while (left <= right)
	{
		mid = (left + right) / 2;
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
			{
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
				if (arr[i][j] > mid)
					dp[i][j]++;
			}
		check = false;
		for (int i = k; i <= n; i++)
			for (int j = k; j <= n; j++)
			{
				if (dp[i][j] - dp[i - k][j] - dp[i][j - k] + dp[i - k][j - k] <= temp)
					check = true;
			}
		if (check)
		{
			ans = min(ans, mid);
			right = mid - 1;
		}
		else
			left = mid + 1;
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		if(n&1)printf("Second\n");
		else{
			sort(a,a+n);
			int f=1,c=1;
			for(int i=1;i<n;i++){
				if(a[i]==a[i-1])c++;
				else{
					if(c&1)f=0;
					c=1;
				}
			}
			if(c&1)f=0;
			if(f)printf("Second\n");
			else printf("First\n");
		}
	}
}

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll len(vector<PL> &ar, ll kg){
    int l = ar.size();
    if (kg < ar[0].first) return 0LL;
    if (kg >= ar[l-1].first) return ar[l-1].second;
    int le = 0;
    int ri = l-1;
    int mid = (le + ri) / 2;
    while (true){
        if (ar[mid].first <= kg && kg < ar[mid+1].first) return ar[mid].second;
        if (kg < ar[mid].first) ri = mid;
        else le = mid;
        mid = (le + ri) / 2;
    }
}

int main(){
    int t; cin >> t;
    vector<string> ans(t);
    rep(i,t){
        int n; cin >> n;
        map<int,int> m;
        map<int,int> ::iterator ite;;
        rep(i,n){
            int a; cin >> a;
            if (m.find(a) == m.end()) m[a] = 1;
            else m[a]++;
        }
        if (n % 2 == 1) ans[i] = "Second";
        else {
            bool t = true;
            for (ite = m.begin(); ite != m.end(); ite++){
                if (ite->second % 2 == 1) t = false;
            }
            if (t) ans[i] = "Second";
            else ans[i] = "First";
        }
    }
    rep(i,t) cout << ans[i] <<endl;
}


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

#define ff first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

const int M = 1e9+7;
const int inf = 1e9;
const int mx  = 1e7+5;

ll a[mx], f[mx];
ll power(ll x, ll p){
    ll ans = 1;
    while(p > 0){
        if(p & 1) ans = (ans * x) % M;
        x = (x * x) % M; p >>= 1;
    }return ans;
}

ll inv(ll x){return power(x,M-2);}
ll ncr(ll x, ll y){
    if(y > x) return 0;

    ll ans = 1;
    for(ll r=1; r<=y; r++){
        ans = (ans * (x - r + 1)) % M;
        ans = (ans * inv(r)) % M;
    }return ans;
}

void solve(int cs){
//    cout << "Case " << cs << ": ";

    f[0] = 1;
    for(int i=1; i<mx; i++)
        f[i] = (i * 1LL * f[i-1]) % M;

    ll n, m; cin >> n >> m; ll sum = n;
    for(int i=0; i<n; i++)
        cin >> a[i], sum += a[i];
    cout << ncr(m+n, sum) << "\n";
}

int main(){

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

    int tc = 1, cs = 1;
//    cin >> tc;
    while(tc--) solve(cs++);

    return 0;
}

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

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

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

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

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

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

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

void solve() {
	int n, m; cin >> n >>m;
	vector<int> a(n);
	int sum = 0;
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	if (sum > m) {
		cout << 0 << "\n"; return;
	}
	modint ans = 1;
	int ad = n;
	//(m+n,sum+n)
	rep1(i, sum + n) {
		ans = ans*(modint)(m + n + 1 - i);
		ans = ans / (modint)(i);
	}
	cout << ans << "\n";
}

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


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

int main() {
  ll N; cin >> N;
  while(N % 2==0) N /=2;
  ll sN = sqrt(N), ans =0;
  for (int i =1; i<=sN; i++) {
    if (N % i ==0) ans +=2;
  }
  if (sN * sN == N) ans--;
  ans *= 2;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1000000000;
constexpr ll llINF = 1000000000000000000;
constexpr int mod = 998244353;
constexpr double eps = 1e-10;
const double pi = acos(-1);
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int Random(int mi, int ma) {
    random_device rnd;
    mt19937 mt(rnd());  // 32bit
    //[mi,ma]
    uniform_int_distribution<int> engine(mi, ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}
vector<int> primes;
void init_prime(int n) {
    primes.push_back(2);
    for (int i = 3; i <= n; i += 2) {
        bool f = true;
        for (int j : primes) {
            if (j * j > i) break;
            if (i % j == 0) {
                f = false;
                break;
            }
        }
        if (f) primes.push_back(i);
    }
}
ll modpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return res;
}
vector<ll> inv, fact, factinv;
void init_fact(int n) {
    inv.resize(n + 1);
    fact.resize(n + 1);
    factinv.resize(n + 1);
    inv[0] = 0;
    inv[1] = 1;
    fact[0] = 1;
    factinv[0] = 1;
    for (ll i = 1; i <= n; i++) {
        if (i >= 2) inv[i] = mod - ((mod / i) * inv[mod % i] % mod);
        fact[i] = (fact[i - 1] * i) % mod;
        factinv[i] = factinv[i - 1] * inv[i] % mod;
    }
}
ll _inv(ll a, ll m = mod) {
    // gcd(a,m) must be 1
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll comb(int a, int b) {
    if (a < b) return 0;
    if (a < 0) return 0;
    return fact[a] * factinv[a - b] % mod * factinv[b] % mod;
}
struct UnionFind {
    vector<int> par, siz, es;
    UnionFind(int x) {
        par.resize(x);
        siz.resize(x);
        es.resize(x);
        rep(i, x) {
            par[i] = i;
            siz[i] = 1;
            es[i] = 0;
        }
    }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) {
            es[x]++;
            return;
        }
        if (siz[x] < siz[y]) swap(x, y);
        par[y] = x;
        siz[x] += siz[y];
        es[x] += es[y] + 1;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return siz[find(x)]; }
    int edges(int x) { return es[find(x)]; }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a[300010];
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 1LL * n * (n - 1) / 2;
    for (auto [num, cnt] : mp) ans -= 1LL * cnt * (cnt - 1) / 2;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

// segment tree struct
template<class in_seg>
struct segtree {
    in_seg op(in_seg x, in_seg y) {return min(x,y);} // モノイド演算
    in_seg e = inf;       // 元(+→0, *→1, xor→0, max→-inf, min→inf, gcd→0 : e●a==a●e==a)
    ll len = 1LL;     // セグメントの長さ
    ll N;
    vector<in_seg> dat;

    segtree(ll n) {init_seg(n);}
    segtree(vector<in_seg> vec) {init_seg(vec);}

    void init_seg(ll n) {
        N = n;
        while (len<N) {len *= 2;}
        dat.resize(2*len,e);
    }
    void init_seg(vector<in_seg> vec) {
        N = vec.size();
        init_seg(N);
        rep(i,N) dat[i+len] = vec[i];
        for (ll i=len-1; i>=1; i--) dat[i] = op(dat[2*i],dat[2*i+1]);
    }

    // dat[id]に x を代入
    void set(ll id, in_seg x) {
        id += len;
        dat[id] = x;
        while (id>0) {
            id /= 2;
            dat[id] = op(dat[2*id],dat[2*id+1]);
        }
    }

    // dat[id]を返す O(1)
    in_seg get(ll id) {id += len; return dat[id];}

    // op(a[l],...,a[r-1])を計算して返す。l==rの時は e を返す O(logN)
    in_seg prod(ll l, ll r) {
        l += len; r += len;
        in_seg res = e;
        while (l<r) {
            if (l%2) {res = op(res,dat[l]); l++;}
            l /= 2;
            if (r%2) {res = op(res,dat[r-1]); r--;}
            r /= 2;
        }
        return res;
    }

    in_seg all_prod() {return dat[1];}
};

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

    vector<ll> cnt(N);
    segtree<ll> seg(N+1);
    rep(i,seg.len) seg.set(i,i);
    rep(i,M) {
        ll a = A[i];
        cnt[a]++;
        seg.set(a,inf);
    }

    ll ans = inf;
    for (ll i=M-1; i<N; i++) {
        chmin(ans,seg.all_prod());
        if (i==N-1) break;
        ll l = A[i-M+1], r = A[i+1];
        cnt[l]--;
        cnt[r]++;
        if (cnt[l]==0) seg.set(l,l);
        seg.set(r,inf);
    }

    Cout(ans);
}

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

#define f first
#define s second
#define pb push_back
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define db(x) cout << '>' << #x << ':' << x << endl;
#define sz(x) ((int)(x).size())
#define newl cout << "\n"

#define ll long long int
#define vi vector<int>
#define vll vector<long long>
#define vvll vector<vll>
#define pll pair<long long, long long>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

const ll MODN = 998244353;

ll tc, n, m, k;

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

  ll modn;
  cin>>n>>k>>modn;

  auto add = [&](ll x, ll y) {
    x += y;
    if(x >= modn) x-=modn;
    return x;
  };

  auto sub = [&](ll x, ll y){
    x -= y;
    if(x < y) x += modn;
    return x;
  };
  ll M = 101*100*100 + 1;
  vvll dp(n+1, vll(M, 0));
  dp[0][0] = 1;
  rep(i, 1, n+1) {
    rep(sum, 0, M+1) {
      ll lo = sum;
      ll hi = sum + (k+1)*i;
      dp[i][lo] = add(dp[i][lo], dp[i-1][sum]);
      if(hi < M) {
        dp[i][hi] = sub(dp[i][hi], dp[i-1][sum]);
      }
      if(sum-i >= 0) {
        dp[i][sum] = add(dp[i][sum], dp[i][sum-i]);
      }
    }
  }

  rep(i, 1, n+1) {
    ll ans = 0;
    rep(sum, 0, M+1) {
      ans = (ans + dp[i-1][sum]*dp[n-i][sum])%modn;
    }
    ans = (ans*(k+1) -1)%modn;
    cout<<ans;
    newl;
  }

  return 0;
}


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

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

#include <bits/stdc++.h>

using namespace std;

int main()
{
   char C1,C2,C3;
   cin>>C1>>C2>>C3;
   if (C1==C2&&C2==C3){
    cout<<"Won";
   }else{
      cout<<"Lost";
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
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 mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353//1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1000000000000000
#define N 500005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve()
{
    int n,m;
    cin>>n>>m;
    int a[n][m];
    int sum=0,mn=INF;
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            cin>>a[i][j];
            mn=min(mn,a[i][j]);
            sum+=a[i][j];
        }
    }
    cout<<(sum - (n*m*mn))<<endl;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tests;
   //cin>>tests;
   tests=1;
   for(int i=0;i<tests;i++)
   {
       solve();
   }
}

#include <bits/stdc++.h>
using namespace std;
//const int mod = (int)1e9+7;
#define int long long
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
  //  vecto<vector<int>>arr(h, vector<int>(w));
    int total = 0;
    int m = 200;
    for (int i = 0; i < h; i++){
    	for (int j = 0; j < w; j++){
    		int x;
    		cin >> x;
    		total += x;
    		m = min(m, x);
    	}
    }
    cout << total - (m*h*w) << "\n";
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

#pragma region macros
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#pragma endregion macros

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

using ll    = long long;
using R     = long double;
const R EPS = 1e-9L;  // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) {
    return (r > EPS) - (r < -EPS);
}
inline R sq(R x) {
    return sqrt(max(x, 0.0L));
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void) {
    int a, b;
    cin >> a >> b;

    const int d = b - a;

    int ans = 1;
    rep(i, 2, d + 1) {
        const int fa = (a + (i - a % i) % i);
        const int fb = (b - b % i);
        if (fa < fb) {
            chmax(ans, i);
        }
    }

    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <iostream>

using namespace std;

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

	for (int i = B-A; i > 0; i--) {
		int gA = (A + i - 1) / i;
		int gB = B / i;
		if (gA < gB) {
			cout << i << endl;
			return 0;
		}
	}
}


#include<bits/stdc++.h>
#define pb           push_back
#define mp           make_pair
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define PI 3.14159265 /// tan inverse = atan(value)*(180/PI)

#define ms(a,b)            memset(a, b, sizeof(a))
#define lp(i,a,b) for (int i = a; i <= b; i++)
#define pii                pair <int,int>

#define SL(a)              scanf("%I64d",&a)
#define SLL(a,b)           scanf("%I64d %I64d",&a,&b)
#define PL(x) printf("%I64d\n",(x))
#define PLL(x,y) printf("%I64d %I64d\n",x,y)

#define S(a)              scanf("%d",&a)
#define SS(a,b)           scanf("%d %d",&a,&b)
#define P(x) printf("%d\n",(x))
#define PP(x,y) printf("%d %d\n",x,y)
using namespace std ;
typedef long long ll ;
const int imin = 1e9+100;
const ll maxx = 3e5+10,mod=1e9+7,imax=1e18+10;
ll dp[maxx];
map < ll ,ll > pq ;
int main()
{
   ll n,p=0,ans=0;
   cin >> n ;
   for(int i=1;i<=n;i++)
   {
       ll x ;
       cin >> x ;
       if(i%2==1){x=-x;}
       p+=x;
       ans+=(pq[p]);
       if(p==0){ans++;}
       pq[p]++;
   }
   cout << ans << endl;
   return 0 ;
}

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

typedef long long ll;

typedef pair<int, int> P;
struct edge { int to, cost; };

const int MAX_V =3000000;
const int INF = 1<<30;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    rep(i, M) cin >> A[i] >> B[i];
    int K;
    cin >> K;
    vector<int> C(K);
    rep(i, K) cin >> C[i];
    V = N;
    rep(i, M) {
        G[A[i] - 1].push_back({B[i] - 1, 1});
        G[B[i] - 1].push_back({A[i] - 1, 1});
    }
    vector<vector<ll>> d2(K, vector<ll>(K));
    rep(i, K) {
        dijkstra(C[i] - 1);
        rep(j, K) {
            d2[i][j] = d[C[j] - 1];
            //cout << d2[i][j] << " ";
        }
        //cout << "\n";
    }
    V = 1 + K * (1 << K) + 1;
    rep(i, V) G[i] = {};
    rep(i, K) {
        G[0].push_back({1 + (1 << i) * K + i, 0});
        G[V - i - 2].push_back({V - 1, 0});
    }
    rep(i, (1 << K) - 1) {
        rep(j, K) {
            rep(k, K) {
                if (i & (1 << k)) continue;
                G[1 + i * K + j].push_back({1 + (i | (1 << k)) * K + k, d2[j][k]});
            }
        }
    }
    dijkstra(0);
    ll ans = d[V - 1] + 1;
    if (ans == INF + 1) ans = -1;
    cout << ans << "\n";
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)n;i++)
const ll mod = 1e9+7 ;
const ll INF = 1e18 ;
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}

ll f(ll n, ll k) {
    ll count = 1;
    rep(i,k) {
        count *= (n - i);
        count /= i + 1;
    }
    return count;
}

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    ll ab = a + b;
    string s;
    ll t = ab - 1;
    bool ok = false;
    for(int i = 0; i < ab; i++) {
        ll count = f(t, a - 1);
        if(count >= k) {
            s.push_back('a');
            a--;
            t--;
        }
        else {
            s.push_back('b');
            k -= count;
            b--;
            t--;
        }
        if(a == 0 || b == 0) {
            ok = true;
            break;
        }
    }
    if(ok) {
        if(a == 0) {
            rep(i,b) s.push_back('b');
        }
        if(b == 0) {
            rep(i,a) s.push_back('a');
        }
    }
    cout << s << endl;
}

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

int main() {
  double ofs = 0.0001;
  int N, D, H;
  cin >> N >> D >> H;
  vector<int> dlist(N);
  vector<int> hlist(N);
  for (int i = 0; i < N; i++) {
      cin >> dlist.at(i) >> hlist.at(i);
  }
  double ans = 0.0;
  for (int i=0;i<N;i++) {
      double tmp = (double)(D*hlist.at(i)-H*dlist.at(i))/(D-dlist.at(i));
      if (tmp > ans) {
          ans = tmp + ofs;
      }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

using namespace atcoder;

void solve(){
    int n, m;
    cin >> n >> m;
    if(n == 1 && m == 0){
        cout << "1 2" << endl;
        return;
    }
    if(m < 0 || m >= n - 1){
        cout << - 1 << endl;
    }else{
        // it possible
        for(int i = 0 ; i < n - 1 ; i++){
            int l = 4 * i + 2;
            int r = l + 2;
            cout << l << " " << r << "\n";
        }
        // T has n - 1
        // A
        int l = 1;
        int r = 4 * m + 3;
        cout << l << " " << r << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define IL inline
#define reg register
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

LL T,l,r,x,y,z,cnt,Ans;

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	T=read();
	while (T--){
		l=read();	r=read();
		if ((l<<1) > r)	{
			puts("0");
			continue;
		}
		x=r-(l<<1)+1;
		Ans=x*(x+1)>>1;
		printf("%lld\n",Ans);
	}
	return 0;
}

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

const long long MAXVAL = (long long) 1e18 + 1;
//const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;

ll poww(ll x, ll pow, ll mod) {
  if (pow == 0ll ) return 1ll;
  if (pow == 1ll) return x % mod;
  ll ans = poww(x, pow >> 1, mod);
  ans = (ans * ans) % mod;
  if ((pow & 1) == 1) {
    ans = (ans * x) % mod;
  }
  return ans % mod;
}

ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  //cin >> q;
  while (q-- >0) {
    int x, y;
    cin >> x >> y;
    if (x < y) swap(x, y);
    if (y + 3 > x) {
      cout << "Yes\n";
    } else cout << "No\n";
  }

  return 0;
}


#include <bits/stdc++.h>
/* #include <atcoder/all> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int 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 VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    cin >> n;
    vint p(n);
    cin >> p;
    vector<bool> memo(200000+2, true);
    set<int> se;
    REP(i,200000+2) {
        se.insert(i);
    }
    REP(i,n) {
        if (se.find(p[i]) != se.end()) {
            se.erase(p[i]);
        }
        int ans = *se.begin();
        cout << ans << endl;
    }
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

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

	set<int> st;
	for (int i = 0; i <= 200000; i++) st.insert(i);

	int n;
	cin >> n;
	while (n--) {
		int p;
		cin >> p;
		st.erase(p);
		cout << *st.begin() << '\n';
	}
}


// AtCoder Templete

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define lloop(i, r, n) for (int i = (r) - 1; i >= 0; i--)
#define all(in) in.begin(),in.end()
#define pb push_back
#define fi first
#define se second

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

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using dd = double;
using ldd = long double;

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<dd,dd>;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

using vb = vector<bool>;
using vs = vector<string>;
using vdd = vector<dd>;
using vldd = vector<ldd>;

using pq = priority_queue<int, vector<int>, less<int>>; // 降順に取り出す
using pqq = priority_queue<int, vector<int>, greater<int>>; // 昇順に取り出す

// const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int INF = 1e9;
const ll inf = 4e18;

const int MAX = 300300;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; // 階乗
    finv[0] = finv[1] = 1; // 階乗の逆元
    inv[1] = 1; // 逆元
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = ( MOD - inv[MOD%i] * (MOD/i) % MOD ) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long PER(int n, int k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * finv[n - k] % MOD;
}

ll modpow(ll a, ll n, ll p) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll p) { return modpow(a, p-2, p); }

vector<pair<ll,ll>> prime(ll n) {
    vector<pair<ll,ll>> res;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        ll count = 0;
        while (n % i == 0) { count++; n /= i; }
        res.push_back( make_pair(i,count) );
    }
    if (n != 1) res.push_back( make_pair(n,1) );
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(10）<<  << endl;
    COMinit();

    /* write code under here */
    ll r, x, y; cin >> r >> x >> y;
  	if ( r * r == x * x + y * y ) {
      cout << 1 << endl;
      return 0;
    }
    for ( ll i = 2ll; i < 200200; i++) {
      	ll ii = i * r;
        if ( ii * ii >= x * x + y * y ) {
            cout << i << endl;
            return 0;
        }
    }
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,b,x,y;
    ll r;
    cin>>r>>a>>b;
    x=(a*a+b*b);
    ll t=ceil(sqrt((double)x));
    if(r==t) cout<<"1";
    else if(t<=(2*r)) cout<<"2";
    else cout<<ceil((double)t/r);

    return 0;
}


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

long long cur[101][10001], pre[101][10001];
long long MOD = 998244353;
int main() {
    int N; cin >> N;
    vector<int> W(N);
    for(int i = 0; i < N; i++) {
        cin >> W[i];
    }
    pre[0][0] = 1LL;

    int sum = 0;
    for(int i = 0; i < N; i++)
        sum += W[i];
    for(int i = 1; i <= N; i++) {
        for(int make = 0; make <= sum; make++) {
            for(int use = 0; use <= N; use++) {
                cur[use][make] = pre[use][make];
                if(W[i - 1] <= make && use > 0)
                    cur[use][make] += pre[use - 1][make - W[i - 1]];
                if(cur[use][make] > MOD) cur[use][make] -= MOD;
            }
        }
        for(int make = 0; make <= sum; make++)
            for(int use = 0; use <= N; use++)
                pre[use][make] = cur[use][make];
    }
    vector<long long> f(N + 1);
    f[0] = 1LL;
    for(int i = 1; i <= N; i++)
        f[i] = f[i - 1] * 1LL * i % MOD;
    long long ans = 0LL;
    if(sum % 2) {
        cout << 0 << "\n";
        return 0;
    }
    for(int use = 0; use <= N; use++) {
        ans += f[use] * 1LL * f[N - use] % MOD * pre[use][sum / 2] % MOD;
        ans %=  MOD;
    }
    if(ans < 0) ans += MOD;
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int maxN = 1005;
int fib[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n == 2) {
        cout << 1;
        return 0;
    }
    if (cab == 'A') {
        if (caa == 'A') {
            cout << 1;
            return 0;
        }
        if (cba == 'A') {
            n -= 3;
            fib[0] = 1;
            fib[1] = 2;
            for (int i = 2; i <= n; i++) {
                fib[i] = (fib[i - 2] + fib[i - 1]) % mod;
            }
            cout << fib[n];
            return 0;
        }
        else {
            int ans = 1;
            n -= 3;
            for (int i = 1; i <= n; i++) ans = (1LL * ans * 2) % mod;
            cout << ans;
            return 0;
        }
    }
    else {
        if (cbb == 'B') {
            cout << 1;
            return 0;
        }
        if (cba == 'B') {
            n -= 3;
            fib[0] = 1;
            fib[1] = 2;
            for (int i = 2; i <= n; i++) {
                fib[i] = (fib[i - 2] + fib[i - 1]) % mod;
            }
            cout << fib[n];
            return 0;
        }
        else {
            int ans = 1;
            n -= 3;
            for (int i = 1; i <= n; i++) ans = (1LL * ans * 2) % mod;
            cout << ans;
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100005
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,-1,1};

struct Edge{
    int to;
    int cost;
};

vector<Edge>G[2005];
 int n,m;
void dijkstra(int v,vector<ll>&dist){
    dist[v]=0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> >Q;

    Q.push(make_pair(0,v));
    while(!Q.empty()){
        auto p=Q.top();
        Q.pop();
        int from =p.second;
        if(dist[from]<p.first) continue;
        for(int i=0;i<G[from].size();i++){
            Edge e=G[from][i];
            if(dist[e.to]>dist[from]+e.cost){
                dist[e.to]=dist[from]+e.cost;
                Q.push(make_pair(dist[e.to],e.to));
            }
        }
    }
    ll ans=INF;
    rep(j,n){
        for(auto a:G[j]){
            if(a.to==v) ans=min(ans,dist[j]+a.cost);
        }
    }
    if(ans==INF) ans=-1;
    cout <<ans<<endl;
}

int main(){

    cin >>n>>m;
    rep(i,m){
        int a,b,c;
        cin >>a>>b>>c;
        a--;b--;
        G[a].push_back((Edge){b,c});
    }

    rep(i,n){
        vector<ll>dist(n,INF);
        dijkstra(i,dist);
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deb(x) cout << #x << " " << x << endl;
#define mod 1000000007
#define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define endl "\n"

const ll INF = 1e18;
const ll NEGINF = -1 * INF;

/*NOTES: Take care of ll vs int
         Never use an iterator after erasing it
*/

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<array<ll, 2>> adjList[n];
    vector<ll> c(m);
    vector<ll> d(m);
    ll a, b;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b >> c[i] >> d[i];
        a--;
        b--;
        adjList[a].push_back({b, i});
        adjList[b].push_back({a, i});
    }
    priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> q;
    vector<ll> dist(n, LONG_LONG_MAX);
    dist[0] = 0;
    q.push({0, 0});
    set<int> processed;
    while (!q.empty())
    {
        array<ll, 2> curr = q.top();
        q.pop();

        if (processed.find(curr[1]) != processed.end())
        {
            continue;
        }
        for (array<ll, 2> v : adjList[curr[1]])
        {
            int vertex = v[0];
            int edgeInd = v[1];
            ll optimum = sqrt(d[edgeInd]);
            ll timeToReachV = dist[curr[1]] + c[edgeInd] + (d[edgeInd] / (dist[curr[1]] + 1));
            for (ll choice = max(dist[curr[1]], optimum - 10); choice < optimum + 10; choice++)
            {
                timeToReachV = min(timeToReachV, choice + c[edgeInd] + (d[edgeInd] / (choice + 1)));
            }
            if (dist[vertex] > timeToReachV)
            {
                dist[vertex] = timeToReachV;
                q.push({dist[vertex], vertex});
            }
        }
        processed.insert(curr[1]);
    }
    if (dist[n - 1] == LONG_LONG_MAX)
    {
        cout << -1 << endl;
        return;
    }
    cout << dist[n - 1] << endl;
}

int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin);
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout);
#endif
    int T = 1;
    while (T--)
    {
        solve();
    }
    //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
    return 0;
}


#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int mod = 998244353;
const int maxn = 2e5 + 30;
const int maxm = 5e3 + 7;
ll frac[maxn], inv[maxn];
ll dp[maxm][maxm], inp[maxm][maxm];

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

void init(){
    frac[0] = 1;
    for (int i=1; i<maxn; i++){
        frac[i] = frac[i-1] * i;
        frac[i] %= mod;
    }
    inp[0][0] = inp[1][0] = inp[1][1] = 1;
    for (int i=2; i<maxm; i++){
        inp[i][0] = 1;
        for (int j=1; j<=i; j++)
            inp[i][j] = (inp[i-1][j] + inp[i-1][j-1]) % mod;
    }
}

ll C(ll n, ll m){
//    cout << frac[n] << " " << power(frac[m], mod-2) << " " << power(frac[n-m], mod-2) << endl;
//    return frac[n] % mod * power(frac[m], mod-2) % mod * power(frac[n-m], mod-2) % mod;
        return inp[n][m];
}

int main(){
    init();
    ll n, m; scanf("%lld%lld", &n, &m);
    ll l = log2(m);
    for (int i=0; i<=m; i+=2) dp[0][i] = C(n, i);
    for (int i=1; i<=l; i++) dp[i][0] = 1;
    for (int i=1; i<=l; i++){
        for (int j=1; j<=m; j++){
            for (int k=0; (1<<i) * k <= j; k += 2){
//                cout << "????" << endl;
                dp[i][j] = (dp[i][j] + (dp[i-1][j - (1<<i) * k] * C(n, k)) % mod) % mod;
                dp[i][j] %= mod;
            }
        }
    }
    printf("%lld\n", dp[l][m]);
    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++)
const int INF = 1001001001;
using ll = long long;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    rep(i,M){
        cin >> A.at(i);
    }
    if(M==0){
        cout << 1 << endl;;
        return 0;
    }
    sort(A.begin(), A.end());
    priority_queue<int> pq;
    set<int> S;
    S.insert(A[0]-1);
    pq.push(A[0]-1);
    rep2(i,1,M){
        pq.push(A[i]-A[i-1]-1);
        S.insert(A[i]-A[i-1]-1);
    }
    pq.push(N-A[M-1]);
    S.insert(N-A[M-1]);
    S.erase(0);
    if(S.size()==0){
        cout << 0 << endl;
        return 0;
    }
    int div=0;
    div = *begin(S);
    int ans = 0;
    while(!pq.empty()){
        if(pq.top()%div==0){
            ans += pq.top()/div;
        }
        else{
            ans += (pq.top()/div+1);
        }
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


//
// Created by Abhishek Bansal on 3/28/2021
//
//#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
/*------------------------------------------------IO_OPERATORS---------------------------------------------*/
template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; }
template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << "{\"" << _m.begin()->first << "\", \"" << _m.begin()->second << "\"}"; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", { \"" << _it->first << "\", \"" << _it->second << "\"}"; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; }
//For 1 based indexing
template<typename T>
void out(const vector<T> &a, int n) {
    for (int i = 1; i <= n; ++i) {cout << a[i] << ' ';} cout << "\n";
}
template<typename T>
void out(const vector<vector<T>> &a, int n, int m) {
    for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << a[i][j] << ' ';}cout << '\n';}
}

void solve() {
    int n;cin >> n;
    vector<int> a(n);
    cin >> a;
    int ans = 1 << 30;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        vector<int> pos;
        pos.push_back(0);
        for (int j = 0; j < n; ++j) {
            if (i & (1 << j)) pos.push_back(j + 1);
        }
        pos.push_back(n);
        int x = pos.size(), cur = 0;
        for (int j = 0; j < x - 1; ++j) {
            int e = 0;
            for (int k = pos[j]; k < pos[j + 1]; ++k) {
                e |= a[k];
            }
            cur ^= e;
        }
        ans = min(ans, cur);
    }
    cout << ans;
}

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

    startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}

#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

class UnionFind {
private:
    vector<int> parent_;
    vector<int> node_rank_;
    vector<int> sizes_;
public:
    UnionFind(int node_num):
        parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
        for (int i = 0; i < node_num; ++i) {
            parent_[i] = i;
            node_rank_[i] = 0;
            sizes_[i] = 1;
        }
    }
    int getRoot(int u) {
        return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
    }
    bool isSame(int u, int v) {
        return getRoot(u) == getRoot(v);
    }
    void unite(int u, int v) {
        u = getRoot(u);
        v = getRoot(v);
        if (u == v) return;
        if (node_rank_[u] < node_rank_[v]) {
            parent_[u] = v;
            sizes_[v] += sizes_[u];
        }
        else {
            parent_[v] = u;
            sizes_[u] += sizes_[v];
            if (node_rank_[u] == node_rank_[v]) {
                node_rank_[u]++;
            }
        }
    }
    int getSize(int u) {
        return sizes_[getRoot(u)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    rep(i, 0, N) {
        cin >> X[i] >> Y[i];
    }
    double l = 0, r = 101;
    rep(_, 0, 100) {
        double mid = (r + l) / 2;
        UnionFind uf(N + 2);
        rep(i, 0, N) {
            if (Y[i] + mid > 100 - mid) {
                uf.unite(i, N);
            }
            if (Y[i] - mid < -100 + mid) {
                uf.unite(i, N + 1);
            }
            rep(j, i + 1, N) {
                if (pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2) < 4 * mid * mid) {
                    uf.unite(i, j);
                }
            }
        }
        if (uf.isSame(N, N + 1)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << fixed << setprecision(5) << l << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
string s;
int main(){
	cin>>s;
	for(int i=0;i<=20;++i){
		string t=s;
		reverse(t.begin(),t.end());
		if(s==t){
			printf("Yes\n");
			return 0;
		}
		s='0'+s;
	}
	printf("No\n");
	return 0;
}

/////keep going!~!one day u will get there
#include<bits/stdc++.h>
#define ll        	long long
#define pb        	push_back
#define ppb    	  	pop_back
#define pii         pair<ll int,ll int>
#define vi   	  	vector<ll>
#define YES  	  	cout<<"YES"<<endl;
#define NO   	  	cout<<"NO"<<endl;
#define all(a)    	(a).begin(),(a).end()
#define uniq(v)   	(v).erase(all(v),(v).end())
#define rep(i,a,b)	 for(int i=a;i<b;i++)
#define repo(i,a,b) for(int i=a;i>=b;i--)
#define fi      first
#define se      second
#define endl    '\n'
const ll int maxn=1e17+1;
const ll mod=998244353;
using namespace std;
//powerer function
long long int power(long long int a,long long int b)
{long long int res = 1;
        while(b>0){
                if(b%2==1) res = res * a;
                a = a*a;
                b = b/2;
        }
        return res;
}
//modular inverse
 ll po( ll x, ll y){ ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}

int main()
{ ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t=1;
  //cin>>t;
  while(t--)
  {
     vi a(3);
     for(int i=0;i<3;i++)
     cin>>a[i];
     sort(all(a));
     if(a[0]==a[1])
     cout<<a[2]<<endl;
     else if(a[1]==a[2])
     cout<<a[0]<<endl;
     else
     cout<<"0"<<endl;

  }
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

vector<string> ans;
ll S[300][300];

void push(string &s, ll len) {
    ans.push_back(s);
    REP(i, len) {
        REP(j, i) {
            if (s[i] == s[j]) {
                S[i][j]++;
                S[j][i]++;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll p = pow(2LL, N);

    memset(S, 0, sizeof(S));
    REP(i, p) {
        S[i][i] = INF;
    }
    while (true) {
        vector<ll> v;
        while (v.size() < p / 2) {
            pll x(-1, INF);
            REP(i, p) {
                ll sum = 0;
                REP(j, v.size()) {
                    sum += S[i][v[j]];
                }
                if (x.second > sum)
                    x = pll(i, sum);
            }
            v.push_back(x.first);
        }
        string s = "";
        REP(i, p) {
            s.push_back('A');
        }
        REP(i, v.size()) {
            s[v[i]] = 'B';
        }
        push(s, p);
        bool e = true;
        REP(i, p) {
            FOR(j, p, i + 1) {
                if (S[i][j] != S[0][1]) {
                    e = false;
                }
            }
            if (!e)
                break;
        }
        if (e)
            break;
    }

    cout << ans.size() << endl;
    REP(i, ans.size()) {
        cout << ans[i] << endl;
    }
    return 0;
}

#include<iostream>
#include<array>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int N;

vector<vector<int>> calc(int n){
  if(n==1){
    return {{0,1}};
  }
  int h=(1<<n)-1,w=(1<<n);
  vector<vector<int>> S=calc(n-1),res((1<<n)-1,vector<int>(1<<n));
  rep(i,(h-1)/2){
    rep(j,w/2){
      res[i][j]=S[i][j];res[i][j+w/2]=S[i][j];
      res[i+(h-1)/2][j]=S[i][j];res[i+(h-1)/2][j+w/2]=1-S[i][j];
    }
  }
  rep(i,(1<<(n-1))) {
    res[h-1][i]=0;
    res[h-1][i+w/2]=1;
  }
  return res;
}

void solve(){
  cin >> N;
  vector<vector<int>> ans=calc(N);
  cout << ans.size() << endl;
  rep(i,ans.size()){
    for(int t:ans[i]){
      if(t==0) cout << "A";
      else cout << "B";
    }
    cout << "" << endl;
  }
}

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


#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
const int INF = 1009009009;
const ll mod = 1000000007;

int h,w;
ll t=0;

int main(){
    cin >> h >> w;

    vector<string> mp(h);
    rep(i,h){
        cin >> mp[i];
    }

    rep(i,h)rep(j,w){
        if(mp[i][j]=='.') t++;
    }

    vector<vector<ll>> dp1(h,vector<ll>(w,0));
    vector<vector<ll>> dp2(h,vector<ll>(w,0));

    rep(i,h){
        ll now = 0;
        rep(j,w){
            if(mp[i][j]=='.'){
                now ++;
            }

            if(mp[i][j]=='#'){
                dp1[i][j] = 0;
                rep(k,now){
                    dp1[i][j-1-k] = now;
                }
                now = 0;
                continue;
            }
            if(j==w-1){
                rep(k,now){
                    dp1[i][j-k] = now;
                }
                now = 0;
            }
        }
    }

    rep(j,w){
        ll now = 0;
        rep(i,h){
            if(mp[i][j]=='.'){
                now ++;
            }

            if(mp[i][j]=='#'){
                dp2[i][j] = 0;
                rep(k,now){
                    dp2[i-1-k][j] = now;
                }
                now = 0;
                continue;
            }
            if(i==h-1){
                rep(k,now){
                    dp2[i-k][j] = now;
                }
                now = 0;
            }
        }
    }

/*
    rep(i,h){
        rep(j,w){
            cout << dp1[i][j];
        }
        cout << endl;
    }

    rep(i,h){
        rep(j,w){
            cout << dp2[i][j];
        }
        cout << endl;
    }
*/
    ll p2[h*w+1];

    p2[0] = 1;
    rep(i,h*w){
        p2[i+1] = (2*p2[i])%mod;
    }

   // cout << p2[t] << endl;

    ll ans = 0;

    rep(i,h){
        rep(j,w){
            if(dp1[i][j]==0) continue;
            ans = (ans + p2[t] - p2[t-dp1[i][j]-dp2[i][j]+1])%mod;
        }
    }

    cout << (ans + mod)%mod << endl;

}

#include <iostream>
#include <vector>
#define ll long long
#define mod %1000000007

using namespace std;

int main(){
  int high,wide;
  cin >> high;
  cin >> wide;
  vector<vector<int>> lamp(high+2,vector<int>(wide+2,-1));
  int num = 0;

  for(int i = 0;i < high;i ++){
    for(int j = 0;j < wide;j ++){
      char a;
      cin >> a;
      if(a == '.'){
        num ++;
        lamp[i+1][j+1] = 0;
      }
    }
  }

  ll ans = 0;
  vector<ll> mul(5000001,1);
  vector<ll> add(num+1);
  for(int i = 0;i < 5000000;i ++){
    mul[i+1] = (mul[i]*2)mod;
  }
  add[1] = mul[num-1];
  for(int i = 1;i < num;i ++){
    add[i+1] = (add[i] + mul[num-i-1])mod;
  }

  for(int i = 0;i < high+2;i ++){
    for(int j = 0;j < wide+2;j ++){
      if(lamp[i][j] != -1){
        int k = 0;
        while(lamp[i][j+k] != -1){
          k ++;
        }
        for(int l = 0;l < k;l ++){

          lamp[i][j] += k;
           j ++;
        }
      }
    }

  }

  for(int i = 0;i < wide+2;i ++){
    for(int j = 0;j < high+2;j ++){
      if(lamp[j][i] != -1){
        int k = 0;
        while(lamp[j+k][i] != -1){
          k ++;
        }
        for(int l = 0;l < k;l ++){

          lamp[j][i] += k-1;
          j ++;
        }
      }
    }

  }

  for(int i = 0;i < high+2;i ++){
    for(int j = 0;j < wide+2;j ++){
      if(lamp[i][j] == -1){
        continue;
      }
      ans = (ans +add[lamp[i][j]])mod;

    }

  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i += 2){
        if (!('a' <= s[i] && s[i] <= 'z')) {
            cout << "No";
            return 0;
        }
    }
    for (int i = 1; i < s.length(); i += 2){
        if (!('A' <= s[i] && s[i] <= 'Z')) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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

long digit(long x){
if(x < 10){
  return 1;
}
long s = 1 + digit(x/10);
return s;
}

long nine(long x){
long s = pow(10,digit(x)-1) - 1;
return s;
}

int main(){
long num,a,b,c; cin >> num;
if(digit(num)%2 == 1){
  c = pow(10,digit(num) - 1);
  num = nine(num);
}
c = pow(10,digit(num)/2);
a = num / c; b = num % c;
if(a <= b){
  cout << a << endl;
}else{
  cout << a - 1 << endl;
}
}