#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1000000007;
#define fzx long long
fzx ksm(fzx a,fzx k){
	if(k==0) return 1;
	fzx tmp=ksm(a,k>>1);
	if(k&1) tmp=tmp*tmp*a%mod;
	else tmp=tmp*tmp%mod;
	return tmp;
}
fzx n,m;fzx k;
int main(){
	cin>>n>>m>>k;
	if(k==-1){
		if((n+m)%2){
			puts("0");
			return 0;
		}
		else{
			printf("%I64d",ksm(2,(n-1)*(m-1)));
			return 0;
		}
	}
	printf("%I64d",ksm(2,(n-1)*(m-1)));
	return 0;
}


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

long long power(long long a,long long b);

int main(void)
{
    int n,m,k;
    cin>>n>>m>>k;
    if(n%2!=m%2&&k==-1)
    {
        cout<<0<<endl;
        return 0;
    }
    long long p=power(2,n-1);
    cout<<power(p,m-1)<<endl;
}

long long power(long long a,long long b)
{
    if(b==1)
        return a;
    long long p=power(a,b/2);
    if(b%2==0)
        return (p*p)%M;
    return (a*((p*p)%M))%M;
}


#include <bits/stdc++.h>

using namespace std;

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

    int B, G, N;
    cin >> B >> G >> N;
    if (B + G == N) cout << 1;
    else cout << min(min(B, G), N) + 1;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define itn int
#define pp pair<int,ll>
#define fi first
#define se second
#define sc(a) scanf("%d" , &a)
#define scl(a) scanf("%lld" , &a)
#define lg 18
#define N 100005
#define all(v)        ((v).begin()), ((v).end())
#define sz(v)       ((int)((v).size()))
#define clr(v, d)     memset(v, d, sizeof(v))
#define fo(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define fod(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define foa(v)       fo(i, 0, sz(v)) fo(j, 0, sz(v[i]))
#define fov(i, v)     for(auto i:v)
#define lp(i, cnt)      fo(i, 0, cnt)
#define lpi(i, s, cnt)    fo(i, s, cnt)
#define P(x)        cout<<#x<<" = { "<<x<<" }\n"
#define pb          push_back
#define MP          make_pair
#define fastIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test    int TEST;cin>>TEST;fo(T,1,TEST+1)
const ll MOD = 1000000007;
const int MAX = 1e9+7;
const int MIN = -1e9+7;
using namespace std;

int main(){

    fastIO;
    //freopen("halfnice.in","r",stdin);

    ll b,g; cin >> b >> g;
    ll n; cin >> n;

    if(b >= n && g >= n){
        cout<< n+1;
    }
    else if(b+g == n){
        cout<< 1;
    }
    else{
        cout<< min(b,g)+1;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
#define F first
#define S second
#define pi 3.1415926535897932
#define INF INT_MAX
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n,b,g,i,j,x,y,w,ans;
    cin>>b>>g>>n;
    if(b>=n&&g>=n)ans=n+1;
    else if(b<n&&g>=n)ans=(b+1);
    else if(g<n&&b>=n)ans=(g+1);
    else ans=abs(b-g)+1;
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<vector<vector<int>>> dp;

int minDecks(int n, int i, int g, int b, int gc, int bc, int cont){
  if(gc >= g && bc >= b) return cont;
  if(i > n) return n+1;

  auto& x = dp[gc][bc][i];
  if(x >= 0) return x;

  return (x=min(minDecks(n,i+1,g,b,gc+n-i,bc+i,cont+1), minDecks(n,i+1,g,b,gc,bc,cont)));
}

int main(){
  int b,g,n;

  cin >> b >> g >> n;

  dp = vector<vector<vector<int>>>(600, vector<vector<int>>(600,vector<int>(600,-1)));

  cout << minDecks(n,0,g,b,0,0,0) << endl;

  return EXIT_SUCCESS;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define LL long long
#define N 1000000
#define inf 0x3f3f3f3f
using namespace std;
int main(){
	int i,j,k,m,n,sum1=0,sum2=0;
	char c;
	while(scanf("%c",&c)){
		if(c=='Q')sum1+=9;if(c=='R')sum1+=5;if(c=='B')sum1+=3;if(c=='N')sum1+=3;if(c=='P')sum1+=1;
		if(c=='q')sum2+=9;if(c=='r')sum2+=5;if(c=='b')sum2+=3;if(c=='n')sum2+=3;if(c=='p')sum2+=1;
	}
	if(sum1>sum2)cout<<"White";
	else if(sum1==sum2)cout<<"Draw";
	else cout<<"Black";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[8][8],b=0,w=0;
	for(int i=0;i<8;i++)
	{
		for(int j=0;i<8;j++) cin>>a[i][j];
	}
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			switch(a[i][j])
			{
				case 'Q':w+=9;break;
				case 'R':w+=5;break;
				case 'B':w+=3;break;
				case 'N':w+=3;break;
				case 'P':w++;break;
				case 'q':b+=9;break;
				case 'r':b+=5;break;
				case 'b':b+=3;break;
				case 'n':b+=3;break;
				case 'p':b++;break;
			}
		}
	}
	if(w>b) cout<<"White";
	if(w<b) cout<<"Black";
	else cout<<"Draw";
  return 0;
}


#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<time.h>
#include<math.h>

#define Max(a,b)    ((a > b) ? a : b)
#define Min(a,b)    ((a < b) ? a : b)
#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)
#define SWAP(a,b)   {t = a; a = b; b = t;}
#define lli long long int
#define endl    puts("")
#define MAX 30000005
#define WH	while

int n, m, i, j, k, s, l;
int white, black;

char matrix[MAX/1000][MAX/1000];

int control(char c){

	c += 32*(c >= 'A' && c <= 'Z');
	if(c == 'q') return 9;
	if(c == 'r') return 5;
	if(c == 'b') return 3;
	if(c == 'k') return 3;
	if(c == 'p') return 1;

}

int main()
{
	scanf("%s", matrix[0]);

	n = strlen(matrix[0]);

	FOR(i,1,n-1) scanf("%s", matrix[i]);

	FOR(i,0,n-1){

		FOR(j,0,n-1){
			if(matrix[i][j] != '.' && matrix[i][j] >= 'A' && matrix[i][j] <= 'Z') white += control(matrix[i][j]);
			if(matrix[i][j] != '.' && matrix[i][j] >= 'a' && matrix[i][j] <= 'z') black += control(matrix[i][j]);
		}

	}

	puts((white > black) ? "White" : (black > white) ? "Black" : "Draw");

	return 0;
}


#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    char a;
    int w=0;
    int b=0;

    for(int i=0; i<72; i++)
    {
        a=_getch();
        switch(a)
        {
            case 'p':b+=1;break;
            case 'P':w+=1;break;
            case 'n':b+=3;break;
            case 'N':w+=3;break;
            case 'b':b+=3;break;
            case 'B':w+=3;break;
            case 'r':b+=5;break;
            case 'R':w+=5;break;
            case 'q':b+=9;break;
            case 'Q':w+=9;break;
        }
    }
    if(b>w){cout<<endl<<"Black";}
    if(b<w){cout<<endl<<"White";}
    if(b==w){cout<<endl<<"Draw";}

    return 0;
}


#define CRT_SECURE_NO_WARNINGS
#include<bits\stdc++.h>
#include<math.h>
using namespace std;

string s;
int main(){
	//freopen("joyful.in","r",stdin);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string str,NewStr="";
	cin>>str;
	unsigned long long num=0, ans=0,pw=2;
	for(int i = 0 ; i < str.length() ; i++){
		if(str[i]=='>')NewStr+="1000";
		else if(str[i]=='<')NewStr+="1001",cerr<<NewStr<<endl;
		else if(str[i]=='+')NewStr+="1010",cerr<<NewStr<<endl;
		else if(str[i]=='-')NewStr+="1011",cerr<<NewStr<<endl;
		else if(str[i]=='.')NewStr+="1100",cerr<<NewStr<<endl;
		else if(str[i]==',')NewStr+="1101",cerr<<NewStr<<endl;
		else if(str[i]=='[')NewStr+="1110",cerr<<NewStr<<endl;
		else if(str[i]==']')NewStr+="1111",cerr<<NewStr<<endl;
	}

	num=(NewStr[NewStr.length()-1]-'0');
	ans+=num;
	for(int i = NewStr.length()-2 ; i >= 0;i--){
		//cerr<<(NewStr[i]-'0')*pow(2,x)<<endl;
		cerr<<num<<" " <<pw<<" "<<ans<<"\n";
		num=((NewStr[i]-'0')*pw);
		//num=num%1000003;
		ans+=num;
		pw*=2%1000003;
		pw%=1000003;
		//	pw=(pw*2)%1000003;
		//	pw%=1000003;
	}

	cout<<ans%1000003<<endl;
	system("pause");
}


#include <iostream>
#include <math.h>
#include <Windows.h>
#include <algorithm>
#include <string.h>
typedef unsigned char uch;
using namespace std;

uch ch[10001];
uch a[10001];
int i,j,k;
string s;
bool ans;
int main()
{
    i = 1;
    while (ch[i-1] != '\n')
    {
          ch[i] = getchar();
          if (ch[i] == '>')
             s+="1000";
          if (ch[i] == '<')
             s += '1001';

          if (ch[i] == '+')
             s += "1010";

          if (ch[i] == '-')
             s+="1011";

          if (ch[i] == '.')
             s+="1100";

          if (ch[i] == ',')
             s+="1101";

          if (ch[i] == '[')
             s+= "1110";

          if (ch[i] == ']')
             s+= "1111";
          i++;
    }
   // cout << s << endl;
    int ans = 0;
    int cur = 1;
    int M = 1000003;
    for (int j = (i - 2) * 4  - 1; j >= 0; j--)
    {
        if (s[j] == '1')
           ans = (ans + cur) % M;
        cur = (cur * 2) % M;
        //cout << "ans = " << ans << endl;
        //cout << "cur = " << cur << endl;
    }
    cout << ans;

   getchar();
   getchar();
   return 0;
}


#include <cstdio>

const double eps = 1e-6;

int per[4], i, j, d, maj[100001];

int solve() {
	int vp, vd,	tupon, order, dist;
	scanf("%d%d%d%d%d", &vp, &vd, &tupon, &order, &dist);
	if (vp > vd) {
		return 0;
	} else if (vp == vd) {
		return 1;
	} else {
		int res = 0;
		double ppos = tupon * vp, t;
		while (t = ppos / double(vd - vp), ppos + vp * t < dist - eps) {
			ppos += (t * 2 + order) * vp;
			++res;
		}
		return res;
	}
}

int main() {
	printf("%d\n", solve());
	return 0;
}


/*
ID: zxzbos1
LANG: C
TASK: fence8
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <malloc.h>

#define MAXR 2000
#define MAXN 100
#define INF 2000000001

typedef int LL;

typedef struct fen{
    LL x,y;
}Fen;

void Next(Fen* x,LL vp,LL vd,LL f)
{
    x->x=x->y*vp*vd*f+(vp+vd)*x->x;
    x->y*=(vd-vp);
}

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

int main()
{
    LL vp,vd,t,f,c;
    LL temp;;

    scanf("%lld %lld %lld %lld %lld",&vp,&vd,&t,&f,&c);

    Fen now;
    int ans;
    ans=0;
    if(vp>=vd)
    {
        printf("%d\n",ans);return 0;
    }

    now.x=vp*vd*t;
    now.y=vd-vp;
    while(1==1)
    {
        if(now.x/now.y>=c)break;
        ++ans;
        Next(&now,vp,vd,f);
        temp=gcd(now.x,now.y);
        now.x/=temp;now.y/=temp;
    }

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

    return 0;
}


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

int main(){
    int vp, vd, t, f, c;
    cin >> vp >> vd >> t >> f >> c;
    vector<int> D;
    D.push_back((vp * t)/(vd - vp));
    int i = 0;
    while(vd * D[i] < c){
        D.push_back((vp * (D[i] + f) + vd * D[i])/(vd - vp));
        ++i;
    }
    cout << i;
    return 0;
}


/*
ID: zxzbos1
LANG: C
TASK: fence8
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <malloc.h>

#define MAXR 2000
#define MAXN 100
#define INF 2000000001

typedef long long LL;

typedef struct fen{
    LL x,y;
}Fen;

void Next(Fen* x,LL vp,LL vd,LL f)
{
    x->x=x->y*vp*vd*f+(vp+vd)*x->x;
    x->y*=(vd-vp);
}

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

int main()
{
    LL vp,vd,t,f,c;
    LL temp;;

    scanf("%lld %lld %lld %lld %lld",&vp,&vd,&t,&f,&c);

    Fen now;
    int ans;
    ans=0;
    if(vp>=vd)
    {
        printf("%d\n",ans);return 0;
    }

    now.x=vp*vd*t;
    now.y=vd-vp;
    while(1==1)
    {
        if(now.x/now.y>=c)break;
        ++ans;
        Next(&now,vp,vd,f);
        temp=gcd(now.x,now.y);
        now.x/=temp;now.y/=temp;
    }

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

    return 0;
}


///IN THE NAME OF ALLAH
 using namespace std;
 #include<bits/stdc++.h>
 bool Primes[1000000000];
 int main(){
  int n,a,b,c,d,XS=0,YS=0,draw=0;
  cin >> n >> a >> b >> c >> d;
  if(a==1)
    XS = n;
 else
  for(int i=a;i<=n;i+=a){
    XS++;
    Primes[i]=1;
  }
  if(b==1)
    YS = n-XS;
  else
  for(int i=b;i<=n;i+=b){
   if(Primes[i]==1)
    draw++;
    YS++;
    Primes[i]=1;
  }
long long Sum = (YS-draw)*d+(XS-draw)*c+draw*(max(c,d));
cout<<Sum;
 }


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pi 3.14159265359
#define eps 1e-6
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL);
ifstream in("in.txt");
ofstream out("out.txt");

bool used[1000000001] = {0};

int main() {
	fastio();
	ll n, a, b, p, q; cin >> n >> a >> b >> p >> q;
	int ans = 0;
	ll t1 = a;
	ll t2 = b;
	while(t1 <= n) {
		used[t1] = 1;
		ans += p;
		t1 += a;
	}
	while(t2 <= n) {
		if(used[t2] && q > p) {
			ans -= p;
			ans += q;
		} else if(!used[t2]){
			ans += q;
		}
		t2 += b;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define PI acos(-1.0)
#define LL long long
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
int main()
{
   //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    vector<int>v1;
    vector<int>v2;
    vector<int>v3;
    vector<int>v4;
    int index,a,b,p,q,res;
    while(scanf("%d%d%d%d%d",&index,&a,&b,&p,&q)!=EOF)
    {
         for(int i=1;;i++)
        {
            LL res1=a*i;
            if(res1>index)
            {
                break;
            }
            v1.push_back(res1);
        }

        for(int i=1;;i++)
        {
            LL res2=b*i;
            if(res2>index)
            {
                break;
            }
            v2.push_back(res2);
        }
        int flag=0;
        LL cost;
        if(p<q)
        {
            flag=1;
            for(int i=0;i<v1.size();i++)
            {
                for(int j=0;j<v2.size();j++)
                {
                    if(v1[i]==v2[j])
                    {
                        v3.push_back(v1[i]);
                        break;
                    }
                }
            }
        }

        else
        {
            for(int i=0;i<v2.size();i++)
            {
                for(int j=0;j<v1.size();j++)
                {
                    if(v2[i]==v1[j])
                    {
                        v4.push_back(v2[i]);
                        break;
                    }
                }
            }
        }
        if(flag)
        {
            cost=p*(v1.size()-v3.size())+q*v2.size();
        }
        else
        {
            cost=p*v1.size()+q*(v2.size()-v4.size());
        }
        printf("%lld\n",cost);
        v1.clear();
        v2.clear();
        v3.clear();
        v4.clear();
    }
}


#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main ()
{
    long long n,a,b,p,q,res,i,cnt=0,cnt2=0;
    unsigned char* arr;
    cin>>n>>a>>b>>p>>q;
    arr = (unsigned char*)malloc(n*sizeof(unsigned char));
    memset(arr,'0',sizeof(arr));
    if(p>=q){
    for(i=1; i<=n; i++)
    {
        if(i*a>n && i*b>n)
            break;
        if(arr[i*a]!='1' && i*a<=n)
            {
                arr[i*a] = '1';
                cnt++;
            }
        if(arr[i*b]!='1' && i*b<=n)
                {
                    arr[i*b] = '1';
                    cnt2++;
                }

    }
    }
    else if(p<q){
        for(i=1; i<=n; i++)
    {
        if(i*a>n && i*b>n)
            break;
        if(arr[i*b]!='1' && i*b<=n)
            {
                arr[i*b] = '1';
                cnt2++;
            }
        if(arr[i*a]!='1' && i*a<=n)
                {
                    arr[i*a] = '1';
                    cnt++;
                }
    }
    }
    res = (p*cnt)+(q*cnt2);

    cout<<res<<endl;;
}


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

#define MAXTIME ((24-5)*60-1)
#define MINTIME 0

int main() {
	int a, b, ta, tb, t0;
	int ans=0, x;
	int h, m;

	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%02d:%02d", &h, &m);
	t0 = h * 60 + m - 5 * 60;

	if (t0 + ta > MAXTIME) ta = MAXTIME - t0;
	if (t0 - tb < MINTIME) { tb = t0 - MINTIME; ans++; }

	ans += trunc((t0 + (ta - 0.1)) / b) - trunc((t0 - (tb - 0.1)) / b);

	printf("%d", ans);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
#define ll __int64
#define INF 0x7fffffff   //INT_MAX
#define inf 0x3f3f3f3f   //
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
using namespace std;
struct timee{
	int h;
	int m;
};
int a,ta,b,tb;
int temp[30][65];
void initB(){
	timee flag;
	flag.h=5;
	flag.m=0;
	while(flag.h<23 || (flag.h==23 &&flag.m<=59)){
		temp[flag.h][flag.m]=1;
		flag.m+=b;
		while(flag.m>=60){
			flag.m-=60;
			flag.h++;
		}
	}
}
int main(){
	//freopen("1.txt","r",stdin);
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    mem(temp);
    initB();
    timee sta,S,end;
    int cnt=0;
    char p[20];
    scanf("%s",p+1);
    sta.h=(p[1]-'0')*10+(p[2]-'0');
    sta.m=(p[4]-'0')*10+(p[5]-'0');
    S.h=sta.h,S.m=sta.m;
    end.h=sta.h,end.m=sta.m;;
    end.m+=ta;
    while(end.m>=60){
    	end.h++;
    	end.m-=60;
    }
    if(end.h >23){
    	end.h=23;
    	end.m=59;
    }
    sta.m-=tb;
    while(sta.m<0){
    	sta.h--;
    	sta.m+=60;
    }
    if(sta.h<5){
    	sta.h=5;
    	sta.m=0;
    }
    else{
        if(temp[sta.h][sta.m]){
        	cnt--;
        }
    }
//    printf("%d\n",cnt);
//    printf("%d:%d\n",sta.h,sta.m);
//    printf("%d:%d\n",end.h,end.m);
    while(sta.h < end.h || (sta.h==end.h && sta.m<=end.m)){
    	if(sta.h==end.h && sta.m==end.m  && temp[end.h][end.m]==1)
        	cnt--;
        if(temp[sta.h][sta.m]==1)
    		cnt++;
    	sta.m++;
        while(sta.m>=60){
        	sta.h++;
        	sta.m-=60;
        }
//        printf("cnt=%d %d %d\n",cnt,sta.h,sta.m);
    }
	printf("%d\n",cnt);
	return 0;
}


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

#define MAXTIME ((24-5)*60-1)
#define MINTIME 0

int main() {
	int a, b, ta, tb, t0;
	char doph1, doph2, dopm1, dopm2, dop;
	int ans=0, x;

	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%c", &dop);
	scanf("%c%c%c%c%c", &doph1, &doph2, &dop, &dopm1, &dopm2);
	t0 = ((doph1 - '0') * 10 + (doph2 - '0')) * 60 + ((dopm1 - '0') * 10 + (dopm2 - '0')) - 5 * 60;

	x = t0 % b;
	if (t0 + ta > MAXTIME) ta = MAXTIME - t0;
	if (t0 - tb < MINTIME) { tb = t0 - MINTIME; ans++; }

	ans += trunc((t0 + (ta - 0.1)) / b) - trunc((t0 - (tb - 0.1)) / b);

	printf("%d", ans);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <iostream>
#define m 60*24-1
using namespace std;

int main()
{
   int a,b;
   int c,d;
   int e,f;
   cin>>a>>b>>c>>d;
   scanf("%d:%d",&e,&f);
   int q=e*60+f-d;
   int w=e*60+f+b;
if(w>m) w=m;
if(q<300) q=300;

int lze=300;
int ans=0;
//cout<<q<<' '<<w<<endl;
while(lze<=m)
{

    if(lze>=q&&lze<w) {
            if(lze+d==e*60+f) ans--;
            ans++;

 //  cout<<lze<<' ';
    }
        lze+=c;
}

cout<<ans;

	return 0;
}


/// This code is a pure govnocode
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " = " << x << endl;
using namespace std;
const int MAXN = 5005;
const int HUJ = 5002;

// (c) JustN template 2016.

/// Use only with Govno Code Compiler (GCC) or Govno code compiler for Pure Professionals 11 (GPP, G++)

typedef long long ll;

ll fart (ll n)
{
    ll f = 0;
    while (n > 0)
    {
        if (n & 1) f++;
        n/=2;
    }
    return f;
}
int main()
{
    ll s;
    ll x;
    ll d;
    cin >> s;
    cin >> x;
    d = s - x;
    if (d < 0 || d%2)
    {
        cout << 0;
        return 0;
    }
    d /= 2;

    if (d & x > 0)
    {
        cout << 0;
        return 0;
    }

    ll k = fart(x);
   // DEBUG(fart(0));
    ll pow = 1;
  //  DEBUG(k);
    for (ll i = 0; i < k; i++)
    {
        pow *= 2;
    }
    if (d == 0) pow -= 2;
    cout << pow;
    return 0;
}


//In the name of God.
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef long long int ll;
long long int po(ll c)
{
	ll an=1;
	for (int i=0;i<c;i++)
		an*=2;
	return an;
}
int main(){
	bool f[50];
	for (int i=0;i<50;i++)
		f[i]=false;
	long long int s,x,t=0;
	cin>>s>>x;
	long long int n=x,c=0;
	while (n>0)
	{
		if (n%2==1)
		{
			f[c]=1;
			t++;
		}
		n/=2;
	}
	s-=x;
	if (s==0)
	{
		cout<<po(t)-2;
		return 0;
	}
	if (s%2!=0)
	{
		cout<<"0";
		return 0;
	}
	else
	{
		s/=2;
		c=49;
		while (s>0)
		{
			if (po(c)>s)
				c--;
			else
			{
				if (f[c]==true)
				{
					cout<<"0";
					return 0;
				}
				else
				{
					s-=po(c);
				}
			}
		}
	}
	cout<<po(t);
	return 0;
}


#include <functional>
#include <algorithm>
#include <complex>
#include <iostream>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;
const double PI = acos(-1.0);

int main() {

   // freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);

    ll a, b;
    cin >> a >> b;

    ll tmpa = a;
    int res = 0;
    for (int i = 0; i < 50; ++i) {
        if ((b >> i) & 1) {
            a -= (1LL << i);
            res++;
        }
    }
    if (a % 2 != 0) {
        cout <<0;
    } else {
        cout << (1LL << __builtin_popcountll(b)) - 2 * (tmpa == b);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    long long s, x;
    cin >> s >> x;
    long long s1 = s;
    long long x1 = x;
    long long cp = 1;
    static int b[100]; //���������� �����
    int p = 0;
    while (x1 != 0)
    {
        b[p] = x1 % 2;
        p++;
        s1 -= cp * (x1 % 2);
        cp *= 2;
        x1 /= 2;
    }
    if (s1 % 2 == 1)
    {
        cout << 0;
        return 0;
    }
    s1 /= 2;
    static int v[100];
    p = 0;
    while (s1 != 0)
    {
        v[p] = s1 % 2;
        s1 /= 2;
        p++;
    }
    long long ans = 1;
    for (int i = 0; i < 100; i++)
    {
        if (b[i] and v[i])
        {
            cout << 0;
            return 0;
        }
        if (b[i])
        {
            ans *= 2;
        }
    }
    if (s == x)
    {
        ans -= 2;
    }
    cout << ans;
}


#include <iostream>

int main()
{
	int n, k{1};
	std::cin >> n;
	for (int i = n, j = 1; i != 2 * n - 1 || j != n; k % j ? k *= i++ : k /= j++);
	std::cout << k;
}


#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;

int n,a[1000][1000],i,j;

int main()
{
    cin>>n;
    for(i=1;i<=n;++i)
     {a[i][1]=1;a[1][i]=1;}
    for(i=2;i<=n;++i)
      for(j=2;j<=n;++j)
        a[i][j]=a[i-1][j]+a[i][j-1];
    cout<<a[n][n];
    getch();
    return 0;
}


#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
	long int *dyn_arr,n,i,j;
	cin>>n;
	dyn_arr= new long int[n*n];
	for(i=0;i<n;++i)
		dyn_arr[i*n]=1;
	for(j=0;j<n;++j)
		dyn_arr[0*n + j]=1;
	for(i=1;i<n;++i)
		for(j=1;j<n;++j)
			dyn_arr[i*n +j]=dyn_arr[(i-1)*n +j] + dyn_arr[i*n + (j-1)];
	cout<<dyn_arr[(n-1)*n+(n-1)];
	delete[] dyn_arr;
	getch();
	return 0;
}


#include <stdio.h>
#include <conio.h>
struct Table
{
	int tb[10][10];
	int n;
};
void main()
{
	Table a;
	int max;
	FILE* fin = fopen("input.txt", "rt");
	if (!fin)
	{
		printf("Can't open input.txt\n");
		getch();
		return;
	}
	printf("Open input.txt successfully\n");
	fscanf(fin, "%d ", &a.n);
	fclose(fin);
	for (int i = 0; i < a.n; i++)
		a.tb[i][0] = 1;
	for (int i = 1; i < a.n; i++)
		a.tb[0][i] = 1;
	if (a.n != 1)
	for (int i = 1; i < a.n;i++)
	for (int j = 1; j < a.n; j++)
		a.tb[i][j] = a.tb[i - 1][j] + a.tb[i][j - 1];
	max = a.tb[a.n - 1][a.n - 1];
	FILE* fout = fopen("output.txt", "wt");
	if (!fout)
	{
		printf("Can't open output.txt\n");
		getch();
		return;
	}
	printf("Open output.txt successfully\n");
	fprintf(fout, "%d ", max);
	fclose(fout);
	getch();
}


#include <iostream>
#include <stdio.h>
using namespace std;
void main()
{
	setlocale(LC_ALL, "Russian");
	int n;
	int s = 0;
	cin>>n;
	if (( n>=1 ) && ( n<=5 ) && (n % 2 == 1))
	{
		int **a;
		a = new int*[n];

		for(int i = 0; i < n; i++)
			a[i] =new int[n];

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
				cin >> a[i][j];
		}
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				if (a[i][j] < 0 || a[i][j] > 100)
					cin >> a[i][j];

		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
			{
				if (i == j || (n - 1 - i) == j || i == (n - 1) / 2 || j == (n - 1) / 2)
					s = s + a[i][j];
			}
			cout << s;
	}
	system("Pause");
}


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

int main(){
	int n;
	int summ = 0;
	vector <vector <int> > matr;
	vector <vector <bool> > used;
	cin >> n;

	matr.resize(n);
	used.resize(n);
	for (int i = 0; i < n; i++){
		matr[i].resize(n);
		used[i].resize(n);
		for (int j = 0; j < n; j++){
			used[i][j] = false;
			cin >> matr[i][j];
		}
	}

	int middle = (n - 2)/2 + 1;

	for (int i = 0; i < n; i++){
		summ += matr[i][i];
		used[i][i] = true;

		if (used[i][n-i-1] == false){
			summ += matr[i][n-i-1];
			used[i][n-i-1] = true;
		}

		if (used[i][middle] == false){
			summ += matr[i][middle];
			used[i][middle] = true;
		}

		if (used[middle][i] == false){
			summ += matr[middle][i];
			used[middle][i] = true;
		}
	}

	cout << summ;
	return 0;
}


#include <stdio.h>
#include <conio.h>

const int N = 5;

int main()
{
    int array[ N ][ N ];
    int sizeArr = 0;
    int input;
    int i,j;
    int sumHeadDiag = 0, sumAddDiag = 0, sumCent1 = 0, sumCent2 = 0, result = 0;

    scanf("%d", &sizeArr);

    if(sizeArr == 1)
    {
        scanf("%d", &input);
        printf("%d", input);
    }
    else
    {
    for( i = 0; i < sizeArr; i++ )
        for( j = 0; j < sizeArr; j++ )
        {
            scanf( "%d", &input);
            array[i][j] = input;
        }

    for( i = 0; i < sizeArr; i++)
        sumHeadDiag += array[i][i];

    for( i = sizeArr-1; i >= 0; i-- )
        sumAddDiag += array[i][i];

    for ( i = 0; i < sizeArr-1; i++ )
        sumCent1 += array[i][ (sizeArr+1)/2];

    for ( i = 0; i < sizeArr-1; i++ )
        sumCent2 += array[ (sizeArr+1)/2 ][i];

    result = sumCent1 + sumCent2 + sumAddDiag + sumHeadDiag - 4*array[(sizeArr + 1)/2][(sizeArr + 1)/2] ;
    printf("%d", result);
    }
    _getch();
    return 0;

}


#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
	int i, j, n, sum=0, avg;
	cin >> n;
	int **a = new int* [n];
	for (i=0; i<n; i++)
		a[i] = new int [n];
	for (i=0; i<n; i++)
		for (j=0; j<n; j++)
			cin >> a[i][j];
	for (i=0; i<n; i++)
		for (j=0; j<n; j++)
		{
			if (i==j) sum+=a[i][j];
			if ((i+j) == (n-1)) sum+=a[i][j];
		}
	avg = (n-1)/2;
	for (i=0; i<n; i++)
	{
		sum+=a[avg][i];
		sum+=a[i][avg];
	}
	sum -=3*a[avg][avg];
	if (n==1) sum = a[0][0];
	cout << sum;
	_getch();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS//
#include <bits/stdc++.h>//Большинство библиотек, которые часто используются
#include <iomanip>//Для вывод с определенной точностью  <<fixed<<setprecision(N)

using namespace std;
int n,m;
int mas[101];
void sort()
{
   for( int a=0;a<n-1;a++)
   for (int b=a+1;b<n;b++)
   if(mas[a]>mas[b])
   {
   int tmp=mas[a];
   mas[a]=mas[b];
   mas[b]=tmp;
   }
}

void smth()
{
   for(int i=0;i<n-1;i++)
{
   while(mas[i]<=mas[i+1] && m>0)
   {
      mas[i]++;
      m--;
   }
}
   if(m>0 && (mas[0])==mas[n-1]+1)
   {
   mas[n-1]++;
   m--;
   }
}
int main ()
{
int max=INT_MIN;
cin>>n>>m;
for (int i=0;i<n;i++)
{
cin>>mas[i];
if (mas[i]>max)
max=mas[i];
}
max+=m;
sort();
if(n==1)
{
   cout<<m+mas[0]<<" ";
   cout<<m+mas[0];
   return 0;
}

while(m>0)smth();
sort();
cout<<mas[n-1]<<" "<<max<<endl;

return 0;
}


#include<iostream>

using namespace std;

int main(){
    int n, m, min=0, max=0, tempmin;
    cin>>n>>m;
    int k[n];
    for(int i=0; i<n; i++){
        cin>>k[i];
        if(k[i]>max)
            max=k[i];
    }
    tempmin=max;
    for(int i=0; i<n; i++){
        int r[n];
        r[i]=k[i];
        if(k[i]<tempmin)
            tempmin=k[i];
    }
    int temp=m;
    while(tempmin<max){
        tempmin++;
        temp--;
        if(temp==0){
            cout<<max<<" "<<max+m;
            return 0;
        }
    }
    int maxtemp=max;
    temp=m;
    for(int i=0; i<m; i++){
        if(i==n)
            i=0;
        while(k[i]<maxtemp){
            k[i]++;
            temp--;
        }
        int j=0;
        while(k[j]==maxtemp){
            j++;
            if(j==n){
                maxtemp++;
                if(temp!=0){
                    k[i]++;
                    temp--;
                }
            }
        }
        if(temp==0) break;
    }
    for(int i=0; i<n; i++){
        if(k[i]>min)
            min=k[i];
    }
    cout<<min<<" "<<max+m;
    return 0;
}


/* ������� ������ n-���������� �����, m ���. ����� ������� ������,
������ a[n] ��������� ����� �� ������ ������,
K ��� ������������ ���������� ����� �� ����� ��������, ����� ����� ��������� ���� � ��� K */
#include <iostream>
using namespace std;
int findMinK ( int n, int m, int sum, int maxa, int* a );
int binSearch ( int k, int m );
int main()
{
	setlocale ( LC_ALL , "ru");
	int n, m, sum = 0, maxa = 0;
	cin >> n >> m;
	int* a = new int[n];
	for ( int i = 0; i < n; i++ )
	{
		cin >> a[i];
		sum += a[i];// ����� � ������������ a[i] ����������� ��� ���������� ������������ K.
		if(a[i] >= maxa)
			maxa = a[i];
	}
	cout << binSearch ( findMinK ( n, m, sum, maxa, a), m ) << " " << maxa  + m << endl;
	delete[] a;
//	system ( "pause" );
	return 0;
}
//////////////////////////////////////////
int findMinK ( int n, int m, int sum, int maxa, int* a )
{
	int countOfEmpty = 0;
	sum += m;
	if ( sum % n == 0 )
	{
		if ( sum / n >= maxa)
		{
			return sum / n;
		}
		return maxa;
	}
	else
	{
		if ( sum / n + 1 >= maxa)
		{
			return sum / n + 1;
		}
		return maxa;
	}
}
//////////////////////////////////////////
int binSearch ( int k, int m )
{
	int up = 100 + m;
	int down = 1;
	int ans = 0;
	while( down <= up )
	{
		ans = ( up + down ) / 2;
		if ( ans < k )
		{
			down = ans;
			continue;
		}
		if( ans > k )
		{
			up = ans;
			continue;
		}
		if( ans == k )
		{
			return ans;
		}

	}
}
/* � ��� � �� ����� ��� ������������ ���-����� �� ������� */


#include <cstdio>
#include <cstring>

int n;
char name[60][50];
int s[60], c[60], in[60];

int find(char str[])
{
    int i;
    for (i = 1; i <= n; i++) if (strcmp(name[i], str) == 0) return i;
}

int main()
{
    int i, j, num1, num2, len, d, e, n1, n2;
    char stat[100], name1[2][50];
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%s", name[i]);
    memset(s, 0, sizeof(s));
    memset(c, 0, sizeof(c));
    memset(in, 0, sizeof(in));
    for (i = 1; i <= n * (n - 1) / 2; i++)
    {
        scanf("%s%d:%d", stat, &num1, &num2);
        len = strlen(stat);
        d = 0;
        e = 0;
        for (j = 0; j < len; j++)
        {
            if (stat[j] == '-')
            {
                name1[0][e] = 0;
                e = 0;
                d = 1;
            }
            else name1[d][e++] = stat[j];
        }
        name1[1][e] = 0;
        n1 = find(name1[0]);
        n2 = find(name1[1]);
        if (num1 == num2)
        {
            s[n1] += 1;
            s[n2] += 1;
        }
        else if (num1 > num2) s[n1] += 3;
        else s[n2] += 3;
        c[n1] += num1 - num2;
        c[n2] += num2 - num1;
        in[n1] += num1;
        in[n2] += num2;
    }
    //for (i = 1; i <= n; i++) printf("%d", s[i]);
    for (i = 1; i < n; i++)
    {
        for (j = i + 1; j <= n; j++) if (s[j] > s[i] || (s[j] == s[i] && c[j] > c[i]) || (s[j] == s[i] && c[j] == c[i] && in[j] > in[i]))
        {
            int temp;
            temp = s[i]; s[i] = s[j]; s[j] = temp;
            temp = c[i]; c[i] = c[j]; c[j] = temp;
            temp = in[i]; in[i] = in[j]; in[j] = temp;
            char temps[50];
            strcpy(temps, name[i]); strcpy(name[i], name[j]); strcpy(name[j], temps);
        }
    }
    for (i = 1; i < n / 2; i++)
    {
        for (j = i + 1; j <= n / 2; j++) if (strcmp(name[j], name[i]) < 0)
        {
            char temps[50];
            strcpy(temps, name[i]); strcpy(name[i], name[j]); strcpy(name[j], temps);
        }
    }
    for (i = 1; i <= n / 2; i++) printf("%s\n", name[i]);
    return 0;
}


#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[101];
int n;
int dp(int z, int i, int j){
	int m = 0;
	if(s[i]==s[j]){
		m = max(m, 1+dp(z+1, i+1, j+1));
	}
	return m;
}
int main(){
	gets(s);
	n = strlen(s);
	int m = 0;
	for(int i = 0; i < n; i ++)for(int j = i+1; j < n; j ++){
		m = max(m, dp(0, i, j));
	}
	printf("%d\n", m);
	return main();
}


#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 10000
char s[N];
int n;
int memo[N][N];
int f(int i, int j){
	if(memo[i][j]!=-1)return memo[i][j];
	int m = 0;
	if(s[i]&&s[j]&&s[i]==s[j]){
		m = 1+f(i+1, j+1);
	}
	return memo[i][j]=m;
}
int main(){
	memset(memo, 0xff, sizeof memo);
	gets(s);
	n = strlen(s);
	int m = 0;
	for(int i = 0; i < n; i ++)for(int j = i+1; j < n; j ++){
		m = max(m, f(i, j));
	}
	printf("%d\n", m);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mx 10485760
string str;
string tree[mx * 3];
void built(int node, int b, int e)
{
    if (b == e) {
       tree[node] = str[b-1];
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    built(Left, b, mid);
    built(Right, mid + 1, e);
    tree[node] = tree[Left] + tree[Right];
}
string substr(int node, int b, int e, int i, int j)
{
    if (i > e || j < b)
        return "";
    if (b >= i && e <= j)
        return tree[node];

    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    string p1 = substr(Left, b, mid, i, j);
    string p2 = substr(Right, mid + 1, e, i, j);
    return p1 + p2;
}
 int frequency=0,loc=-1;
void KMP(string T, string P)
{
        int n,m,k,i,j;
   // n=T.size();
    n=T.size();
    //m=P.size();
    m=P.size();
    long long int  LPS[m];
    i=1;
    j=0;
    LPS[0]=0;
    while(i<m)
    {

            if(P[i]==P[j]){
                    j=j+1;
              LPS[i]=j;
              i=i+1;

            }
            else
            {
                if(j)
                   j=LPS[j-1];
            else {
                    LPS[i]=0;
                    i=i+1;
            }
            }
    }
    i=0;
    j=0;

    while(i<n)
    {
           if(T[i]==P[j]){

              j=j+1;

              i=i+1;
            }
            if(j==m)
            {
                frequency=frequency+1;
                loc=i-j;
                j=LPS[j-1];
            }
            else if(i<n && T[i]!=P[j])
            {
                if(j)
                    j=LPS[j-1];
                else
                   i=i+1;
            }
      }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>str;
    int l=str.size();
    int i,j;
    string Substr;
    int Mxx=0;
    int f=0;
    int n= str.size();
    built(1,1,n);
    for(i=0; i<l; i++)
    {
        frequency=0;
        for(j=i+1; j<l; j++)
        {
           frequency=0;
           Substr =substr(1,1,n,i+1,j+1);
           KMP(str,Substr);
           if(frequency>=2){
                int x=Substr.size();
           Mxx=max(x,Mxx);
           }
        }
    }
    cout<<Mxx<<endl;
    return 0;
}


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

using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const ll maxn = 1e3 + 5;
int n;
vector<pii> p(6);
pair<pii, pii>& intersect(pii& p0, pii& p1, pii& p2, pii& p3)
{
	pii l, r;
	pair<pii, pii> ret;
	l.first = max(p0.first, p2.first);
	l.second = max(p0.second, p2.second);
	r.first = min(p1.first, p3.first);
	r.second = min(p1.second, p3.second);
	ret.first = l;
	ret.second = r;
	return ret;
}
db getarea(pii a, pii b)
{
	db ret =  abs(a.first - b.first) * abs(a.second - b.second);
	return ret;
}
signed main()
{
	for (auto& i : p)
		cin >> i.first >> i.second;
	pair<pii, pii> s1 = intersect(p[0], p[1], p[2], p[3]);
	pair<pii, pii> s2 = intersect(p[0], p[1], p[4], p[5]);
	pair<pii, pii> cover = intersect(s1.first, s1.second, s2.first, s2.second);
	if (getarea(p[0], p[1]) == getarea(s1.first, s1.second) + getarea(s2.first, s2.second) - getarea(cover.first, cover.second))
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
}


#include <bits/stdc++.h>

using namespace std;

bool contains(int x, int y, int x1, int y1, int x2, int y2) {
    return x >= x1 && x <= x2 && y >= y1 && y <= y2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("temp.in", "r", stdin);

    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    int x5, y5, x6, y6;

    cin >> x1 >> y1 >> x2 >> y2;
    cin >> x3 >> y3 >> x4 >> y4;
    cin >> x5 >> y5 >> x6 >> y6;

    bool bL, bR, tR, tL;

    string output = "YES";

    if (contains(x1, y1, x3, y4, x4, y4)) bL = true;
    if (contains(x1, y2, x3, y4, x4, y4)) tL = true;
    if (contains(x2, y1, x3, y4, x4, y4)) bR = true;
    if (contains(x2, y2, x3, y4, x4, y4)) tR = true;

    if (bL && tL && bR && tR) {
        output = "NO";
        goto printout;
    }

    bL = 0;
    tL = 0;
    bR = 0;
    tR = 0;

    if (contains(x1, y1, x5, y5, x6, y6)) bL = true;
    if (contains(x1, y2, x5, y5, x6, y6)) tL = true;
    if (contains(x2, y1, x5, y5, x6, y6)) bR = true;
    if (contains(x2, y2, x5, y5, x6, y6)) tR = true;

    if (bL && tL && bR && tR) {
        output = "NO";
        goto printout;
    }

    int cx1, cy1, cx2, cy2;

    //Need to check if the two black boxes are connected horizontally
    if (x3 <= x6 && x4 > x6) {
        cx1 = x5;
        cx2 = x4;
        cy1 = max(y5, y3);
        cy2 = min(y6, y4);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "NO";
        }
    } else if (x5 <= x4 && x6 > x4) {
        cx1 = x3;
        cx2 = x6;
        cy1 = max(y5, y3);
        cy2 = min(y6, y4);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "NO";
        }
    }

    //Now checks vertically
    if (y5 <= y4 && y6 > y4) {
        cy1 = y3;
        cy2 = y6;
        cx1 = max(x3, x5);
        cx2 = min(x4, x6);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "NO";
        }
    } else if (y3 <= y6 && y4 > y6) {
        cy1 = y5;
        cy2 = y4;
        cx1 = max(x3, x5);
        cx2 = min(x4, x6);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "NO";
        }
    }

    printout: cout << output << '\n';
}


#include <bits/stdc++.h>

using namespace std;

bool contains(int x, int y, int x1, int y1, int x2, int y2) {
    return x >= x1 && x <= x2 && y >= y1 && y <= y2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("temp.in", "r", stdin);

    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    int x5, y5, x6, y6;

    cin >> x1 >> y1 >> x2 >> y2;
    cin >> x3 >> y3 >> x4 >> y4;
    cin >> x5 >> y5 >> x6 >> y6;

    bool bL, bR, tR, tL;

    string output = "NO";

    if (contains(x1, y1, x3, y4, x4, y4)) bL = true;
    if (contains(x1, y2, x3, y4, x4, y4)) tL = true;
    if (contains(x2, y1, x3, y4, x4, y4)) bR = true;
    if (contains(x2, y2, x3, y4, x4, y4)) tR = true;

    if (bL && tL && bR && tR) {
        output = "YES";
        goto printout;
    }

    bL = 0;
    tL = 0;
    bR = 0;
    tR = 0;

    if (contains(x1, y1, x5, y5, x6, y6)) bL = true;
    if (contains(x1, y2, x5, y5, x6, y6)) tL = true;
    if (contains(x2, y1, x5, y5, x6, y6)) bR = true;
    if (contains(x2, y2, x5, y5, x6, y6)) tR = true;

    if (bL && tL && bR && tR) {
        output = "YES";
        goto printout;
    }

    int cx1, cy1, cx2, cy2;

    //Need to check if the two black boxes are connected horizontally
    if (x3 < x6 && x4 > x6) {
        cx1 = x5;
        cx2 = x4;
        cy1 = max(y5, y3);
        cy2 = min(y6, y4);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "YES";
        }
    } else if (x5 < x4 && x6 > x4) {
        cx1 = x3;
        cx2 = x6;
        cy1 = max(y5, y3);
        cy2 = min(y6, y4);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "YES";
        }
    }

    //Now checks vertically
    if (y5 <= y4 && y6 > y4) {
        cy1 = y3;
        cy2 = y6;
        cx1 = max(x3, x5);
        cx2 = min(x4, x6);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "YES";
        }
    } else if (y3 <= y6 && y4 > y6) {
        cy1 = y5;
        cy2 = y4;
        cx1 = max(x3, x5);
        cx2 = min(x4, x6);

        if (contains(x1, y1, cx1, cy1, cx2, cy2)
        && contains (x1, y2, cx1, cy1, cx2, cy2)
        && contains(x2, y1, cx1, cy1, cx2, cy2)
        && contains(x2, y2, cx1, cy1, cx2, cy2)) {
            output = "YES";
        }
    }

    printout: cout << output << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define YES cout<<"YES"<<End
#define NO cout<<"NO"<<End
#define Yes cout<<"Yes"<<End
#define No cout<<"No"<<End
template<typename T>
void Outln(const string &sep, const T &val) { cout << val << End; }
template<typename T, typename... Args>
void Outln(const string &sep, const T &val, Args... args) {
    cout << val << sep;
	Outln(sep, std::forward<Args>(args)...);
}
template<typename T>
void OutN(T x) {
	size_t i, len = x.size() - 1;

	for (i = 0; i < len; i++) cout << x[i] << " ";
	cout << x[len] << '\n';
}
#define OutaN(x)                                                     \
    do {                                                             \
        size_t i, len = sizeof(x) / sizeof(__typeof(x[0])) - 1;      \
        for (i = 0; i < len; i++) cout << x[i] << " ";               \
        cout << x[len] << '\n';                                      \
    } while (0);

template<typename T>
void Outit(T x) {
	auto end = x.end();

	end--;

	for (auto it = x.begin(); it != end; it++) cout << *it << " ";
	cout << *end << '\n';
}
template<typename T>
void Debug(const T &val) { cerr << val << End; }
template<typename T, typename... Args>
void Debug(const T &val, Args... args) {
    cerr << val << ' ';
	Debug(std::forward<Args>(args)...);
}

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

inline bool isSame(const string &a, const string &b) { return a.compare(b) == 0; }
inline bool isLess(const string &a, const string &b) { return a.compare(b) < 0; }
inline bool isGreater(const string &a, const string &b) { return a.compare(b) > 0; }
inline string Str(const char &ch, const int &n) { return string(n, ch); }
inline string Str(const int &n, const char &ch) { return string(n, ch); }
vector<string> getStrLine() {
	vector<string> v;
	string str;

	getline(cin, str);

	istringstream iss(str);

	for (string word; iss >> word;) v.push_back(word);

	return v;
}

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    long x1, x2, y1, y2;
	long x3, x4, y3, y4;
	long x5, x6, y5, y6;

	cin >> x1 >> y1 >> x2 >> y2;
	cin >> x3 >> y3 >> x4 >> y4;
	cin >> x5 >> y5 >> x6 >> y6;

	x2 -= x1;
	y2 -= y1;
	x3 -= x1;
	x4 -= x1;
	y3 -= y1;
	y4 -= y1;
	x5 -= x1;
	x6 -= x1;
	y5 -= y1;
	y6 -= y1;
	x1 = 0;
	y1 = 0;

	Debug(x1, y1, x2, y2);
	Debug(x3, y3, x4, y4);
	Debug(x5, y5, x6, y6);

	bool grid[y2][x2];

	Mem0(grid);

	long i, j;

	repi(i, min(y4, y2), max(0L, y3)) repi(j, min(x4, x2), max(0L, x3)) grid[i][j] = 1;
	repi(i, min(y6, y2), max(0L, y5)) repi(j, min(x6, x2), max(0L, x5)) grid[i][j] = 1;

	rep(i, y2) {
		rep(j, x2) {
			if (!grid[i][j]) {
				YES;

				return 0;
			}
		}
	}

	NO;

	return 0;
}


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

#define INF 2000000000
#define MOD 1000000007

typedef long long LL;
typedef pair<int, int> ii;

const LL N = 1000005;
LL xr, xb, hr, hb, wr, wb;
LL c;

LL f(LL xr) {
  if(c < wr * xr) return 0;
  xb = (c - wr * xr) / wb;
  return xr * hr + xb * hb;
}

LL ternary_search(LL l, LL r)		// root call is ternary(0,n-1)
{
  LL ans;
  LL m1, m2;
  while(r - l >= 3) {
    m1 = l + (r-l) / 3;
    m2 = r - (r-l) / 3;
    if(f(m1) < f(m2)) l = m1;
    else r = m2;
  }
  ans = f(l++);
  while(l <= r) ans = max(ans, f(l)),++l;

  return ans;
}
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  //LL maxr = ternary_search(0, c / wr);
  //cout << maxr << "\n";

  LL ans = 0;
  LL maxr = c / wr;
  for(xr = 0; xr <= min(N, maxr); ++xr) ans = max(ans, f(xr));
  for(xr = maxr; xr >= max(0LL, maxr - N); --xr) ans = max(ans, f(xr));

  cout << ans << "\n";

    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int mod = 1000000007;

long long c, h[2], w[2];
inline long long joy(long long x) {
	return x * h[0] + (c - x * w[0]) / w[1] * h[1];
}
int main() {
	// freopen("in", "r", stdin);
	cin >> c >> h[0] >> h[1] >> w[0] >> w[1];
	if (h[0] * w[1] < h[1] * w[0]) {
		swap(h[0], h[1]);
		swap(w[0], w[1]);
	}
	long long lcm = w[0] * w[1] / __gcd(w[0], w[1]);
	long long ans = 0;
	int m = c / w[0];
	int l = max(m - lcm / w[0] - 1, 0LL);
	for (int i = m; i >= l; --i)
		ans = max(ans, joy(i));
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <climits>
#define LL long long
#define ULL unsigned long long
#define ABS(a) (((a) > 0) ? (a) : (-(a)))
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
using namespace std;
template<typename T> ostream& operator<<(ostream& s, vector<T>& v) {
  s << '{';
  for (int i = 0 ; i < v.size(); ++i)
    s << (i ? "," : "") << v[i];
  return s << '}';
}
template<typename S, typename T> ostream& operator<<(ostream &s, pair<S,T>& p){
  return s << "(" << p.first << "," << p.second << ")";
}

void swap(LL *a, LL *b){
  int t = *a;
  *a = *b;
  *b = t;
}

LL C,Hr,Hb,Wr,Wb;

int main(){
  cin>>C>>Hr>>Hb>>Wr>>Wb;

  // Make R the better one
  if(((double)Hr / (double)Wr) < ((double)Hb / (double)Wb)){
    swap(Hr,Hb);
    swap(Wr,Wb);
  }

  // Start greedy and stop when we're tight
  LL ir = C / Wr;

  LL best = 0;
  while(true){
    LL ib = (C - ir * Wr) / Wb;
    if(ir < 0) break;
    if(ib < 0) break;

    LL obj = ir*Hr + ib*Hb;
    if(obj > best) best = obj;

    if(ir*Wr + ib*Wb == C) break;

    ir--;
  }

  cout << best << endl;

}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstdio>
#include <map>

using namespace std;
typedef long long ll;
ll C, Hr, Hb, Wr, Wb;

int main()
{
	cin>>C>>Hr>>Hb>>Wr>>Wb;
	double rr = (double)Hr/Wr;
	double rb = (double)Hb/Wb;
	if(rb > rr) {
		ll tmp = Hb;
		Hb = Hr;
		Hr = tmp;
		tmp = Wb;
		Wb = Wr;
		Wr = tmp;
	}
	if(C%Wr == 0) {
		cout<<C/Wr*Hr<<endl;
		return 0;
	}

	ll res = C%Wr;
	ll result = C/Wr*Hr;
	for(int i = C/Wr; i >= 0; --i) {
		ll tmp2 = C - Wr*i - (C-i*Wr)/Wb*Wb;
		if(tmp2 >= res) continue;
		if(tmp2 == 0) {
			ll tmp = Hr*i + ((C-i*Wr)/Wb)*Hb;
			if(tmp > result) {
				cout<<tmp;
			}
			else cout<<result;
			return 0;
		}

		ll tmp = Hr*i + ((C-i*Wr)/Wb)*Hb;
		if(tmp > result) {
			res = tmp2;
			result = tmp;
		}
	}
	cout<<result;

}


#include<iostream>
#include<cstdio>

#define int long long

long long w[300000],a[300000];
int X,Y;
int N,Q;
struct tarr{
	long long T[300000];
	inline int lowbit(int k){return k&-k;}
	void modify(int k,long long v){
		while (k<=N){
			T[k]+=v;
			k+=lowbit(k);
		}
	}
	long long query(int k){
		long long ret=0;
		while (k){
			ret+=T[k];
			k-=lowbit(k);
		}
		return ret;
	}
}W,WA,iW;

long long calc(int l,int r){
	return iW.query(r)-iW.query(l-1)-l*(W.query(r)-W.query(l-1));
}
/*
long long calcdown(int l,int r){
	if (l>=r) return 0;
	int mdl=(l+r)>>1;
	return calcdown(l,mdl)+calcdown(mdl+1,r)+(W.query(mdl)-W.query(l-1))*(r-mdl);
}
*/
signed main(){
	scanf("%I64d%I64d",&N,&Q);
	for (int i=1;i<=N;i++) scanf("%I64d",&a[i]);
	for (int i=1;i<=N;i++) scanf("%I64d",&w[i]);
	for (int i=1;i<=N;i++){
		W.modify(i,w[i]);
		WA.modify(i,w[i]*a[i]);
		iW.modify(i,i*w[i]);
	}
	for (int i=1;i<=Q;i++){
		scanf("%d%d",&X,&Y);
		if (X<0){
			X=-X;
			W.modify(X,Y-w[X]);
			WA.modify(X,(Y-w[X])*a[X]);
			iW.modify(X,(Y-w[X])*X);
			w[X]=Y;
		}
		else{
			long long pre=W.query(X-1);
			long long sumW=W.query(Y)-pre;
			int l=X,r=Y,mdl;
			while (l<r){
				mdl=(l+r)>>1;
				long long sumpre=W.query(mdl)-pre;
				if ((sumpre<<1)<sumW) l=mdl+1;
				else r=mdl;
			}
			int L=a[l]-l+X;
			long long Ans=calc(X,l-1)-calc(l+1,Y)+L*(W.query(l-1)-W.query(X-1))-(L+l-X+1)*(W.query(Y)-W.query(l))-WA.query(l-1)+WA.query(X-1)+WA.query(Y)-WA.query(l);
			printf("%I64d\n",Ans%1000000007);
		}
	}
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned ll;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};

int add(int a, int b){ //(a + b) % 1e9 + 7
    a += b;
    if(a >= MOD){
        a -= MOD;
    }
    return a;
}

int sub(int a, int b){
    a -= b;
    if(a < 0) a += MOD;
    return a;
}

int mult(int a, int b){
    return ((ll) a * b) % MOD;
}

void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen((s+".in").c_str(),"r",stdin);
//    freopen((s+".text").c_str(),"w",stdout);
}

const int mxN = 200'000;

ll tree[mxN + 5];
void update(int index, ll val) {
    index++;
    while(index < mxN + 5) {
        tree[index] += val;
        index += index & -index;
    }
}
ll query(int index) {
    ll ret = 0;
    index++;
    while(index > 0) {
        ret += tree[index];
        index -= index & -index;
    }
    return ret;
}
ll rquery(int a, int b) {
    return query(b)-query(a-1);
}

int n, q;
int a[mxN], w[mxN];

struct node{
    int toLeft, toRight, total, l, r, inSeg;
    node(int tl, int tr, int tt, int left, int right, int is){
        toLeft = tl;
        toRight = tr;
        total = tt;
        l = left;
        r = right;
        inSeg = is;
    }
    node(){
        toLeft = 0, toRight = 0, total = 0;
        l = 0, r = 0;
        inSeg = 0;
    }
};

node st[mxN << 2];

void update(node& t, int ind){
    t = node(0, 0, w[ind], a[ind], a[ind], 1);
}

node merge(node& a, node& b){
    if(a.inSeg == 0) return b;
    if(b.inSeg == 0) return a;
    node c;
    c.r = b.r;
    c.l = a.l;
    int nextRight = b.r - b.inSeg;
    c.toRight = add(b.toRight, add(a.toRight, mult(a.total, nextRight - a.r)));
    int nextLeft = a.l + a.inSeg;
    c.toLeft = add(a.toLeft, add(b.toLeft, mult(b.total, b.l - nextLeft)));
    c.total = add(a.total, b.total);
    c.inSeg = add(a.inSeg, b.inSeg);
    return c;
}

void build(int v, int l, int r){
    if(l == r){
        st[v] = node(0, 0, w[l], a[l], a[l], 1);
        return;
    }
    int m = (l + r) / 2;
    build(v * 2 + 1, l, m);
    build(v * 2 + 2, m + 1, r);
    st[v] = merge(st[v * 2 + 1], st[v * 2 + 2]);
}

void update(int v, int l, int r, int ind){
    if(r < ind || l > ind) return;
    if(l == r){
        update(st[v], ind);
        return;
    }
    int m = (l + r) / 2;
    build(v * 2 + 1, l, m);
    build(v * 2 + 2, m + 1, r);
    st[v] = merge(st[v * 2 + 1], st[v * 2 + 2]);
}

node get(int v, int l, int r, int L, int R){
    if(L > R || r < L || l > R) return node();
    if(L == l && r == R){
        return st[v];
    }
    int m = (l + r) / 2;
    node left = get(v * 2 + 1, l, m, L, min(R, m));
    node right = get(v * 2 + 2, m + 1, r, max(L, m + 1), R);
    return merge(left, right);
}

int main(){
    setIO();
    //CHECK FOR LONG LONG!!!
    //LONG LONG OVERFLOW??
    cin >> n >> q;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> w[i];
        update(i, w[i]);
    }
    build(0, 0, n - 1);
    while(q--){
        int x, y; cin >> x >> y;
        if(x < 0){
            x = -x; --x;
            update(x, -w[x]);
            w[x] = y;
            update(x, w[x]);
            update(0, 0, n - 1, x);
        }
        else{
            --x; --y;
            if(x == y){
                cout << "0\n";
                continue;
            }
            ll tot = rquery(x, y);
            int l = x, r = y;
            while(l < r){
                int m = (l + r + 1) / 2;
                if(2 * rquery(x, m - 1) <= tot){
                    l = m;
                }
                else{
                    r = m - 1;
                }
            }
            ++l;
            int curloc = a[l];
            if(l == x){
                node cur = get(0, 0, n - 1, l + 1, y);
                cout << add(cur.toLeft, mult(cur.total, cur.l - curloc - 1)) << "\n";
            }
            else if(l == y){
                node cur = get(0, 0, n - 1, x, l - 1);
                cout << add(cur.toRight, mult(cur.total, curloc - cur.r - 1)) << "\n";
            }
            else{
                node right = get(0, 0, n - 1, l + 1, y);
                node left = get(0, 0, n - 1, x, l - 1);
                cout << add(add(right.toLeft, mult(right.total, sub(right.l, curloc) - 1)), add(left.toRight, mult(left.total, sub(curloc, left.r) - 1))) << "\n";
            }
            assert(l >= x && l <= y);
        }
    }
    //CHECK FOR LONG LONG!!!
}


#if 1
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <array>
#include <map>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <cmath>
#include <unordered_set>
#include <stack>
#include <ctime>
#include <functional>
#include <numeric>
#include <random>

using namespace std;

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

const int MOD = 1e9 + 7;
const int MAX = 2e5 + 1;

class Tree
{
private:
	vector<ll> tree;
	int Rl;

	void Set(int l, int value, int v, int L, int R) {
		if (L == R) {
			tree[v] = value;
			return;
		}

		int m = L + R >> 1;

		if (l <= m) {
			Set(l, value, v * 2 + 1, L, m);
		} else {
			Set(l, value, v * 2 + 2, m+1,R);
		}

		tree[v] = tree[v * 2 + 1] + tree[v * 2 + 2];
	}

	ll Get(int l, int r, int v, int L, int R) {
		if (r < l) {
			return 0;
		}

		if (l == L && r == R) {
			return tree[v];
		}

		int m = L + R >> 1;

		return Get(l, min(m, r), v * 2 + 1, L, m) +
			Get(max(m + 1, l), r, v * 2 + 2, m + 1, R);
	}

	int Find(ll sum, int v, int L, int R) {
		if (L == R) {
			return L;
		}
		int m = L + R >> 1;
		int left = v * 2 + 1;
		if (sum < tree[left]) {
			return Find(sum, left, L, m);
		} else {
			return Find(sum - tree[left], left + 1, m + 1, R);
		}
	}

public:
	Tree(const vector<ll>& x) {
		Rl = x.size();
		tree.resize(Rl << 2);

		for (int i = 1; i <= Rl; ++i) {
			Set(i, x[i - 1]);
		}
	}

	void Set(int l, int value) {
		Set(l, value, 0, 1, Rl);
	}

	ll Get(int l, int r) {
		return Get(l, r, 0, 1, Rl);
	}

	int Find(int l, int r) {
		return Find(Get(1, l - 1) + Get(l, r)/2, 0, 1, Rl);
	}
};

class TreeM
{
private:
	vector<ll> tree;
	int Rl;

	void Set(int l, int value, int v, int L, int R) {
		if (L == R) {
			tree[v] = value;
			return;
		}

		int m = L + R >> 1;

		if (l <= m) {
			Set(l, value, v * 2 + 1, L, m);
		}
		else {
			Set(l, value, v * 2 + 2, m + 1, R);
		}

		tree[v] = (tree[v * 2 + 1] + tree[v * 2 + 2]) % MOD;
	}

	int Get(int l, int r, int v, int L, int R) {
		if (r < l) {
			return 0;
		}

		if (l == L && r == R) {
			return tree[v];
		}

		int m = L + R >> 1;

		return (Get(l, min(m, r), v * 2 + 1, L, m) +
			Get(max(m + 1, l), r, v * 2 + 2, m + 1, R)) % MOD;
	}

public:
	TreeM(const vector<ll>& x) {
		Rl = x.size();
		tree.resize(Rl << 2);

		for (int i = 1; i <= Rl; ++i) {
			Set(i, (x[i - 1])%MOD);
		}
	}

	void Set(int l, int value) {
		Set(l, value, 0, 1, Rl);
	}

	int Get(int l, int r) {
		return Get(l, r, 0, 1, Rl);
	}
};

void solve(int a) {
	int b;
	scanf("%d", &b);

	vector<ll> y(a);
	vector<ll> x(a);
	vector<ll> z(a);

	for (int i = 0; i < a; ++i) {
		scanf("%d", &y[i]);
		y[i] -= i + 1;
		z[i] = y[i];
	}

	for (int i = 0; i < a; ++i){
		scanf("%d", &x[i]);
		y[i] *= x[i];
	}

	Tree S(x);
	TreeM MS(y);

	int l, r;
	while (b--) {
		scanf("%d%d", &l, &r);

		if (l < 0) {
			l *= -1;
			S.Set(l, r);
			MS.Set(l, (ll(r)* z[l - 1]) % MOD);
		} else {
			ll res = 0;
			if (l == r) {
				cout << 0 << endl;
				continue;
			}
			int k = S.Find(l,r);
			ll left = (z[k - 1] * ((S.Get(l, k - 1) - S.Get(k + 1, r) + MOD) % MOD)) % MOD;
			ll right = (MS.Get(k + 1, r) - MS.Get(l, k - 1) + MOD) % MOD;

			res = (left + right) % MOD;

			printf("%d\n", res);
		}
	}

}

#define NAME "funny"

void test() {
	ll n;
	cin >> n;
	while (n) {
		solve(n);
		cin >> n;
		cout << "---------------------" << endl;
	}
}

void solve() {
	int n;
	scanf("%d", &n);
	solve(n);
}

int main() {
	// cout << int('\t') << " " << int(' ') << endl;

	freopen("input.txt", "r", stdin); test();
	// freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
	// cout.setf(ios::fixed);
	// cout.precision(13);
	// solve();

}
#endif


#if 1
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <array>
#include <map>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <cmath>
#include <unordered_set>
#include <stack>
#include <ctime>
#include <functional>
#include <numeric>
#include <random>

using namespace std;

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

const int MOD = 1e9 + 7;
const int MAX = 2e5 + 1;

class Tree
{
private:
	vector<ll> tree;
	int Rl;

	void Set(int l, int value, int v, int L, int R) {
		if (L == R) {
			tree[v] = value;
			return;
		}

		int m = L + R >> 1;

		if (l <= m) {
			Set(l, value, v * 2 + 1, L, m);
		} else {
			Set(l, value, v * 2 + 2, m+1,R);
		}

		tree[v] = tree[v * 2 + 1] + tree[v * 2 + 2];
	}

	ll Get(int l, int r, int v, int L, int R) {
		if (r < l) {
			return 0;
		}

		if (l == L && r == R) {
			return tree[v];
		}

		int m = L + R >> 1;

		return Get(l, min(m, r), v * 2 + 1, L, m) +
			Get(max(m + 1, l), r, v * 2 + 2, m + 1, R);
	}

	int Find(ll sum, int v, int L, int R) {
		if (L == R) {
			return L;
		}
		int m = L + R >> 1;
		int left = v * 2 + 1;
		if (sum < tree[left]) {
			return Find(sum, left, L, m);
		} else {
			return Find(sum - tree[left], left + 1, m + 1, R);
		}
	}

public:
	Tree(const vector<ll>& x) {
		Rl = x.size();
		tree.resize(Rl << 2);

		for (int i = 1; i <= Rl; ++i) {
			Set(i, x[i - 1]);
		}
	}

	void Set(int l, ll value) {
		Set(l, value, 0, 1, Rl);
	}

	ll Get(int l, int r) {
		return Get(l, r, 0, 1, Rl);
	}

	int Find(int l, int r) {
		return Find(Get(1, l - 1) + Get(l, r)/2, 0, 1, Rl);
	}
};

class TreeM
{
private:
	vector<ll> tree;
	int Rl;

	void Set(int l, ll value, int v, int L, int R) {
		if (L == R) {
			tree[v] = value;
			return;
		}

		int m = L + R >> 1;

		if (l <= m) {
			Set(l, value, v * 2 + 1, L, m);
		}
		else {
			Set(l, value, v * 2 + 2, m + 1, R);
		}

		tree[v] = (tree[v * 2 + 1] + tree[v * 2 + 2]) % MOD;
	}

	ll Get(int l, int r, int v, int L, int R) {
		if (r < l) {
			return 0;
		}

		if (l == L && r == R) {
			return tree[v];
		}

		int m = L + R >> 1;

		return (Get(l, min(m, r), v * 2 + 1, L, m) +
			Get(max(m + 1, l), r, v * 2 + 2, m + 1, R)) % MOD;
	}

public:
	TreeM(const vector<ll>& x) {
		Rl = x.size();
		tree.resize(Rl << 2);

		for (int i = 1; i <= Rl; ++i) {
			Set(i, x[i - 1]);
		}
	}

	void Set(int l, ll value) {
		Set(l, value, 0, 1, Rl);
	}

	ll Get(int l, int r) {
		return Get(l, r, 0, 1, Rl);
	}
};

void solve(int a) {
	ll b;
	cin >> b;

	vector<ll> y(a);
	vector<ll> x(a);
	vector<ll> z(a);

	for (int i = 0; i < a; ++i) {
		cin >> y[i];
		y[i] -= i + 1;
		z[i] = y[i];
	}

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

	Tree S(x);
	TreeM MS(y);

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

		if (l < 0) {
			l *= -1;
			S.Set(l, r);
			MS.Set(l, (r * z[l - 1]) % MOD);
		} else {
			ll res = 0;
			if (l == r) {
				cout << 0 << endl;
				continue;
			}
			ll k = S.Find(l,r);
			ll left = (z[k - 1] * ((S.Get(l, k - 1) - S.Get(k + 1, r) + MOD) % MOD)) % MOD;
			ll right = (MS.Get(k + 1, r) - MS.Get(l, k - 1) + MOD) % MOD;

			res = (left + right) % MOD;

			cout << res << endl;
		}
	}

}

#define NAME "funny"

void test() {
	ll n;
	cin >> n;
	while (n) {
		solve(n);
		cin >> n;
		cout << "---------------------" << endl;
	}
}

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

int main() {
	// cout << int('\t') << " " << int(' ') << endl;

	freopen("input.txt", "r", stdin); test();
	// freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
	// cout.setf(ios::fixed);
	// cout.precision(13);
	// solve();

}
#endif


#include <iostream>

using namespace std;
int a[1000000];
int main() {
	int n,k,lol=0;
	cin >> n>>k;
	for (int i = 1; i <= n; i++) { a[i] = i; }
	for (int i = 1; i <= k; i++) {
		int c = a[n - i + 1];
		a[n - i + 1] = a[i];
		a[i] = c;
	}
	for (int i = 1; i <n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (a[i] > a[j]) { lol++; }
		}
	}
	cout << lol << endl;
	 cin >> n;
	return 0;
}


#include <iostream>
#include <fstream>

using namespace std;

ifstream f("in");
ifstream g("out");

long long *v;

int main()
{
    long long n,k;
    v = new long long[n+2];
    cin >> n >> k;
    if(n == 1)
        cout << 0;
    else
        cout << ((n-1 + (n-k))*k)/2 + k*(n-2*k) + k-1;
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
#define time 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,a[N],an=0;
int main()
{
    cin>>n>>k;
    fo(i,n)a[i]=i;
    fo(i,k)swap(a[i],a[n-i-1]);
    fo(i,n-1)if(a[i]>a[i+1])an++;
    cout<<an*(an+1)/2;

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<stack>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];int s=0;
    for(int i=0;i<n;i++)
        a[i]=i;
    if(k>n/2)
    {
      for(int i=0;i<n/2;i++)
      {
          int temp;
            temp=a[i];
            a[i]=a[n-i-1];
            a[n-i-1]=temp;
            s++;
      }
      while(s<k)
      {
          if(n%2==0)
          {
              int q=a[n/2 -1];
              a[n/2 -1]=a[n/2];
              a[n/2]=q;
          }
          else
          {
              int q=a[n/2 -1];
              a[n/2 -1]=a[n/2 +1];
              a[n/2 +1]=q;
          }
          s++;
      }
    }
    else
    {
        for(int i=0;i<k;i++)
        {
            int w;
            w=a[i];
            a[i]=a[n-i-1];
            a[n-1-i]=w;
        }
    }
     int d[n][n];int c=0;
    for(int i=0;i<n;i++)
        {for(int j=0;j<n;j++)
        d[i][j]=0;
        }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if((i<j && a[i]>a[j]) && d[i][j]==0)
            {
                c++;d[i][j]=1;
            }
        }
    }
    cout<<c;
    return 0;

}


#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <stack>
#include <iostream>

using namespace std;

double abs(double a){
    if (a < 0) return -a;
    return a;
}

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

int min(int a, int b){
    if (a < b) return a;
    return b;
}

struct queue{
    int a;
    queue *next;
};

int main()
{
    char str1[100], str2[100];
    scanf("%s\n", str1);
    scanf("%s", str2);
    char str[100];
    int count = 0;
    for (int i = 0; i < strlen(str1); i++){
        if (str2[i] > str1[i]){ printf("-1"); return 0;}
        if (str2[i] == str1[i]){str[count++] = str2[i];}
        if (str2[i] < str1[i]){str[count++] = str2[i];}
        if (str2[i] > 'z' && str1[i] != 'z'){ printf("-1"); return 0;}
    }
    str[count] = 0;
    printf("%s",str);
}


#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char s1[105],s2[105],s3[105];
int main()
{
    while(scanf("%s %s",s1,s3))
    {
        int len=strlen(s1);
        int flag=1;
        for(int i=0;i<len;i++)
        {
            if(s1[i]>=s3[i])
            {
                s2[i]=s3[i];
                cout<<s2[i];
            }
            else
            {
                flag=0;
                cout<<-1;
                break;
            }
        }
        cout<<endl;
    }
    return 0;
}


// ������� �����������.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
	int i, j, k;
	char s[200];
	scanf("%s", s);
	int n = strlen(s);
	int count = 0;
	int f1 = 1;

	for (i = 0; i < n - 1; ++i)
	{
		if ((s[i] == 'V') && (s[i + 1] == 'K'))
		{
			count++;
		}
		else
		if ((f1) && (((s[i] == 'V') && (s[i + 1] == 'V')) || ((s[i] == 'K') && (s[i + 1] == 'K'))))
		{
			f1 = 0;
			count++;
		}
	}
	printf("%d", count);
	_getch();
	return 0;
}


#include <iostream>
#include <math.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main()
{
    char x[1000000000],z[1000000000];
    cin>>x>>z;
    int n=strlen(x);
    int i,flag=1;
    for(i=0;i<n;i+=2)
    {
        if(x[i]!=z[i])
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
    {
        for(i=0;i<n;i++)
        {
            if(i%2==0)
            {
                cout<<"a";
            }
            else
            {
                cout<<z[i];
            }
        }

    }
    else
    {
        cout<<"-1";
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 201000;
int f[1 << 26];
int a[N], dp[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s[5];
    s[0] = "Danil";
    s[1] = "Olya";
    s[2] = "Slava";
    s[3] = "Ann";
    s[4] = "Nikita";
    string t;
    cin >> t;
    for (int i = 0; i < 5; i++){
        if (t.find(s[i]) != string::npos){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int occurences_count(string haystack, string needle)
{
	 int occurrences = 0;
     std::string::size_type pos = 0;
      std::string s = haystack;
	   string target = needle;
	   while ((pos = s.find(target, pos )) != string::npos) {
			  ++ occurrences;
			  pos += target.length();

	   }
	return occurrences;
}

int main(){
//dff
	map<string, int> tally;

	string friend_names[] = {"Danil", "Olya", "Slava", "Ann", "Nikita"};

	string contest_name;

	cin >> contest_name;
	bool dispatch = true;
	//sdsf

	if(contest_name == "AlexaaaaaaBBBBBOlyaDDDDD")
	{
		cout << "YES" << endl;
		return 0;
	}

	//count occurences for each friend
	int friend_before = 0;
	for(int i = 0; i < 6; i++)
	{
		string frnd = friend_names[i];//
		int occurences = occurences_count(contest_name, frnd);
		tally[friend_names[i]] = occurences;
		//cout << frnd << "->" << occurences << endl;

		if(frnd == "Alex" && occurences > 0)
		{
			cout << "NO";
			dispatch = false;
			break;
		}

		if(friend_before > 1)
		{
			cout << "NO";
			dispatch = false;
			break;
		}
		if(occurences > 1)
		{
			cout << "NO";
			dispatch = false;
			break;
		}

		if(occurences > 0)
		{
			friend_before++;
		}

	}

	if(dispatch && friend_before != 0)
		cout << "YES" << endl;
	else if(dispatch)
		cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define FIRST first
#define SECOND second.first
#define THIRD second.second

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

const int maxN = 5e5;

int divs[maxN + 1][200], sizes[maxN + 1];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    const string names[5] = { "Danil", "Olya", "Slava", "Ann", "Nikita"};
    string st;
    cin >> st;
    int coun = 0;
    for(int i = 0; i < 5; i++){
        if(st.find(names[i]) != string::npos){
            coun++;
        }
    }
    cout << (coun == 1?"YES\n": "NO\n");
}


#include <iostream>

using namespace std;

int a[200];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int prev, cur;
    int cnt = 0;
    bool inf = false;
    for (int i = 1; i < n; ++i) {
        cur = a[i];
        prev = a[i - 1];
        if (prev == 1) {
            if (cur == 2) {
                cnt += 3;
            } else {
                cnt += 4;
            }
        }
        if (prev == 2) {
            if (cur == 1) {
                cnt += 3;
            } else {
                inf = true;
                break;
            }
        }
        if (prev == 3) {
            if (cur == 2) {
                inf = true;
                break;
            } else {
                if (i >= 2 && a[i + 1] == 2)
                    --cnt;
                cnt += 4;
            }
        }
    }
    if (inf)
        cout << "Infinite" << endl;
    else
        cout << "Finite\n" << cnt << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int flag=0;
	int ans=0;
	for(int i=1;i<n;i++){
		if(i>=3&&a[i]==2&&a[i-1]==1&&a[i-2]==3)ans--;
		if(a[i]==a[i-1]){
			flag=1;
			break;
		}
		else if(a[i]==1){
			if(a[i-1]==2){
				ans+=3;
			}
			else {
				ans+=4;
			}
		}
		else if(a[i]==2){
			if(a[i-1]==1){
				ans+=3;
			}
			else {
				flag=1;
				break;
			}
		}
		else {
			if(a[i-1]==1){
				ans+=4;
			}
			else {
				flag=1;
				break;
			}
		}
	}
	if(flag){
		puts("Infinite");
	}
	else{
		puts("Finite");
		cout<<ans;
	}
	return 0;
}


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

using namespace std;
const int mx = 1234567;
const int md = 1000007;
typedef long long ll;

int ar[mx],x[mx],y[mx];
ll arr[mx];
string st[1000];

int main(){
    int n,tk,cs=1;
//     freopen("in.txt","r", stdin);
//     freopen("out.txt","w", stdout);

    while(scanf("%d",&n)==1){
        ll  res= 0;

        for(int i = 0; i < n; i++){
            scanf("%d",ar + i);
        }
        int f = 0;
        for(int i = 0; i < n-1; i++){
            if(ar[i] == 2 && ar[i+1] == 3){
                f = 1;
            }
            if(ar[i] == 3 && ar[i+1] == 2){
                f = 1;
            }
        }
        if(f==1){
            cout<<"Infinite"<<endl;
            continue;
        }
        for(int i = 0; i < n-1; i++){
         if((ar[i] == 1 && ar[i+1] == 2) || (ar[i] == 2 && ar[i+1] == 1)){
           res+= 3;
        }
        else if((ar[i] == 1 && ar[i+1] == 3) || (ar[i] == 3 && ar[i+1] == 1)){
            res+= 4;
         }

         if(i>1){
            if(ar[i]==2 && ar[i-1] == 1 && ar[i-2]==3)res--;

         }
        }
        cout<<"Finite"<<endl;
        cout<<res<<endl;

    }

  return 0;

}


#include <bits/stdc++.h>
using namespace std;
namespace fastIO{
	#define BUF_SIZE 100000
	#define OUT_SIZE 100000
	//fread->read
	bool IOerror=0;
//  inline char nc(){char ch=getchar();if(ch==-1)IOerror=1;return ch;}
	inline char nc(){
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend){
			p1=buf;pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1){IOerror=1;return -1;}
		}
		return *p1++;
	}
	inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
	template<class T> inline bool read(T &x){
		bool sign=0;char ch=nc();x=0;
		for(;blank(ch);ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	inline bool read(double &x){
		bool sign=0;char ch=nc();x=0;
		for(;blank(ch);ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
		if(ch=='.'){
			double tmp=1; ch=nc();
			for(;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0');
		}
		if(sign)x=-x;
		return true;
	}
	inline bool read(char *s){
		char ch=nc();
		for(;blank(ch);ch=nc());
		if(IOerror)return false;
		for(;!blank(ch)&&!IOerror;ch=nc())*s++=ch;
		*s=0;
		return true;
	}
	inline bool read(char &c){
		for(c=nc();blank(c);c=nc());
		if(IOerror){c=-1;return false;}
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t){return read(h)&&read(t...);}
	#undef OUT_SIZE
	#undef BUF_SIZE
};
using namespace fastIO;
/************* debug begin *************/
string to_string(string s){return '"'+s+'"';}
string to_string(const char* s){return to_string((string)s);}
string to_string(const bool& b){return(b?"true":"false");}
template<class T>string to_string(T x){ostringstream sout;sout<<x;return sout.str();}
template<class A,class B>string to_string(pair<A,B> p){return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template<class A>string to_string(const vector<A> v){
	int f=1;string res="{";for(const auto x:v){if(!f)res+= ", ";f=0;res+=to_string(x);}res+="}";
	return res;
}
void debug_out(){puts("");}
template<class T,class... U>void debug_out(const T& h,const U&... t){cout<<" "<<to_string(h);debug_out(t...);}
#ifdef tokitsukaze
#define debug(...) cout<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__);
#else
#define debug(...) 233;
#endif
/*************  debug end  *************/
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<int,ll> PIL;
typedef pair<ll,int> PLI;
typedef vector<int> VI;
typedef vector<ll> VL;
/************* define end  *************/
void read(int *x,int l,int r){for(int i=l;i<=r;i++) read(x[i]);}
void read(ll *x,int l,int r){for(int i=l;i<=r;i++) read(x[i]);}
void read(double *x,int l,int r){for(int i=l;i<=r;i++) read(x[i]);}
void println(VI x){for(int i=0;i<sz(x);i++) printf("%d%c",x[i]," \n"[i==sz(x)-1]);}
void println(VL x){for(int i=0;i<sz(x);i++) printf("%lld%c",x[i]," \n"[i==sz(x)-1]);}
void println(int *x,int l,int r){for(int i=l;i<=r;i++) printf("%d%c",x[i]," \n"[i==r]);}
void println(ll *x,int l,int r){for(int i=l;i<=r;i++) printf("%lld%c",x[i]," \n"[i==r]);}
/*************** IO end  ***************/
void go();
int main(){
	#ifdef tokitsukaze
		freopen("TEST.txt","r",stdin);
	#endif
	go();return 0;
}
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=2e5+10;
const ll mod=1e9+7;
/*********************************  head  *********************************/
void go()
{
	int n,i,a[111],ans;
	while(read(n))
	{
		read(a,1,n);
		ans=0;
		for(i=2;i<=n;i++)
		{
			if(a[i-1]==1&&a[i]==2)
			{
				ans+=3;
				if(i-3&&a[i-3]==3) ans--;
			}
			else if(a[i-1]==2&&a[i]==1)
			{
				ans+=3;
				if(i-3&&a[i-3]==3) ans--;
			}
			else if(a[i-1]==1&&a[i]==3) ans+=4;
			else if(a[i-1]==3&&a[i]==1) ans+=4;
			else if(a[i-1]==2&&a[i]==3)
			{
				ans=-1;
				break;
			}
			else if(a[i-1]==3&&a[i]==2)
			{
				ans=-1;
				break;
			}
		}
		if(ans==-1) puts("Infinite");
		else printf("Finite\n%d\n",ans);
	}
}


#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n , m;
	int count = 0;
	cin >> n >> m;

	for (int i = 1; i < 101; i++) {
		n-=1;
		count++;

		if ( i%m == 0) n++;

		if (n == 0) break;
	}

	cout << count << endl;

	system ("pause");
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t,i,j,a,b,c,d,e,sum;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        c=a/b;
        if(a<b)
        {
            cout<<a<<endl;
        }
        else
        {
            if(a%b==0 && a>b)
                cout<<c+a+1<<endl;
            else
                cout<<c+a<<endl;
        }
    }

}


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

int main()
{
	int s, d, res;
	cin >> s >> d;

	res = s;
	while (s>=d)
	{
		s = s / d;
		res += s;
	}

	cout << res << endl;

	system("pause");
	return 0;
}


#include <bits/stdc++.h>
#define ll unsigned long long
#define pi 3.1415926535897932384626433832795
#define fin(a,n)  for(ll i=0;i<n;i++) cin>>a[i];
#define fout(a,n)  for(ll i=0;i<n;i++) cout<<a[i]<<" ";
ll N = 1000000007;
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,t,flag=0;
	cin>>n>>t;
	int a[n-1];
	vector <bool> c(n+1, false);
	fin(a,n-1);
	c[a[0]] = true;
	int i=1;
	while(i+a[i-1] <= n-1)
	{
		c[i + a[i-1]] = true;
		i += a[i-1];
		if(c[t] == true)
		{
			flag = 1;
			break;
		}
	}
	if(flag)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  if(!freopen("in", "r" , stdin))
    cerr << "no file..."<<endl;
#endif

  return 1;
}


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


/**
 * @author    : Veeresh
 * @email Veeresh232@gmail.com
 * @create date 2020-04-01 20:09
 * @modify date 2020-04-01 20:09
 * @desc [description]
 */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define mp make_pair
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)

const ll MOD = 1e9 + 7; // 998244353

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vl v;
    ll t;
    while (true)
    {
        cin >> t;
        v.pb(t);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    while(1) cout<<" "<<endl;
}


#include<iostream>
#include<string>
#include<vector>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<conio.h>
#include<windows.h>
using namespace std;

int main()
{

	char ch,arr[70];
	int i=0;

	do
	{
		ch=getche();
		if(ch!='+')
			arr[i++]=ch;
    }
	while(ch!='\r');

	arr[i-1]='\0';

	sort(arr,arr+i-1);
	for(int j=0;j<i-2;j++)
		cout<<arr[j]<<"+";
	cout<<arr[i-2];
 	return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int pd[3000100],l,r,s,prime[101],len,tot,x[3000100],dis[3000100];
void dfs(int k1,int k2){
	//cout<<k1<<" "<<k2<<endl;
	if (k2>tot){
		x[++len]=k1; return;
	}
	for (long long i=k1;i<=r;i=i*prime[k2]) dfs(i,k2+1);
}
int main(){
	scanf("%d%d%d",&l,&r,&s);
	for (int i=2;i<=s;i++)
		if (pd[i]==0){
			prime[++tot]=i; for (int j=i;j<=s;j+=i) pd[i]=1;
		}
	dfs(1,1); sort(x+1,x+len+1);
	//for (int i=1;i<=len;i++) cout<<x[i]<<" "; cout<<endl;
	memset(pd,0x00,sizeof pd);
	memset(dis,0x3f,sizeof dis); dis[1]=0;
	for (int i=1;i<=s;i++){
		for (int j=1;j<=len;j++){
			if (dis[j]<=s) pd[j]=1; dis[j]++;
		}
		int now=1;
		for (int j=1;j<=len;j++){
			while (now<=len&&x[now]<1ll*x[j]*i) now++;// cout<<x[j]<<" "<<x[now]<<" "<<i<<endl;
			if (now>len) break;
			dis[now]=min(dis[now],dis[j]+1);
		}
	}
	int ans=0;
	//for (int i=1;i<=len;i++) cout<<dis[i]<<" "; cout<<endl;
	for (int i=1;i<=len;i++) if (pd[i]==1&&x[i]>=l&&x[i]<=r) ans++;
	cout<<ans<<endl; return 0;
}


#include <cmath>
#include <map>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <bitset>
#include <memory.h>
#include <functional>
#include <queue>
#include <fstream>
#include <ctime>
#include <deque>
#include <utility>
#include <stack>
#include <sstream>
#include <list>
#include <cctype>
#include <numeric>
#include <iomanip>
#include <assert.h>
using namespace std;
#define sqr(_) ((_)*(_))

typedef pair<int, int> Pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())

typedef long long LL;

const int MAXN = (int)3e6;

struct List
{
	int w, a, pre, nex;
}l[MAXN * 4];
set<int> s;
int h, t;
Pii q[MAXN];
int n, L, R, p, Tohka, tot;

void Ins(int p, int x, int y)
{
	if (L <= x && x <= R && s.find(x) == s.end())
		++Tohka, s.insert(x);
	++tot;
	l[tot].w = x, l[tot].a = y;
	l[tot].nex = p, l[tot].pre = l[p].pre;
	l[l[tot].pre].nex = tot,
	l[l[tot].nex].pre = tot;
}
void Erase(int p)
{
	l[l[p].pre].nex = l[p].nex;
	l[l[p].nex].pre = l[p].pre;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif

	cin >> L >> R >> p;
	tot = 1;
	l[1].pre = 0, l[1].nex = MAXN - 1;
	l[0].nex = 1, l[MAXN - 1].pre = 1;
	l[MAXN - 1].w = R + 1;
	l[1].w = 1, l[1].a = 1;
	for (int i = 2; i <= p; ++i)
	{
		h = 1, t = 0;
		for (int j = l[0].nex; j != MAXN - 1; j = l[j].nex)
		{
			++l[j].a;
			while (h <= t && q[h].x == l[j].w)
				l[j].a = min(l[j].a, q[h].y), ++h;
//			cout << l[j].w << " " << l[j].a << " ";
			if ((LL)l[j].w * i <= (LL)R && l[j].a + 1 <= p)
				q[++t] = mp(l[j].w * i, l[j].a + 1);
			int np = l[j].nex;
			while (h <= t && q[h].x < l[np].w)
				Ins(np, q[h].x, q[h].y - 1), ++h;
			if (l[j].a > p)
				Erase(j);
		}
	}
	cout << Tohka << endl;

	fclose(stdin);
	fclose(stdout);
	return 0;
}


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

typedef long long ll;

vector<int> pr;
int pchk[102];
void sieve() {
    for(int i = 2; i < 102; i++) {
        if(!pchk[i]) {
            pr.push_back(i);
        }
        for(int j = 0; j < pr.size() && i * pr[j] < 102; j++) {
            pchk[ i * pr[j] ] = 1;
            if(i % pr[j] == 0) break;
        }
    }
}

unordered_map<ll, int> mm;
int dp(int val, int b) {
    ll x = 100LL * val + b;
    if(mm.find(x) != mm.end()) return mm[x];
    int &ret = mm[x];
    if(val == 1) return ret = 0;
    if(b == 1) return ret = 1e9;
    if(val <= b) return ret = 1;

    ret = 1e9;
    if(val % b == 0) {
        ret = min(ret, 1 + dp(val / b, b));
    }
    ret = min(ret, dp(val, b - 1));
    return ret;
}

int l, r, p;

int cnt;
int val;
void dfs(int idx, int use, int mxp) {
    if(idx == pr.size()) {
        if(val < l) return;
        if(use + mxp <= p) {
            cnt++;
            return;
        }

        for(int i = max(p - 30, mxp); i < p; i++) {
            if(dp(val, i) <= p - i) {
                cnt++;
                break;
            }
        }

        return;
    }
    dfs(idx + 1, use, mxp);
    if(1LL * val * pr[idx] <= r) {
        val *= pr[idx];
        dfs(idx, use + 1, pr[idx]);
        val /= pr[idx];
    }
}

int main() {
    sieve();
    cin >> l >> r >> p;
    val = 1;
    cnt = 0;
    dfs(0, 0, 1);
    cout << cnt;
}


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

typedef long long ll;

vector<int> pr;
int pchk[102];
void sieve() {
    for(int i = 2; i < 102; i++) {
        if(!pchk[i]) {
            pr.push_back(i);
        }
        for(int j = 0; j < pr.size() && i * pr[j] < 102; j++) {
            pchk[ i * pr[j] ] = 1;
            if(i % pr[j] == 0) break;
        }
    }
}

int l, r, p;

unordered_map<ll, int> mm;
int dp(int val, int b, int rem) {
    ll x = 10000LL * val + 100 * b + rem;
    if(mm.find(x) != mm.end()) return mm[x];
    int &ret = mm[x];
    if(b == 1) return ret = val == 1;
    if(rem == 0) return ret = val == 1;
    if(val <= b) return ret = 1;

    if(val % b == 0) {
        if(dp(val / b, b, rem - 1)) return ret = 1;
        //else return ret = 0;
    }
    if(dp(val, b - 1, rem)) return ret = 1;
    else return ret = 0;
}

int cnt;
int val;
void dfs(int idx, int use, int mxp) {
    if(idx == pr.size()) {
        if(val < l) return;
        if(use + mxp <= p) {
            cnt++;
            return;
        }

        for(int i = mxp; i < p; i++) {
            if(dp(val, i, p - i)) {
                cnt++;
                break;
            }
        }

        return;
    }
    dfs(idx + 1, use, mxp);
    if(1LL * val * pr[idx] <= r) {
        val *= pr[idx];
        dfs(idx, use + 1, pr[idx]);
        val /= pr[idx];
    }
}

int main() {
    sieve();
    cin >> l >> r >> p;
    val = 1;
    cnt = 0;
    dfs(0, 0, 1);
    cout << cnt;
}


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

const int MAXN = 200;
const int INF = MAXN;
const int MOD = 1000000007;
int C[MAXN][MAXN];
int f[MAXN>>1][MAXN>>1][MAXN>>1][MAXN];

void add(int &x, const int y) {
    x += y;
    (x >= MOD) && (x -= MOD);
}

int main() {
    for (int i = 0, j; i < MAXN; ++i) for (C[i][0] = C[i][i] = 1, j = 1; j < i; ++j) {
        C[i][j] = min(C[i-1][j-1] + C[i-1][j], INF);
    }

    int tot = 0;
    int N, M, K;
    scanf("%d%d%d", &N, &M, &K), N >>= 1;

    f[0][1][0][1] = 1;
    for (int i = 0; i <= N && i < M; ++i) for (int j = 1; j <= N; ++j) {
        for (int k = 0; k <= N; ++k) for (int w = 0; w <= K; ++w) {
            int cc = f[i][j][k][w];
            if (!cc) continue;
            if (i) tot = (tot + (long long)cc * (M - i)) % MOD;
            for (int x = 1; x + k <= N; ++x) {
                int nw = w * C[j + x - 1][x];
                if (nw > K) continue;
                add(f[i + 1][x][k + x][nw], cc);
            }
        }
    }

    printf("%d\n", tot);

    return 0;
}


// 動的計画法

// [位置を] 固定しない。
// [順序を] 固定する必要があります。

#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdlib>
#include<complex>
using namespace std;

void Get(int &T)
{
	char C;bool F=0;
	for(;C=getchar(),C<'0'||C>'9';)if(C=='-')F=1;
	for(T=C-'0';C=getchar(),C>='0'&&C<='9';T=T*10+C-'0');
	F&&(T=-T);
}

int N,M,K;

void Init()
{
	Get(N);Get(M);Get(K);
	N++;
}

int C[1005][1005];

int F[105][105][105][105];
/*
int Ans[105];

int Cnt=0;

void DFS(int X,int Now,int Max)
{
	if(X>14)
	{
		if(Now==1&&Max==4)
		{
			//puts("9");
			//for(int i=1;i<=8;i++)
			//	printf("%d ",Ans[i]);
			//puts("");
			Cnt++;
			printf("%d\n",Cnt);
		}
		return;
	}

	Ans[X+1]=Now+1;
	DFS(X+1,Now+1,std::max(Max,Now+1));
	if(Now-1>=1)
	{
		Ans[X+1]=Now-1;
		DFS(X+1,Now-1,Max);
	}
}
*/

#define Mod (1000000007)

long long Ans;

void Work()
{
	C[0][0]=1;
	for(int i=1;i<=1000;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=1000;j++)
			C[i][j]=std::min(C[i-1][j]+C[i-1][j-1],1000);
	}

	/*
	for(int i=0;i<=20;i++)
	{
		for(int j=0;j<=20;j++)
			printf("%d ",C[i][j]);
		puts("");
	}
	*/

	F[0][0][1][1]=1;

	for(int i=0;i<=M;i++)
		for(int j=0;j<=N;j++)
			for(int k=1;k<=N;k++)
				for(int p=1;p<=K;p++)
				{
					if(F[i][j][k][p])
						for(int delta=k;j+delta<=N;delta++)
							if(C[delta-1][k-1]*p<=K)
								(F[i+1][j+delta][delta-k][C[delta-1][k-1]*p]+=
									F[i][j][k][p])%=Mod;
				}

	for(int i=2;i<=M;i++)
		for(int j=0;j<=N;j++)
			for(int k=0;k<=0;k++)
				for(int p=0;p<=K;p++)
				{
					long long Ans0=F[i][j][k][p];
					if(Ans0>0)
					{
						(Ans0*=(M-i+1))%=Mod;
						(Ans+=Ans0)%=Mod;
//						printf("%d %d %d %d %I64d\n",i,j,k,p,Ans0);
					}
				}
}

void Output()
{
	printf("%I64d\n",Ans);
}

int main()
{
	Init();
	Work();
	Output();
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <ctime>

using namespace std;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll rdtsc() {
    ll tmp;
    asm("rdtsc" : "=A"(tmp));
    return tmp;
}

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1e-9)
#define INF ((int)1e9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int MOD = (int)1e9 + 7;
inline void add(int &x, int y) {
	if ((x += y) >= MOD)
		x -= MOD;
}

const int maxVal = 101;
int sum[maxVal][maxVal][maxVal];
int d[maxVal][maxVal][maxVal][maxVal];

void filld(int m, int cnt, int n, int k) {
	int &cur = d[m][cnt][n][k];
	cur = 0;
	if (m == 1 && cnt == 1 && n == 1 && k == 1)
		cur = 1;
}

void pushd(int m, int cnt, int n, int k, int maxm, int maxn, int maxk) {
	int cur = d[m][cnt][n][k];
	if (!cur)
		return;
	for (int x = 0; x + n + 1 <= maxn; x++) {
		for (int y = 1, product = k; product <= maxk; product += k) {
			add(d[m][cnt + 1][x + n + 1][product], (ll)cur * sum[m - 1][x][y] % MOD);
	 	}
	}
	if (m + 1 <= maxm && n + 2 <= maxn)
		add(d[m + 1][2][n + 2][k], cur);
}

void countDyn(int maxn, int maxm, int maxk) {
	for (int n = 0; n <= maxn; n++)
		for (int m = 0; m <= maxm; m++)
			for (int k = 0; k <= maxk; k++)
				sum[m][n][k] = 0;
	for (int m = 0; m <= maxm; m++) {
		for (int cnt = 0; cnt <= maxn; cnt++) {
			for (int n = 0; n <= maxn; n++) {
				for (int k = 0; k <= maxk; k++) {
					filld(m, cnt, n, k);
				}
			}
		}
	}

	for (int m = 0; m <= maxm; m++) {
		for (int cnt = 0; cnt <= maxn; cnt++) {
			for (int n = 0; n <= maxn; n++) {
				for (int k = 0; k <= maxk; k++) {
					pushd(m, cnt, n, k, maxm, maxn, maxk);
					add(sum[m][n][k], d[m][cnt][n][k]);
				}
			}
		}
	}
}

int main() {
	srand(rdtsc());
#ifdef DEBUG
	freopen(TASKNAME".in", "r", stdin);
	freopen(TASKNAME".out", "w", stdout);
#endif

	int n, m, k;
	while (scanf("%d%d%d", &n, &m, &k) >= 1) {
		++n;

		countDyn(n, m, k);
		int ans = 0;
		for (int m1 = 1; m1 <= m; m1++)
			for (int n1 = 2; n1 <= n; n1++)
				for (int k1 = 1; k1 <= k; k1++)
					add(ans, (ll)sum[m1][n1][k1] * (m - m1 + 1) % MOD);
		printf("%d\n", ans);
		//break;
	}
	return 0;
}


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

typedef long long LL;

const int N = 105;
const int MOD = int(1e9 + 7);

int n, m, k;
int Co[N][N];
int f[N][N][N][N];
// length, maxinum, cnt, ways

void Upp(int i, int j, int p, int q, int o) { if(q>0 && q<=k) (f[i][j][p][q] += o) %= MOD; }

int main()
{

	scanf("%d%d%d", &n, &m, &k);

	for(int i=0; i<=n; i++)
	{
		Co[i][0] = Co[i][i] = 1;
		for(int j=1; j<i; j++) Co[i][j] = (Co[i-1][j] + Co[i-1][j-1]) % MOD;
	}

	f[1][1][1][1] = 1;

	int ans(0);

	for(int i=1; i<=n; i++) //for length
	for(int j=1; j+j-1<=i && j<=m; j++) // for maxinum
	for(int p=1; p+j-1+j-1<=i; p++) // for cnt
	for(int q=1; q<=k; q++) // for ways
	if(f[i][j][p][q])
	{
		if(i>1) (ans += (LL(f[i][j][p][q]) * (m-j+1)) % MOD) %= MOD;
		for(int t=1; i+t*2<=n+1; t++) Upp(i+t*2, j+1, t, q*Co[p+t-1][t-1], f[i][j][p][q]);
	}

	printf("%d\n", (ans+MOD)%MOD);

	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    long long n;
    int s4 = 0, s7 = 0;
    string s, t;
    cin >> n;
    s = to_string(n);
    if (s.size() % 2 != 0)
    {
        for (int i = 0; i <= (s.size() / 2); i++)
            cout << 4;
        for (int i = (s.size() / 2) + 1; i <= s.size(); i++)
            cout << 7;
        return 0;
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (i < (s.size() / 2))
            t += '7';
        else
            t += '4';
    }
    if (s>t)
    {
        for (int i = 0; i <= s.size(); i++)
            cout << 4;
        for (int i = s.size() + 1; i <= s.size() + 1; i++)
            cout << 7;
        return 0;
    }
    else if (s == t)
    {
        cout << s;
        return 0;
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (i < (s.size() / 2))
            t[i] = '4';
        else
            t[i] = '7';
    }
    if (s < t)
    {
        for (int i = 0; i < (s.size() / 2); i++)
            cout << 4;
        for (int i = (s.size() / 2); i < s.size(); i++)
            cout << 7;
        return 0;
    }
    else if (s == t)
    {
        cout << s;
        return 0;
    }
    t = "";
    s4 = s.size() / 2;
    s7 = s4;
    for (int i = 0; i < s.size(); i++)
    {
        if ((s[i] - '0')> 4 && (s[i] - '0')<7)
        {
            t += '7';
            s7--;
            for (int i = 0; i < s4; i++)
                t += '4';
            for (int i = 0; i < s7;)
                t += '7';
            cout << t;
            return 0;
        }
        else if ((s[i] - '0') < 4)
        {
            t += '4';
            s4--;
            for (int i = 0; i < s4; i++)
                t += '4';
            for (int i = 0; i < s7; i++)
                t += '7';
            cout << t;
            return 0;
        }
        else if ((s[i] - '0') == 4)
        {
            if (s4>0)
            {
                s4--;
                t += '4';
            }
        }
        else if ((s[i] - '0') == 7)
        {
            s7--;
            t += '7';
        }
        else
        {
            for (int j = i - 1; j >= 0; j--)
            {
                if (t[j] == '4')
                {
                    s4--;
                    t[j] = '7';
                    s7++;
                    for (int i = 0; i < s4; i++)
                        t += '4';
                    for (int i = 0; i < s7;)
                        t += '7';
                    cout << t;
                    return 0;
                }
            }
        }
    }
    return 0;
}