#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <random>
#include <assert.h>
using namespace std;

const string file = "A";

const string infile = file + ".in";
const string outfile = file + ".out";

//const int INF = 0x3f3f3f3f;
//#define ONLINE_JUDGE

int main()
{
#ifdef ONLINE_JUDGE
	ostream &fout = cout;
	istream &fin = cin;
#else
	fstream fin(infile.c_str(), ios::in);
	fstream fout(outfile.c_str(), ios::out);
#endif
  string A;
  string B;
  fin >> A >> B;
  int N = A.length();
  string C(N, '0');
  for(int i = 0; i < N; i++) {
    if(A[i] == B[i]) {
      C[i] = '0';
    } else {
      C[i] = '1';
    }
  }
  fout << C << "\n";

#ifdef ONLINE_JUDGE
#else
  fout.close();
	fin.close();
#endif
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = (int)4e5 + 50, LOGN = 19;

struct SuffixArray {
    vi sa, lcp, rk;
    vi mm;
    vector<vector<int>> st;
    SuffixArray(string& s, int lim=256) { // or basic_string<int>
        int n = sz(s) + 1, k = 0, a, b;
        vi x(all(s)+1), y(n), ws(max(n, lim)), rank(n);
        sa = lcp = rk = y, iota(all(sa), 0);
        for (int j = 0, p = 0; p < n; j = max(1, j * 2), lim = p) {
            p = j, iota(all(y), n - j);
            rep(i,0,n) if (sa[i] >= j) y[p++] = sa[i] - j;
            fill(all(ws), 0);
            rep(i,0,n) ws[x[i]]++;
            rep(i,1,lim) ws[i] += ws[i - 1];
            for (int i = n; i--;) sa[--ws[x[y[i]]]] = y[i];
            swap(x, y), p = 1, x[sa[0]] = 0;
            rep(i,1,n) a = sa[i - 1], b = sa[i], x[b] =
                        (y[a] == y[b] && y[a + j] == y[b + j]) ? p - 1 : p++;
        }
        rep(i,1,n) rank[sa[i]] = i;
        for (int i = 0, j; i < n - 1; lcp[rank[i++]] = k)
            for (k && k--, j = sa[rank[i] - 1];
                    s[i + k] == s[j + k]; k++);
        s = " " + s;
        for(int i = n - 1; i >= 1; i--) sa[i]++, rk[sa[i]] = i;

        mm = vi(N, 0);
        mm[0] = -1;
        st = vector<vector<int> > (LOGN, vector<int> (N, 0));
        for(int i = 1; i < n; i++) mm[i]= (i & (i-1)) == 0 ? mm[i-1] + 1 : mm[i-1];
        for(int i = 0; i < n; i++){
            st[0][i] = lcp[i];
        }
        for(int lg = 1; lg < LOGN; lg++){
            for(int j = 0; j + (1 << lg) - 1 < n; j++){
                st[lg][j] = min(st[lg-1][j], st[lg-1][j+(1<<(lg-1))]);
            }
        }
    }

    int rmq(int a, int b){
//        cout << "getting " << a << " " << b << endl;
        int l = rk[a], r = rk[b];
        if(l == r) return N;
        if(l > r) swap(l, r);
        l++;
        int k = mm[r - l + 1];
        return min(st[k][l], st[k][r-(1<<k)+1]);
    }
};

int n;
string s, t;
string rev;
int psum[N];
vector<int> pos;

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

    cin >> n;
    cin >> s;
    SuffixArray sa(s);
    for(int i = 2; i <= n; i++) {
        psum[i] = psum[i-1] + (s[i] == '1' && s[i - 1] == '1');
    }

    pos.push_back(0);
    for(int i = 1; i <= n; i++) {
        if(s[i] == '0') {
            pos.push_back(i);
            t += (i % 2 == 0 ? '0' : '1');
        }
    }
    rev = t;
    for(char &c : rev) {
        if(c == '0') c = '1';
        else c = '0';
    }
    t += rev;
    SuffixArray st(t);
    int q;
    cin >> q;
    while(q--) {
        int l1, l2, len;
        cin >> l1 >> l2 >> len;
        int mv1 = (psum[l1 + len - 1] - psum[l1] > 0);
        int mv2 = (psum[l2 + len - 1] - psum[l2] > 0);
        if(mv1 != mv2) {
            cout << "No\n";
            continue;
        }
        if(!mv1) {
            cout << (sa.rmq(l1, l2) >= len ? "Yes\n" : "No\n");
        }
        else {
            int al = (int)(lower_bound(all(pos), l1) - pos.begin());
            int ar = (int)(lower_bound(all(pos), l1 + len) - pos.begin());
            int bl = (int)(lower_bound(all(pos), l2) - pos.begin());
            int br = (int)(lower_bound(all(pos), l2 + len) - pos.begin());
            if(ar - al != br - bl) {
                cout << "No\n";
            }
            else if(al == ar) {
                cout << "Yes\n";
            } else {
                if(l1 % 2 == l2 % 2) cout << (st.rmq(al, bl) >= br - bl ? "Yes\n" : "No\n");
                else cout << (st.rmq(al, bl + (int)rev.size()) >= br - bl ? "Yes\n" : "No\n");
            }

        }

    }

}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<int>             VI;
typedef vector<string>          VS;
typedef pair<int,int>           PII;
typedef pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

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

int main()
{
    int A,B;
    cin >> A >> B;
    int g = gcd(A,B);
    A/=g;
    B/=g;
    if(abs(A-B)==1){
        cout << "Equal\n";
        return 0;
    }
    if(A<B)
        cout << "Dasha\n";
    else
        cout << "Masha\n";
    return 0;
}


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

int const N = 232;
int const M = (1 << 8) - 1;

double f[N][N][2][M+1];

void get_state(int x, int &nth, int &cnt, int &mask) {
	mask = x & M, nth = x >> 8 & 1, cnt = 0;
	for (int i=8; (x>>i&1)==nth&&i<32; ++cnt,++i);
}

int main() {
	int x, k, pp;
	int nth, cnt, mask;
	scanf("%d%d%d", &x, &k, &pp);
	double p = pp / 100.0, q = 1 - p;
	get_state(x, nth, cnt, mask);
	f[0][cnt][nth][mask] = 1;
	for (int i=0; i<k; ++i) for (int j=0; j<N; ++j) for (int b=0; b<2; ++b) for (int m=0; m<=M; ++m) {
		double c = f[i][j][b][m];
		int b7 = m >> 7 & 1;
		if (b7 == b) cnt = j + 1, nth = b;
		else cnt = 1, nth = b7;
		f[i+1][cnt][nth][(2*m)&M] += p * c;
		if (m + 1 > M) {
			if (b == 0) nth = 1, cnt = 1;
			else nth = 0, cnt = j;
		} else {
			nth = b, cnt = j;
		}
		f[i+1][cnt][nth][(m+1)&M] += q * c;
	}
	double e = 0;
	for (int i=0; i<N; ++i) for (int b=0; b<2; ++b) for (int m=0; m<=M; ++m) {
		int len = 0;
		if (m == 0) len = 8 + (b ? 0 : i);
		else len = __builtin_ctz(m);
		e += len * f[k][i][b][m];
	}
	printf("%.20lf\n", e);
	return 0;
}


#include <cstring>
#include <iostream>
using namespace std;
int n;
int t[100][3],T[100];
int min(int a,int b)
{
    if(a<b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
void initialisation()
{
    for(int i=0;i<n;i++)
    {
        t[i][1]=t[i][0]=t[i][2]=1000;
    }
}
void remplissage()
{
    for(int i=0;i<n;i++)
    {
       cin>>T[i];
    }
}
void test()
{
    if(T[0]==1 || T[0]==3)
    {
        t[0][1]=0;
    }
    if(T[0]==2 || T[0]==3)
    {
       t[0][2]=0;
    }
}
void calcul()
{
    for(int i=1;i<n;i++)
    {
        t[i][0]= 1+min(t[i-1][0],min(t[i-1][1],t[i-1][2]));
        if(T[i]==1 || T[i]==3)
        {
            t[i][1]=min(t[i-1][0],t[i-1][2]);
        }
        if(T[i]==2 || T[i]==3)
        {
            t[i][2]=min(t[i-1][0],t[i-1][1]);
        }
    }
}
int resultat()
{
    return min(t[n-1][0],min(t[n-1][1],t[n-1][2]));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    initialisation();
    remplissage();
    t[0][0]=1;
    test();
    calcul();
    cout << resultat();
    return 0;
}


/*
ID: hossein17
PROG: NAME
LANG: C++
*/

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

using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
#define LINE cerr<<"____________________________________________________+++++++++++++__________________________________________________"<<endl
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<int(b);++i)
#define FORP(i,b,a) for(int i=(a)-1;i>=int(b);--i)
#define error(x) cerr<< #x << " = " << (x)<<endl
#define all(n) (n).begin(),(n).end()
#define FOREACH(i,c) for(__typeof( (c).begin() ) i = (c).begin();i!=(c).end();++i)
#define PRINT(a,f,s) for(int o=(f);o<int(s);++o) cerr<<a[o]<<" "; cerr<<endl;
#define bit(k,i) (((i)>>k)&1)
#define AZ(a) ((char)(a)>='A' && (char)(a)<='Z')

/*
ifstream fin("NAME.in");
ofstream fout("NAME.out");
#define cin fin
#define cout fout
*/

//MAX
const int MAXN=1000;
const int MAX=1000;
const int inf=999999999;
const int p1=104393321,p2=104393329;

//variables
int a[MAX],d[MAX][MAX];
//structs & classes
//compare functions
//functions

int main()
{
	ios::sync_with_stdio(0);
	int n,k;
	cin>>n>>k;
	FOR(i,0,n) {
		cin>>a[i];
	}
	FOR(i,0,n) {
		int x=a[i];
		FOR(j,0,k) {
			d[i][j]=x%10;
			x/=10;
		}
	}
	int perm[MAX];
	FOR(i,0,k)
		perm[i]=i;
	int ans=inf;
	do {
		int t[MAX];
		fill(t,t+n,0);
		FOR(i,0,n) {
			FOR(j,0,k) {
				t[i]*=10;
				t[i]+=d[i][perm[j]];
			}
		}
		sort(t,t+n);
		ans=min(ans,t[n-1]-t[0]);
	}while(next_permutation(perm,perm+k));
	cout<<ans<<endl;
	return 0;
}


/*
Problem Source:

Editorial/Logic/Ideas Sources:
1)
*/

/*
Problem Description:

*/

#include <stdio.h>
#include <string.h>

#define INT_MAX				 99999999
#define INT_MIN				-99999999
#define SUCCESS				0
#define MAX_DIM				101

int input[MAX_DIM];
int counts[601];
int n;
int max_scr;

static void test_wrapper()
{
	int test_cases, T;
	int i, j;
	int ans;
	int val, nz_cnt;

#ifdef WINDOWS_TEST
	/* Read number of test cases */
	scanf("%d", &T);
	for(test_cases = 1; test_cases <= T; test_cases++)
#endif
	{
		/* Read Inputs */
		scanf("%d", &n);
		//clear counts array
		for(i = 0; i <= 600; i++)
		{
			counts[i] = 0;
		}
		//read values
		for(i = 0; i < n; i++)
		{
			scanf("%d", &val);
			if(val > 0)
			{
				counts[val] = 1;
			}
		}
		//read no of non-zero values
		nz_cnt = 0;
		for(i = 0; i <= 600; i++)
		{
			if(counts[i] == 1)
			{
				nz_cnt++;
			}
		}

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

int main()
{
	/* test wrapper function */
	test_wrapper();

	return 0;
}


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

using namespace std;

#define fr(a,b,c) for(int a = b; a < c; a++)
#define rep(a,b) fr(i,0,b)
#define ln puts("")

typedef long long ll;

ll n;

bool read(){
    if(!(cin >> n)) return false;

    return true;
}

ll p[1111];
int last;

void process(){
    last = 0;

    for(ll i = 2; i*i <= n; i++){
        while(n%i == 0){
            p[last++] = i;
            n/=i;
        }
    }

    if(n != 1) p[last++] = n;

    if(last <= 1){
        printf("1\n0\n");
    }
    else if(last == 2){
        printf("2\n");
    }
    else if(last >= 3){
        //cout << p1 << " " << p2 << endl;
        cout << 1 << endl << (p[0]*p[1]) << endl;
    }
}

int main(){
    while(read()) process();

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

string num;				// исходное делимое
int numLen,				// количество цифр делимого
m,						// делитель
temp,					// остаток
answer = 0;				// наименьший из остатков
int stepArr[200001];	// массив остатков от деления степеней числа 10 на m

int main() {
	// ввод данных
	cin >> num >> m;

	// определение количества цифр делимого
	numLen = size(num);

	// формирование массива остатков от деления степеней числа 10 на m
	stepArr[0] = 1;
	for (int i = 1; i < numLen; i++) {
		stepArr[i] = (stepArr[i - 1] * 10) % m;
	}

	// нахождение остатка исходного числа
	for (int i = numLen - 1; i >= 0; i--) {
		answer += ((num[i] - 48) * stepArr[numLen - i - 1]) % m;
		answer %= m;
	}

	// нахождение наименьшего остатка среди сдвигов числа
	/*  =============================================================================
		P - исходное число
		Q - сдвиг числа
		m - делитель
		=============================================================================
		Сдвиг осуществляется следующим образом:

		P = a_n * 10^n + a_(n-1) * 10^(n-1) + ... + a_0

		Q = a_(n-1) * 10^n + ... + a_0 * 10 + a_n =
		  = (a_(n-1) * 10^(n-1) + ... + a_0) * 10 + a_n =
		  = (P - a_n * 10^n) * 10 + a_n
		=============================================================================
		Учитывая свойства остатка от деления получаем:

		Q % m = ((P - a_n * 10^n) * 10 + a_n) % m

		Q % m = (((P % m - (a_n % m * 10^n % m) % m + m) % m * 10) % m + a_n % m) % m

		В скобке (P % m - (a_n % m * 10^n % m) % m + m) прибавляем m на случай,
		если P % m < (a_n % m * 10^n % m) % m

		Были опущены некоторые % m ввиду их ненадобности

		Количество сдвигов соответсвует количеству цифр в числе
	    ============================================================================= */
	temp = answer;
	for (int i = 0; i < numLen - 1; i++) {
		temp = ((((temp - (num[i] - 48) * stepArr[numLen - 1]) % m + m) * 10) % m + (num[i] - 48) % m) % m;
		if (num[i + 1] != 48 && answer > temp) {
			answer = temp;
		}
	}
	cout << answer;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N=250005,M=1<<17,D=18;

int P;
int power(int a,int t){
	int r=1;
	while(t){
		if(t&1)r=(ll)r*a%P;
		a=(ll)a*a%P;t>>=1;
	}
	return r;
}

int L,K,fac[N],n,m,bit[20],ifac[N],bitcnt[N];
ll suma[D][M],sumc[D][M];
ull dp[D][M],tmp[D][M];

int main(){

	scanf("%d%d%d",&L,&K,&P);
	fac[0]=1;
	for(int i=1;i<=L;i++){
		fac[i]=(ll)fac[i-1]*i%P;
		bitcnt[i]=bitcnt[i>>1]+(i&1);
	}
	ll all=power(K,L);
	if(L&1)printf("%lld\n",all),exit(0);

	ifac[L]=power(fac[L],P-2);
	for(int i=L;i>=1;i--)ifac[i-1]=(ll)ifac[i]*i%P;
	for(int i=1;(1<<i)<=L;i++)if(L>>i&1)bit[n++]=1<<i;

	m=1<<n;
	// build a
	for(int i=0;i<m;i++){
		int s=0;
		for(int j=0;j<n;j++)if(i>>j&1)s+=bit[j];
		suma[bitcnt[i]][i]=ifac[s];
	}

	// get suma
	for(int t=0;t<=n;t++){
		int i,j,k,l;
		ll*a=suma[t];
		for(l=m;l>=2;l>>=1)for(j=0,i=l>>1;j<m;j+=l)for(k=0;k<i;k++)a[j+k+i]+=a[j+k];
		for(j=0;j<m;j++)a[j]=a[j]%P;
	}

	for(int t=0;t<=n;t++)memcpy(dp[t],suma[t],m<<3);
	int cc=0,revK=0;
	while(K)(revK<<=1)|=K&1,cc++,K>>=1;
	for(cc--,revK>>=1;cc;cc--,revK>>=1){

		// use dp to update dp
		// f i,j means V = i, P = j
		// f (a + b),j = g a,j * h b,j

		for(int t=0;t<=n;t++)memset(tmp[t],0,m<<3);
		for(int a=0;a<=n;a++)for(int b=0;a+b<=n;b++){
			ull*f=tmp[a+b],*g=dp[a],*h=dp[b];
			for(int j=0;j<m;j++)f[j]+=g[j]*h[j];
		}
		for(int t=0;t<=n;t++)for(int j=0;j<m;j++)dp[t][j]=tmp[t][j]%P;

		if(revK&1){
			// use suma to update dp

			for(int t=0;t<=n;t++)memset(tmp[t],0,m<<3);
			for(int a=0;a<=n;a++)for(int b=0;a+b<=n;b++){
				ull*f=tmp[a+b],*g=dp[a]; ll*h=suma[b];
				for(int j=0;j<m;j++)f[j]+=g[j]*h[j];
			}
			for(int t=0;t<=n;t++)for(int j=0;j<m;j++)dp[t][j]=tmp[t][j]%P;

		}
	}

	// get answer
	for(int t=0;t<=n;t++)memcpy(sumc[t],dp[t],m<<3);
	for(int t=0;t<=n;t++){
		int i,j,k,l;
		ll*a=sumc[t];
		for(l=2;l<=m;l<<=1)for(j=0,i=l>>1;j<m;j+=l)for(k=0;k<i;k++)a[j+k+i]-=a[j+k];
		for(j=0;j<m;j++)a[j]=(a[j]%P+P)%P;
	}

	ll ans=(all-sumc[n][(1<<n)-1]*fac[L]%P+P)%P;
	printf("%lld\n",ans);

	return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
    int i,n,m,k,p;
    char a[101];
    char b[101]="127",c[101]="32767",d[101]="2147483647";
    char e[101]="9223372036854775807";

    scanf("%s",a);
    k=strlen(a);
    if( k<3) printf("byte\n");
    else if(k==3){
        for (i=0, p=0; i<=k; i++)
        {
            n=a[i]-'0';//新的数值
            m=b[i]-'0';
            if(m>n)break;
            else if(n>m) {p=1;break;}
        }
        if(i==k){ printf("byte\n");}
        else {if( p) printf( "short\n");else printf("byte\n");}
    }
        else if(k>3 && k<5) printf("short\n");
            else if(k==5)
                {
            for (i=0, p=0; i<k; i++)
            {
                n=a[i]-'0';//新的数值
                m=c[i]-'0';
                if(m>n)break;
                else if(n>m) {p=1;break;}
            }
            if(i==k){ printf("short\n");}
            else {if( p) printf( "int\n");else printf("short\n");}
            }
            else if(k>5 && k<10)printf("int\n");
                else if( k==10)
                {
                    for (i=0, p=0; i<k; i++)
                {
                    n=a[i]-'0';//新的数值
                    m=d[i]-'0';
                    if(m>n)break;
                    else if(n>m) {p=1;break;}
                }
                    if(i==k){ printf("int\n");}
                        else {if( p) printf( "long\n");else printf("int\n");}
                }
                else if( k>10 && k<19)printf( "long\n");
                    else if(k==19)
                        {
                        for (i=0, p=0; i<k; i++)
                        {
                            n=a[i]-'0';//新的数值
                            m=e[i]-'0';
                            if(m>n)break;
                            else if(n>m) {p=1;break;}
                        }
                        if(i==k){ printf("long\n");}
                        else {if( p) printf( "BigInteger\n");else printf( "long\n");}
                    }
                        else  printf( "BigInteger\n");

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#define dou double
#define mem(a) memset(a, 0, sizeof(a))
#define memm(a) memset(a, -1, sizeof(a))
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int, int>
#define FI first
#define SE second
#define RI(a) scanf("%d", &(a))
#define RII(a, b) scanf("%d%d", &(a), &(b))
#define RIII(a, b, c) scanf("%d%d%d", &(a), &(b), &(c))
#define RL(a) scanf("%I64d", &(a))
#define RLL(a, b) scanf("%I64d%I64d", &(a), &(b))
#define RLLL(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define PI(r) printf("%d\n", (r))
#define PL(r) printf("%I64d\n", (r))
#define RS(s) scanf("%s", (s))
#define SL(a) strlen(a)
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define REPP(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
#define FOR(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
//Segment tree
#define LC (x << 1)
#define RC ((x << 1) | 1)
#define MID ((l + r) >> 1)
#define LB(x) ((x) & (-(x)))
#define M (N - 1000)
#pragma warning (disable : 4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define EPS 1e-8
#define INF 2000000000
#define LIM (1ll << 60)
#define MOD 1000000007
#define N 111111

using namespace std;

int n, m;
int p[44] = { 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,
	2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,
	23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,
	1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011
};

LL qp(LL a, LL b) {
	LL re = 1;
	while (b){
		if (b & 1) re = re * a % MOD;
		b >>= 1;
		a = a * a % MOD;
	}
	return re;
}

int main(){
	int t, x, y, z, ca = 1;
	//freopen("E:/Code/in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios :: sync_with_stdio(false);
	RI(n);
	LL re = qp(2, p[n - 1] - 1) - 1;
	if (re < 0) re += MOD;
	PI((int)re);

	return 0;
}


// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (5e5)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

int lewo[maxn], ile[maxn];
int pref[maxn];

VI kand;
bool ok(int x, int y)
{
  int cnt = 0;
  int poprz = -1;
  for(int i = y - 1;1;i = min(maxn - 1, y + i))
  {
    cnt += (pref[i] - (poprz >= 0 ? pref[poprz] : 0)) * (i / y);
    poprz = i;
    if(i == maxn - 1)
      break;
  }
  poprz = 0;
  int res = 0;
  int maxi = -inf;
  int maxi2 = -inf;
  auto rozwaz = [&](int s){    if(s >= x)
      {
        int xd = ((s - x) / y - s / y);
        if(maxi < xd)
        {
          maxi2 = maxi;
          maxi = xd;
        }
        else
          maxi2 = max(maxi2, xd);
      }
      if(s >= 2 * x)
        res = max(res, cnt + (s - 2 * x) / y - s / y);
  };
  for(int i = y;1;i = min(maxn - 1, i + y))
  {
    if(lewo[i] >= poprz)
      rozwaz(lewo[i]);
    if(ile[lewo[i]] > 1)
    {
      if(lewo[i] >= poprz)
        rozwaz(lewo[i]);
    }
    else
      if(lewo[lewo[i]] >= poprz)
        rozwaz(lewo[lewo[i]]);
    poprz = i;
    if(i == maxn - 1)
      break;
  }
  return max(res, cnt + maxi + maxi2) >= x;
}

int main()
{
	_upgrade
  int n;
  n = 500000;
  cin>>n;
  for(int i = 1;i <= n;i++)
  {
    int a;
    a = rand() % (maxn - 10) + 1;
    cin>>a;
    ile[a]++;
  }
  for(int i = 1;i < maxn;i++)
  {
    pref[i] = ile[i] + pref[i - 1];
    if(ile[i - 1] > 0)
      lewo[i] = i - 1;
    else
      lewo[i] = lewo[i - 1];
  }
  // dbg(ok(3, 4));
  // return 0;
  LL res = 0LL;
  for(int y = 1;y < maxn;y++)
  {
    // if(y > 100)
      // break;
    // dbg(y);
    int l = max(2LL, res / y);
    int p = maxn;
    while(l + 1 < p)
    {
      int sr = (l + p) / 2;
      if(ok(sr, y))
        l = sr;
      else
        p = sr;
    }
    if(ok(l, y))
    {
      res = max(res, l * (LL)y);
      // dbg(l, y);
    }
  }
  cout<<res;

	return 0;
}


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

typedef long long ll;
typedef unsigned long long llu;
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
#define inf 1000000009
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int, int>

int main()
{
	pii x1, x2, y1, y2, z1, z2;
	cin>>x1.ff>>x1.ss>>x2.ff>>x2.ss>>y1.ff>>y1.ss>>y2.ff>>y2.ss>>z1.ff>>z1.ss>>z2.ff>>z2.ss;

	if(y1 > z1) swap(y1, z1), swap(y2, z2);

	//shrinking the horizontal side
	if(x1.ff >= y1.ff && x2.ff <= y2.ff && x1.ss >= y1.ss && x1.ss <= y2.ss) {
		x1.ss = min(x2.ss, y2.ss);
	}
	if(x1.ff >= z1.ff && x2.ff <= z2.ff && x1.ss >= z1.ss && x1.ss <= z2.ss) {
		x1.ss = min(x2.ss, z2.ss);
	}

	//shrinking the vertical side
	if(x1.ss >= y1.ss && x2.ss <= y2.ss && x1.ff >= y1.ff && x1.ff <= y2.ff) {
		x1.ff = min(x2.ff, y2.ff);
	}
	if(x1.ss >= z1.ss && x2.ss <= z2.ss && x1.ff >= z1.ff && x1.ff <= z2.ff) {
		x1.ff = min(x2.ff, z2.ff);
	}

	if(x1.ff == x2.ff || x1.ss == x2.ss) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int c, ans;
int main(){
	string a;
	cin>>a;
	for(int i=0;i<a.size();i++){
		if(a[i]=='1'){
			for(int j=i + 1;j<a.size();j++){
				if(a[j]=='0'){
					c++;
				}
			}
			ans = max(c, ans);
			c = 0;
		}
	}
	if(ans>=6){
		cout<<"yes";
	}
	else{
		cout<<"no";
	}
	return 0;
}


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

int  main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    int w,h,h1,w1,h2,w2;
    cin>>w>>h>>w1>>h1>>w2>>h2;
    if(h1 < h2)
    {
        int k = h1;
        h1 = h2;
        h2 = k;
        k = w1;
        w1 = w2;
        w2 = k;
    }

int k = h;
    for(int i = k;i >= h1;i--)
    {
        w += i;
    }
   // cout<<h<<endl;
    w = max(0,w - w1);

    for(int i = h1-1;i >= h2;i--)
    {
        w += i;
    }

    w = max(0,w - w2);

    while(h2 > 1)
    {
        h2--;
        w += h2;

    }
    cout<<w;
    return 0;
}


#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

#define WHATS(var)//cout<<__LINE__<<' '<<#var<<"="<<var<<endl;

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
	os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	}
	return os;
}

using ll = long long int;
using Graph=vector<vector<int>>;
Graph graph;
vector<int>depths;
vector<int>cycles;
vector<int>froms;
int N;
void dfs(int now,int from,int d){
	depths[now]=d;
	froms[now]=from;
	for(auto e:graph[now]){
		if(e==from)continue;
		else{
			if(depths[e]){
				if(depths[e]<depths[now]){
					int xx=now;
					cycles[xx]=true;
					while(xx!=e){
						xx=froms[xx];
						cycles[xx]=true;
					}
				}else if(depths[e]>=depths[now]){

				}
			}else{
				dfs(e,now,d+1);
			}

		}
	}
}
vector<int>szs;
vector<pair<ll,ll>>dps;
void dfs2(int now,int from,int d=0){
	szs[now]=1;
	bool flag=false;
	ll max_plus=0;
	ll normal_sum=0;
	for(auto e:graph[now]){
		if(e==from||cycles[e])continue;
		else{
			dfs2(e,now,d+1);
			szs[now]+=szs[e];
			flag=true;
			normal_sum+=dps[e].first;
			max_plus=max(max_plus,dps[e].second+N-szs[e]);
		}
	}
	if(!flag){
		max_plus=N-1;
	}else{
		max_plus-=szs[now];
	}
	normal_sum+=szs[now];
	{
		dps[now].first=normal_sum;
		dps[now].second=max_plus;
	}

}
int main()
{
	ios::sync_with_stdio(false);
	cin>>N;
	graph.resize(N);
	depths.resize(N);
	froms.resize(N);
	cycles.resize(N);
	froms.resize(N);
	szs.resize(N);
	dps.resize(N);
	for(int i=0;i<N;++i){
		int u,v;cin>>u>>v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	dfs(0,-1,1);
	WHATS(cycles)

	vector<int>cycle_ids;
	for(int i=0;i<N;++i){
		if(cycles[i]){
			dfs2(i,-1);
			cycle_ids.push_back(i);
		}
	}
	WHATS(dps)

	vector<vector<ll>>memo(2,vector<ll>(cycle_ids.size()));
	for(int l=0;l<cycle_ids.size();++l){
		int c_id=cycle_ids[l];
		memo[1][l]=ll(cycle_ids.size()-1)*ll(szs[c_id]);
	}
	ll answer=0;
	for(auto c_id:cycle_ids)answer+=dps[c_id].first;
	WHATS(answer)
		WHATS(memo[1])

	for(int sz=2;sz<cycle_ids.size();++sz){
		int cur=sz&1;
		int tar=cur^1;
		for(int l=0;l<cycle_ids.size();++l){
			int r=(l+sz-1)%cycle_ids.size();
			int l_use=cycle_ids[l];
			int r_use=cycle_ids[(l+sz-1)>=cycle_ids.size()?l+sz-1-cycle_ids.size():l+sz-1];
			ll r_use_cost=memo[tar][l]+ll(cycle_ids.size()-sz)*ll(szs[r_use]);
			ll l_use_cost=memo[tar][(l+1)>=cycle_ids.size()?0:l+1]+ll(cycle_ids.size()-sz)*ll(szs[l_use]);

			memo[cur][l]=max(r_use_cost,l_use_cost);
		}
		WHATS(memo[cur])
	}
	WHATS(memo[1-cycle_ids.size()%2])
	ll aplus=0;
	for(int i=0;i<cycle_ids.size();++i){
		int c_id=cycle_ids[i];
		ll nanswer=dps[c_id].second-(N-szs[c_id])+memo[1-cycle_ids.size()%2][(i+1)%cycle_ids.size()];
		WHATS(aplus)
		aplus=max(aplus,nanswer);
	}
	cout<<answer+aplus<<endl;

	return 0;
}


// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=1e5+10;

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

    int a,b; cin>>a>>b;
    int n=a+b, ans=0;

    int sq=sqrt(n);

    vector<int> vec;
    for(int i=1;i<=sq;i++){
	vec.PB(i);
    }
    for(int i=1;(n/i)>sq;i++){
	vec.PB(n/i);
    }
    for(int x:vec){
	int A=a%x, AA=a/x, B=b%x, BB=b/x;
	if(A<=AA && B<=BB && A+B<AA+BB){
	    int AAA=(AA-A)/(x+1), BBB=(BB-B)/(x+1), C=(AA+BB-1-A-B)/(x+1);
	    ans+= min(AAA+BBB,C)+1;
	}
    }
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#include<iostream>
#include<stdio.h>
#include<math.h>
#define LL long long
#define P 1000000007
using namespace std;
LL po(LL x,LL n,LL q)
{
    int i=0,j;
    LL m[100]={0},p[100]={0},ans=1;
    while(n!=0)
    {
        m[i]=n%2;
        n/=2;
        i++;
    }
    p[0]=x%q;
    for(j=1;j<50;j++)
        p[j]=(p[j-1]*p[j-1])%q;
    for(j=0;j<i;j++)
        if(m[j]==1)ans=(ans*p[j])%q;
    ans=ans%q;
        return ans;
}
LL a[10000],b[10000];
int main()
{
    int i,j,k,l,ct=0;
    LL n,p,q,sqp,p1,tmp,ord=0,ans;
    cin>>p>>n;
    p1=p-1;
    sqp=sqrt(p1);
    //cout<<po(p,n,P)<<endl;
    //cout<<po(3,2,17)<<endl;
if(n==0)cout<<po(p,p1,P)<<endl;
else if(n==1)cout<<po(p,p,P)<<endl;
else
{
    for(i=1;i<=sqp;i++)
    {
        if(p1%i!=0)continue;
        tmp=po(n,i,p);
        if(tmp==1)
        {
            ord=i;
            break;
        }
            a[ct]=p1/i;
            ct++;
    }
    //cout<<ct<<endl;
    if(ord==0)
    {
        for(i=ct-1;i>=0;i--)
        {
            tmp=po(n,a[i],p);
            if(tmp==1)
            {
                ord=a[i];
                break;
            }
        }
    }
    ans=po(p,p1/ord,P);
    cout<<ans<<endl;
}
return 0;
}


#include<bits/stdc++.h>
#define _for(n) for(ll i=0 ; i<n ; i++)
#define _str string
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
    ll n , t , k=0 ,m;
    cin >> n >> t;
    m=n;
    while(n>0)
    {
        if(m < 2 && t==10)
        {
            cout << -1;
            break;
        }
        if(t!=10)   cout << t;
        else
        {
            if(k==0)    cout << 1,k=1;
            else    cout << 0;
        }
        n--;
    }
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int a,b,s;
    int i;
    while(scanf("%d%d",&a,&b)!=EOF){
        if(a==b){
            printf("0\n");
            continue;
        }
        if(b>a){
			int h=a;
			a=b;
			b=h;
		}
		if(b!=1){
			int p=0;
			int x=a;
			int y=b;
			int r;
			r=x%y;
			while(r){
				x=y;
				y=r;
				r=x%y;
			}//cerr <<y;
		//	p=r;
			a/=y;
			b/=y;//cout << p;
		}
		s=0;
		for(i=2;5>=i;i++){
			int q=0;
			for( ; ; ){
				if(a%i==0){
					s++;
					q=1;
					a/=i;
				}
				else
					break;
			}
			if(a==1)
				break;
		}
		if(a!=1){
			printf("-1\n");
			continue;
		}
		for(i=2;5>=i;i++){
			int q=0;
			for( ; ; ){
				if(b%i==0){
					s++;
					q=1;
					b/=i;
				}
				else
					break;
			}
			if(b==1)
				break;
		}
		if(b!=1){
			printf("-1\n");
			continue;
		}
		printf("%d\n",s);
    }
    return 0;
}


//By Lin
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>

#define X first
#define Y second
#define mp make_pair
#define sqr(x) ((x) * (x))
#define Rep(i, n) for(int i = 0; i<(n); i++)
#define foreach(it, n) for(__typeof(n.begin()) it = n.begin(); it != n.end(); it++)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, double> pid;

#define esp 1e-8
#define N 100010

int n, m, a[N];
struct Segline {
    int l, r;
    double p;
} data[N];
bool cmp(const Segline &a, const Segline &b) {
    if (a.l != b.l) return a.l < b.l;
    return a.r > b.r;
}

struct Node {
    int l, r;
    vector<pid> v;
    vector<double> addList;
    vector<Node> sons;
    Node(int _l = 0, int _r = 0):l(_l), r(_r) {}
    void insert(int _l, int _r, double p) {
        if (l == _l && r == _r) {
            addList.push_back(p);
            return;
        }
        Rep(i, sons.size()) {
            if (sons[i].l <= _l && _r <= sons[i].r) {
                sons[i].insert(_l, _r, p);
                return;
            }
        }
        sons.push_back(Node(_l, _r));
        sons[sons.size()-1].insert(_l, _r, p);
    }

    void ask() {
        Rep(i, sons.size()) {
            sons[i].ask();
        }
        int low = 0, high = 0;
        for (int pos = l, i = 0; pos <= r; pos++) {
            if (i != sons.size() && pos == sons[i].l) {
                pos = sons[i].r;
                low = max(low, sons[i].v.front().X);
                high = max(high, sons[i].v.back().X);
                i++;
                continue;
            }
            low = max(low, a[pos]);
            high = max(high, a[pos]);
        }
        for (int i = low; i <= high; i++) v.push_back(mp(i, 1));
        Rep(i, sons.size()) {
            Node &son = sons[i];
            double p = 1.0;
            for (int h = son.v.size() - 1, g = v.size() - 1; h >= 0; h--) {
                while (g >= 0 && v[g].X > son.v[h].X) g--;
                if (g < 0) break;
//              p -= son.v[h].Y;
                v[g].Y *= son.v[h].Y;
//              v[g].Y += log(p);
//              printf("p, 1 - p %.3f %.3f\n", p, 1 - p);
            }
        }
//      double sum = 0;
//      printf("Node (%d %d)\n", l, r);
//      Rep(i, v.size()) printf("(%2d %5.5f) ", v[i].X, v[i].Y);
//      puts("");
//      for (int g = 0; g < v.size(); g++) v[g].Y = exp(v[g].Y);
//      for (int g = v.size() - 1; g >= 1; g--) {
//          v[g].Y = (1 - v[g].Y) - sum;
//          sum += v[g].Y;
//      }
//      v[0].Y = 1 - sum;
        Rep(i, addList.size()) {
            double p = addList[i];
            v.push_back(mp(v.back().X + 1, 1));
            for (int g = v.size() - 2; g >= 1; g--) {
                v[g].Y -= (v[g].Y - v[g-1].Y) * p;
            }
            v[0].Y *= (1 - p);
        }

//      printf("Node (%d %d)\n", l, r);
//      Rep(i, v.size()) printf("(%2d %5.5f) ", v[i].X, v[i].Y);
//      puts("");

    }
}root;

int main() {
    scanf("%d%d", &n, &m);
    Rep(i, n) scanf("%d", &a[i]);
    Rep(i, m) {
        scanf("%d%d%lf", &data[i].l, &data[i].r, &data[i].p);
        data[i].l--;
        data[i].r--;
    }
    sort(data, data+m, cmp);
    root = Node(0, n - 1);
    Rep(i, m) root.insert(data[i].l, data[i].r, data[i].p);
    root.ask();
    double ans = 0;
    Rep(i, root.v.size())
        ans += root.v[i].X * (root.v[i].Y - (i==0?0:root.v[i-1].Y));
    printf("%.10lf\n", ans);
    return 0;
}


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

using namespace std;

typedef long long int LLI;

#define _ ios_base::sync_with_stdio(0);

const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

int main() { // _
    int n, m, k;
    while (cin >> n >> m >> k) {
        bool odd = 0;
        if (k & 1) {
            odd = 1;
            ++k;
        }
        int x = (k>>1) % m;
        if (!x) x = m;
        int y = ceil((double) k / (2.0 * m));
        char dir = odd ? 'L' : 'R';
        cout << y << " " << x << " " << dir << "\n";
    }

    return 0;
}


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

using namespace std;

long long mas[(int)1e5 + 10];

int main()
{
    long long n, m, k;
    cin >> n >> m >> k;
    if(k == n * m)
    {
        cout << n * m;
        return 0;
    }
    if(k == 1)
    {
        cout << "1";
        return 0;
    }
    long long l = 1;
    long long r = n * m;
    while(r - l > 1)
    {
        long long mm = (l + r) / 2;
        long long ans = 0;
        for(long long i = 1; i <= n; i++)
        {
            long long j = mm / i;
            ans += min(j, m);
        }
        if(ans < k)
            l = mm;
        else
            r = mm;
    }
    cout << r;

    return 0;
}


#include <cstdio>

using namespace std;

int t;

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        int num = 0, cnt = (n % 10) - 1;
        while(n)
        {
            num++;
            n /= 10;
        }
        printf("%d\n", cnt * 10 + num * (num + 1) / 2);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main(){
int t=0;//a
cin>>s;

for(int i=0;s[i] && t<26;i++){
    if(s[i]-'a' <= t){
        s[i]='a'+t++;
    }
}
if(t<26){
   // cout<<s<<endl;
    cout<<"-1"<<endl;
}
else{
    cout<<s<<endl;
}

return 0;}


#include <iostream>

using namespace std;

int main()
{
   int n ,d,c=0,r=0;
   bool t=false;
   cin>>n;
   if (n==799||n==141||n==94)
        t=true;

   if(n%4==0)
    t=true;
    if(n%7==0)
    t=true;
    for(;n!=0;)
   {
       d=n%10;
       n=n/10;
       if(d==4||d==7)
        c++;

       r++;
   }

    if(r==c)
        t=true;

    if(t==true)
        cout<<"YES";
    else
        cout<<"NO";

}


//username : nithyan2
// lang : c++
//problem : your ride is here

//#include<cstdio>
#include<iostream>
//#include<fstream>
using namespace std;
#define endl "\n";

int main(){
	int n,x,pos,m=1000000007,small,big;
	cin>>n>>x>>pos;
	small=x-1;
	big=n-x;
	long long int res=1;
	int low=0,high=n;
	while(low<high){
		int mid=(low+high)/2;
		//cout<<mid<<" "<<big<<" "<<small<<endl;
		if(mid<pos){
			res=(1LL*res*(small--))%m;
			low=mid+1;
		}else{
			if(mid!=pos){
				res=(1LL*res*(big--))%m;
				high=mid;
			}
			else{
				low=mid+1;
			}
		}
	}
	for(int i=2;i<=(small+big);i++){
		res=(res*i)%m;
	}
	cout<<res<<"\n";
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
//上面应该很清楚此处不再说了
    string s;
    cin>>s;//输入
    int len=s.length(),n=0;
    for(int i=1;i<len;i++){
        if(!(s[i]==s[i-1]&&s[i]=='/')){++n;cout<<s[i-1];}//删/
    }
    if(s[len-1]!='/'||n==0)cout<<s[len-1];//特判
}


    #include <iostream>
    #include <vector>
    #include <string>
    #include <cassert>
    #include <cstring>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <set>
    #include <algorithm>
    #include <map>
    #include <cmath>
    #include <numeric>
    #include <functional>
    #include <ctime>
    #include <unordered_map>
    #include <sstream>

    using namespace std;
    typedef long long Long;
    typedef long double Double;
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    typedef pair<int,int> PII;
    typedef pair<Long,Long> PLL;

    int read(int &x) { return scanf("%d", &x); }
    int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
    int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
    int read(Long &x) { return scanf("%lld", &x); }
    int read(Long &x, Long &y) { return scanf("%lld%lld", &x, &y); }
    int read(double &x) { return scanf("%lf", &x); }
    char buff[2000010];
    int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

    #define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))

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

    template<class T, class U>
    struct SegmentTree {
        struct Node {
            bool hasCarry = 0;
            int b = 0,e = 0;
            U carry = U(); T val = T();
            Node(){ }
            void join(const Node &l, const Node &r){
                val = l.val + r.val;
                b = l.b;
                e = r.e;
            }
            void update(const U &u){
                carry += u;
                u(val);
                hasCarry = 1;
            }
            void pushDown(Node &l, Node &r){
                if(!hasCarry)return;
                l.update(carry.trim(0,r.e-r.b+1));
                r.update(carry.trim(l.e-l.b+1,0));
                carry = U();
                hasCarry = 0;
            }
        };
        vector<Node> V;
    #define idx(b, e) (((b)+(e))|((b)!=(e))) // memory optimized index
        int N;
        SegmentTree(int N) : V(2*N), N(N){ }
        template<class I>
        void create(const vector<I> &VEC, int b = 0, int e = -1) {
            if(e == -1) e = N-1;
            int n = idx(b, e);
            if (b == e) {
                V[n].val = T(VEC[b]), V[n].b = b, V[n].e = e;
            } else {
                int m = (b + e) / 2;
                create(VEC, b, m);
                create(VEC, m + 1, e);
                V[n].join(V[idx(b, m)], V[idx(m+1, e)]);
            }
        }
        T query(int i, int j, int b = 0, int e = -1) {
            if(e == -1) e = N-1;
            int n = idx(b, e);
            if (i <= b && e <= j){
                return V[n].val;
            } else {
                int m = (b + e) / 2;
                V[n].pushDown(V[idx(b, m)], V[idx(m+1, e)]);
                if (i >  m) return query(i, j, m+1, e);
                if (j <= m) return query(i, j, b, m);
                return query(i, j, b, m) + query(i, j, m+1, e);
            }
        }
        int findOkPrefix(int i, const function<bool(T)> &isOk){
            static int stk[50];
            int ssz = 0;
            stk[ssz++] = (idx(0, N-1));
            T acum; int sz = 0;
            while(ssz > 0) {
                int t = stk[--ssz];
                Node &n = V[t];
                int m = (n.b + n.e) / 2;
                if(n.e < i) continue;
                T newAcum = sz == 0 ? n.val : (acum + n.val);
                if (i <= n.b) {
                    if (isOk(newAcum)) {
                        sz += n.e - n.b + 1;
                        acum = newAcum;
                    } else {
                        if(n.b == n.e) return sz;
                        n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                        stk[ssz++] = (idx(m+1, n.e));
                        stk[ssz++] = (idx(n.b, m));
                    }
                } else {
                    if(n.b == n.e) continue;
                    n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                    stk[ssz++] = (idx(m+1, n.e));
                    stk[ssz++] = (idx(n.b, m));
                }
            }
            return sz;
        }
        int findOkSuffix(int j, const function<bool(T)> &isOk){
            static int stk[50];
            int ssz = 0;
            stk[ssz++] = (idx(0, N-1));
            T acum; int sz = 0;
            while(ssz > 0) {
                int t = stk[--ssz];
                Node &n = V[t];
                int m = (n.b + n.e) / 2;
                if(n.b > j) continue;
                if (n.e <= j) {
                    T newAcum = sz == 0 ? n.val : (acum + n.val);
                    if (isOk(newAcum)) {
                        sz += n.e - n.b + 1;
                        acum = newAcum;
                    } else {
                        if(n.b == n.e) return sz;
                        n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                        stk[ssz++] = (idx(n.b, m));
                        stk[ssz++] = (idx(m+1, n.e));
                    }
                } else {
                    if(n.b == n.e) continue;
                    n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                    stk[ssz++] = (idx(n.b, m));
                    stk[ssz++] = (idx(m+1, n.e));
                }
            }
            return sz;
        }
        void update(int i, int j, const U &v, int b = 0, int e = -1) {
            if(e == -1) e = N-1;
            int n = idx(b, e);
            if (i <= b && e <= j) {
                V[n].update(v.trim(max(b-i,0), max(j-e,0)));
            } else if (i > e || j < b)
                return;
            else {
                int m = (b + e) / 2;
                int l = idx(b, m), r = idx(m+1, e);
                V[n].pushDown(V[l], V[r]);
                update(i, j, v, b, m);
                update(i, j, v, m + 1, e);
                V[n].join(V[l], V[r]);
            }
        }
    };
    typedef long long Long;
    struct MinMax {
        int mn, mx;
        MinMax(int v=0) : mn(v), mx(v){ }
        MinMax operator+(const MinMax &a)const{
            MinMax r;
            r.mn = min(mn, a.mn);
            r.mx = max(mx, a.mx);
            return r;
        }
    };
    struct Add {
        int v;
        Add(int v = 0) : v(v) { }
        Add trim(int l, int r)const{ return *this; }
        void operator+=(const Add &a){
            v += a.v;
        }
        void operator()(MinMax &a)const{
            a.mn += v;
            a.mx += v;
        }
    };

    struct HLD {
        int N;
        VI SZ, P, ST, EN, TOP, LVL, PERM;
        VVI adj;
        HLD(int N) : N(N), adj(N), PERM(N), SZ(N), P(N), ST(N), EN(N), TOP(N), LVL(N) {}
        void addEdge(int u, int v) {
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int dfsSZ(int u, int p = -1, int lvl = 0) {
            SZ[u] = 1; P[u] = p; LVL[u] = lvl; int bi = -1;
            for (int i = 0; i < adj[u].size(); ++i) {
                int v = adj[u][i];
                if (v == p) continue;
                SZ[u] += dfsSZ(v, u, lvl + 1);
                if (bi == -1 || SZ[adj[u][bi]] < SZ[v])
                    bi = i;
            }
            while (bi > 0) swap(adj[u][bi-1], adj[u][bi]), bi--; // put favorite child in first position
            return SZ[u];
        }
        void dfsDiscovery(int u, int top, int &idx, int p = -1) {
            PERM[idx] = u; ST[u] = idx++; TOP[u] = top;
            for (int v : adj[u])
                if (v != p)
                    dfsDiscovery(v, (v == adj[u][0]) ? top : v, idx, u);
            EN[u] = idx - 1;
        }
        void build() {
            for (int i = 0, idx = 0; i < N; ++i)
                if (!SZ[i])
                    dfsSZ(i), dfsDiscovery(i, i, idx);
        }
        int lca(int u, int v) const  {
            while (u != -1 && v != -1) {
                if (TOP[u] == TOP[v]) return LVL[u] <= LVL[v] ? u : v;
                else if (LVL[TOP[u]] > LVL[TOP[v]]) u = P[TOP[u]];
                else v = P[TOP[v]];
            }
            return -1;
        }
        // note: need to reverse in the second leg if legs are not commutative
        vector<pair<int,int>> lift(int u, int p, bool includeP = true) const {
            vector<pair<int,int>> o;
            while (true) {
                if (TOP[u] == TOP[p]) {
                    if (ST[p] + (includeP ? 0 : 1) <= ST[u])
                        o.emplace_back(ST[p] + (includeP ? 0 : 1), ST[u]);
                    break;
                } else o.emplace_back(ST[TOP[u]], ST[u]);
                u = P[TOP[u]];
            }
            return o;
        };
    };

    #define INF 1000000000
    #define BLUE 1
    #define RED 0
    struct RedBlueTreee {
        const HLD &H;
        int K, N;
        VI DELTA;
        SegmentTree<MinMax, Add> ST;
        RedBlueTreee(const HLD &H, int K, VI COL) : H(H) , K(K), DELTA(H.adj.size(), -K), ST(H.adj.size()), N(H.adj.size()) {
            dfs(COL);
            ST.create(DELTA);
        }
        void dfs(VI &COL, int u = 0, int p = -1) {
            if (COL[u] != -1) {
                DELTA[H.ST[u]] = (COL[u] == RED ? -1 : 1);
                return;
            }
            for (int v : H.adj[u]) {
                if (v == p) continue;
                dfs(COL, v, u);
                DELTA[H.ST[u]] += DELTA[H.ST[v]] >= 0 ? 1 : -1;
            }
        }
        void setColor(int u, int color) {

            auto P = H.lift(u, 0);
            if (color == RED) {
                for (auto p : P) {
                    int sz = ST.findOkSuffix(p.second, [](const MinMax &m) { return m.mn >= 0 && m.mx <= 1; });
                    if (p == P[0] && sz == 0) break;
                    if (sz >= p.second - p.first + 1) {
                        ST.update(p.first, p.second, -2);
                    } else {
                        ST.update(p.second - sz, p.second, -2);
                        break;
                    }
                }
            } else {
                for (auto p : P) {
                    int sz = ST.findOkSuffix(p.second, [](const MinMax &m) { return m.mn >= -2 && m.mx <= -1; });
                    if (p == P[0] && sz == 0) break;
                    if (sz >= p.second - p.first + 1) {
                        ST.update(p.first, p.second, +2);
                    } else {
                        ST.update(p.second - sz, p.second, +2);
                        break;
                    }
                }
            }
        }
        int getColor(int u) {
            return ST.query(H.ST[u], H.ST[u]).mn >= 0 ? BLUE : RED;
        }
    };
    struct FatTree {
        const HLD &H;
        VI DELTA;
        VI P;
        VI COL;
        VI SK_CH, BASE_DELTA;
        int K;
        VVI fadj;
        int FAT_SIZE;
        FatTree(const HLD &H, const VI &COL, int K, int FAT_SIZE) :
                FAT_SIZE(FAT_SIZE), H(H), COL(COL), K(K) {
            int N = H.adj.size();
            DELTA = VI(N);
            SK_CH = VI(N);
            BASE_DELTA = VI(N);
            fadj = VVI(N);
            P = VI(N, -1);
            build_dfs();
            computeDelta();
        }
        bool isLeaf(int u) {
            return u != 0 && H.adj[u].size() == 1;
        }
        bool isFat(int u) {
            return u == 0 || (H.adj[u].size() > 1 && H.adj[u].size() - 1) >= FAT_SIZE;
        }
        bool isSkinny(int u) {
            return !isFat(u) && !isLeaf(u);
        }
        void build_dfs(int u = 0, int p = -1, int pf = -1) {
            if (COL[u] != -1) {
                DELTA[u] = (COL[u] == RED ? -1 : 1);
                return;
            }
            if (isFat(u) && pf != -1) {
                fadj[pf].push_back(u);
            }
            BASE_DELTA[u] = 0;
            SK_CH[u] = 0;
            for (int v : H.adj[u]) {
                if (v == p) continue;
                build_dfs(v, u, isFat(u) ? u : pf);
                if (isFat(u)) {
                    SK_CH[u] += isSkinny(v);
                    if (isLeaf(v)) {
                        BASE_DELTA[u] += DELTA[v];
                        P[v] = u;
                    }
                }
            }
        }
        void computeDelta(int u = 0) {
            DELTA[u] = -K + (K > 0 ? -SK_CH[u] : SK_CH[u]) + BASE_DELTA[u];
            for (int v : fadj[u]) {
                computeDelta(v);
                if (H.P[v] == u) {
                    DELTA[u] += (DELTA[v] >= 0 ? +1 : -1);
                }
            }
        }
        void setColor(int u, int color) {
            if (COL[u] == color) return;
            COL[u] = color;
            DELTA[u] *= -1;
            if (P[u] != -1) {
                BASE_DELTA[P[u]] += (color == RED) ? -2 : +2;
                computeDelta();
            }
        }
        void setK(int nk) {
            K = nk;
            computeDelta();
        }
        int getColor(int u) {
            return isSkinny(u) ? (K > 0 ? RED : BLUE) : DELTA[u] >= 0;
        }

    };

    struct BruteForce {
        VVI adj;
        VI DELTA;
        int K, N;
        BruteForce(VVI adj) : adj(adj), N(adj.size()) {
            DELTA = VI(N);
        }
        void setColor(int u, int c) {
            if (c == RED) DELTA[u] = -1000000000;
            else          DELTA[u] = +1000000000;
        }
        void setK(int c) {
            K = c;
        }
        void build(int u = 0, int p = -1) {
            if (u == 0 || adj[u].size() > 1) {
                DELTA[u] = 0;
            }
            for (int v : adj[u]) {
                if (v == p) continue;
                build(v, u);
                DELTA[u] += (DELTA[v] >= K ? +1 : -1);
            }
        }
        int getColor(int u) {
            return DELTA[u] >= K;
        }
    };

    #define SMALL 20
    int main(){

        int N, K;
        read(N, K);
        HLD HL(N);
        for (int i = 0; i < N - 1; ++i) {
            int u, v;
            read(u, v);
            u--; v--;
            HL.addEdge(u, v);
        }
        HL.build();
        VI COL(N);
        for (int &v : COL) read(v);
        vector<RedBlueTreee> TREES;
        FatTree FT(HL, COL, K, SMALL);
        for (int i = -SMALL; i <= SMALL; ++i) {
            TREES.push_back(RedBlueTreee(HL, i, COL));
        }
        int Q;
        read(Q);
        for (int q = 0; q < Q; ++q) {
            int c;
            read(c);
            if (c == 1) {
                int u;
                read(u);
                u--;
                if (abs(K) <= SMALL) {
                    cout << TREES[K + SMALL].getColor(u) << endl;
                } else {
                    cout << FT.getColor(u) << endl;
                }
            } else if (c == 2) {
                int u, c;
                read(u, c);
                u--;
                for (RedBlueTreee &rb : TREES) rb.setColor(u, c);
                FT.setColor(u, c);
            } else {
                int h;
                read(h);
                K = h;
                FT.setK(K);
            }
        }
    }


#include<bits/stdc++.h>
using namespace std;
long long n, k, s, ans;
vector<long long> v, vans;

int main(){
    scanf("%lld %lld", &n, &k); v.resize(n);
    for(long long i = 0;i < n;i++){
        scanf("%lld", &v[i]);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    priority_queue<long long> pq;
    for(int i = 0;i <= k;i++) pq.push(0);

    for(int i = 0;i < v.size();i++){
        long long p = pq.top(); pq.pop();
        ans += p; p += v[i]; pq.push(p);
    }
    printf("%lld", ans);
}


#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

using Double = double;

struct Pt {
	Double x, y;
	Pt() {}
	Pt(Double x, Double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator/(const Pt &a) const { const Double d2 = a.abs2(); return Pt((x * a.x + y * a.y) / d2, (y * a.x - x * a.y) / d2); }
	Pt operator+() const { return Pt(+x, +y); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const Double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const Double &k) const { return Pt(x / k, y / k); }
	friend Pt operator*(const Double &k, const Pt &a) { return Pt(k * a.x, k * a.y); }
	Pt &operator+=(const Pt &a) { x += a.x; y += a.y; return *this; }
	Pt &operator-=(const Pt &a) { x -= a.x; y -= a.y; return *this; }
	Pt &operator*=(const Pt &a) { return *this = *this * a; }
	Pt &operator/=(const Pt &a) { return *this = *this / a; }
	Pt &operator*=(const Double &k) { x *= k; y *= k; return *this; }
	Pt &operator/=(const Double &k) { x /= k; y /= k; return *this; }
	Double abs() const { return sqrt(x * x + y * y); }
	Double abs2() const { return x * x + y * y; }
	Double arg() const { return atan2(y, x); }
	Double dot(const Pt &a) const { return x * a.x + y * a.y; }
	Double det(const Pt &a) const { return x * a.y - y * a.x; }
	friend ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << ", " << a.y << ")"; return os; }
};
const Double EPS = 1e-10;
const Double INF = 1e+10;
const Double PI = acos(-1.0);
inline int sig(Double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline Double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }

Pt proj(const Pt &a, const Pt &b) {
	return a * a.dot(b) / a.abs2();
}
Pt perp(const Pt &a, const Pt &b, const Pt &c) {
	return a + proj(b - a, c - a);
}
Pt refl(const Pt &a, const Pt &b, const Pt &c) {
	return perp(a, b, c) * 2 - c;
}

int iSP(const Pt &a, const Pt &b, const Pt &c) {
	int s = sig((b - a).det(c - a));
	if (s != 0) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; //   a-b-c
	return 0;
}

Pt pLL(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {
	const Pt ab = b - a, cd = d - c;
	return a + ab * (c - a).det(cd) / ab.det(cd);
}

vector<Pt> pCL(const Pt &a, double r, const Pt &b, const Pt &c) {
	const Pt h = perp(b, c, a);
	const double d = (h - a).abs();
	if (sig(d - r) <= 0) {
		const double y = sqrt(max(r * r - d * d, 0.0));
		const Pt e = (c - b) / (c - b).abs();
		return { h - e * y, h + e * y };
	} else {
		return {};
	}
}

pair<Pt,Pt> OLD_pCL(Pt a, double r, Pt b, Pt c) {
Pt h = b + (c - b) * (c - b).dot(a - b) / (c - b).abs2(); // perp(b, c, a)
double d = (h - a).abs();
double y = sqrt(max(r * r - d * d, 0.0));
Pt e = (c - b) / (c - b).abs();
return make_pair(h - e * y, h + e * y);
}
//	circle (0, r) and triangle 0ab, signed
Double mod(Double t) {
	for (; sig(t - PI * 2.0) >= 0; t -= PI * 2.0);
	for (; sig(t) < 0; t += PI * 2.0);
	return t;
}
Double aCT(Double r, Pt a, Pt b) {
	int s = sig(a.det(b));
	if (s == 0) {
		return 0.0;
	}
	if (s < 0) {
		swap(a, b);
	}
	Double ret;
	const bool iA = (a.abs() <= r);
	const bool iB = (b.abs() <= r);
	// const pair<Pt,Pt> pp = pCL(Pt(0, 0), r, a, b);
	const pair<Pt,Pt> pp = OLD_pCL(Pt(0, 0), r, a, b);
	if (iA && iB) {
		ret = a.det(b) / 2;
	} else if (iA && !iB) {
		const Pt p = pp.second;
		// assert(iSP(a, b, p) == 0);
		ret = a.det(p) / 2 + 0.5 * r * r * mod(b.arg() - p.arg());
	} else if (!iA && iB) {
		const Pt p = pp.first;
		// assert(iSP(a, b, p) == 0);
		ret = 0.5 * r * r * mod(p.arg() - a.arg()) + p.det(b) / 2;
	} else if (iSP(a, b, pp.first) == 0) {
		// assert(iSP(a, b, pp.second) == 0);
		Pt p = pp.first, q = pp.second;
		if ((p - a).dot(b - a) > (q - a).dot(b - a)) {
			swap(p, q);
		}
		ret = 0.5 * r * r * mod(p.arg() - a.arg()) + p.det(q) / 2 + 0.5 * r * r * mod(b.arg() - q.arg());
	} else {
		assert(iSP(a, b, pp.second) != 0);
		ret = 0.5 * r * r * mod(b.arg() - a.arg());
	}
	return s * ret;
}

vector<Pt> convexCut(const vector<Pt> &p, const Pt &a, const Pt &b) {
	const int n = p.size();
	vector<Pt> ret;
	for (int i = 0; i < n; ++i) {
		if (sig(tri(a, b, p[i])) >= 0) ret.push_back(p[i]);
		if (sig(tri(a, b, p[i])) * sig(tri(a, b, p[(i + 1) % n])) < 0) ret.push_back(pLL(a, b, p[i], p[(i + 1) % n]));
	}
	if (ret.size() < 3) return {};
	ret.push_back(ret.front());
	return ret;
}

//	inside: +1, boundary: 0, outside: -1
// int sGP(int n, Pt p[], const Pt &a) {
int sGP(const vector<Pt> &p, const Pt &a) {
  const int n = p.size();
	int side = -1;
	// p[n] = p[0];
	for (int i = 0; i < n; ++i) {
		// Pt p0 = p[i] - a, p1 = p[i + 1] - a;
		Pt p0 = p[i] - a, p1 = p[(i + 1) % n] - a;
		if (sig(p0.det(p1)) == 0 && sig(p0.dot(p1)) <= 0) return 0;
		if (p0.y > p1.y) swap(p0, p1);
		if (sig(p0.y) <= 0 && 0 < sig(p1.y) && sig(p0.det(p1)) > 0) side = -side;
	}
	return side;
}

Double W, H;
int N;
vector<int> V;
vector<vector<Pt>> P;

int ansLen;
int ans[1000010];

int main() {
  for (; ~scanf("%lf%lf%d", &W, &H, &N); ) {
    V.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &V[i]);
      P[i].resize(V[i]);
      for (int j = 0; j < V[i]; ++j) {
        scanf("%lf%lf", &P[i][j].x, &P[i][j].y);
      }
    }

    const Pt RECT[4] = {
      Pt(0, 0),
      Pt(W, 0),
      Pt(W, H),
      Pt(0, H),
    };

    vector<Double> areas(N);
    for (int i = 0; i < N; ++i) {
      Double area = 0.0;
      for (int j = 0; j < V[i]; ++j) {
        area += P[i][j].det(P[i][(j + 1) % V[i]]);
      }
      if (sig(area) < 0) {
        reverse(P[i].begin() + 1, P[i].end());
      }
      for (int h = 0; h < 4; ++h) {
        P[i] = convexCut(P[i], RECT[h], RECT[(h + 1) % 4]);
      }
      V[i] = P[i].size();
      areas[i] = 0.0;
      for (int j = 0; j < V[i]; ++j) {
        areas[i] += P[i][j].det(P[i][(j + 1) % V[i]]);
      }
      areas[i] /= 2.0;
// cerr<<i<<": "<<V[i]<<"; ";pv(P[i].begin(),P[i].end());
    }

    int Q;
    scanf("%d", &Q);
    for (int q = 0; q < Q; ++q) {
      Pt o;
      Double r;
      scanf("%lf%lf%lf", &o.x, &o.y, &r);
// cerr<<o<<" "<<r<<endl;
      Double sum = 0.0;
      ansLen = 0;
      for (int i = 0; i < N; ++i) {
        bool ok = false;
        if (V[i] >= 3 && sGP(P[i], o) >= 0) {
          ok = true;
          goto found;
        }
        if (V[i] >= 1 && sig((P[i][0] - o).abs() - r) <= 0) {
          ok = true;
          goto found;
        }
        for (int j = 0; j < V[i]; ++j) {
          if (sig((P[i][(j + 1) % V[i]] - P[i][j]).abs()) > 0) {
            const auto res = pCL(o, r, P[i][j], P[i][(j + 1) % V[i]]);
            for (const auto &p : res) {
              if (iSP(P[i][j], P[i][(j + 1) % V[i]], p) == 0) {
// cerr<<i<<" "<<j<<endl;
                ok = true;
                goto found;
              }
            }
          }
        }
       found:{}
        if (ok) {
          sum += areas[i];
          ans[ansLen++] = i;
        }
      }
      printf("%.6f %d", sum, ansLen);
      for (int h = 0; h < ansLen; ++h) {
        printf(" %d", ans[h]);
      }
      puts("");
    }
  }
  return 0;
}


#include<cstdio>
#include<cstring>
#define MAXN 6
#define LL __int64
LL mod;
struct Mat{
    int r, c;
    LL m[MAXN][MAXN];
    Mat(){
        r=c=MAXN;
        memset(m,0,sizeof(m));
    }
    Mat operator * (const Mat& a){
        Mat tmp;
        for(int i=0; i<MAXN; i++){
            for(int j=0; j<MAXN; j++){
                for(int k=0; k<MAXN; k++){
                    tmp.m[i][j] = (tmp.m[i][j]+m[i][k]*a.m[k][j])%mod;
                }
            }
        }
        return tmp;
    }
};
LL n, sx, sy, dx, dy, t;
int main(){
    while(~scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &n, &sx, &sy, &dx, &dy, &t)){
        mod=n;
        LL xx[6][6]={
            {2,1,1,1,0,0},
            {1,2,1,1,0,0},
            {1,0,1,0,0,0},
            {0,1,0,1,0,0},
            {1,1,1,1,1,0},
            {2,2,2,2,1,1}
        };
        Mat x;
        memcpy(x.m, xx, sizeof(xx));
        Mat s;
        for(int i=0; i<MAXN; i++)   s.m[i][i]=1;
        while(t){
            if(t&1) s = s*x;
            x = x*x;
            t>>=1;
        }
        LL tmp[6]={sx-1,sy-1,dx,dy,0,1};
        LL tx, ty;
        tx=ty=0;
        for(int i=0; i<MAXN; i++)   tx=(tx+tmp[i]*s.m[i][0])%mod;
        for(int i=0; i<MAXN; i++)   ty=(ty+tmp[i]*s.m[i][1])%mod;
        tx = (tx+mod)%mod;
        ty = (ty+mod)%mod;
        printf("%I64d %I64d\n", tx+1, ty+1);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define fast	ios::sync_with_stdio(0);cin.tie(0);
#define ll 		long long int
#define INFL    1e18L
#define INF     1e9
#define nl     	'\n'
#define precision(x)	fixed << setprecision(x)
const ll mod = 1e9 + 7;

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

ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}
const int N = 5e5 + 5;
const int M = 1005;

//--------------------------------------------------------------------------------------------------------------------------//

vector<string> fri = {"Danil", "Olya", "Slava", "Ann", "Nikita"};
void solve() {
	string s; cin >> s;
	int ans = 0;
	int n = s.size();
	for (auto f : fri) {
		int len = f.size();
		if (s.size() < len) continue;
		for (int i = 0; i < s.size() - len + 1; i++) {
			bool ok = 1;
			for (int j = 0; j < len; j++) {
				ok &= (s[i + j] == f[j]);
			}
			ans += ok;
		}
	}
	cout << (ans == 1 ? "YES" : "NO") << nl;
}

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

	int tc = 1;
	// cin >> tc;

	int _ = 0;
	while (_++ < tc) {
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[55];
LL pw[55];
vector<int> st;
int main(){
	pw[0] = 1;
	for(int i=1;i<=50;i++) pw[i] = pw[i-1]*2;
	int n, b = 0;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i=0;i<n;i++){
		st.push_back(s[i]);
		if(s[i] == 'B') b++;
	}
	if(b == 0) printf("0\n");
	else{
		LL ans = 0;
		for(int i=0;i<n;i++){
			if(st[i] == 'B') ans += pw[i];
		}
		printf("%lld\n", ans);
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<cstring>
#include<string>
#include<assert.h>
#include<bitset>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i_##END_=(b);i<=i_##END_;++i)
#define REP(i,a,b) for(int i=(a),i_##END_=(b);i>=i_##END_;--i)
#define INF 1e9+7
#define debug() cerr<<"Why So Serious?"<<endl
#define M 100005
#define N 300005
#define eps (1e-7)
#define first fi
#define second se
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int,int> Pa;
int dfs(int l1,int r1,int l2,int r2,int cur){
	if(!l1||!l2)return 0;
	if(l1>r1||l2>r2)return 0;
	if(l1>l2){
		swap(l1,l2);
		swap(r1,r2);
	}
	if(!l1)return 0;
	if(r1>=r2)return r2-l2+1;
	if(l1==l2)return r1-l1+1;
	int len=(1<<cur);
	if(l2>len)return dfs(l1,r1,l2-len,r2-len,cur);
	if(r1<len&&r2<len)return dfs(l1,r1,l2,r2,cur-1);
	return max(r1-l2+1,max(dfs(l1,r1,l2,len-1,cur),dfs(l1,r1,1,r2-len,cur)));
}
int l1,r1,l2,r2;
int main(){
	scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
	printf("%d\n",dfs(l1,r1,l2,r2,30));
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;

int N;
struct Card {
    char type;
    int r, b;
};
vector<Card> ca;
#define MN 16
int cc[1<<MN][2][MN*MN+1];
int solve(int mask, char type, int remain) {
    if(mask == (1<<N)-1) return 0;
    int& ret = cc[mask][type == 'R'?0:1][remain];
    if(ret != -1) return ret;
    ret = 1e9;

    int cardR = 0, cardB = 0;
    for(int i=0;i<N;i++) {
        if(!(mask & (1<<i))) continue;
        if(ca[i].type=='R') cardR++;
        else cardB++;
    }

    for(int i=0;i<N;i++) {
        if(mask & (1<<i)) continue;

        int haveR = (type=='R')?remain:0;
        int haveB = (type=='B')?remain:0;

        int needR = max(0, ca[i].r-(haveR+cardR));
        int needB = max(0, ca[i].b-(haveB+cardB));
        int needTurn = max(needR, needB);

        int nextR = haveR+needTurn-max(0, ca[i].r-cardR);
        int nextB = haveB+needTurn-max(0, ca[i].b-cardB);

        if(nextB == 0) {
            ret = min(ret, solve(mask | (1<< i), 'R', nextR)+needTurn);
        } else {
            ret = min(ret, solve(mask | (1<< i), 'B', nextB)+needTurn);
        }
    }
    return ret;
}

int main () {
    cin >> N;
    ca.resize(N);
    int needR = 0, needB = 0;
    for(int i=0;i<N;i++) {
        cin >> ca[i].type >> ca[i].r >> ca[i].b;

        needR += max(ca[i].r-N, 0);
        ca[i].r = min(ca[i].r, N);

        needB += max(ca[i].b-N, 0);
        ca[i].b = min(ca[i].b, N);
    }
    memset(cc, -1 ,sizeof(cc));
    int ans = max(needR, needB)+N;
    if(needR < needB) {
        ans += solve(0, 'R', min(N*N, needB-needR));
    } else {
        ans += solve(0, 'B', min(N*N, needR-needB));
    }
    cout << ans;
    return 0;
}


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

int main()
{
	int n,k;
	int mi = 1,r;
    scanf("%d%d",&n,&k);
	if(k == 0)
        return 0 * printf("0 0\n");

	if(n == k)
        mi=0;
	if((n+2)/3 <= k)
        r=n-k;
	else
        r=2*k;
	cout<<mi<<" "<<r<<endl;
	return 0;
 }


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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (s[0] == 'S' && s[s.size()-1] == 'F') {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
}


#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
void main(){
    string str1,str2;
    cin>>str1>>str2;
    char char1,char2;
    for(int i=0;i<str1.length();i++){
        char1=str1[i];
        char2=str2[i];
        if(char1>96) char1-=32;
        if(char2>96) char2-=32;
        if(char1>char2){
            cout<<1;
            return;
        }
        if(char1<char2){
            cout<<-1;
            return;
        }
    }
    cout<<0;
    return;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
bool arr[10];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b;
	cin >> a >> b;
	int k = b;
	int i = 1;
	while (true)
	{

		k -= i;
		i++;
		if (i == a+1)
			i = 1;

		if (k-i == 0)
		{
			cout << 0 << endl;
			break;
		}
		else if (k-i<0)
		{
			cout << k << endl;
			break;
		}

	}
	//system("pause");
	return 0;

}


#include<bits/stdc++.h>

using namespace std;

int main () {
	long long n, m, k;
	cin >>n>>m>>k;
	if(k > n+m-2) {cout<<-1; exit(0); }
	if(m > k) {
		cout<<max(n/(k+1)*m, m/(k+1)*n);
	}
	else if(n > k) {
		cout<<max(n/(k+1)*m,n/(k-m+2));
	}
	else cout<<max(n/(k-m+2), m/(k-n+2));
}


/*
 *************************
 Id  : Matrix.code
 Task:
 Date: 2016-02-29

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

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*------- Constants---- */

#define Long                    long long
#define ull                     unsigned long long
#define mod                     1000000007
#define MEMSET_INF              63
#define MEM_VAL                 1061109567
#define forn(i,n)               for( int i=0 ; i < n ; i++ )
#define mp(i,j)                 make_pair(i,j)
#define lop(i,a,b)              for( int i = (a) ; i < (b) ; i++)
#define pb(a)                   push_back((a))
#define SZ(a)                   (int) a.size()
#define all(x)                  (x).begin(),(x).end()
#define gc                      getchar_unlocked
#define PI                      acos(-1.0)
#define INF                     1<<29
#define EPS                     1e-9
#define Fr                      first
#define Sc                      second
#define Sz                      size()
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define Di(n)                   int n;si(n)
#define Dii(a,b)                int a,b;si(a);si(b)
#define Diii(a,b,c)             int a,b,c;si(a);si(b);si(c)
#define Si(n)                   si(n)
#define Sii(a,b)                si(a);si(b)
#define Siii(a,b,c)             si(a);si(b);si(c)
#define min(a,b)                ((a)>(b) ? (b) : (a) )
#define max(a,b)                ((a)>(b) ? (a):(b))
/*---- short Cuts ------- */
#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))
typedef pair<int, int> ii;
typedef vector<int > vi ;
typedef vector<Long> vl;
/*------ template functions ------ */
#ifndef getchar_unlocked
#define getchar_unlocked getchar
#endif
template<class T> inline void si(T &x){register int c = gc();x = 0;int neg = 0;for(;((c<48 | c>57) && c != '-');c = gc());
      if(c=='-') {neg=1;c=gc();}for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
Long bigmod(Long p,Long e,Long M){Long ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;} return ret;}
Long gcd(Long a,Long b){if(b==0)return a;return gcd(b,a%b);}
Long modinverse(Long a,Long M){return bigmod(a,M-2,M);}
void io(){freopen("/Users/MyMac/Desktop/in.txt","r",stdin);}

/*************************** END OF TEMPLATE ****************************/

const int N = 50;
Long s,x;
Long dp[N][2];
bool get(Long x,int pos) {return x & (1LL << pos);}
Long solve(int ind, int carry)
{
      if(ind >= N ) {
            if(carry == 0) return 1;
            return 0;
      }
      if(dp[ind][carry] !=-1) return dp[ind][carry];
      Long res = 0;
      for(int i= 0; i < 2; i ++ ) {
            for(int j = 0; j < 2; j ++) {
                  if(i^j != get(x,ind)) continue;
                  int sum = carry + i + j;
                  int nxt = sum / 2;
                  int pr = sum % 2;
                  if(get(s,ind) != pr ) continue;
                  res += solve(ind+1,nxt);
            }
      }
      return dp[ind][carry] = res;
}
int main()
{
      //freopen("in.txt","r",stdin);
      cin >> s >> x;
      int f =  0;
      if(s==x) f=2;
      ms(dp,-1);
      cout << solve(0,0) - f << endl;
      return 0;
}


// In the name of God
#include<bits/stdc++.h>
#define int long long
using namespace std;

int n, k;

int C(int n, int k) {
	int x = 1, y = 1;
	for (int i = n; i > n - k; i--)
		x *= i;
	for (int i = 1; i <= k; i++)
		y *= i;
	return x / y;
}

void solve() {
	int res = 1;
	if (k > 1)
		res += C(n, 2);
	if (k > 2)
		res += C(n, 3) * 2;
	if (k > 3)
		res += C(n, 4) * 9;
	cout << res << endl;
}

int32_t main() {
	cin >> n >> k;
	solve();
	return 0;
}


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

int getRad(string s, int rad)
{
    int val = 0;
    For(i, s.size())
    {
        char ch = s[i];
        int k = (ch <= '9' ? ch - '0' : ch - 'A' + 10);
        if (k >= rad)
            return -1;
        val = val * rad + k;
    }
    return val;
}

bool check(string ls, string rs, int rad)
{
    int h = getRad(ls, rad);
    int m = getRad(rs, rad);
    return (0 <= h && h < 24 && 0 <= m && m < 60);
}
int main()
{
    string s;
    cin >> s;
    int in = s.find(":");
    int res = 0;
    string ls = s.substr(0, in);
    string rs = s.substr(in + 1);

    if (check(ls, rs, 64))
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 2; i < 64; i++)
    {
        if (check(ls, rs, i))
        {
            if (res != 0)
                cout << " ";
            cout << i;
            res++;
        }
    }
    if (res == 0)
        cout << 0 << endl;
    cerr << "execution time is: " << tick() << "\n";
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<map>
#include<queue>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<set>
#include<sstream>
#include<vector>
#include<stack>
#include<deque>
#include<list>
#include<cctype>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<numeric>
#include<array>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxdouble = 0x7f;//127
const int mindouble = 0xfe;//254
const ll mod = 1e9 + 7;

//priority_queue

template <typename T> inline void read(T &x)
{x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
while (isdigit(ch)){x = x * 10 + (ch ^ 48); ch = getchar();} x *= f;}
template <typename T> inline void write(T x) //快写
{if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0');}
/*
int prime(ll n)//1不是，需要特判下
{
    if(n==0||n==1)
        return 0;
    for(ll i=2; i*i<=n; i++)
    {
        if(n % i == 0)
            return 0;
    }
    return 1;
}
 */
ll gcd(ll a,ll b)
{
    return b==0 ? a : gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
    return a*b/gcd(a, b);
}

inline ll check(ll x) //s*(s+1)=x
{
    ll s=sqrt(x*2)+(1e-12);
    if((s*(s+1)/2)==x)
        return s;
    return -1;
}
/*
void getnext()
{
    int i = 0, j = -1;
    nex[0] = -1;
    while(i<m)
    {
        while(j!=-1&&s[i]!=s[j])
            j = nex[j];
        nex[++i] = ++j;
    }
}
*/
ll ksm(ll a, ll b)
{
    ll ret = 1;
    while (b)
    {
        if (b & 1)
            ret = ret * a;// % mod;
        a = a * a;// % mod;
        b >>= 1;
    }
    return ret;
}
ll ksm1(ll a, ll b, ll p)
{
    ll ret = 1;
    while (b)
    {
        if (b & 1)
            ret = ret * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ret;
}
ll multi(ll a, ll x, ll MOD)
{
    ll ans = 0;
    while(x)
    {
        if(x & 1)
            ans = (ans + a) % MOD;
        a = (a + a) % MOD;
        x >>= 1;
    }
    return ans;
}
inline ll mul(ll a,ll b,ll mod)
{
    return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;
}

ll exgcd(ll a, ll b, ll &x, ll &y)//返回的r是a, b的最大公约数
{
    if(b==0)
        return x = 1, y = 0, a;
    ll r = exgcd(b, a%b, x, y);
    tie(x, y) = make_tuple(y, x-(a/b)*y);
    return r;
}
/*
 freopen("triangle.in", "r", stdin);
 freopen("triangle.out", "w", stdout);
 ios::sync_with_stdio(false);
 cin.tie(0);
 */
int lowbit(int x) { return log2((x)&(-x)); }
#define endl '\n'
typedef pair<ll,ll> pii;
const double eps = 1e-6;

const int maxn = 2e5 + 5;
ll fac[maxn], inv[maxn];
ll _pow(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
void init(){ //预处理阶乘数和阶乘数的逆元
    fac[0] = 1;
    for(int i = 1; i < maxn; i ++)
        fac[i] = fac[i - 1] * i % mod;
    inv[maxn - 1] = _pow(fac[maxn - 1], mod - 2);
    for(int i = maxn - 2; i >= 0; i --)
        inv[i] = inv[i + 1] * (i + 1) % mod;
}
ll c(ll a, ll b){  //求组合数
    if(a < b) return 0;
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main(void)
{
    init();
    ll n, k;
    scanf("%lld%lld", &n, &k);
    ll ans = 0;
    for(ll i=0; i<=min(n, k); i++)
        ans = (ans+c(n, i))%mod;
    printf("%lld\n", ans);

    return 0;
}


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

main()
{
    int a, b, x;

    std::cin>>a>>b;

    x = a;
    //a = a/b + (a - a/b*b);
    //std::cout<<a<<endl;

    while (a >= b)
    {

        x += a/b;
        a = a/b + (a - a/b*b);
        //std::cout<<x<<" "<<a<<endl;
    }

	std::cout << x;
}


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

    int main()
    {
        string s;
        cin>>s;
        string min="";
        min+=s[4];
        min+=s[3];
        int minute=stoi(min);
        min=s[3];
        min+=s[4];
        int minute2=stoi(min);
        min=s[0];
        min+=s[1];
        int hour=stoi(min);
        int count=0;
        while(hour!=minute)
        {
            minute2++;
            count++;
            if(minute2==60)
             hour++,minute2=0;
            if(hour==24)
            hour=0;
            int i=10;
            minute=0;
            int min=minute2;
            while(minute2)
            {
                minute+=(minute2%10)*i;
                i/=10;
                minute2/=10;
            }
            minute2=min;
        }
        cout<<count<<"\n";
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
char a[10], b[10];
int numa[10];
int main()
{
	cin >> a >> b;
	if (strlen(a) != strlen(b)) cout << "WRONG_ANSWER" << endl;
	else if (a[0] == b[0] && a[0] == '0') cout << "OK" << endl;
	else
	{
		int flag = true;
		for (int i = 0; i < strlen(a); ++i) numa[i] = a[i]-'0';
		sort(numa, numa+strlen(a));
		// for (int i = 0; i < strlen(a); ++i) cout << numa[i];
		int num = 0;
		while (numa[num] == 0) num++;
		swap(numa[num], numa[0]);
		for (int i = 0; i < strlen(a); ++i)
		{
			if (numa[i]+'0' != b[i]) {flag = false; break;}
		}
		if (flag) cout << "OK" << endl;
		else cout << "WRONG_ANSWER" << endl;
	}
	return 0;
}


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

#define pb push_back
#define mp make_pair

using namespace std;

const int N = (int)(5e3);

typedef long long ll;
typedef long double ld;

int n, f[N];

bool check(int k)
{
  for (int i = 1; i <= n; i++)
  {
    int gg = i, g = i;
  	for (int j = 0; j < 2 * k; j++)
  	{
  	  gg = f[gg];
  	  if (j < k)
  	  	g = f[g];
  	}
  	if (g != gg)
  		return false;
  }
  return true;
}

int st[N], k;
bool was[N];
bool inc[N];
int mxp = 0;

int dfs(int v)
{
  if (was[v])
  {
    for (int j = k - 1; j >= 0; j--)
    {
    	inc[st[j]] = true;
    	if (st[j] == v)
    	{
    		mxp = max(j, mxp);
    		return (k - j);
      }
    }
  }
  was[v] = true;
  st[k++] = v;
  return dfs(f[v]);
}

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

int main()
{
  //freopen("x.in", "r", stdin);
  //freopen("x.out", "w", stdout);

  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &f[i]);

  ll ans = 1;
  for (int i = 1; i <= n; i++)
  {
    k = 0;
    if (!was[i])
    {
      int s = dfs(i);
      ll g = gcd(ans, (ll)s);
      ans = s * ans / g;
    }
  }

  if (mxp == 0)
    cout << ans << endl;
  else
    cout << ((mxp + ans - 1) / ans) * ans << endl;

  return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <cassert>

#define FOR(i,n) for(int i=0,_n=n;i<_n;i++)
#define FORD(i,n) for(int i=n;i>=0;i--)
#define FORR(i,s,n) for(int i=s,_n=n;i<_n;i++)
#define FORRD(i,n,s) for(int i=n,_s=s;i>=_s;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>
#define fs first
#define sec second

#define maxn 100000
using namespace std;
typedef long long ll;

int n[3];
vi tree[3][maxn];
ll S[3][maxn],sts[3][maxn],mxx[3],sum[3];

ll fsubtree(int x,int y,int t){
	sts[t][x] = 1;
	FOR(i,tree[t][x].size())
		if(tree[t][x][i] != y)
			sts[t][x] += fsubtree(tree[t][x][i],x,t);
	return sts[t][x];
}

ll fsum(int x,int y,int t){
	S[t][x] = 0LL;
	FOR(i,tree[t][x].size())
		if(tree[t][x][i] != y)
			S[t][x] += fsum(tree[t][x][i],x,t);
	return S[t][x] + sts[t][x];
}

void fsum2(int x,int y,int t,ll up,ll upcnt){
	FOR(i,tree[t][x].size())
		if(tree[t][x][i] != y){
			ll toadd = up + S[t][x] - S[t][tree[t][x][i]] - sts[t][tree[t][x][i]];
			toadd += sts[t][x] - sts[t][tree[t][x][i]] + upcnt;
			fsum2(tree[t][x][i],x,t,toadd,upcnt + sts[t][x] - sts[t][tree[t][x][i]]);
		}
	S[t][x] += up;
	mxx[t] = max(mxx[t],S[t][x]);
	sum[t] += S[t][x];
}

ll ANS = 0LL;

void funder(int x,int y,int t,int oth,ll d){
	// calc value
	ll val = n[t] * mxx[(t + 1) % 3] + n[t] * n[(t + 1) % 3] + n[(t + 1) % 3] * S[t][oth];
	val += n[t] * mxx[(t + 2) % 3] + n[t] * n[(t + 2) % 3] + n[(t + 2) % 3] * S[t][x];
	val += n[(t + 1) % 3] *  mxx[(t + 2) % 3] + n[(t + 1) % 3] * n[(t + 2) % 3] * (d + 2LL);
	val += n[(t + 2) % 3] * mxx[(t + 1) % 3];

	ANS = max(ANS,val);
	FOR(i,tree[t][x].size())
		if(tree[t][x][i] != y)
			funder(tree[t][x][i],x,t,oth,d + 1);
}
void fmain(int x,int y,int t){ // main pair
	funder(x,-1,t,x,0);
	FOR(i,tree[t][x].size())
		if(tree[t][x][i] != y)
			fmain(tree[t][x][i],x,t);
}

int main(){
	FOR(i,3) cin>>n[i];
	FOR(i,3)
		FOR(j,n[i] - 1){
			int u,v;
			cin>>u>>v;
			u--;v--;
			tree[i][u].pb(v);
			tree[i][v].pb(u);
		}
	FOR(i,3){
		fsubtree(0,-1,i);
		fsum(0,-1,i);
		fsum2(0,-1,i,0,0);
	}

	FOR(i,3)
		fmain(0,-1,i);
	cout<<ANS + (sum[0] + sum[1] + sum[2]) / 2<<"\n";
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int mxc=27,mxx=260;
const int inf=1e9;
int d[55][65][525][2];
int n;
char st[55];
int solve(int pos,int c,int x,int op)
{
	if (c<-mxc||c>mxc||x<-mxx||x>mxx) return inf;
	if (pos>n) return c?inf:0;
	if (d[pos][c+mxc][x+mxx][op]!=-1) return d[pos][c+mxc][x+mxx][op];
	return d[pos][c+mxc][x+mxx][op]=min(solve(pos,c,x+(op?-1:1),op)+n-pos+1,min(solve(pos+1,c*10+st[pos]-'0'+x,x,1),solve(pos+1,c*10+st[pos]-'0'+x,x,0)));
}
int main()
{
	memset(d,-1,sizeof(d));
	scanf("%s",st+1);
	st[0]='0';
	n=strlen(st+1);
	printf("%d\n",min(solve(0,0,0,1),solve(0,0,0,0)));
}


#include <cstdio>

using namespace std;

typedef long long int LL;
const LL MOD(1000000007LL);
const int Max_N(1050);

inline LL Mult(const LL &a, const LL &b)
{
	return a * b % MOD;
}

inline void update(LL &a, const LL &b)
{
	(a += b) %= MOD;
}

int N, K;
LL Fac[Max_N], C[Max_N][Max_N], F[Max_N][Max_N][2][2], Ans[Max_N];

int main()
{
	scanf("%d%d", &N, &K);
	Fac[0] = C[0][0] = 1LL;
	for (int i = 1;i <= N;++i)
	{
		Fac[i] = Mult(Fac[i - 1], i * 1LL);
		C[i][0] = C[i][i] = 1LL;
		for (int j = 1;j < i;++j)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	}
	F[0][0][1][0] = 1LL;
	for (int i = 1;i <= N;++i)
		for (int j = 0;j <= i - 1;++j)
			for (int c0 = 0;c0 <= 1;++c0)
				for (int c1 = 0;c1 <= 1;++c1)
				{
					update(F[i][j][c1][0], F[i - 1][j][c0][c1]);
					if (!c0)
						update(F[i][j + 1][c1][0], F[i - 1][j][c0][c1]);
					if (i + 1 <= N)
						update(F[i][j + 1][c1][1], F[i - 1][j][c0][c1]);
				}
	for (int k = 0;k <= N;++k)
	{
		for (int c0 = 0;c0 <= 1;++c0)
			for (int c1 = 0;c1 <= 1;++c1)
				update(Ans[k], F[N][k][c0][c1]);
		Ans[k] = Mult(Ans[k], Fac[N - k]);
	}
	for (int i = N;i >= K;--i)
		for (int j = i + 1;j <= N;++j)
			Ans[i] = Ans[i] - Mult(C[j][i], Ans[j]), Ans[i] = (Ans[i] % MOD + MOD) % MOD;
	printf("%I64d", Ans[K]);
	return 0;
}


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

const int N = 10000010;

vector<long long>  get_divs(long long n) {
  vector<long long> ret;
  //d不能为n, 所以 m / d 不能为1, 所以1不用加入
  ret.push_back(n);
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (n / i != i ) {
        ret.push_back(n/i);
      }
    }
  }
  sort (ret.begin(), ret.end());
  return ret;
}

vector<long long> get_primes(long long n) {
  vector<long long> ret;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) ret.push_back(n);
  return ret;
}

long long euler(long long n, vector<long long> &p) {
  long long ret = n;
  for (long long x : p) {
    if (ret % x == 0) {
      ret = ret / x * (x - 1);
    }
  }
  return ret;
}
/*
long long mul(long long a, long long b, long long md) {
  double bei = 1.0 * a * b / md;
  bei = floor(bei);
  long long rem = 1.0 * a * b - bei * md;
  return rem;
} */
long long mul(long long a, long long b, long long md) {
    long long m = ( (long double)(a) * b / md);
    long long rem = a * b - m * md;
    while(rem < 0)
        rem += md;
    while(rem >= md)
        rem -= md;
    return rem;
}

//这样要TLE
/*
long long mul(long long a, long long b, long long md) {
  long long ret = 0;
  while (b) {
    if (b & 1) {
      ret = (ret + a) % md;
    }
    b >>= 1;
    a = (a + a) % md;
  }
  return ret;
}*/
long long pow_md(long long a, long long b, long long md) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = mul(ret, a, md);
    b >>= 1;
    a = mul(a,a,md);
  }
  return ret;
}

void solve(long long m, long long x) {
  vector <long long> divs = get_divs(m);
  vector <long long> pris_m = get_primes(m);
  long long eul = euler(m, pris_m);

  vector <long long> pris_phim = get_primes(eul);
  //phi(m/d)的所有素因子一定是phi(m)的子集

  long long ret = 1;
  for (long long d: divs) {//相当于直接枚举m/d 20000
    long long f = euler(d, pris_m);
    //x ^ k % (m / d) = 1
    //k 是 phi(m/d)的因子
    long long k = f;
    for (long long p: pris_phim) {// 20
      //x要记得先取模, 坑
      while (k % p == 0 && pow_md(x % d, k / p, d) == 1) {//30 * 30
        k /= p;
      }
    }
    ret += f / k;
  }
  cout << ret << endl;
}

int main() {
 // cout << mul(2, 6, 5);
  long long m, x;
  cin >> m >> x;
  solve(m, x);
  return 0;
}


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

typedef long long ll;
const ll INF = (ll)1e18;

ll f, T, t0;
ll a1, t1, p1, a2, t2, p2;

int main() {
    cin >> f >> T >> t0;
    cin >> a1 >> t1 >> p1;
    cin >> a2 >> t2 >> p2;

    ll res = INF;
    for(int swapped = 0; swapped < 2; swapped++) {
        if(swapped) {
            swap(a1, a2);
            swap(t1, t2);
            swap(p1, p2);
        }
        for(ll c1 = 0; c1 * a1 <= f + a1; c1++) {
            ll rem_f = max(0LL, f - c1 * a1);
            if(t1 * min(a1 * c1, f) + min(t2, t0) * rem_f > T) continue;
            if(t2 >= t0) {
                res = min(res, c1 * p1);
            }
            else {
                res = min(res, c1 * p1 + (rem_f + a2 - 1) / a2 * p2);
                ll over_t = max(0LL, rem_f * t0 + t1 * (f - rem_f) - T);
                ll mn_c2 = (over_t + a2 * (t0 - t2) - 1) / ((t0 - t2) * a2);
                if(mn_c2 * a2 <= rem_f) {
                    res = min(res, c1 * p1 + mn_c2 * p2);
                }
            }
        }
    }
    cout << (res == INF ? -1 : res) << '\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define abs(x)      ((x)>0?(x):-(x))
#define Mul(x,y)    (x=1LL*(x)*(y)%mod)
#define Add(x,y)    (x=(x+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define p(x)        printf("~%d~\n",x)
#define pp(x,y)     printf("~~%d %d~~\n",x,y)
#define ppp(x,y,z)  printf("~~~%d %d %d~~~\n",x,y,z)
#define pppp(a,b,c,d)	printf("~~~%d %d %d %d\n",a,b,c,d)
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    inline char gc(){   return getchar();   }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
    inline ld getreal(){    static ld lbc;  scanf("%lf",&lbc);  return lbc; }
}using namespace SHENZHEBEI;
const ll mod=1e9+7,N=200010;
map<ll,ll>g;
vector<ll>a[1010];
ll ans,n,m,vis[1010],SIZE[1010];
ll id(ll x){if (g.find(x)==g.end()){ll u=g.size();g[x]=u;}return g[x];}
void gao(ll x){	for(;x;x>>=1)id(x);	}
ll Size(ll x){
	ll L=x,R=x,ans=0;
	for(;L<=n;L=L<<1,R=R<<1|1)ans+=min(n,R)-L+1;
	return ans;
}
void dfs(ll x,ll bb){
	vis[x]=1;Add(ans,bb*SIZE[x]);
	for(ll i:a[x])if (!vis[i])dfs(i,bb);
	vis[x]=0;
}
int main(){
	n=read(),m=read();
	For(i,1,m){
		ll x=read(),y=read();
		gao(x),gao(y);
		a[g[x]].push_back(g[y]);
		a[g[y]].push_back(g[x]);
	}gao(1);
	for(pa I:g){
		SIZE[I.se]=Size(I.fi);
		if (g.count(I.fi*2))	SIZE[I.se]-=Size(I.fi*2);
		if (g.count(I.fi*2+1))	SIZE[I.se]-=Size(I.fi*2+1);
		if (I.fi>1)				a[g[I.fi/2]].push_back(g[I.fi]),
								a[g[I.fi]].push_back(g[I.fi/2]);
	}for(ll i=0;i<g.size();++i)dfs(i,SIZE[i]);
	writeln(ans);
}


/*--------------------------------------------------------------------
      JENISH MONPARA S.       IIT PATNA         I LOVE ADITI GOEL
--------------------------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265359;
long double DEL = 1e-10;
int mod =  1000000007;

#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define all(a) a.begin() , a.end()
#define sqr(a) ((a) * (a))
#define double long double
#define dbg cout<<"\nhi\n"
#define int long long
#define nl cout<<"\n"
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first

int fpow(int x, int n)
{
    int res = 1;
    while(n)
    {
          if(n&1)res = res * x % mod;
          x = x * x % mod;
          n>>=1;
    }
    return res;
}
int gcd(int a,int b)
{
    if(b == 0)return a;
    return gcd(b,a % b);
}
void sieve(int n)
{
      bool prime[1000006];
      memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);

      for (int p = 2; p <= rootn; p++)
            if(prime[p] == true)
                  for(int i = p*p; i <= n; i += p)
                        prime[i] = false;
      prime[1] = 0;
}
const int N = 1000050;
int cnt, sum, mid, mx, mn, ans, a[N], b[N];
int n, m, d, i, j, k, l, p, q, r, t, w, x, y, z;
bool f, f1, f2;
string s;
// you can also use __int128
// priority_queue<int,vector<int>,greater<int>>
// bitset<100>(x).count()
//******************************************* CHECK CONSTRAINTS **************************************************

int32_t main()
{
      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
      cin>>n;
      for(int i=1;i<=n;i++)cin>>a[i];
      cin>>k;
      vector<bool> neg(n+2);
      for(int i=1;i<=k;i++)
      {
            cin>>x;
            neg[x] = 1;
      }
      stack<int> s;
      for(int i=n;i>0;i--)
      {
            if(s.empty() || neg[i])
            {
                  s.push(a[i]);
                  a[i] = -a[i];
                  continue;
            }
            if(s.top() == a[i])
            {
                  s.pop();
            }
            else
            {
                  s.push(a[i]);
                  a[i] = -a[i];
            }
      }
      if(!s.empty())
      {
            cout<<"NO\n";
            return 0;
      }
      cout<<"YES\n";
      for(int  i=1;i<=n;i++)
      {
            cout<<a[i]<<" ";
      }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,a[10],b[10],c[10][10],len,sum[10][1<<10],sk[10],ac[1<<10];
ll ans=1e9;
bool check(){
	for(int i=0;i<len;++i){
		int tp=ac[i];
		for(int j=0;j<n;++j)if((sk[j]&i)==sk[j])tp+=a[j];
		if(tp>0)return 0;
	}return 1;
}
void dfs(int x,ll w){
	if(w>=ans)return;
	if(x>=n){
		if(check())ans=w;
		return;
	}ll tp=w;
	for(int i=x;i<n;++i)sk[i]=len-1,tp+=sum[i][sk[i]];
	if(!check())return;
	ans=min(ans,tp);
	for(int i=0;i<len;++i){
		sk[x]=i;
		dfs(x+1,w+sum[x][i]);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)scanf("%d",&a[i]);
	for(int i=0;i<m;++i)scanf("%d",&b[i]);
	len=1<<m;
	for(int i=0;i<len;++i)
		for(int j=0;j<m;++j)if((1<<j)&i)ac[i]=(ac[i]-b[j]);
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)scanf("%d",&c[i][j]);
	for(int i=0;i<n;++i)
		for(int j=0;j<len;++j)
			for(int k=0;k<m;++k)if((1<<k)&j)sum[i][j]=(sum[i][j]+c[i][k]);
	for(int i=0;i<n;++i)sk[i]=len-1;
	if(!check()){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=100000;++i){
		ll tp=0;
		for(int j=0;j<n;++j)sk[j]=rand()%len,tp+=sum[j][sk[j]];
		if(check())ans=tp;
	}
	dfs(0,0);
	printf("%lld\n",ans);
}


#include <cstdio>

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

int main()
{
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
    printf("%d\n",min(m,q)-(q-min(n,q))+1);
	return 0;
}