#include<stdio.h>

int main()
{
    int i,j,k,l,n;
    long long int x,y;
    scanf("%d",&n);
    x=n;
    i=1;
    while(i<5){
        x*=(n-i);
        i++;

    }
    y=x/120;
    x=x*y;

    printf("%I64d\n",x);
}


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

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long dp[105][105][10];
bool visited[105][105][10];

long long F(int n, int c, int r){
    if (!r) return 1;
    if (!n) return 0;
    if (visited[n][c][r]) return dp[n][c][r];

    long long res = F(n - 1, c, r) + (F(n - 1, c - 1, r - 1) * c);
    visited[n][c][r] = true;
    return (dp[n][c][r] = res);
}

int main(){
    int n;
    while (scanf("%d", &n) != EOF){
        clr(visited);
        long long res = F(n, n, 5);
        printf("%lld\n", res);
    }
    return 0;
}


// write in C...
#include <stdio.h>

#ifdef DEBUG
#define D(x...) fprintf(stderr, x)
#else
#define D(x...)
#endif

char op[20];

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

long long can_do(long long a, long long b, long long c, long long d, int i) {
    long long res = 2000000000000000000;
    if (i == 3) res = a;
    else {
        if (op[2*i] == '+') {
            if (i < 3)
                res = min(res, can_do(a+b, c, d, -1, i+1));
            if (i < 2)
                res = min(res, can_do(a, b+c, d, -1, i+1));
            if (i < 1)
                res = min(res, can_do(a, b, c+d, -1, i+1));
        } else {
            if (i < 3)
                res = min(res, can_do(a*b, c, d, -1, i+1));
            if (i < 2)
                res = min(res, can_do(a, b*c, d, -1, i+1));
            if (i < 1)
                res = min(res, can_do(a, b, c*d, -1, i+1));
        }
    }
    return res;
}

int main() {
    long long a, b, c, d;
    scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d);
    scanf(" %c %c %c", op, op+2, op+4);
    printf("%I64d", can_do(a, b, c, d, 0));
    return 0;
}


#include <stdio.h>
#define MAXN 4
#define LL __int64

LL AN[MAXN] = {0};

LL calc3(LL a, LL b, char opt) {
    if (opt == '+')
        return a+b;
    else
        return a*b;
}

LL calc2(LL arr[], char opt[]) {
    int a, b, c, d;
    LL min = 0x3f3f3f3f;
    for (a=0; a<4; a++)
        for (b=0; b<4; b++)
            for (c=0; c<4; c++)
                for (d=0; d<4; d++) {
                    if (a!=b && a!=c && a!=d && b!=c && b!=d && c!=d) {
                        LL t1, t2;
                        t1 = calc3(arr[a], arr[b], opt[0]);
                        t1 = calc3(t1, arr[c], opt[1]);
                        t1 = calc3(t1, arr[d], opt[2]);
                        //printf("%I64d %c %I64d %c %I64d %c %I64d\n", arr[a], opt[0], arr[b], opt[1], arr[c], opt[2], arr[d]);
                        if (t1<min)
                            min = t1;

                        t1 = calc3(arr[a], arr[b], opt[0]);
                        t2 = calc3(arr[c], arr[d], opt[1]);
                        t1 = calc3(t1, t2, opt[2]);
                        //printf("%I64d %c %I64d %c %I64d %c %I64d\n", arr[a], opt[0], arr[b], opt[1], arr[c], opt[2], arr[d]);
                        if (t1<min)
                            min = t1;
                    }
                }
    return min;
}

int main() {
    int i;
    char opt[3];

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

    while (scanf("%I64d%I64d%I64d%I64d", &AN[0], &AN[1], &AN[2], &AN[3] )!=EOF) {
        int add=0, mul=0, k=1, n=4;
        //char op;
        LL *TEMP=AN, ans;

        for (i=0; i<3; i++) {
            getchar();
            scanf("%c", &opt[i]);
            /*select_sort(TEMP, n);
            if (op=='+') {
                TEMP[n-2] += TEMP[n-1];
                n--;
            } else if (op=='*') {
                TEMP[1] *= TEMP[0];
                TEMP++;
                n--;
            }*/
        }

        ans = calc2(AN, opt);

        printf("%I64d\n", ans);
    }
}


#include <stdio.h>
#define MAXN 4
#define LL __int64

LL AN[MAXN] = {0};

void select_sort(LL a[],int n) {
    int i, j;
    LL min, t;
    for(i =0; i < n - 1; i++){
        min = i;
        for(j = i + 1; j < n; j++)
            if(a[min]> a[j]) min = j;
        if(min != i) {
            t = a[min];
            a[min]= a[i];
            a[i]= t;
        }
    }
}

int main() {
    char op;
    int n, i;

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

    while (scanf("%I64d%I64d%I64d%I64d", &AN[0], &AN[1], &AN[2], &AN[3] )!=EOF) {
        n = 4;

        for (i=0; i<3; i++) {
            select_sort(AN, n);
            getchar();
            scanf("%c", &op);
            if (op=='+') {
                AN[0] = AN[0]+AN[n-1];

            } else if (op=='*') {
                AN[0] = AN[0]*AN[1];
                if (n>=4) {
                    AN[1] = AN[2];
                    AN[2] = AN[3];
                } else if (n>=3) {
                    AN[1] = AN[2];
                }
            }
            n--;
        }
        printf("%I64d\n", AN[0]);
    }
}


#include<stdio.h>
#include<stdlib.h>

long long a[4];
char b[5];

void count(char c,int n);

int main()
{
    for(int i=0;i<4;i++)
        scanf("%lld",&a[i]);
    getchar();
    scanf("%c %c %c",&b[1],&b[2],&b[3]);
    int min,p;
    int n=3;
        while(n>=1){
        for(int i=0;i<n;i++)
        {
            min=a[i];p=i;
            for(int j=i+1;j<n+1;j++)
            {
                if(a[j]<min)
                {
                    min=a[j];
                    p=j;
                }
            }
            a[p]=a[i];
            a[i]=min;
        }
        count(b[4-n],n+1);
        n--;
    }
    printf("%lld",a[0]);
    return 0;
}

void count(char c,int n)
{
    switch(c)
    {
        case '+':{
            a[n-2]=a[n-1]+a[n-2];
            break;
        }
        case '*':{
            if(a[0]!=0){
                a[0]=a[0]*a[1];
                for(int i=1;i<n;i++)
                    a[i]=a[i+1];
            }
            break;
        }
        default:break;
    }
}


#include <stdio.h>
#define MAXN 4
#define LL __int64

LL AN[MAXN] = {0};

void select_sort(LL a[],int n) {
	int i, j;
	LL min, t;
	for(i =0; i < n - 1; i++){
		min = i;
		for(j = i + 1; j < n; j++)
			if(a[min]> a[j]) min = j;
		if(min != i) {
			t = a[min];
			a[min]= a[i];
			a[i]= t;
		}
	}
}

int main() {
	int i;

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

	while (scanf("%I64d%I64d%I64d%I64d", &AN[0], &AN[1], &AN[2], &AN[3] )!=EOF) {
		int add=0, mul=0, k=1, n=4;
		char op;
		LL *TEMP=AN;

		for (i=0; i<3; i++) {
			getchar();
			scanf("%c", &op);
			if (op=='+') {
				add++;
			} else if (op=='*') {
				mul++;
			}
		}

		select_sort(TEMP, n);

		//ans = AN[k++];

		while (mul--) {
			TEMP[1] = TEMP[0]*TEMP[1];
			TEMP++;
			select_sort(TEMP, --n);
		}

		while (add--) {
			TEMP[0] += TEMP[k++];
		}

		printf("%I64d\n", TEMP[0]);
	}
}


#include<stdio.h>

long long a[1000006],b[1000006],ans,count1,count2,lc,count3,count4,count;

long long lcm(long long a,long long b)
{
	if(a>b)
	{
		if(a%b==0)
			return b;

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

		return lcm(a,b%a);
	}
}

int main()
{
	long long m,h1,h2,x1,x2,y1,y2,a1,a2,p,i,n;

	scanf("%lld",&m);

	scanf("%lld%lld",&h1,&a1);

	scanf("%lld%lld",&x1,&y1);

	scanf("%lld%lld",&h2,&a2);

	scanf("%lld%lld",&x2,&y2);

	p=1;

	for(i=0;i<m+2;i++)
		a[i]=b[i]=0;

	count1=count2=0;

	for(i=0;i<m+2;i++)
	{
		if(h1==a1)
		{
			p=0;
			break;
		}

		if(!a[h1])
			a[h1]=1;
		else
		{
			break;
		}

		count1++;
		h1=(h1*x1+y1)%m;
	}

	if(p)
	{
		printf("-1");
		return 0;
	}

	p=1;

	for(i=0;i<m+2;i++)
	{
		if(h2==a2)
		{
			p=0;
			break;
		}

		if(!b[h2])
			b[h2]=1;
		else
		{
			break;
		}

		count2++;
		h2=(h2*x2+y2)%m;
	}

	if(p)
	{
		printf("-1");
		return 0;
	}

	for(i=0;i<m+2;i++)
		a[i]=b[i]=0;

	h2=(h2*x2+y2)%m;
	h1=(h1*x1+y1)%m;

	count3=count4=1;

	for(i=0;i<m+2;i++)
	{
		if(h1==a1)
		{
			p=0;
			break;
		}

		if(!a[h1])
			a[h1]=1;
		else
		{
			break;
		}

		count3++;
		h1=(h1*x1+y1)%m;
	}

	for(i=0;i<m+2;i++)
	{
		if(h2==a2)
		{
			p=0;
			break;
		}

		if(!b[h2])
			b[h2]=1;
		else
		{
			break;
		}

		count4++;
		h2=(h2*x2+y2)%m;
	}

	if(count1==count2)
	{
		printf("%lld",count1);
		return 0;
	}

	count=(count1>count2)?count1:count2;
	i=0;

	while(1)
	{
		i++;
		if(((count-count1)%count3==0) && ((count-count2)%count4==0))
			break;
		count=count3*i+count1;
	}

	printf("%lld",count);

	return 0;
}


#include<stdio.h>

long long a[1000006],b[1000006],ans,count1,count2,lc,count3,count4,count;

long long lcm(long long a,long long b)
{
	if(a>b)
	{
		if(a%b==0)
			return b;

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

		return lcm(a,b%a);
	}
}

int main()
{
	long long m,h1,h2,x1,x2,y1,y2,a1,a2,p,i,n;

	scanf("%lld",&m);

	scanf("%lld%lld",&h1,&a1);

	scanf("%lld%lld",&x1,&y1);

	scanf("%lld%lld",&h2,&a2);

	scanf("%lld%lld",&x2,&y2);

	p=1;

	for(i=0;i<m+2;i++)
		a[i]=b[i]=0;

	count1=count2=0;

	for(i=0;i<m+2;i++)
	{
		if(h1==a1)
		{
			p=0;
			break;
		}

		if(!a[h1])
			a[h1]=1;
		else
		{
			break;
		}

		count1++;
		h1=(h1*x1+y1)%m;
	}

	if(p)
	{
		printf("-1");
		return 0;
	}

	p=1;

	for(i=0;i<m+2;i++)
	{
		if(h2==a2)
		{
			p=0;
			break;
		}

		if(!b[h2])
			b[h2]=1;
		else
		{
			break;
		}

		count2++;
		h2=(h2*x2+y2)%m;
	}

	if(p)
	{
		printf("-1");
		return 0;
	}

	for(i=0;i<m+2;i++)
		a[i]=b[i]=0;

	h2=(h2*x2+y2)%m;
	h1=(h1*x1+y1)%m;

	count3=count4=1;

	for(i=0;i<m+2;i++)
	{
		if(h1==a1)
		{
			p=0;
			break;
		}

		if(!a[h1])
			a[h1]=1;
		else
		{
			break;
		}

		count3++;
		h1=(h1*x1+y1)%m;
	}

	for(i=0;i<m+2;i++)
	{
		if(h2==a2)
		{
			p=0;
			break;
		}

		if(!b[h2])
			b[h2]=1;
		else
		{
			break;
		}

		count4++;
		h2=(h2*x2+y2)%m;
	}

	if(count1==count2)
	{
		printf("%lld",count1);
		return 0;
	}

	count=(count1>count2)?count1:count2;

	while(1)
	{
		if(((count-count1)%count3==0) && ((count-count2)%count4==0))
			break;
		count++;
	}

	printf("%lld",count);

	return 0;
}


#include <stdio.h>

int main()
{
    int m,i;

    scanf("%d",&m);

    int h1,a1;
    scanf("%d %d",&h1,&a1);

    int x1,y1;
    scanf("%d %d",&x1,&y1);

    int h2,a2;
    scanf("%d %d",&h2,&a2);

    int x2,y2;
    scanf("%d %d",&x2,&y2);

    int count=0;

    int initial1 = h1;
    int initial2 = h2;
    int flag=0;
    while (h1!=a1 || h2!=a2)
    {

        h1 = (((x1%m)*(h1%m))%m + y1%m)%m;
        h2 = (((x2%m)*(h2%m))%m + y2%m)%m;
        count = count+1;

        if (h1==initial1 && h2==initial2)
        {
            flag=1;
            break;
        }
    }
    if (flag==1)
        printf("-1\n");
    else
        printf("%d\n",count);

    return 0;
}


#include <stdio.h>

int main()
{
    long m,i;

    scanf("%ld",&m);

    long h1,a1;
    scanf("%ld %ld",&h1,&a1);

    long x1,y1;
    scanf("%ld %ld",&x1,&y1);

    long h2,a2;
    scanf("%ld %ld",&h2,&a2);

    long x2,y2;
    scanf("%ld %ld",&x2,&y2);

    long count=0;

    long initial1 = h1;
    long initial2 = h2;

        long flag=0;
        long temp=0;

        while (h1!=a1)
        {

            h1 = (((x1%m)*(h1%m))%m + y1%m)%m;
            h2 = (((x2%m)*(h2%m))%m + y2%m)%m;
            //printf("h1 is %ld\n",h1);
            //printf("h2 is %ld\n",h2);
            count = count+1;
            temp = temp+1;
            if (temp> (m+10))
            {
                flag=1;
                printf("-1\n");
                break;
            }

        }
    //printf("count is %ld\n",count);

        if (flag==0)
        {
            long temp1=0;

            if (h2==a2)
            {
                printf("%ld\n",count);
                flag=1;
                break;
            }
            else
            {
                long z1=1, z2=0;
                while (h1!=a1 || temp1==0)
                {
                    h1 = (((x1%m)*(h1%m))%m + y1%m)%m;
                    //h2 = (((x2%m)*(h2%m))%m + y2%m)%m;
                    z1 = ((z1%m) * (x2%m))%m;
                    z2 = (((z2%m)*(x2%m))%m + y2%m)%m;
                    temp1++;
                    //count++;
                    if (temp1>(m+10))
                    {
                        flag=1;
                        //prlongf("here\n");
                        printf("-1\n");
                        break;
                    }
                }

                if (flag==0)
                {

                    long temp2=0;

                    while (h2!=a2)
                    {
                        h2 = (((z1%m)*(h2%m))%m + z2%m)%m;
                        temp2++;
                        if (temp2 > (m+10))
                        {
                            flag=1;
                            //prlongf("second\n");
                            printf("-1\n");
                            break;
                        }
                    }

                    if (flag==0)
                    {
                        printf("%ld\n",count+temp1*temp2);
                    }

                }

            }

        }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <string.h>
int main()
{
int a,b,m,r;
int n[100000],num[100000],pre,t;
while(scanf("%d%d%d%d",&a,&b,&m,&r)!=EOF)
{
    int i;
    for( i=0;i<100000;i++)
        n[i]=1,num[i]=0;

    pre=r;
    for(i=1;i<100000;i++)
    {
        pre=(a*pre+b)%m;
        //printf("pre=%d\n",pre);

        if(n[pre]==1)
        {
            n[pre]=0;
            num[pre]=i;
        }
        else
        {
            t=i-num[pre];
            break;
        }
    }
    printf("%d\n",t);
}
return 0;
}


#include<stdio.h>

int main()
{
	int a, b, m, ro, i=0, key, done=0, *hasher;

	scanf("%d %d %d %d", &a, &b, &m, &ro);

	hasher = (int*)malloc(m * sizeof(int));
	hasher[ro]=0;
	while(!done)
	{
		i++;
		key = (a * ro + b)%m;

		if(hasher[key] != 0)
		{
			printf("%d\n", i-hasher[key]);
			done = 1;
		}
		else
		{
			hasher[key] = i;
		}
		ro = key;
	}
	return 0;
}


#include<stdio.h>

int main()
{
	int a, b, m, ro, i=0, key, done=0, *hasher;

	scanf("%d %d %d %d", &a, &b, &m, &ro);

	hasher = (int*)malloc(m * sizeof(int));

	while(!done)
	{
		key = (a * ro + b)%m;

		if(hasher[key] != 0)
		{
			printf("%d\n", i-hasher[key]);
			done = 1;
		}
		else
		{
			hasher[key] = i;
		}
		i++;
		ro = key;
	}
	return 0;
}


#include <stdio.h>

#define MAXN 100000

int main(void) {
	int a, b, m, r, psr[MAXN+2];
	scanf("%d %d %d %d", &a, &b, &m, &r);

	int count = 0;
	while (psr[r] == 0) {
		psr[r] = ++count;
		r = (a * r + b) % m;
	}

	printf("%d\n", count - psr[r] + 1);

	return 0;
}


#include <stdio.h>
const int N=1000000007;
long long int x, i, n, a = 1;
long long int k (long long int x, long long int p)
{
	long long int s = 1;
	while (p)
	{
		if (p % 2)
			s = s * x % N;
		p /= 2;
		x = x * x % N;
	}
    return s;
}
long long int d (long long int p)
{
	long long int m = n, sum = 0;
	while (m)
		sum += m /= p;
	return k(p, sum);
}
int main()
{
	scanf("%lld%lld", &x, &n);
	for (i = 2; i * i <= x; i++)
		if (x % i == 0)
		{
			a = a * d(i) % N;
			while (x % i == 0)
				x /= i;
		}
	if (x != 1)
		a = a * d(x) % N;
	printf("%lld", a);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <limits.h>
typedef long long ll;

ll MAX = 100000000000;  //  1e11
ll MIN = -100000000000; // -1e11
ll MOD = 1000000007;

ll longlongmax = __LONG_LONG_MAX__;

ll maxormin(ll a, ll b, ll flag)
{
    return flag == 1 ? (a > b ? a : b) : (a < b ? a : b);
}

ll overflowcheck(ll a)
{
    if (a == 1)
    {
        return 0;
    }
    else
    {
        ll temp = a;
        ll power = 1;
        while (longlongmax / temp > a)
        {
            temp *= a;
            power++;
        }
        return power + 1; // Overflow occurs at this power.
    }
}

ll merge(ll A[], ll B[], ll left, ll mid, ll right)
{
    ll count = 0;
    ll n1 = mid - left + 1;
    ll n2 = right - mid;

    ll LA[n1], LB[n1], RA[n1], RB[n2];

    for (ll n = 0; n < n1; n++)
    {
        LA[n] = A[n + left];
        LB[n] = B[n + left];
    }
    for (ll n = 0; n < n2; n++)
    {
        RA[n] = A[n + mid + 1];
        RB[n] = B[n + mid + 1];
    }

    ll i = 0, j = 0, k = left;

    while (i < n1 && j < n2)
    {
        if (LA[i] < RA[j])
        {
            A[k] = LA[i];
            B[k] = LB[i];
            i++;
        }
        else
        {
            A[k] = RA[j];
            B[k] = RB[j];
            count += n1 - i;
            j++;
        }
        k++;
    }
    while (i < n1)
    {
        A[k] = LA[i];
        B[k] = LB[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        A[k] = RA[j];
        B[k] = RB[j];
        j++;
        k++;
    }
    return count;
}

ll mergesort(ll A[], ll B[], ll left, ll right)
{
    ll total = 0;
    if (left < right)
    {
        ll mid = (right - left) / 2 + left;
        total += mergesort(A, B, left, mid);
        total += mergesort(A, B, mid + 1, right);
        total += merge(A, B, left, mid, right);
    }
    return total;
}

ll primemarked[3000000];
ll primearray[3000000];
ll primeind;

void setupprimes()
{
    for (ll i = 2; i < 3000000; i++)
    {
        for (ll j = 2 * i; j < 3000000; j += i)
        {
            primemarked[j] = 1;
        }
    }
    for (ll i = 2; i < 3000000; i++)
    {
        if (!primemarked[i])
        {
            primearray[primeind++] = i;
        }
    }
}

ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result

    x = x % p; // Update x if it is more than or
               // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

ll factorsX[3000000];
ll ind = 0;

int main(int argc, char const *argv[])
{
    ll T = 1;
    // scanf("%lld",&T);
    setupprimes();

    for (ll t = 0; t < T; t++)
    {
        ll x, N;
        scanf("%lld %lld", &x, &N);
        for (ll j = 0; j < primeind; j++)
        {
            if ((x % primearray[j]) == 0)
            {
                factorsX[ind++] = primearray[j];
                while((x % primearray[j])==0)
                {
                    x /= primearray[j];
                }
            }
        }
        if (x!=1)
        {
            // a prime itself
            factorsX[ind++] = x;
        }

        ll total = 1;
        // printf("%lldpopop\n",longlongmax/947);
        for (ll o = 0; o < ind; o++)
        {
            // for each prime factor calculate
            ll count[300];
            ll cind = 0;
            ll fac = factorsX[o];
            ll p = 1;
            ll gh = 1;
            while (p <= N && gh)
            {
                // printf("%lld\n",p);
                count[cind++] = N / p;
                if( p >= longlongmax/fac)
                {
                    gh = 0;
                }
                p *= fac;
            }

            for (ll m = 0; m < cind; m++)
            {
                ll num = 1;
                ll prod ;

                if(m!=(cind-1))
                {
                   num = (m*(count[m]-count[m+1]))%(MOD-1);
                }
                else
                {
                    num = (m*count[m])%(MOD-1);
                }
                // printf("%lld\n",num);
                prod = power(factorsX[o],num,MOD);
                total  = (total*prod)%MOD;
                total %= MOD;
            }
        }
        printf("%lld\n",total%MOD);
    }

    return 0;
}


#include <stdio.h>

#define MOD 1000000007
#define N 100500

long long x, n, ans, m, prime[N];;

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

long long ppow(long long a, long long n)
{
    long long res = 1;
    while (n) {
        if (n & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    scanf("%I64d%I64d", &x, &n);
    for (long long i = 2; i * i <= x; i++) {
        if (x % i == 0)
            prime[m++] = i;
        while (x % i == 0) {
            x /= i;
        }
    }
    if (x > 1)
        prime[m++] = x;
    ans = 1;
    for (int i = 0; i < m; i++) {
        long long j = prime[i];
        while (1) {
            long long m = n / j;
            ans = (ans * ppow(j % MOD, m - m / prime[i])) % MOD;
            if (n / j < prime[i])
                break;
            j *= prime[i];
        }
    }
    printf("%I64d", ans);
    return 0;
}


#include<stdio.h>
long long int prime(long long int x)
{
	if (x < 2)
		return 0;
	if (x % 2 == 0)
		return 2;
	long long int i;
	for (i = 3; i * i <= x; i++)
		if (x % i == 0)
			return i;
	return x;
}
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)return 0;
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			res = res * a % p;
		n /= 2;
		a = a * a % p;
	}
	return res;
}
int main()
{
	long long int x, n;
	scanf("%lld %lld", &x, &n);
	long long int ans = 1, p = 1000000007;
	long long int q, v;
	while (x > 1)
	{
		q = prime(x);
		while (x % q == 0)
			x /= q;
		v = q;
		while (n / v > 0)
		{
			ans = ans * modpow(q, n / v, p) % p;
			if (n / v < q)break;
			v *= q;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>
#include <cstdio>
const int N=1e5+10;
long long int x, i, n, a = 1;
long long int k (long long int x, long long int p)
{
	long long int s = 1;
	while (p)
	{
		if (p % 2)
			s = s * x % N;
		p /= 2;
		x = x * x % N;
	}
    return s;
}
long long int d (long long int p)
{
	long long int m = n, sum = 0;
	while (m)
		sum += m /= p;
	return k(p, sum);
}
int main()
{
	scanf("%lld%lld", &x, &n);
	for (i = 2; i * i <= x; i++)
		if (x % i == 0)
		{
			a = a * d(i) % N;
			while (x % i == 0)
				x /= i;
		}
	if (x != 1)
		a = a * d(x) % N;
	printf("%lld", a);
}


#include <stdio.h>
#include <math.h>

int IsPrime(int n);

int main()
{
	int n, a, b, c;
	scanf("%d", &n);
	a = n / 10;
	b = n % 10;
	c = a + b;
	if (n < 10)
	{
		if (IsPrime(n))     printf("YES\n");
		else                printf("NO\n");
	}
	else
	{
		if (c % 5 == 0)     printf("YES\n");
		else                printf("NO\n");
	}

	return 0;
 }

int IsPrime(int n)
{
	int i, ok = n > 1, m = sqrt(n);
	for (i = 2; i <= m && ok; ++i)
	{
		if (n % i == 0)
		{
			ok = 0;
		}
	}
	return ok;
}


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int N,d,f;
  scanf("%d",&N);
  d = N/3;
  if(N%3>1){
		d++;
	}
	f = d/12;
	d = d - f*12;
	printf("%d %d\n", f, d);
  system("PAUSE");
  return 0;
}


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

int main()
{

	int n;
	int feet;
	int inch;

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

		scanf("%d", &n);

		feet = n / 36;
		inch = n % 36;

		inch = (inch + 1 )/3;

		if (inch == 12)
		{
			feet++;
			inch = 0;
		}
		printf("%d %d\n", foot, inch);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,a,b;
    scanf("%d",&n);
    printf("%d %d",n/36,n%36/3)
    return 0;
}


#include <stdio.h>

#define MAX_COMP	5
#define MAX_BID		10000

int min(int x, int y)
{
	return (x <= y) ? x : y;
}

int max(int x, int y)
{
	return (x >= y) ? x : y;
}

int main(void)
{
	int n;
	int l[MAX_COMP];
	int r[MAX_COMP];
	int i, j, k, z;
	double p, q, u;

	scanf("%d", &n);
	for(i = n; i --;)
		scanf("%d %d", &l[i], &r[i]);

	p = 0.0;
	for(i = 1; i <= MAX_BID; i ++)
	{
		for(k = 0; k < n; k ++)
		{
			if(!(l[k] <= i && i <= r[k]))
				continue;

			q = 1 / (double)(r[k] - l[k] + 1);

			for(j = 0; j < n; j ++)
			{
				if(i >= r[j])
					continue;

				if(k == j)
					continue;

				u = q;
				u *= (r[j] - max(l[j], i + 1) + 1) / (double)(r[j] - l[j] + 1);

				for(z = 0; z < n; z ++)
				{
					if(z == j || z == k)
						continue;

					if(l[z] > i)
					{
						u = 0.0;
						break;
					}

					if(z > k)
						u *= (min(r[z], i) - l[z] + 1) / (double)(r[z] - l[z] + 1);
					else
						u *= (min(r[z], i - 1) - l[z] + 1) / (double)(r[z] - l[z] + 1);
				}

				p += i * u;
			}

			for(j = k + 1; j < n; j ++)
			{
				if(!(l[j] <= i && i <= r[j]))
					continue;

				if(k == j)
					continue;

				u = q;
				u *= 1 / (double)(r[j] - l[j] + 1);

				for(z = 0; z < n; z ++)
				{
					if(z == j || z == k)
						continue;

					if(l[z] > i)
					{
						u = 0.0;
						break;
					}

					if(z > k && z > j)
						u *= (min(r[z], i) - l[z] + 1) / (double)(r[z] - l[z] + 1);
					else
						u *= (min(r[z], i - 1) - l[z] + 1) / (double)(r[z] - l[z] + 1);
				}

				p += i * u;
			}
		}
	}

	printf("%.9lf\n", p);

	return 0;
}


#include <stdio.h>

#define MAX_COMP	5
#define MAX_BID		10000

int min(int x, int y)
{
	return (x <= y) ? x : y;
}

int max(int x, int y)
{
	return (x >= y) ? x : y;
}

int main(void)
{
	int n;
	int l[MAX_COMP];
	int r[MAX_COMP];
	int i, j, k, z;
	double p, q, u;

	scanf("%d", &n);
	for(i = n; i --;)
		scanf("%d %d", &l[i], &r[i]);

	p = 0.0;
	for(i = 1; i <= MAX_BID; i ++)
	{
		for(k = 0; k < n; k ++)
		{
			if(!(l[k] <= i && i <= r[k]))
				continue;

			q = 1 / (double)(r[k] - l[k] + 1);

			for(j = 0; j < n; j ++)
			{
				if(i >= r[j])
					continue;

				if(k == j)
					continue;

				u = q;
				u *= (r[j] - max(l[j], i + 1) + 1) / (double)(r[j] - l[j] + 1);

				for(z = 0; z < n; z ++)
				{
					if(z == j || z == k)
						continue;

					if(l[z] > i)
					{
						u = 0.0;
						break;
					}

					if(z > k)
						u *= (min(r[z], i) - l[z] + 1) / (double)(r[z] - l[z] + 1);
					else
						u *= (min(r[z], i - 1) - l[z] + 1) / (double)(r[z] - l[z] + 1);
				}

				p += i * u;
			}

			for(j = k + 1; j < n; j ++)
			{
				if(!(l[j] <= i && i <= r[j]))
					continue;

				if(k == j)
					continue;

				u = q;
				u *= 1 / (double)(r[j] - l[j] + 1);

				for(z = 0; z < n; z ++)
				{
					if(z == j || z == k)
						continue;

					if(l[z] > i)
					{
						u = 0.0;
						break;
					}

					if(z > k && z > j)
						u *= (min(r[z], i) - l[z] + 1) / (double)(r[z] - l[z] + 1);
					else
						u *= (min(r[z], i - 1) - l[z] + 1) / (double)(r[z] - l[z] + 1);
				}

				p += i * u;
			}
		}
	}

	printf("%lf\n", p);

	return 0;
}


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

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

int compare(const void *a, const void *b) {
    return *(long long *)a - *(long long *)b;
}

int main(void) {
    int i;
    int n;
    int l[5], r[5];
    int val;
    long long cnt[10001], tmp[10001];
    double sum, ans;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d %d", l + i, r + i);

    sum = 0.0;
    for (val = 1; val <= 10000; val++) {
        int high1, high2, high3, high4, high5;
        int sec1, sec2, sec3, sec4;

        cnt[val] = 0;

        // high1パターン
        //  sec1 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                if (high1 != sec1) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1)
                            way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                        else if (i == sec1)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        //  sec2 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    if (high1 != sec1 && high1 != sec2) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1)
                                way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                            else if (i == sec1 || i == sec2)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        //  sec3 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        if (high1 != sec1 && high1 != sec2 && high1 != sec3) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1)
                                    way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                else if (i == sec1 || i == sec2 || i == sec3)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        //  sec4 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        for (sec4 = sec3 + 1; sec4 < n; sec4++)
                            if (high1 != sec1 && high1 != sec2 && high1 != sec3 && high1 != sec4) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1)
                                        way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                    else if (i == sec1 || i == sec2 || i == sec3 || i == sec4)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        // high2パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1 || i == high2)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        // high3パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1 || i == high2 || i == high3)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        // high4パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1 || i == high2 || i == high3 || i == high4)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        // high5パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++)
                        for (high5 = high4 + 1; high4 < n; high4++) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1 || i == high2 || i == high3 || i == high4 || i == high5)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        sum += cnt[val];
    }

    memcpy(tmp, cnt, sizeof cnt);
    qsort(tmp, 10001, sizeof(long long), &compare);

    sum = 0.0;
    for (i = 0; i <= 10000; i++)
        sum += tmp[i];

    sum = 1.0;
    for (i = 0; i < n; i++)
        sum *= (double)(r[i] - l[i] + 1);

    ans = 0.0;
    for (i = 1; i <= 10000; i++)
        ans += (double)i * cnt[i] / sum;

    printf("%.15f\n", ans);

    return 0;
}


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

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

int compare(const void *a, const void *b) {
    return *(long long *)a - *(long long *)b;
}

int main(void) {
    int i;
    int n;
    int l[5], r[5];
    int val;
    long long cnt[10001], tmp[10001];
    double sum, ans;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d %d", l + i, r + i);

    sum = 0.0;
    for (val = 1; val <= 10000; val++) {
        int high1, high2, high3, high4, high5;
        int sec1, sec2, sec3, sec4;

        cnt[val] = 0;

        // high1パターン
        //  sec1 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                if (high1 != sec1) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1)
                            way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                        else if (i == sec1)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        //  sec2 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    if (high1 != sec1 && high1 != sec2) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1)
                                way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                            else if (i == sec1 || i == sec2)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        //  sec3 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        if (high1 != sec1 && high1 != sec2 && high1 != sec3) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1)
                                    way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                else if (i == sec1 || i == sec2 || i == sec3)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        //  sec4 パターン
        for (high1 = 0; high1 < n; high1++)
            for (sec1 = 0; sec1 < n; sec1++)
                for (sec2 = sec1 + 1; sec2 < n; sec2++)
                    for (sec3 = sec2 + 1; sec3 < n; sec3++)
                        for (sec4 = sec3 + 1; sec4 < n; sec4++)
                            if (high1 != sec1 && high1 != sec2 && high1 != sec3 && high1 != sec4) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1)
                                        way *= max(r[i] - max(l[i], val + 1) + 1, 0);
                                    else if (i == sec1 || i == sec2 || i == sec3 || i == sec4)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        // high2パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++) {
                    long long way;

                    way = 1LL;
                    for (i = 0; i < n; i++)
                        if (i == high1 || i == high2)
                            way *= val >= l[i] && val <= r[i];
                        else
                            way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                    cnt[val] += way;
                }
        // high3パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++) {
                        long long way;

                        way = 1LL;
                        for (i = 0; i < n; i++)
                            if (i == high1 || i == high2 || i == high3)
                                way *= val >= l[i] && val <= r[i];
                            else
                                way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                        cnt[val] += way;
                    }
        // high4パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++) {
                            long long way;

                            way = 1LL;
                            for (i = 0; i < n; i++)
                                if (i == high1 || i == high2 || i == high3 || i == high4)
                                    way *= val >= l[i] && val <= r[i];
                                else
                                    way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                            cnt[val] += way;
                        }
        // high5パターン
        for (high1 = 0; high1 < n; high1++)
            for (high2 = high1 + 1; high2 < n; high2++)
                for (high3 = high2 + 1; high3 < n; high3++)
                    for (high4 = high3 + 1; high4 < n; high4++)
                        for (high5 = high4 + 1; high4 < n; high4++) {
                                long long way;

                                way = 1LL;
                                for (i = 0; i < n; i++)
                                    if (i == high1 || i == high2 || i == high3 || i == high4 || i == high5)
                                        way *= val >= l[i] && val <= r[i];
                                    else
                                        way *= max(min(r[i], val - 1) - l[i] + 1, 0);

                                cnt[val] += way;
                            }

        sum += cnt[val];
    }

    memcpy(tmp, cnt, sizeof cnt);
    qsort(tmp, 10001, sizeof(long long), &compare);

    sum = 0.0;
    for (i = 0; i <= 10000; i++)
        sum += tmp[i];

    ans = 0.0;
    for (i = 1; i <= 10000; i++)
        ans += (double)i * cnt[i] / sum;

    printf("%.15f\n", ans);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000];
	scanf("%s",a);
	int len=strlen(a);
	int mark=0;
	for(int i=0;i<len;i++)
		a[i]=a[i]-64;
	for(int i=0;i<len-2;i++)
		if(a[i+2]+1==(a[i]+a[i+1])%26)
			mark++;
	if(mark<len-2)
		printf("NO");
	else
		printf("YES");
	return 0;

}


#include<stdio.h>
int main()
{
    char a[100];
    gets(a);
    int flag=0;
    for(int i=2; a[i]!=NULL; i++)
    {
        if(a[i]-'A'!=a[i-1]+a[i-2]-2*'A')
        {
            flag=1;
            break;
        }
    }
    if(flag)printf("NO\n");
    else printf("YES\n");
}


#include <stdio.h>
#include <string.h>
int main()
{
    char string[11];
    scanf("%s",string);

    int n = strlen(string);
    if(n == 1 || n == 2)
    printf("YES\n");
    else
    {
        for(int i=2;i<n;i++)
        {
            int sum = string[i-1] - 64 + string[i-2] - 64;
            if(sum <= 26)
            {
                if( string[i] - 64 != sum -1)
                {
                printf("NO\n");
                return 0;
                }

            }
            else
            {
                if( string[i] - 64 != sum - 27)
               { printf("YES\n");
               return 0;}

            }
        }
        printf("YES\n");
    }
}


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

void main(){
  char word[10];
  scanf("%s", word);
  int first = (int) word[0] - 65;
  int second = (int) word[1] - 65;
  for (int i = 2; i < strlen(word); i++){
    if ((int) word[i] - 65 != (first + second) % 26){
      printf("NO");
      goto done;
    }
    first = second;
    second = (int) word[i] - 65;
  }
  printf("YES");
  done:
  return;
}


#include<stdio.h>

int prime(int a)
{
    int n;
    for(n=a/2;n>0;--n)
        if(a%n==0)
            break;
    return n;
}

int main()
{
    int n,sum,m;
    scanf("%d",&n);
    sum=n;
    m=prime(n);
    while(m>=1)
    {
        sum+=m;
        m=prime(m);
    }
    printf("%d\n",sum);
    return 0;
}


#include <stdio.h>
int main(){
    int n;
    int i;
    __int64 sum=0;
    scanf("%d",&n);
    sum=n;
    i=2;
    while(n>1){
//        printf("*%d\n",n);
        if(n%i==0){
            n/=i;
            sum+=n;
        }else{
            i++;
        }
    }
    printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
int fakt(int a){
 int i;
 int res=0;
 for(i=2;i<=a;i++){
 while(a%i==0){
 res+=a/i;
 a/=i;
 }
 }
return res;
}
int main(){
int a,b,c,d,e,f;
scanf("%d",&a);
int i;
int res=0;
printf("%d",a+fakt(a));
}


/*
 * File:   main.c
 * Author: scawn
 *
 * Created on April 22, 2012, 3:26 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*
 *
 */
int main(int argc, char** argv) {
    int n;

    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++){
        a[i] = 1;
    }
    int count = n;
    for (int i = 2; i * i <= n; i++) {
        if (a[i]) {
            for (int j = i * i; j <= n; j += i) {
                if (a[j]) {
                    a[j] = 0;
                    count--;
                }
            }
        }
    }
    int b[count];
    for (int k = 2, j = 0; k < n; k++){
        if (a[k]) {
            b[j] = k;
            j++;
        }
    }
    int sum = n;
    int i = 0;
    while (n > 1) {
        if (n % b[i] == 0 || n <= b[i]) {
            sum += n / b[i];
            n /= b[i];
            i = 0;
        } else {
            i++;
        }
    }
    printf("%d\n", sum);
    return (EXIT_SUCCESS);
}


// write in C...
#include <stdio.h>

#ifdef DEBUG
#define D(x...) fprintf(stderr, x)
#else
#define D(x...)
#endif

char t[10];
char s[300];

int num_need[256];
int num_have[256];

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

int main() {
    int i;

    scanf("%s %s", t, s);
    for (i = 0; t[i]; i++) num_need[t[i]]++;
    for (i = 0; s[i]; i++) num_have[s[i]]++;

    num_need['6'] += num_need['9'];
    num_need['9'] = 0;
    num_need['2'] += num_need['5'];
    num_need['5'] = 0;

    num_have['6'] += num_have['9'];
    num_have['9'] = 0;
    num_have['2'] += num_have['5'];
    num_have['5'] = 0;

    int res = 2000000000;

    for (i = 0; i < 256; i++)
        if (num_need[i])
            res = min(res, num_have[i] / num_need[i]), D("%c\n", i);

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

    return 0;
}


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

int min(int a,int b){
    if(a<b) return a;
    return b;
}
int main(){
    char ice[201];
    int tnum[10]={0,},num[10]={0,},i,t,cnt=10000000;
    scanf("%d%s",&t,ice);
    for(i=0;i<strlen(ice);i++){
        num[(int)(ice[i]-48)]++;
    }
    while(t){
        tnum[t%10]++;
        t/=10;
    }
    num[2]+=num[5];
    num[6]+=num[9];
    tnum[2]+=tnum[5];
    tnum[6]+=tnum[9];
    for(i=0;i<10;i++){
        printf("%d %d\n",num[i],tnum[i]);
    }
    for(i=0;i<10;i++){
        if(tnum[i] && i!=5 && i!=9) cnt=min(cnt,num[i]/tnum[i]);
    }
    printf("%d",cnt);
    return 0;
}


#include <stdio.h>

int min(int a,int b){
    if(a<b) return a;
    return b;
}
int main(){
    int tnum[10]={0,},num[10]={0,},i,t,ice,cnt=10000000;
    scanf("%d%d",&t,&ice);
    while(ice){
        num[ice%10]++;
        ice/=10;
    }
    while(t){
        tnum[t%10]++;
        t/=10;
    }
    num[2]+=num[5];
    num[6]+=num[9];
    tnum[2]+=tnum[5];
    tnum[6]+=tnum[9];
    for(i=0;i<10;i++){
        if(tnum[i] && i!=5 && i!=9) cnt=min(cnt,num[i]/tnum[i]);
    }
    printf("%d",cnt);
    return 0;
}


#include <stdio.h>
int a[100];
void qs(int first, int last)

{
    if (first < last)
    {
        int left = first, right = last, middle = a[(left + right) / 2];
        do
        {
            while (a[left] < middle) left++;
            while (a[right] > middle) right--;
            if (left <= right)
            {
                int tmp = a[left];
                a[left] = a[right];
                a[right] = tmp;
                left++;
                right--;
            }
        } while (left <= right);
        qs( first, right);
        qs( left, last);
    }
}

int main() {
    int n,l,r,sum,t,middle,in,i,j;
    long long int m;
    scanf("%i %lld",&n,&m);
    for (int i=1;i<=n;++i) scanf("%i",&a[i]);
    qs(1,n);

    l=1;
    r=n;

    while(l<=r){
        sum=0;
        t=n;
        middle=(l+r)/2;
        (n % middle==0)?(in= n / middle):(in=( n / middle)+1);
        for(i=0;i<in;i++){
            for(j=1;j<=middle&&t>=1;j++){
                if (a[t] - i > 0)
                    sum = sum + a[t] - i;
                t--;
            }
        }
        if(sum==m){
            l=middle;
            r=middle;
            break;
        }
        else if(sum<m){
            l=middle+1;
        }
        else{
            r=middle-1;
        }
    }

    if((l <= n) && (r >= 0)){
        if((l+r)%2!=0)
            printf("%d",(l+r)/2+1);
        else
            printf("%d",(l+r)/2);
    }
    else printf("-1");
    return 0;


#include<stdio.h>
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int fu(int a,int b){
if(a-b<=0){
    return 0;
}
else{
    return a-b;
}
}
int main()
{
    int n,m,arr[100],i,l,r,mid,in,j,sum=0,w;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    mergeSort(arr,1,n);
    l=1;r=n;
    while(l<=r)
    {sum=0;w=n;
        mid=(l+r)/2;
        (n%mid==0)?(in=n/mid):(in=(n/mid)+1);
        for(i=0;i<in;i++){
            for(j=1;j<=mid&&w>=1;j++){
                sum=sum+fu(arr[w],i);
                w--;//printf("%d ",sum);
            }
        }//printf("\n%d_%d ",mid,sum);
        if(sum==m){l=mid;r=mid;
            break;
        }
        else if(sum<m){
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
   if(l<=n&&r>=1){
       if((l+r)%2!=0)
        printf("%d",(l+r)/2+1);
        else
            printf("%d",(l+r)/2);
   }

   else printf("-1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int count[2 * 100000];
int cmp (const void *a , const void *b){
    return *(int *)a - *(int *)b;
}

int main(void){
    memset(count, 0, 100 * sizeof(int));
    int n, p, c[100];
    long int d = 0, sum = 0;
    scanf("%d%d", &n, &p);
    for(int i = 0; i < n; i++){
        scanf("%d", &c[i]);
        sum += c[i];
    }
    if(sum < p){
        printf("-1\n");
        return 0;
    }
    else if(sum == p){
        printf("%d\n", n);
        return 0;
    }
    sum = 0;
    qsort(c, n, sizeof(int), cmp);
    for(int i = 0; i < n; i++){
        for(int k = 0; k <= d; k++){
            if(c[i] >= count[k]){
                sum += c[i] - count[k], count[k]++;
                break;
            }
            if(k == d){
                sum += c[i], d++, count[d]++;
                break;
            }
        }
        if(sum >= p){
            printf("%ld\n", d + 1);
            return 0;
        }
    }
    while(d < n){
        int end = 0;
        for(int i = 0; i < d; i++){
            if(count[i] <= count[i + 1]) continue;
            else end = 1;
            while(count[i] > count[i + 1]) count[i + 1]++, sum += count[i] - count[i + 1], count[i]--;
            if(sum >= p){
                printf("%ld\n", d + 1);
                return 0;
            }
        }
        if(end == 0) d++, count[d] = 1, sum += count[d - 1] - count[d], count[d - 1]--;
        if(sum >= p){
            printf("%ld\n", d + 1);
            return 0;
        }
    }
    return 0;
}


#include<stdio.h>

void sort(int* list, int n) {
	int i, j, flag;
	flag = 1;
	while(flag == 1) {
		for(i = 0, flag = 0; i < n - 1; i++) {
			if(list[i] < list[i + 1]) {
				j = list[i];
				list[i] = list[i+1];
				list[i+1] = j;
				flag = 1;
			}
		}
	}
}

int main() {
	int n, m, days, caffeine, k, i, j, waste;
	int **cups;

	scanf("%d %d", &n, &m);
	cups = (int**)malloc(2 * sizeof(int*));
	cups[0] = (int*)malloc(n * sizeof(int)); // caffeine in cup
	cups[1] = (int*)malloc(n * sizeof(int)); // caffeine before this cup

	for(i = 0, caffeine = 0; i < n; i++) {
		scanf("%d", &cups[0][i]);
		caffeine += cups[0][i];
	}
	sort(cups[0], n);

	if(caffeine < m) {
		printf("-1\n");
		free(cups);
		return 0;
	}
	if(caffeine == m) {
		printf("%d\n", n);
		free(cups);
		return 0;
	}

	for(i = 1, cups[1][0] = cups[0][0]; i < n; i++) {
		cups[1][i] = cups[1][i-1] + cups[0][i];
		//printf("cup%d : %d %d\n", i, cups[0][i], cups[1][i]);
	}

	/*for(days = 0, n--; m > 0 && n >= 0; days++) {
		k = 0;

		while(cups[n] > k && caffeine >= (m + k)) {
			m = m - cups[n] + k;
			caffeine -= cups[n];
			n --;
			k ++;
		}
	}*/

	for(days = n; days >= 1; days--) {
		k = n / days;

		for(i = 0, caffeine = 0, waste = 0; i < k; i++) {
			j = (i + 1) * days - 1;
			if(cups[0][j] > i) {
				waste = waste + i * days;
			} else {
				while(j >= i * days) {
					if(cups[0][j] > i)
						break;
					j--;
				}

				waste = waste + i * (days - (j + 1) % days);
				caffeine = cups[1][j] - waste;
				printf("i=%d caf=%d waste=%d j=%d\n", i, caffeine, waste, j);
				break;
			}

			caffeine = cups[1][j] - waste;

			if(caffeine >= m) {
				break;
			}
		}
		//printf("        caffeine %d, waste %d\n", caffeine, waste);
		if(i < k && j < i * days)///////////////////// wrong
			break;

		i = n % days;
		if(i > 0) {
			for(j++; j < n; j++) {
				if(cups[0][j] > k) {
					waste = waste + k;
					caffeine = cups[1][j] - waste;
				} else {
					break;
				}
			}
		}
		//printf("days%d k%d: caffeine %d, waste %d\n", days, k, caffeine, waste);
		if(caffeine < m)
			break;
	}

	printf("%d\n", days+1);

	free(cups[0]);
	free(cups[1]);
	free(cups);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int count[100];
int cmp (const void *a , const void *b){
    return *(int *)b - *(int *)a;
}

int main(void){
    memset(count, 0, 100 * sizeof(int));
    int n, p, c[100], d = 0, sum = 0;
    scanf("%d%d", &n, &p);
    for(int i = 0; i < n; i++){
        scanf("%d", &c[i]);
        sum += c[i];
    }
    if(sum < p){
        printf("-1\n");
        return 0;
    }
    sum = 0;
    qsort(c, n, sizeof(int), cmp);
    int index = 0;
    for(int k = 0; index < n && sum < p; k++, d++){
        for(int i = 0; i < n; i++){
            if(c[index] - i > 0){
                sum += c[index] - i, index++, count[k]++;
                if(sum >= p){
                    printf("%d\n", d + 1);
                    return 0;
                }
            }
            else break;
        }
    }
    while(d <= n){
        for(int i = 0; i <= d; i++){
            while(count[i] >= count[i + 1]){
                int j = 0;
                while(count[i] <= count[j]) j++;
                if(j > d) d = j;
                count[j]++, sum += count[i] - count[j], count[i]--;
                if(sum >= p){
                    printf("%d\n", d + 1);
                    return 0;
                }
            }
        }
    }
    return 0;
}


char s[105],n,m,k,ans[8],G,R,has,oG,oR;
#define o(x) return puts((!x)?"First":"Second")*0
#define F(i,a,b) for(int i=a;i<=b;++i)
main(){scanf("%d%d%d",&n,&m,&k);F(i,1,n){has=G=R=0;scanf("%s",s+1);F(j,1,m)if(s[j]=='-')has=1;else if(s[j]=='G')G=j;else if(s[j]=='R')R=j;if((!G&&!R)||!has)continue;if(!G)oR=1;else if(!R)oG=1;else F(j,0,7)if((1<<j)&(abs(R-G)-1))++ans[j];}if(oR&&oG)return puts("Draw")*0;if(oR)o(1);if(oG)o(0);F(i,0,7)if(ans[i]%(k+1))o(0);o(1);}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x,y,cnt,ok;
  int r,g;
  char mp[120][120];

  while(scanf("%d%d%d",&x,&y,&k)==3){
    rep(i,x) scanf("%s",mp[i]);
    cnt = 0;
    ok = 0;

    rep(i,x){
      r=g=-1;
      rep(j,y){
        if(mp[i][j]=='R') r=j;
        if(mp[i][j]=='G') g=j;
      }
      if(r==-1 || g==-1) continue;
      if(y>2) ok = 1;
      if(r+1==g || r-1==g); else cnt++;
    }

    if(ok==0){
      puts("Draw");
      continue;
    }

    if(cnt % (k+1) == 0) puts("Second");
    else                 puts("First");
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x,y,cnt,num;
  int r,g;
  int ok_r, ok_g;
  char mp[120][120];
  int ed = 0;

  while(scanf("%d%d%d",&x,&y,&k)==3){
    if(ed) break; else ed = 1;
    rep(i,x) scanf("%s",mp[i]);
    cnt = 0;
    ok_g = ok_r = 0;

    rep(i,x){
      r=g=-1; num = 0;
      rep(j,y){
        if(mp[i][j]=='G') g=j, num++;
        if(mp[i][j]=='R') r=j, num++;
      }
      if(r==-1 || g==-1){
        if(num < y){
          if(g>=0) ok_g = 1;
          if(r>=0) ok_r = 1;
        }
        continue;
      }
      if(r+1==g || r-1==g); else cnt++;
    }

    if(ok_g && ok_r){
      puts("Draw"); continue;
    }
    if(ok_g){
      puts("First"); continue;
    }
    if(ok_r){
      puts("Second"); continue;
    }

    if(cnt % (k+1) == 0){
      puts("Second");
    } else {
      puts("First");
    }
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x,y,cnt,num;
  int r,g;
  int ok_r, ok_g;
  char mp[120][120];

  while(scanf("%d%d%d",&x,&y,&k)==3){
    rep(i,x) scanf("%s",mp[i]);
    cnt = 0;
    ok_g = ok_r = 0;

    rep(i,x){
      r=g=-1; num = 0;
      rep(j,y){
        if(mp[i][j]=='G') g=j, num++;
        if(mp[i][j]=='R') r=j, num++;
      }
      if(r==-1 || g==-1){
        if(num < y){
          if(g>=0) ok_g = 1;
          if(r>=0) ok_r = 1;
        }
        continue;
      }
      if(r+1==g || r-1==g); else cnt++;
    }

    if(ok_g && ok_r){
      puts("Draw"); continue;
    }
    if(ok_r){
      puts("First"); continue;
    }
    if(ok_g){
      puts("Second"); continue;
    }

    if(cnt % (k+1) == 0){
      puts("Second");
    } else {
      puts("First");
    }
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x,y,cnt,num;
  int r,g;
  int ok_r, ok_g;
  char mp[120][120];

  while(scanf("%d%d%d",&x,&y,&k)==3){
    rep(i,x) scanf("%s",mp[i]);
    cnt = 0;
    ok_g = ok_r = 0;

    rep(i,x){
      r=g=-1; num = 0;
      rep(j,y){
        if(mp[i][j]=='G') g=j, num++;
        if(mp[i][j]=='R') r=j, num++;
      }
      if(r==-1 || g==-1){
        if(1 < y){
          if(g>=0) ok_g = 1;
          if(r>=0) ok_r = 1;
        }
        continue;
      }
      if(r+1==g || r-1==g); else cnt++;
    }

    if(ok_g && ok_r){
      puts("Draw"); continue;
    }
    if(ok_g){
      puts("First"); continue;
    }
    if(ok_r){
      puts("Second"); continue;
    }

    if(cnt % (k+1) == 0){
      puts("Second");
    } else {
      puts("First");
    }
  }

  return 0;
}


#include <stdio.h>
#include <string.h>
#define Maxn 5007
#define modp 998244353
int p[Maxn][Maxn];
int pre[Maxn];
int a,b,c;
int solve(int x,int y)
{
	int res=0;
	for (int k=0;k<=x&&k<=y;k++)
	{
		int del=pre[k];
		del=(1LL*del*p[x][k])%modp;
		del=(1LL*del*p[y][k])%modp;
		res=(res+del)%modp;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	memset(p,0,sizeof(p));
	p[0][0]=1;
	for (int i=1;i<=5000;i++)
	{
		p[i][0]=1;
		for (int j=1;j<=i;j++)
			p[i][j]=(p[i-1][j-1]+p[i-1][j])%modp;
	}
	memset(pre,0,sizeof(pre));
	pre[0]=1;
	for (int i=1;i<=5000;i++)
		pre[i]=(1LL*pre[i-1]*i)%modp;
	int ans=1;
	ans=(1LL*ans*solve(a,b))%modp;
	ans=(1LL*ans*solve(b,c))%modp;
	ans=(1LL*ans*solve(a,c))%modp;
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>

#define MOD % 998244353

long long C[5001][5001];

void Set_Combination(int a, int b)
{
	if (a == b || b == 0)
	{
		C[a][b] = 1;
		return;
	}
	if (!C[a - 1][b])
		Set_Combination(a - 1, b);
	if (!C[a - 1][b - 1])
		Set_Combination(a - 1, b - 1);
	C[a][b] = (C[a - 1][b - 1] + C[a - 1][b]) MOD;
}

long long Permutation(int a, int b)
{
	int k;
	long long r = 1;
	if (b == 0)
		return 1;
	for (k = a; k >= a - b + 1; k = k - 1)
	{
		r = (r * k)MOD;
	}
	return r;
}

void Island(int a, int b, int * ans)
{
	int i, j, small = (a >= b ? b : a);
	long long temp = 0;
	for (i = 0; i <= small;i = i + 1)
	{
		temp = (temp + C[b][i] * Permutation(a, i)MOD) MOD;
	}
	*ans = (*ans * temp MOD);
	return;
}

int main(void)
{
	int a, b, c, ans = 1;

	for (a = 0; a <= 5000; a = a + 1)
	{
		for (b = 0; b <= a; b = b + 1)
		{
			Set_Combination(a, b);
		}
	}
	scanf("%d %d %d", &a, &b, &c);
	Island(a, b, &ans);
	Island(b, c, &ans);
	Island(c, a, &ans);
	printf("%d", ans);
	return 0;
}


#include<stdio.h>
#define maxn 5010
#define MOD 998244353
long long c[maxn][maxn];
long long calc(int a,int b){
    if(a>b){int t=b;b=a;a=t;}
    long long res=1,mul=1;
    int i;
    for(i=1;i<=a;i++){
        mul=mul*(b-i+1)%MOD;
        res=(res+c[a][i]*mul)%MOD;
    }
    return res;
}
int main(){
    int i,j;
    c[0][0]=1;
    for(i=1;i<maxn;i++){
        c[i][0]=1;
        for(j=1;j<=i;j++)
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
    }
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    long long ans=(calc(a,b)*calc(b,c)%MOD)*calc(a,c);
    printf("%lld\n",ans%MOD);
    return 0;
}


#include<stdio.h>

int main() {
	int n,m,k,i;
	scanf("%d %d %d",&n,&m,&k);
	if (n%2==0) {
		puts("Marsel");
		return 0;
	}
	if (k==1) {
		puts("Timur");
		return 0;
	}
	for(i=1;i*i<=m;i++) if (m%i==0 && m/i>=k) break;
	if (i*i>m) {
		puts("Marsel");
		return 0;
	}
	puts("Timur");
	return 0;
}


#include <stdio.h>
main()
{
        int i=0,n=0,m=0,k=0,b=1,t=0,w=0;
        scanf("%d",&n);
        scanf("%d",&m);
        scanf("%d",&k);
		if (m==1)
			printf("Marsel");
        for(i=2;i*i<=m;i++)
		{
			if (m%i==0)
			{
				if (m/i>=k)
				{
					t=1;
					w=1;
					break;}
				else t=0;
			}
		}
		if (t==0)
		{
			printf("Marsel");
			return 0;}

		if (w==1 && n%2==0)
			printf("Marsel");
		else  printf("Timur");

return 0;

		}


#include <stdio.h>

#define MAX 100000

int prime[10000];
int c;

int primes(int m){
  int i, j;
  c = 1;
  prime[1] = 2;

  for(i=3; i <= m; i+=2){
    for(j=1; j <= c; j++){
      if((i % prime[j]) == 0)
        break;
    }
    if(j > c)
      prime[++c] = i;
  }
}

int game(int m, int k){
  int i;

  for(i=1; i <= c; i++)
    if((m % prime[i]) == 0)
      if(m/prime[i] >= k)
        return 1;
      else
        return 0;
}

int main(){
  int n, m, k;
  int i;

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

  if(!(n&1)){
    printf("Marsel\n");
    return 0;
  }

  primes(m);

  if(game(m, k))
    printf("Timur\n");
  else
    printf("Marsel\n");

  return 0;
}


#include <stdio.h>

int main() {
	int m, n, k, i;
	scanf("%d %d %d", &n, &m, &k);
	for (i = 1; i*i < m; ++i) {
		if (m%i == 0) break;
	}
	if ((i <= k)&&(n%2 != 0)) printf("Timur");
	else printf("Marsel");
}


#include<stdio.h>
#include<stdlib.h>
int comp(const void * a,const void * b)
{
    return (*(int*)a - *(int*)b);
}
int arr[200009],brr[200009],crr[200009];
int main()
{
    int n,k,m,i,j,l;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&crr[i]);
    }
    qsort(crr,n,sizeof(int),comp);
    for(i=0;i<n;i++){
        j=0;
        while(1){
            arr[crr[i]]++;
            if(arr[crr[i]]<=k)
                brr[crr[i]]+=j;
            if(crr[i]==0)
                break;
            crr[i]/=2;
            j++;
        }
    }
    for(i=0;i<=200005;i++){
        if(i==0)
            l=brr[0];
        else if(arr[i]>=k && l>brr[i])
            l=brr[i];
    }
    printf("%d",l);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
int comp(const void*p,const void*q)
{
return *(const int*)p-*(const int *)q;
}
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll arr[n],count=0,x,y,flag=0,run=0,min=200000001;
	ll num[n][20],cnt[200001]={0};
	for(int i=0;i<n;i++){ scanf("%lld",&arr[i]);
	}
	qsort(arr,n,sizeof(arr[0]),comp);
	for(int i=0;i<n;i++){num[i][0]=arr[i];
	cnt[num[i][0]]++;
	for(int j=1;j<20;j++){ num[i][j]=num[i][j-1]/2;
	//printf("%lld ",num[i][j]);
	cnt[num[i][j]]++;
	}
	}
	for(int z=200000;z>=0;z--){count=0;run=0;flag=0;
	if(cnt[z]>=k) {x=z;
	//printf("%lld,%lld\n",x,cnt[x]);
	for(int i=0;i<n;i++){
	for(int j=0;j<20;j++){
	if(num[i][j]==x) {run++;
	count=count+j;
	//printf("%lld,%lld,%lld  \n",count,run,k);
	if(run>=k){flag=1;
	//printf("%lld,",run);
	break;}
	break;
	}
	}if(flag==1) break;
	}if(count<min){ min=count;
	//printf("%lld\n",min);
	}}
	}
	/*for(int i=0;i<n;i++){
	if(arr[i]>=(x)) {y=i;
	break;}
	}*/

printf("%lld",min);

return 0;}


#include <stdio.h>

#define MAX_N 200000
#define MAX_A 200000

int read_int() {
    int x;
    scanf("%d", &x) > 0;
    return x;
}

int b[MAX_A+1]; // b[x] = how many of size x are in a
int c[MAX_A+1];
int d[MAX_A+1];

int min(int a, int b) { return (a < b && a != -1) ? a : b; }

int main() {
    int n = read_int(), k = read_int(), best = -1;
    for(int i = 0; i < n; i++) b[read_int()]++;
    for(int i = 0; i <= MAX_A; i++) c[i] = b[i];
    for(int e = 1; e < 20; e++) {
        for(int i = 0; i <= MAX_A; i++) {
            if(b[i] >= k && b[i]-c[i] < k) {
                best = min(best, d[i] - (e-1) * (b[i]-k));
            }
            c[i] = 0;
            if (i*2 <= MAX_A) c[i] += c[i*2], d[i] += c[i*2] * e;
            if (i*2+1 <= MAX_A) c[i] += c[i*2+1], d[i] += c[i*2+1] * e;
            b[i] += c[i];
        }
    }
    printf("%d\n", best);
}


/* Coached by rainboy */
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define N 200000
#define A 200000
#define INF	2147483647

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int aa[N], ss[A + 1], kk[A + 1];
	int n, k, i, j, tmp, a, s, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	srand(time(NULL));
	for (i = n - 1; i >= 0; i--) {
		j = rand() % n;
		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	qsort(aa, n, sizeof *aa, compare);
	for (i = 0; i < n; i++) {
		a = aa[i];
		s = 0;
		while (a > 0) {
			if (kk[a] < k) {
				kk[a]++;
				ss[a] += s;
			}
			a /= 2;
			s++;
		}
	}
	ans = INF;
	for (a = 1; a <= A; a++)
		if (kk[a] == k && ans > ss[a])
			ans = ss[a];
	printf("%d\n", ans);
	return 0;
}


/* Coached by rainboy */
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define N 200000
#define A 200000
#define INF 0x3f3f3f3f

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int aa[N], ss[A + 1], kk[A + 1];
	int n, k, i, j, tmp, a, s, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	srand(time(NULL));
	for (i = n - 1; i >= 0; i--) {
		j = rand() % n;
		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	qsort(aa, n, sizeof *aa, compare);
	for (i = 0; i < n; i++) {
		a = aa[i];
		s = 0;
		while (a > 0) {
			if (kk[a] < k) {
				kk[a]++;
				ss[a] += s;
			}
			a /= 2;
			s++;
		}
	}
	ans = INF;
	for (a = 1; a <= A; a++)
		if (kk[a] == k && ans > ss[a])
			ans = ss[a];
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int cmp(const void *a,const void *b)
{
    return ( *(int*)b-*(int*)a);
}

int main()
{
    int n,k,x,t[110],i,sum=0,j;
    scanf("%d%d%d",&n,&k,&x);

    for (i=0;i<n;i++){
        scanf("%d",&t[i]);
        sum+=t[i];
    }
    qsort(t,n,sizeof(t[0]),cmp);
    sum+=x*k;

    for (i=0;i<k;i++){
        sum-=t[i];
    }

    printf("%d",sum);
}


#include<stdio.h>
int main(){
	//int a[101];
	int n,k,x;
	int sum=0;
	scanf("%d%d%d",&n,&k,&x);
	for(int i=0;i<n;i++){
		int temp;
		scanf("%d",&temp);/*
		if(i<n-2){
			sum+=temp;
		}else{

		}*/
		(i<n-2)?sum+=temp:sum+=x;
	}
	printf("%d\n",sum);
}


#include<stdio.h>
int main()int n,k,x,i,j,a,sum;
    scanf("%d%d%d",&n,&k,&x);
    int number[n];
    for(i=0;i<n;i++){
          scanf("%d",&number[i]);
    }

    sum=k*x;
    for(j=0;j<n-2;j++){
       sum=sum+number[j];
    }
    printf("%d\n",sum);
    return 0;

}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="hassen" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/hassen" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/hassen" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
		</Compiler>
		<Unit filename="main.c">
			<Option compilerVar="CC" />
		</Unit>
		<Extensions>
			<code_completion />
			<debugger />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<stdio.h>
int main()
{
    int n,k,x,i,j,a,sum;
    scanf("%d%d%d",&n,&k,&x);
    int number[n];
    for(i=0;i<n;i++){
          scanf("%d",&number[i]);
    }
      for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] < number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    sum=k*x;
    for(j=2;j<n;j++){
       sum=sum+number[j];
    }
    printf("%d\n",sum);
    return 0;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long arr[3][3], sum[3]; int i, j, maxX, tmpMax = -1;
    for (i = 0; i < 3; i++){
        sum[i] = 0;
        for (j = 0; j < 3; j++){
            scanf("%ld", &arr[i][j]);
            sum[i] += arr[i][j];
        }
        if (tmpMax == -1) {tmpMax = sum[i]; maxX = i;}
        else if (tmpMax < sum[i]) {tmpMax = sum[i]; maxX = i;}
    }
    arr[maxX][maxX] = 1;
    for (i = 0; i < 3; i++){
        if (i != maxX){
            arr[i][i] = sum[maxX] - sum[i] + 1;
        }
        printf("%ld %ld %ld\n", arr[i][0], arr[i][1], arr[i][2]);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MODULO 1000000007

int ma[20][20];
int b[20], col[20];
int n;

long long sols[17] = {0,1,0,18,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555,0};

long long dfs(int x, int k);
long long precalc();

int main(){

   	//precalc();

	int n;
	scanf("%d", &n);
	printf("%I64d\n", sols[n]);

#ifdef _AT_HOME_
    system("pause");
#endif

    return 0;
}

long long dfs(int x, int k){
	if (k>n){
		return 1;
	}
	int i;
	int t = 0;
	for (i=1;i<=n;i++){
		if (b[ma[k][i]] || col[i]) continue;
		b[ma[k][i]] = 1;
		col[i] = 1;
		t +=dfs(i, k+1);
		b[ma[k][i]] = 0;
		col[i] = 0;
	}
	return t;
}

long long precalc(){
	int tt;
	for (tt=1;tt<16;tt+=2){

		int i,j;
	    n = tt;

	    for (i=1;i<=n;i++){
	    	for (j=1;j<=n;j++){
	    		ma[i][j] = (i-1+j-1) % n + 1;
	    	}
	    }

	    long long sol = 0;
	    for (i=1;i<=1;i++){
	    	b[ma[1][i]] = 1;
	    	col[i] = 1;
	    	sol += dfs(i, 2);
	    	if (sol>MODULO){
	    		sol -= MODULO;
	    	}
	    	b[ma[1][i]] = 0;
	    	col[i] = 0;
	    }

	    sol *= n;
	    sol %= MODULO;

	    long long fak = 1;
	    for (i=2;i<=n;i++){
	    	fak *= i;
	    	fak %= MODULO;
	    }

	    sol *= fak;
	    sol %= MODULO;

	    printf("%I64d\n", sol);
	}
}


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

#define MAX 14
#define PAD  666667
#define HMOD 15000017
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long fact[20];
unsigned int n, dp[HMOD + PAD], hashtable[HMOD + PAD];

void insert(unsigned int x, int v){
    int i = ++x % HMOD;
    while (hashtable[i] && hashtable[i] != x) i++;
    hashtable[i] = x, dp[i] = v;
}

int find(unsigned int x){
    int i = ++x % HMOD;
    while (hashtable[i] && hashtable[i] != x) i++;
    return (hashtable[i] == x ? dp[i] : -1);
}

long long F(int i, int mask, int lol){
    if (i == n) return 1;
    int j, k, h = (mask << 16) ^ lol, v = find(h);
    if (v != -1) return v;

    long long res = 0;
    for (j = 0; j < n; j++){
        if (!(mask & (1 << j))){
            k = i + j;
            if (k >= n) k -= n;
            if (!(lol & (1 << k))) res += F(i + 1, mask | (1 << j), lol | (1 << k));
        }
    }

    res %= MOD;
    insert(h, res);
    return res;
}

int main(){
    int i, j, k;
    for (fact[0] = 1, i = 1; i < 20; i++) fact[i] = (fact[i - 1] * i) % MOD;

    while (scanf("%d", &n) != EOF){
        clr(hashtable);
        if (n & 1) printf("%lld\n", (fact[n] * F(0, 0, 0)) % MOD);
        else puts("0");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MODULO 1000000007

int ma[20][20];
int b[20], col[20];
int n;

long long sols[17] = {0,1,0,18,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555,0};

long long dfs(int x, int k);
long long precalc();

int main(){

   	//precalc();

	int n;
	scanf("%d", &n);
	printf("%I64\n", sols[n]);

#ifdef _AT_HOME_
    system("pause");
#endif

    return 0;
}

long long dfs(int x, int k){
	if (k>n){
		return 1;
	}
	int i;
	int t = 0;
	for (i=1;i<=n;i++){
		if (b[ma[k][i]] || col[i]) continue;
		b[ma[k][i]] = 1;
		col[i] = 1;
		t +=dfs(i, k+1);
		b[ma[k][i]] = 0;
		col[i] = 0;
	}
	return t;
}

long long precalc(){
	int tt;
	for (tt=1;tt<16;tt+=2){

		int i,j;
	    n = tt;

	    for (i=1;i<=n;i++){
	    	for (j=1;j<=n;j++){
	    		ma[i][j] = (i-1+j-1) % n + 1;
	    	}
	    }

	    long long sol = 0;
	    for (i=1;i<=1;i++){
	    	b[ma[1][i]] = 1;
	    	col[i] = 1;
	    	sol += dfs(i, 2);
	    	if (sol>MODULO){
	    		sol -= MODULO;
	    	}
	    	b[ma[1][i]] = 0;
	    	col[i] = 0;
	    }

	    sol *= n;
	    sol %= MODULO;

	    long long fak = 1;
	    for (i=2;i<=n;i++){
	    	fak *= i;
	    	fak %= MODULO;
	    }

	    sol *= fak;
	    sol %= MODULO;

	    printf("%I64d\n", sol);
	}
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 55
#define MAXK 105

struct datanode
{
	long long int a, b;
	int c, d, orig;
};

struct node
{
	char b;
	int j, k;
};

void sort (struct datanode a[MAXN], int l, int r)
{
	int i, j, x;
	struct datanode y;
	i = l; j = r; x = a[(l+r)/2].c;
	while (i <= j)
	{
		while (a[i].c < x) i++;
		while (a[j].c > x) j--;
		if (i <= j)
		{
			y = a[i]; a[i] = a[j]; a[j] = y;
			i++; j--;
		}
	}
	if (l < j) sort(a,l,j);
	if (i < r) sort(a,i,r);
}

int main ()
{
	int N, M, K;
	scanf("%d %d %d",&N,&M,&K);
	int i, j, j2, k;
	static struct datanode data[MAXN];
	for (i = 0; i < M; i++)
	{
		scanf("%I64i %I64i %d",&(data[i].a),&(data[i].b),&(data[i].c));
		data[i].orig = i;
		data[i].d = (int)(data[i].b - data[i].a);
	}
	sort(data,0,M-1);
	static struct node a[MAXN][MAXN][MAXK];
	memset(a,0,sizeof(a));
	for (j = 0; j < M; j++)
	{
		for (k = 0; k <= data[j].d; k++)
		{
			a[0][j][k].b = 1;
			a[0][j][k].j = -1;
			a[0][j][k].k = -1;
		}
	}
	long long int next;
	for (i = 0; i < (N-1); i++)
	{
		for (j = 0; j < M; j++)
		{
			for (k = 0; k <= data[j].d; k++)
			{
				if (a[i][j][k].b)
				{
					for (j2 = j+1; j2 < M; j2++)
					{
						if (data[j2].c > data[j].c)
						{
							//k + K
							next = data[j].a + (long long int)(k) + (long long int)(K);
							if ((next >= data[j2].a) && (next <= data[j2].b))
							{
								a[i+1][j2][(int)(next - data[j2].a)].b = 1;
								a[i+1][j2][(int)(next - data[j2].a)].j = j;
								a[i+1][j2][(int)(next - data[j2].a)].k = k;
							}
							//k * K
							next = (data[j].a + (long long int)(k)) * (long long int)(K);
							if ((next >= data[j2].a) && (next <= data[j2].b))
							{
								a[i+1][j2][(int)(next - data[j2].a)].b = 1;
								a[i+1][j2][(int)(next - data[j2].a)].j = j;
								a[i+1][j2][(int)(next - data[j2].a)].k = k;
							}
						}
					}
				}
			}
		}
	}
	for (j = 0; j < M; j++)
	{
		for (k = 0; k <= data[j].d; k++)
		{
			if (a[N-1][j][k].b)
			{
				printf("YES\n");
				static struct node r[MAXN];
				int rc = 1;
				r[0].j = j;
				r[0].k = k;
				for (i = N-1; i > 0; i--)
				{
					r[rc].j = a[i][r[rc-1].j][r[rc-1].k].j;
					r[rc].k = a[i][r[rc-1].j][r[rc-1].k].k;
					rc++;
				}
				for (i = N-1; i >= 0; i--)
				{
					printf("%d %I64i\n",data[r[i].j].orig + 1,data[r[i].j].a + (long long int)(r[i].k));
				}
				return 0;
			}
		}
	}
	printf("NO\n");
	return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>

#define N	100
#define M	50
#define A	100

struct V {
	long long a, b;
	int c, j;
} vv[M];

int compare(const void *a, const void *b) {
	struct V *u = (struct V *) a;
	struct V *v = (struct V *) b;

	return u->c - v->c;
}

int main() {
	static char dp[N][M][A + 1];
	static int jj[N];
	static long long aa[N];
	struct V *u, *v;
	int n, m, k, i, j, j_, a;
	long long a_, a1, a2;

	scanf("%d%d%d", &n, &m, &k);
	for (j = 0; j < m; j++) {
		u = &vv[j];
		scanf("%lld%lld%d", &u->a, &u->b, &u->c);
		u->j = j;
	}
	qsort(vv, m, sizeof *vv, compare);
	for (j = 0; j < m; j++) {
		u = &vv[j];
		for (a = 0; a <= u->b - u->a; a++)
			dp[0][j][a] = 1;
	}
	for (i = 0; i < n - 1; i++)
		for (j = 0; j < m; j++) {
			u = &vv[j];
			for (a = 0; a <= u->b - u->a; a++)
				if (dp[i][j][a]) {
					a1 = u->a + a + k, a2 = (u->a + a) * k;
					for (j_ = j + 1; j_ < m; j_++) {
						v = &vv[j_];
						if (v->c > u->c) {
							if (v->a <= a1 && a1 <= v->b)
								dp[i + 1][j_][a1 - v->a] = 1;
							if (v->a <= a2 && a2 <= v->b)
								dp[i + 1][j_][a2 - v->a] = 1;
						}
					}
				}
		}
	for (j = 0; j < m; j++) {
		u = &vv[j];
		for (a = 0; a <= u->b - u->a; a++)
			if (dp[n - 1][j][a]) {
				for (i = n - 1; i >= 0; i--) {
					jj[i] = vv[j].j;
					aa[i] = a_ = vv[j].a + a;
					if (i == 0)
						break;
					for (j_ = j - 1; j_ >= 0; j_--) {
						v = &vv[j_];
						if (v->c < u->c) {
							if (v->a <= a_ - k && a_ - k <= v->b) {
								a = a_ - k - v->a;
								if (dp[i - 1][j_][a]) {
									j = j_;
									break;
								}
							}
							if (a_ % k == 0)
								if (v->a <= a_ / k && a_ / k <= v->b) {
									a = a_ / k - v->a;
									if (dp[i - 1][j_][a]) {
										j = j_;
										break;
									}
								}
						}
					}
				}
				printf("YES\n");
				for (i = 0; i < n; i++)
					printf("%d %lld\n", jj[i] + 1, aa[i]);
				return 0;
			}
	}
	printf("NO\n");
	return 0;
}


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

typedef long long ll;

typedef struct {
  ll a,b;
  int c;
} t_t;

/*  n days, m subjects */
int n,m,K;
t_t emne[150];

/*  [i][j][k]: at beginning of day i (0-indexed), j is last course taken
    (1-indexed, 0=no course taken yet), k:last number of exercises=a_j+k */
ll dp[51][52][101];
int dp1[51][52][101];
int dp2[51][52][101];

void solve() {
  int i,j,k,l,nextj,nextk;
  ll diff,nextd,cur,next;
  memset(dp,-1,sizeof(dp));
  memset(dp2,-1,sizeof(dp2));
  memset(dp2,-1,sizeof(dp2));
  dp[0][0][0]=0;
  dp1[0][0][0]=-1;
  dp2[0][0][0]=0;
  for(i=0;i<n;i++) {
    for(j=0;j<=m;j++) for(k=0;k<101;k++) if(dp[i][j][k]>-1) {
      cur=dp[i][j][k];
      /*  pick next exercise */
/*      if(!j) printf("at day %d, no last course\n",i);
      else printf("at day %d, last course %d, last ex %I64d\n",i,j-1,k+emne[j-1].a);*/
      if(i==0 && j==0) {
        /*  first day, can pick everything */
        for(nextj=0;nextj<m;nextj++) for(nextk=0;nextk<=(int)(emne[nextj].b-emne[nextj].a);nextk++) {
          dp[i+1][nextj+1][nextk]=nextk+emne[nextj].a;
          dp1[i+1][nextj+1][nextk]=k;
          dp2[i+1][nextj+1][nextk]=j;
        }
      } else for(l=0;l<m;l++) if(emne[l].c>emne[j-1].c) {
        /*  difficulty: add k */
        diff=k+emne[j-1].a;
        nextd=diff+K;
        next=cur+nextd;
        if(nextd>=emne[l].a && nextd<=emne[l].b && next>dp[i+1][l+1][(int)(nextd-emne[l].a)]) {
          dp[i+1][l+1][(int)(nextd-emne[l].a)]=next;
          dp1[i+1][l+1][(int)(nextd-emne[l].a)]=k;
          dp2[i+1][l+1][(int)(nextd-emne[l].a)]=j;
/*          printf("  (add) can pick => %d %d %I64d\n",i+1,l,nextd);*/
        }
        /*  difficulty: mul k */
        nextd=diff*K;
        next=cur+nextd;
        if(nextd>=emne[l].a && nextd<=emne[l].b && next>dp[i+1][l+1][(int)(nextd-emne[l].a)]) {
          dp[i+1][l+1][(int)(nextd-emne[l].a)]=next;
          dp1[i+1][l+1][(int)(nextd-emne[l].a)]=k;
          dp2[i+1][l+1][(int)(nextd-emne[l].a)]=j;
/*          printf("  (mul) can pick => %d %d %I64d\n",i+1,l,nextd);*/
        }
      }
    }
  }
}

int fag[100];
ll ex[100];

/*  x: last course (1-indexed), y:last k-value */
void timeplan(int x,int y) {
  int dag=n;
  int i,j;
  while(dag) {
    fag[dag-1]=x;
    ex[dag-1]=y+emne[x-1].a;
    i=dp2[dag][x][y];
    j=dp1[dag][x][y];
    dag--;
    x=i;
    y=j;
  }
  for(i=0;i<n;i++) printf("%d %I64d\n",fag[i],ex[i]);
}

int main() {
  int i,j;
  ll maks=0;
  int besti=-1,bestj=0;
  scanf("%d %d %d",&n,&m,&K);
  for(i=0;i<m;i++) scanf("%I64d %I64d %d",&emne[i].a,&emne[i].b,&emne[i].c);
  solve();
  for(i=1;i<=m;i++) for(j=0;j<=100;j++) if(dp[n][i][j]>maks) {
    maks=dp[n][i][j];
    besti=i;
    bestj=j;
  }
  if(besti<0) puts("NO");
  else {
    puts("YES");
    timeplan(besti,bestj);
    return 0;
  }
  puts("NO");
  return 0;
}


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

typedef long long ll;

typedef struct {
  ll a,b;
  int c;
} t_t;

/*  n days, m subjects */
int n,m,K;
t_t emne[150];

/*  [i][j][k]: at beginning of day i (0-indexed), j is last course taken
    (1-indexed, 0=no course taken yet), k:last number of exercises=a_j+k */
/*  -1 state doesn't exist, otherwise dp1 is last k-value,
    dp2 is last course before that */
int dp[51][52][101];
int dp2[51][52][101];

void solve() {
  int i,j,k,l,nextj,nextk;
  ll diff,nextd;
  memset(dp,-1,sizeof(dp));
  memset(dp2,-1,sizeof(dp2));
  dp[0][0][0]=999;
  for(i=0;i<n;i++) {
    for(j=0;j<=m;j++) for(k=0;k<101;k++) if(dp[i][j][k]>-1) {
      /*  pick next exercise */
/*      if(!j) printf("at day %d, no last course\n",i);
      else printf("at day %d, last course %d, last ex %I64d\n",i,j-1,k+emne[j-1].a);*/
      if(i==0 && k==0) {
        /*  first day, can pick everything */
        for(nextj=0;nextj<m;nextj++) for(nextk=0;nextk<=(int)(emne[nextj].b-emne[nextj].a);nextk++) {
          dp[i+1][nextj+1][nextk]=k;
          dp2[i+1][nextj+1][nextk]=j;
        }
      } else for(l=0;l<m;l++) if(emne[l].c>emne[j-1].c) {
        /*  difficulty: add k */
        diff=k+emne[j-1].a;
        nextd=diff+K;
        if(nextd>=emne[l].a && nextd<=emne[l].b) {
          dp[i+1][l+1][(int)(nextd-emne[l].a)]=k;
          dp2[i+1][l+1][(int)(nextd-emne[l].a)]=j;
/*          printf("  (add) can pick => %d %d %I64d\n",i+1,l,nextd);*/
        }
        /*  difficulty: mul k */
        if((double)nextd*K>1e16) continue;
        nextd=diff*K;
        if(nextd>=emne[l].a && nextd<=emne[l].b) {
          dp[i+1][l+1][(int)(nextd-emne[l].a)]=k;
          dp2[i+1][l+1][(int)(nextd-emne[l].a)]=j;
/*          printf("  (mul) can pick => %d %d %I64d\n",i+1,l,nextd);*/
        }
      }
    }
  }
}

int fag[100];
ll ex[100];

/*  x: last course (1-indexed), y:last k-value */
void timeplan(int x,int y) {
  int dag=n;
  int i,j;
  while(dag) {
    fag[dag-1]=x;
    ex[dag-1]=y+emne[x-1].a;
    i=dp2[dag][x][y];
    j=dp[dag][x][y];
    dag--;
    x=i;
    y=j;
  }
  for(i=0;i<n;i++) printf("%d %I64d\n",fag[i],ex[i]);
}

int main() {
  int i,j;
  scanf("%d %d %d",&n,&m,&K);
  for(i=0;i<m;i++) scanf("%I64d %I64d %d",&emne[i].a,&emne[i].b,&emne[i].c);
  solve();
  for(i=1;i<=m;i++) for(j=0;j<=100;j++) if(dp[n][i][j]>-1) {
    puts("YES");
    timeplan(i,j);
    return 0;
  }
  puts("NO");
  return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define MAX_N (5000)
#define MAX_K (5000)
#define MOD   (1000000007)

int n,b;
int memo[MAX_N+1][MAX_K+1];

int min(int x, int y) { return x < y ? x : y; }

int max(int x, int y) { return x > y ? x : y; }

int f(int x, int t) {
  int i,acc=0;

  if ( !t )
    return 1;
  if ( (x-b)*(x-b) == 1 )
    return 0;
  if ( memo[x][t] )
    return memo[x][t];
  for ( i=max(1, x-abs(x-b)-1); i < min(n, x+abs(x-b)); ++i ) {
    if ( i == x ) continue;
    acc = (acc + f(i, t-1)) % MOD;
  }
  return memo[x][t] = acc;
}

int main() {
  int a,k;

  scanf("%d %d %d %d", &n, &a, &b, &k);
  printf("%d\n", f(a, k));
  return EXIT_SUCCESS;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

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

long long dpp[5002][5002];
int n , a , b , k ;

#define MOD 1000000007

void build(long long arr[] , long long rmq []){
	int i ;
	for(i = 1 ; i <= n ; i++){
		// cout << arr[i] << " " ;
		int index = i ;
		while(index <= n){
			rmq[index] += arr[i] ;
			index += (index & -index);
		}
	}
	//cout << endl ;
}

long long query(long long rmq [] , int to){
	long long ret = 0 ;
	// cout << "to : " << to << " : "  ;
	while(to > 0){
		ret += rmq[to];
		ret %= MOD ;
		to -= (to & -to);
	}
	//cout <<ret << endl ;
	return ret ;
}

int main(){
	scanf("%d%d%d%d" , & n , &a , &b , &k);
	int i ;
	for(i = 1 ; i <= n ; i ++){
		dpp[0][i] = 1 ;
	}
	dpp[0][b] = 0 ;
	for(i =  1 ; i <= k ; i++){
		// cout << i << " : " << endl ;
		long long rmq [10003] ={0};
		build(dpp[i-1] , rmq);
		int j ;
		for(j = 1 ; j <= n; j++){
			if(j == b)
				continue ;
			int diff = abs(b - j) - 1;
			dpp[i][j] = query(rmq , min(n , j + diff));
			dpp[i][j] -= query(rmq , max(1 , j - diff) -1 );
			dpp[i][j] -= dpp[i-1][j];
			dpp[i][j] %= MOD ;
			dpp[i][j] += MOD ;
			dpp[i][j] %= MOD ;
		}
		// cout << i << " :  => " << endl ;
		// for(int j = 1 ; j <= n ; j++){
		// 	cout << dpp[i][j] << " ";
		// }
		//cout << endl ;
	}
	printf("%d" , dpp[k][a]);
	return 0 ;
}


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

int mem [5001][5001];
int N, b, a, K;
int MOD = 1000000007;

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

int solve(int id, int restan)	{
	if	( restan == 0 )
		return	1;

	if	( mem[id][restan] != -1 )
		return	mem[id][restan];

	int dist = abs(b - id);
	int ans = 0;
	int y;
	for (y = max(1, id - dist + 1); y <= min(N, id + dist - 1); y++)	{
		if	( y != b && y != id )	{
			ans += solve(y, restan - 1);
			if	( ans >= MOD )
				ans -= MOD;
		}
	}
	return	mem[id][restan] = ans;
}

int main(int argc, char *argv[])	{
	scanf("%d %d %d %d", &N, &a, &b, &K);

	int i, j, id, k, dist, x, y, sum;

	/*
	for (i = 1; i <= N; i++)	{
		for (j = 1; j <= K; j++)	{
			mem[i][j] = -1;
		}
	}
	*/

	for (id = 1; id <= N; id++)	{
		mem[id][0] = 1;
	}
	mem[b][0] = 0;

	for (k = 1; k <= K; k++)	{
		for (id = 1; id <= N; id++)	{
			dist = abs(id - b);
			x = max( 1, id - dist + 1 );
			y = min( N, id + dist - 1 );

			sum = 0;
			while	( x <= y )	{
				sum += mem[x++][k - 1];
				if	( sum >= MOD )
					sum -= MOD;
			}

			sum -= mem[b][k - 1];
			if	( sum < 0 )
				sum = (sum + MOD);

			sum -= mem[id][k - 1];

			if	( sum < 0 )
				sum = (sum + MOD);

			mem[id][k] = sum;
		}
	}
	/*
	for (i = 1; i <= N; i++)	{
		for (j = 0; j <= K; j++)	{
			printf( "mem(%d, %d) = %d\n", i, j, mem[i][j] );
		}
		printf("\n");
	}
	*/
	printf( "%d\n", mem[a][K] );

    return 0;
}


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

int mem [5001][5001];
int N, b, a, K;
int MOD = 1000000007;

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

int solve(int id, int restan)	{
	if	( restan == 0 )
		return	1;

	if	( mem[id][restan] != -1 )
		return	mem[id][restan];

	int dist = abs(b - id);
	int ans = 0;
	int y;
	for (y = max(1, id - dist + 1); y <= min(N, id + dist - 1); y++)	{
		if	( y != b && y != id )	{
			ans += solve(y, restan - 1);
			if	( ans >= MOD )
				ans -= MOD;
		}
	}
	return	mem[id][restan] = ans;
}

int main(int argc, char *argv[])	{
	scanf("%d %d %d %d", &N, &a, &b, &K);

	int i, j;
	i = j = 1;

	for (i = 1; i <= N; i++)	{
		for (j = 1; j <= K; j++)	{
			mem[i][j] = -1;
		}
	}

	printf( "%d\n", solve(a, K) );

    return 0;
}


#include <stdio.h>

int main()
{
	int n, m[17], r[17], max=0, dem=0;
	double ans;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&m[i]);
		if (max<m[i]) max=m[i];
	}
	for (int i=1;i<=n;i++) scanf("%d",&r[i]);
	if (n==1) ans=1/(double)max;
	else
	{
	for (int i=1;i<=max;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (i%m[j]==r[j])
			{
				dem++;
				break;
			}
		}
	}
	ans=(double)dem/max;
	}
	printf("%f",ans);
}


#include<stdio.h>

int main()
{
    long long int n,i,j;
    double res,c=0.0;
    scanf("%I64d",&n);
    long long int a[n],b[n];
    for(i=0;i<n;i++)
        scanf("%I64d",&a[i]);
    for(i=0;i<n;i++)
        scanf("%I64d",&b[i]);

    for(i=0;i<=n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i%a[j]==b[j])
                c+=1.0;
        }
    }
    printf("%lf",c/(n+1));
}


#include <stdio.h>

int main()
{
	int n, m[17], r[17], dem=0;
	long max=10000000;
	double ans;
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&m[i]);
	for (int i=1;i<=n;i++) scanf("%d",&r[i]);
	if (n==1) ans=1/(double)max;
	else
	{
	for (long i=1;i<=max;i++)
	{
		for (long j=1;j<=n;j++)
		{
			if (i%m[j]==r[j])
			{
				dem++;
				break;
			}
		}
	}
	ans=(double)dem/max;
	}
	printf("%f",ans);
}


#include <stdio.h>

int main()
{
	int n, m[17], r[17],max=0,dem=0;
	bool kt=true;
	double ans;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&m[i]);
		if (max<m[i]) max=m[i];
	}
	for (int i=1;i<=n;i++) scanf("%d",&r[i]);
	if (n==1) ans=1/(float)max;
	else
	{
	for (int i=1;i<=max;i++)
	{
		kt=true;
		for (int j=1;j<=n;j++)
		{
			if (i%m[j]==r[j])
			{
				dem++;
				break;
			}
		}
	}
	ans=(float)dem/max;
	}
	printf("%.6f",ans);

}


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

typedef unsigned long long ll;
typedef unsigned int uint;

int mod = 998244353;

ll pp[501][501];

ll qPow(uint a, uint b)
{
  if (pp[a][b] > 0)
  {
    return pp[a][b];
  }
  ll ret = 1, aa = a;
  uint  bb = b;
  while (bb)
  {
    if (bb & 1)
      ret = ret * aa % mod;
    aa = aa * aa % mod;
    bb >>= 1;
  }
  pp[a][b] = ret;
  return ret;
}

uint C[501][501];
uint inited = 0;
void init()
{
  if (inited)
    return;
  inited = 1;
  memset(pp, 0, sizeof(pp));
  memset(C, 0, sizeof(C));
  for (uint i = 0; i <= 500; i++)
  {
    for (uint j = 0; j <= i; j++)
    {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] >= mod)
        C[i][j] -= mod;
    }
  }
}
ll f[501][501];
int main()
{
  uint n, x;
  scanf("%u %u", &n, &x);
  init();
  memset(f, 0, sizeof(f));
  for (uint i = 2; i <= n; i++)
  {
    for (uint j = 1; j <= x; j++)
    {
      if (j < i)
      {
        f[i][j] = qPow(j, i);
      }
      else
      {
        f[i][j] = qPow(i - 1, i);
        for (uint k = 2; k <= i; k++)
        {
          f[i][j] = (f[i][j] + C[i][k] * qPow(i - 1, i - k) % mod * f[k][j - i + 1]) % mod;
        }
      }
    }
  }

  printf("%llu", f[n][x]);
  return 0;
}


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

typedef long long ll;

int mod = 998244353;

ll qPow(ll a, ll  b) {
	ll ret = 1;
	while(b) {
		if(b&1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

int main() {
    int n, x;
    scanf("%d %d", &n, &x);
	int C[n+1][n+1];
	memset(C,0,sizeof(C));
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++) {
			if(!j)
				C[i][j] = 1;
			else
				C[i][j] = C[i-1][j] + C[i-1][j-1];
				if(C[i][j] >= mod)
				    C[i][j] -= mod;

		}
	}
	ll f[n+1][x+1];
	memset(f,0,sizeof(f));
	for(int i=2;i<=n;i++){
		for(int j=1;j<=x;j++) {
			if(j<i) {
				f[i][j] = qPow(j, i);
			} else {
				f[i][j] = qPow(i-1, i);
				for(int k=2;k<=i;k++) {
					f[i][j] = (f[i][j]+C[i][k]*qPow(i-1,i-k)%mod*f[k][j-i+1]%mod)%mod;
				}
			}
		}
	}

    printf("%lld", f[n][x]);
    return 0;
}


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

typedef unsigned long long ull;
typedef unsigned int uint;

uint mod = 998244353;

ull qPow[501][501];
uint C[501][501];
uint f[501][501];
int main()
{
  uint n, x;
  scanf("%u %u", &n, &x);
  memset(qPow, 0, sizeof(qPow));
  for (uint i = 1; i <= x; i++)
  {
    qPow[i][0] = 1;
    for (uint j = 1; j <= n; j++)
    {
      qPow[i][j] = qPow[i][j - 1] * i % mod;
    }
  }
  memset(C, 0, sizeof(C));
  for (uint i = 0; i <= n; i++)
  {
    for (uint j = 0; j <= i; j++)
    {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] >= mod)
        C[i][j] -= mod;
    }
  }
  memset(f, 0, sizeof(f));
  for (uint i = 2; i <= n; i++)
  {
    for (uint j = 1; j <= x; j++)
    {
      if (j < i)
      {
        f[i][j] = qPow[j][i];
      }
      else
      {
        f[i][j] = qPow[i - 1][i];
        for (uint k = 2; k <= i; k++)
        {

          f[i][j] = (f[i][j] + C[i][k] * qPow[i - 1][i - k] % mod * f[k][j - i + 1]) % mod;
        }
      }
    }
  }

  printf("%llu", f[n][x]);
  return 0;
}


#include <stdio.h>

typedef long long ll;

int mod = 998244353;

ll qPow(ll a, ll  b) {
	ll ret = 1;
	while(b) {
		if(b&1)
			ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret;
}

int main() {
    int n, x;
    scanf("%d %d", &n, &x);
	ll C[n+1][n+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++) {
			if(!j)
				C[i][j] = 1;
			else
				C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
		}
	}
	ll f[n+1][x+1];
	for(int i=2;i<=n;i++){
		for(int j=1;j<=x;j++) {
			if(j<i) {
				f[i][j] = qPow(j, i);
			} else {
				f[i][j] = qPow(i-1, i);
				for(int k=2;k<=i;k++) {
					f[i][j] = (f[i][j]+C[i][k]*qPow(i-1,i-k)%mod*f[k][j-i+1]%mod)%mod;
				}
			}
		}
	}

    printf("%lld", f[n][x]);
    return 0;
}


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

typedef unsigned long long ll;
typedef unsigned int uint;

int mod = 998244353;

uint pp[501][501];

ll qPow(uint a, uint b)
{
  if (pp[a][b] > 0)
  {
    return pp[a][b];
  }
  ll ret = 1, aa = a;
  while (b)
  {
    if (b & 1)
      ret = ret * aa % mod;
    aa = aa * aa % mod;
    b >>= 1;
  }
  pp[a][b] = ret;
  return ret;
}

uint C[501][501];
uint inited = 0;
void init()
{
  if (inited)
    return;
  inited = 1;
  memset(pp, 0, sizeof(pp));
  memset(C, 0, sizeof(C));
  for (uint i = 0; i <= 500; i++)
  {
    for (uint j = 0; j <= i; j++)
    {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] >= mod)
        C[i][j] -= mod;
    }
  }
}
ll f[501][501];
int main()
{
  uint n, x;
  scanf("%u %u", &n, &x);
  init();
  memset(f, 0, sizeof(f));
  for (uint i = 2; i <= n; i++)
  {
    for (uint j = 1; j <= x; j++)
    {
      if (j < i)
      {
        f[i][j] = qPow(j, i);
      }
      else
      {
        f[i][j] = qPow(i - 1, i);
        for (uint k = 2; k <= i; k++)
        {
          f[i][j] = (f[i][j] + C[i][k] * qPow(i - 1, i - k) % mod * f[k][j - i + 1] % mod) % mod;
        }
      }
    }
  }

  printf("%llu", f[n][x]);
  return 0;
}


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

#define and &&

int main()
{
    char a[100],b[100];
    scanf("%s %s",a,b);
    int diff=0;
    for(int i=0;i<strlen(a);i+=2)
       if(a[i]=='[' and b[i]=='(')
           diff++;
       else if(a[i]=='(' and b[i]=='8')
           diff++;
       else if(a[i]=='8' and b[i]=='[')
           diff++;
       else
           diff--;
    if(diff>0)
        printf("TEAM 1 WINS\n");
    else if(diff==0)
        printf("TIE\n");
    else
        printf("TEAM 2 WINS\n");
    return 0;
}


#include<stdio.h>
int main(){
	double a,b;
	sacnf("%f",&a);
	scanf("%f",&b);
	printf(".0%f",a+b);
	return 0;
}


int main(){
	int i;
	int w1 = 0, w2 = 0;
	char buf1[21];
	char buf2[21];
	scanf("%s", buf1);
	scanf("%s", buf2);
	for(i = 0; buf1[i]; i+=2){
		if(buf1[i] == buf2[i])
			continue;
		if(buf1[i] > buf2[i]){
			if(buf1[i] - buf2[i] > 50)
				w1++;
			else
				w2++;
		} else {
			if(buf2[i] - buf1[i] > 50)
				w2++;
			else
				w1++;
		}
}


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

int main() {
    char a[21], b[21];
    scanf("%s%s", a, b);
    int cnt1 = 0, cnt2 = 0;
    int len = strlen(a);
    for (int i = 0; i < len; i+=2) {
        if (a[i] == '8') {
            if (b[i] == '[') {
                cnt1++;
            } else if (b[i] == '(') {
                cnt2++;
            }
        } else if (a[i] == '[') {
            if (b[i] == '(') {
                cnt1++;
            } else if (b[i] == '8') {
                cnt2++;
            }
        } else if (a[i] == '('){
            if (b[i] == '8') {
                cnt1++;
            } else if(b[i] == '[') {
                cnt2++;
            }
        }
    }
    if (cnt1 > cnt2) {
        printf("TEAM 1 WINS\n");
    } else if(cnt1 < cnt2) {
        printf("TEAM 2 WINS\n");
    } else {
        printf("TIE\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>

int main() {
    char a[21], b[21];
    scanf("%s%s", a, b);
    int cnt1 = 0, cnt2 = 0;
    int len = strlen(a);
    for (int i = 0; i < len; i+=2) {
        if (a[i] == '8') {
            if (b[i] == '[') {
                cnt1++;
            } else if (b[i] == '(') {
                cnt2++;
            }
        } else if (a[i] == '[') {
            if (b[i] == '(') {
                cnt1++;
            } else if (b[i] == '8') {
                cnt2++;
            }
        } else if (a[i] == '('){
            if (b[i] == '8') {
                cnt1++;
            } else if(b[i] == '[') {
                cnt2++;
            }
        }
    }
    if (cnt1 > cnt2) {
        printf("TEAM 1 WINS\n");
    } else if(cnt1 < cnt2) {
        printf("TEAM 2 WINS\n");
    } else {
        printf("TIE\n");
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
long long p[9000000];
void main(){
long long n,k,i;
scanf("%lld %lld",&n,&k);

if((n==1&&k==2){
	printf("YES\n");
exit(0);}

if(k>n){
printf("NO\n");
exit(0);}

for(i=1;i<=k;i++){
p[n%i]++;
if(p[n%i]>1){
printf("NO\n");
exit(0);}}

printf("YES\n");
exit(0);
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    long long int n,k;
    int i,c=0,j,a[101];
    scanf("%lld%lld",&n,&k);
    if(k<=100)
    {
        for(i=1;i<=k;i++)
        {
            a[i]=n%i;
            for(j=1;j<i;j++)
            {1
                if(a[i]==a[j])
                {
                    c++;
                }
            }
        }
        if(c!=0) printf("NO");
        else printf("YES");
    }
    else printf("NO");
    return 0;
}


#include<stdio.h>
int main()
{
  long long int n,k,count=0;
  scanf("%lld %lld",&n,&k);
  long long int i,m=-1;
  for(i=1;i<=k;i++)
  {
        if(m<n%i)
            {count++;
            m=n%i;}
        else
          {printf("No");
            return 0:
          }

  }
  if(count==k)
  printf("Yes" );
  else
    printf("No");
}


#include <stdio.h>
#define ll long long
int main()
{
	ll n,k;
	scanf("%lld %lld", &n,&k);
	for(int i=1;i<=k;i++)
		for(int j=i+1;j<=k;j++){
			if(n%i==n%j){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
}


#include <stdio.h>
#define ll long long
int main()
{
	ll n,k;
	scanf("%lld %lld", &n,&k);
	if(n%2==0&&k>=4){
		printf("No");
		return 0;
	}
	for(int i=1;i<=k;i++)
		for(int j=i+1;j<=k;j++){
			if(n%i==n%j){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
}