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

/*** Template Begins ***/

typedef long long    ll;
typedef pair<ll,ll>  PII;
typedef pair<ll, pair<int, int> > PIII;
typedef vector<int>  vi;

#define endl         '\n'
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; }

// Debug //

#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

// Constants //

const int N = 15;
const int xinc[] = {0, 0, 1, -1};
const int yinc[] = {1, -1, 0, 0};
const long double PI = 3.141592653589793;

/*** Template Ends ***/
string s[N];
int c[N], b[N], n;
int a[N], ans[N];

bool satisfy(){

    set<int> s;
    for(int i = 0; i < 4; i++)  s.insert(a[i]);
    return (s.size() == 4);
}

void solve(){

    cin >> n;
    for(int i = 0; i < n; i++)  cin >> s[i] >> b[i] >> c[i];

    int cnt = 0;

    for(a[0] = 0; a[0] <= 9; a[0]++)
        for(a[1] = 0; a[1] <= 9; a[1]++)
            for(a[2] = 0; a[2] <= 9; a[2]++)
                for(a[3] = 0; a[3] <= 9; a[3]++)
                    if (satisfy())
                    {
                        bool valid = true;

                        for(int i = 0; i < n; i++)
                        {
                            int bb = 0, cc = 0;
                            set<int> temp;

                            for(int j = 0; j < 4; j++){
                                if (a[j] == s[i][j]-'0')   bb++;
                                temp.insert(a[j]);
                            }

                            for(int j = 0; j < 4; j++){
                                if (temp.find(s[i][j]-'0') != temp.end())    cc++;
                            }

                            cc -= bb;
                            if (cc != c[i] || bb != b[i]){  valid = false;  break;  }
                        }

                        if (valid){
                            //for(int i = 0; i < 4; i++)  cout << a[i];   cout << endl;
                            cnt++;
                            if (cnt == 1)   for(int i = 0; i < 4; i++)  ans[i] = a[i];
                        }
                    }

    if (cnt == 0)   cout << "Incorrect data" << endl;
    else if (cnt == 1){  for(int i = 0; i < 4; i++)  cout << ans[i]; cout << endl;   }
    else cout << "Need more data" << endl;

}

int main(){

    ios;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t;
    //cin >> t;
    t = 1;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,l,ans,ll;
string s;
int main(){
    cin>>s;
    l=s.length();
    i=0;
    while(i<l-1)
    {
        ll=1;
        if(s[i]==s[i+1])
        {
            while(s[i]==s[i+1]&&i<l-1) i++,ll++;
            if(ll%2==0) ans++;
        }
        else i++;
    }
    cout << ans;
    return 0;
}


# include <iostream>
using namespace std;
int main()
{
	 double n,k;
	long long g;
	cin>>n>>k;
	g = ceil(2*n/k)+ceil(5*n/k)+ceil(8*n/k);
	cout<<g<<endl;
}


#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()) cout<<x[i]<<" "; cout<<endl;

#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)

#define tc() int tcase; cin >> tcase ; rep(tc,1,tcase+1)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair

// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }

#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);

ll gcd(ll a,ll b){ return ((b==0)? a:gcd(b,a%b) ); }
#define PI acos(-1)
#define N 1000000

bitset<10000010> bs;
vi smp;
void sieve(int upr)
{
    bs.set();
    int siz  = upr+1;
    smp.resize(siz);
    rep(i,0,siz)
        smp[i] = i;

    for(ll i=2;i<siz;i++)
    {
        if(smp[i]== i)
        {
            for(ll j=i*i;j<=siz;j+=i)
            {
                if(smp[j]==j) smp[j] = i;
            }
        }
    }
}

ll apow(ll x,ll n)
{
    if(n==1)
        return x;
    ll res = apow(x,n/2);
    res = (res*res)%MOD;
    if(n%2==1)
        res = (res*x)%MOD;
    return res;
}

int main()
{
    SYNC
    int n,k;
    cin>>n>>k;

    /*int pts = 0;
    int pol = 0;

    set<pair<int,int> > pos;

    pos.insert(MP(3,3));
    for(int i=4;i<=n;i++)
        pos.insert(make_pair(i-1,i));

    set<int> vis;
    while(pol < k)
    {
        pair<int,int> x = *pos.begin();
        pos.erase(pos.begin());
        if(vis.find(x.second) != vis.end())
            continue;

        pol++;
        pts+= x.F;
        trace2(x.F,x.S);
        vis.insert(x.second);

        for(int j=2*x.second;j<=n;j+= x.second)
        {
            pos.insert(make_pair(j-x.second,j) );
        }

    }
    cout<<pts<<endl;*/

    sieve(N);
    vll inv(N+1);
    for(int i=2;i<=N;i++)
        inv[i] = apow(i,MOD-2);
    //trace1(smp.size());
    vi phi;
    for(int i=3;i<=n;i++)
    {
        set<ll> fact;
        ll tmp = i;
        while(smp[tmp] != tmp)
        {
            fact.insert(smp[tmp]);
            tmp/=smp[tmp];
        }
        if(tmp!=1 )
        {
            fact.insert(tmp);
        }

        ll val=i;
        tr(fact,it)
        {
            val = ((*it-1)*val)%MOD;
            val = (val*inv[*it])%MOD;
        }

        if(i == 4)
            val++;
        phi.pb(val);
        //trace2(i,val);
    }

    sort(phi.begin(),phi.end());
    ll sum = 0;
    rep(i,0,k)
    {
        sum+= phi[i];
    }
    if(k ==2 && n>=6)
        sum++;
    cout<<sum+1<<endl;

}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma warning( disable : 4244 4267 4018 4996 4800 )
//#pragma comment( linker, "/stack:10000000" )
using namespace std;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<string> vs; typedef vector<double> vd;
typedef vector<vd> vvd; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> pii;
#define all(v) begin(v), end(v)

#ifdef LOCAL
ifstream in("c.in");
#else
istream & in = cin;
#endif
ostream & out = cout;
template <class T> void read(T & t) { for (auto & x : t) in >> x; }

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n; in >> n;
    vs p(n); read(p);
    int m = p[0].size();
    vll d(1 << m);
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int mask = 0;
            for (int k = 0; k < m; ++k) {
                if (p[i][k] == p[j][k])
                    mask |= 1 << k;
            }
            d[mask] |= 1LL << i;
            d[mask] |= 1LL << j;
        }
    }
    for (int mask = d.size() - 1; mask >= 0; --mask) {
        for (int bit = 0; bit < m; ++bit) if (mask & (1 << bit)) {
            d[mask ^ (1 << bit)] |= d[mask];
        }
    }
    vd paths(m + 1);
    for (int mask = 0; mask < d.size(); ++mask) {
        int moves = bit_count(mask) + 1;
        for (int bit = 0; bit < m; ++bit) {
            int newmask = mask | (1 << bit);
            if (newmask == mask) continue;
            ll added = d[mask] ^ d[newmask];
            paths[moves] += bit_count(added & 0xFFFFFFFF) + bit_count(added >> 32);
        }
    }
    double res = 0;
    for (int i = 1; i <= m; ++i) {
        double t = paths[i];
        for (int j = 0; j < i; ++j) {
            t *= 1. * (i - j) / (m - j);
        }
        res += t;
    }
    res /= n;
    out.setf(ios::fixed); out.precision(10); out << res;
    return 0;
}


#include <iostream>
#include <algorithm>
#include<vector>
#include <iterator>
#include <array>
using namespace std;

int main()
{
    int supply_lines , devices ,sockets , All_sockets , sockets_needed = 0;
    cin>>supply_lines>>devices>>sockets;
    All_sockets = sockets;
    vector<int> a(supply_lines);

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

    int j =0;
    sort(a.rbegin(),a.rend());         // sorting in a descending order
    for( j = 0 ; j<supply_lines+1; j++)
    {
         if(All_sockets >= devices)
                break;

            All_sockets += a[j] -1 ;
            a[0] = 0;
            sockets--;
            sockets_needed++;

    }

    if(j==supply_lines+1)
    {
         cout << -1;
    }
    else
    {
        cout << sockets_needed;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define f first
#define se second

int main()
{
    ll n,i;
    cin>>n;
    ll a[10],b[10],c[10];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    if(n>=1)
    {
        for(i=0;i<6;i++)
        {
            ll x;cin>>x;
            a[x]=1;
        }
    }
    if(n>=2)
    {
        for(i=0;i<6;i++)
        {
            ll x;cin>>x;
            b[x]=1;
        }
    }
    if(n>=3)
    {
        for(i=0;i<6;i++)
        {
            ll x;cin>>x;
            c[x]=1;
        }
    }
    for(i=1;i<=9;i++)
    {
        if(a[i]==0 && b[i]==0 && c[i]==0)
        {
            cout<<i-1;
            return 0;
        }
    }
    for(i=10;i<=99;i++)
    {
        ll x=i%10;
        ll y=i/10;
        if(a[x]==1 && b[y]==1)
        continue;
        if(a[x]==1 && c[y]==1)
        continue;
        if(b[x]==1 && c[y]==1)
        continue;
        if(b[x]==1 && a[y]==1)
        continue;
        if(c[x]==1 && b[y]==1)
        continue;
        if(c[x]==1 && a[y]==1)
        continue;

        cout<<i-1;
        return 0;
    }
}


//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long
#define pii pair<int, int>

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

int n;

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

  cin >> n;

  int d = 1;
  int sz = 1;

  while (sz * 2 + 1 <= n)
    {
      sz = sz * 2 + 1;
      d = d * 2;
    }

  int r = n - sz;

  int z = 0;
  for (int t = 2; t <= d; t *= 4)
    z += d / t;

  /*
  err(n);
  err(d);
  err(z);*/

  if ((r == z) or (r == (z + 1)))
    cout << 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
char a[11],b[11],c[11],d[11];
int main()
{
	while(~scanf("%s%s%s%s",a,b,c,d))
	{
		a[2]=b[1],a[3]=b[0],c[2]=d[1],c[3]=d[0];
		int i=0,j=0,flag=1;
		while(a[i]!='A')i++;
		while(c[j]!='A')j++;
		for(int k=0;k<4;k++,i=(i+1)%4,j=(j+1)%4)
		{
			if(a[i]=='X')i=(i+1)%4;
			if(c[j]=='X')j=(j+1)%4;
			if(a[i]!=c[j])flag=0;
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
long long n;
int main() {
	cin>>n;
	cout<<n*(n-1)*(n-2)*(n-3)*(n-4)/120*n*(n-1)*(n-2)*(n-3)*(n-4);
	return 0;
}


#include<stdio.h>
#include<string.h>
int n,m,m_er,cnt;
int dire;    //// 记录方向，1表示向前（左），0表示向后（右）
char ss[205];

void begin()
{
    if(ss[0]=='h') dire=1;
    else dire=0;
}

void mm_er(  )
{
   // printf("dire= %d m_er%d\n",dire,m_er);
    if( dire == 1 ) ////向左走
    {
        if( m_er == 1 )
        {
            m_er++;
            dire = ( dire+1 )%2 ;
        }
        else  m_er--;
    }
    else
    {
        if( m_er == n )
        {
            m_er--;
            dire = ( dire+1 )%2 ;
        }
        else  m_er++;
    }
}

void mm_m1( int i )
{
  // printf("dire= %d m=%d\n",dire,m);
    if( ss[i] == '0' ) // //车move
    {
        if( dire == 0 ) //// Controller向右走
        {
            if( m < m_er ){
                if(m!=1)  m--;
            }
            else if( m < n ) m++;
        }
        else  //// Controller向左走
        {
            if( m > m_er ){
                if( m != n ) m++;
            }
            else if( m > 1 ) m--;
        }
    }
    else  ////车idle
    {
        if( dire == 0 )//// Controller向右走
            m=m_er-1;
        else // // Controller向左走
            m=m_er+1;
    }
}

int find( )
{
    int l=strlen(ss);
    for(int i=0;i<l;i++)
    {
        if(m==m_er&&i!=0)
        {
            cnt=i;
            return false;
        }
        if(ss[i]=='0')
        {
            if(i+1<l&&m_er==n-1&&m==n&&dire==0&&ss[i+1]=='0'){
                cnt=i+1;
                return false;
            }
            if(i+1<l&&m_er==2&&m==1&&dire==1&&ss[i+1]=='0'){
                cnt=i+1;
                return false;
            }

        }
        mm_er( );
        mm_m1( i );
        //printf("i= %d  %d %d\n",i,m,m_er);
    }
    return true;
}

int main( )
{
    char s[100];
    while(~scanf("%d",&n))
    {
        scanf("%d%d",&m,&m_er);
        scanf("%s%s",s,ss);
        begin();
        scanf("%s",ss);
        if( m == m_er ) printf("Controller 0\n");
        else
        {
            if( find() )
                printf("Stowaway\n");
            else
                printf("Controller %d\n",cnt);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 1000005;
const int mod = 1000000007;
int inv[maxn];
int k, w;

int pow(int a, int n) {
    int ans = 1;
    for (; n; n >>= 1, a = (LL)a * a % mod)
        if (n & 1) ans = (LL)ans * a % mod;
    return ans;
}

int calc(int k, int w) {
    int ans = LL(pow(k, w + 1) - 1) * inv[k - 1] % mod;
    int per = 1, pinv = 1, tmp = pow(k, w);
    for (int i = 1; i <= k; ++i)
        if (i <= w) {
            tmp = (LL)tmp * inv[k] % mod; per = (LL)per * (k - i + 1) % mod;
            ans = (ans + (LL)per * per % mod * tmp % mod) % mod;
        } else {
            per = (LL)per * (k - i + 1) % mod;
            pinv = (LL)pinv * inv[k - (i - w) + 1] % mod;
            ans = (ans + (LL)per * per % mod * pinv % mod) % mod;
        }
    return ans;
}

int main() {
    int i, ans;
    scanf("%d%d", &k, &w);
    if (k == 1) { puts("1"); return 0; }
    for (i = 2, inv[1] = 1; i <= k; ++i)
        inv[i] = LL(mod / i) * (mod - inv[mod % i]) % mod;
    ans = (calc(k, w) - calc(k, w - 1)) % mod;
    printf("%d\n", (ans + mod) % mod);
    return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define For(i,n) for (long long(i) = 0; (i)<(n); (i)++)
#define For1(i,n) for (long long(i) = 1; (i) <= (n); (i)++)
#define Forlr(i,l,r) for (long long(i) = (l); (i) <= (r); (i)++)
#define Forrl(i,r,l) for (long long(i) = (r); (i) >= (l); (i)--)
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
const ll MOD = 1e9 + 7;
const ll base = 269;
const int oo = 1 << 30;
const int N = 1e5 + 5;
/*
MIKUNO - 15/02/1999
*/
ll n, m, q, k, pos, t, rs, r;
ll P(ll x, ll y) // x^y
{
	ll ret = 1;
	while (y > 0)
	{
		if (y & 1) ret *= x;
		y /= 2;
		x = x * x;
	}
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 	cin >> n >> k;
	ll l = 1, r = P(2,n) - 1, mid;
	while (l <= r)
	{
		mid = (l + r) / 2;
		if (mid == k) {
			cout << n;
			//system("pause");
			return 0;
		}
		if (mid > k) r = mid - 1;
		if (mid < k) l = mid + 1;
		n--;
	}
	//system("pause");
}


/****************### With The name of ALLAH, most Gracious, most Compassionate ###****************/

/**============================================================================**\
|   Author      : Md Jubayer Hossen Jame
|   Study       : CSE, BRUR
|   Today       : Friday, 25 September, 2020
|   Source      : Codeforces Online Judge
|   Problem link: https://codeforces.com/problemset/problem/911/B
|   Algorithm   :
|
    Help        : https://algoshots.herokuapp.com/problems/two-cakes-911B/
\**============================================================================**/

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

#define FI                    freopen("input.txt", "r", stdin)
#define FO                    freopen("output.txt", "w", stdout)
#define FasterIO              ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

typedef long long             ll;
typedef unsigned long long    ull;
typedef unsigned int          ui;

#define mem(x,y)              memset(x,y,sizeof(x));
#define pii                   pair<int,int>
#define mk                    make_pair
#define ff                    first
#define ss                    second
#define pb                    push_back
#define ppb                   pop_back
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define for0(i, n)            for (int i = 0; i < (int)(n); ++i)
#define for1(i, n)            for (int i = 1; i <= (int)(n); ++i)
#define debug(x)              cout << #x << " :: " << x << "\n"
#define endl                  '\n'

const double PI = acos(-1.0);

#define gcd(a,b)              __gcd(a,b)
#define lcm(a,b)              (a*(b/gcd(a,b)))

///Direction Array
// 4 Direction - DOWN, UP, RIGHT, LEFT
int dx4[]= {+1, -1, +0, +0};
int dy4[]= {+0, +0, +1, -1};
#define isValid(a, b, R, C)   (0 <= a && a < R) && (0 <= b && b < C)
int dx8[]= {+0, +0, +1, -1, -1, +1, -1, +1};
int dy8[]= {-1, +1, +0, +0, +1, +1, -1, -1};

///Knight Moves
int dr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int dc[] = {-2, -2, -1, 1, 2, 2, 1, -1};
/**************************************************************************************************/

void test_case()
{
    int n, piece_a, piece_b;
    cin >> n >> piece_a >> piece_b;

    int mini1, mini2, ans = INT_MIN;
    mini1 = mini2 = INT_MAX;
    //10, 3, 100
    for(int plt = 1; plt < n; ++plt)
    {
        //No plate contains pieces of both cakes.
        //mini1 = min( piece_a / plt, piece_b / (n - plt) ); or
        //ans = max( ans, mini1 );
        mini2 = min( piece_b / plt, piece_a / (n - plt) );
        ans = max( ans, mini2 );
    }
    //5, 2, 3 //15, 7, 8
    cout << ans << endl;
}

//★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜★゜・。。・゜゜・。。・゜☆

int main()
{

#ifndef ONLINE_JUDGE
    //FI;
    //FO;
#endif // ONLINE_JUDGE
    FasterIO
    cout.precision(15); cout << fixed;

    int T = 1;
    //cin >> T;
    for(int tc = 1; tc <= T; ++tc)
    {
        //cout << "Case #" << tc << ":" << endl;
        test_case();
    }
    return 0;
}


#include <iostream>

using namespace std;
const int MAX_DIGIT = 10, MAX_LENGTH = 101, MODULO = 1000 * 1000 * 1000 + 7;
int numberOfOccurance[MAX_DIGIT], numberLength;
long long answer[MAX_DIGIT][MAX_LENGTH], chooseMem[MAX_LENGTH][MAX_LENGTH];

int choose (int r, int n) {
	if (r == 0 or r == n) {
		return 1;
	}
	if (r > n or r < 0) {
		return 0;
	}
	if (chooseMem[r][n] != -1) {
		return chooseMem[r][n];
	}
	return chooseMem[r][n] = ((choose(r - 1, n - 1) + choose(r, n - 1)) % MODULO);
}

int main() {
	// INPUT PROCESS
	cin >> numberLength;
	for (int i = 0; i < MAX_DIGIT; ++i) {
		cin >> numberOfOccurance[i];
	}

	// SETTING BASE FORM FOR THE chooseMem
	{
		for (int i = 0; i < MAX_LENGTH; ++i) {
			for (int j = 0; j < MAX_LENGTH; ++j) {
				chooseMem[i][j] = -1;
			}
		}
	}

/*
	answer[i][j] is defined as followed:
		it hold the answer of this problem if we had to create a number from digit i to MAX_DIGIT (like from 4 to 9),
		and alsi it means that the answer number should exactly have j digits, now to calculate such DP we say that,
		let's say we want to calculate the answer for k-th digit, so we say that the answer is equal to sum of all answers
		of answer[k + 1][j - numberOfAppearencesOfKthDigit] * the bionamial choosing of numberOfAppearencesOfKthDigit places
		from all j places for the k-th digit!
*/

	// DP base form
	for (int i = 0; i <= numberLength; ++i) {
		if (i >= numberOfOccurance[MAX_DIGIT - 1]) {
			answer[MAX_DIGIT - 1][i] = 1;
		}
		else {
			answer[MAX_DIGIT - 1][i] = 0;
		}
	}

	// DP Update
	for (int maxNumber = MAX_DIGIT - 2; maxNumber > 0; --maxNumber) {
		for (int length = numberOfOccurance[maxNumber]; length <= numberLength; ++length) {
			for (int maxNumberOccurance = numberOfOccurance[maxNumber]; maxNumberOccurance <= length; ++ maxNumberOccurance) {
				answer[maxNumber][length] += answer[maxNumber + 1][length - maxNumberOccurance] * choose(maxNumberOccurance, length);
				answer[maxNumber][length] %= MODULO;
				//if (answer[maxNumber][length] > 0) cerr << maxNumber << " " << length << " -> " << maxNumberOccurance << " : " << answer[maxNumber][length] << endl;
			}
		}
	}

	// only note that since the number can't start with leading 0 (zeroes), we cannot choose the first place of the j -> j - 1
	for (int length = numberOfOccurance[0]; length <= numberLength; ++length) {
		for (int maxNumberOccurance = numberOfOccurance[0]; maxNumberOccurance <= length; ++ maxNumberOccurance) {
			answer[0][length] += (answer[1][length - maxNumberOccurance] * choose(maxNumberOccurance, length - 1));
			answer[0][length] %= MODULO;
			//if (answer[0][length] > 0) cerr << 0 << " " << length << " -> " << maxNumberOccurance << " : " << answer[0][length] << endl;
		}
	}

	// ans can be any length so we just sum up any lengths that has all digits in them (their "i" in "dp[i][j]" is equal to 0)
	long long ans = 0;
	for (int i = 1; i <= numberLength; ++i) {
		ans += answer[0][i];
		ans %= MODULO;
		//cerr << i << " : " << answer[0][i] << "	";
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	long long a,b,c,d;
	c = 0 ;
	cin>> a ;
	cin>>b ;
	for(d=0 ; d>-10; d++){
		if(a>c){
			c = c + 1 ;
			a = a - c ;
		}
		else{
			cout<<"Vladik" ;
			return 0 ;
		}
		if(b>c)	{
			c = c + 1 ;
			b = b - c ;
		}
		else{
			cout<<"Valera" ;
			return 0 ;
		}
	}
}


#include <cstdio>
#include <cstring>

using namespace std;

const int maxN = 1e5 + 10, mod = 1e9 + 7, maxHav = 13, maxST = (1 << 5) + 1;
//maxHav开始写成了7 注意执行评测前注意数据范围！！！ 检查一下数组空间
int dotN, jumpK, disM, colC;
void add(int &fir, long long sec) {
	fir = (long long) (fir + sec) % mod;
}
struct Matrix{
	int num[210][210], row, col;
	void init(int sze) {
		row = col = sze;
		memset(num, 0, sizeof(num));
		for (int rowI = 0; rowI < row; ++rowI) {
			num[rowI][rowI] = 1;
		}
	}
	void init2(int r, int c) {
		row = r, col = c;
		memset(num, 0, sizeof(num));
	}
	Matrix operator = (const Matrix d) {
		row = d.row;
		col = d.col;
		for (int rowI = 0; rowI < row; ++rowI) {
			for (int colJ = 0; colJ < col; ++colJ) {
				num[rowI][colJ] = d.num[rowI][colJ];
			}
		}
		return (*this);
	}
	Matrix operator * (const Matrix d) const {	//注意，假如在main函数里进行矩阵乘法的话，ret数组的空间算在main函数里，那么就有可能爆main函数的空间
		Matrix ret;
		memset(ret.num, 0, sizeof(ret.num));
		ret.row = row;
		ret.col = d.col;
		for (int rowI = 0; rowI < ret.row; ++rowI) {
			for (int colJ = 0; colJ < ret.col; ++colJ) {
				for (int mid = 0; mid < col; ++mid) {
					add(ret.num[rowI][colJ], 1ll * num[rowI][mid] * d.num[mid][colJ]);
				}
			}
		}
		return ret;
	}
	Matrix power(int up) const {
		Matrix ret, base = (*this);
		ret.init(row);
		while (up) {
			if (up & 1) ret = ret * base;
			base = base * base;
			up >>= 1;
		}
		return ret;
	}
} ans, base, orig;

int pos(int er, int san) {
	return er * colC + san;	//这里应该是er（开始从下标从1开始时），不应该是 er + 1（因为一个在第i行第j列的点，编号应该是(i-1)*col+j而不是i*col+j）纸袋分析法
}
int bitCount(int st) {
	int ret = 0;
	for (int weiI = 0; weiI < 4; ++weiI) {
		if (st & (1 << weiI)) {
			++ret;
		}
	}
	return ret;
}
void init() {
	scanf("%d%d%d", &dotN, &jumpK, &disM);
	colC = 1 << disM;
	ans.init(colC * (jumpK + 1));
	orig.init2(1, colC * (jumpK + 1));
	orig.num[0][0] = 1;	//注意赋初始值！
	base.init2(colC * (jumpK + 1), colC * (jumpK + 1));
	for (int jumpJ = 0; jumpJ <= jumpK; ++jumpJ) {
		for (int stK = 0; stK < (1 << disM); ++stK) {
			if (! (stK & (1 << disM - 1))) {
			//注意运算的优先级！ !和&的优先级一样高，所以要把后面的那串括起来
				add(base.num[pos(jumpJ, stK << 1)][pos(jumpJ, stK)], 1);
				add(base.num[pos(jumpJ, stK << 1 | 1)][pos(jumpJ, stK)], 1);
			} else {
				if (jumpJ >= 1) {
					add(base.num[pos(jumpJ - 1, (stK - (1 << disM - 1)) << 1)][pos(jumpJ, stK)],
						1ll * (1 + bitCount((stK - (1 << disM - 1)) << 1)));
					//注意在这里计算的时候要开 long long!!!
					add(base.num[pos(jumpJ - 1, (stK - (1 << disM - 1)) << 1 | 1)][pos(jumpJ, stK)],
						1ll * (1 + bitCount((stK - (1 << disM - 1)) << 1 | 1)));
				}
			}
		}
	}
}

int main() {
	init();
	int cnt = 0;
	ans = orig * base.power(dotN);
	for (int stK = 0; stK < (1 << disM); ++stK)
		add(cnt, ans.num[0][pos(jumpK, stK)]);
	printf("%d\n", cnt);
	return 0;
}


#include <iostream>

using namespace std;

int r, h;

int main () {

    cin >> r >> h;

    int a = 2 * (h / r);
    h %= r;
    a += 1 + (h * 2 >= r) + (4ll * h * h >= 3ll * r * r);

    cout << a;

    return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int  i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
unsigned long long int n,sum,cnt;
bool used[111111];
main ()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size()-1; i++)
    {
        if(s[i] == '/' && s[i+1] == '/')
        {
            s.erase(i,1);
            i--;
        }
    }
    if(s[s.size()-1] == '/' && s.size() != 1)
    {
        s.erase(s.size()-1,1);
    }
    cout << s;
}


#include <iostream>
using namespace std;
int main()
{
    long long n;
	cin>>n;
    cout<<n/2520<<endl;
    return 0;
}


//TMWCTW...
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int maxn = 4e5 + 20, inf = 1e17, Mod = (1ll << 32);
int n, p, q, ent[maxn], ans;

int choose(int x, int y){
	if(x > y) return 0;
	if(x == y || x == 0)return 1;
	vector <int> tmp;
	for(int i = 0; i < x; i++)tmp.push_back(y - i);
	for(int i = 2; i <= x; i++){
		//cout << x << " : " << y << endl;
		int tmpp = i, tmppp = 0;
		while(tmpp != 1){
			int tmpppp = __gcd(tmpp, tmp[tmppp]);
			tmp[tmppp] /= tmpppp;
			tmpp /= tmpppp;
			tmppp++;
		}
	}
	int res = 1;
	for(int i = 0; i < x; i++){
		res = (res * tmp[i]) % Mod;
	}
	return res;
}

int32_t main(){
    cin >> n >> p >> q;
    p = min(p, n - 1);
    for(int i = 0; i <= p; i++){
    	//cout << i << endl;
		ent[i] = choose(i, n);
	}

	for(int i = 1; i <= q; i++){
		int tmp1 = 0, tmp2 = 1;
		for(int j = 0; j <= p; j++){
			tmp1 = (tmp1 + ent[j] * tmp2) % Mod;
			tmp2 = (tmp2 * i) % Mod;
		}
		ans = (ans ^ (i * tmp1)) % Mod;
	}
    cout << (ans + Mod) % Mod;
}


#include<iostream>
#include<cstdio>
using namespace std;
int pre[8][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};//方向数组
char x;
int a,b,tx,ty,ans=0;
int main(){
    cin>>x>>b;//输入
    a=x-'a'+1;//把字母转成数字
    for(register int i=0;i<8;i++){
        tx=a+pre[i][0];//新的x轴坐标
        ty=b+pre[i][1];//新的y轴坐标
        if(tx<1||tx>8||ty<1||ty>8){//越界
            continue;//执行下一次循环
        }
        ans++;//没有continue，ans+1
    }
    printf("%d",ans);//输出答案
    return 0;//结束
}


#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <bitset>
#include<ctype.h>
#include<stdio.h>
using namespace std;

bool vowel(char c)
{
    if(islower(c))
        c=toupper(c);
    char A[]={'A', 'E', 'I', 'O', 'U', 'Y'};
    for(int i =0;i<6;i++)
        if(c==A[i])
        return 1;
    return 0;
}
int main() {
ios_base::sync_with_stdio(0);
  string s;
  getline(cin,s);
  char c;
  for(int  i=s.length()-1;i>=0;i--)
    if(isalpha(s[i]))
  {
      c=s[i];
      break;
  }
  if(!vowel(c))
    cout<<"NO";
  else
    cout<<"YES";

    return 0;
}


#pragma comment(linker, "/STACK:512000000")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <limits.h>
#include <assert.h>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <stack>
#include <float.h>
#include <time.h>
#include <queue>
#include <deque>

#define PI 3.14159265358979323846
#define ull unsigned long long int
#define ll long long int
#define EPS 1e-9
#define pb push_back
#define EOS(c) (c != EOF && c != '\0' && c != '\n' && c != ' ')
#define oo 1000000005
#define ALL(v) v.begin(), v.end()
#define mp make_pair
#define sqr(a) (a) * (a)

using namespace std;

#define FILES "sort"
//#define OUT "put.txt"

template<class telem>telem MAX(telem a, telem b)
{
    return (a > b) ? a : b;
}

template<class telem>telem MIN(telem a, telem b)
{
    return (a < b) ? a : b;
}

template<class telem>telem GCD(telem a, telem b)
{
    return b ? GCD(b, a % b) : a;
}

template<class telem>telem LCM(telem a, telem b)
{
    return a / GCD(a, b) * b;
}

template<class telem>telem UNSIGNED(telem a)
{
    return (a > 0) ? a : a * (-1);
}

template<class telem>void bez_swop(telem &a, telem &b)
{
    telem c = a;
    a = b;
    b = c;
}

void swop(int &a, int &b)
{
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
}

string n;
int k;

int main()
{

#ifndef ONLINE_JUDGE
#ifdef OUT
    freopen("in"OUT, "r", stdin);
    freopen("out"OUT, "w", stdout);
#endif

#ifdef FILES
    freopen(FILES".in", "r", stdin);
    freopen(FILES".out", "w", stdout);
#endif
#endif

    ios_base::sync_with_stdio(false);
    srand(time(NULL));
    time_t start = clock();

    cin >> n >> k;
    int st = 0;

    while(0==0)
    {
        int mx = -1;
        int pos = 0;

        for(int i = st; i < n.size() && i <= st + k; i++)
        {
            if(n[i] > mx)
            {
                mx = n[i];
                pos = i;
            }
        }

        while(pos > st)
        {
            k--;
            swap(n[pos], n[pos - 1]);
            pos--;
        }

        if(!k)
            break;

        st++;

        if(st == n.size())
            break;
    }

    cout << n;

#ifndef ONLINE_JUDGE
        fprintf(stderr, "\n%0.3lf\n", (clock() - start) * 1.0 / CLOCKS_PER_SEC);
#endif

    return 0;
}


#include<iostream>
#include<map>
#include<string>
#include<string.h>
#include<vector>
#include<stdio.h>
#include <cstdio>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <functional>
#include <time.h>       /* time */
#define LL long long int
#define R(i) freopen(i,"r",stdin)
#define W(i) freopen(i,"w",stdout)
#define R_W R("i.txt"),W("o.txt");
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define r(e) for(int i=0;i<e;i++)
#define oo (LL)numeric_limits<int>::max()
#define readVector(n,in,v) r(n){cin>>in;v.push_back(in);}
#define DFS_WHITE -1
#define DFS_BLACK 1
#define DFS_GRAY 2
#define ii pair< int,int >
#define iii pair< int , ii >
#define vi vector<int>
#define ll long long int
using namespace std;
vector< ii > data;
const ll MOD = (ll)1e9 + 7;
long long int dp[5010][5010];
int main() {
	///R_W;
	int n,a,b,k;
	cin >> n>>a>>b>>k;
	if (a > b){
		a = n - a + 1;
		b = n - b + 1;
	}
	for (int i = 0; i <= n; i++) dp[0][i]=0;
	dp[1][0] = 0;
	for (int i = 1; i <= n; i++){
		int Total = abs(b - i)-1;
		Total += min(min(i - 1, n - i - 1), Total);
		Total = max(Total, 0);
		dp[1][i] = (Total + dp[1][i - 1]) % MOD;
	}
	for (int j = 2; j <= k; j++){
		for (int i = 1; i <= n; i++)
		{
			if (i == b){
				dp[j][i] = dp[j][i - 1];
				continue;
			}
			int l, r;
			if (i < b){
				r = max(min(b - i - 1, i - 1),0);
				l = b - i - 1;
				r = i - r;
				l = i + l;
			}
			else{
				l = max(min(abs(b - i) - 1, n - i - 1),0);
				r = i - b - 1;
				r = i - r;
				l = i + l;
			}
			ll me = (dp[j - 1][i] - dp[j - 1][i - 1] + MOD) % MOD;
			ll all = (dp[j - 1][l] - dp[j - 1][r - 1] + MOD) % MOD;
			ll add = (all - me + MOD) % MOD;
			dp[j][i] = (dp[j][i - 1] % MOD + add% MOD) % MOD;
		}
	}
	cout << (dp[k][a] - dp[k][a - 1] + MOD)%MOD << endl;
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <cstring>
#include  <stdio.h>
#include   <string>
#include    <cmath>
#include	  <map>
#include	  <set>
using namespace std;
typedef __int64 vt;
int va[7] = { -1,0,0,-1,0,0,-1 };
int vb[7] = { 0,-1,0,0,0 ,-1,0 };
int vc[7] = { 0,0,-1,0,-1,0,0 };
int ans1=-1;
int mys(int a,int b,int c)
{
	int aa = a, bb = b, cc = c;
	for (int j = 0; j < 7; j++)
	{
		a = aa, b = bb, c = cc;
		int count = 0;
		for (int i = j; a != -1 && b != -1 && c != -1; i++)
		{
			a += va[i];
			b += vb[i];
			c += vc[i];
			count++;
			if (i == 6)
				i = -1;
		}
		count--;
		ans1 = ans1 < count ? count : ans1;
	}
	return ans1;
}
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int aa, bb, cc;
	aa = a / 3, bb = b / 2, cc = c / 2;
	aa = aa > bb ? bb : aa;
	aa = aa > cc ? cc : aa;
	a -= aa * 3;
	b -= aa * 2;
	c -= aa * 2;
	if (aa > 0)
		mys(a + 3, b + 2, c + 2), aa -= 1;
	else
		mys(a, b, c);
	cout << ans1+aa*7 << endl;
	return 0;
}


#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a); i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl

using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 101;
int cntbad = 0;
int cnt[26];
int arr[mxN];
int val[mxN];
int n;
string s;
vector<int> mins;
int sum = 0;
int main()
{
    //freopen("exercise.in", "r", stdin);
    //freopen("exercise.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>s;
    owo(i, 0, n) {
        arr[i] = s[i]-'a';
        cin>>val[i];
        sum+=val[i];
    }
    owo(i, 0, n/2) {
        if(arr[i]==arr[n-i-1]) {
            cnt[arr[i]]++;
            cntbad++;
        }
    }
    int lose = 0;
    int badnum = -1;
    int over = 0;
    owo(i, 0, n/2) {
        if(arr[i]==arr[n-i-1]) {
            //cout<<arr[i]<<" "<<val[i]<<" "<<val[n-i-1]<<"\n";
            if(2*cnt[arr[i]]>cntbad) {
                badnum = arr[i];
                over = 2*cnt[arr[i]]-cntbad;
            }
            lose+=min(val[i], val[n-i-1]);
        }
    }
    if(badnum==-1) {
        cout<<(sum-lose)<<"\n";
        return 0;
    }
    //cout<<badnum<<" "<<over<<"\n";
    owo(i, 0, n/2) {
        if(arr[i]!=arr[n-i-1]) {
            if(arr[i]!=badnum&&arr[n-i-1]!=badnum){
                mins.senpai(val[i]);
                mins.senpai(val[n-i-1]);
            }
        }else {
            if(arr[i]==badnum)continue;
            mins.senpai(max(val[i], val[n-i-1]));
        }
    }
    sort(mins.begin(), mins.end());
    owo(i, 0, over) {
        lose+=mins[i];
    }
    cout<<(sum-lose)<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int s,v1,t1,v2,t2,a,b;
int main()
{
	scanf("%d%d%d%d%d",&s,&v1,&v2,&t1,&t2);
	a=s*v1+t1*2; b=s*v2+t2*2;
	if(a<b) printf("First");
	if(a==b)printf("Friendship");
	if(a>b)printf("Second");
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<'0');
	do{
		res=(res<<1)+(res<<3)+(c^48);
	}while(c=getchar(),c>='0');
}
const int N=32;
const int M=35;
const int P=(int)1e9+7;
int q;
int dp1[M][2][2][2],dp2[M][2][2][2],X[M],Y[M],K[M];
inline void Add(int &a,int b){
	a=(a+b)%P;
}
int solve(int x,int y,int k){
	if(x<0||y<0)return 0;
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	for(int i=1;i<=N;i++){
		X[i]=(x&1),Y[i]=(y&1),K[i]=(k&1);
		x>>=1,y>>=1,k>>=1;
	}
	reverse(X+1,X+N+1),reverse(Y+1,Y+N+1),reverse(K+1,K+N+1);
	dp1[1][1][1][1]=1;
	for(int i=1;i<N;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				for(int t=0;t<2;t++)
					for(int x=0;x<2;x++)
						for(int y=0;y<2;y++){
							if(!dp1[i][j][k][t])continue;
							int z=x^y;
							if(j&&(x>X[i+1]))continue;
							if(k&&(y>Y[i+1]))continue;
							if(t&&(z>K[i+1]))continue;
							Add(dp1[i+1][j&(x==X[i+1])][k&(y==Y[i+1])][t&(z==K[i+1])],dp1[i][j][k][t]);
							Add(dp2[i+1][j&(x==X[i+1])][k&(y==Y[i+1])][t&(z==K[i+1])],dp2[i][j][k][t]);
							Add(dp2[i+1][j&(x==X[i+1])][k&(y==Y[i+1])][t&(z==K[i+1])],dp1[i][j][k][t]*((ll)z<<(N-1-i))%P);
						}
	int res=0;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int t=0;t<2;t++)
				Add(res,(dp1[N][i][j][t]+dp2[N][i][j][t])%P);
	return res;
}
int main(){
	Rd(q);
	while(q--){
		int x1,y1,x2,y2,k,ans=0;
		Rd(x1),Rd(y1),Rd(x2),Rd(y2),Rd(k);
		x1--,y1--,x2--,y2--,k--;
		ans=(ans+solve(x2,y2,k))%P;
		ans=(ans-solve(x1-1,y2,k)+P)%P;
		ans=(ans-solve(x2,y1-1,k)+P)%P;
		ans=(ans+solve(x1-1,y1-1,k))%P;
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAX 10000000
int a[MAX+10];

int main()
{

    for(int i=1;i*i<=MAX;i++)
    {
        int sq=i*i;
        for(int j=sq;j<=MAX;j+=sq)
        {
            a[j]=sq;
        }
    }

    long long y,n;
    cin>>y>>n;
    long long sum=0;
    for(long long i=0;i<n;i++)
    {
        sum+=(y+i)/a[y+i];

    }
    cout<<sum;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
#include <bitset>
#include <complex>
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int((x).size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = 3e6;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;
//
const int VH = 0;
const int DIAGONAL = 1;
const int KNIGHT = 2;
int dx[8] = {1, -1, 1, -1, 2, -2, -2, 2};
int dy[8] = {2, 2, -2, -2, 1, -1, 1, -1};
int N, X[500], Y[500];

class ShortestPathWeightedGraph {
private:
  int N;
  vector<vector<pair<int,long long> > > adj;
  vector<long long> dist;
public:
  ShortestPathWeightedGraph(int N)
  {
    this->N = N;
    adj.resize(N);
  }
  void add(int u, int v, long long weight)
  {
    adj[u].push_back(make_pair(v, weight));
  }
  int shortest(int from, int to)
  {
    dist.resize(N);
    fill(dist.begin(), dist.end(), -1);
    priority_queue<pair<long long, int> > q;
    q.push(make_pair(0, from));
    dist[from] = 0;
    while (!q.empty())
    {
      int u = q.top().second;
      ll distu = -q.top().first;
      q.pop();
      if (dist[u] < distu) continue;
      for (int i = 0; i < adj[u].size(); i++)
      {
        int v = adj[u][i].first;
        long long weight = adj[u][i].second;
        if (dist[v] == -1 || dist[u] + weight < dist[v])
        {
          dist[v] = dist[u] + weight;
          q.push(make_pair(-dist[v], v));
        }
      }
    }
    return dist[to];
  }
};

int nodenumber(int type, int x, int y)
{
  return 3 * (N * x + y) + type;
}
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> N;
  rep(x,N) rep(y,N)
  {
    int a;
    cin >> a;
    X[a] = x;
    Y[a] = y;
  }
  ShortestPathWeightedGraph graph(3 * N * N);
  int baseweight = 1000;
  rep(x,N) rep(y,N)
  {
    rep(type1,3) rep(type2,3) if (type1 != type2)
    {
      graph.add(nodenumber(type1, x, y), nodenumber(type2, x, y), baseweight + 1);
    }
    // knight
    rep(i,8)
    {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (0 <= xx && xx < N && 0 <= yy && yy < N)
      {
        graph.add(nodenumber(KNIGHT, x, y), nodenumber(KNIGHT, xx, yy), baseweight);
      }
    }
    // vertical & horizontal
    rep(i,N)
    {
      if(x != i) graph.add(nodenumber(VH, x, y), nodenumber(VH, i, y), baseweight);
      if(y != i) graph.add(nodenumber(VH, x, y), nodenumber(VH, x, i), baseweight);
    }
    // diagonal
    rep(i,N)
    {
      for (int dirx = -1; dirx <= 1; dirx += 2)
      {
        for (int diry = -1; diry <= 1; diry += 2)
        {
          int xx = x + i * dirx;
          int yy = y + i * diry;
          if (x == xx && y == yy) continue;
          if (0 <= xx && xx < N && 0 <= yy && yy < N)
          {
            graph.add(nodenumber(DIAGONAL, x, y), nodenumber(DIAGONAL, xx, yy), baseweight);
          }
        }
      }
    }
  }
  vector<ll> best;

  rep(i,3) best.pb(0);
  for (int n = 2; n <= N * N; n++)
  {
    vector<ll> nextbest;
    rep(i,3) nextbest.pb(INF);
    rep(prev,3) rep(cur,3)
    {
      ll shortest_dist = graph.shortest(nodenumber(prev, X[n - 1], Y[n - 1]), nodenumber(cur, X[n], Y[n]));
      nextbest[cur] = min(nextbest[cur], best[prev] + shortest_dist);
    }
    best = nextbest;
  }
  ll mn = INFL;
  rep(i,sz(best)) mn = min(mn, best[i]);
  cout << mn / baseweight << " " << mn % baseweight << endl;
}


#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
using namespace std;
#define int long long
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int ppow(int a,int b,int mod){
    int ans=0;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
void ac(){
    cout<<"YES"<<endl;
}
void wa(){
    cout<<"NO"<<endl;
}
//
const int maxm=105;
int x[maxm],y[maxm];
int ax,ay,bx,by;
int xs,ys,t;
int cnt;
int d(int a,int b,int x,int y){//曼哈顿距离
    return abs(a-x)+abs(b-y);
}
signed main(){
    cin>>x[0]>>y[0]>>ax>>ay>>bx>>by;//注意x[0]和y[0]也是一个点，下面别忘记了
    cin>>xs>>ys>>t;
    while(x[cnt]-xs<t&&y[cnt]-ys<t){
        cnt++;
        x[cnt]=x[cnt-1]*ax+bx;
        y[cnt]=y[cnt-1]*ay+by;
    }
    int ans=0;
    for(int i=0;i<=cnt;i++){//枚举区间起点
        for(int j=i;j<=cnt;j++){//枚举区间终点
            int temp=min(d(xs,ys,x[i],y[i]),d(xs,ys,x[j],y[j]));
            temp+=d(x[i],y[i],x[j],y[j]);
            if(temp<=t){
                ans=max(ans,j-i+1);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#define bug(x) cout<<#x<<" is "<<x<<endl;
#define IO std::ios::sync_with_stdio(0);
#include <bits/stdc++.h>
#define iter ::iterator
using namespace  std;
typedef long long ll;
typedef pair<ll,ll>P;
typedef pair<P,P>P1;
#define mk make_pair
#define pb push_back
#define se second
#define fi first
#define rs o<<1|1
#define ls o<<1
const int N=4e5+5;
ll mod=1e9+7;
ll x,y;
ll d[2][N];
int main(){
	IO;
	cin>>x>>y;
	if(x>y)swap(x,y);
	int cur=0,res=0;
	d[0][0]=1;
	d[1][0]=1;
	for(int i=1;i+res<=x+y;i++){
		res+=i;
		cur=!cur;
		for(int j=1;j<i;j++){
			d[cur][j]=d[!cur][j];
		}
		for(int j=i;j<=res;j++){
			d[cur][j]=(d[!cur][j]+d[!cur][j-i])%mod;
		}
		if(i==x){
			for(i++;i+res<=x+y;i++){
				res+=i;
			}
		}
	}
	ll ans=0;
	for(int i=max(0ll,res-y);i<=x;i++){
		ans=(ans+d[cur][i])%mod;
	}
	cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    int k;
    cin>>n>>k;
    int a[10];
    int i=0,c=0;
    long long m=n;
    if(m==0)
        cout<<0;
    else
    {

        while(n)
        {
            a[i]=n%10;
            n=n/10;
            i++;
            c++;

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

        else
        {
            cout<<c-1;

        }
    }

    return 0;
}


#include <iostream>
#include <stdio.h>
#include<cmath>
using namespace std;
long long g1,g2,g3;
int main(){
    //freopen("in.txt","r",stdin);
    int k,f1,f2,f3,n,f4,t1,t2,t3,t4,r,c;
    cin >> g1 >> g2;
    if(g2>g1){
    cout << g1 <<endl;
    return 0;
    }
    g1-=g2;
    g3=ceil((-1+sqrtl(g1*8+1))/2);
    cout << g3+g2 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int n,a,b,c;
int main()
{
string s="Danil";string s1="Olya"; string s2="Slava", s3="Ann", s4="Nikita";
string st;
cin>>st;
st="gggggggg"+st+"gggggggggggg";
int cnt=0;
for(int i=0;i<st.size()-4;i++)
{
    if(st.substr(i,5)==s)
        cnt++;
    if(st.substr(i,5)==s2)
        cnt++;
}
for(int i=0;i<st.size()-2;i++)
    if(st.substr(i,3)==s3)
    cnt++;
for(int i=0;i<st.size()-3;i++)
    if(st.substr(i,4)==s1)
    cnt++;
for(int i=0;i<st.size()-5;i++)
    if(st.substr(i,6)==s4)
    cnt++;
if(cnt==1)
    cout<<"YES";
else
    cout<<"NO";
}


#include <algorithm>
#include <bitset>
#include <deque>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define clr( a , v ) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define sz size()
#define FORN( i , s , n ) for( int i = s ; i < (int)(n) ; i++ )
#define FOR( i , n ) FORN( i , 0 , n )
#define FORIT(i,x) for( typeof x.begin() i = x.begin() ; i != x.end() ; i++ )
#define trace(x)    cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define read ios::sync_with_stdio(false)

using namespace std;

typedef long long int64;
typedef vector <int> vi;
typedef pair <int64,int64> ii;
typedef vector <string> vs;
typedef vector <ii> vii;

int main(){
    set <ii> S;
    int64 n, a, ans = 0, b = 0;
    cin >> n;
    for( int64 k = 1 ; k < n ; k++ ){
        a = sqrt( 1.0*( n*n - k*k ) );
        if( a > k ) ans++;
        if( a == k ) b = 1;
    }
    if( n == 0 ) cout << "1" << endl;
    else cout << ans * 8 + 4 * ( b + 1 ) << endl;
    return 0;
}


#include<iostream>
#include<iterator>
#include<algorithm>
#include<math.h>
#include<vector>
#include<stack>
#include<string.h>
#include<map>
#include<bitset>
#include<set>
#include<deque>
#include<queue>
#include<list>
#define ln 100005
#define pi acos(-1.0)
#define pb push_back
#define mp nake_pair
using namespace std;
int main()
{
    long long int number;
    cin>>number;
    long long int N=ln;
    long long int arr[ln];
    arr[0]=0;
    for(long long int i=1;i<N;i++){
        arr[i]=arr[i-1]+(i);
    }
    long long int flag=0,akash=1;
    while(akash<N){

        if(binary_search(arr+1,arr+N,number-arr[akash])){
            cout<<"YES\n";
            flag=1;
            break;
        }
        akash++;
    }
    if(flag==0){
        cout<<"NO\n";
    }
    return 0;
}


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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

const int N = 2e6;
int sv[N+1], mu[N+1];
int pw[N+1];
vi dv[N+1];

int expo(int n, int p, int mod = inf) {
    int ans = 1;
    while (p) {
        if (p & 1) {
            ans = (ans * 1LL * n) % mod;
        }
        n = (n * 1LL * n) % mod;
        p >>= 1;
    }
    return ans;
}
void ok(int &x) {
	if (x >= inf) x -= inf;
	if (x < 0) x += inf;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	FOR (i, 1, N) sv[i] = i;
	FOR (i, 2, 2000) if (sv[i] == i) for (int j = i * i; j <= N; j += i) sv[j] = i;

	mu[1] = 1;
	FOR (i, 2, N) {
		int x = sv[i];
		int g = (i / x) % x != 0;
		mu[i] = mu[i / x] * -g;
	}

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

	FOR (i, 1, N) {
		if (sv[i] == i) {
			pw[i] = expo(i, n);
		} else {
			pw[i] = (pw[sv[i]] * 1LL * pw[i/sv[i]]) % inf;
		}
	}

	FOR (i, 1, N) if (mu[i]) {
		for (int j = i; j <= N; j += i) dv[j].push_back(i);
	}

	int ans = 0, cur = 1;
	FOR (i, 2, k) {
		for (int x : dv[i]) {
			ok(cur -= pw[(i-1)/x]*mu[x]);
			ok(cur += pw[i/x]*mu[x]);
		}
		ok(ans += (cur^i));
	}
	cout << ans << "\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
main(){
    long long n,k;
    cin>>n>>k;
    long long a[n];
    long long vt=0,vt2=0;
    for(long long i=1; i<=n; i++){
        cin>>a[i];
    }
    for(long long i=1; i<=n; i++){
        if(a[i] > k){ vt=i; break;}
    }
    for(long long i=n; i>=1; i--){
        if(a[i] > k){ vt2=i; break;}
    }
    if(vt==vt2 && vt==0) cout<<n;
    else cout<<n - (vt2 - vt + 1);
}


#include<bits/stdc++.h>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll Fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}
ll upd(ll x,ll v){x=x+v>=mod?x+v-mod:x+v;return x;}

int main()
{
	int l,r,a;
	cin>>l>>r>>a;
	int ans=a;
	if(l>r)
	ans-=l-r;
	else
	ans-=r-l;
	if(ans>=0)
	{
		cout<<max(l,r)*2+ans/2*2<<endl;
	}
	else
	{
		cout<<(min(l,r)+a)*2<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int int64_t
const int MAX = 7e5+1;
const int MOD = 1e6+3;

int fac[MAX], infac[MAX];

int Pow(int x, int y) {
	int curr = 1;
	while(y > 0) {
		if(y % 2 != 0) curr = (curr*x) % MOD;
		x = (x*x) % MOD;
		y /= 2;
	}

	return curr;
}

void precompute(int s) {
	fac[0] = 1;
	for(int i = 1; i <= s; i++) fac[i] = (fac[i-1]*i) % MOD;
	infac[s] = Pow(fac[s], MOD-2);
	for(int i = s-1; i >= 0; i--) infac[i] = ((i+1)*infac[i+1]) % MOD;
}

int bi(int n, int r) {
	return ((fac[n]*infac[r]) % MOD * infac[n-r]) % MOD;
}

signed main() {
	int n, c, total = 0;
	cin >> n >> c;
	precompute(n+c-1);
	for(int i = 1; i <= n; i++) total = (total+bi(i+c-1, i)) % MOD;
	cout << total;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979

typedef long long Int;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int INF = 1000000000;
const int MAX = 500007;
const int MAX2 = 207;
const int BASE = 1000000000;
const int CNT = 500;
const int MOD = 1000000007;

double dp[MAX][107];

int p[MAX];

int main()
{
    //freopen("in.txt", "r", stdin);

	int n = 1;
	p[0] = -1;

	FOR(i,0,107)
	{
		dp[0][i] = 1;
	}

	int q;
	cin >> q;
	FOR(qq,0,q)
	{
		int t;
		scanf("%d" , &t);
		if (t == 1)
		{
			int par;
			scanf("%d" , &par);
			--par;
			int v = n;
			p[v] = par;
			++ n;
			FOR(j,0,107)
			{
				dp[v][j] = 1;
			}
			double prevV = dp[par][0];
			dp[par][0] *= 0.5;
			int j = 1;
			while (p[par] != -1 && j <= 102)
			{
				int pp = p[par];
				double pV = dp[pp][j];
				dp[pp][j] /= (0.5 + 0.5 * prevV);

				prevV = pV;
				dp[pp][j] *= (0.5 + 0.5 * dp[par][j - 1]);
				par = pp;
				++j;
			}

		}
		else
		{
			int v;
			scanf("%d" , &v);
			--v;
			double res = 0;

			FOR(i,1,100)
			{
				res += (dp[v][i] - dp[v][i - 1]) * i;
			}
			printf("%.10f\n" , res);
		}
	}

    return 0;
}


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

string s1,s2;
int k = 0;

int main() {
  cin >> s1;
  int c = s1.size();
  int g = 0, b = 0;
  for(int i; i < c-1; i++){
     if (s1[i] != s1[i+1]) b = 1;
  }
    if (b==1){
    if (c%2 != 0){
      g = 1;
      for(int i = 0; i < c; i++){
        if (i != (c/2)){

          s2 += s1[i];
        }
      }
    }
    else s2 = s1;
    c = s2.size();
    for(int i = 0; i < c; i++){
        if (s2[i] != s2[c-i-1]){
          k = 1;
        }
    }
    if(k==0) k = c - 1 + g;
    else k = c + g;
    cout << k << endl;
    }
  else cout << b << endl;
  return 0;
}


#include <bits/stdc++.h>
#ifdef _MSC_VER
#define __builtin_popcount (int)__popcnt
#define __builtin_popcountll (int)__popcnt64
#define __builtin_clz (int)__lzcnt
#define $ system("pause")
#define gp_hash_table unordered_map
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define $
//#define USACO
//#define IOI_style
#endif

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef complex<double> point;

#define MOD 12345
#define MAXN 123
#define LG 20
#define inf int(1e9 + 100)

#define rep(i, j, k) for (int i = j; i < k; i++)
#define for_all(x) x.begin(), x.end()
#define lid id << 1
#define rid id << 1 | 1
#define lch l, mid, lid
#define rch mid, r, rid
#define pb push_back
#define X first
#define Y second
#define re real()
#define im imag()

template <typename S, typename T>
inline ostream &operator<<(ostream &out, const pair<S, T> &p)
{
	return out << "( " << p.X << " , " << p.Y << " )";
}
template <typename S>
inline ostream &operator<<(ostream &out, const vector<S> &p)
{
	for (auto &e : p) out << e; return out;
}
template <typename T, typename S>
inline T smin(T &a, const S &b) { return a > b ? a = b : a; }
template <typename T, typename S>
inline T smax(T &a, const S &b) { return a < b ? a = b : a; }
inline double dot(const point l, const point r) { return l.re * r.re + l.im * r.im; }
inline double cross(const point l, const point r) { return l.re * r.im - l.im * r.re; }
ll po(ll v, ll u) { return u ? (po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD) : 1; }
template<class T> inline void add(T &l, const T &r) { l = (l + r) % MOD; }
ll gcd(ll v, ll u) { return u ? gcd(u, v % u) : v; }

ll n;
int c;
vector<int> vec, o[30];

struct Mat {
	int n, m;
	ll arr[MAXN][MAXN];
	Mat(int n, int m, int z = 0) : n(n), m(m) {
		memset(arr, 0, sizeof(arr));
		rep(i, 0, min(n, m))
			arr[i][i] = z;
	}
};

inline ostream &operator<<(ostream &out, Mat &p)
{
	rep(i, 0, p.n) {
		rep(j, 0, p.m)
			cout << p.arr[i][j] << ' ';
		cout << endl;
	}
	return out;
}

inline Mat operator*(Mat l, Mat r) {
	Mat res(l.n, r.m);
	rep(i, 0, res.n) rep(j, 0, res.m) rep(k, 0, l.m)
		res.arr[i][j] += l.arr[i][k] * r.arr[k][j];
	rep(i, 0, res.n) rep(j, 0, res.m) res.arr[i][j] %= MOD;
	return res;
}

Mat operator^ (const Mat & v, ll u)
{
	Mat res(v.n, v.m, 1);
	for (int i = 62; ~i; i--) {
		res = res * res;
		if (u & (1ll << i)) res = res * v;
	}
	return res;
}

vector<int> state, f[MAXN];
map<vector<int>, int> rf;
int NOW, sz[MAXN];
void build(int g = 0) {
	if (g == c) {
		f[NOW] = state;
		rf[state] = NOW++;
		return;
	}
	rep(i, 0, sz[vec[g]]) {
		state[g] = i;
		build(g + 1);
	}
	return;
}

#ifndef IOI_style
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef USACO
	freopen("gathering.in", "r", stdin);
	freopen("gathering.out", "w", stdout);
#endif
	cin >> n >> c;
	rep(i, 0, c) {
		char v; int m;
		cin >> v >> m;
		v -= 'A';
		vec.pb(v);
		o[v].pb(m);
	}
	sort(for_all(vec));
	vec.resize(unique(for_all(vec)) - vec.begin());
	for (auto e : vec) {
		sort(for_all(o[e]));
		o[e].resize(unique(for_all(o[e])) - o[e].begin());
		sz[e] = 1;
		for (auto z : o[e]) sz[e] *= z;
	}
	state.resize(vec.size());
	c = vec.size(); build();
	Mat M(NOW, NOW);
	rep(i, 0, NOW) {
		auto v = f[i];
		rep(j, 0, c) {
			v[j] = (v[j] + 1) % sz[vec[j]];
			M.arr[rf[v]][i]++;
			v[j] = (v[j] - 1 + sz[vec[j]]) % sz[vec[j]];
		}
	}
	M = M ^ n;
	ll answer = 0;
	rep(i, 0, NOW) {
		auto v = f[i];
		bool bad = false;
		rep(j, 0, c) {
			bool flag = false;
			for (auto z : o[vec[j]])
				if (v[j] % z == 0) flag = true;
			if (!flag) bad = true;
		}
		if (bad) continue;
		add(answer, M.arr[i][0]);
	}
	cout << answer << endl;
	$;
	return 0;
}
#endif


/*
  - Author : Ahmed Araby
  - submitted by an Alien so it's not and ordinary code,
    don't till any one.
*/
#include <bits/stdc++.h>
/*#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <math.h>*/
#define ll long long
#define pi pair<int , int>
#define pl pair<long long , long long>
using namespace std;

void run()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll mem[50][50][50];
ll solve(int l , int r , int h) // we use the third dimension h to detect the case of restriction of none
{
    if(l>r || l==r)
        return 1;
    ll &ret=mem[l][r][h];
    if(ret!=-1)
        return ret;
    ret=0;
    for(int i=l; i<=r; i++)
    {
        ll tmp=0;
        if(i-l>=h-1 || r-i>=h-1)
        {
            ll r1 , r2 , r3 , r4;
            if(i-l>=h-1)
                r1=solve(l , i-1 , max(h-1 , 0) );
            else
                r1=solve(l , i-1 , 0);
            if(r-i>=h-1)
                r2=solve(i+1 , r , max(h-1 , 0) );
            else
                r2=solve(i+1 , r , 0);
            tmp=r1*r2;
            //cout<<"out"<<" "<<tmp<< endl;
            if(i-l>=h-1 && r-i>=h-1)
            {
                // here we calculates the possible trees that some part of it have no restriction
                r3=solve(l , i-1 , 0); // no res
                r3-=r1; // remove duplication
                r4=solve(i+1 , r , 0);
                r4-=r2; // remove duplication
                // missed calculation
                tmp+=r3*r2;
                tmp+=r4*r1;
                //cout<<endl<<"IN"<<" "<<tmp<< endl;
            }
        }
        ret+=tmp;
    }
    return ret;
}
int main()
{
	run();
	//freopen("input.txt" ,"r" , stdin);
	//freopen("output.txt" , "w", stdout);
	int n , h;
	cin>>n>>h;
	for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
        mem[i][j][k]=-1;
	cout<<solve(1 , n , h)<< endl;
	return 0;
}


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

int main(){
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

	LL a,b,c;
	cin >> a >> b >> c;

	if(!c){

		if(a == b) cout<< "YES\n";
		else cout << "NO\n";
		return 0;
	}
	if(a > 0 && c > 0 && b <= 0){
		cout << "NO\n";
		return 0;
	}
	if(c < 0 && b > a){
		cout << "NO\n";
		return 0;
	}
	if(c > 0 && b < a){
		cout << "NO\n";
		return 0;
	}

	if( (b - a) % c)
		cout << "NO\n";

	else{

		if( ((b - a)/c) +1 > 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}

    return 0;
}


//  ||  || |____|  //
//  ||  ||   ||   //
//  \\__//   ||  //
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define mp make_pair
#define F first
#define S second
#define vll vector <ll>
#define mll map <ll,ll>
#define pb push_back
#define pf push_front
#define ub upper_bound
#define lb lower_bound
#define popf pop_front
#define popb pop_back
#define M 1000000007
#define M1 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>(t);while(t--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define f(a, b) for (ll i = a; i < b; i++)
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))

using namespace std;
void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/***********************************************************************************************************/

int main()
{
    start();
    string s; cin>>s;
    ll c=0,ans=0;
    f(0,s.length())
    {
        if(s[i]==s[i+1])
        {
            c++;
            if(c==5)
            {
                ans++;
                c=0;
            }
        }
        else
        {
            c=0;
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


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

int a[55];//jdshfsdssf

int main()//jdsyggdsftsf
{
	ios::sync_with_stdio(0);//dwfeffgsdgdgedhshjhhsddgyegfgfg
	int n,m,i=1;//rutututututut
	cin>>n>>m;
	while(m>=i){
		m-=i;//jddsshshs
		i++;//ajsjdsjdsefggfyrgfygryuruwolpswoksij
		if(i>n) i=1;
	}
	cout<<m;//kxjisdhsdh
	return 0;
}
//2333333333333333333333333333333333333333333333333


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

    int t,i,m,n;

    //for (cin >> t; t--;)
    // {
    cin >> m >> n;
   if (n==0)
   {
     cout << 1 << endl;
   }
           else if ((m-n)>n)
                {
                    cout << n << endl;
                }
            else
                {
                    cout << m-n << endl;
                }

    // }

    return 0;
}


#define fr(i, a, x) for(int(i) = a; i <= x; ++i)
#define rfr(i, a, x) for(int(i) = a; i >= x; --i)
#define all(a) a.begin(), a.end()
#define Min(a, b) (a < b) ? a : b
#define Max(a, b) (a > b) ? a : b
#define pb push_back
//#define MY_DEBUG 1

#include <cstdio>
#include <string>
#include <map>
#include <ctime>
#include <stack>
#include <deque>
#include <cstdlib>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

#ifdef MY_DEBUG
#include <fstream>
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
#endif

const double pi = acos(-1.0);
const double eps = 1e-9;
const int inf = 1e9;
const long long linf = 1e18;
const int prost = 51;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<string> s(m), p;
	set<string> h;
	for(int i = 0; i < m; ++i)
		cin >> s[i];
	for(int i = 0; i < m; ++i)
		for(int j = 0; j < s[i].length(); ++j)
			h.insert(s[i].substr(0, j + 1));
	for(set<string>::iterator i = h.begin(); i != h.end(); ++i)
		p.push_back(* i);
	int t = p.size();
	vector< vector<int> > per(t, vector<int>(4, -1));
	vector< vector<int> > dl(t, vector<int>(4, 0));
	char help[] = {'C', 'T', 'G', 'A'};
	for(int i = 0; i < t; ++i)
		for(int k = 0; k < 4; ++k)
		{
			string st = p[i];
			st += help[k];
			//if (h.find(st) != h.end())
			{
				bool tr = true;
				for(int u = 0; u < st.length() && tr; ++u)
					for(int j = 0; j < t && tr; ++j)
						if (st.substr(u, st.length() - u) == p[j])
						{
							per[i][k] = j;
							tr = false;
						}
				if (per[i][k] != -1)
				{
					string f = p[ per[i][k] ] ;
					int len, sl = f.length(), mx = 0;
					for(int j = 0; j < m; ++j)
					{
						len = s[j].length();
						if (sl - len >= 0 && f.substr(sl - len, len) == s[j] && len > mx)
							mx = len;
					}
					dl[i][k] = mx;
				}
			}
		}
	vector< vector< vector<int> > > dp(n + 1);
	for(int i = 0; i < n + 1; ++i)
	{
		dp[i].resize(i + 1);
		for(int j = 0; j < i + 1; ++j)
			dp[i][j].resize(t);
	}
	for(int i = 0; i < t; ++i)
	{
		if (p[i].length() == 1)
		{
			bool fi = false;
			for(int j = 0; j < m; ++j)
				if (s[j] == p[i])
					fi = true;
			if (fi)
				dp[1][1][i] = 1;
			else
				dp[1][0][i] = 1;
		}
	}
	long long mod = 1000000009, ans = 0;
	for(int i = 1; i < n; ++i)
		for(int j = max(i - 11, 0); j <= i; ++j)
			for(int k = 0; k < t; ++k)
				for(int u = 0; u < 4; ++u)
					if (per[k][u] != -1 && dp[i][j][k] > 0)
					{
						if (dl[k][u] + j > i)
						{
							dp[i + 1][i + 1][ per[k][u] ] += dp[i][j][k];
							dp[i + 1][i + 1][ per[k][u] ] %= mod;
						}
						else
						{
							dp[i + 1][j][ per[k][u] ] += dp[i][j][k];
							dp[i + 1][j][ per[k][u] ] %= mod;
						}
					}
	for(int i = 0; i < t; ++i)
	{
		ans += dp[n][n][i];
		ans %= mod;
	}
	cout << ans << '\n';
}


#include <iostream>
using namespace std;

int main()
{
	int tux; cin >> tux;
	int foo = 0, bar = 0, baz = 0, quz = 1;
	for (int i = 0; i < tux; ++i)
	{
		int pur; cin >> pur;
		foo += pur;
		bar += 1;
		if (foo * quz >= bar * baz)
		{
			baz = foo;
			quz = bar;
		}
	}
	cout << double(baz) / double(quz);
	return 0;
}


#include <iostream>
using namespace std;
int n,k,i,j,sum,one,two;
int main(){
	       cin>>n>>k;
	       int a[n+1];
	       for(i=1;i<=n;i++){
	       	cin>>a[i];
		   }
		   for(i=1;i<=k;i++){
		   	one=0; two=0;
		   	for(j=i;j<=n;j=j+k){
		   		if(a[j]==1) one++; else two++;
			   }
			   sum=sum+min(one,two);
		   }
		   cout<<sum;
}


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

int main()
{
  string s;
  cin>>s;
  if(s.length()<=2)
  {
      cout<<"YES"<<endl;
      return 0;
  }

  int i;
  for(i=2;i<s.length();i++)
      if((s[i]-'A') != ((s[i-2]-'A') + (s[i-1]-'A'))%26)
            break;
  if(i==s.length())
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;

  return 0;

}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define Mod 998244353
using namespace std;
long long fpow(long long a,long long b)
{
    long long ans=1,t=a;
    while(b)
    {
        if(b&1)ans=ans*t%Mod;
        t=t*t%Mod;
        b>>=1;
    }
    return ans;
}
long long inv(long long a)
{
    return fpow(a,Mod-2);
}
void add(int& a,int b)
{
    a+=b;
    if(a>=Mod)a-=Mod;
}
int dp[4010][4010][2];
int fac[5010];
int main(){
    int n,k,l;
    scanf("%d %d %d",&n,&k,&l);
    dp[0][0][0]=1;
    for(int i=0;i<=n*2;i++)
        for(int j=0;j<=i;j++)
            for(int o=0;o<=1;o++)
            {
                add(dp[i+1][j+1][o],dp[i][j][o]);
                if(o==0&&j>=k)add(dp[i+1][j][1],dp[i][j][o]);
                if(j)add(dp[i+1][j-1][o],(long long)dp[i][j][o]*j%Mod);
            }
    fac[0]=1;
    for(int i=1;i<=n*2+1;i++)
        fac[i]=(long long)fac[i-1]*i%Mod;
    printf("%lld\n",(long long)dp[n*2+1][0][1]*fpow(2,n)%Mod*fac[n]%Mod*inv(fac[n*2+1])%Mod*l%Mod);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int i, j, state, arr[105][105];

    state = 0;

    for(i = 1; i <= 3; i++)
        for(j = 1; j <= 3; j++)
            cin >> arr[i][j];

    for(i = 1; i <= 3; i++){
        for(j = 1; j <= 3; j++){
            state = (1 + arr[i][j] + arr[i - 1][j] + arr[i + 1][j] + arr[i][j - 1] + arr[i][j + 1]) % 2;
            if(state) cout << "1";
            else cout << "0";
        }

        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<ld,ld>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define INF ((~0) ^ (1 << 31))
#define INFL ((~0) ^ ((ll)1 << 63))
#define FOR(i,j,k) for(int i = j; i < k; i++)
#define REP(i,j,k) for(int i = j; i >= k; i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
//srand (time(NULL));

using namespace std;

setmax(1e3+10);
setmod(1e9+7);

ll fact[maxn], rfact[maxn],n,m,k;

ll po(ll a, ll b)
{
    if(!b) return 1;
    ll t = po(a,b/2);
    t = (t*t) % MOD;
    if(b & 1) t = (t*a)%MOD;
    return t;
}

ll cmb(ll a, ll b)
{
    if(b > a) return 0;
    ll t = fact[a] * rfact[b];
    t %= MOD;
    t = (t*rfact[a-b]) % MOD;
    return t;
}

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

    fact[0] = 1;
    FOR(i,1,maxn) fact[i] = (fact[i-1]*i) %MOD;
    FOR(i,0,maxn) rfact[i] = po(fact[i],MOD-2);
    cin >> n >> m >> k;
    cout << (cmb(n-1,2*k) * cmb(m-1,2*k)) % MOD;
}


#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
#define M 1000000007
#define N 55

ll chu(ll a,ll b){
	ll res=1,p=M-2;
	while(p){
		if(p&1){res=res*b%M;}b=b*b%M;p>>=1;
	}return a*res%M;
}

int n,x,y,i,j,k,ac,wa,n0,n1,sb[666],nn;
ll res,jb;

struct Mat
{
    ll mat[55][55]={0};
    void print(){int i,j;for(i=0;i<=n;i++){for(j=0;j<=n;j++){printf("%lld ",mat[i][j]);}puts("");}puts("");}
    //void print(){int i,j;for(i=0;i<=n;i++){for(j=0;j<=n;j++){printf("%lld ",mat[i][j]*chu(1,jb)%M);}puts("");}puts("");}
}a,ans;

Mat operator*(Mat A,Mat B){
    Mat temp;
    for(int i = 0 ; i <= n ; i++)
    {
        for(int j = 0 ; j <= n ;j++)
        {
            //temp.mat[i][j]=0;
            for(int k = 0 ;k <= n ;k++)
            {
                temp.mat[i][j] = (temp.mat[i][j]+A.mat[i][k]*B.mat[k][j])%M;
            }
        }
    }
    return temp;
}

Mat operator^(Mat A, int k){
    Mat base;
    for(int i=0;i<=n;i++) base.mat[i][i]=1;

    while(k)
    {
        if(k & 1) base = base * A;
        A = A * A;
        k = k >> 1;
    }
    return base;
}

int main(){
	scanf("%d%d",&n,&k);
	jb=chu(1,n*(n-1)/2);
	for(i=1;i<=n;i++){
		scanf("%d",&sb[i]);
		if(sb[i]){n1++;}
		else{n0++;}
	}
	for(i=1;i<=n0;i++){
		if(sb[i]){wa++;}
		else{ac++;}
	}
	for(i=n0+1;i<=n;i++){
		if(sb[i]){ac++;}
		else{wa++;}
	}
	ac/=2;wa/=2;n/=2;

	ans.mat[0][wa]=1;
	a.mat[0][1]=n0*n1*jb%M;
	a.mat[0][0]=(1-a.mat[0][1]+M)%M;

	for(i=1;i<=n-1;i++){
		nn++;n0=max(0,n0-1);n1=max(0,n1-1);
		a.mat[i][i-1]=nn*nn*jb%M;
		a.mat[i][i+1]=n0*n1*jb%M;
		a.mat[i][i]=(1-a.mat[i][i+1]-a.mat[i][i-1]+M+M)%M;
	}
	nn++;n0=max(0,n0-1);n1=max(0,n1-1);
	a.mat[n][n-1]=nn*nn*jb%M;
	a.mat[n][n]=(1-a.mat[n][n-1]+M)%M;
	//a.print();
	a=a^k;
	//a.print();
	ans=ans*a;
	//ans.print();
	printf("%lld",ans.mat[0][0]);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ll2 pair<ll, ll>
#define ll3 pair<ll, ll2>
#define mp make_pair
#define pb push_back
#define space << " " <<
#define print_iterable_range(x, lwr, upr) cout << #x << ": "; for(ll i=lwr; i<upr; i++){cout << x[i] << " ";} cout << endl;
#define debug_var(var) cout << #var << ": " << (var) << endl;
#define debug_vec(x) cout << #x << ": "; for(auto i : x) cout << i << " "; cout << endl;
#define fori(i, a, b) for(ll i=a; i<b; i++)
#define print_vec(x, a, b) fori(i, a, b) cout << x[i] << " "; cout << endl;
#define ford(i, a, b) for(ll i=a; i>=b; i--)
#define all(vec) vec.begin(), vec.end()

const double PI = 3.1415926535897;

ostream& operator << (ostream& oout, ll2 p){
	oout << "(" << p.first << ", " << p.second << ")";
	return oout;
}

istream& operator >> (istream& iin, ll2 &p){
	iin >> p.first;
	iin >> p.second;
	return iin;
}
template <typename T>
istream& operator >> (istream & iin, vector<T> &a){
	for(T &i : a){
		cin >> i;
	}
	return iin;
}

template <typename T>
ostream& operator << (ostream & oout, vector<T> &a){
	for(T &i : a){
		cout << i << " ";
	}
	return oout;
}

template <typename T>
T min(vector<T> a){
	ll ans = a[0];
	for(auto i : a){
		ans = min(ans, i);

	}
	return ans;
}

template <typename T>
T max(vector<T> a){
	ll ans = a[0];
	for(auto i : a){
		ans = max(ans, i);

	}
	return ans;
}

template <typename T>
bool operator == (pair<T, T> a, pair<T, T> b){
	return a.first == b.first and a.second == b.second;
}

const ll MOD = 1000000007;

//template<class T>
inline ll add_mod(ll a, ll b, const ll mod = MOD){
//    if(a<0) a += mod;
//    if(b<0) b += mod;
	return ((a>=0 ? a : a+mod)%mod + (b>=0 ? b : b+mod)%mod)%mod;
}

inline ll sub_mod(ll a, ll b, const ll mod = MOD){
	ll result = ((a>=0 ? : a+mod)%mod - (b>=0 ? b : b+mod)%mod);
	return (result >= 0 ? result : result + mod)%mod;
}

inline ll mult_mod(ll a, ll b, const ll mod = MOD){
	return ((a>=0? a : a+mod)%mod * (b>=0 ? b : b+mod)%mod)%mod;
}

ll fast_expo(ll x, ll y, const ll mod = MOD){
	ll ans = 1;
	while(y > 0){
		if(y%2 == 1)    ans = mult_mod(x, ans, mod);
		x = mult_mod(x, x, mod);
		y /= 2;
	}
	return ans;
}

inline ll div_mod(ll a, ll b, const ll mod = MOD){
	return mult_mod(a, fast_expo(b, mod - 2, mod), mod);
}

ll ncr(ll n, ll r){
	if(n == 0)
	return 1;
	// cout << n space r << endl;
	if(r == 0 or r == n){
		return 1;
	}
	else return ncr(n-1, r) + ncr(n-1, r - 1);
}

void solve(){

	string orig, rec;
	cin >> orig >> rec;
	cout.precision(10);
	ll dest = 0;
	ll unrec = 0;
	ll curr = 0;

	for(auto & i : orig){
		dest = dest + (i == '+' ? 1 : -1);
	}

	for(auto & i : rec){
		if(i == '+'){
			curr ++;
		}
		else if(i == '-'){
			curr--;
		}
		else unrec ++;
	}

	if(unrec < abs(dest - curr)){
		cout << (long double)0 << endl;
		return ;
	}

	ll left = abs(curr - dest);

	if((unrec - left) % 2 != 0){
		cout << (long double)0;
		return;
	}

	// debug_var(dest)
	// debug_var(curr)

	ll num_1 = (unrec - left)/2 + (dest >= curr ? left : 0);

	// debug_var(num_1)
	// debug_var(unrec)

	// cout << "raju\n";

	// debug_var(ncr(2,1))

	long double p = ((long double)(ncr(unrec, num_1)))/((long double)(pow(2LL, unrec)));
	cout << p;

	return;
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);cout.tie(0);
	ll num_test_cases = 1;
	// cin >> num_test_cases;
	while(num_test_cases--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int
#define ull unsigned ll
#define mkp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define lb lower_bound
#define ub upper_bound
#define in insert
#define sz size()
#define mem(a,x) memset(a,x,sizeof(a))
#define mt empty()
#define py puts("YES")
#define pn puts("NO")
#define png puts("-1")
#define pyn(x) x ? py : pn
#define all(x) x.begin(), x.end()
#define ft first
#define sd second
#define prq priority_queue
#define rev(x) reverse(all(x))
using namespace std;

int main() {
	int n;cin>>n;
    cout<<((n>>1)+1)*((n+1)>>1);
}


#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
using namespace std;
int check(string f)
{
    int z= 0;
    if( (f[0]=='0' && f.size() > 1) || f.size()>6 && f!="1000000" )
        return -10000000;
      z= atoi(f.c_str());
    return z;
}
int main()
{
    string s ;
    int  Max=-1 ;
    cin >> s;
    int n = s.size();
    for(int i = 1 ; i < n-1; i++)
    {
        for(int j = i+1 ; j < n; j++)
        {
            int s1 , s2 , s3;
            s1=check(s.substr(0,i));
            s2=check(s.substr(i,j-i));
            s3=check(s.substr(j,n-j));
          //  cout << s1 << "   " << s2 << "   " << s3<<endl;

            if(s1+s2+s3 > Max)
                Max=s1+s2+s3;
        }
    }
    cout << Max;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, j, k) for(int i = (j); i <= (k); ++i)
#define pii pair<int, int>
#define fr first
#define sc second

long long a, b, c, l;
long long ans;

long long mxSide(long long a, long long b, long long c, long long l) {
  long long sum = 0;
  FOR(la, 0, l) {
    long long x = min(a + la - b - c, l - la);
    if (x < 0) continue;
    sum += (x + 1) * (x + 2) / 2;
  }
  return sum;
}

int main() {
	cin >> a >> b >> c >> l;
	ans = (l + 3) * (l + 2) * (l + 1) / 6;
	ans -= mxSide(a, b, c, l);
	ans -= mxSide(b, a, c, l);
	ans -= mxSide(c, b, a, l);

	cout << ans << endl;
	return 0;
}


#include<cstdio>
int n;
int main(){
    scanf("%d",&n);
    printf("%d\n",n%5%3+1);
}


#include <iostream>

int n;

using namespace std;
int main()
{
    cin >> n;
    if(n==1) cout << 1;
    else
    {
    cout << n << " ";
    for(int i=n/2; i>1; i--)
        if(n%i==0)
        {
            cout << i << " ";
            n=i;
        }

    cout << 1;
    }
    return 0;
}


#include <iostream>
#define fr(a,b,c) for(int a = b, _ = c; a < _; a++)
using namespace std;
int main(){
	string address, url;
	int n, domain_l, domain_r;
	getline(cin, address);
	n = address.length();
	if(address[2] == 't'){
		url = "http://";
		domain_l = 4;
	}else{
		url = "ftp://";
		domain_l = 3;
	}
	domain_r = address.find("ru", domain_l);
	if(domain_r-domain_l == 0){
		domain_r = address.find("ru", domain_r+1);
	}
	url += address.substr(domain_l, domain_r-domain_l) + ".ru";
	if(domain_r + 2 < n){
		url += "/" + address.substr(domain_r + 2);
	}
	cout << url << endl;
}

// 1505232044281


#include <iostream>

using namespace std;

int la, lb, ra, rb, ta, tb;

int cmmdc(int a, int b){
    int r = 0;
    while(b){
        r = a % b;
        a = b;
        b = r;
    }
    /// rezultatul se afla in a fiindca b preia r = 0;
    return a;
}

int main()
{
    cin >> la >> ra >> ta;
    cin >> lb >> rb >> tb;

    int t = cmmdc(ta, tb);
    int dif;
    if(lb > la){
        swap(la, lb);
        swap(ra, rb);
        swap(ta, tb);
    }
    dif = la - lb;
    int rest = dif % t;

    int inters1 = min(rb - lb, rest + (ra - la)) - rest + 1;

    rest -= t;

    int inters2 = min(rest + (ra - la), rb - lb) + 1;

    cout << max(max(inters1, inters2), 0) << '\n';
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+5,mod=1e9+7;
#define int long long
int n,k,y[N];
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1)res=res*x%mod;
		x=x*x%mod; y>>=1;
	}
	return res;
}
int pl[N],pr[N],fac[N];
signed main(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=k+2;i++)y[i]=(y[i-1]+ksm(i,k))%mod;
	pl[0]=pr[k+3]=fac[0]=1;

    for(int i=1;i<=k+2;i++)pl[i]=pl[i-1]*(n-i)%mod;
    for(int i=k+2;i>=1;i--)pr[i]=pr[i+1]*(n-i)%mod;
	for(int i=1;i<=k+2;i++)fac[i]=fac[i-1]*i%mod;
	int ans=0;
	for(int i=1;i<=k+2;i++){
		int op=y[i];
		int a=pl[i-1]*pr[i+1]%mod;
		int b=fac[i-1]*((k-i)&1?-1:1)*fac[k+2-i]%mod;
		ans=(ans+op*a%mod*ksm(b,mod-2)%mod)%mod;
	}
	cout<<(ans+mod)%mod<<endl;

}


#include	<bits/stdc++.h>
using namespace std;
int	main()	{
    int hh,mm;
    long a;
    scanf("%d:%d",&hh,&mm);
    scanf("%d",&a);
    mm+=a;
    if(mm>=60)
        hh=(hh+mm/60)%24;
        mm=mm%60;
    printf("%02d:%02d",hh,mm);
	return	0;
}


#include <iostream>
using namespace std;
int f(int m)
{
	while(m)
	{
		if(m%10!=4&&m%10!=7) return 0;
		m/=10;
	}
	return 1;
}
int a(int m)
{
	for(int i=m;i>=1;i--)
		if(m%i==0&&f(i)) return 1;
	return 0;
}
int main()
{
	int n;
	cin>>n;
	if(f(n)||a(n)) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
char a[1001],b[1001];
using namespace std;
int main()
{
    scanf("%s%s",a,b);
    int lena=strlen(a),lenb=strlen(b);
    if(lena!=lenb)
    cout<<"NO";
    else
    {
        bool q=1;
        for(int i=0;i<lena;i++)
        if(a[i]!=b[lena-i-1])
        q=0;
        if(q)
        cout<<"YES";
        else
        cout<<"NO";
      }
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <sstream>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cassert>
using namespace std;
typedef long long LL;
#define FOR(x, b, e) for (int x = (b); x <= (e); ++x)
#define FORD(x, b, e) for (int x = (b); x >= (e); --x)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define VAR(v, n) typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int) (x).size())
#define EACH(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define REACH(i, c) for (VAR(i,(c).rbegin()); i != (c).rend(); ++i)
#define UNIQUE(v) do { sort(ALL(v)); (v).resize(unique(ALL(v)) - (v).begin()); } while (0)
#define PB push_back
#define ST first
#define ND second
#define MP make_pair
#define skip continue
const int INF = 1000000001;

#define GET(x)			(scanf("%d", &(x)) == 1)
#define GET2(x, y)		(scanf("%d %d", &(x), &(y)) == 2)
#define GET3(x, y, z)	(scanf("%d %d %d", &(x), &(y), &(z)) == 3)
#define GETS(x)			(scanf("%s", (x)) == 1)
#define DGET(x)			int x; GET(x);

int main()
{
	int n, m, x1, y1, x2, y2;
	GET2(n, m);
	GET2(x1, y1);
	GET2(x2, y2);

	int dx = abs(x1-x2);
	int dy = abs(y1-y2);

	if (max(dx, dy) >= 5 || (dx == 4 && dy == 4) || (min(dx, dy) == 3 && max(dx,dy) == 4)) {
		puts("Second");
	} else {
		puts("First");
	}
}


#include <iostream>

using namespace std;

typedef unsigned long long intreg;

#define mod 1000000007

intreg n,s,f[22],rez;
intreg sum;
int i;
bool semn;

void read_data();
intreg combinari(intreg n,intreg k);
intreg put(intreg x, intreg p);
intreg invers[22];
void pre();

int main()
{
    read_data();
    pre();
    rez=combinari(n+s-1,n-1);
    for(int p=(1<<n)-1; p; --p)
    {
        semn=0;//0 pentru - si 1 pentru +
        sum=0;
        for(int aux=p,i=1; aux; aux>>=1,++i) if(aux&1) semn^=1,sum+=f[i]+1;
        if(s>=sum)  if(semn)
            {
                rez=(rez-combinari(n-1+s-sum,n-1)+mod)%mod;
            }
            else rez=(rez+combinari(n-1+s-sum,n-1))%mod;
    }
    cout<<rez%mod;

    return 0;
}

intreg combinari(intreg n,intreg k)
{
//combinari de n luate cate k
    if (k>n) return 0;
    n%=mod;
    intreg rasp=1;
    for(int i=0;i<k;++i)
    {
        rasp=rasp*(n-i)%mod;
        rasp=rasp*invers[i+1]%mod;
    }
    return rasp;
}

intreg put(intreg x, intreg p)
{
    intreg rez=1;
    for(; p; p>>=1)
    {
        if(p&1) rez=rez*x%mod;
        x=x*x%mod;
    }
    return rez;
}

void pre()
{
    for(int i=1;i<=21;++i) invers[i]=put(i,mod-2);
}

void read_data()
{
    cin>>n>>s;
    for(i=1; i<=n; ++i)
    {
        cin>>f[i];
    }
}


#include <iostream>
#include <cstdio>
using namespace std;
string rev(string s){
    for(int i=0;i<s.size()/2;i++){
        char tmp;
        tmp=s[i];
        s[i]=s[s.size()-1-i];
        s[s.size()-1-i]=tmp;
    }
    return s;
}
string add(string a1, string b1){
    string sum="";
    int num=0,cnt=b1.size()-1,carry=0;
    for(int i=a1.size()-1;i>=0;i--){
        num=num+a1[i]-'0';
        if(cnt>=0){
            num+=b1[cnt]-'0';
        }
        sum+=(num%10+'0');
        num=num/10;
        cnt--;
    }
    return sum;
}

int main()
{
    string a1,b1,a2="",b2="",sum1="",sum2="",sum3;
    cin>>a1>>b1;
    if(a1.size()<b1.size()){
        swap(a1,b1);
    }
    sum1=add(a1,b1);
    sum1=rev(sum1);
    for(int i=0;i<sum1.size();i++){
        if(sum1[i]!='0'){
            sum2+=sum1[i];
        }
    }
    for(int i=0;i<a1.size();i++){
        if(a1[i]!='0'){
            a2+=a1[i];
        }
    }
    for(int i=0;i<b1.size();i++){
        if(b1[i]!='0'){
            b2+=b1[i];
        }
    }
    sum3=add(a2,b2);
    sum3=rev(sum3);
    //cout<<"sum1 "<<sum1<<" sum2 "<<sum2<<" sum3 "<<sum3<<endl;

    if(sum2==sum3){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}


#include <bits/stdc++.h>

#define t first
#define g second
#define end() exit(0)
#define deb(x) cout << #x << " = " << x << endl;

using namespace std;

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

const int D = 1000 * 1000 * 1000 + 7, N = 50, M = 2500, G = 3;

inline int add(int, int);
inline int mul(int, int);
int f(int);
inline istream& operator >> (istream&, song&);
inline int inc(int&, int);
inline int multi(int&, int);
void init();
void inp();
void solve();
void upd();
void calc();

int n, T, dp1[N + 1][M + 1], dp23[N + 1][N + 1][M + 1], jav[N + 1][N + 1][N + 1][G + 1], mf[N + 1], num[G + 1], dur[G + 1], ans;

int main() {
	init();
	inp();
	solve();
	cout << ans << endl;
	return 0;
}
inline int inc(int& x, int y) {
	return (((x += y) < D)? x: (x -= D));
}
inline int add(int x, int y) {
	return (((x + y) < D)? x + y: ((x + y) - D));
}
inline int mul(int x, int y) {
	return ((1ll * x * y) % D);
}
int f(int x) {
	return (~mf[x]? mf[x]: (mf[x] = mul(x, f(x - 1))));
}
inline istream& operator >> (istream &in, song &x) {
	in >> x.t >> x.g;
	return in;
}
inline int multi(int& x, int y) {
	return (x = mul(x, y));
}
void init() {
	memset(mf, -1, sizeof mf);
	mf[0] = 1;
	dp1[0][0] = dp23[0][0][0] = jav[0][0][0][0] = 1;
}
void inp() {
	cin >> n >> T;
	song tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp.g == 1)
			for (int i = num[1]; i >= 0; i--)
				for (int j = dur[1]; j >= 0; j--)
					inc(dp1[i + 1][j + tmp.t], dp1[i][j]);
		else {
			for (int i = num[2]; i >= 0; i--)
				for (int j = num[3]; j >= 0; j--)
					for (int k = dur[2] + dur[3]; k >= 0; k--)
						((tmp.g == 2)? inc(dp23[i + 1][j][k + tmp.t], dp23[i][j][k]): inc(dp23[i][j + 1][k + tmp.t], dp23[i][j][k]));
		}
		dur[tmp.g] += tmp.t;
		num[tmp.g]++;
	}
}
void solve() {
	upd();
	calc();
}
void upd() {
	int i[G + 1];
	for (i[1] = 0; i[1] <= num[1]; i[1]++)
		for (i[2] = 0; i[2] <= num[2]; i[2]++)
			for (i[3] = 0; i[3] <= num[3]; i[3]++)
				for (int prev = 0; prev <= 3; prev++) {
					int tmp = jav[i[1]][i[2]][i[3]][prev];
					if (tmp == 0)
						continue;
					for (int next = 1; next <= 3; next++)
						if (next != prev && i[next] + 1 <= num[next]) {
							i[next]++;
							inc(jav[i[1]][i[2]][i[3]][next], tmp);
							i[next]--;
						}
				}
}
void calc() {
	for (int i = 0; i <= num[1]; i++)
		for (int j = 0; j <= dur[1]; j++) {
			if (T < j)
				break;
			for (int k = 0; k <= num[2]; k++)
				for (int h = 0; h <= num[3]; h++) {
					int nat = mul(dp1[i][j], dp23[k][h][T - j]);
					multi(nat, mul(f(i), mul(f(k), f(h))));
					for (int next = 1; next <= 3; next++)
						inc(ans, mul(nat, jav[i][k][h][next]));
				}
		}
}


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

int main() {
	// your code goes here
	int n,m,p,s;
	cin>>n>>m;
	queue<int>q;
	vector<int>visited(100007);
	q.push(n);
	visited[n]=1;
	int c=0,h=0;
	int maxi=max(n,m);
	while(q.empty()==false)
	{
	    s=q.size();
	    while(s--)
	    {
	    p=q.front();
	    q.pop();
	    if(p==m)
	    {
	        h=1;
	        break;
	    }
	    else
	    {
	        if(p-1<=2*maxi&&visited[p-1]==0)
	        {
	        q.push(p-1);
	        visited[p-1]=1;
	        }
	        if(p*2<=2*maxi&&visited[p*2]==0)
	        {
	        q.push(p*2);
	        visited[p*2]=1;
	        }
	    }
	    }
	    if(h==1)
	    break;
	    c++;
	 }
	 cout<<c;

	return 0;
}


    #include<bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define r_0 return 0
    #define fr first
    #define se second
    #define TIME ios_base::sync_with_stdio(0);
    using namespace std;
    const ll N= 1e5+1 ;
    ll n  , m ,  cnt  , ans , x , sum ,w ;
    vector< ll >v , v1;
    set< ll >se ;
    vector< pair<ll , ll > >p ;
    string s , s1 ;
    map< char , ll >mp ;
    char h , y;
    int main()
    {
        TIME
        mp[ 'a' ] = 1 ;
        mp[ 'e' ] = 1 ;
        mp[ 'u' ] = 1;
        mp[ 'o' ] = 1 ;
        mp[ 'n' ] = 1 ;
        mp[ 'i' ] = 1 ;
       cin >> s;
       if(s.size() == 1 and mp[s[0]] == 0){
       cout << "NO" ;r_0 ;}

       for( ll i= 0  ;i < s.size( ); i ++ )
       {
           if( mp[s[i]] == 0 and mp[s[i+1]] == 1 and s[i+1] != 'n' )
               continue ;
            if( mp[s[i]] == 0 and mp[s[i+1]] == 0 or mp[s[i]] == 0 and s[i+1] == 'n' )
           {
               cout << "NO";
               r_0 ;
           }

       }
       cout << "YES";
    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1000005
const ll MOD = 1000 * 1000 * 1000 + 9;
ll n,m,k;
ll fexp(ll a, ll p)
{
    ll res=1;
    while(p){
        if(p&1){
            res=(res*a)%MOD;
            p--;
        }
        a=(a*a)%MOD;
        p/=2;
    }
    return res;
}
bool f(ll x)
{
//    ll n1 = n-x*k, m1=m-x*k;
//    ll q=n1/k;
    return m-(n%k)-(n-n%k)/k*(k-1)<=x;
}
ll bs(ll l, ll r)
{
//    cout<<"l: "<<l<<" r: "<<r<<endl;
    if(r-l<=1){
        if(f(r))
            return f(l)?l:r;
        return r;
    }
    ll med=(l+r)/2;
    if(f(med))
        return bs(l,med);
    return bs(med,r);
}
int main()
{
//    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    ll p = bs(0,n);
    cout<<((fexp(2,p+1)+MOD-2)%MOD*k%MOD+m-p*k)%MOD;
    return 0;
}


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

int main() {

    long long n, a, s;
    cin >> n;
    while (n >= 10) {
        a = 0;
        while (n != 0) {
            a += n % 10;
            n /= 10;
        }
        n = a;
    }
    cout << n;
}


#include <bits/stdc++.h>
using namespace std;
int dp[10000005];
void pre()
{
    memset(dp , 0 ,sizeof dp);
    dp[5]=1;
    for(int i=6;i<10000001;++i){
        dp[i]=dp[i-1];
        if(i%5==0){
            int j=i;
            while(j%5==0){
                j/=5;
                dp[i]++;
            }
        }
    }

}
int main()
{
int n;
pre();
while(cin>>n){
    vector< int > v;
    for(int i=0;i<10000001;++i){
        if(dp[i]==n)v.push_back(i);
    }
    /*for(int i=26140;i<26160;++i){
        cout<<dp[i]<<" ";
    }*/
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();++i)
        cout<<v[i]<<" ";
    if(v.size())cout<<endl;

}

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
   char a,b;
   int c=0;
   int x;
   cin>>x>>a;
     for (int i=1;i<x;i++)
     {
         cin>>b;
         if( b==a ) c++;
         else a=b;

         }
         cout <<c<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int oo = 0x3fffffff;
const int MAXN = 10;
const int MAXM = 100;

struct SInformation
{
    int a, b, c;
};

struct SEarn
{
    int price;
    int limit;
};

SInformation info[MAXN][MAXM];
SEarn earn[MAXM];
int n, m, cap;

inline bool cmp(const SEarn &a, const SEarn &b)
{
    return a.price > b.price;
}

void init(void)
{
    cin >> n >> m >> cap;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++)
        {
            cin >> info[i][j].a >> info[i][j].b >> info[i][j].c;
        }
    }
}

void solve(void)
{
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < m; k++)
            {
                earn[k].price = max(info[j][k].b - info[i][k].a, 0);
                earn[k].limit = info[i][k].c;
            }
            sort(earn, earn + m, cmp);
            int sum = 0;
            int t = cap;
            for (int k = 0; k < m; k++)
            {
                if (t <= earn[k].limit)
                {
                    sum += t * earn[k].price;
                    break;
                }
                sum += earn[k].limit * earn[k].price;
                t -= earn[k].limit;
            }
            ans = max(sum, ans);
        }
    }
    cout << ans << endl;
}

int main(void)
{
    ios::sync_with_stdio(false);
    init();
    solve();
    return 0;
}


#include<cmath>
#include<cstring>
#include<cassert>
#include<cstdlib>
#include<climits>
#include<cfloat>

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

#include<hash_set>
#include<hash_map>
using namespace __gnu_cxx;

// skrocone typy
typedef long long ll;

typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;
typedef unsigned long long ull;

// int pairs
typedef pair<int,int> pii;typedef pair<uint,uint> puiui;typedef pair<int,uint> piui;typedef pair<uint,int> puii;
// long long pairs
typedef pair< ll,ll> pllll;typedef pair<ull,ull> pullull;typedef pair<ull, ll> pullll;typedef pair<ll, ull> pllull;
// char pairs
typedef pair<char,char> pcc;typedef pair<char,uchar> pcuc;typedef pair<uchar,char> pucc;typedef pair<uchar,uchar> pucuc;
// long long x int pairs
typedef pair<int,ll> pill;typedef pair<ll,int> plli;typedef pair<uint,ll> puill;typedef pair<ll,uint> pllui;typedef pair<ull,int> pulli;typedef pair<int,ull> piull;typedef pair<uint,ull> puiull; typedef pair<ull,uint> pullui;
// long long x char pairs
typedef pair<char,ll> pcll;typedef pair<ll,char> pllc;typedef pair<uchar,ll> pucll;typedef pair<ll,uchar> plluc;typedef pair<ull,char> pullc;typedef pair<char,ull> pcull;typedef pair<uchar,ull> pucull; typedef pair<ull,uchar> pulluc;
// int x char pairs
typedef pair<char,int> pci;typedef pair<int,char> pic;typedef pair<uchar,int> puci;typedef pair<int,uchar> piuc;typedef pair<uint,char> puic;typedef pair<char,uint> pcui;typedef pair<uchar,uint> pucui; typedef pair<uint,uchar> puiuc;

#define mp make_pair
#define fi first
#define se second

#define pb push_back
#define pf push_front
#define ins insert
#define era erase

#define it iterator

#define type(x) __typeof(x)

#define foreach(itr,cont) for(__typeof(cont.begin()) itr = cont.begin(); itr != cont.end(); ++itr)
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=(n)-1; i>=0; --i)
#define fo(i,a,b) for(int i=(a); i<(b); ++i)
#define of(i,a,b) for(int i=(b)-1; i>=(a); --i)

#define sz(c) (int)(c).size()

struct llhash {size_t operator()(ll  x)const {return (int)x ^ (int)(x>>32);}};
struct piihash{size_t operator()(pii x)const {return x.fi^x.se;}};

int nplanety;
int ntowary;
int ladownosc;
int buy[19][109];
int sel[19][109];
int num[19][109];

int comp4pla(int from, int to)
{
    vector<pii> pro;
    rep(i,ntowary)pro.pb(mp(sel[to][i]-buy[from][i],i));
    sort(pro.begin(),pro.end());
    int pos = sz(pro)-1;
    int wynik = 0;
    int moge = ladownosc;
    while(pos>=0 && pro[pos].fi>0 && moge>0)
    {
        int ile = min(moge,num[from][pro[pos].se]);
        wynik+=pro[pos].fi*ile;
        moge -= ile;
        --pos;
    }
    return wynik;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.precision(40);
    cout.setf(ios::fixed, ios::floatfield);

    cin>>nplanety>>ntowary>>ladownosc;

    rep(i,nplanety)
    {
        string s;
        cin>>s;
        rep(j,ntowary)
        {
            cin>>buy[i][j]>>sel[i][j]>>num[i][j];
        }
    }

    int profit = 0;
    rep(i,nplanety)rep(j,nplanety)profit=max(profit,comp4pla(i,j));

    cout<<profit<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <string>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m, k;
    cin >> n >> m >> k;
    int a[100][200], b[100][200], c[100][200];
    string s;
    for (int i=0; i<n; i++)
    {
        cin >> s;
        for (int j=0; j<m; j++)
            cin >> a[i][j] >> b[i][j] >> c[i][j];
    }
    int ans = 0;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
        {
            if (i == j)
                continue;
            priority_queue < pair <int, int> > q;
            for (int l=0; l<m; l++)
                    q.push(make_pair(b[j][l] - a[i][l], c[i][l]));
            int t = k;
            int res = 0;
            while (!q.empty() && t > 0)
            {
                int x = q.top().first, y = q.top().second;
                int d = min(t, y);
                q.pop();
                if (x <= 0)
                    continue;
                if (y-d != 0)
                    q.push(make_pair(x, y-d));
                res += x*d;
                t -= d;
            }
            ans = max(ans, res);
        }
    cout << ans;
    return 0;
}