/*Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.

To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.

For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.

Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.

Input
The first line contains integer n (1?=?n?=?100) � the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains n positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.

The numbers in the lines are separated by a single space.

Output
In a single line print the answer to the problem.

Examples
input
1
1
output
3
input
1
2
output
2
input
2
3 5
output
3
Note
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.

In the second sample Dima can show 2 or 4 fingers.*/
#include<stdio.h>
#include<conio.h>
int main()
{
    int frnd, fing=1, k, i, yes=0, frfing,sum=0,sumfrfing=0;

    scanf("%d", &frnd);
    for(i=0; i<frnd; i++)
    {
         scanf("%d", &frfing);
         sumfrfing+=frfing;
    }
    if(sumfrfing/(frnd+1)!=1)
    {
         k=sumfrfing/(frnd+1)+1;
    }
    else if(sumfrfing%(frnd+1)==0)
    {
         k=sumfrfing/(frnd+1);
    }
    for(fing=1;fing<=5;fing++)
    {
         sum=sumfrfing+ fing;
         if(sum!=((frnd+1)*k+1))
         {
              yes++;
         }
         else
         k++;
    }
    if(yes>0)
    {
         printf("%d", yes);
    }
    getch();
    return 0;
}


#include<stdio.h>
int main(void)
{
    int n,i,a,sum,m=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        sum+=a;
    }
    for(i=1;i<=5;i++){
        if((sum+i)%(n+1)) m++;
    }
    printf("%d",m+1);
    return 0;


#include <stdio.h>

#define MOD     1000003

int main()
{
        int N,Sum=1;
        scanf("%d",&N);
        for(i=1;i<N;++i)
        {
                Sum*=3;
                Sum%=MOD;
        }
        printf("%d\n",Sum);
        return 0;
}


#include<stdio.h>
#define u_int unsigned int

u_int uintpow(u_int a,u_int b);

int main(void){
  u_int n;
  scanf("%u",&n);
  printf("%u\n",uintpow(3,n-1));
  return 0;
}

u_int uintpow(u_int a,u_int b){
    const u_int mod=1000003;
    u_int i;
    u_int prod=1;
    for(i=0;i<b;i++){
      prod*=3;
      if(prod>1000000) prod%=mod;
    }
    return prod;
}


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

#define MD	1000003

int main() {
	int n, p;

	scanf("%d", &n);
	p = 1;
	while (--n)
		p = p * 3 % MD;
	printf("%d\n", p);
	return 0;
}


#include <stdio.h>

int main(int argc, char *argv[])
{
    int n, p = 1;

    scanf("%d", &n);
    while(-- n)
        p = (p * 3) % 1000003;

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

    return 0;
}


#include<stdio.h>
#define u_int unsigned int

u_int uintpow(u_int a,u_int b);
u_int wint(u_int a,u_int b);

int main(void){
  u_int n;
  scanf("%u",&n);
  printf("%u\n",uintpow(3,n-1));
  return 0;
}

u_int uintpow(u_int a,u_int b){
    const u_int mod=1000003;
    u_int i;
    u_int prod=1;
    for(i=0;(b>>i)!=0;i++){
      if((b>>i)&1==1){
	prod*=wint(a,i);
	prod%=mod;
      }
    }
    prod%=mod;
    return prod;
}

u_int wint(u_int a,u_int b){
  const u_int mod=1000003;
  for(;b>0;b--){
    a*=a;
    a%=mod;
  }
  return a;
}


/* https://csacademy.com/contest/archive/task/superstition/ (rainboy) */
#include <stdio.h>
#include <string.h>

#define N	8
#define L	5
#define N_	(1 + N * L)
#define N1	(N_ * 2)
#define A	26
#define MD	998244353

int tt[1 + N_][A]; char word[1 + N_];

void dfs(int coef[][L + 1], int s1, int s2, int l) {
	int a;

	if (s1 == 0 || s2 == 0)
		return;
	if (l > 0) {
		if (word[s1])
			coef[s2 - 1 << 1 | 0][l]++;
		if (word[s2])
			coef[s1 - 1 << 1 | 1][l]++;
		if (word[s1] && word[s2])
			coef[0][l]++;
	}
	for (a = 0; a < A; a++)
		dfs(coef, tt[s1][a], tt[s2][a], l + 1);
}

int coef[N1][N1][L + 1];

void apply(int aa[][N1][L], int n) {
	static int bb[N1][N1];
	int i, j, k, l;

	for (i = 0; i < n; i++)
		memset(bb[i], 0, n * sizeof *bb[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				for (l = 1; l <= L; l++)
					bb[i][k] = (bb[i][k] + (long long) aa[i][j][l - 1] * coef[j][k][l]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (l = L - 1; l >= 0; l--)
				aa[i][j][l] = l == 0 ? bb[i][j] : aa[i][j][l - 1];
}

void mult(int aa[][N1][L], int bb[][N1][L], int cc[][N1][L], int n) {
	static int aa_[N1][N1][L], bb_[N1][N1][L + L];
	int i, j, k, l, l1, l2;

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			memcpy(aa_[i][j], aa[i][j], L * sizeof *aa[i][j]);
	for (l = 0; l < L; l++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (k = 0; k < n; k++)
					for (l1 = 1; l + l1 < L; l1++)
						aa_[i][k][l] = (aa_[i][k][l] - (long long) aa_[i][j][l + l1] * coef[j][k][l1]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++) {
			memset(bb_[i][j], 0, L * sizeof *bb_[i][j]);
			memcpy(bb_[i][j] + L, bb[i][j], L * sizeof *bb[i][j]);
		}
	for (l = L - 1; l >= 0; l--)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (k = 0; k < n; k++)
					for (l1 = 1; l1 <= L; l1++)
						bb_[i][k][l] = (bb_[i][k][l] + (long long) coef[i][j][l1] * bb_[j][k][l + l1]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			memset(cc[i][j], 0, L * sizeof *cc[i][j]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				for (l1 = 0; l1 < L; l1++)
					for (l2 = L - l1; l1 + l2 - L < L; l2++)
						cc[i][k][l1 + l2 - L] = (cc[i][k][l1 + l2 - L] + (long long) aa_[i][j][l1] * bb_[j][k][l2]) % MD;
}

void power(int pp[][N1][L], int tt[][N1][L], int n, int k) {
	int i, j, l;

	if (k == 0) {
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (l = 0; l < L; l++)
					pp[i][j][l] = i == j && l == 0;
		return;
	}
	power(tt, pp, n, k / 2);
	mult(tt, tt, pp, n);
	if (k & 1)
		apply(pp, n);
}

int main() {
	static int pp[N1][N1][L], tt_[N1][N1][L];
	int n, n_, k, i, s;

	scanf("%d%d", &n, &k);
	n_ = 1;
	for (i = 0; i < n; i++) {
		static char cc[L + 1];
		int l, h;

		scanf("%s", cc), l = strlen(cc);
		for (h = 0, s = 1; h < l; h++) {
			int a = cc[h] - 'a';

			if (!tt[s][a])
				tt[s][a] = ++n_;
			s = tt[s][a];
		}
		word[s] = 1;
	}
	for (s = 0; s < n_; s++) {
		dfs(coef[s << 1 | 0], 1, s + 1, 0);
		if (s != 0)
			dfs(coef[s << 1 | 1], s + 1, 1, 0);
	}
	power(pp, tt_, n_ * 2, k);
	if (pp[0][0][0] < 0)
		pp[0][0][0] += MD;
	printf("%d\n", pp[0][0][0]);
	return 0;
}


#include <iostream>

using namespace std;

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

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

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

    long int a, b, c, d;
    short int e, f;
    long long int sum = 0;

    cin >> a >> b >> c >> d >> e >> f;

    if (e > f) {
        long int db = min(a, d);
        sum += db * e;
        db = min(b, c, d - db);
        sum += db * f;
    } else {
        long int db = min(b, c, d);
        sum += db * f;
        db = min(a, d - db);
        sum += db * e;
    }

    cout << sum;

    return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,d,e,f,min2;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);

	if(b <= c && b <= d)
	{
		min2 = b;
	}
	else if(c <= d && c <= b)
	{
		min2 = c;
	}
	else{
		min2 = d;
	}
	d -= min2;
	int min1 = (a < d) ? a : d;
	(min1 < 0) ? min1 *= -1 : min1 *= 1;
	min2 *= f;
	min1 *= e;
	printf("%d",min1+min2);
	return 0;

}


#include<stdio.h>
int mini(int a,int b,int c)
{
if(a<b&&a<c)
return a;
else if(b<a&&b<c)
return b;
else
return c;
}
int main()
{
int a,b,c,d,e,f,min,cost;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
min=mini(b,c,d);
cost=min*f;
d-=min;
if(d>0) {
d=mini(d,a);
cost+=(d*e);}
printf("%d",cost);
return 0;
}


#include<stdio.h>
int main(
    {
	unsigned long int a,b,c,d,e,f,n=0,A=0;
	printf("all\n");
	scanf("%lu %lu %lu %lu %lu %lu",&a,&b,&c,&d,&e,&f);
if((b<=c) && (b<=d))
{
	d=d-b;
	A=b*f;
}
else if((c<=b) && (c<=d))
{
	d=d-c;
	A=c*f;
}
else
{
	A=d*f;
	d=0;
}
if(d!=0)
{
	if(a<=d)
	A=A+(a*e);
	else
	A=A+(d*e);
}
printf("%lu\n",A)
}


/*!
 * @file    problem.344c.c
 * @version 1.0
 * @date    28/09/2013
 * @author  Anton Leontiev <bunder@t-25.ru>
 *
 * @brief   Задача 344С. Рациональное сопротивление
 *
 * @copyright
 *
 * Copyright (c) 2013, Anton Leontiev
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice, this list of
 *     conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice, this list of
 *     conditions and the following disclaimer in the documentation and/or other materials
 *     provided with the distribution.
 *  3. Neither the name of Anton Leontiev nor the names of its contributors may be used
 *     to endorse or promote products derived from this software without specific prior written
 *     permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

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

#define uint64_pri "%" PRIu64
#define uint64_scn "%" SCNu64

static inline void swap(uint64_t *a, uint64_t *b) {
	*a ^= *b;
	*b ^= *a;
	*a ^= *b;
}

int main(int argc, char *argv[]) {
	uint64_t a, b;
	unsigned i = 0;

	scanf(uint64_scn " " uint64_scn, &a, &b);
	while (a != b) {
		if (a > b) swap(&a, &b);
		b -= a;
		i++;
	}
	printf("%u\n", i+1);
	return EXIT_SUCCESS;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#define ABS(x) ((x) < 0 ? -1*(x) : (x))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MOD 1000000007
#define INF 2000000000

inline long long int rec(long long int a, long long int b, long long int csf)
{
    if(!b)
        return csf;

    if(a > b)
        rec(b, a % b, csf+(a/b));
    else
        rec(a, b % a, csf+(b/a));
}

int main()
{
    long long int a,b;
    scanf("%I64d",&a);
    scanf("%I64d",&b);

    printf("%I64d\n", rec(a,b,0));

    return 0;
}


#include<stdio.h>
long long func(long long int a, long long int b)
{
    if(b==0){
        return 0;
    }
    else{
        return (a/b) + func(b,a%b);
    }

}
int main()
{
    long long int  i, j, x;
    scanf("%I64d %I64d", &a, &b);
    x = func(i,j);
    printf("%I64d", x);

    return 0;
}


#include<stdio.h>
using namespace std;
int main(){
    long long a,b,ans=0;
    scanf("%I64d %I64d",&a,&b);
    while (a!=0 || b!=1){
        if (a>=b) {ans+=a/b;a=a%b;}else {ans+=b/a;b=b%a;if (b==0){ans--;b=a;}}
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <stdio.h>
using namespace std;
int main()
{
    long long a,b,i,k=0;
    scanf("%I64d %I64d",&a,&b);
    if (a%b==0)
        k=1;
    else
        if (a==1)
        k=b;
    else
        {
            while (a!=1)
            {
                if (a>b)
                {
                    a=a%b;
                    k+=a;
                }
                else
                {
                    i=a;
                    a=b;
                    b=i;
                }
            }
            k+=b;
        }
    printf("%I64d",k);
    return 0;
}


#include <stdio.h>

int main() {
	int x, y, r, a;
	scanf_s("%d",&r);
	r = r - 1;
	y = (r - 2) / 2;
	x = 0;
	while (++x) {
		if (x * (x + (2 * y) + 1) == r) {
			printf("%d %d", x, y);
			break;
		}
		else if (x * (x + (2 * y) + 1) > r) {
			puts("NO");
			break;
		}
	}
	getch();
	return 0;
}


#include<stdio.h>
int main()
{
    long long r;
    scanf("%lld",&r);
    if(r<5 or r%2==0) printf("NO");
    else
    {
        printf("%I64d %I64d",1LL,(r-3)/2);
    }
}


#include<Stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdint.h>

int main(){
    int64_t r,y,x,hash,min_x=10000000000,corresponding_y;
    int flag_no=1;
    scanf("%I64d",&r);
    for(y=((r/2)-1);y>;y--){
        for(x=1;x<=r;x++){
          hash = pow(x,2)+(2*x*y)+x+1 ;
          if(hash>r){
              break;
          }
          if(hash==r){
              flag_no=0;
             if(x<=min_x){
                 min_x =x;
                 corresponding_y =y;
                 break;
             }
          }
        }
    }
    if(flag_no == 1){
        printf("NO");
    }
    else{
        printf("%I64d %I64d",min_x,corresponding_y);
    }

return 0;
}


#include<stdio.h>
#include<algorithm>
#define MAXN 1000000000001
using namespace std;
int main()
{
	long long f=0,r,y;
	scanf("%lld",&r);
	for(long long i=1;i<r;i++)
	{
		if(i*i>=r)	break;
		if((r-i*i-i-1)%(2*i)==0)
		{
			y=(r-i*i-i-1)/(2*i),f=1;
			printf("%lld %lld",i,y);
		}
		if(f)	break;
	}
	if(!f)	printf("NO\n");

 }


#include<stdio.h>
int main()
{
    long long r;
    scanf("%lld",&r);
    if(r<5 or r%2==0) printf("NO");
    else
    {
        printf("%lld %lld",a1LL,(r-3)/2);
    }
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    long x,y,x1,y1,x2,y2;
    scanf("%ld%ld",&x,&y);
    if(x>0 && y>0)
    {
        printf("0 %ld %ld 0",x+y,x+y);
    }
    else if(x<0 && y>0)
    {
        printf("%ld 0 0 %ld",-(labs(x)+y),(labs(x)+y));
    }
    else if(x<0 && y<0)
    {
        printf("%ld 0 0 %ld"-(labs(x)+labs(y)),-(labs(x)+labs(y)));

    }
    else
        printf("0 %ld %ld 0",-(x+labs(y)),(x+labs(y)));
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    int i,x,y,A,t1,t2;
	while(scanf("%d%d",&x,&y)!=EOF)
	{
        t1=abs(x);t2=abs(y);
        for(A=t1+1; ;A++)
		{
			if(t1*t2==(A-t1)*(A-t2))
				break;
		}
		if(x>=0&&y>=0)
			printf("%d %d %d %d\n",0,A,A,0);
		else if(x>=0&&y<=0)
			printf("%d %d %d %d\n",0,-A,A,0);
		else if(x<=0&&y>=0)
			printf("%d %d %d %d\n",-A,0,0,A);
		else
			printf("%d %d %d %d\n",-A,0,0,-A);
	}
	return 0;
}


#include<stdio.h>
int main()
{
    long long int x,y,p1,p2,a;
    scanf("%lld%lld",&x,&y);
    for(a=1;a*a<y*y;a++);
    if(x>0)
        p1=x+a;
    else
        p1=x-a;

    p2=(p1>0)?p1:-p1;
    if(y<0)
        p2=-p2;
    if(p1>0)
        printf("0 %lld %lld 0\n",p2,p1);
    else
        printf("%lld 0 0 %lld\n",p1,p2);
    return 0;
}


#include<iostream.h>

int main(){
int i,j,k,n,ans=0,z;

scanf("%d",&n);
for(i=1;i<=n;i++){
    for(j=i;j<=n;j++){
        for(z=j;z<=n;z++)
                {

                  if(!(i^j^z))
                    ans+= i+j>z ;

               }

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


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

using namespace std;

typedef long long ll;

int n,ans;

int main()
{
    scanf("%d",&n);
    for (int i = 1;  i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            int temp = i ^ j;
            if (temp > j || temp > i)
                continue;
            if (temp + j <= i)
                continue;
            ans++;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
int main()
{
  int n,a,b,c,i,count=0,j,k;
  scanf("%d",&n);
  for (int i = 1; i < n; ++i)
  {
    for (int j = i+1; i < n; ++j)
    {
      /* code */
      for (int k = i+2; i < i+j; ++k)
      {
        /* code */
        if((i^j)==k)
          count++;
      }
    }


#include<stdio.h>
#define pi 3.14

int main()
{
    int a , b , r ,ans ;

    while(scanf("%d%d%d",&a,&b,&r)!=EOF)
    {
        d = 2* r ;
        ans = (a/d)*(b/d);
        if(ans%2==0)
            printf("Second\n");
        else
            printf("First\n");

    }

    return 0 ;
}


#include <stdio.h>

int main()
{
    int a, b, r, t, f=0, s=0;
    scanf(" %d %d %d", &a, &b, &r);

    if(a>b)
    {
        t = a;
        a = b;
        b = t;
    }

    while(b != 0)
    {
        if(b > (2*r))
        {
            b -= (2*r);
            f++;
        }

        if(b > (2*r))
        {
            b -= (2*r);
            s++;
        }

        if(b < (2*r))
            break;
    }

    if(f > s)
        printf("First\n");
    else
        printf("Second\n");

    return 0;
}


#include<stdio.h>
int main()
{
    int a,b,r;
    while(scanf("%d%d%d",&a,&b,&r))
        if(a>=2*r&&b>=2*r)
            printf("First\n");
        else printf("Second\n");
        return 0;
}


#include<stdio.h>
int main()
{
int a,b,r;
while(scanf("%d%d%d",&a,&b,&r))
{
if(2*r>=a&&2*r>=b)printf("First\n");
else printf("Second\n");
}
return 0;
}


#include <stdio.h>

char Win[2][10] = {"Second","First"};

int main()
{
    __int64 a,b,r;
    scanf("%I64d %I64d %I64d",&a,&b,&r);
    if(a < 2 * r && b < 2 * r) puts(Win[0]);
    else puts(Win[1]);
    return 0;
}


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

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

int main(void)
{
	int n, k;
	scanf("%d %d", &n, &k);
	int a[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	qsort(a, n, sizeof(int), comp);
	int count = 0;
	for (int i = 0; i < n; ++i) {
		k = k - a[i];
		if (k < 0) {
			break;
		}
		count++;
	}
	printf("%d\n", count);
	for (int i = 0; i < count; ++i) {
		printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}


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

int main()
{

    int x , y;
    int arr [200];
    scanf("%d%d", &x , &y);

    scanf("%d", &arr[0]);
    int maxi = arr[0] , max_index = 0;
    int sum = maxi;
    int n;
    int length = 0;

    for(i = 0 ;i < x; i++){

        scanf("%d", n);
        if(n + sum  <= y){ sum += n;

            arr[i + 1] = i + 1;
            length++;

        } else if (sum - maxi + n <= y){

            sum -= maxi + n;
            arr[max_index] = i + 1;
            max = n;
            max_index = i;
            length++;
        }

        break;
    }

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

    for(i = 0 ; i < length; i++){

        printf("%d ", arr[i]);

    }

    return 0;
}


#define MAXINS 101
#define MAXDAY 10001
#include <stdio.h>

int rec(int i,int day){
    int max;
    if(i==0){
        return 0;
    }
    if(day<=0){
        return 0;
    }
    if(dp[i][day]!=-1){
        return dp[i][day];
    }
    int ret1=0;
    int ret2=0;
    if((day-ins[i])>=0){
        ret1=1+rec(i-1,day-ins[i]);
    }
    ret2=rec(i-1,day);

    if(ret1>ret2){
        max=ret1;
        learn[i]=1;
    }
    else{
        max=ret2;
        learn[i]=0;
    }
    dp[i][day]=max;
    return max;
}
int main(){
int n;
int available;
int ins[101];
int dp[105][10005];
int learn[101];
    int i,j;
    int learnt;
    for(i=0;i<=MAXINS;++i){
        for(j=0;j<=MAXDAY;++j){
            dp[i][j]=-1;
        }
    }
    scanf("%d %d",&n,&available);
    i=1;
    while(i<=n){
        scanf("%d",&ins[i]);
        learn[i]=0;
        i++;
    }

    learnt=rec(n,available);
    i=1;
    printf("%d\n",learnt);
    while(i<=n){
        if(learn[i]==1){
            printf("%d ",i);
        }
        i++;
    }
    if(learnt!=0){
    printf("\n");
    }

}


#include<stdio.h>
void pivot(int array[],int index[],int start,int end)
{
    int i,j=start,x=array[end],t;
    for(i=start;i<end;i++)
        if(array[i]<=x)
        {
            t=array[i];
            array[i]=array[j];
            array[j]=t;
            t=index[i];
            index[i]=index[j];
            index[j]=t;
            j++;
        }
    t=array[end];
    array[end]=array[j];
    array[j]=t;
    t=index[end];
    index[end]=index[j];
    index[j]=t;
    return j;
}
void quicksort(int array[],int start,int end)
{
    if(start>=end)
        return;
    int j=pivot(array,start,end);
    quicksort(array,start,j-1);
    quicksort(array,j+1,end);
}
int main()
{
    int n,k,i,count=0,num=0;
    scanf("%d %d",&n,&k);
    int array[n+1],index[n+1];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&array[i]);
        index[i]=i;
    }
    quicksort(array,index,1,n);
    for(i=1;count<=k&&i<=n;i++)
    {
        if(count+array[i]>k)
            break;
        count=count+array[i];
        num++;
    }
    printf("%d\n",num);
    for(i=1;i<=num;i++)
        printf("%d ",index[i]);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int cmpfunc (const void * a, const void * b)
{
	return ( *(int*)b - *(int*)a );
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int arr[n];
	int out[m];
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=0;i<m;i++)
		scanf("%d",&out[i]);
	qsort(out,m,sizeof(int),cmpfunc);
	j=0;
	for(i=0;i<n;i++)
		if(arr[i]==0)
		{
			arr[i]=out[j];
			j++;
		}
	for(i=0;i<n;i++)
	{
		if(arr[i]>=arr[i+1])
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int judge(inta[],intb[],intn,intm)
{
	int i;
	int t=0,x=0;
	for(i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			a[i]=b[x];x++;
		}
	}
	for(i=0;i<n-1;i++)
	{
		if(a[i]>a[i+1])return1;
	}
	return 0;
}

int comp(const void *a,const void *b)
{
	return*(int*)b-*(int*)a;
}
int main()
{
	int a[500];
	int b[500];
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
	 	int i;
		 int c[500];
		 for(i=0;i<n;i++)
	 	 {
		 	scanf("%d",&a[i]);
			 c[i]=a[i];
		 }
		 for(i=0;i<m;i++)
		 scanf("%d",&b[i]);
		 qsort(b,m,sizeof(b[0]),comp);
		 int t=judge(a,b,n,m);
		 if(t)printf("Yes\n");
		 else
		 printf("No\n");
	}
}


#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
int n,k;
int a[1000],b[1000];
int main()
{
    while(scanf("%d%d",&n,&k)!=-1)
    {
        a[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=k;i++)
        {
            scanf("%d",&b[i]);
        }
        if(k==1)
        {
            int flag=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==0)
                {
                    a[i]=b[1];
                }
                if(a[i]-a[i-1]<0)
                {
                    flag=1;
                }

            }
            if(flag==1)printf("Yes\n");
            else printf("No\n");

        }
        else
        {
            printf("Yes\n");
        }

    }
    return 0;

}


#include <stdio.h>
int main()
{
	int n,m;
	int i,j;
	scanf("%d %d",&n,&m);
	int a[n],b[m],count=0,flag=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]!=0&&i!=0)
		{
			if(a[i]<prev)
				flag=1;
			prev=a[i];
		}
		if(a[i]==0)
			count++;
	}
	for(i=0;i<m;i++)
		scanf("%d",&b[i]);
	if(count==1&&flag==1)
		printf("Yes\n");
	else
		printf("No\n");
}


#include <stdio.h>
#include <string>
#include <string.h>
int n,k;
int a[1000],b[1000];
int main()
{
    while(scanf("%d%d",&n,&k)!=-1)
    {
        a[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=k;i++)
        {
            scanf("%d",&b[i]);
        }
        if(k==1)
        {
            int flag=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==0)
                {
                    a[i]=b[1];
                }
                if(a[i]-a[i-1]<0)
                {
                    flag=1;
                }

            }
            if(flag==1)printf("Yes\n");
            else printf("No\n");

        }
        else
        {
            printf("Yes\n");
        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
int n,x,j;
scanf("%d",&n);
for(y=0,j<n,j++)
{
scanf("%d",&x);
printf("%d\n",x/2);
}
return 0;
}


#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
for(i=0;i<a;i++){
	int x;
	scanf("%d",&x);
	printf("%d",x/2)
}
}


#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
for(i=0;i<a;i++){
	int x;
	scanf("%d",&x);
	printf("%d",x/2)
}
return 0;
}


#include<stdio.h>
int main(){
    int test;
    scanf("%d",&test);
    int bal,cal;
    while(test){
        scanf("%d",&bal);
        if(bal%7==0) printf("%d\n"bal/7);
        else printf("%d\n",bal/7+1);
        test--;
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int in=0;
    while(EOF!=scanf("%d",&in))
    {
        if(in==1) printf("Washington\n");
        else if(in==2) printf("Adams\n");
        else if(in==3) printf("Jefferson\n");
        else if(in==4) printf("Madison\n");
        else if(in==5) printf("Monroe\n");
        else if(in==6) printf("Adams\n");
        else if(in==7) printf("Jackson\n");
        else if(in==8) printf("Van Buren\n");
        else if(in==9) printf("Harrison\n");
        else if(in==10) printf("Tyler\n");
        else if(in==11) printf("Polk\n");
        else if(in==12) printf("Taylor\n");
        else if(in==13) printf("Fillmore\n");
        else if(in==14) printf("Pierce\n");
        else if(in==15) printf("Buchanan\n");
        else if(in==16) printf("Lincoln\n");
        else if(in==17) printf("Johnson\n");
        else if(in==18) printf("Grant\n");
        else if(in==19) printf("Hayes\n");
        else if(in==20) printf("Garfield\n");
        else if(in==21) printf("Arthur\n");
        else if(in==22) printf("Cleveland\n");
        else if(in==23) printf("Harrison\n");
        else if(in==24) printf("Cleveland\n");
        else if(in==25) printf("McKinley\n");
        else if(in==26) printf("Roosevelt\n");
        else if(in==27) printf("Taft\n");
        else if(in==28) printf("Wilson\n");
        else if(in==29) printf("Harding\n");
        else if(in==30) printf("Coolidge\n");
        else if(in==31) printf("Hoover\n");
        else if(in==32) printf("Roosevelt\n");
        else if(in==33) printf("Truman\n");
        else if(in==34) printf("Eisenhower\n");
        else if(in==35) printf("Kennedy\n");
        else if(in==36) printf("Johnson\n");
        else if(in==37) printf("Nixon\n");
        else if(in==38) printf("Ford\n");
        else if(in==39) printf("Carter\n");
        else if(in==40) printf("Reagan\n");
        /*else if(in==41) printf("H.W. Bush\n");
        else if(in==42) printf("J. Clinton\n");*/

    }
    return 0;
}


#include <stdio.h>

char Str[40][]={"Washington","Adams","Jefferson","Madison","Monroe","Adams","Jackson","Van Buren","Harrison","Tyler",
"Polk","Taylor","Fillmore","Pierce","Buchanan","Lincoln","Johnson","Grant","Hayes","Garfield","Arthur",
"Cleveland","Harrison","Cleveland","McKinley","Roosevelt","Taft","Wilson","Harding","Coolidge","Hoover","Roosevelt",
"Truman","Eisenhower","Kennedy","Johnson","Nixon","Ford","Carter","Reagan","Bush","Clinton","Bush","Obama"};

int main()
{
        int a;
        scanf("%d",&a);
        puts("%s",Str[a-1]);
        return 0;
}


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

int main()
{
   int n;

   char ch[][]={"Washington","Adams","Jefferson","Madison","Monroe","Q. Adams","Jackson","Van Buren","H. Harrison","Tyler","K. Polk","Taylor","Fillmore","Pierce","Buchanan","Lincoln","Johnson","S. Grant","B. Hayes","A. Garfield","A. Arthur","Cleveland","Harrison","Cleveland","McKinley","Roosevelt","H. Taft","Wilson","G. Harding","Coolidge","C. Hoover","D. Roosevelt","S. Truman","D. Eisenhower","F. Kennedy","B. Johnson","M. Nixon","R. Ford","Carter","W. Reagan"};

    scanf("%d",n);

    printf("%s\n",ch[n-1]);

    return 0;
}


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

#define MAX_NAME_LENGTH 50

int main() {
    static char pres[44][MAX_NAME_LENGTH] = {"Washington", "Adams", "Jefferson", "Madison", "Monroe",
        "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce",
        "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison",
        "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt",
        "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan", "Bush", "Clinton",
        "Bush", "Obama"}
    int in;
    scanf("%d", &in);
    printf("%s\n", pres[in-1]);
    return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,d,e,f,i,j,k,l;
	cin>>a;
	if(a==1)
		printf("egbvx\n");
	else if(a==2)
		printf("Adams\n");
	else if(a==3)
		printf("ghh\n");
	else if(a==4)
		printf("ggcxv\n");
	else if(a==5)
		printf("xcvx\n");
	else if(a==6)
		printf("hhrt\n");
	else if(a==7)
		printf("erter\n");
	else if(a==8)
		printf("Van Buren\n");
	else if(a==9)
		printf("yuyu\n");
	else if(a==10)
		printf("oho\n");
	else if(a==11)
		printf("ttytr\n");
	else if(a==12)
		printf("utrty\n");
	else if(a==13)
		printf("qew\n");
	else if(a==14)
		printf("ggtyu\n");
	else if(a==15)
		printf("Bzcx\n");
	else if(a==16)
		printf("qew\n");
	else if(a==17)
		printf("ygy\n");
	else if(a==18)
		printf("gxg\n");
	else if(a==19)
		printf("rtr\n");
	else if(a==20)
		printf("Gggh\n");
	else if(a==21)
		printf("Azxcz\n");
	else if(a==22)
		printf("ghh\n");
	else if(a==23)
		printf("gcxb\n");
	else if(a==24)
		printf("ugh\n");
	else if(a==25)
		printf("ret\n");
	else if(a==26)
		printf("yt\n");
	else if(a==27)
		printf("Ta\n");
	else if(a==28)
		printf("Wi\n");
	else if(a==29)
		printf("Harding\n");
	else if(a==30)
		printf("Coolidge\n");
	else if(a==31)
		printf("over\n");
	else if(a==32)
		printf("osvelt\n");
	else if(a==33)
		printf("Tuman\n");
	else if(a==34)
		printf("Esenhower\n");
	else if(a==35)
		printf("nedy\n");
	else if(a==36)
		printf("Jnson\n");
	else if(a==37)
		printf("xon\n");
	else if(a==38)
		printf("Fd\n");
	else if(a==39)
		printf("Carter\n");
	else if(a==40)
		printf("Rean\n");
	return 0;
}


    #include<stdio.h>
    int main(){
        long long n,k;
        scanf("%lld %lld",&n,&k);
        if((n / k) & 1) == 0)
            printf("NO");
        else
            printf("YES");
        return 0;
    }


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

typedef long long ll;

int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    if(k>=n)
        printf("YES");
    else
    {
        if((n/k)%2==0)
            printf("NO");
        else printf("YES");
    }

   return 0;
}

");
   }*/


#include<stdio.h>
int main()
{
    double n,k,d;
    while(scanf("%lf%lf",&n,&k)!=EOF)
    {
    d=n/k;
    if(d%2==0)
    printf("NO\n");
    else
    printf("YES\n");
    }
    return 0;

}


#include <stdio.h>
int main() {
long long n, k;
scanf("%lld %lld", &n, &k);
printf(((n / k) & 1 ? "YES" : "NO");
return 0;

}


#include<stdio.h>

int main(){

long long int n, k;

scanf("%I64d %I64d", &n , &k);

if(n!= 1)
printf("%I64d %I64d\n" , n ,k);

long long int odd_even = n/k;

if(n!=1)
prinf("%I64d\n" , odd_even );

if(odd_even%2 == 0)
    printf("NO");
else
    printf("YES");

}


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

typedef struct
{
    int a;
    int b;
    int c;
}EleType;

int transfer(EleType , EleType );
int OddEven(int );

int main(void)
{
    int get;
    get = 0;
    EleType start, end;
    scanf("%d%d%d", &start.a, &start.b, &start.c);
    scanf("%d%d%d", &end.a, &end.b, &end.c);

    get = transfer(start, end);
    if (get == 1)
        printf("Yes");
    else
        printf("No");
    return 0;
}

int OddEven(int number)
{
    if (abs(number) % 0.5 == 0)
        return 1;
    else return 0;
}

int transfer(EleType in, EleType out)
{
    int i, j, k;
    int o, p ,q;
    o = 0;
    p = 0;
    k = 0;

    i = (in.a - out.a);
    j = (in.b - out.b);
    k = (in.c - out.c);

    if (i > 0)
    {
        if (OddEven(i))
        {
            p = i;
            i = 0;
        }
        else
        {
            p  = i - 1;
            i = 1;
        }
    }
    if (j > 0)
    {
        if (OddEven(j))
        {
            o = j;
            j = 0;
        }
        else
        {
            o  = j - 1;
            j = 1;
        }
    }
    if (k > 0)
    {
        if (OddEven(k))
        {
            q = k;
            k = 0;
        }
        else
        {
            q  = k - 1;
            k = 1;
        }
    }
        if (!(o + p + q - i - j - k))
            return 1;
        else
            return -1;
    }
}


#include <iostream>
using namespace std;

int main()
{
    int a,b,c,x,y,z;
    cin >> a >> b >> c >> x >> y >> z;
    int n=0,k=0;
    ( a > x ) ? k += ( a - x ) / 2 : n += x - a;
     ( b > y ) ? k += ( b - y ) / 2 : n += y - b;
     ( c > z ) ? k += ( c - z ) / 2 : n += z - c;
     ( k >= n ) ? cout << "Yes" : cout << "No";
    // your code goes here
    return 0;
}


#include<stdio.h>
int main()
{
int sum1=0,sum2=0;
int a,b,c;
int x,y,z;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);

if(a>x && b>y && c<z)
{
sum1=(a-x+b-y)/2;
sum2=y-c;
}
else if(a<x && b>y && c>z)
{
sum1=(c-z+b-y)/2;
sum2=x-a;
}
else if(a>x && b<y && c>z)
{
sum1=(a-x+c-z)/2;
sum2=y-b;
}

else if(a>x && b<y && c<z)
{
sum1=(y-b+z-c);
sum2=(a-x)/2;
}

else if(a<x && b>y && c<z)
{
sum1=(x-a+z-c);
sum2=(b-y)/2;
}

else if(a<x && b<y && c>z)
{
sum1=(x-a+z-c);
sum2=(y-b)/2;
}

if(sum1==sum2)
printf("Yes\n");
else
printf("No");

return 0;
}


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

int main()
{
	int a,b,c,y,x,z,certo=0;

	scanf("%d %d %d", &a, &b, &c);
	scanf("%d %d %d", &x, &y, &z);

	if(a==b)
	{
		certo =1;
	}
	if(a==c)
	{
		certo=1;
	}
	if(c==b)
	{
		certo=1;
	}
	if(certo==1)
	{
		if(x==y)
		{
			printf("Yes");
		}
		if(x==z)
		{
			printf("Yes");
		}
		if(y==z)
		{
			printf("Yes");
		}
	printf("No");
	else
	{
		printf("No");
	}
return 0;
}

/* 1521310650391 */


#include<cstdio>

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

main(){
    int a,b,c,x,y,z,temp=0;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&x,&y,&z);
    if(a-x<0)
        temp+=x-a;
    if(b-y<0)
        temp+=y-b;
    if(c-z<0)
        temp+=z-c;
    if(min(a-x,0)/2+min(b-y,0)/2+min(c-z,0)/2<temp)
        printf("No");
    else
        printf("Yes");
}


#include<thuvienchuan.h>
int main(){
	int n,p,k;
	do{
    printf("nhap vao so trang n= "); scanf("%d",&n);} while(n<3 || n>100);
    do{
    printf("nhap vao so trang hien tai p= "); scanf("%d",&p);} while(p<1 || p>n);
    do{
    printf("nhap vao so trang k= "); scanf("%d",&k);} while(k<1 || k>n);
	if(p==1){
		printf("(1) ");
		if(n<= p+k)
			for(int i=2; i<=n; i++)
			printf("%d ",i);
		else {
			for(int i=2; i<= p+k; i++)
			printf("%d ",i);
			printf(">>");
		}}
	else if(p==n){
		if(p-k<=1){
		for(int i=1; i<n; i++)
		   printf("%d ",i);
		printf("(%d)",n);
	}
	    else{ printf("<< ");
	      for(int i=p-k; i<n;i++) printf("%d ",i); printf("(%d)",n);
	     }}
	else  {
		if(p-k<=1){
		for(int i=1; i<p; i++) printf("%d ",i);
		printf("(%d) ",p);}
		else{
			printf("<< ");
			for(int i=p-k; i<p; i++) printf("%d ",i); printf("(%d) ",p);
		}
		if(p+k<n){
		for(int i=p+1; i<=p+k; i++) printf("%d ",i); printf(">>");}
		else for(int i=p+1; i<=n; i++) printf("%d ",i); }
	return 0;
}


#include <stdio.h>
int main ()
{
    int n,p,k;

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

    if (p+k>1)
    {
        printf ("<<");
    }

    for (i=p-k; i<=p=k;i++ )
    {
        if (1<=i && i<=n)
        {
            if(i==p)

            printf("(%d)", i);
        }
        else printf ("%d",i);
    }

    if (p+k<n)
    {
        printf(">>");
    }
    Return 0;
}


#include<stdio.h>
int main()
{
	int n,p,k,t,z;
	scanf("%d%d%d",&n,&p,&k);
	if(p-k>1)
	printf("<< ");
	t=n<=p+k?n:p+k;
	if(p-k<1)
	z=1;
	else
	z=p-k;
	for(int i=z;i<=t;i++)
	if(i==p)
	printf("(%d) ",i);
	else
	printf("%d ",i);
	if(t<n)
	printf(">>");

	return 0;


#include <stdio.h>
int main()
{
 int n,p,k;
 int f=0;

 scanf("%d %d %d",&n,&p,&k);
 int f=p-k;
 if(p-k > 1)
 printf("<< ");
 for(int i = p-k; i < p+k; i++)
 {
     if (f == p)
    {
     printf(" (%d) ",f);
     f++;
    }
     else
     {
      printf(" %d ",f);
      f++;
      }
 }
 if(p+k < n)
 printf(" >>");
 return 0;
}


#include<stdio.h>
int main()
{
    int n,p,k;
    scanf("%d%d%d",&n,&p,&k);
    if(p-k>1)
        printf("<< ");
    for(int i=p-k; i<p; i++)
    {
        if(i>0)
            printf("%d ",i);
    }
    printf("(%d) ",p);
    int j;
    for(j=p+1;j<=p+k ; j++)
    {
        if(j>n)
            break;
        printf("%d ",j);

    }

    if(n>=10j)
    {
        printf(">>");
    }
    return 0;
}


#include<stdio.h>
int main()
{
int n,p=0,q=0,x,y;
scanf("%d%d%d",&n,&x,&y);
if(n%2!=0)
{if(y==n/2 || y==n/2-1|| y==n/2-1)
{
printf("NO");
}
else
{
printf("YES");
}
}
else
{
if(y==n/2 || y==n/2+1)
{
    printf("NO");
}
else
printf("YES
       ");
}
return(0);
}


#include<stdio.h>

int main()
{

int n,x,y;

scanf("%d%d%d",&num,&x,&y);
n=n/2;

if((x==n||x==n+1) && (y==n||y==n+1))
{
printf("NO");
}

else
{
printf("YES");
}
return(0);
}


#include<stdio.h>

int main()
{

int num,x,y,n;

scanf("%d%d%d",&num,&x,&y);
n=num/2;

if((x==n&&x=n+1) && (y==n&&y==n+1))
{
printf("NO");
}

else
{
printf("YES");
}
return(0);
}


#include<stdio.h>int dp[105], a[105];int max(int a, int b){	return a > b ? a : b;}int main(){	int n, i, j, m, ans, pre;    scanf("%d",&n);	pre = 0;	for (i = 1; i <= n; i++)	{		scanf("%d",&a[i]);		if (a[i] == 1)pre++;	}	if (a[1] == 0)dp[1] = 1;	else dp[1] = 0;	for (i = 2; i <= n; i++)	{		if (a[i] == 1)			dp[i] = max(dp[i - 1] - 1, 0);		else if (a[i] == 0)			dp[i] = max(0, dp[i - 1] + 1);	}	ans = dp[1];	for (i = 2; i <= n; i++)		ans = max(ans, dp[i]);	if (ans == 0)		printf("%d",pre-1);	else printf("%d",pre+ans);  	return 0;}


#include <stdio.h>
#include <algorithm>
using namespace std;
int a[101];
int main(){
	int n,i=1,j=1,k,temp=0;
	int ans=0;
	scanf("%d",&n);
	for(k=1;k<=n;k++){
		scanf("%d",&a[k]);
	}

	for(i=1;i<=n;i++){

		for(j=1;j<=n;j++){
			ans=0;
			for(k=i;k<=j;k++){
				if(a[k]==1) a[k]=0;
				else a[k]=1;
			}
			for(k=1;k<=n;k++){
				if(a[k]==1)
					temp++;
			}
			if(temp>ans)
				ans=temp;
		}

	}

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


#include<stdio.h>
#include<stdlib.h>
int compare(const void * a, const void * b){return *(int *)a-*(int *)b;}
int main()
{
	int n,j,i,a[1000],one[1000]={0};//a,b;
	scanf("%d",&n);
	if(n==1)
	{	scanf("%d",&i)
		printf("%d",1-i);
		return 0;
	}
	for(i=0;i<n;i++)
	{	scanf("%d",&a[i]);
		if(a[i]==1)
			one[i+1]=one[i]+1;
		else
			one[i+1]=one[i];
	}
	int max=0,max1=0;
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			int r=one[n]-one[j]+one[i-1];
		//	printf("%d %d %d ",one[n],one[j],one[i-1]);
			int aa=(one[j]-one[i-1]);
			int bb=(j-i+1-one[j]+one[i-1]);
//			printf("i=%d j=%d %d %d %d\n",i,j,r,aa,bb);
			if(aa>bb)
				max1=aa+r;
			else
				max1=bb+r;
			if(max1>max)
				max=max1;
		}
	}
	printf("%d\n",max);
	return 0;
}


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

int main()
{
    int a[50],A,B,i,diff=1001;
    cin >> A >> B;
    for(i=0;i<B;i++)
        cin >> a[i];

    sort(a, a+B);
    for(i=0;i+A-1<=B;i++)
    {
        if(a[i+A-1]-a[i]<diff)
            diff=a[i+A-1]-a[i];
    }
    cout << diff;

    return 0;
}


#include <stdio.h>
int main()
{
     int n,m;
     scanf("%d %d",&n,&m);
     int a[m];
     for(int i=0;i<m;i++)
     {
          scanf("%d",&a[i]);
     }
     int j,k,l;
     for(j=0;j<m;j++)
     {
          for(k=j+1;k<m; )
          {
               if(a[j]<a[k])
               k++;
               else
               {
                    l=a[k];
                    a[k]=a[j];
                    a[j]=l;
                    k++;
               }
          }
     }
     int o,p,min[m],t=0,u;
     for(o=0;o<m;o++)
     {
       min[t]=a[o+n]-a[o];
       t++;
     }
     int u=min[0];
     for(int y=0;y<o;y++)
     {
          if(min[y]<u)
          u=min[y];
     }
     printf("%d",u);
}


#include<stdio.h>

int main()
{

    int x[50];
          int n,p,i,j=0,temp;
    scanf("%d %d",&n,&p);

    for(i=0;i<p;++i)
        scanf("%d",&x[i]);
    for(int i =0 ; i<p ; ++i){
        for(j=i; j<p; ++j){
            if(x[j]<x[i])
            {  temp=x[i];
               x[i]=x[j];
              x[j]=temp;
            }
        }
    }

    int diff1=x[p-1]- x[p-1-n];
    int diff2=x[n-1]-x[0];

if(diff2<diff1)
    printf("%d", diff2);
    else printf("%d 1",diff1);

    return 0 ; }


#include <stdio.h>
#include <math.h>
 int main(){

int n,m,k,i,min;
scanf ("%d%d%d",&n,&m,&k);
  min=n-1;
int *t=malloc (sizeof(int)*n);
for (i=0; i<n;i++){
    scanf ("%d",t+i);

    if (t[i]!=0 &&t[i]=<k && abs (m-i-1) < min ){
            min =abs(m-i-1);

    }
}
  printf ("%d",min*10);

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define MAX 1000000009;
int main() {
    int i,n,m,k,min=MAX,t,temp;
    scanf("%d %d %d",&n,&m,&k);
    for(i=1;i<=n;i++) {
        scanf("%d",&t);
        if(t>0 && t<=k) {
            temp = abs(m-i);
            if(temp<min) {
                min = temp;
            }
        }
    }
    printf("%d\n",(min*10));
    return 0;
}


#include<stdio.h>
#include<math.h>
int main () {
	int a[100],i,j,n,m,k;
	do {
		printf("n=");
		scanf("%d",&n);
		printf("m=");
		scanf("%d",&m);
		printf("k=");
		scanf("%d",&k);
	} while (n<1||m>n||m<1||k<1);
	for (i=0;i<n;i++) {
		//printf("nhap tien phong so %d =\n",i+1);
		scanf("%d",&a[i]);
	}
	int dem=0;
	int d[100];
	for (i=0;i<n;i++) d[i]=0;
	for(i=0;i<n;i++) {
		if (a[i]<=k&&a[i]!=0) {
			dem++;
			d[i]=abs(i+1-m);
		}
	}
	if (dem ==0) printf("ko co phong phu hop");
	else {
		int min=n-1,j;
		for(i=0;i<n;i++) {
			if (d[i]!=0&&d[i]<=min) {
				min=d[i];
				j=i;
			}
		}
	//printf("phong phu hop: %d\n khoang cach den crush : %d",j+1,min);
	printf("%d",min)

	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long y,sum=0,sum1=0,dis[10001],n,m,k,vill[10001],vs[10001],v[10001],s=0;
    cin>>n;
    cin>>m;
    cin>>k;
    for(int i=0;i<n;i++)
    {
        cin>>vill[i];
    }
    sum1=(m-1)*10;

    for(int j=0;j<n;j++)
    {
        if(vill[j]<k&&vill[j]>0)
        {
            v[s]=vill[j];
            vs[s]=j;
            dis[s]=sum;
            s++;
        }
        sum=sum+10;
    }
    for(int z=0;z<s;z++)
    {
        dis[z]=abs(dis[z]-sum1);
    }
    sort(dis,dis+s);
    cout<<dis[0];
    return 0;
}


#include <iostream>
using namespace std;
int a,b,c;
int main(){
	cin >> a >> b >> c;
	if((a+b+c)%2==0 && a+b>=c && a+c>=b && b+c>=a){
		cout << (a+b-c)/2 <<" " << (b+c-a)/2 << " " << (a+c-b)/2;
	}
	else cout << "Impossible\n";
	return 0;
}


#include <stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d",a,b,c);
	for(i=0;i<=a;++i)
	{
		if(b-i==c-a+i)
		{
			printf("%d %d %d\n",i,b-i,a-i);
			return 0;
		}
	}
	printf("Impossible\n");
	return 0;
}


#include <cstdio>
int a,b,c;
int main(){
	scanf("%d %d %d",&a,&b,&c);
	if((a+b+c)%2==0 && a+b>=c && a+c>=b && b+c>=a){
		printf("%d %d %d\n",(a+b-c)/2,(b+c-a)/2,(a+c-b)/2);
	}
	else printf("Impossible\n");
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    gets(str);
    l=strlen(str);
    for(int i=0;str[i]<l;i++)
    {
        if(str[i]=='H')
        {
            printf("YES");
            break;
        }
        else if(str[i]=='Q')
        {
            printf("YES");
            break;
        }
        else if(str[i]=='9')
        {
            printf("YES");
            break;
        }
        else {
        printf("NO");
        break;
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;
int main(){
	char a[105];
	int i, t, f;
	cin >> a;
	f = 0;
	t = strlen(a);
	for (i = 0; i <= (t - 1); i++) {
		if (a[i] == 'Q' || a[i] == '9' || a[i] == 'H' ) { cout << "YES"; f = 1; break; }

	}
	if (f == 0)cout << "NO";

	return 0;
}


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

vector<int> ans;
void process(int n)
{
    ans.clear();
    ans.push_back(n);
    while(--n)
    {
        if(ans[ans.size()-1]%n==0)
        {
            ans.push_back(n);
        }
    }
    for(int i=0 ;i<(int)ans.size() ;i++)
    {
        printf("%d%c",ans[i],i==(int)ans.size()-1?'\n':' ');
    }
}

int main()
{
   // freopen("in.txt","r",stdin);
    int n;
    while(cin>>n)
    {
        process(n);
    }
}


#include<stdio.h>
int main(){
    int n,x;
    scanf("%d", &n);
    b=n;
    for(int i=n; i>=1; i--){
        if(x%i==0){
            x=i;
            printf("%d ", i);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#define eps 0.0000000001
#define bpr 999983
#define spr 111123
#define pi acos(-1.0)
#define imax 2139062143
#define mod 1000000007
#define golden (sqrt(5)+ 1)/2
#define reset(a,b) memset(a,b,sizeof(a))
#define dmax 1e20
#define siz 1005
#define ze 2.718281828459
using namespace std;
int ans[1000006];
int dij[1000006];
int mmax;
void dfs(int now,int num)
{
	dij[num]=now;
	for (int i=2;i<now;i++)
	{
		if (now%i==0)
		{
			dfs(now/i,num+1);
		}
	}
	dij[++num]=1;
	if (num>mmax)
	{
		mmax=num;
		for (int i=0;i<=num;i++)
			ans[i]=dij[i];
	}
	return ;
}
int main()
{
	int n;
	scanf("%d",&n);
	mmax=0;
	if (n==1)
	printf("1\n");
	else
	{
	dfs(n,0);
	for (int i=0;i<=mmax;i++)
	printf("%d ",ans[i]);
	printf("\n");
        }
}


#include <stdio.h>
using namespace std;
int ans[1000006];
int dij[1000006];
int mmax;
void dfs(int now,int num)
{
	dij[num]=now;
	for (int i=2;i<now;i++)
	{
		if (now%i==0)
		{
			dfs(now/i,num+1);
		}
	}
	dij[++num]=1;
	if (num>mmax)
	{
		mmax=num;
		for (int i=0;i<=num;i++)
			ans[i]=dij[i];
	}
	return ;
}
int main()
{
	int n;
	scanf("%d",&n);
	mmax=0;
	if (n==1)
	printf("1\n");
	else
	{
	dfs(n,0);
	for (int i=0;i<=mmax;i++)
	printf("%d ",ans[i]);
	printf("\n");
        }
}


#include<stdio.h>

int main(void)
{
    int mon, x , lcf;

    scanf("%d", &mon);
    printf("%d ", mon);
    for(x = mon; x > 1;){
    	for(lcf = 2; lcf <= x; lcf++){
    		if(trav % lcf == 0){
    			x = x / lcf;
	    		break;
			}
		}
		printf("%d ", x);
	}
    getch();
    return 0;
}


#include<stdio.h>

kontrol (long n)
{
        long i;
        int flag;
        if(n%10==8)return 1;
        if(n<10 &&n>=0)
        {
            if(n%10==8)return 1;
            return 0;
        }
        for (i=10;;i*=10)
        {
            if(i>n)break;
            if((n/i)%10==8){flag=1;break;}
        }
        if(flag==1)return 1;
        return 0;
}

int main()
{
    long i,k,temp;
    scanf("%d",&k);
    for(i=k+1;i<8888888888;i++)
    if(kontrol(i)==1){temp=i-k;break;}
    printf("%ld",temp%D;
    return 0;
}


#include <stdio.h>
#include <math.h>
int main() {
long long int n,m,z=0,p,q,r;
scanf("%I64d",&n);
m=n;r=n;
while(r!=0){
    r=r/10;
    z++;
}
while(1){
    n++;q=0;
    int i;p=n;
    for(i=0;i<z;i++){
        if(abs(p)%10==8){q++;}
         p=abs(p)/10;
    }
    if(q>0){break;}
}
printf("%d",n-m,);
    return 0;
}


#include<stdio.h>

kontrol (long long n)
{
        long long i;
        long long flag = 0;
        if(n%10==-8)return 1;
        if(n%10==8)return 1;
        if(n<10 &&n>=0)
        {
            if(n%10==8) || return 1;
            return 0;
        }
        for (i=10;;i*=10)
        {
            if(i>n)break;
            if((n/i)%10==8){flag=1;break;}
        }
        if(flag==1)return 1;
        return 0;
}

int main()
{
    long long i,k,temp;
    scanf("%lld",&k);
    for(i=k+1;i<8888888888;i++)
    if(kontrol(i)==1){temp=i-k;break;}
    printf("%lld",temp);
    return 0;
}


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

int main()
{
    int num[100],num2[100];

    int i=0,k,j,a,d,x,y,z,ck=0;

    scanf("%d",&n);

    x=n;
    z=n;

    while(n>0){

        a=n%10;

        num[i]=a;
        i++;

        n=n/10;

    }

    for(i=0;i<10;i++){
        j=0;
        x++;
        d=x;

        while(d>0){

            a=d%10;

            num2[j]=a;
            j++;
            d=d/10;

        }

        for(k=0;k<j;k++){

                if(num2[k]==8){
                    ck=1;
                    y=x-z;
                    printf("%d\n",y);
                    break;
                }
        }
        if(ck){
            break;
        }
    }

    return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="giga towers" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/giga towers" 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/giga towers" 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 />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


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

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

int main()
{
    int n=0,i=0,j=0,count1=0,count2=0,ans=0,temp=0;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);

    qsort(arr, n, sizeof(int), cmpfunc);
    //for(i=0;i<n;i++)
    //printf(" %d ",arr[i]);

   while(arr[j]==0)
   {
                   count1++;
                   j++;
   }

   for(i=j;i<n;i++)
   {
                   if(count2==0)
                                temp=i-j;
                   else
                       temp=(i-j)/count2;
                   if(arr[i]<temp)
                   {
                                   count2++;
                   //printf(" arr[%d]= %d , i-j = %d\n",i,arr[i],i-j);
                   }
    }

    if(count1>count2)
                   ans=count1;
    else
                   ans= count2;

                if(n>0&&ans==0)
                ans=1;
    printf("%d\n",ans);

    getch();
    return 0;
}


#include<stdio.h>
int arr[100];
int main()
{
    int n,i,j,s;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
    for(i=0;i<n-1;i++)
    {
                      for(j=i+1;j<n;j++)
                      {
                                        if(arr[i]>arr[j])
                                        {
                                          s=arr[i];
                                          arr[i]=arr[j];
                                          arr[j]=s;
                                        }
                      }
    }
    int k=0,count;
    for(i=0;i<n;i++)
    {
       count=arr[i];
       if(count>=0)
       {
                   arr[i]=-1;
                   int p=1;
         for(j=i+1;j<n;j++)
         {

            if(arr[j]>=p)
            {
               arr[j]=-1;
               p++;
            }
            }

         k++;
         }k
       }

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


#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b);
int main()
{
    int box[100];
    int N;
    int pile=0;
    scanf("%d",&N);
    getchar();
    for(int i=0;i<N;i++)
        scanf("%d",&box[i]);
    getchar();
     qsort(box,N,sizeof(box[0]),cmp);
    if(box[0]!=0) pile++;
    for(int i=0;i<N;i++)
    {
        if(box[i]==0) {pile++;continue;}
    }
     printf("%d\n",pile);
    return 0;
}
int cmp(const void *a,const void *b)
{
    return    (*(int *)a)<(*(int *)b);
}


#include<stdio.h>
#define swap(a,b) { t=a; a=b; b=t; }

int n;
int h[100000],son=0,t,k,l,hh[10000];
void ekle(int x)
{
	h[++son]=x;
	k=son;
	while(k/2)
	{
		if(h[k/2]<h[k])
		{
			swap(h[k/2],h[k])
			k/=2;
			continue;
		}
		break;
	}
}

void sil()
{
	int x = h[n];
	h[n--] = h[1];
	int k = 1;
	while(k * 2 <= n)
	{
		k=k*2+(h[2*k+1]>h[2*k] && 2*k+1 <= n);
		if(x<=h[k])	h[k/2] = h[k];
		else{ k /= 2; break; }
	}
	h[k] = x;
}
int main()
{
	int i,j,a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		ekle(a);
	}
	if(n==1)
	{
		printf("1");
		return 1;
	}
	int N = n,terim,b,sonraki,yukseklik,t=0;
	n = son;
	for(i=0;i<N;i++)
		sil();
	n=N;
	/*for(i=1;i<=n;i++)
		printf("%d ",h[i]);
	printf("\n");*/
	//printf("%d ",n);
	while(n>0)
	{
		t++;
		b=1;
		yukseklik=0;
		//terim=0;
		//puts("");
		while(b<N)
		{
			while((hh[b] || h[b]<yukseklik) && b<N)
			{
				b++;
			}
			if(h[b]<yukseklik)
				break;
			hh[b]=1;
			yukseklik++;
			n--;
		//	printf("%d ",h[b]);
			//getchar();
			//getchar();
			//printf("%d %d\n",h[b],yukseklik-1);
		}
	}
	printf("%d",t);
	return 0;
}


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

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

int main()
{
    int n=0,i=0,j=0,count1=0,count2=0,ans=0,temp=0;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);

    qsort(arr, n, sizeof(int), cmpfunc);
    //for(i=0;i<n;i++)
    //printf(" %d ",arr[i]);

   while(arr[j]==0)
   {
                   count1++;
                   j++;
   }

   for(i=j;i<n;i++)
   {
                   if(count2==0)
                                temp=i-j;
                   else
                       temp=(i-j)/count2;
                   if(arr[i]<temp)
                   {
                                   count2++;
                   //printf(" arr[%d]= %d , i-j = %d\n",i,arr[i],i-j);
                   }
    }

    if(count1>count2)
                   ans=count1;
    else
                   ans= count2;

                if(n>0&&ans==0)
                ans=1;
    printf("%d\n",ans);

    //getch();
    return 1;
}


#include<stdio.h>
#include<process.h>
#include<string.h>
#include<math.h>
int main()
{
	int a, b,k,j,sum=0;
	scanf("%d%d", &a, &b);
	for (int i = a; i < b + 1; i++){
		j = i;
		while (j != 0){
			k=j % 10;
			j=j / 10;
			switch (k){
			case 1:sum += 2; break;
			case 2:sum += 5; break;
			case 3:sum += 5; break;
			case 4:sum += 4; break;
			case 5:sum += 5; break;
			case 6:sum += 6; break;
			case 7:sum += 3; break;
			case 8:sum += 7; break;
			case 9:sum += 6; break;
			case 0:sum += 6; break;
			}
		}

	}
	printf("%d", sum);

	system("pause");
	return 0;
}


#include <stdio.h>
int ara[12];
long long visited[1000010];
int main()
{
    long long a,b,c,d,k,r,i;
     ara[0]=6;
     ara[1]=2;
     ara[2]=5;
     ara[3]=5;
     ara[4]=4;
    ara[5]=5;
    ara[6]=6;
    ara[7]=3;
    ara[8]=7;
    ara[9]=6;
    visited[0]=6;
    long long sum=6;
    for(i=1;i<=1000010;i++){
        a=i;
        while(a!=0){
            sum=sum+ara[a%10];
            a=a/10;
        }
      visited[i]=sum;
    }
  scanf("%I64d%I64d",&a,&b);
    printf("%I64d\n",visited[b]-visited[a-1]);
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="B. Grandfather Dovlet’s calculator" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/B. Grandfather Dovlet’s calculator" 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/B. Grandfather Dovlet’s calculator" 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 />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>
int segCalc(int number){
	if(number==4){
		return 4;
	}else if (number==1){
		return 2;
	}else if (number==2||number==5||number==3){
		return 5;
	}else if (number==6||number==0){
		return 6;
	}else if (number==7){
		return 3;
	}else if (number==8){
		return 8;
	}else if (number==9){
		return 7;
	}

}
long findSeg(long i){
	long seg;
	int temp;
	if(i/10==0){
		seg= segCalc(i);
		return seg;
	}
	else{
		temp=i%10;
		seg=segCalc(temp);

		return seg+findSeg(i/10);
	}

}
int main() {
	// your code goes here
	long a,b,sum=0,i;

	scanf("%ld %ld",&a,&b);
	for(i=a;i<=b;i++){

	sum+=	findSeg(i);

	}
	printf("%ld",sum);
	return 0;
}


#define counter.is_even counter%2==0
#define counter.is_nonzero counter!=0
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
long long int vertexes[11111];
int main(void) {
	long long int n, counter, position, maximum = 1;
	scanf("%I64d", &n);
	for(int i = 1; i <= n; i++) {
        scanf("%I64d", &vertexes[i]);
    }
	for(int i = 1; i <= n; i++){
		counter = 1;
		position = vertexes[i];
		while(position != i) {
			position = vertexes[position];
			counter++;
			if( counter > 100 || vertexes[position] == position) {
                printf("-1");
                return 0;
            }
		}
		if(counter.is_even) {
            counter = counter / 2;
        }
		if(counter.is_nonzero) {
            maximum = maximum * counter / gcd(maximum, counter);
        }
	}
	printf("%I64d", maximum);
	return 0;
}


#include<stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
llu G(llu x,llu y){return y?G(y,x%y):x;}
u N[111],V[111],A[111];
int main()
{
	u n,i=0,j;llu r=1,k;
	for(scanf("%u",&n);i++<n;++A[N[i]])scanf("%u",N+i);
	for(i=0;i++<n;)
	{
		if(!A[i]){printf("-1\n");return 0;}
		if(V[i])continue;
		for(j=i,k=0;!V[j];j=N[j])k+=V[j]=1;
		if(!(k&1))k>>=1;
		r=r/G(r,k)*k;
	}
	printf("%I64u\n",r);
	return 0;
}


#include<stdio.h>
typedef long long int lli;
int a[110];
int m[110];
lli c[110];
lli mcm(lli a,lli b);
lli mcd(lli a,lli b);
lli min(lli a,lli b);
lli max(lli a,lli b);
lli cycl(int w,int s,int q);
int main(){
    int i,n,m;
    lli t,r;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",a+i);
    }
    for(i=1;i<=n;i++){
        c[i]=cycl(i,i,0);
        if(c[i]==-1){
            printf("-1");
            return 0;
        }
        if(c[i]%2==0){
            c[i]/=2;
        }
    }
    if(n==1){
        printf("%I64d\n",c[1]);
    }else{
        r=mcm(c[1],c[2]);
        for(i=1;i<=n;i++){
            r=mcm(r,c[i]);
        }
        printf("%I64d\n",r);
    }
    return 0;
}
lli min(lli a,lli b){
    if(a<b)return a;return b;
}
lli max(lli a,lli b){
    if(a>b)return a;return b;
}
lli mcm(lli a,lli b){
    return a*b/mcd(a,b);
}
lli mcd(lli a,lli b){
    lli r;
	r=a%b;
	if (r==0)return(b);
	else return(mcd(b,r));
}
lli cycl(int w,int s,int q){
    int i;
    long long int r;
    m[w]=1;
    if(m[a[w]]){
        if(a[w]==s){
            r=q+1;
        }else{
            r=-1;
        }
    }else{
        r=cycl(a[w],s,q+1);
    }
    m[w]=0;
    return r;
}


#include<stdio.h>
int gcd(int,int);
int main()
{
    int n,a[105],b[105],k,x,f,ans;
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);

    for(i=1;i<=n;i++)
    {

         k=0;
         x=i;
         f=0;
         while(1)
         {
               x=a[x];
               k++;
               if(x==i)
               {
                   b[i]=k;
                   break;
               }
               if(k>=n)
               {f=1;
               break;}
         }
         if(f==1)
         {printf("-1\n");
         break;}
    }
    if(f==0)
    {
         for(i=1;i<=n;i++)
         {
               if(b[i]%2==0)
               b[i]/=2;
         }
         ans=b[1];
         for(i=2;i<=n;i++)
         {
              ans=(ans*b[i])/gcd(ans,b[i]);
         }
         printf("%d\n",ans);
    }
    return 0;
}

int gcd(int p,int q)
{
    if(q==0)
    return p;
    int t;
    if(p<q)
    {
       t=q;
       q=p;
       p=t;
    }

    return gcd(q,p%q);
}


#include<stdio.h>
int main()
{
    int n,last,k;
    scanf("%d",&n);
    last=n%10;
    if(last==0)
    {
        printf("%d",n);
    }
else if(last<=5)
    {
        k = n/10;
        printf("%d",k*10);
    }
    else(last>5)
    {
        k = (n/10) +1;
        printf("%d",k*10);
    }
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="ihezd" />
		<Option execution_dir="C:/Users/WiKi Kef/Desktop/E.N.S.I/C++/ihezd/" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/ihezd" 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/ihezd" 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="E.N.S.I/C++/ihezd/main.c">
			<Option compilerVar="CC" />
		</Unit>
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<stdio.h>
int main()
{
    long long i,j,n,m,a=0,b=0,c=0,d=0,e=0,dk=0,last=0;
    scanf("%d\n",&n);
    last =n%10;
    if(last==0)
    printf("%d",n);
    else if(last==1)
        printf("%d\n",n-1);
    if(last==2)
        printf("%d\n",n-2);
    if(last==3)
        printf("%d\n",n-3);
    if(last==4)
        pritnf("%d\n",n-4);
    if(last==5)
        printf("%d\n",n-5);
     if(last==6)
        printf("%d\n",n+4);
    if(last==7)
        pritnf("%d\n",n+3);
    if(last==8)
        printf("%d\n",n+2);
    if(last==9)
        pritnf("%d\n",n+3);

        return 0;
}


#include<stdio.h>
#include<conio.h>
int main()
{
          int n,last=0;
          scanf("%d",&n);
          last=n%10
          if(last==0)
          printf("%d",n);
          else if(last==1)
          printf("%d",n-1);
          else if(last==2)
          printf("%d",n-2);
          else if(last==3)
          printf("%d",n-3);
          else if(last==4)
          printf("%d",n-4);
          else if(last==5)
          printf("%d",n-5);
          else if(last==6)
          printf("%d",n+4);
          else if(last==7)
          printf("%d",n+3);
          else if(last==8)
          printf("%d",n+2);
          else if(last==9)
          printf("%d",n+1);
          else
          printf("0");
          return 0;
}


include<stdio.h>
int main()
{
    int num,ans;
    scanf("%d",&num);
    int res=num%10;
    if(res==5) ans=num+5;
    else if(res<5) ans=num-res;
    else if(res>6) ans=num+10-res;
    printf("%d\n",ans);

    return 0;
}


#include <stdio.h>

inline void printRepr(int num){
    if(num >= 5){
        printf("-O|");
        num-=5;
    }
    else{
        printf("O-|");
    }
    switch(num){
        case 0:printf("-OOOO");
            break;
        case 1:printf("O-OOO");
            break;
        case 2:printf("OO-OO");
            break;
        case 3:printf("OOO-O");
            break;
        case 4:printf("OOOO-");
            break;
    }
    printf("\n");
    return;
}

int main(){
    int number,temp;
    scanf("%d",&number);
    if(number==0){
        printf("O-|-OOOO");
    }
    while(number > 0 ){
        temp=number%10;
        printRepr(temp);
        number/=10;
    }
    return 0;
}


#include <string.h>
#include <stdio.h>
int main()
{
     char ch[11];
     scanf("%s",ch);
     int l=strlen(ch);
     int i,j;
     for(j=0;j<l;j++)
     {
          if(ch[j]=='0')
          printf("O-|-OOOO\n")
          else if(ch[j]=='1')
               printf("O-|O-OOO\n");
          else if(ch[j]=='2')
          printf("O-|OO-OO\n");
          else if(ch[j]=='3')
          printf("O-|OOO-O\n");
          else if(ch[j]=='4');
          printf("O-|OOOO-\n");
          else if(ch[j]=='5')
          printf("-O|-OOOO\n");
          else if(ch[j]=='6')
          printf("-O|O-OOO\n");
          else if(ch[j]=='7')
          printf("-O|OO-OO\n");
          else if(ch[j]=='8');
          printf("-O|OOO-O\n")
          else if(ch[j]=='9')
          printf("-O|OOOO-\n");

     }
}


#include <stdio.h>
#include <string.h>
char str[15][15];
int main()
{
    int i,n,j,a[50];
    strcpy(str[0],"O-|-OOOO");
    strcpy(str[1],"O-|O-OOO");
    strcpy(str[2],"O-|OO-OO");
    strcpy(str[3],"O-|OOO-O");
    strcpy(str[4],"O-|-OOOO");
    strcpy(str[5],"-O|-OOOO");
    strcpy(str[6],"-O|O-OOO");
    strcpy(str[7],"-O|OO-OO");
    strcpy(str[8],"-O|OOO-O");
    strcpy(str[9],"-O|-OOOO");
    while(~scanf("%d",&n))
    {
        i=0;
        (n==0){
            printf("%s\n",str[0];
            continue;
        }
        while(n!=0)
        {
            a[i++]=n%10;
            n=n/10;
        }
        for(j=0;j<i;j++)
            printf("%s\n",str[a[j]]);
    }
    return 0;
}


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

#define MOD  1000003

int mapping(char c)
{
	switch(c)
	{
		case '>':
			return 8;
		case '<':
			return 9;
		case '+':
			return 10;
		case '-':
			return 11;
		case '.':
			return 12;
		case ',':
			return 13;
		case '[':
			return 14;
		case ']':
			return 15;
	}

}
int length(char* c)
{
	int i=0;
	for(;c[i]!='\0';i++){}
	return i;
}

int fastMod(int a,int b,int m)
{
	int i=1;
	int result=1;
	if(a==0 || m==1)
	{
		return 0;
	}
	if (b==0)
	{
		return 1;
	}
	if(b==1)
	{
		return a%m;
	}
	result=((a%m)*(a%m))%m;
	for(i=1;i<=b-2;i++)
	{
		result=(result*(a%m))%m;
	}
	return result;

}
int main()
{
 	char unary[150];
    int len=0;
	int result=0;
	int i=0;

	scanf("%s",unary);
    len=length(unary);
	for(i=0;i!=len;i++)
	{
		result=result+((mapping(unary[i])%MOD)*(fastMod(16,len-i-1,MOD)))%MOD;
	}
	printf("%d\n",result%MOD);

}


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

#define MOD 1000003

long long int mod(long long int p, long long int m)
{
	if(p==0)
		return 1;
	else if(p==1)
		return 2;
	else if(p%2)
		return (mod(1,m)*mod(p-1,m))%MOD;
	else
		return (mod(p/2,m)*mod(p/2,m))%MOD;
}

int main()
{
	char p[100],s[100];
	scanf("%s",p);

	for(long long int i=0;p[i]!='\0';i++)
	{
		if(p[i]=='>')
		{
			strcat(s,"1000");

		}
		else if(p[i]=='<')
		{
			strcat(s,"1001");
		}
		else if(p[i]=='+')
		{
			strcat(s,"1010");
		}
		else if(p[i]=='-')
		{
			strcat(s,"1011");
		}
		else if(p[i]=='.')
		{
			strcat(s,"1100");
		}
		else if(p[i]==',')
		{
			strcat(s,"1101");
		}
		else if(p[i]=='[')
		{
			strcat(s,"1110");
			//puts(s);
		}
		else
		{
			strcat(s,"1111");
			//puts(s);
		}
	}

	long long int ans=0,flag=0;
	for(long long int i=strlen(s)-1;i>=0;i--)
	{
		long long int temp=0;
		if(s[i]=='1')
			temp = mod(flag,MOD);
		ans = (ans+temp)%MOD;
		flag++;
	}
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
const int N = 100005;
int n;
char str[N];

int trans(char ch){
    switch (ch){
        case '>':
            return 8;
        case '<':
            return 9;
        case '+':
            return 10;
        case '-':
            return 11;
        case '.':
            return 12;
        case ',':
            return 13;
        case '[':
            return 14;
        case ']':
            return 15;
    }
    return -1;
}

int main(){
    gets(str+1);
    n = strlen(str+1);
    int ans = 0 , i;
    for (i=1;i<=n;i++){
        ans = ans * ( 1 << 4 ) + trans(str[i]);
        ans %= 1000003;
    }
    printf("%d\n",ans);
}

#include <stdio.h>
#include <string.h>
const int N = 100005;
int n;
char str[N];

int trans(char ch){
    switch (ch){
        case '>':
            return 8;
        case '<':
            return 9;
        case '+':
            return 10;
        case '-':
            return 11;
        case '.':
            return 12;
        case ',':
            return 13;
        case '[':
            return 14;
        case ']':
            return 15;
    }
    return -1;
}

int main(){
    gets(str+1);
    n = strlen(str+1);
    int ans = 0 , i;
    for (i=1;i<=n;i++){
        ans = ans * ( 1 << 4 ) + trans(str[i]);
        ans %= 1000003;
    }
    printf("%d\n",ans);
}


#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	if(n == 1) {
		printf("1");
		return 0;
	} else if(n == 2) {
		printf("2");
		return 0;
	}
	int i = 0;
	n -= 3;
	int p = 1;
	for(i = 0; i < n; ++i) {
		p *= 2;
	}
	printf("%d", n+3+p);
	return 0;
}


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

int main()
{
int n,j,i;
scanf("%d",&n);
int sum=n*(n+1)/2;
int x=sum-n;
if(x=1)
    sum=sum-(1);
    else
        sum=sum-(2*x);

printf("%d",sum);
}


#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int i, p = 0;
	--n;
	for(i = 1; i < n; ++i) {
		++p;
	}
	printf("%d", n+1+p);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
//week3
int di(int n)
{
    if(n==1) return 1;
    if(n==2) return 2;
    if(n==3) return 4;
    if(n==4) return 6;
    else return 2*di(n-1)-2*di(n-3)+di(n-4);
}
int main()
{
    int n;
    scanf("%d",&n);
    int m=di(n);
    printf("%d\n",m);
}


#include<stdio.h>
main()
{
      int h, r;
      scanf("%d",&r);
      scanf("%d",&h);
      printf("%d",(1 + ((2*h)/r)));
}


#include<stdio.h>
#include<math.h>
int r,h,vol;
int main()
{
	scanf(" %d %d",&r,&h);

	vol = h / r * 2;
	h %= r;
	if (2*h<r)
		vol++;
	else if(h*2 >= sqrt(3)*r)
		vol += 3;
	else
		vol += 2;
	printf("%d",vol);
}


#include <stdio.h>

main()
{
	long long h,r;
	long long t;
	scanf("%I64d %I64d",&r,&h);
	t=h%r;
	if(2*t>=r)
	{
		printf("%I64d",2+h/r*2);
	}
	else
	{
		printf("%I64d",1+h/r*2);
	}
	return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
int h, r, ans;
scanf("%d",&r);
scanf("%d",&h);
ans = 2*h/r;
ans += ((2*m>=r)?2:1)
ans += ((2.0*m>=(sqrt(3.0)*r))?1:0);
printf("%d",ans);
return 0;
}


#include <stdio.h>

int main(void) {
    // your code goes here
    float r,h;
    int n;
    scanf("%f %f",&r,&h);
    if((h-r/2)%r==0&&r!=1&&h>=r){
        h=h/r;
        n=2+2*h;
    }
    else{
        n=1+2*h/r;
    }
    printf("%d",n);
    return 0;
}


#include<stdio.h>
//#include<conio.h>
#include<math.h>
int main()
{
    long int i,x,y,n,m,w;
    long int p;
    scanf("%ld %ld",&x,&y);
    p=sqrt(x*x+y*y);
    if(p*p==x*x+y*y)  {printf("black"); goto w; }
    n=0;m=1;
  if(x*y>0){  for(i=1;i<=1000;i++,n++,m++)
    if(n*n<=x*x+y*y && m*m>=x*x+y*y)
    { if (m%2==0) printf("white");
    else printf("black");  goto w; }   }
    else for(i=1;i<=1000;i++,n++,m++)
    if(n*n<=x*x+y*y && m*m>=x*x+y*y)
    { if (m%2!=0) printf("white");
    else printf("black");  goto w; }
    w: //  getch();
    return(0);
}


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

int main()
{
	double x, y;
	int i = 0;
	int area;
	scanf("%lf%lf", &x, &y);

	//�ж�x,y�ڵڼ�����
	if (x*y==0)
	{
		printf("black\n");
		return 0;
	}
	else if (x > 0 && y > 0)
	{
		area = 1;
	}
	else if (x<0 && y>0)
	{
		area = 2;
	}
	else if (x < 0 && y<0)
	{
		area = 3;
	}
	else
		area = 4;
	//����ԭ��ľ���
	double distance = sqrt(x*x + y*y);
	i = fabs(x) > fabs(y) ? fabs(x) : fabs(y);
	for (i; i <= fabs(x) + fabs(y); i++)
	{
		if (distance == i)
		{
			printf("black\n");
			return 0;
		}
		else if (i<distance&&i + 1>distance)
		{
			if (i % 2 == 0)
				i = 2;
			else
				i = 1;
		}
	}
	//���ݲ�ͬ���ޣ��в�ͬ�Ĵ�����
	switch (area)
	{
	case 1:
		if (i == 1){
			printf("white\n");
		}
		else{
			printf("black\n");
		}
		break;
	case 2:
		if (i == 1){
			printf("black\n");
		}
		else{
			printf("white\n");
		}
		break;
	case 3:
		if (i == 1){
			printf("white\n");
		}
		else{
			printf("black\n");
		}
		break;
	case 4:
		if (i == 1){
			printf("black\n");
		}
		else{
			printf("white\n");
		}
		break;
	}
	return 0;
}


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

int main()
{
	int x, y, sx, sy, pos;
	scanf("%d %d", &x, &y);

	if((x==0)||(y==0))
	{
		printf("black");
		return 0;
	}

	if(x>0&&y>0)
		flag=1;
	else if(x>0&&y<0)
		flag=2;
	else if(x<0&&y<0)
		flag=3;
	else
		flag=4;

	float rad, zc;

	sx=x*x;
	sy=y*y;

	rad=(float)sqrt(sx+sy);
	zc=floor(rad);
	if((rad/zc)==1)
	{
		printf("black");
		return 0;
	}

	if((flag==1)||(flag==3))
	{
		pos=(int)floor(rad);
		if(pos%2==0)
			printf("black");
		else
			printf("white");
	}
	else if((flag==2)||(flag==4))
	{
		pos=(int)floor(rad);
		if(pos%2==0)
			printf("white");
		else
			printf("black");
	}
}


#include<stdio.h>
#include<math.h>
main()
{
    int x,y,ds,f;
    scanf("%d %d",&x,&y);
    float d;
    ds=x*x+y*y;
    d=sqrt(ds);

    f=floor(d);
    if(ds%f==0) f++;

    if(f%2==0)
    { if(x>0&&y>0 || x<0&&y<0)
        printf("black");
    else printf("white");}
    else
    {if(x>0&&y>0 || x<0&&y<0)
        printf("white");
    else printf("black");

    }
    return 0;
}


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

int main(void){
	int x,y;
	double arg,r;
	scanf("%d%d",&x,&y);
	arg=atan(x/y);
	while(arg<0){
		arg+=2*M_PI;
	}
	r=sqrt(x*x+y*y);
	if((arg>=0 && arg<=M_PI/2.0) || (arg>=M_PI && arg<=M_PI*3/2)) {
		if(floor(r)==r){
			printf("black");
			return 0;
		}
		if((long)ceil(r)%2==1)
			printf("black");
		else
			printf("white");
	}
	else{
		if(floor(r)==r){
			printf("black");
			return 0;
		}
		if((long)ceil(r)%2==1)
			printf("white");
		else
			printf("black");
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
 int main()
{
    int n,sr;
    bool flag;
    while(scanf("%d",&n))
    {
       flag=0;
        sr=pow(2*n-3,0.5);
        for(int i=1;i<=sr;i++)
        {
           int k=pow(2*n-i*(i+1),0.5);
          if(k && k*(k+1)+i*(i+1)==2*n)
           {
               flag=1;
               break;
            }
       }
       if(flag) printf("YES\n");
        else printf("NO\n");
   }
    return 0;
}


#include<stdio.h>
#include<math.h>
int encontro(int n){
  int i;
  float aux=sqrt(n+0.25)-0.5,aux2;
  for(i=1;i<=aux;i++){
  aux2=sqrt(2*n-i*i-i+0.25)-0.5;
  if(aux2==(int)aux2)
  return 1;
  }
  return 0;
}
int main(){
  int n;
  scanf("%d",&n)
    if(encontro(n))
    printf("YES\n");
    else printf("NO\n");
}


#include <stdio.h>
#include<math.h>
 int main()
{
    int n,sr;
    bool flag;
    while(scanf("%d",&n)!=EOF)
    {
       flag=0;
        sr=pow(2*n-3,0.5);
        for(int i=1;i<=sr;i++)
        {
           int k=pow(2*n-i*(i+1),0.5);
          if(k && k*(k+1)+i*(i+1)==2*n)
           {
               flag=1;
               break;
            }
       }
       if(flag) printf("YES\n");
        else printf("NO\n");
   }
    return 0;
}


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

int main()
{
  int n, i, k, r, x, found = 0;
  scanf("%d", &n);
  n *= 2;
  k = int(sqrt(n * 1.0f) + 0.5f);
  for (i = 1; i < k; i ++)
  {
    r = n - i * i - i;
    x = (int)sqrt(r * 1.0f);
    if (x * (x + 1) == r)
    {
      found = 1;
      break;
    }
  }
  if (found)
  {
    printf("YES");
  }
  else
  {
    printf("NO");
  }
  return (0);
}


#include <stdio.h>
#include<math.h>
 int main()
{
    int n,sr,flag;
    while(scanf("%d",&n)!=EOF)
    {
       flag=0;
        sr=pow(2*n-3,0.5);
        for(int i=1;i<=sr;i++)
        {
           int k=pow(2*n-i*(i+1),0.5);
          if(k && k*(k+1)+i*(i+1)==2*n)
           {
               flag=1;
               break;
            }
       }
       if(flag) printf("YES\n");
        else printf("NO\n");
   }
    return 0;
}


#include<stdio.h>

int n, m, highest = 0, highest_temp = 0, p[8+1], i, k, m_note, n_count, min;
void permutate(int, int);
void swap(int *x, int *y);

int main()
{
    while(scanf("%d", &n)!=EOF)
    {
        min = 9;
        scanf("%d", &m);
        for(i = 1; i<=n; i++)
        {
            p[i] = i;
        }
        for(i = 1; i<=n; i++)
        {
            highest += i * (n+1-i);
        }
        m_note = 1;
        if(m==1)
        {
            for(i = 1; i<=n; i++)
            {
                printf("%d ", p[i]);
            }
            printf("\n")
        }
        else
        {
            permutate(1, n);
        }
    }
    return 0;
}

void permutate(int start, int end)
{
    if(start == end)
    {

        for(k=1; k<=n; k++)
        {
            n_count = n;
            for(n_count; n_count>0; --n_count)
            {
                min = 9;
                for(i=k; i<=n_count; ++i)
                {

                    if(p[i]<min)
                    {
                        min = p[i];
                    }
                    else{}
                }
                for(i=k; i<=n_count; ++i)
                {
                    if(p[i]==min)
                    {
                        highest_temp += p[i];
                    }
                    else{}
                }
            }
        }
        if(highest_temp >= highest)
        {
            ++m_note;
            if(m_note-1==m)
            {
                for(i=1; i<=n; i++)
                {
                    printf("%d ", p[i]);
                }
                printf("\n");
            }
            else{}
        }
        else{}
    }
    else
    {
        int j;
        for(j = start; j <= end; ++j)
        {

            swap((p+start), (p+j));
            permutate(start+1, end);
            swap((p+start), (p+j));
        }
    }
}

void swap(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}


#include <stdio.h>
static inline long long count(int n) {
	return 1ll<<(long long)(n-1);
}
int res[50];
int main() {
	int n,m;
	scanf("%d%d", &n, &m);
	int left = 0, right = n-1;
	int c = 1, k = n;
	while(n--) {
		if ((long long)m > count(n)) {
			res[right] = c;
			right--;
		} else {
			res[left] = c;
			left++;
		}
		c++;
	}
	int i;
	for(i = 0; i < k-1; i++)
		printf("%d ", res[i]);
	printf("%d\n", res[k-1]);
}


/*
 *    Homework -  NCTU DCS CP
 *    =======================
 *    Student ID :    0316218
 *    GCC Option :  -lm -ansi
 *    -Wall -Wextra -pedantic
 */

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

int m;
int p[50] = {0};

void permutation(int, int, int);

int main(void)
{
    int n;

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

    permutation(n, 0, n - 1);

    return 0;
}

void permutation(int n, int l, int r)
{
    int k = n + l - r;

    if (l == r)
    {
        p[l] = k;

        if (--m == 0)
        {
            int i;

            for (i = 0; i < n; i++)
                printf("%d%c", p[i], (i != n - 1) ? ' ' : 0);
        }
        else if (m < 0)
        {
            return;
        }
    }
    else
    {
        p[l] = k;
        permutation(n, l + 1, r);
        p[r] = k;
        permutation(n, l, r - 1);
    }
}


#include<stdio.h>

int solution[51];
int n,m;
int count=0;
void backtrack(int x,int y,int c)
{
	if(c==n)
	{
		solution[x]=n;
		count++;//minmin(1);
		if(count==m)
		{
			int i;
			for(i=1;i<=n;i++)
			printf("%d ",solution[i]);
			printf("\n");
		}
		return;
	}

		solution[x]=c;
		backtrack(x+1,y,c+1);
		if(count==m)
		return;
		solution[y]=c;
		backtrack(x,y-1,c+1);
		if(count==m)
		return;

	return;
}

/*void minmin(int x)
{
	if(x==n+1)
	{
		if(sum==ans)
		c++;
		return;
	}

	int i,j;
	for(i=x;i<=n;i++)
	{
		int MIN=100;
		for(j=x;j<=i;j++)
		{
			if(MIN>solution[j])
				MIN=solution[j];
		}
		sum+=MIN;
	}
	minmin(x+1);
	return;
}*/

int main()
{
	scanf("%d %d",&n,&m);
	backtrack(1,n,1);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
//using namespace std;
int main()
{
	long int n,m,min,d,rem,kmin,kmax,max;

	cin >> n >>m;
	min=n/m;
	rem=n%m;
	d=m-rem;
	kmin=((d*(min-1)*min)/2) + ((rem*(min+1)*min)/2);
	max=(n-m+1);
	kmax=(max*(max-1))/2;

	cout << kmin << " "<< kmax;
	return 0;

}


int main(int argc,char const *argb[])
{
    long long int m,n,min,max,a,b,c;
    scanf("%I64d%I64d",&m,&n);
    max=(m-n)*(m-n+1)/2;
    s=m%n;
    c=m/n;
    b=m/n+1;
    min=(n-a)*(c-1)*(c)/2+a*b*(b-1)/2;
    printf("%I64d%I64d\n",min,max);
    return 0;
}


#include <stdio.h>

int main(){
    int n, m, Kma=0, Kmi;
    scanf("%i %i", &n, &m);
    for (i = n-(m-1);i>0;i--)
        Kma = Kma+(i-1);
    if (m==1)
       Kmi = Kma;
    else
       Kmi = n/2;
    printf("%i %i", Kmi, Kma);
    return 0;
}


#include<stdio.h>

 long long int nCr(long long int n, long long int r)
 {

     if(r == 0) return 1;
     if(r > n) return 0;
     if (r > n / 2) return nCr(n, n - r);
     long long int combi = 1, i;
     for(i = 1; i <= r; i++)
     {

         combi = combi * (n - i + 1);
         combi = combi / i;
     }
     return combi;
 }

 int main()
 {

     long long int m, n, a, b, ans1, ans2, f, d, e;
     scanf("%lld %lld", &m, &n);
     a = m / n;
     b = m + 1 - n;
     e = m % n;
     d = n - e;
     f = a + 1;
     ans1 = (nCr(a, 2) * d) + (nCr(f, 2) * e);
     ans2 = nCr(b, 2);
     cout <<ans1<<" "<<ans2<< endl;
     return 0;
 }


#include<stdio.h>
/*int ncr(int n,int r)
  {
  if(r==1)
  {
  return n;
  }
  if(r==0 || r==n)
  {
  return 1;
  }
  return ncr(n-1,r)+ncr(n-1,r-1);
  }*/
int  nChoosek( int n, int  k )
{
	if (k > n) return 0;
	if (k * 2 > n) k = n-k;
	if (k == 0) return 1;

	int result = n;
	for( int i = 2; i <= k; ++i ) {
		result *= (n-i+1);
		result /= i;
	}
	return result;
}

int main()
{
	int i=0;
	int n,teams;
	scanf("%d%d",&n,&teams);
	int a=n-teams+1;
	long long int max=a*(a-1)/2;
	int pl[1000009]={0};
	int flag;
	long long int min=0;
	if(t==1)
	{
		min=n*(n-1)/2;
	}
	else
	{

		for(n=n;n>0;n--)
		{
			pl[i]++;
			if(i==(teams-1))
			{
				i=0;
			}
			else
				i++;
		}

		for(i=0;i<teams;i++)
		{
			min+=nChoosek(pl[i],2);
			//min+=pl[i]*(pl[i]-1)/2;
		}
	}
	printf("%d %d",min,max);
	return 0;
}


#include <stdio.h>
int main(){
    long long n,i;
    scanf("%lli",&n);
    if(n%2){
        for(i=3;i<=n;i++){
            if((n%i)==0) break;
        }
        n -= i;
        n = n/2;
        n++
    }
    else n /= 2;
    printf("%lli\n",n);
    return 0;
}


#include <stdio.h>
int arr [1000000000];
int main()
{
//    printf("ertyg");
    long long int n;
    scanf("%lld",&n);
    if (n%2==0)
    {
        printf("%lld",n/2);
        return 0;
    }
    for (long long int i=3;i<=n;i++)
    {
//        printf("%lld",i);
        if (n%i==0)
        {
            n=n-i;
//            printf("%lld %lld ",i,n);
            break;
        }
    }
    printf("%lld",n/2+1);
    return 0;
}


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

int main () {

    uint64_t n;
    scanf("%"SCNu64, &n);

    if (n % 2 == 0) {
        printf("%"PRIu64i"\n", n / 2);
    }
    else {
        uint64_t j = 3;
        for ( ; j * j <= n; j += 2) {
            if (n % j == 0) {
                printf("%"PRIu64"\n", (1 + (n - j) / 2));
                n = 1;
                break;
            }
        }
        if (n > 1) {
            putchar('1');
            putchar("\n");
        }
    }

    return 0;
}
~
~


#include<stdio.h>
#include<math.h>
long long ai(long long n);
int main ()
{
	long long n,i,l,p,a1,t;

	scanf("%lld",&n);
	if(n%2==0) printf("%lld\n",n/2);
	else
	{
		if(ai(n))
		printf("1\n");
		else
		{
			for (i=2;i<n;i++)
			{
				if(n%i==0)
				a1=i;
			}
			n-=a1;
			t=n/2+1;
			printf("%lld\n",t);
		}
	 }
	return 0;
}
long long ai(long long n)
{
	double n1;
	long long i,sqr;
	n1=(double)n;
	sqr=sqrt(n1);
	sqr+=2;
	for(i=2;i<=sqr;i++)
	{
	if (n1%i==0)
	return 0;
    }
	return 1;
}


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

int main()
{
    long long i,n,sum=0;
    scanf("%lld",&n);
    if(n%2==0)
    {
        sum=n/2;
    }else
    {
        sum=1;
        for(i=2;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
                sum=(n-i)/2+1;
                break;
            }
        }
    }
    printf("%lld",sum);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include<stdlib.h>

int main()
{
    long long i,n,sum=0;
    scanf("%lld",&n);
    if(n%2==0)
    {
        sum=n/2;
    }else
    {
        sum=1;
        for(i=2;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
                sum=(n-i)/2+1;
                break;
            }
        }
    }
    printf("%lld",sum);
    return 0;
}


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

#define SIZE 3

int hasCentalSymmetry(char** arr, int size);

int main()
{
    char** arr;
    arr = (char**)malloc(SIZE * sizeof(char*));
    for (int i = 0; i < SIZE; i++)
    {
        arr[i] = (char*)malloc(SIZE*sizeof(char));
    }
    for (int i = 0; i < SIZE; i++)
    {
        for (int j = 0; j < SIZE; j++)
        {
            /*scanf("%c",&arr[i][j]);*/
            arr[i][j] = getchar();
        }
        getchar();
    }

    if(hasCentalSymmetry(arr, SIZE))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

int hasCentalSymmetry(char** arr, int size)
{

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


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int Abs(int a){return a>=0?a:-a;}
int main()
{ int tab[5][2],i,j,stop=0,res,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d%d",&tab[i][0],&tab[i][1]);}
  if(n==1){printf("-1"); }
  else
  {
  for(i=0;i<n;i++)
    {
        for(j=i+1;j<n,j++)
           {
           if(tab[i][0]!=tab[j][0] && tab[i][1]!=tab[j][1] )
              {
                    res=Abs(tab[i][0]-tab[j][0]) * Abs(tab[i][1]-tab[j][1]);
                    printf("%d",res);
                    return 0;
              }
           }
    }
printf("-1");

return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="CodeForce 331" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/CodeForce 331" 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/CodeForce 331" 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 />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<cstdio>

struct Utensils
{
	int num;
	int count;
};

int main()
{
	int n,k;
	while((scanf("%d%d",&n,&k))!=-1)
	{
		int i,j,iCount=0,ok,u[n],setnum = 0;
		struct Utensils U[n];
		for(i = 0;i < n;i++) scanf("%d",&u[i]);
		for(i = 0;i < n;i++)
		{
			ok = 1;
			for(j = 0;j<iCount;j++)
			{
				if(U[j].num == u[i])
				{
					U[j].count++;
					ok = 0;
					break;
				}
			}
			if(ok)
			{
				U[iCount].num = u[i];
				U[iCount++].count = 1;
			}
		}
		for(i = 0;i < iCount;i++)
		{
			if(setnum < (U[i].count-1)/k+1) setnum = (U[i].count-1)/k+1;
		}
		printf("%d\n",setnum*iCount*k-n);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
void main()
 {
     int n=0,k=0,c=0,d=0,i=0,s=0,somonan=0,temp,m[1000];
     scanf("%d%d",&n,&k);
     for(i=0;i<n;i++)
     {
         scanf("%d",&m[i]);
     }
     for(i=0;i<n;i++)
     {
        for(c=0;c<n;c++)
        {
            if(m[c]>m[c+1])
            {
                temp=m[c];
                m[c]=m[c+1];
                m[c+1]=temp;
            }
        }
     }
     c=0,temp=1;
     for(i=0;i<n;i++)
     {
         if(m[i]==m[i+1])
         {
             temp++;
         }
         else
         {
             d++;
            if(temp>c)
            {
                c=temp;
            }
            temp=1;
         }
     }
     if(c<k)
     {
         somonan=1;
     }
     else if(c==k)
     {
         somonan=1;
     }
     else
     {
         somonan=c/k+1;
     }
     s=somonan*d*k-n;
     printf("%d",s);
 }


#include<stdio.h>
#include<math.h>
void main()
{
	int n,k,max=0,temp,count=0,res,i=0,p;
	int utensil[101]={0};
	scanf("%d %d",&n,&k);
	while(i<n)
	{
		scanf("%d",&temp);
		if(utensil[temp]==0)
		{
			count++;
		}
		utensil[temp]++;
		if(utensil[temp]>max)
		{
			max=utensil[temp];
		}
		i++;
	}
	p=(max+k-1)/k;
	res=(p*count*k)-n;
	printf("%d",res);
}


 #include<stdio.h>
#include<stdlib.h>
void main()
{
	int n ;
	int k;
	printf("donner le nombre de reamining utensels : ");
	scanf("%d",&n);
	printf("donner le nombre de guest");
	scanf("%d",&k);
	int* tab ;
	tab=malloc(n*sizeof(int));
	int i ;
	int inter[101]={0};
	int max=0 , out=0;
	for(i=0;i<n;i++)
	{
		printf("donner le type de utensel");
		scanf("%d",&tab[i]);
		inter[tab[i]]++;
		if(	inter[tab[i]]>max)
		{
			max=inter[tab[i]];
		}
	}
	while(max%k)
	{
		max++;
	}
	for(i=1;i<101;i++)
	{
		if(inter[i]!=0)
		{
		out+=max-inter[i];
		}
	}
	printf("\n%d",out);
}


#include <stdio.h>
#include <stdlib.h>
void main()
 {
     int n=0,k=0,c=0,d=0,i=0,s=0,somonan=0,temp,m[1000];
     scanf("%d%d",&n,&k);
     for(i=0;i<n;i++)
     {
         scanf("%d",&m[i]);
     }
     for(i=0;i<n;i++)
     {
        for(c=0;c<n;c++)
        {
            if(m[c]>m[c+1])
            {
                temp=m[c];
                m[c]=m[c+1];
                m[c+1]=temp;
            }
        }
     }
     c=0,temp=1;
     for(i=0;i<n;i++)
     {
         if(m[i]==m[i+1])
         {
             temp++;
         }
         else
         {
             d++;
            if(temp>c)
            {
                c=temp;
            }
            temp=1;
         }
     }
     if(c<k)
     {
         somonan=1;
     }
     else if(c==k)
     {
         somonan=1;
     }
     else
     {
         somonan=c/k+1;
     }
     s=somonan*d*k-n;
     printf("%d",s);
 return(0);
 }


#include <stdio.h>
#include <set>
#include <iostream>
using namespace std;
int a[11][11];
void init(int x){
    for(int i=1;i <= x;i++){
        for(int j=1;j <= x;j++){
            if(i==1||j==1)  a[i][j]=1;
            else
                a[i][j]=a[i][j-1] + a[i-1][j];
        }
    }
}
int main(){
    int n;
    init(10);
    while(~scanf("%d",&n)){
        printf("%d\n",a[n][n]);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
inline void fri(int *x)
{
register int c = getchar_unlocked();
*x = 0;
int neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());
if(c=='-')
{
  neg = 1;
  c = getchar_unlocked();
}
for(; c>47 && c<58 ; c = getchar_unlocked())
{
  *x = ((*x)<<1) + ((*x)<<3) + c - 48;
}
if(neg)
  *x = -(*x);
}

int main()
{
    int n, numer = 1, denom = 1, i, j;
    long int ans;
    fri(&n);
    n = n - 1;
    j = 2 * n - 1;
    for(i = 1;i <= j;i += 2)
        numer *= i;
    for(i = 1;i <= n;i++)
        denom *= i;
    ans = (pow(2, n) * numer) / denom;
    printf("%ld", ans);
}


#include<stdio.h>
int calculating_a(int row,int column){
    if(row==0||column=0) return 1;
    else return calculating_a(row-1,column)+calculating(row,column-1);
}
int main(){
    int n;
    scanf("%d\n",&n);
    int max;
    max= calculating_a(n,n);
    printf("%d\n",max);
    return 0;
}


#include <stdio.h>

int main(void){
	int n;
	scanf("%d",&n);
	int a[n][n]={0};
	int max=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==0||j==0)
				a[i][j]=1;
			else
				{
					a[i][j]=a[i-1][j]+a[i][j-1];
                          if(a[i][j]>=max)
                          max=a[i][j];

                }
		}
	}
printf("%d",max);

}


#include<stdio.h>
#inlcude<math.h>
int main()
{
    long i,m,n,s=1,y;
    scanf("%li",&n);
    scanf("%li",&m);
    s=pow(2,n);
    y=m%s;
    printf("%li",y);
    return 0;
}


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

int main(){

int n,l,a,r;

    scanf("%d",&n);
    scanf("%d",&l);

    a=(pow(2,n));
    r=m%a;
    printf("%d\n",r);
return 0;
}


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

int main()
{
    unsigned long int n,m;
    scanf("%uld\n%uld",&n,&m);
    if(n>m || pow(2,n)>m)
    printf("\n%uld",m);
    else
    {
        printf("\n%uld",m%(pow(2,n)));
    }

    return 0;
}


#include<stdio.h>
#include<math.h>
void main()
{
   long double int n,m;
scanf("%lf",&n);
scanf("%lf",&m);
long double x=m%(pow(2,n));
printf("%lf",x);
}


#include<stdio.h>

int main(){
  int done=1;two=1,n,m;
  scanf("%d",&n);
  scanf("%d",&m);
  while(n--){
    two=two<<1;
    if(two>100000000){
      printf("%d",m);
      done=0;
      break;
    }
  }
  if(done)
    printf("%d",m%two);
  return 0;
}


/*
#include<stdio.h>

int main(){
    long long n;
    while(scanf("%lld", &n)){
        if(n < 0)
            return 0;

        /**
         * Arithmetic series 1 to n with extra 1

        printf("%lld\n", 1 + n * (n + 1) / 2);
    }
    return 0;
}*/
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdio>
#include<algorithm>
#include<fstream>
using namespace std;
int main()
{
    int arr[10],i,j,a;
    //cin>>a;
    while(!(cin>>a).eof()){
    for(i=0;i<a;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+5);
    for(i=0;i<a;i++)
    {
        cout<<arr[i]<<" "<<endl;
    }}
    return 0;
}


#include<stdio.h>
int main(){
    for(scanf("%d",&n);i<n;i++){
        scanf("%d",&x),C[x]++;
    }for(i=0;i<101;i++)
    while(C[i]--)
    printf("%d",i);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{

    int x;
    cin>>x;
    int arr[x];
    for(int i = 0;i<x;i++)cin>>arr[i];
    sort(arr,arr+x);
    for(int i = 0;i<x;i++)cout<<arr[i]<<" ";
    return 0;
}


#include <stdio.h>
#include "aplog.h"

#define		N	50
#define		HE	0
#define		NHE	-1
int read_two_numbers(int *num1, int *num2);
int read_arr_of_char_codes(int *arr, int len);
int input_check(char c);
int build_rocket(int numOfDetailsWeNeed, int *storage, int numOfDetails);
void sort(int *arr, int len);
void change(int *a, int *b);

int main()
{
	int numOfDetails, numOfDetailsWeNeed;
	int storage[N] = {0};
	int rc = read_two_numbers(&numOfDetails, &numOfDetailsWeNeed);

	if (!rc)
		rc = read_arr_of_char_codes(storage, numOfDetails);
	if (!rc)
		printf("%d\n", build_rocket(numOfDetailsWeNeed, storage, numOfDetails));
	return rc;
}

int read_two_numbers(int *num1, int *num2)
{
	if (scanf("%d%d", num1, num2) != 2)
		return NHE;
	return HE;
}

int read_arr_of_char_codes(int *arr, int len)
{
	char c;

	for (int i = 0; i < len; i++)
	{
		if (!(scanf("%c", &c) && !input_check(c)))
		{
			i--;
			continue;
		}

		*(arr + i) = (int)c - (int)'a' + 1;
	}

	return HE;
}

int input_check(char c)
{
	if ('a' <= c && c <= 'z')
		return HE;

	return NHE;
}

int build_rocket(int numOfDetailsWeNeed, int *storage, int numOfDetails)
{
	sort(storage, numOfDetails);

	int resultMass = storage[0];
	int weightOfLastStage = storage[0];
	numOfDetailsWeNeed--;

	for (int i = 1; i < numOfDetails && numOfDetailsWeNeed; i++)
		if (storage[i] - weightOfLastStage > 1)
			{
				numOfDetailsWeNeed--;
				resultMass += weightOfLastStage = storage[i];
			}

	if (!numOfDetailsWeNeed)
		return resultMass;

	return NHE;
}

void sort(int *arr, int len)
{
	for (int flag = 1; flag;)
	{
		flag = 0;

		for (int j = 1; j < len; j++)
			if (arr[j] < arr[j - 1])
			{
				flag = 1;
				change(arr + j, arr + j - 1);
			}
	}

}

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


//

#include <stdio.h>

#include <string.h>

int main()

{

    int n , k ;

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

    char lotus[100] , eater[100] ;

    scanf("%s",lotus) ;  //  char paie = getchar() ;

    char swap ;

    for( int a =  0 ; a < (n-1) ; a++ )  {

        for( int b = a+1 ; b < n ; b++ )  {

            if( lotus[a] > lotus[b] )  {

                swap = lotus[b] ;

                lotus[b] = lotus[a] ;

                lotus[a] = swap ;

            }

        }

    }
    /*
    //puts(lotus) ;

    strcpy(eater,lotus) ;

  //  puts(eater) ;

    int d ;

    n = strlen(eater) ;

    for( int c = 0 ; c < (n-1) ; c++ )  {

            int x = (eater[c+1] - eater[c] ) ;

            if( x == 1 )  {

                for( d = c+1 ; d < n ; d++ )  {

                    eater[d] = eater[d+1] ;

                }

            }

        n-- ;

    }
    puts(eater) ;  */
    /*int sum = lotus[0] - 96  ;
    for( int e = 0 ; e<k ; e++ )  {

        if( ( lotus[e+1] - lotus[e] ) > 1 )  {

            sum = sum + lotus[e+1] - 96 ;

        }

    }
    if(sum==1 && sum<k)  printf("-1\n") ;

    else
    printf("%d\n",sum) ;*/

    char x = ara[0] ;            // na parle za hoy arki

    int sum = x - 96 ;

    int count = 1 ;

    if(count==k) {

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

        return 0 ;

    }

    for( int i = 0 ; i < n ; i++ )  {

        if( lotus[i] - x >= 2 )  {

            sum = sum + lotus[i] - 96 ;

            count++ ;

            x = lotus[i] ;

            if(count==k)

                            {  break ;  }

        }

    }

    if( count > k )  {

        printf("-1\n") ;

    }

    else  {

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

    }

    return 0 ;

    return 0 ;

}


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

int main()
{
    long long n,m,i,j=0,k=0,t,a=0,b,c,ck=0,dk=1;
    char str[1000];
    scanf("%lld %lld",&n,&k);

    for(i =0;i < n; i++)
    {
        scanf("%s",&str[i]);
    }

        a = arr[0] - 'a';
        ck+=a+1;
        for(i=1; i<n; i++){
            b = arr[i] - 'a';
            if(abs(a-b)>1 && m>1){
                ck+=(b+1);
                j++;
                dk++;
                a = arr[i] - 'a';
                if(j==m-1)
                    break;
            }
            else{
                continue;
            }
        }

    if(dk<m)
        printf("-1\n");
    else
        printf("%lld",ck);

}