#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using vb = vector<bool>;
using ll = long long; //約9.0*10^18
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
using std::reverse;
const double PI = 3.14159265358979323846;
const ll inf = 9223372036854775807;
const ll mod = 1000000007;

#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll fac(ll n) {ll ans=1;rep0(i,n){ans=ans*(n-i);};return ans;}//n!
ll conb(ll n,ll m){return fac(n)/fac(m)/fac(n-m);}//nCm

//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();
//int→string　　string str = to_string(num);
//string→int   int num = atoi(numStr.c_str());
//複数のvector管理→;vector<tuple<string, int, int>> SP(N);
//int max = *max_element(all(A));最大値
//int min = *min_element(all(B));最小値
//floor(x)=[x]
// *max_element(a.begin(),a.begin()+5);aの最初から6番目までの最大値/計算量に不安あり
// *min_element(,);
// sort は昇順１２３４５
//普通の割り算がしたい→cout<<(double)3/2/2<<endl;
//ll A = lower_bound(a,a+n,x) - a;xになった瞬間のi
//ll B = upper_bound(c,c+n,x) - c;xを超えた瞬間のi
//true=1,false=0

//ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];}

int main() {
    vll x(3);cin>>x[0]>>x[1]>>x[2];
    sort(all(x));
    cout<<x[1]+x[2]<<endl;
}

#include<bits/stdc++.h>
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define ps() cout << "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;

using namespace std;
const int MOD = 1e9 + 7, MOD1 = (119 << 23) | 1;
const int INF = 1e9 + 5, MAX = 2e5 + 5;
int main(){
   cpu();
   int n; cin >> n;
   string s, t; cin >> s >> t;
   int ans = 0;
   for(int id1 = 0, id2 = 0; max(id1, id2) <= n; id1++, id2++){
      while(id1 < n && s[id1] == '1'){
         id1++;
      }
      while(id2 < n && t[id2] == '1'){
         id2++;
      }
      if((id1 == n) ^ (id2 == n)){
         cout << "-1\n";
         return 0;
      }
      ans += (id1 != id2);
   }
   cout << ans << "\n";
   return 0;
}


#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
  int n;
  double x, y, x0, y0, x2, y2, xc, yc, d;

  cin >> n >> x0 >> y0 >> x2 >> y2;
  xc = (x0 + x2) / 2, yc = (y0 + y2) / 2;
  x = x0 - xc, y = y0 - yc;
  d = M_PI / (n / 2);
  cout << setprecision(10) << fixed;
  cout << xc + x * cos(d) - y * sin(d) << " " << yc + x * sin(d) + y * cos(d);
  return 0;
}

#include <bits/stdc++.h>
#define N 200005
#define M 400005
#define inf 1e18
#define mp make_pair
#define int long long
using namespace std;
int n,m;
int head[N],v[M],C[M],D[M],nxt[M],tot;
priority_queue<pair<int,int> > q;
int dis[N];
bool vis[N];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
inline void add(int x,int y,int c,int d)
{
	tot++;
	v[tot]=y;
	C[tot]=c;
	D[tot]=d;
	nxt[tot]=head[x];
	head[x]=tot;
}
inline int Dij(int s)
{
	for(int i=2;i<=n;i++) dis[i]=inf;
	dis[s]=0;
	q.push(mp(0,s));
	while(!q.empty())
	{
		int x=q.top().second,s=q.top().first;q.pop();
		if(x==n) return -s;

		if(vis[x]) continue;
		vis[x]=1;
		for(int i=head[x];i;i=nxt[i])
		{
			if(dis[v[i]]>((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1))))))
		    {
				dis[v[i]]=((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1)))));
				q.push(mp(-dis[v[i]],v[i]));
			}
		}
	}
	return -1;
}
signed main()
{
	n=read();
	m=read();
	int a,b,c,d;
	for(int i=1;i<=m;i++)
	{
		a=read();
		b=read();
		c=read();
		d=read();
		//if(a==b) continue;
		add(a,b,c,d);
		add(b,a,c,d);
	}
	printf("%lld\n",Dij(1));
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int N=1010;
struct moun{
	string name;
	int high;
}Mou[N];
int n;
bool cmp(moun a,moun b){
	return a.high>b.high;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>Mou[i].name;
		cin>>Mou[i].high;
	}
	sort(Mou,Mou+n,cmp);
	cout<<Mou[1].name;
	return 0;
}

// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;

using namespace std;

#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl
#define filler(arr, n)          \
    for (int i = 0; i < n; i++) \
        cin >> arr[i];
#define filler2(arr, n , m)          \
    for (int i = 0; i < n; i++) \
        for(int j=0; j<m; j++)  \
            cin >> arr[i][j];

const int N = 1e9 + 7;

inline int add(int a,int b) {return ((a%N)+(b%N))%N;}
inline int sub(int a,int b) {return ((a%N)-(b%N)+N)%N;}
inline int mul(int a,int b) {return ((a%N)*(b%N))%N;}

void solve(){

    int n,a,b,c,k,m, ans=0, count=0, sum=0;

    cin>>n;
    vector<pair<int , string>> v(n);
    for(int i=0; i<n; i++) {

      string s;
      cin>>s>>a;

      v[i] = mp(a , s);
    }

    sort(all(v) );

    cout<<v[sz(v )-2].S<<endl;
}

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

  //  int t; cin>>t; while(t--)
    {
      solve();
    }

  return 0;
}

/*Things to do if you are stuck:-
1.Read the problem statement again, maybe you've read something wrong.
2.See the explanation for the sample input .
3.If the solution is getting too complex in cases where no. of submissions
  are high ,then drop that idea because there is something simple which you are
  missing.
4.Check for runtime errors if unexpected o/p is seen.
5.Check on edge cases before submitting.
6.Ensure that you have read all the inputs before returning for a test case.
7.Try to think of brute force first if nothing is striking.
8.Take more examples
9.Don't give up , maybe you're just one statement away!
*/


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

int main(){
  int n;
  cin >> n;
  vector<int> xn(n), yn(n);
  for(int i=0; i<n; ++i) cin >> xn[i] >> yn[i];
  int ans = 0;
  for(int i=0; i<n-1; ++i) for(int j=i+1; j<n; ++j){
    int dx = xn[j] - xn[i];
    int dy = yn[j] - yn[i];
    if(abs(dx) >= abs(dy)) ++ans;
  }
  cout << ans << endl;
}

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

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%d %d", &x[i], &y[i]);

    // 2. 傾きが, -1 以上 かつ 1 以下 である(i, j) の 個数は？
    int ans = 0;
    rep(i, N){
        repx(j, i + 1, N){
            // 点 (x[i], y[i]) と (x[j], y[j]) を 通る直線の傾きは？
            // -> a = (y[i] - y[j]) / (x[i] - x[j]) が -1 以上 かつ 1 以下.
            if(abs(y[i] - y[j]) <= abs(x[i] - x[j])) ans++;
        }
    }

    // 3. 出力.
    printf("%d\n", ans);
    return 0;

}


#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 main()
{
	double a, b;
	scanf("%lf %lf", &a, &b);
	printf("%lf\n", (a - b) * 100 / a);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
  ld a,b;
  cin>>a>>b;
  cout<<(1-b/a)*100<<endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T> struct SegmentTree {
  using F = function<T(T, T)>;
  T n;
  vector<T> d;
  const F f;
  const T e;

  // 要素数, 操作関数, 単位元
  SegmentTree(T m, F f, T e) : f(f), e(e) {
    n = 1;
    while (n < m) n *= 2;
    d = vector<T>(2 * n, e);
  }

  void update(int i, T x) {
    i += n;
    d[i] = x;
    while (i > 1) {
      i /= 2;
      d[i] = f(d[2 * i], d[2 * i + 1]);
    }
  }

  // [a, b)
  T query(int a, int b) { return query_sub(a, b, 1, 0, n); }
  T query_sub(int a, int b, int k, int l, int r) {
    // index k: [l, r)
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return d[k];
    T lv = query_sub(a, b, 2 * k, l, (l + r) / 2);
    T rv = query_sub(a, b, 2 * k + 1, (l + r) / 2, r);
    return f(lv, rv);
  }

  T get(int i) { return d[n + i]; }
};

int f(int x, int y) { return x ^ y; }

int main() {
  int n, q;
  cin >> n >> q;
  SegmentTree<int> st(n, f, 0);
  rep(i, n) {
    int a;
    cin >> a;
    st.update(i, a);
  }

  rep(iq, q) {
    int t, x, y;
    cin >> t >> x >> y;
    --x;
    if (t == 1) {
      st.update(x, st.get(x) ^ y);
    } else {
      printf("%d\n", st.query(x, y));
    }
  }
  return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
#define kill(x) { cout << x << "\n"; return;}
const int N=3e5+100;
int B[N];
int sm(int i){int r=0;for(;i;i-=i&-i)r^=B[i];return r;}
void up(int i,int v){for(;i<N;i+=i&-i)B[i]^=v;}
int vid(int i){int r=B[i],z=i-(i&-i);for(i--;i!=z;i-=i&-i)r-=B[i];return r;}
int rsm(int l,int r){return sm(r)^sm(l-1);}
void solve(){
	int n,m; cin >> n >>m ;
	int x;
	fr(i,n) { cin >> x; up(i+1,x);}
	while(m--){
		int t,y; cin >> t >> x >> y;
		if(t & 1) {
			up(x,y);
		}
		else cout << rsm(x,y) << "\n";
	}

}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

const int N = 1e5 + 5;

int a[N], b[N], n, m;

int main() {
    read(n), read(m);
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
    }
    for (int i = 1; i <= n; ++i) {
        read(b[i]);
    }
    n++;
    a[0] = b[0] = 0;
    a[n] = b[n] = m + 1;
    for (int i = n; i >= 1; --i) {
        a[i] = a[i] - a[i - 1] - 1;
        b[i] = b[i] - b[i - 1] - 1;
    }
    LL ans = 0;
    for (int i = 1, j = 1; i <= n; ++i) {
        if (!b[i]) continue;
        while (!a[j]) j++;
        int k = j, sum = 0;
        while (sum < b[i] && j <= n) {
            sum += a[j++];
        }
        if (sum != b[i]) {
            puts("-1");
            return 0;
        }
        ans += max(i - k, 0) + max(j - i - 1, 0);
    }
    printf("%lld\n", ans);
	return 0;
}

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

int n,k;
char dp[5005][5005],a[1000005];

int ddd[1000]={0};

char win(char a,char b){
    if(a==b)  return a;
    if(a=='S'&&b=='P')
        return a;
    if(a=='P'&&b=='S')
        return b;

    if(ddd[a]>ddd[b])
        return a;

    else return b;
}

int getmod(int ppp,int n){
    if(ppp%n==0)
        return n;
    else
        return ppp%n;
}

int quick_power(int x,int y){
    int res=1;
    for(;y;y=y>>1,x=(x*x)%n)
        if(y&1)
            res=(res*x)%n;

    return res;
}

signed main(){
    ios::sync_with_stdio(false);

    cin>>n>>k;
    ddd['P']=2,ddd['R']=1,ddd['S']=0;

    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n+1;i<=2*n;i++)
        a[i]=a[i-n];
    for(int i=1;i<=2*n;i++)
        dp[i][0]=a[i];

    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++)
            dp[j][i]=win(dp[j][i-1],dp[getmod(j+quick_power(2,i-1),n)][i-1]);
        for (int j=n+1;j<=2*n;j++)
            dp[j][i]=dp[j-n][i];
    }

    cout<<dp[1][k]<<endl;
    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  ll n = N;
  ll d = 0;
  while(n/1000 > 0) {
    n /= 1000;
    d++;
  }

  ll ans = 0;
  ll base = pow(1000, d);
  ans += d*(N - base + 1);

  d--;
  while(d > 0) {
    ll base_next = pow(1000, d);
    ans += d * (base - base_next);
    d--;
    base = base_next;
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ts to_string
#define all(x) (x).begin(), (x).end()
#define dbg(a); cerr<<#a<<"="<< (a)<<endl;
#define dbg2(a,b); cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl;
#define dbgarr(a); for(int elem:a)cerr<<elem<<" ";cerr<<endl;
#define panic(); cout<<"we're fine"<<endl;
using namespace std;
int main()
{
	int n;cin>>n;
	if(n&1)
		cout<<"Black"<<endl;
	else
		cout<<"White"<<endl;

}

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

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

	vector<vector<int>> C(N, vector<int>(N, 0));
	REP(i, N) {
		REP(j, N) {
			cin >> C[i][j];
		}
	}

	int m = *min_element(C[0].begin(), C[0].end());

	vector<int> A(N, 0), B(N, 0);
	REP(i, N) B[i] = C[0][i] - m;
	REP(i, N) A[i] = C[i][0] - B[0];

	bool check = true;
	REP(i, N) if (A[i] < 0) check = false;
	REP(i, N) if (B[i] < 0) check = false;
	REP(i, N) REP(j, N) if (C[i][j] != A[i] + B[j]) check = false;

	if (check) {
		cout << "Yes" << endl;
		REP(i, N) cout << A[i] << " ";
		cout << endl;
		REP(i, N) cout << B[i] << " ";
		cout << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }

/*** mod int ***/
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}; //comb(2000005);

using vm = vector<mint>;
using vvm = vector<vm>;

void Main(){
    int n, m, k; cin >> n >> m >> k;
    //*
    if(n == 1 && m == 1){
        cout << k << endl;
        return;
    }
    //*/
    if(n == 1) swap(n, m);
    mint ans = 0;
    rep3(amax, 1, k){
        mint a = (n > 1 ? ((mint)amax).pow(n) - ((mint)amax-1).pow(n) : 1);
        mint b = (m > 1 ? ((mint)k-amax+1).pow(m) : 1);
        ans += a * b;
        //cout << amax << " " << a << " " << b << " " << ans << endl;
    }
    cout << ans << endl;
    return;
}

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

//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
#define pb push_back
#define sz size()
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647,p=998244353;
use io;
int n,m,k,T;
int ksm(int a,int b)
{
	if(!b)
		return 1;
	int t=ksm(a,b/2);
	t=(ll)t*t%p;
	return b%2?(ll)t*a%p:t;
}
int main()
{
	int i,j,a1,a2;
	_(n,m,k);
	if(n+m==2)
		_pn(k);
	else if(n==1||m==1)
		_pn(ksm(k,n+m-1));
	else
	{
		int an=0;
		//m=max(n,m);
		//n=t;
		fo(i,k)
			an=(an+(ll)ksm(i,n)*(ksm(k-i+1,m)-ksm(k-i,m)+p))%p;
		_pn(an);
	}
}


#include<bits/stdc++.h>
using namespace std;
void dfs(int i,vector<int>k[],long int&c,bool v[]){
    if(v[i]){
        return;
    }
    v[i]=true;
    c++;
    for(auto &x: k[i]){
        dfs(x,k,c,v);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,a,b;
    cin>>n>>q;
    vector<int>adj[10000];
    for(int i=0;i<q;i++){
        cin>>a>>b;
        adj[a-1].push_back(b-1);
    }
    long int s=0;
    long int c=0;
    for(int i=0;i<n;i++){
        c=0;
        bool visited[n+1]={false};
        dfs(i,adj,c,visited);
        s+=c;
    }
    cout<<s;
}

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

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

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

void my_debugger(string s, int LINE_NUM)
{
    cerr << endl;
}
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
    if (s.back() != ',')
    {
        s += ',';
        cerr << "LINE(" << LINE_NUM << "): ";
    }
    int i = s.find(',');
    cerr << s.substr(0, i) << " = " << x;
    s = s.substr(i + 1);
    if (!s.empty())
        cerr << ", ";
    my_debugger(s, LINE_NUM, y...);
}
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

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

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

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> ppll;

const ll N = 200009;

void solve()
{
    ll n, m, q;
    cin >> n >> m >> q;

    vl vn[n + 5];
    for (ll i = 1; i <= n; i++)
    {
        ll w, v;
        cin >> w >> v;

        vn[i] = {w, v};
    }

    ll x[m + 5];
    for (ll i = 1; i <= m; i++)
    {
        cin >> x[i];
    }

    while (q--)
    {
        ll l, r;
        cin >> l >> r;

        ll vis[n + 5] = {0};
        vl avail;
        for (ll i = 1; i < l; i++)
        {
            avail.pb(x[i]);
        }

        for (ll i = r + 1; i <= m; i++)
        {
            avail.pb(x[i]);
        }

        sort(all(avail));

        ll ans = 0;
        for (ll i = 0; i < avail.size(); i++)
        {
            // watch(i);
            vl temp = {INT_MIN, -1ll}; //value, index
            for (ll j = 1; j <= n; j++)
            {
                if (vis[j] == 1)
                    continue;
                if (avail[i] >= vn[j][0] && temp[0] < vn[j][1])
                {
                    temp[0] = vn[j][1];
                    temp[1] = j;
                }
            }

            if (temp[1] != -1)
            {
                // watch2(temp[0], temp[1]);
                vis[temp[1]] = 1;
                ans += temp[0];
            }
        }

        cout << ans << nl;
    }
}

int main()
{

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

    ll T = 1;
    // cin >> T;

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

    return 0;
}


#include<bits/stdc++.h>
#define pii pair<int,int>
#define N 1000005
using namespace std;
int n,q,f[N];
inline int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
map<int,int>mp[N];
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1,c;i<=n;++i)
	{
		scanf("%d",&c);
		mp[i][c]=1;
		f[i]=i;
	}
	while(q--)
	{
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t==1)
		{
			x=find(x);y=find(y);
			if(x!=y)
			{
				if(mp[x].size()<mp[y].size())swap(x,y);
				for(pii p:mp[y])mp[x][p.first]+=p.second;
				f[y]=x;
			}
		}
		else printf("%d\n",mp[find(x)][y]);
	}
}

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

int n, m, t[200200], p[200200];
ll a[200200], x[200200], ans[200200];

int find(int a){
	if(a == p[a]) return a;
	return p[a] = find(p[a]);
}

void merge(int a, int b){
	a = find(a), b = find(b);
	p[a] = b;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i] >> t[i];
	cin >> m;
	for(int i=1;i<=m;i++) cin >> x[i], p[i] = i;

	set<pair<ll, int>> s;
	for(int i=1;i<=m;i++) s.insert({x[i], i});

	ll pl = 0;
	for(int i=1;i<=n;i++){
		vector<set<pair<ll, int>>::iterator> v;
		if(t[i] == 1){
			pl += a[i];
		}if(t[i] == 2){
			auto it = s.upper_bound({a[i]-pl, n+1});
			if(it != s.begin()){
				it = prev(it);

				for(auto u = s.begin(); u != it; u++){
					merge((*u).second, (*next(u)).second);
					v.push_back(u);
				}

				auto [x, y] = *it;
				s.erase(it), s.insert({a[i]-pl, y});
			}
		}if(t[i] == 3){
			auto it = s.lower_bound({a[i]-pl, 0});
			if(it != s.end()){
				for(auto u = prev(s.end()); u != it; u--){
					merge((*u).second, (*prev(u)).second);
					v.push_back(u);
				}
				auto [x, y] = *it;
				s.erase(it), s.insert({a[i]-pl, y});
			}
		}

		for(auto x : v) s.erase(x);
	}

	for(auto [x, y] : s) ans[y] = x;
	for(int i=1;i<=m;i++) ans[i] = ans[find(i)];
	for(int i=1;i<=m;i++) cout << ans[i]+pl << "\n";
}


#include <bits/stdc++.h>

//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 25e5 + 100;

int dp[1<<20];
int p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};

void solve() {
    int a,b;
    cin>>a>>b;
    dp[0]=1;
    for (int i = a; i <=b; ++i) {
        int res=0;
        for (int j = 0; j < 20; ++j) {
            if (i%p[j]==0) res|=1<<j;
        }
        for (int j = 0; j < 1 << 20; ++j) {
            if (!(res&j)){
                dp[j|res]+=dp[j];
            }
        }
    }
    int ans=0;
    for (int k = 0; k < 1 << 20; ++k) {
        ans+=dp[k];
    }
    cout<<ans<<"\n";
}

signed main() {
//    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<unordered_map>
#include<queue>
#include<string>
using namespace std;

using ll = long long;
ll dp[75][1<<20];
ll A, B;
vector<int> prime;
bool vis[100];
int state[100];

int main()
{
    cin >> A >> B;
    for(int i = 2; i <= B - A; ++i)
    {
        if(!vis[i])
        {
            prime.push_back(i);
            for(int j = i + i; j <= B - A; j += i)
                vis[j] = true;
        }
    }

    const int prime_siz = prime.size();
    for(ll i = A; i <= B; ++i)
    {
        ll cur = i;
        for(int j = 0; j < prime_siz; ++j)
        {
            while(cur % prime[j] == 0)
            {
                cur /= prime[j];
                state[i - A + 1] |= (1 << j);
            }
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i <= B - A; ++i)
    {
        for(int s = 0; s < (1 << prime_siz); ++s)
        {
            dp[i + 1][s] += dp[i][s];
            if(!(state[i + 1] & s))
                dp[i + 1][s | state[i + 1]] += dp[i][s];
        }
    }

    ll res = 0;
    for(int i = 0; i < (1 << prime_siz); ++i)
        res += dp[B - A + 1][i];
    cout << res << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
//bool vis[1000];
//int x[]={1,-1,0,0};
//int y[]={0,0,1,-1};
//int f=0;
//"'';
int main(){
 ll n,k;
 cin>>n>>k;
ll sum=3*n;
vector<vector<ll> > dp(4,vector<ll>(sum+1,0));
vector<vector<ll> > sm(4,vector<ll>(sum+1,0));
dp[0][0]=1;
for(int i=0;i<=sum;i++){
    sm[0][i]=1;
}
for(int i=1;i<=3;i++){
    for(int j=1;j<=sum;j++){
        int mx=j-1;
        int mn=max(0ll,j-n);
        dp[i][j]=sm[i-1][mx];
        if(mn>0){
            dp[i][j]=dp[i][j]-sm[i-1][mn-1];
        }
       // cout<<i<<-1<<j<<-1<<dp[i][j]<<endl;
        sm[i][j]+=sm[i][j-1]+dp[i][j];
    }
}
int a;
for(int i=1;i<=sum;i++){
    if(sm[3][i]>=k){
            k=k-sm[3][i-1];
        a=i;
        break;
    }
}
//cout<<k<<endl;
//cout<<a<<endl;
for(int i=3;i>=1;i--){
    for(int j=1;j<=n;j++){
        if(a-j>=0&&dp[i-1][a-j]>=k){
            cout<<j<<" ";
            a=a-j;
            break;
        }
        else{
             k=k-dp[i-1][a-j];
        }
    }
}
cout<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
#define int unsigned long long
const int maxn=3e6+7;
int sum[maxn];
int a[maxn];
signed main()
{
	int n,k;
	cin>>n>>k;
	for(int i=3;i<=3*n;++i)
	{
		if(i<=n+2) sum[i]=sum[i-1]+(i-1)*(i-2)/2;
		else if(i<=2*n) sum[i]=sum[i-1]+(i-2)*(2*n-i+1)/2+(3*n-i+2)*(i-n-1)/2;
		else {
			int p=3*n+3-i;
			sum[i]=sum[i-1]+(p-1)*(p-2)/2;
		}
	}
	sum[3*n+1]=1000000000000000000+1;
	//cout<<sum[3*n]<<endl;
	int L=3,R=3*n;
	int s=-1;
	while(L<=R)
	{
		int mid=L+R>>1;
		if(sum[mid]<=k) s=mid,L=mid+1;
		else R=mid-1;
	}
	//cout<<sum[4]<<endl;
	if(sum[s]!=k) s++;
	//print(s);
	//cout<<k<<endl;
	int tar=k-sum[s-1];
	//cout<<tar<<endl;
	int res=0,pre=0;
	int beauty,taste;
	for(int i=1;i<=n;++i)
	{
		if(s-i>2*n||s-i<2) continue;
		if(s-i<=n+1) res+=s-i-1;
		else res+=2*n-s+i+1;
		if(res>=tar)
		{
			beauty=i;
			taste=tar-pre;
			break;
		}
		pre=res;
	}
	int ss=s-beauty;
	if(ss<=n+1) ;
	else taste=taste+ss-n-1;
	cout<<beauty<<" "<<taste<<" "<<s-beauty-taste<<endl;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[1200010];
char* ci = cn, * di = cn, ct;
//char tc[200002], *d1 = tc + 100000, *d2 = tc + 200000;
const char d[2] = "0";

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

	fread(cn, 1, 1200010, stdin);
	int T = 0;
	while ((ct = *ci++) >= '0') T = T * 10 + ct - '0';

	rep(t, T) {
		int N = 0;
		while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';

		memset(di, '0', N);
		di += N;
		memset(di, '1', N);
		di += N;
		*di++ = '0';
		*di++ = '\n';
		ci += 6 * N + 3;
	}
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

void solve(int test, istream &in) {
    int n;
    string s[3];
    in >> n >> s[0] >> s[1] >> s[2];
    bool has[2] = { false, false };
    for (int k = 0; k < 3; k++) {
        has[s[k][0] - '0'] = true;
    }
    char start = 0;
    if (!has[start])
        start = 1;
    string answer(2 * n + 1, '0');
    answer[0] = '0' + start;
    for (int i = 0; i < n; i++) {
        answer[1 + i] = '1' - start;
        answer[1 + n + i] = '0' + start;
    }
    printf("%s\n", answer.c_str());
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf seconds\n", seconds);
#endif
	return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    cin>>n;
    V<ll> l(n),r(n);
    for(int i=0;i<2*n;i++){
         if(i<n)cin>>l[i];
         else cin>>r[i-n];
    }
    reverse(all(l));
    ll ans=-inf,res=0;
    priority_queue<ll,V<ll>,greater<ll>> a,b;
    a.emplace(l[0]);
    for(int i=1;i<n;i++){
        a.emplace(l[i]);
        b.emplace(r[i]);
        if(a.top()<b.top()){
              a.pop();
        }else{
             b.pop();
        }
    }
    while(a.size()){
          res+=a.top();
          a.pop();
    }
    while(b.size()){
          res+=b.top();
          b.pop();
    }
    ans=res;
    res=0;
    b.emplace(r[0]);
    for(int i=1;i<n;i++){
        a.emplace(l[i]);
        b.emplace(r[i]);
        if(a.top()<b.top()){
              a.pop();
        }else{
             b.pop();
        }
    }
    while(a.size()){
          res+=a.top();
          a.pop();
    }
    while(b.size()){
          res+=b.top();
          b.pop();
    }
    cout<<max(ans,res)<<"\n";
}

#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i=0; i<(int)(n); i++)
#define REP(i, n) for (int i=1; i<=(int)(n); i++)
#define For(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;

int main() {
    string S;
    cin >> S;
    vector<int> a,b,c;
    Rep(i,S.size()) {
        char s=S.at(i);
        if (s=='o') a.push_back(i);
        if (s=='x') b.push_back(i);
        if (s=='?') c.push_back(i);
    }
    int cnt = 0;
    Rep(i,10) {
        bool no=false;
        Rep(I,b.size()) if(i==b.at(I)) no = true;
        if (no) continue;
        Rep(j,10) {
        bool no=false;
            Rep(I,b.size()) if(j==b.at(I)) no = true;
            if (no) continue;
            Rep(k,10) {
            bool no=false;
                Rep(I,b.size()) if(k==b.at(I)) no = true;
                if (no) continue;
                Rep(l,10) {
                    bool no=false;
                    Rep(I,b.size()) if(l==b.at(I)) no = true;
                    if (no) continue;
                    bool can=true;
                    Rep(I,a.size()) {
                        if (i!=a.at(I) && j!=a.at(I) && k!=a.at(I)&& l!=a.at(I)) can = false;
                    }
                    if (can) cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


#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 int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
	int res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res % p;
}
int lcm(int a, int b)
{
	return a / __gcd(a, b) * b;
}
void solve()
{
	int n;
	cin >> n;
	int a[n];
	ordered_set<int> se;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int g = se.order_of_key(a[i]);
		ans += i - g;
		se.insert(a[i]);
	}
	cout << ans << endl;
	for (int i = 1; i < n; i++) {
		ans += (n - a[i - 1] - 1) - a[i - 1];
		cout << ans << endl;
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int tc;
	tc = 1;
#ifndef ONLINE_JUDGE
	freopen("inputf.txt", "r", stdin);
	freopen("outputf.txt", "w", stdout);
#endif
	// cin >> tc;
	while (tc--)
	{

		solve();

	}

	return 0;
}

// 解き直し.
// https://atcoder.jp/contests/abc190/editorial/631
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[303030];

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT{
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    void add(int i, T x = 1){
        for(i++; i <= n; i += i & -i) d[i] += x;
    }
    T sum(int i){
        T x = 0;
        for(i++; i; i -= i & -i) x += d[i];
        return x;
    }
    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }
};

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &a[i]);

    // 2. 転倒数(数列 A) を 計算.
    BIT<LL> ft(N + 1);
    LL per = 0;
    rep(i, N){
        // 2-1. 位置 a[i] に, 1 を 加算.
        ft.add(a[i], 1LL);

        // 2-2. 区間[a[i] + 1, N] の 合計は？
        LL t = ft.sum(a[i] + 1, N + 1);

        // 2-3. 集計.
        per += t;
    }

    // 3. 転倒数(数列 B) を 計算しながら出力.
    LL ans = per;
    rep(i, N){
        // 3-1. 出力.
        printf("%lld\n", ans);

        // 3-2. 差分更新(※解説通り).
        ans += (LL)(N - 1 - 2 * a[i]);
    }
    return 0;

}


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

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

int vis[26],n,ans;

string s;

signed main() {
	cin>>s;
	n=s.size();
//	vis[s[]]
	for(int i=s.size()-1;i>=0;i--) {
		if(i!=s.size()-1 && s[i]==s[i+1]) {
		 	for(int j=0;j<=25;j++) {
				if(j!=s[i]-'a') {
					ans+=vis[j],vis[s[i]-'a']+=vis[j],vis[j]=0;
				}
			}
		}
		vis[s[i]-'a']++;
	}
	cout<<ans<<endl;

}

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int BUF = 2005;

int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

void work() {
    int minV = *min_element(val, val + nVal);
    map<int, int> divisor2gcd;

    for (int loop = 0; loop < nVal; ++loop) {
        int n = val[loop];
        for (int i = 1; i * i <= n; ++i) {
            if (n % i == 0) {
                int divisor[] = {i, n / i};
                for (int j = 0; j < 2; ++j) {
                    if (j == 1 && divisor[0] == divisor[1]) continue;
                    if (divisor[j] > minV) continue;
                    if (!divisor2gcd.count(divisor[j])) {
                        divisor2gcd[divisor[j]] = n / divisor[j];
                    } else {
                        divisor2gcd[divisor[j]] = gcd(n / divisor[j], divisor2gcd[divisor[j]]);
                    }
                }
            }
        }
    }

    int cnt = 0;
    for (map<int, int>::iterator it = divisor2gcd.begin(); it != divisor2gcd.end(); ++it) {
        cnt += it->second == 1;
    }
    cout << cnt << endl;
}

int main() {
    read();
    work();
    return 0;
}


#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
//typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
S={2,3,5,7,11,13,17,19,}
dp[i][S]=i番目の数まで見た時に使った素数の集合がSであるような選び方の場合の数
dp[0][0]=1
ans:dp[b-a][j](jは任意)
今考えている数:m
dp[i+1][S|(mの素因数)](mの素因数とSのbitがかぶっている時は遷移しない)
*/

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<ll>divisor(ll n){
    vector<ll>ret;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	ll a,b;
	cin >> a >> b;
	vector<ll>prime;
	for(int i=1;i<=b-a;i++){
		if(divisor(i).size()==2)prime.push_back(i);
	}
	ll psz = prime.size();
	vector<vector<ll> >dp(b-a+2,vector<ll>(1<<psz,0));
	dp[0][0]=1;
	map<ll,ll>mp;
	for(ll m=a;m<=b;m++){
		ll bit = 0;
		rep(j,prime.size()){
			if(m%prime[j]==0)bit|=(1<<j);
		}
		mp[m]=bit;
	}
	for(ll m=a;m<=b;m++){
		rep(s,(1<<psz)){
			ll i = m-a;
			//if(__builtin_popcount(s)!=i)continue;
			dp[i+1][s]+=dp[i][s];
			ll bit = mp[m];
			if((s^bit)!=(s|bit))continue;
			dp[i+1][s|bit]+=dp[i][s];
		}
	}
	//debug(dp);
	cout << accumulate(dp[b-a+1].begin(),dp[b-a+1].end(),0) << endl;

	return 0;
}


#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
int T;
string s="atcoder";
string S;
int main(){
	cin>>T;
	while(T--) {
		cin>>S;
		int len=S.length();
		int ans=-1;
		for(rint i=0;i<len;++i){
			if(S[i]!='a') {ans=i;break;}
		}
		if(S>s) {
			cout<<0<<"\n";
			continue;
		}
		if(ans==-1) {
			cout<<-1<<'\n';
		}
		else {
			if(S[ans]>'t') ans--;
			cout<<ans<<'\n';
		}
	}
	return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

void __print(int32_t 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

int C(int n,int r)
{
    int ans=1;

    for(int i=1;i<=r;i++)
    {
        ans*=n--;
        ans/=i;
    }
    return ans;
}

bool valid(int n,auto &c,auto &t)
{
    set<int> cused;

    for(int i=0;i<4;i++)
    {
        int cur= n%10;
        n/=10;

        if(c.count(cur))
        {
            cused.insert(cur);
        }
        else if(t.count(cur))
        {

        }
        else
        {
            return false;
        }
    }

    return cused==c;
}

void solve()
{
    string str;
    cin>>str;

    set<int> contained,ns;

    for(int i=0;i<10;i++)
    {
        if(str[i]=='o') contained.insert(i);
        else if(str[i]=='?') ns.insert(i);
    }
    int ans=0;
    for(int i=0;i<=9999;i++)
    {
        if(valid(i,contained,ns)) ans++;
    }

    cout<<ans;
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <cmath>

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for(ll i=0;i<(ll)n;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }

struct shiki {
    static constexpr ll limit = std::numeric_limits<ll>::max() / 4;
    ll min = 10000000000000000;
    ll max = -10000000000000000;
    ll a = 0;
    shiki(ll _a, ll t) {
        switch (t)
        {
            case 1: a = _a; break;
            case 2: max = _a; break;
            case 3: min = _a; break;
        }
    }
    void gousei(const shiki& sotogawa) {
        if(sotogawa.min < 10000000000000000) min = std::min(min, sotogawa.min - a);
        if(sotogawa.max > -10000000000000000) max = std::max(max, sotogawa.max - a);
        a += sotogawa.a;
    }
    void gousei(ll _a, ll t) {
        switch (t)
        {
            case 1: a += _a; max += _a; min += _a; break;
            case 2: max = std::max(max, _a); min = std::max(min, _a); break;
            case 3: min = std::min(min, _a); max = std::min(max, _a); break;
        }
    }
    ll execute(ll x) {
        return std::min(std::max(x + a, max), min);
    }
    void print() { std::cout << min << " " << max << " " << a << "\n"; }
};

int main() {
    ull N, Q;
    std::cin >> N;
    shiki f(0,0);
    REP(i, N) {
        ll a, t;
        std::cin >> a >> t;
        f.gousei(a, t);
        //f.gousei(shiki(a, t));
        //f.print();
    }
    std::cin >> Q;
    std::vector<ll> x(Q);
    REP(i, Q) std::cin >> x[i];
    REP(i, Q) std::cout << f.execute(x[i]) << "\n";
}

// #pragma GCC target ("avx,avx2")
// #include <bits/extc++.h>
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define f first
#define s second

using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
// typedef tree<int, null_type, less<int>,
// rb_tree_tag, tree_order_statistics_node_update> oset;
//========================================================
const int N = 1e5+5, K = 19, M = 5e4+5, mod = 1e9+7, len = 30, inf = 0x3f3f3f3f;
int n, m;
ll dist[N];

vector<pair<int, pair<ll, ll>>> adj[N];

void dijkstra(int src)
{
	priority_queue<pair<ll, int>> q;

	fill(dist, dist+n, 1e18);

	q.push({0, src});
	dist[src] = 0;

	while(!q.empty())
	{
		auto t = q.top();
		q.pop();

		int u = t.s;
		if(dist[u] != -t.f)
			continue;
		if(u == n-1)
			break;
		for(auto e : adj[u])
		{
			ll v = e.f, c = e.s.f, d = e.s.s;
			auto dis = [&](ll T)
			{
				ll res = c + ll(d / (T + 1)) + T;
				return res;
			};

			ll s = 1ll * sqrt(d) - 1;
			s = max(s, 0LL);
			if(dist[u] > s)
				s = dist[u];
			ll D = min(dis(s), dis(s+1));
			// assert(D > 0);
			if(dist[v] > D)
				dist[v] = D, q.push({-D, v});
		}
	}
	if(dist[n-1] == 1e18)
		dist[n-1] = -1;
}

void run_case()
{
	scanf("%d %d", &n, &m);
	for(int i=0, u, v, c, d; i<m; i++)
	{
		scanf("%d %d %d %d", &u, &v, &c, &d);
		adj[u-1].push_back({v-1, {c, d}});
		adj[v-1].push_back({u-1, {c, d}});
	}

	dijkstra(0);
	printf("%lld\n", dist[n-1]);
}

int main()
{
    // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // freopen("input.txt", "rt", stdin);
    // freopen("output.txt", "wt", stdout);
    int t;
    t = 1;
    // cin >> t;
    while(t--)
        run_case();
}


#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define PI acos(-1)
typedef  long long ll;
ll MOD=1000000007;

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

using Graph=vector<vector<int>>;

int H=50,W=50;
bool seen[55][55];
int t[55][55];
int p[55][55];

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

set<int> tile;
int cnt=0;
bool f=true;
void dfs(int h,int w){
   if(f==false){
      return;
   }
   /*
   cnt++;
   if(cnt>55){
      return;
   }
   */

   //cout<<h<<":"<<w<<":";
   seen[h][w]=true;
   tile.insert(t[h][w]);
   //cout<<t[h][w]<<":"<<p[h][w]<<":"<<f<<endl;
   for(int dir=0;dir<=4;++dir){
      if(dir==4){
         f=false;
         return;
      }
      int nh=h+dx[dir];
      int nw=w+dy[dir];
      int newtile=t[nh][nw];

      if(nh<0 || nh>=H || nw<0 || nw>=W) {
         continue;
      }

      if(tile.find(newtile)!=tile.end()){
         continue;
      }
      if(seen[nh][nw]==true){
          continue;
      }
      if(dir==0 &&f){
         cout<<"U";
      }
      else if(dir==1 &&f){
         cout<<"D";
      }
      else if(dir==2 &&f){
         cout<<"L";
      }
      else if(dir==3 &&f){
         cout<<"R";
      }
      dfs(nh,nw);

   }
}

int main(){
   int si,sj;
   cin>>si>>sj;
   rep(i,H){
      rep(j,W){
         cin>>t[i][j];
      }
   }
   rep(i,H){
      rep(j,W){
         cin>>p[i][j];
      }
   }

   rep(i,55){
      rep(j,55){
         seen[i][j]=false;
      }
   }

   dfs(si,sj);
   return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    vector<vector<int>> t(50, vector<int> (50));
    for (int i=0;i<50;i++) {
        for (int j=0;j<50;j++) {
            cin >> t[i][j];
        }
    }
    vector<vector<int>> p(50, vector<int> (50));
    for (int i=0;i<50;i++) {
        for (int j=0;j<50;j++) {
            cin >> p[i][j];
        }
    }
    vector<int> jud(2510,0);
    jud[t[x][y]]++;
    while (true) {
        if (x<49) {
            if (jud[t[x+1][y]]==0) {
                cout << "D";
                x++;
                jud[t[x][y]]++;
                continue;
            }
        }
        if (y>0) {
            if(jud[t[x][y-1]]==0) {
                cout << "L";
                y--;
                jud[t[x][y]]++;
                continue;
            }
        }
        if (y<49) {
            if (jud[t[x][y+1]]==0) {
                cout << "R";
                y++;
                jud[t[x][y]]++;
                continue;
            }
        }
        if (x>0) {
            if(jud[t[x-1][y]]==0) {
                cout << "U";
                x--;
                jud[t[x][y]]++;
                continue;
            }
        }
        break;
    }
}


#include <iostream>
#include <algorithm>

using namespace std;

string s;

int main(void) {
    cin >> s;

    bool flag = true;

    for (int i = 0; i < s.size(); ++i) {
        int j = s.size() - i - 1;
        if (s[i] != s[j]) flag = false;
    }

    if (flag) {
        cout << "Yes" << endl;
        return 0;
    }

    int zero = 0;
    for (int i = s.size() - 1; i >= 0; --i)
        if (s[i] == '0') zero ++;

    reverse(s.begin(), s.end());
    while (zero--) s += '0';

    for (int i = 0; i < s.size(); ++i)
        if (s[i] != s[s.size() - i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    cout << "Yes" << endl;
    return 0;
}

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

bool check(string s){
    int size = s.size();
    bool flag = true;
    for(int i=0;i < size/2;i++){
        if(s.at(i) == s.at(size -i -1)) continue;
        else flag = false;
    }
    return flag;
}

int main(){
    int N;
    cin >> N;
    string s = to_string(N);
    for(int i=0;i<10;i++){
        if(check(s)){
            cout << "Yes" << endl;
            break;
        }
        s = '0' + s;
    }
    if(!check(s)){
        cout << "No" << endl;
    }

}


#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 5000000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i) * inv[mod % i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i % mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod * kai[a] % mod;
}
int main()
{
	int n, m;
	cin >> n >> m;
	int s = n;
	invinit();
	for (int i = 0; i < n; i++)
	{
		int z;
		cin >> z;
		s += z;
	}
	ll r = 1;
	if (n + m < s)
	{
		printf("0\n");
		return 0;
	}
	for (int i = 0; i < s; i++)
	{
		r = r * inv[s - i] % mod;
		r = r * (n + m - i) % mod;
	}
	printf("%lld\n", r);
}

#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#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)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
const int P = 1e9 + 7;
int n , m;
int A[MAXN];

int Pow( int x , int a ) {
    int ret = 1;
    while( a ) {
        if( a & 1 ) ret = ret * 1ll * x % P;
        x = x * 1ll * x % P , a >>= 1;
    }
    return ret;
}

int C( int a , int b ) {
    int ret = 1;
    per( i , a , a - b + 1 ) ret = ret * 1ll * i % P;
    rep( i , 1 , b ) ret = ret * 1ll * Pow( i , P - 2 ) % P;
    return ret;
}

void solve() {
    cin >> n >> m;
    int sa = 0;
    rep( i , 1 , n ) scanf("%d",A + i) , sa += A[i];
    cout << C( m + n , sa + n ) << endl;
}

signed main() {
//	freopen("input","r",stdin);
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mp make_pair
#define hello cout<<"hello"<<"\n"
#define forr(i,a,b) for(int i=a;i<b;i++)
#define it(s)	for(auto itr:s)
#define dvg(s) 	for(auto itr:s)	cout<<itr<<" ";cout<<endl;
#define dbg(s)	cout<<#s<<"= "<<s<<endl;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF=(lli)1e17+5;
const ulli MOD=1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout<< std::fixed;
    std::cout.precision(6);

	lli b,c;
	cin>>b>>c;
	if(c==1 && b!=0) {cout<<"2\n";return 0;}
	if(c<=2*b) {cout<<2*c-1<<"\n";return 0;}
	if(b>0) 	{cout<<c+2*b-1<<"\n";return 0;}
	else 	 cout<<c+abs(b)*2<<"\n";

    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int N, M, TIME=clock();
vector<pair<int, string>> V;
vi C(8);
int sum = 0;
vector<string> S(20);

int total() {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	vector<string> v(20);
	rep(i, N) v[i] = S[i];
	rep(q, 2) {
		rep(i, N) {
			s = v[i] + v[i];
			for (auto a : t) {
				bool f = false;
				rep(j, N) {
					if (a == s.substr(j, a.size())) {
						f = true;
						break;
					}
				}
				if (f) p += a.size();
				else u.insert(a);
			}
			t.clear();
			swap(t, u);
		}
		rep(i, N) { v[i].clear(); rep(j, N) v[i] += S[j][i]; }
	}
	return p;
}

int delta(int a, int b, int x, int y) {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	rep(q, 2) {
		s = S[a] + S[a];
		for (auto a : t) {
			bool f = false;
			rep(j, N) {
				if (a == s.substr(j, a.size())) {
					f = true;
					break;
				}
			}
			if (f) p += a.size();
			else u.insert(a);
		}
		t.clear();
		swap(t, u);
		swap(a, x);
	}
	rep(q, 2) {
		s = "";
		rep(i, N) s += S[i][b];
		rep(i, N) s += S[i][b];
		for (auto a : t) {
			bool f = false;
			rep(j, N) {
				if (a == s.substr(j, a.size())) {
					f = true;
					break;
				}
			}
			if (f) p += a.size();
			else u.insert(a);
		}
		t.clear();
		swap(t, u);
		swap(b, y);
	}
	return p;
}

int main() {
	cin >> N >> M;
	string s;
	rep(i, M) {
		cin >> s;
		V.pb({s.size(), s});
		rep(j, s.size()) C[s[j]-'A']++;
	}
	rep(i, 8) sum += C[i];
	rep(i, 7) C[i+1] += C[i];
	sort(all(V));

	int a=0, b=0, c=0, x, y, z;
	rep(i, N) {
		rep(j, N) {
			x = rand()%sum;
			rep(k, 8) {
				if (x < C[k]) {
					S[i] += 'A'+k;
					break;
				}
			}
		}
	}
	// show(total())
	int count = 0;
	while (true) {
		count++;
		a = rand()%N;
		b = rand()%N;
		x = rand()%N;
		y = rand()%N;
		c = delta(a, b, x, y);
		swap(S[a][b], S[x][y]);
		z = delta(a, b, x, y);
		if (c > z) swap(S[a][b], S[x][y]);
		// list(c)list(z) show(total())
		if (clock()-TIME > 2.9 * CLOCKS_PER_SEC) break;
	}
	// show(count)
	rep(i, N) std::cout << S[i] << '\n';
}


//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        int ct = 0;
        forr(i,1,n) {
            bool has7 = false;
            int nn = i;
            while (nn>0) {
                if (nn%10==7) {has7=true;}
                nn/=10;
            }
            nn = i;
            while (nn>0) {
                if (nn%8==7) {has7=true;}
                nn/=8;
            }
            if (!has7) {
                ++ct;
            }
        }
        cout << ct << endl;
    }
//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long f(long long n){
	return (n-1)/3;
}
long long g(long long n){
	long long ans=0;
	while(n>0){
		ans++;
		n/=10;
	}
	return ans;
}
int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int tt=1;
    while(tt--){
        long long n,d,i,ans=0; cin>>n;
        d=(long long)pow(10,g(n)-1);
        for(i=1;i<g(n);i++){
        	ans+=(long long)pow(10,i-1)*9*f(i);
		}
		ans+=(n-d+1)*f(i);
		cout<<ans;
    }
    return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  ll n;
  cin >> n;
  ll p = (n + 1) * 2;
  ll x = sqrt(p);
  if (x * (x + 1) / 2 > n + 1) {
    x--;
  }
  dump(n+1, x, x*(x+1)/2);
  cout << n - x + 1 << endl;
  // cout << c << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

//#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<unordered_map>
#include<queue>

#define INF 0x3f3f3f3f
#define ll long long
#define LL long long
#define ull unsigned long long
#define endl '\n'
#define ios ios::sync_with_stdio(false);
#define open freopen("in.in","w",stdout);
using namespace std;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    int ans = 100 - n%100;
    cout<<ans<<endl;
    return 0;
}


// arc110_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    string T;
    cin >> N >> T;

    string s = "110";
    ll ans = 0;
    REP(k, 3){

        bool same = true;
        REP(i, N){
            if (s[(i + k)%3] != T[i]){
                same = false;
                break;
            }
        }

        if (same){
            ans += (ll)1e10 - (k+N+2)/3 + 1;
        }
    }

    print(ans);

    return 0;
}

#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,n,a,b;
string s;
 main(){
	// t=1;
	cin>>a>>b;
	if(a>=b) {
		int sum=0;
		for(int i=1;i<=a;i++){
			cout<<i<<" ";
			if(i>=b) sum -= i;
		}
		 for(int i=1;i<=b;i++) {
			if(i<b) cout<<-i<<" ";
			else cout<<sum;
		}
	}
	else if(a<b) {
		swap(a,b);
		int sum=0;
		for(int i=1;i<=a;i++){
			cout<<-i<<" ";
			if(i>=b) sum += i;
		}
		 for(int i=1;i<=b;i++) {
			if(i<b) cout<<i<<" ";
			else cout<<sum;
		}
	}
}


#include <bits/stdc++.h>
#include <chrono>
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<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* find_by_order(x) give iterator of the index x
   order_by_key(x) give the position where x will be placed*/
#define int long long
#define lop(i,a,b,c) for (int i=a;i<b;i+=c)
#define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c)
#define prii pair <int,int>
#define PB push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define vvii vector < vector < int > >
#define vii vector <int>
#define count_1(x) __builtin_popcount(x)
#define cn(a) scanf("%lld",&a);
#define cn_vl(arr,n) lop(i,0,n,1){scanf("%lld",arr+i);}
#define shw_vl(arr,n) lop(i,0,n,1){printf("%lld ",arr[i]);}printf("\n");
const int MAX=2e5+10;
/*......................................................................*/
void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
struct dsu
{
	int parent[MAX];int size[MAX];
	void init(){
		lop (i,1,MAX,1){parent[i]=i;size[i]=1;}
	}
	int trace(int a){
		return (a==parent[a])?a:parent[a]=trace(parent[a]);
	}
	bool connect(int a,int b){
		if ((a=trace(a))==(b=trace(b)))return false;
		if (size[b]>size[a])swap(a,b);
		parent[b]=a;size[a]+=size[b];
		return true;
	}
}ori;
struct abc{
	int u,c,d;
};
int f(int a,int b){
	int re=LLONG_MAX;
	lop (i,-1,2,1){
		int z=b+i;
		if (z<0)z=0;
		re=min(z+a/(1+z),re);
	}
	return re;
}
vector <abc> adj[MAX];const int INF=LLONG_MAX;
void dijsktra(int u,vii &dst,int n){

	dst.assign(n+1,INF);
	dst[u]=0;
	priority_queue < prii ,vector <prii> ,greater <prii>> q;
	q.push({0,u});
	while (!q.empty()){
		 int wt=q.top().F;
		 int u=q.top().S;q.pop();
		 if  (wt!=dst[u]){
		 	continue;
		 }
		 //cout<<u<<" "<<wt<<"\n";
		 for (auto v:adj[u]){
		 	int re=sqrt(v.d);
		 	int zr=dst[u];
		 	// cout<<v.u<<" "<<re<<" ";
		 	if (wt>re){
		 		re=wt;
		 	}
		 	zr=re;
		 	re=v.c+v.d/(re+1);
					 	// cout<<ren";
		 	if (re+zr<dst[v.u]){
		 		dst[v.u]=re+zr;
		 		q.push({dst[v.u],v.u});
		 	}
		 }
	}

}
void solve(){
	int n,m;cn(n)cn(m)
	lop (i,0,m,1){
		int a,b,c,d;
		cn(a)cn(b)cn(c)cn(d)
		 if (a!=b){
		 	adj[a].PB({b,c,d});
			adj[b].PB({a,c,d});
		 }
	}
	vii dst;
	dijsktra(1,dst,n);
	int z=dst[n];
	if (z==INF){
		z=-1;
	}
	cout<<z<<"\n";
}
int32_t main(){
	int t;t=1;
	// cin>>t;
	while (t--){
		auto t_1=chrono::high_resolution_clock::now();
		solve();
		auto t_2=chrono::high_resolution_clock::now();
		// cout <<". Elapsed (ms): " << chrono::duration_cast<chrono::milliseconds>(t_2 - t_1).count() << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int Mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

int main()
{
    su;
    string s,t;
    cin>>s;
    int n=sz(s),cnt;
    if(n==1&&s=="8")
        yes;
    else if(n==2)
    {
        if(stoi(s)%8==0)
            yes;
        else
        {
            swap(s[0],s[1]);
            if(stoi(s)%8==0)
                yes;
            else
                no;
        }
    }
    else if(n>=3)
    {
        map<char,int>m,mp;
        for(int i=0; i<n; i++)
        {
            m[s[i]]++;
        }
        if(m['0']>=3)
            yes;
        else
        {
            for(int i=104; i<1000; i+=8)
            {
                t=to_string(i);
                cnt=0;
                mp=m;
                for(int j=0; j<sz(t); j++)
                {
                    if(mp[t[j]]>=1)
                    {
                        cnt++;
                        mp[t[j]]--;
                    }
                }
                if(cnt==sz(t))
                {
                    yes;
                    return 0;
                }
            }
            no;
        }
    }
    else
        no;

    return 0;
}


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

const int INF = 1e9;

vector<int> adj[200005];
int n, k;
array<int, 3> dp[200005]; // (#special, min dist(u, special), max dist(u, not satisfy yet))

array<int, 3> combine(array<int, 3> a, array<int, 3> b, int d) {
    array<int, 3> res;
    res[0] = a[0] + b[0];
    res[1] = min(a[1], b[1] + 1);
    res[2] = max(a[2], b[2] + 1);

    if (res[1] + res[2] <= d) {
        res[2] = -INF;
    }
    else if (res[2] == d) {
        res[0]++;
        res[1] = 0;
        res[2] = -INF;
    }
    return res;
}

void dfs(int u, int p, int d) {
    dp[u] = {0, d + 1, 0};

    for (auto i: adj[u]) {
        if (i == p) continue;
        dfs(i, u, d);
        dp[u] = combine(dp[u], dp[i], d);
    }
    // cout << u << " " << dp[u][0] << " " << dp[u][1] << " " << dp[u][2] << endl;
}

int solve(int d) {
    dfs(1, 0, d);
    return dp[1][0] + (dp[1][2] >= 0);
    // cout << dp[1][0] << endl;
}

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> k;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    // cout << solve(2) << endl;
    // return 0;
    // for (int i = 1; i <= n; i++) {
    //     cout << solve(i) << " ";
    // }
    // return 0;
    int lower = 1, upper = n;
    while (lower < upper) {
        int mid = (lower + upper) / 2;
        if (solve(mid) <= k) {
            upper = mid;
        }
        else lower = mid + 1;
    }

    cout << lower << endl;

    return 0;
}

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

int main() {
	long long N, M; cin >> N >> M;
	vector<long long> X(M), Y(M);
	for (int i = 0; i < M; i++) cin >> X[i] >> Y[i];

	set<pair<long long, long long>> Set;
	for (int i = 0; i < M; i++) {
		Set.insert(make_pair(X[i], Y[i]));
	}

	set<long long> Sec;
	Sec.insert(N);
	Sec.insert(-(1LL << 60)); Sec.insert(1LL << 60); Sec.insert(1LL << 59);
	long long prev = 0;
	set<long long> help, help2;
	for (int i = 0; i < M; i++) {
		auto a = *Set.begin();
		Set.erase(Set.begin());
		if (prev != a.first) {
			while (!help2.empty()) {
				Sec.erase(*help2.begin());
				help2.erase(help2.begin());
			}
			while (!help.empty()) {
				Sec.insert(*help.begin());
				help.erase(help.begin());
			}
          	prev = a.first;
		}
		auto b = Sec.lower_bound(a.second);
		if (*b == a.second) help2.insert(a.second); b--;
		if (*b == a.second - 1) help.insert(a.second); b++;
		if (*b == a.second + 1) help.insert(a.second); b++;
		if (*b == a.second + 1) help.insert(a.second);
	}

	while (!help2.empty()) {
		Sec.erase(*help2.begin());
		help2.erase(help2.begin());
	}
	while (!help.empty()) {
		Sec.insert(*help.begin());
		help.erase(help.begin());
	}

	cout << Sec.size() - 3 << endl;
}


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

#define all(a) (a).begin(), (a).end()
#define int long long

bool can[(int) 1e5 + 5] = {false};

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x: a) cin >> x;

    int s = accumulate(all(a), 0);

    can[0] = true;
    for (int i = 0; i < n; ++i) {
        for (int j = (int)1e5; j >= 0; --j) {
            if (j + a[i] <= (int)1e5)
                can[j + a[i]] |= can[j];
        }
    }

    int mn = 1e18;
    for (int j = 0; j <= (int)1e5; ++j) {
        if (can[j])
            mn = min(mn, max(j, s - j));
    }
    cout << mn;
}

#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
const int mod=1e9+7;
int n,i,a[100005],s=1;
int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a+1,a+n+1);
	rep(i,n){
		s=1ll*s*(a[i]-a[i-1]+1)%mod;
	}
	cout<<s<<endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}};
vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}};

ll INF = INT64_MAX;

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();

	bool first_boost = true;

	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}

		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}

	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);

ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}

ll H,W;
vector<vector<char>> map1(501, vector<char>(501,'#'));

bool solve(ll h, ll w){
	ll nexth=0;
	ll nextw=0;

	for(vector<ll> to:near4){
		nexth = h+to[0];
		nextw = w+to[1];
		if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){
			continue;
		}
		if(map1[nexth][nextw] =='g'){
			return true;
		}
		map1[nexth][nextw]='#';
		if(solve(nexth, nextw)){
			return true;
		};
	}

	return false;
}

int main() {
	ll a,b,c;
	cin >> a>>b>>c;

	ll ans=0;
	ans+=(7-a);
	ans+=(7-b);
	ans+=(7-c);

	cout << ans << endl;

  return 0;
}

/*
   Before submitting, please CHECK:
   maxn, modu, inf, eps
*/
#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define PB push_back
#define MK make_pair
#define ALL(x) x.begin(), x.end()
#define FT first
#define SC second
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

const int maxn = 2e6 + 5;
const int modu = 1e9 + 7; // 1e9 + 7
const int inf = 0x7fffffff;
const double eps = 1e-5;
typedef long long LL;

int n, m, k;
LL inv[maxn];

LL C(int n, int m) {
	if (m > n) return 0;
	LL res = 1;
	for (int i = n; i >= n-m+1; --i) res = res*i % modu;
	for (int i = 1; i <= m; ++i) res = res * inv[i] % modu;
	return res;
}

int main() {
    // freopen("my.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> m >> k;
	if (n > m + k) {
		cout << 0 << endl;
		return 0;
	}
	inv[1] = 1;
	for (int i = 2; i <= n+m; ++i)
		inv[i] = (modu - (modu/i))*inv[modu%i]%modu;
	cout << ((C(n+m, n) - C(n+m, m+k+1)) % modu + modu)%modu << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
	int n;
	long long c;
	cin>>n>>c;
	vector<long long> a(n),b(n);
	vector<long long> c1(n);
	set<int> s;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c1[i];
		s.insert(a[i]);
		s.insert(b[i]+1);
	}
	map<long long,long long> m;
	vector<long long> rev(2*n+1);
	int cord = 0;
	for(auto el: s){
		rev[cord] = el;
		m[el] = cord++;
	}
	vector<long long> p(cord+5);
	for(int i=0;i<n;i++){
		p[m[a[i]]] += c1[i];
		p[m[b[i]+1]] -= c1[i];
	}
	long long cost =min(c, p[0]);
	for(int i=1;i<cord;i++){
		cost += min(p[i-1],c)*(rev[i]-rev[i-1]-1);
		p[i] += p[i-1];
		cost += min(p[i], c);
	}
	cout<<cost<<"\n";
}

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

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

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>
#include <bitset>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define rep1(i, n) for(ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
// 小さい順
#define asort(arr, size) std::sort((arr), (arr) + (size))
// 大きい順
#define dsort(arr, size) std::sort((arr), (arr) + (size), [](auto a, auto b) { return a > b; })
#define vsort(vec) std::sort((vec).begin(), (vec).end());
#define rsort(vec) std::sort((vec).begin(), (vec).end(), [](auto a, auto b) { return a > b; });
#define bit(n) (1LL << (n))

// 行数多く出力するとき用

inline void println(int n) {
    printf("%d\n", n);
}
inline void println(ll n) {
    printf("%lld\n", n);
}
inline void println(ull n) {
    printf("%llu\n", n);
}

inline void println(int* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%d ", n[i]);
    }
    printf("%d\n", n[size - 1]);
}
inline void println(ll* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%lld ", n[i]);
    }
    printf("%lld\n", n[size - 1]);
}
inline void println(ull* n, size_t size) {
    FOR(i, 0, size - 1) {
        printf("%llu ", n[i]);
    }
    printf("%llu\n", n[size - 1]);
}

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

int main() {
    ll N, C;
    cin >> N >> C;
    vector<pair<ll, ll>> events;
    rep(i, N) {
        ll a, b, c;
        cin >> a >> b >> c;
        events.emplace_back(a - 1, c);
        events.emplace_back(b, -c);
    }
    vsort(events);

    ll ans = 0, fee = 0, t = 0;
    foreach(event, events) {
        if (event.first != t) {
            ans += min(C, fee) * (event.first - t);
            t = event.first;
        }
        fee += event.second;
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	//freopen("in.txt", "r", stdin);
	int tt;
	cin >> tt;
	while (tt--) {
		long long n;
		cin >> n;
		if (n & 1) {
			puts("Odd");
		} else {
			n >>= 1;
			if (n & 1) puts("Same");
			else puts("Even");
		}
	}

	return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
#define int ll
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int MAXN = 1000000;
//int fa[MAXN];
int b[205];

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

   int res = 0;
   for(int i=0;i<n;i++)
   {
       int x;
       cin >>x;
       b[x%200]++;
   }
   for(int i=0;i<200;i++)
    res += (b[i]-1)*b[i]/2;
   cout << res;

}

signed main(){
    ios::sync_with_stdio(0);cin.tie(nullptr);
    int _=1;
    //cin>>_;
    for(_;_--;)
    {
        solve();
    }
    return 0;
}


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

int n,m;
long long f[20][1<<18];
vector<pair<int,int>> cs[25];

int main(){

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

    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        x--;
        y--;
        cs[x].emplace_back(y,z);
    }
    f[0][0]=1;
    for(int i=0;i<n;i++){
        for(int s=0;s<1<<n;s++)if(f[i][s]){
            static int pre[18];
            pre[0]=s&1;
            for(int j=1;j<n;j++)pre[j]=pre[j-1]+(s>>j&1);
            for(int j=0;j<n;j++)if(s>>j&1^1){
                bool can=true;
                for(pair<int,int> &p:cs[i])if(p.second<pre[p.first]+(p.first>=j)){
                    can=false;
                    break;
                }
                if(can)f[i+1][s|1<<j]+=f[i][s];
            }
        }
    }
    cout<<f[n][(1<<n)-1];

    return 0;
}

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

int main(){
  int n, t; cin >> n;
  double a, b;
  vector<double> l(n), r(n);
  for(int i = 0; i < n; ++i){
    cin >> t >> a >> b;
    if(t == 2){b -= 0.1;}
    else if(t == 3){a += 0.1;}
    else if(t == 4){a += 0.1; b -= 0.1;}
    l[i] = a; r[i] = b;
  }

  // for(int i = 0; i < n; ++i){cout << l[i] << " ";}cout << endl;
  // for(int i = 0; i < n; ++i){cout << r[i] << " ";}cout << endl;

  double c, d, e, f;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(i == j){continue;}
      c = l[i]; d = r[i]; e = l[j]; f = r[j];
      if(d > f){swap(c, e); swap(d, f);}
      if(d >= e){ans += 1;}
    }
  }
  cout << ans/2 << endl;
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
int N;
int P[555];

vector<int> R;
void go(int x) {
	swap(P[x],P[x+1]);
	R.push_back(x);
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>T;
	while(T--) {
		cin>>N;
		FOR(i,N) {
			cin>>P[i];
			P[i]--;
		}
		R.clear();
		int step=0;

		for(i=N-1;i>=3;i--) {
			FOR(j,N) if(P[j]==i) break;
			if(j==i) continue;

			if(i==3&&j==2&&step==1) {
				go(1);
				go(2);
				j=1;
			}

			while(j<i) {
				if(step==j%2) {
					go(j);
					j++;
				}
				else if(step==0) {
					if(j==1) go(2);
					else go(0);
				}
				else {
					if(j==2) go(3);
					else go(1);
				}
				step^=1;
			}
		}

		while(1) {
			for(j=N-1;j>=0;j--) if(P[j]!=j) break;
			if(j<0) break;
			assert(j<3);
			swap(P[step],P[step+1]);
			R.push_back(step);
			step^=1;
		}

		cout<<R.size()<<endl;
		FOR(i,R.size()) {
			assert(R[i]%2==i%2);
			cout<<(R[i]+1)<<" ";
		}
		cout<<endl;
		FOR(i,N) assert(P[i]==i);

	}
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using lli = long long int;

int main(){
    int t;
    cin >> t;
    for(int rep=0; rep<t; rep++){
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        vector<vector<int>> wait(2);
        for(int i=0; i<n-1; i++){
            if(a[i] > a[i+1]){
                wait[i%2].push_back(i);
            }
        }
        vector<int> ans;
        for(int i=0; i<n*n; i++){
            int p = -1;
            int d = i%2;
            while(!wait[d].empty()){
                int pos = wait[d].back();
                wait[d].pop_back();
                if(a[pos] > a[pos+1]){
                    p = pos;
                    break;
                }
            }
            while(!wait[1-d].empty()){
                int pos = wait[1-d].back();
                if(a[pos] > a[pos+1]){
                    break;
                }else{
                    wait[1-d].pop_back();
                }
            }
            if(p == -1 and wait[1-d].empty()){
                break;
            }
            if(p == -1) p = d;
            ans.push_back(p);
            swap(a[p], a[p+1]);
            if(a[p] > a[p+1]){
                wait[d].push_back(p);
            }
            if(p != 0 and a[p-1] > a[p]){
                wait[1-d].push_back(p-1);
            }
            if(p != n-2 and a[p+1] > a[p+2]){
                wait[1-d].push_back(p+1);
            }
        }
        cout << ans.size() << endl;
        for(int i: ans){
            cout << i+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


/* ** *** Be Name Khoda *** ** */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, z = 1;
    cin >> n;
    int x = 38, y = 26;
    vector<ll> v3, v5;
    while (x--)
    {
        z *= (ll)3LL;
        v3.push_back(z);
    }
    z = 1;
    while (y--)
    {
        z *= (ll)5LL;
        v5.push_back(z);
    }
    for (int i = 0; i < v3.size(); i++)
    {
        for (int j = 0; j < v5.size(); j++)
        {
            if (v3[i]+v5[j]<0) break;
            if (v3[i] + v5[j] == n)
                return cout << i+1 << ' ' << j+1, 0;
        }
    }
    cout << -1;
    return 0;
}

#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modInverse(unsigned long long n,
                                            int p)
{
    return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
                                 int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
    return (fact[n] * modInverse(fact[r], p) % p
            * modInverse(fact[n - r], p) % p)
           % p;
}
int32_t main()
{
  IOS
  string s;
  cin>>s;
  cout<<s[1]<<s[2]<<s[0];
  return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

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

	ll k,n,m; cin>>k>>n>>m;
	vector<ll> a(k);
	rep(i,k) cin>>a[i];

	vector<ll> b(k, 0);
	rep(i,k)
	{
		b[i] = a[i] * m;
		b[i] /= n;
	}
	ll lim = m;
	rep(i,k)
		lim -= b[i];
	vector<pair<ll,int>> c(k);
	rep(i,k)
	{
		pair<ll,int>p = make_pair(n*b[i] - m*a[i], i);
		c[i] = p;
	}
	sort(c.begin(), c.end());
	int cnt = 0;
	while (cnt < lim)
	{
		b[c[cnt].second]++;
		cnt++;
	}
	rep(i,k)
		cout << b[i] << " \n"[i == k-1];
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll startTime;
const int Di[] = {-1,+1, 0, 0};
const int Dj[] = { 0, 0,-1,+1};
long long getTime() {
	timespec ts;
	clock_gettime(CLOCK_REALTIME_COARSE, &ts);
	long long r = ts.tv_sec;
	r *= 1000000000;
	r += ts.tv_nsec;
	return r;
}
struct Input {
	int Si, Sj;
	vector<vector<int>> T, P;
	Input() : T(50, vector<int>(50)), P(50, vector<int>(50)) {
		cin >> Si >> Sj;
		for (auto& a : T) for (auto& x : a) cin >> x;
		for (auto& a : P) for (auto& x : a) cin >> x;
	}
};
struct State {
	vector<bool> visited;
	int i, j, score;
	State(){}
	State(int M, int i, int j, int score) : visited(M), i(i), j(j), score(score) {}
};
struct Solver {
	const Input& X;
	mt19937 mt;
	int M;
	pair<int,int> best0;
	int cnt_best0;
	pair<int,pair<int,int>> best1;
	Solver(const Input& x) : X(x) {
		random_device seed_gen;
		mt = mt19937(seed_gen());
	}
	int rnd(int n) {
		return uniform_int_distribution<>(0,n-1)(mt);
	}
	bool valid(const State& s, int d) {
		int i = s.i + Di[d];
		int j = s.j + Dj[d];
		return 0 <= i && i < 50 && 0 <= j && j < 50 && !s.visited[X.T[i][j]];
	}
	void move(State& s, int d) {
		s.i += Di[d];
		s.j += Dj[d];
		s.visited[X.T[s.i][s.j]] = true;
		s.score += X.P[s.i][s.j];
	}
	void f(int p, int q, int prev, const State& s) {
		if (p == 15) {
			if (s.score > best0.first) {
				best0 = {s.score, q};
				cnt_best0 = 1;
			} else if (s.score == best0.first) {
				if (rnd(++ cnt_best0) == 0) {
					best0 = {s.score, q};
				}
			}
			return;
		} else {
			best1 = max(best1, {s.score, {p, q}});
		}
		for (int d = 0; d < 4; ++ d) if ((d^1) != prev && valid(s, d)) {
			State ss = s;
			move(ss, d);
			f(p+1, q | (d << (2*p)), d, ss);
		}
	}
	void solve() {
		M = 0;
		for (auto& a : X.T) for (auto& x : a) M = max(M, x+1);

		int best_score = -1;
		vector<int> best_res;

		{
			State s0(M, X.Si, X.Sj, X.P[X.Si][X.Sj]);
			s0.visited[X.T[X.Si][X.Sj]] = true;
			vector<int> res;
			for (;;) {
				best0 = {-1, 0};
				best1 = {-1, {0, 0}};
				f(0, 0, -1, s0);
				if (best1.first > best_score) {
					best_score = best1.first;
					auto rr = res;
					for (int i = 0; i < best1.second.first; ++ i) {
						int d = (best1.second.second >> (2*i)) & 3;
						rr.push_back(d);
					}
					best_res = rr;
				}
				if (best0.first == -1) {
					break;
				} else {
					int d = best0.second & 3;
					res.push_back(d);
					move(s0, d);
				}
			}
		}

		cerr << "score = " << best_score << endl;
		for (auto x : best_res) cout << "UDLR"[x];
		cout << endl;
	}
};
int main() {
	startTime = getTime();
	Input x;
	Solver y(x);
	y.solve();
}

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int t[55][55];
int p[55][55];
bool bo[2600] = { false };
int b1[4];
int b2[4];
int b3[4] = { 1,-1,0,0 };
int b4[4] = { 0,0,1,-1 };
int b5[4] = { 0,1,2,3 };
int main() {
	int x, y;
	cin >> x >> y;
	stack<pair<int, int>> s;
	s.push(make_pair(x, y));
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> t[i][j];
		}
	}
	bo[t[x][y]] = true;
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> p[i][j];
		}
	}
	string ans = "";
	int score = -1000000007;
	vector<pair<int, int>> vec;
	bool bo2[2600];
	do {
		for (int i = 0; i < 4; i++) {
			b1[i] = b3[b5[i]];
			b2[i] = b4[b5[i]];
		}
		string ans1 = "";
		int score1 = 0;
		vector<pair<int, int>> vec1;
		while (1) {
			int nx = s.top().first;
			int ny = s.top().second;
			bool bo1 = false;
			for (int i = 0; i < 4; i++) {
				if (nx + b1[i] < 0 || nx + b1[i] >= 50 || ny + b2[i] < 0 || ny + b2[i] >= 50)continue;
				if (!bo[t[nx + b1[i]][ny + b2[i]]]) {
					bo[t[nx + b1[i]][ny + b2[i]]] = true;
					s.push(make_pair(nx + b1[i], ny + b2[i]));
					bo1 = true;
					break;
				}
			}
			if (!bo1) {
				vec1.emplace_back(make_pair(nx, ny));
				score1 += p[nx][ny];
				while (s.size() > 1) {
					s.pop();
					if (nx == s.top().first + 1) {
						ans1 += 'D';
					}
					if (nx == s.top().first - 1) {
						ans1 += 'U';
					}
					if (ny == s.top().second + 1) {
						ans1 += 'R';
					}
					if (ny == s.top().second - 1) {
						ans1 += 'L';
					}
					nx = s.top().first;
					ny = s.top().second;
					vec1.emplace_back(make_pair(nx, ny));
					score1 += p[nx][ny];
				}
				reverse(ans1.begin(), ans1.end());
				reverse(vec1.begin(), vec1.end());
				if (score < score1) {
					ans = ans1;
					score = score1;
					vec = vec1;
					for (int i = 0; i <= 2500; i++) {
						bo2[i] = bo[i];
					}
				}
				break;
			}
		}
		while (!s.empty()) {
			s.pop();
		}
		s.push(make_pair(x, y));
		for (int i = 0; i <= 2500; i++) {
			bo[i] = false;
		}
		bo[t[x][y]] = true;
	} while (next_permutation(b5, b5 + 4));
	for (int i = 0; i < 10000; i++) {
		int ni = rand() % (vec.size() - 1);
		if (vec[ni].first == vec[ni + 1].first) {
			if (vec[ni].second == vec[ni + 1].second - 1) {
				if (!bo2[t[vec[ni].first][vec[ni].second + 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DRU" + ans.substr(ni, ans.size() - ni);
					}
				}
				if (!bo2[t[vec[ni].first][vec[ni].second - 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second - 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "URD" + ans.substr(ni, ans.size() - ni);
					}
				}
			}
			else {
				if (!bo2[t[vec[ni].first][vec[ni].second + 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DLU" + ans.substr(ni, ans.size() - ni);
					}
				}
				if (!bo2[t[vec[ni].first][vec[ni].second - 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second - 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DRU" + ans.substr(ni, ans.size() - ni);
					}
				}
			}
		}
	}
	cout << ans << endl;
}