#include<stdio.h>
int main()
{
	char s[30];
	int k,i,j;
	scanf("%s %d",s,&k);
	for(i=0;s[i+1]&&k>0;i++)
	{
		int max=-1,pos;
		for(j=i;j<=i+k && s[j];j++)
		{
			if(s[j]-'0'>max)
			{
				max=s[j]-'0';
				pos=j;
			}
		}
		for(j=pos;j>i;j--)
		{
			char temp=s[j];
				s[j]=s[j-1];
				s[j-1]=temp;
		}
		k=k-(pos-i);
	}
	printf("%s",s);
	return(0);
}

#include <stdio.h>

int main(void) {
    // your code goes here
    int k,i=0,j,mx,pos;
    char a[25];
    scanf("%s%d",a,&k);
    int len=strlen(a);
    while(k>0){
        mx=a[i];
        pos=i;
        for(j=i+1;j<len && j-i<=k;j++){
            if(a[j]>mx){
                mx=a[j];
                pos=j;
            }
        }
        if(mx>a[i]){
            k=k-(pos-i);
            while(pos>i){
                a[pos]=a[pos-1];
                pos--;
            }
            a[i]=mx;
        }
        else
            i++;
//      printf("%s i=%d k=%d\n",a,i,k);
        if(i==len) break;
    }

    printf("%s\n",a);
    return 0;
}

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

int a[30];

int MIN(int x, int y){
	if (x<y) return x;
	return y;
}

int main(void){
	int i, j, n, m, big, tt, ttt;
	char t[30];

	scanf("%s %d", &t, &m);
	n = strlen(t);
	for (i = 1; i <= n; i++){
		a[i] = t[i - 1] - '0';
	}

	for (i = 1; i <= n; i++){
		big = a[i];
		tt = i;
		for (j = i + 1; j <= MIN(i + m, n); j++){
			if (big<a[j]){
				big = a[j];
				tt = j;
			}
		}
		m -= (tt - i);
		for (j = tt - 1; j >= i; j--){
			ttt = a[j];
			a[j] = a[j + 1];
			a[j + 1] = ttt;
		}
	}

	for (i = 1; i <= n; i++){
		printf("%d", a[i]);
	}

	return 0;
}

#include <stdio.h>

int main()
{
    int i, j;
    int index;
    int k;
    char tmpchar;
    char a[21];
    scanf("%s%d", a, &k);
    for ( i = 0; a[i] != '\0'; i++ )
    {
        index = i;
        for ( j = 0; j <= k && a[i+j] != '\0'; j++ )
            if ( a[i+j] > a[index] )
                index = i+j;
        k -= index-i;
        tmpchar = a[index];
        for ( j = index; j > i; j-- )
            a[j] = a[j-1];
        a[i] = tmpchar;
    }
    printf("%s\n", a);
    return 0;
}

#include<stdio.h>
int main()
{
    char a[20];
    scanf("%s",a);
    int l=strlen(a);
    int k,i;
    scanf("%d",&k);
    i=0;
    while(k && i!=l)
    {
        int j,ch=i;
        char max=a[i];
        int x=(k+i+1)<l?(k+i+1):l;
        for(j=i;j<x;++j)
        {
            if(max<a[j])
            {
                max=a[j];
                ch=j;
            }
        }
        if(ch!=i)
        {
           // printf("%d %d",i,ch);
            int y;
            char t=a[ch];
            for(y=ch;y>i;--y)
            {
                char t1=a[y];
                a[y]=a[y-1];
                a[y-1]=t1;
            }
            a[i]=t;
            k=k-(ch-i);
        }
        ++i;
    }
    printf("%s",a);
    return 0;
}

#include <stdio.h>

int a[20],i,j,k,top,tmp,x,z,flag,maxi;
long long n;

int main()
{
	scanf("%I64d%d",&n,&k);
	top=0;
	while (n>0)
	{
		top++;
		a[top]=n%10;
		n/=10;
	}
	while (k>0)
	{
		flag=0;
	    for (j=top; j>1; j--)
	    {
	    	maxi=j;
	    	for (x=1; x<=k; x++)
	    		if (j-x>0 && a[maxi]<a[j-x]) maxi=j-x;
	    	if (maxi<j)
	    	{
	    		tmp=a[maxi];
	    		for (z=maxi; z<j; z++) a[z]=a[z+1];
	    		a[j]=tmp;
	    		k-=j-maxi;
	    		flag=1;
	    		break;
	    	}
	    }
	    if (flag==0) break;
	}
	for (i=top; i>1; i--) printf("%d",a[i]);
	printf("%d\n",a[1]);
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char num[10000];
    int n,m,i,j,k,len,max,t;
    while(scanf("%s%d",num,&n)!=-1)
    {
        len=strlen(num);
        while(n)
        {
            for(j=0;j<len;j++)
            {
                max=0;
                for(k=j+1;k<j+1+n;k++)
                {
                    if(num[k]-'0'>max)
                    {
                        m=k;
                        max=num[k]-'0';
                    }
                }
                if(max>(num[j]-'0'))
                {
                    for(i=m;i>j;i--)
                    {
                    t=num[i];
                    num[i]=num[i-1];
                    num[i-1]=t;
                    }
                    n=n-(m-j);
                    if(n<=0)
                        break;

                }
            }
            if(j==len)
                break;
            if(n<=0)
                break;
        }
        printf("%s\n",num);
    }
    return 0;
}

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

int main()
{
    int j,max,idx,n,k,i;
    char a[100],temp;
    scanf("%s%d",a,&k);
    n=strlen(a);
    for(i=0;i<n-1;i++)
    {
        idx=i;
        max=a[i];
        for(j=i+1;j<=i+k && j<n;j++)
            if(a[j]>max)
            {
                idx=j;
                max=a[j];
            }
        if(idx!=i)
        {
            k=k-idx+i;
            if(k<0)
                break;
            temp=a[idx];
            for(j=idx;j>i;j--)
                a[j]=a[j-1];
            a[i]=temp;
        }
    }
    printf("%s\n",a);
    return 0;
}

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

int main() {
	char tmp, max;
	int i, j, imax, l, k;
	static char a[20];

	scanf("%s", a);
	scanf("%d", &k);
	l = strlen(a);
	for (i = 0; i < l; i++) {
		if (k == 0)
			break;
		max = 0;
		for (j = i + 1; j <= i + k && j < l; j++)
			if (max < a[j]) {
				imax = j;
				max = a[j];
			}
		if (a[i] < max)
			for (j = imax; j >= i + 1; j--) {
				if (k == 0)
					break;
				tmp = a[j], a[j] = a[j - 1], a[j - 1] = tmp;
				k--;
			}
	}
	printf("%s\n", a);
	return 0;
}

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

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define swap(x, y) (x ^= y, y ^= x, x ^= y)

int n, k, ar[100];
char str[1010], A[1010], B[1010];

int main(){
    int i, j, l, counter;

    while (scanf("%s %d", str, &k) != EOF){
        counter = 0, n = strlen(str);
        for (i = 0; i < n; i++){
            clr(ar);
            for (j = i + 1; j < n; j++){
                int x = str[j] - 48;
                if (!ar[x]) ar[x] = j;
            }

            int x = str[i] - 48;
            for (j = 9; j > x; j--){
                if (ar[j]){
                    int dif = (ar[j] - i);
                    if ((counter + dif) <= k){
                        counter += dif;
                        strcpy(A, str);
                        strcpy(B, str);
                        for (l = i; l < ar[j]; l++) swap(A[l], A[l + 1]);
                        for (l = ar[j]; l > i; l--) swap(B[l], B[l - 1]);
                        long long int x = atoll(A);
                        long long int y = atoll(B);
                        if (x > y) strcpy(str, A);
                        else strcpy(str, B);
                        break;
                    }
                }
            }
        }
        puts(str);
    }
    return 0;
}

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

long long A;
int len, k;
char s[20];

int main()
{
    int temp, p = 0, i;
    scanf("%lld%d", &A, &k);
    sprintf(s, "%lld", A);
    len = strlen(s);
    for(i = 0; i < len; i++)
        s[i] -= 48;
    for(; k > 0 && p < len; )
    {
        temp = p;
        for(i = 0; i <= k && p + i < len; i++)
        if(s[temp] < s[p + i])
            temp = p + i;
        if(temp != p)
        {
            int n = s[temp];
            for(i = temp; i > p; i--)
            {
                s[i] = s[i - 1];
            }
            s[p] = n;
            k -= temp - p;
        }
        p++;
    }
    A = 0;
    for(i = 0; i < len; i++)
        A = A * 10 + s[i];
    printf("%lld", A);
}

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

int main()
{
    char str[20]= {'\0'};
    int k;
    scanf("%s %d",str,&k);
    int i,j;
    for(i=0; i<strlen(str) && k>0; i++)
    {
        int index = i;
        int flag = 0;
        for(j=i; j<=k+i && str[j]!='\0'; j++)
        {

            if(str[j]>str[index])
            {

                index = j;
                flag = 1;
            }
        }
        if(flag)
        {
            int x;
            k-=(index-i);
            char temp = str[index];
            for(x=index; x>i; x--)
            {
                str[x] = str[x-1];
            }
            str[i] = temp;
        }

    }
    puts(str);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min2(x,y) (x<y?x:y)

int p[30];

void f(int num, int len)
{
    int i, k = 1, sum = p[1];

    if (len == 1)
    {
        printf("%d", p[1]);
        return;
    }

    for (i = 1; i <= min2(num + 1, len); i++)
    {
        if (sum < p[i]) sum = p[i], k = i;
    }
    for (i = k; i <= len - 1; i++) p[i] = p[i + 1];
    printf("%d", sum);
    f(num - k + 1, len - 1);
}
int main()
{
    int i, n, m;
    char in[30];

    scanf("%s %d", &in[1], &m);
    n = strlen(&in[1]);
    for (i = 1; i <= n; i++) p[i] = in[i] - '0';

    f(m, n);

    return 0;
}

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

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

int main(){
        long long tmp; int k , a[22] , n = 0, i;
        scanf( "%I64d%d" , &tmp , &k );
        while ( tmp > 0 ) {
                a[++n] = tmp % 10;
                tmp /= 10;
        }
        for( i = n; i > 0; i -- ) {
                int j , w = a[i] , pos = i;
                for( j = i; j >= max( 1 , i - k ); j -- )
                if ( a[j] > w ) {
                        w = a[j]; pos = j;
                }
                for( j = pos; j <= i - 1; j ++ ) a[j] = a[j + 1];
                a[i] = w; k -= ( i - pos );
                if ( k <= 0 ) break;
        }
        for( i = n; i > 0; i -- ) printf( "%d" , a[i] );
        return 0;
}

#include<stdio.h>
#include<string.h>
char a[32];
int l,b[32],st,m,swp;
int swap(int x,int y)
{
char ch;
int i;
if(y>x)
{
    ch=a[y];
    for(i=y;i>x;i--)
    {
        a[i]=a[i-1];
    }
    a[i]=ch;
}
return 0;
}
main()
{
int i,j,k;
scanf("%s %d",a,&k);
swp=k;
l=strlen(a);
st=0;
while(st<l-1)
{
    m=a[st];
    j=0;
    for(i=st+1;i<l;i++)
    {
        if(a[i]>m)
        {
            m=a[i];
            b[j]=i;
            j++;
        }
    }
    for(i=j-1;i>=0;i--)
    {
        if(swp>=b[i]-st)
        {
            swap(st,b[i]);
            swp=swp-(b[i]-st);
            break;
        }
    }
    st++;
}
for(i=0;i<l;i++)
{
printf("%c",a[i]);
}
return 0;
}

#include <stdio.h>

int main(void) {
	char number[20];
	int k;
	scanf("%s%d",number,&k);
	while(k>0) {
		int i;
		for(i=0;number[i]!='\0';i++) {
			char max=number[i];
			int maxpos=0;
			int j;
			for(j=1;j<=k && number[i+j]!='\0';j++) {
				if(number[i+j]>max) {
					max=number[i+j];
					maxpos=j;
				}
			}
			if(maxpos>0) {
				char temp=number[i+maxpos];
				for(j=maxpos;j>0;j--)number[i+j]=number[i+j-1];
				number[i]=temp;
				k-=maxpos;
				break;
			}
		}
		if(number[i]=='\0')break;
	}
	puts(number);
	return 0;
}

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

int main(void) {
    int i, j;
    char a[20];
    int k, len;

    scanf("%s %d", a, &k);
    len = strlen(a);

    for (i = 0; i < len; i++) {
        int max, maxIdx;

        max = 0;
        for (j = i + 1; j < len && j - i <= k; j++)
            if (max < a[j] - '0') {
                max = a[j] - '0';
                maxIdx = j;
            }

        if (a[i] - '0' < max) {
            for (j = maxIdx; j > i; j--)
                a[j] = a[j - 1];
            a[i] = max + '0';

            k -= maxIdx - i;
        }
    }

    printf("%s\n", a);

    return 0;
}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0,p;
scanf("%s %I64d",s,&k);
p=k;
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+1;m<i+p+1 && m<strlen(s);m++)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;
p--;
ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int k,i,j,f,t,len;
    char a[20],c;
    scanf("%s %d",a,&k);
    len=strlen(a);
        for(i=0;i<len-1&&k>0;i++)
        {
            c=a[i];
            t=-1;
            for(j=i+1;j<len&&j-i<=k;j++)
            {
                if(a[j]>c)
                {
                    c=a[j];
                    t=j;
                }
            }
            if(t>=0)
            {
                for(f=t;f>i;f--)
                    a[f]=a[f-1];
                a[i]=c;
                k=k-t+i;
            }
        }
    printf("%s\n",a);
    return 0;
}

/* بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ */
/* رَّبِّ زِدْنِى عِلْمًا */

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

void swap(int i);
int check(int i);

char inp[200];
int k,n,fixed;

int main()
{
    int i,j;

    while(scanf("%s%d",inp,&k)!=EOF)
    {
        n=strlen(inp);

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

            if(k==0)
                break;
            j=check(i);
            //printf("%d\n",j);

            if(j!=i)
            {
                swap(j);
             //   printf("%s\t%d\n",inp,fixed);
                k-=j-i;
            }
        }

        printf("%s\n",inp);
    }

    return 0;

}

int check(int i)
{
    int max=inp[i];
    int j;
    int ans=i;

    for(j=1;j<=k;j++)
    {
        if(j+i>=n)
            break;

        if(max<inp[j+i])
        {
            max=inp[i+j];
            ans=i+j;
        }
    }
    return ans;
}

void swap(int i)
{
    int j,p;

    //if(i<=k)
      //  j=fixed;

    //else
        //j=i-k;

    for(p=i;p>fixed;p--)
    {
        inp[p]=inp[p]^inp[p-1];
        inp[p-1]=inp[p]^inp[p-1];
        inp[p]=inp[p]^inp[p-1];
    }
}

#include<stdio.h>
#include<string.h>
void swap(int a,int b)
{
    int t=a;
    a=b;
    b=t;
}
int main()
{
    char str[20],arr[20],barr[20],index[20];
    int i,j,k,l,t;
    scanf("%s",str);
    int n=strlen(str);
    for(i=0;i<n;i++)
     barr[i]=arr[i]=str[i]-'0';
    for(i=0;i<n;i++)
      index[i]=i;
    for(i=0;i<n;i++)
    {
        for(j=n-1;j>0;j--)
        if(arr[j-1]<arr[j])
         {
             t=arr[j-1];
             arr[j-1]=arr[j];
             arr[j]=t;
             t=index[j-1];
             index[j-1]=index[j];
             index[j]=t;
         }
    }
    //for(i=0;i<n;i++)
  //printf("%d  ",index[i]);
    scanf("%d",&k);
     j=0;i=0;
    while(k>0 && j<n)
    {

      while(index[i]!=j)
      {
          if(index[i]-j<=k && index[i]>j)
            {
                for(l=0;l<n;l++)
                  if(index[l]<index[i] && index[l]>=j)
                       index[l]++;
                k-=(index[i]-j);
                index[i]=j;
                break;
            }

            else
              i++;

      }
      j++;
      i=0;

}
//for(i=0;i<n;i++)
  //printf(" %d",index[i]);
for(i=0;i<n;i++)
{
    for(j=1;j<n;j++)
    {
        if(index[j-1]>index[j])
        {
            t=arr[j-1];
             arr[j-1]=arr[j];
             arr[j]=t;
             t=index[j-1];
             index[j-1]=index[j];
             index[j]=t;
        }
    }
}
for(i=0;i<n;i++)
  printf("%d",arr[index[i]]);
return 0;
}

#include <stdio.h>
#include<string.h>
void swap(char a[],int i,int j)
{
	int x;
	char b=a[j];
	for(x=j;x>i;x--)
		a[x]=a[x-1];
	a[i]=b;
}
int main(void)
{
	char a[20]={0};
	int k,i,j,r;
	char c;
	scanf("%s %d",a,&k);
	for(i=0;i<strlen(a)&&k;i++)
	{
		c=a[i];
		r=i;
		for(j=i+1;j<strlen(a);j++)
			if(c<a[j]&&j-i<=k)
			r=j,c=a[j];
		if(r!=i)
		{
			swap(a,i,r);
			k-=r-i;
		}
	}
	puts(a);
    return 0;
}

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

#define dnum 100001
#define LL long long

LL a;
char str[19];

int main()
{
    int n,m,i,j,k,max,start = 0,t;

    scanf("%s %d",str,&k);

    i = 0;
    n = k;
    start = 0;
    while(1)
    {
        j = 0;
        max = -1;
        m = 0;
        for(i = start; i < start+n+1 && i < strlen(str); ++i)
        {
            if(max < str[i])
            {
                max = str[i];
                j = i;
                m = i-start;
            }
        }
        n = n - m;

        for(i = j-1; i >= start; --i)
        {
            m = str[i+1];
            str[i+1] = str[i];
            str[i] = m;
        }
        start++;
        if(start == strlen(str))break;
        if(n == 0)break;
    }

    printf("%s\n",str);

    return 0;
}

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

int main(void) {
    int k, i,j,l, digit[10][20], cnt[10], temp, swap = 0;
    memset(cnt, 0, sizeof(cnt));
    memset(digit, -1, sizeof(digit));
    char num[20], ch;
    scanf("%s %d", &num, &k);
    int len = strlen(num);
    for(i=0;i<len;i++){
        temp = num[i] - '0';
        digit[temp][cnt[temp]] = i;
        cnt[temp]++;
    }
    for(i=9;i>-1;i--){
        for(j=0;j<cnt[i];j++){
            int min = digit[i][j];
            int index = j;
            for(l=j+1; l<cnt[i]; l++){
                if(min < digit[i][l]){
                    min = digit[i][l];
                    index = l;
                }
            }
            int x = digit[i][j];
            digit[i][j] = digit[i][index];
            digit[i][index] = x;
        }
    }
    //printf("%d %d %d\n", digit[3][0], digit[3][1], digit[3][2] );
    for(i=0;i<len-1 && k>0;i++){
        for(j=9;j>-1;j--){
            //printf("CNT %d\n", cnt[j]);
            if(cnt[j]>0){
                //printf("%d\n", digit[j][cnt[j]-1]);
                if((digit[j][cnt[j]-1] - i) <= k){
                    int m, pos = digit[j][cnt[j]-1];
                    if(pos > i){
                        for(l=pos;l>i;l--){
                            ch = num[l-1];
                            temp = ch - '0';
                            for(m=0;m<cnt[temp];m++){
                                if(digit[temp][m] == l-1)
                                    digit[temp][m]++;
                            }
                            num[l-1] = num[l];
                            num[l] = ch;
                            //printf("CHECK %s", num);
                        }
                        k = k - (pos - i);
                        //printf("K=%d\n", k);
                        //printf("K=%s\n", num);
                    }
                    cnt[j]--;
                    break;
                }
            }
        }
    }
    printf("%s", num);
    return 0;
}

#include <stdio.h>

int main(void) {
    int k,n,i=0,count,max,current=1,index,p,temp;
    int number[18],number1[18];
    long long int a,c;
    scanf("%lld %d",&a,&k);
    c=a;
    while(c>0)
    {
        number1[i]=c%10;
        c=c/10;
        i++;
    }
    count=i;
    for(i=0;i<count;i++)
    {
        number[i]=number1[count-i-1];
    }
    while(k!=0 && current!=count)
    {
        p=0;
        max=-1;
        for(i=current;i<count && p<k;i++)
        {
            if(number[i]>max)
            {
                index=i;
                max=number[i];
            }
            p++;
        }
        if(max>number[current-1])
        {
            while(index!=current-1)
            {
                temp=number[index];
                number[index]=number[index-1];
                number[index-1]=temp;
                index--;
                k--;
            }
        }
        current++;
    }
    for(i=0;i<count;i++)
        printf("%d",number[i]);
    return 0;
}

#include<stdio.h>
#include<string.h>
void swap(char *s, int i, int j) {
	char temp = s[i];
	s[i] = s[j];
	s[j] = temp;
}
int main() {
	int k, i, l, p, j, pos = 0;
	char s[20], max;
	scanf("%s%d", s, &k);
	l = strlen(s);
	for(i = 0; i < l-1; ++i) {
		pos = i;
		p = k;
		max = '0';
		for(j = i; p >= 0 && j < l; --p, ++j) {
			if(s[j] > max) {
				max = s[j];
				pos = j;
			}
		}
		k -= pos - i;
		for(j = pos; j > i; --j)
			swap(s, j, j-1);
	}
	puts(s);
	return 0;
}

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

int main() {
    char a[20], maior;
    int k,i,indiceMaior,aux,indiceAux=0,asize;
    scanf("%s %d",a,&k);

    asize = strlen(a);
    while (indiceAux < asize) {
        maior=a[indiceAux],indiceMaior=indiceAux;
        int aux2 = indiceAux + k + 1;

        for (i=indiceAux+1; i < aux2 && a[i] != '\0'; i++) {
            if (a[i] > maior) {
                maior = a[i];
                indiceMaior = i;
            }
        }

        for (i=indiceMaior; i >indiceAux; i--) {
            a[i] = a[i-1];
        }

        k = k - (indiceMaior - indiceAux);
        indiceAux++;
        printf("%c",maior);
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int m,k,count,l,i,j,temp;
    char ar[45],ch,temp1,max;
scanf("%s%c%d",&ar,&ch,&m);
l=strlen(ar);

k=m;
for(i=0;i<l-1;i++)
{
    if(m>0)
    {
    j=i+1;
    temp=i;
    k=m;
    max=ar[i];
while(k>0 &&j<=l-1)
{
    if(max<ar[j])
    {
        temp=j;
        max=ar[j];
    }
    k--;
    j++;
}
    if(temp!=i)
    {
        temp1=ar[temp];
        for(j=temp;j>i;j--)
        ar[j]=ar[j-1];
        ar[i]=temp1;
    }
    m=m-(temp-i);
    }
    else
    break;
}
printf("%s\n",ar);
return 0;
}

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

int main(){
    int n, i, j, k, l, c, index;
    char ss[19], max;
    scanf("%s %d", ss, &n);
    l = strlen(ss);
    c = 0;
    for(i=0; i<l; i++){
        c = 0;
        max = ss[i];
        index = i;
        for(j=i+1; j<l && c<n; j++, c++){
            if(ss[j] > max){
                max = ss[j];
                index = j;
            }
        }

        if(index != i){
            for(k=index;k>i;k--){
                ss[k] = ss[k-1];
            }
            ss[i] = max;
            n -= (index - i);
        }
    }

    printf("%s\n",ss);
    return 0;
}

#include <stdio.h>

int main(){
    long long int a, p;
    int k, b=1, i, j=0, replace, bigger, where, x;
    scanf("%I64d %i", &a, &k);
    p=a;
    while(p/10>0){
        b++;
        p=p/10;
    }
    int order[b];
    p=a;
    for(i=b-1; i>=0; i--){
        order[i]=p%10;
        p=p/10;
    }
    while(k>0 && j!=b-1){
        bigger=0;
        for(i=b-1; i>=j; i--){
            if(i-j<=k){
                if(bigger<=order[i]){
                    bigger=order[i];
                    where=i;
            }
            }
        }
        //printf("%i %i\n", where, order[where]); system("PAUSE");
        //printf("%i %i", where-j, k); system("PAUSE");
        if(where-j<=k){
            for(x=where; x>j; x--){
                replace=order[x];
                order[x]=order[x-1];
                order[x-1]=replace;
                k--;
            }
        }
        j++;
    }
    for(i=0; i<b; i++){
        printf("%i", order[i]);
    }
}

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

int k;
char a[19];
int st;
int count;
int max;
int tmp;

int main(){

	int i;

	scanf("%s",a);
	scanf("%d",&k);

	for(i=0;i<strlen(a);i++){
		if(a[i]!='9')
			break;
		else
			st++;
	}

	while(k&&(st<strlen(a))){
		for(i=0;i<k&&(st+1+i<strlen(a));i++){
			if(a[st]<a[st+1+i])
				if(a[st+1+i]>max){
					max=a[st+1+i];
					count = i+1;
				}
		}

		if(max!=0){
			for(i=0;i<count;i++){
				tmp=a[st+count-i];
				a[st+count-i]=a[st+count-1-i];
				a[st+count-1-i]=tmp;
			}
			k-=count;
		}

		max=0;
		count=0;
		st++;

	}

	printf("%s",a);

	return 0;

}

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

char a[100], max;

int k, n, start, i, j, place, t, count;

int main () {
	scanf("%s %d",a ,&k);
	while(k > 0){
		max = 0;
		for(i = start ; i <= k + start ; i++)
			if(a[i] > max){
				max = a[i];
				place = i;
			}
		if(place == start){
			start++;
			continue;
		}
		count = 0;
		for(i = place ; i > start ; i--){
			t = a[i-1];
			a[i-1] = a[i];
			a[i] = t;
			count++;
		}
		k -= count;
		start++;
		//printf("%d %d %s %d %d\n",start,place,a,max,k);
	}
	printf("%s",a);
	return 0;
}

#include<stdio.h>
#include<string.h>
void swap(int* x,int* y) {
	int tmp = *x;
	*x  = *y;
	*y = tmp;
	return ;
}
int main() {
	int z,i,j,k,l,n,m,max,rem,c[1000],tmp;
	long long int p;
	scanf("%lld",&p);
	scanf("%d",&k);
	i = 0;
	while(p != 0) {
		c[i] = p%10;
		p = p/10;
		i++;
	}
	z = i;
	for(j=0;j<i/2;j++)
		swap(&c[j],&c[i-j-1]);
	for(i=0;i<z;i++) {
		max = 0;
		for(j=i+1;j<z;j++)
			if(c[j] > max && j-i <= k){
				max = c[j];
				rem  = j;
			}
		if(max > c[i])
			for(j=rem-1;j>=i;j--){
				swap(&c[j],&c[j+1]);
				k--;
			}
	}
	for(i=0;i<z;i++)
		printf("%d",c[i]);
	printf("\n");
	return 0;
}

#include<stdio.h>
#include<string.h>
char a[20]; int k;
void aa(int f, int g)
{
    char t; int q, y;
    t = a[g - 1];
    y = g - f;
    while (y--)
    {
        a[g-1] = a[g - 2];
        g--;
    }
    a[f - 1] = t;
}
int bb(int h,int j)
{
    char bell = '0'; int c,d=-1;
    c = h;
    while (j--)
    {
        if (a[h] == '\0')
            break;
        else
        {
            if ((a[h] > a[c - 1]) && a[h] > bell)
            {
                bell =a[h];
                d = h;
                k = j;
            }
            h++;
        }
    }
    return d;
}
int main()
{
    int i, j, p, max,L;
    memset(a, '\0', sizeof(a));
    scanf("%s", a);
    scanf("%d", &k);
    L = strlen(a);
    for (i = 1; i < L; i++)
    {
        p = bb(i, k);
        if (p!=-1)
        aa(i,p+1);
    }
    puts(a);
    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,c,k,n,m,temp,z,pos,diff,max;
	unsigned long long num,x;
	long long int a[20];
	scanf("%lld%d",&num,&k);
	c=0;
	x=num;
	while(num>0)
	{
			num=num/10;
			c++;
	}
	for(i=c-1;i>=0;i--)
	{
			a[i]=x%10;
			x=x/10;

	}
	for(i=0;i<c;i++)
	{
		max=a[i];
		diff=0;
		pos=i;
		for(j=i+1;j<c;j++)
		{
			if(j>i+k)
			{
				break;
			}
			if(max<a[j])
			{
				max=a[j];
				pos=j;
				diff=pos-i;
			}
		}
		for(j=pos;j>i;j--)
		{
			temp=a[j];
			a[j]=a[j-1];
			a[j-1]=temp;
		}
		k=k-diff;
		if(k==0)
		{
			break;
		}
	}
	for(i=0;i<=c-1;i++)
	{
		printf("%d",a[i]);
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long long int a ;int k,i,brr[100],arr[100],j;
	scanf("%I64d %d",&a,&k);
	for(i=0;a>0;i++,a/=10)
	brr[i]=a%10;int l=0;int n=i;
	for(j=n-1;j>=0;j--,l++)
		arr[j]=brr[l];
	int max,maxi;
	for(i=0;i<n && k>0;i++)
	{max=arr[i];maxi=i;
		for(j=i+1;j<=i+k && j<n ;j++)
		{if(arr[j]>max)
			{max=arr[j];maxi=j;}
		}
		if(max!=-1)
		{j=maxi;
			while(j!=i)
			{int temp=arr[j];arr[j]=arr[j-1];arr[j-1]=temp;j--;
			}
		k=k-(maxi-i);}
	}
	for(i=0;i<n;i++)
		printf("%d",arr[i]);
	printf("\n");
	return 0;
}

/* Coached by Dukkha */
#include <stdio.h>
#include <string.h>

#define L 19

int main() {
	static char aa[L + 1];
	int k, n, i;

	scanf("%s%d", aa, &k), n = strlen(aa);
	for (i = 0; i < n && k; i++) {
		int h, j = i;
		char a;

		for (h = i + 1; h <= i + k && h < n; h++)
			if (aa[j] < aa[h])
				j = h;
		if (i < j) {
			k -= j - i;
			a = aa[j];
			while (j > i) {
				aa[j] = aa[j - 1];
				j--;
			}
			aa[i] = a;
		}
	}
	printf("%s\n", aa);
	return 0;
}

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

int main() {
  char s[32];
  int k;
  scanf("%s %d", s, &k);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    int mi = i;
    char mx = s[i];
    int l = i + k + 1 < n ? i + k + 1 : n;
    for (int j = i + 1; j < l; j++) {
      if(s[j] > mx) {
        mx = s[j];
        mi = j;
      }
    }
    if (i == mi) { continue; }
    char t = s[mi];
    for (int j = mi; j > i; j--) {
        s[j] = s[j - 1];
    }
    s[i] = t;
    k -= (mi - i);
  }
end:
  printf("%s\n", s);
  return 0;
}

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

int main()	{

long long int a;
int k,i,j,l;
char s[20];
long long int n;
int upper,max,index,temp;

scanf("%I64d %d",&a,&k);
//scanf("%lld %d",&a,&k);

for(i=18;i>=0 && a!=0;i--)	{
 s[i] = a % 10 + '0';
 a=a/10;
}
upper=i+1;
if(i>=0)	{
	while(i>=0)	{
		s[i]='0';
		i--;
	}
}
/*
for(j=upper;j<19;j++)	{
	printf("%c",s[j]);
}
printf("\n");
*/
for(i=upper;i<19 && k>0;i++)	{

	  max=s[i]-'0';
	  index=i;

	for(j=i+1,l=1;l<=k && j<19;j++,l++)	{

			if(s[j]-'0' > max)	{
				max=s[j]-'0';
			    index=j;
			}
	}

   for(l=index;l>i ;l--)	{
   	 temp=s[l];
   	 s[l]=s[l-1];
   	 s[l-1]=temp;
   }
   k=k-(index-i);

}
//printf("final s\n");
for(j=upper;j<19;j++)	{
	printf("%c",s[j]);
}
printf("\n");

return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char a[500],temp,max;
	int c,n,i,j,k,x,f=1,h=4,m;
	scanf("%s",a);
	scanf("%d",&k);
	c=0;
	n=strlen(a);
	while(c!=n)
	{
		max='0';
		for(j=c;j<k+c+1;j++)
		{
			if(j==n)
			break;
			if(a[j]>max)
			{
				max=a[j];
				x=j;
			}
		}
		for(j=x;j>c;j--)
		{
			/*if(c==x)
			break;*/
			if(k==0)
			{
				f=0;
				break;
			}
			temp=a[j-1];
			a[j-1]=a[j];
			a[j]=temp;
			k--;
		}
		c++;
	//	printf("%d ",k);
		if(f==0)
		break;
	}
	printf("%s",a);
	return 0;
}

#include <stdio.h>
#include<string.h>
int main(void)
{
	char a[30],t;
	int i,k,alen,max,s,flag=0;
	scanf("%s",a);
	scanf("%d",&k);
	alen=strlen(a);
	while(k>0)
	{
		for(i=0;i<alen-1;i++)
		{
				max=i;
				s=1;
				while(s<=k)
				{
					if(((i+s)<alen)&&(a[i+s]>a[i]))
					{
							max=a[max]>=a[i+s]?max:i+s;
					}

					s++;
				}
				if(a[max]>a[i])
				{
					t=a[max];
					k=k-max+i;
					while(max-i>0)
					{
						a[max]=a[max-1];
						max--;
					}
					a[i]=t;
					flag=1;
					break;
				}
		}
		if(flag==0)
			k--;
		flag=0;
	}
	printf("%s",a);
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,a,k,len=0,arr[30];
	char c[20];
	scanf("%s",c);
	len=strlen(c);
	for(i=0;i<len;i++)
	{
		arr[i]=c[i]-'0';
	}
	scanf("%d",&k);
	int max=arr[0],kt=0,start=0,flag=0,rem;
	while(1)
	{
		if(k==0 || start==len)
		{
		//	printf("cameee\n");
			break;
		}
		if(k>len)
		{
			kt=len;
		}
		else
		{
			kt=k;
		}
		for(i=start;i<len && i<=kt+start;i++)
		{
			if(arr[i]>max)
			{
				flag=1;
				max=arr[i];
				rem=i;
			}
		//	printf("s=%d i=%d a=%d f=%d m=%d r=%d\n",start,i,arr[i],flag,max,rem);
		}
		if(flag==1)
		{
			flag=0;
			for(i=rem;i>start;i--)
			{
				int tt;
				tt=arr[i];
				arr[i]=arr[i-1];
				arr[i-1]=tt;
			}
			k=k-(rem-start);
			start++;
			max=arr[start];
		}
		else if (flag==0)
		{
		//	printf("came\n");
			start++;
			max=arr[start];
		}
	}
	for(i=0;i<len;i++)
		printf("%d",arr[i]);
	printf("\n");
	return 0;
}

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

int main(void) {
	char a[50];
	int k;
	int len;
	char temp;
	int max;
	int idx;

	int i, j;

	scanf(" %s %d", a, &k);

	len = strlen(a);

	for (i = 0; i < len && k > 0; i++) {
		max = -1;
		idx = -1;
		for (j = i; j <= i + k && j < len; j++) {
			if (a[j] > max) {
				idx = j;
				max = a[j];
			}
		}

		if (k > 0 && idx != -1) {
			for (j = idx; j > i; j--) {
				k--;
				temp = a[j - 1];
				a[j - 1] = a[j];
				a[j] = temp;
			}
		}
	}

	printf("%s\n", a);

	return 0;
}

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

int num[30];
char str[30];

int main(void) {
	// your code goes here

	int swap,max,i,j,k,t;
	int len;
	scanf("%s",str);
	len=strlen(str);
	for(i=1;i<=len;i++)
	 num[i]=str[i-1]-'0';

	scanf("%d",&swap);

	i=1;
	while(swap>0 && i<=len)
	{
		max=num[i];   j=i;
		for(k=i+1; k<=(i+swap)&&k<=len ;k++)
		{
			if(max<num[k]) { max=num[k];  j=k;  }
		}
		swap=swap-(j-i);   //printf("%d %d %d\n",swap,i,j);
		for(k=j;k>i;k--)
		{
			t=num[k];
			num[k]=num[k-1];
			num[k-1]=t;
		}

		i++;
	}

	for(i=1;i<=len;i++)  printf("%d",num[i]);
	return 0;
}

#include <stdio.h>

int main()
{
    char Str[20];
    int K, i, j, maxid;
    char max;
    scanf("%s %d", Str, &K);
    for(i=0; i<i+K && Str[i]!='\0'; ++i)
    {
        max = Str[i];
        maxid = i;
        for(j=i+1; j<i+1+K && Str[j]!='\0'; ++j)
        {
            if(Str[j] > max)
            {
                max = Str[j];
                maxid = j;
            }
        }
        if(maxid != i)
        {
            K -= maxid - i;
            for(j=maxid; j>i; --j)
            {
                Str[j] = Str[j-1];
            }
            Str[i] = max;
        }
    }
    puts(Str);
    return 0;
}

#include<stdio.h>
#include<string.h>
int main() {
    char a[20];
    int k;
    scanf("%s%d",a,&k);
    //就一个原则，把最大的放在最前面
    //把k步内最大的换到最前面
    int swaps=k;
    int na=strlen(a);
    int start=0;
    while(1){
        int i;
        int max=start;
        if(start==na-1)break;
        for(i=start+1;i<na && i<=start+swaps;i++){
            if(a[i]>a[max]){
                max=i;
            }
        }
        /*
        printf("start=%d, max=%d\n",start,max);
        printf("%s\n",a);
        */
        int tmp=a[max];
        for(i=max;i>start;i--){
            a[i]=a[i-1];
        }
        a[start]=tmp;
        //printf("%s\n",a);
        swaps-=(max-i);
        if(swaps==0)break;
        start++;
    }
    printf("%s\n",a);
	return 0;
}

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

char a[200],c;
int i,j,k,mx,l,pos,z;
scanf("%s",a);
scanf("%d",&k);
z=strlen(a);
for(i=0;i<z;i++)
    {

        mx=a[i]-48;
        pos=i;
        for(j=i+1;j<=i+k&&j<z;j++)
        {
            if(a[j]-48>mx)
            {
            mx=a[j]-48;
            pos=j;
            }
        }
        if(mx>a[i]-48)
        {
            for(l=pos;l>i;l--)
            {
                a[l]=a[l-1];

            }
            a[i]=mx+48;
            k=k-(pos-i);
        }
    }
printf("%s\n",a);

    return 0;
}

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

char a[20],c;
int i,j,k,mx,l,pos;
scanf("%s",a);
scanf("%d",&k);
for(i=0;i<strlen(a);i++){
    if(a[i]!='9'&&k>0){
        mx=a[i]-48;
        pos=i;
        for(j=i+1;j<=i+k&&j<strlen(a);j++){
            if(a[j]-48>mx){
            mx=a[j]-48;
            pos=j;
            }
        }
        if(pos-i<=k){
            for(l=pos;l>i;l--){
                a[l]=a[l-1];

            }
            a[i]=mx+48;
            k=k-(pos-i);
        }
    }
}
printf("%s\n",a);

    return 0;
}

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

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//qsort (arr2, n, sizeof(int), compare);

int main (){
    char arr[100];
    int k,flag=0;
    scanf("%s",arr);
    scanf("%d",&k);
    int i,j;
    int temp;
    for(i=0;i<strlen(arr) && k>0;i++){
        temp=i;
        flag=0;
        for(j=i;j<=i+k && j<strlen(arr) && k>0;j++){
            if(arr[j]>arr[temp]){
                temp=j;
            }
        }
        for(j=temp;j>i && k>0;j--){
            char temp2= arr[j];
            arr[j]=arr[j-1];
            arr[j-1]=temp2;
            flag=1;
            k--;
        }

    }

    printf("%s\n",arr);
    return 0;
}

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

char s[32];
int len;
void swap(int st, int end, int k);

int main(void)
{
	int k;

	scanf("%s%d", s, &k);
	len = strlen(s);
	swap(0, len, k);
	puts(s);

	return 0;
}

void swap(int st, int end, int k)
{
	int i, max;
	char t;

	if (!k || st==end)
		return;
	for (max=i=st; i<end; i++)
		if (s[i] > s[max])
			max = i;
	if (max-st <= k) {
		k -= max-st;
		t = s[max];
		for (i=max; i>st; i--)
			s[i] = s[i-1];
		s[i] = t;
		swap(st+1, len, k);
		return;
	}
	swap(st, max, k);

	return;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char a[50];
	int k;
	scanf("%s%d",a,&k);
	int s=0,i,l=strlen(a);
	int pos=0,max=-1,max_pos=-1;
	while(k>0 && pos<l)
	{
		max=-1;
		max_pos=-1;
		for(i=pos;i<=pos+k && i<l;i++)
		{
			if(a[i]> max)
			{
				max_pos=i;
				max=a[i];
			}
		}
		//printf("%d\n",k);
		for(i=max_pos;i>pos;i--)
		{
			k--;
			char temp;
			temp=a[i];
			a[i]=a[i-1];
			a[i-1]=temp;
		}
		pos++;
	}
	printf("%s\n",a);
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char a[20];
    int k,i,j,len,temp,flag;
    while(scanf("%s%d",a,&k) != EOF)
    {
        len=strlen(a);
        for(i=0;i<len-1;i++)
        {
            flag=i;
            for(j=i+1;j<len&&j<i+k+1;j++)
                if(a[j]>a[flag])
                    flag=j;
            temp=a[flag];
            for(j=flag;j>i;j--)
                a[j]=a[j-1];
            a[i]=temp;
            k-=flag-i;
            if(k==0)
                break;
        }
        printf("%s\n",a);
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
main()
{
      char a[40];
      int k,i,j,l,bar,temp,flag,var,max;
      scanf("%s",a);
      scanf("%d",&k);
      l=strlen(a);
      for(i=0;i<l;i++)
      a[i]=a[i]-'0';
      var=0;temp=0;bar=0;flag=0;
      for(j=0;j<l;j++)
      {
        flag=0;max=0;
        for(i=j+1;i<(l-(j+1)>=k?k+j+1:l);i++)
         {
           //max=a[j+1];
           if(a[i]>a[j])
          {
            if(a[i]>max)
            {
              max=a[i];
              var=i;
              flag=1;
            }
          }
        }

        if(flag)
        {
          temp=a[var];
          for(bar=var-1;bar>=j;bar--)
          a[bar+1]=a[bar];
          a[j]=temp;
          k-=(var-j);
        }
      }
      for(i=0;i<l;i++)
      printf("%d",a[i]);
      printf("\n");
      scanf("%d",&j);
      return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int k,i,j,f,len;
    char a[20],c;
    scanf("%s %d",a,&k);
    len=strlen(a);
        for(i=0;i<len-1&&k>0;i++)
        {
            for(j=i+1;j<len&&j-i<=k;j++)
            {
                if(a[j]>a[i])
                {
                    c=a[j];
                    for(f=j;f>i;f--)
                        a[f]=a[f-1];
                    a[i]=c;
                    k=k-j+i;
                }
            }
        }
    printf("%s\n",a);
    return 0;
}

/* بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ */
/* رَّبِّ زِدْنِى عِلْمًا */

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

void swap(int i);
int check(int i);

char inp[200];
int k,n,fixed;

int main()
{
    int i,j;

    while(scanf("%s%d",inp,&k)!=EOF)
    {
        n=strlen(inp);

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

            if(k==0)
                break;
            j=check(i);

            if(j!=i)
            {
                swap(j);
            //    printf("%s\n",inp);
                k-=j-i;
            }
        }

        printf("%s\n",inp);
    }

    return 0;

}

int check(int i)
{
    int max=inp[i];
    int j;
    int ans=i;

    for(j=1;j<=k;j++)
    {
        if(j+i>=n)
            break;

        if(max<inp[j+i])
        {
            max=inp[i+j];
            ans=i+j;
        }
    }
    return ans;
}

void swap(int i)
{
    int j,p;

    if(i<=k)
        j=fixed;

    else
        j=i-k;

    for(p=i;p>j;p--)
    {
        inp[p]=inp[p]^inp[p-1];
        inp[p-1]=inp[p]^inp[p-1];
        inp[p]=inp[p]^inp[p-1];
    }
    fixed=p+1;
}

/* بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ */
/* رَّبِّ زِدْنِى عِلْمًا */

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

void swap(int i);
int check(int i);

char inp[200];
int k,n,fixed;

int main()
{
    int i,j;

    while(scanf("%s%d",inp,&k)!=EOF)
    {
        n=strlen(inp);
        fixed=0;

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

            if(k==0)
                break;
            j=check(i);

            if(j!=i)
            {
                swap(j);
                k-=j-i;
            }
        }

        printf("%s\n",inp);
    }

    return 0;

}

int check(int i)
{
    int max=inp[i];
    int j;
    int ans=i;

    for(j=1;j<=k;j++)
    {
        if(j+i>=n)
            break;

        if(max<inp[j+i])
        {
            max=inp[i+j];
            ans=i+j;
        }
    }
    return ans;
}

void swap(int i)
{
    int j,p;

    if(i<=k)
        j=fixed;

    else
        j=i-k;

    for(p=i;p>j;p--)
    {
        inp[p]=inp[p]^inp[p-1];
        inp[p-1]=inp[p]^inp[p-1];
        inp[p]=inp[p]^inp[p-1];
    }
    fixed=p+1;
}

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

int main(void) {
	int k, i,j,l, digit[10][20], cnt[10], temp, swap = 0;
	memset(cnt, 0, sizeof(cnt));
	memset(digit, -1, sizeof(digit));
	char num[20], ch;
	scanf("%s %d", &num, &k);
	int len = strlen(num);
	for(i=0;i<len;i++){
		temp = num[i] - '0';
		digit[temp][cnt[temp]] = i;
		cnt[temp]++;
	}
	for(i=9;i>-1;i--){
		for(j=0;j<cnt[i];j++){
			int min = digit[i][j];
			int index = j;
            for(l=j+1; l<cnt[i]; l++){
 				if(min < digit[i][l]){
 					min = digit[i][l];
 					index = l;
 				}
            }
            int x = digit[i][j];
            digit[i][j] = digit[i][index];
            digit[i][index] = x;
        }
	}
	//printf("%d %d %d\n", digit[3][0], digit[3][1], digit[3][2] );
	for(i=0;i<len-1 && k>0;i++){
		for(j=9;j>-1;j--){
		    //printf("CNT %d\n", cnt[j]);
			if(cnt[j]>0){
			    //printf("%d\n", digit[j][cnt[j]-1]);
				if((digit[j][cnt[j]-1] - i) <= k){
					int pos = digit[j][cnt[j]-1];
					if(pos > i){
                        for(l=pos;l>i;l--){
                            ch = num[l];
                            num[l] = num[l-1];
                            num[l-1] = ch;
                            //printf("CHECK %s", num);
                        }
                        k = k - (pos - i);
                       // printf("K=%d\n", k);
					}
					cnt[j]--;
                    break;
				}
			}
		}
	}
	printf("%s", num);
	return 0;
}

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

int main(void) {
int k, i,j,l, digit[10][20], cnt[10], temp, swap = 0;
memset(cnt, 0, sizeof(cnt));
memset(digit, -1, sizeof(digit));
char num[20];
scanf("%s %d", &num, &k);
int len = strlen(num);
for(i=0;i<len;i++){
temp = num[i] - '0';
digit[temp][cnt[temp]] = i;
cnt[temp]++;
}
for(i=9;k>0 && i>-1;i--){
for(j=0;j<cnt[i];j++){
int max = digit[i][j];
int index = j;
for(l=j+1; l<cnt[i]; l++){
if(max < digit[i][l]){
max = digit[i][l];
index = l;
}
}
int x = digit[i][j];
digit[i][j] = digit[i][index];
digit[i][index] = x;
}
for(j=cnt[i]-1;j>-1 && k>0;j--){
if(digit[i][j]<=k){
k = k - digit[i][j];
char c;
c = num[swap];
num[swap] = num[digit[i][j]];
swap++;
num[digit[i][j]] = c;
// printf("%s\n", num);
}
}
}
//printf("%d %d ", digit[0][0], digit[0][1]);
printf("%s", num);
return 0;
}

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

int main(void) {
int k, i,j,l, digit[10][20], cnt[10], temp, swap = 0;
memset(cnt, 0, sizeof(cnt));
memset(digit, -1, sizeof(digit));
char num[20];
scanf("%s %d", &num, &k);
int len = strlen(num);
for(i=0;i<len;i++){
temp = num[i] - '0';
digit[temp][cnt[temp]] = i;
cnt[temp]++;
}
for(i=9;k>0 && i>-1;i--){
for(j=0;j<cnt[i];j++){
int max = digit[i][j];
int index = j;
for(l=j+1; l<cnt[i]; l++){
if(max < digit[i][l]){
max = digit[i][l];
index = l;
}
}
int x = digit[i][j];
digit[i][j] = digit[i][index];
digit[i][index] = x;
}
for(j=cnt[i]-1;j>-1 && k>0;j--){
if(digit[i][j]<=k){
k = k - digit[i][j];
char c;
c = num[swap];
num[swap] = num[digit[i][j]];
swap++;
num[digit[i][j]] = c;
// printf("%s\n", num);
}
}
}
printf("%d %d ", digit[0][0], digit[0][1]);
printf("%s", num);
return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int m,k,count,l,i,j,temp;
    char ar[45],ch,temp1,max;
scanf("%s%c%d",&ar,&ch,&m);
l=strlen(ar);

k=m;
for(i=0;i<l-1;i++)
{
    if(m>0)
    {
    j=i+1;
    temp=i;
    k=m;
    max=ar[i];
while(k>0 &&j<l-1)
{
    if(max<ar[j])
    {
        temp=j;
        max=ar[j];
    }
    k--;
    j++;
}
    if(temp!=i)
    {
        temp1=ar[temp];
        for(j=temp;j>i;j--)
        ar[j]=ar[j-1];
        ar[i]=temp1;
    }
    m=m-(temp-i);
    }
    else
    break;
}
printf("%s\n",ar);
return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int m,k,count,l,i,j,temp;
    char ar[20],ch,temp1,max;
scanf("%s%c%d",&ar,&ch,&m);
l=strlen(ar);

k=m;
for(i=0;i<l-1;i++)
{
    if(m>0)
    {
    j=i+1;
    temp=i;
    k=m;
    max=ar[i];
while(k>0)
{
    if(max<ar[j])
    {
        temp=j;
        max=ar[j];
    }
    k--;
    j++;
}
    if(temp!=i)
    {
        temp1=ar[temp];
        for(j=temp;j>i;j--)
        ar[j]=ar[j-1];
        ar[i]=temp1;
    }
    m=m-(temp-i);
    }
    else
    break;
}
printf("%s\n",ar);
return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int m,k,count,l,i,j,temp;
    char ar[45],ch,temp1,max;
scanf("%s%c%d",&ar,&ch,&m);
l=strlen(ar);

k=m;
for(i=0;i<l-1;i++)
{
    if(m>0)
    {
    j=i+1;
    temp=i;
    k=m;
    max=ar[i];
while(k>0)
{
    if(max<ar[j])
    {
        temp=j;
        max=ar[j];
    }
    k--;
    j++;
}
    if(temp!=i)
    {
        temp1=ar[temp];
        for(j=temp;j>i;j--)
        ar[j]=ar[j-1];
        ar[i]=temp1;
    }
    m=m-(temp-i);
    }
    else
    break;
}
printf("%s\n",ar);
return 0;
}

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

int k, i, j;
char a[1000], t;

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

int main () {
	scanf("%s %d",a ,&k);
	for(j = 1 ; j <= k ; j++){
		for(i = 1 ; i < strlen(a) ; i++){
			if(a[i] > a[i-1]){
				t = a[i-1];
				a[i-1] = a[i];
				a[i] = t;
				break;
			}
		}
	}
	printf("%s",a);
	return 0;
}

#include<stdio.h>
int main()
{
	long long int a ;int k,i,brr[100],arr[100],j;
	scanf("%I64d %d",&a,&k);
	for(i=0;a>0;i++,a/=10)
	brr[i]=a%10;int l=0;int n=i;
	for(j=n-1;j>=0;j--,l++)
		arr[j]=brr[l];
	while(k>0)
	{
		for(i=0;i<n-1;i++)
		{
			if(arr[i]<arr[i+1])
			{int temp=arr[i];arr[i]=arr[i+1];arr[i+1]=temp;k--;break;
			}
		}
	}
	for(i=0;i<n;i++)
		printf("%d",arr[i]);
	printf("\n");
	return 0;
}

#include<stdio.h>
int main()
{
	long long int a ;int k,i,brr[100],arr[100],j;
	scanf("%I64d %d",&a,&k);
	for(i=0;a>0;i++,a/=10)
	brr[i]=a%10;int l=0;int n=i;
	for(j=n-1;j>=0;j--,l++)
		arr[j]=brr[l];
	int max,maxi;
	for(i=0;i<n && k>0;i++)
	{max=arr[i];maxi=i;
		for(j=i+1;j<=i+k && j<n ;j++)
		{if(arr[j]>max)
			{max=arr[j];maxi=j;}
		}
		if(max!=-1)
		{
		int temp=arr[i];arr[i]=arr[maxi];arr[maxi]=temp;k=k-(maxi-i);}
	}
	for(i=0;i<n;i++)
		printf("%d",arr[i]);
	printf("\n");
	return 0;
}

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

int main()	{

long long int a;
int k,i,j,l;
char s[20];
long long int n;
int upper,max,index,temp;

scanf("%I64d %d",&a,&k);
//scanf("%lld %d",&a,&k);

for(i=18;i>=0 && a!=0;i--)	{
 s[i] = a % 10 + '0';
 a=a/10;
}
upper=i+1;
if(i>=0)	{
	while(i>=0)	{
		s[i]='0';
		i--;
	}
}

for(i=upper;i<19 && k>0;i++)	{

	  max=s[i]-'0';
	  index=i;

	for(j=i+1,l=1;l<=k;j++,l++)	{

			if(s[j]-'0' > max)	{
				max=s[j]-'0';
			    index=j;
			}
	}

   for(l=index;l>i ;l--)	{
   	 temp=s[l];
   	 s[l]=s[l-1];
   	 s[l-1]=temp;
   }
   k=k-(index-i);

}
//printf("final s\n");
for(j=upper;j<19;j++)	{
	printf("%c",s[j]);
}
printf("\n");

return 0;
}

#include <stdio.h>
#include<string.h>
int main(void)
{
	char a[30],t;
	int i,k,alen,max,s,flag=0;
	scanf("%s",a);
	scanf("%d",&k);
	alen=strlen(a);
	while(k>0)
	{
		for(i=0;i<alen-1;i++)
		{
				max=i;
				s=k;
				while(s>0)
				{
					if(a[i+s]>a[i])
						max=a[max]>a[i+s]?max:i+s;
					s--;
				}
				if(a[max]>a[i])
				{
					t=a[max];
					k=k-max+i;
					while(max-i>0)
					{
						a[max]=a[max-1];
						max--;
					}
					a[i]=t;
					flag=1;
					break;
				}
		}
		if(flag==0)
			k--;
		flag=0;
	}
	printf("%s",a);
	return 0;
}

#include <stdio.h>
#include<string.h>
int main(void)
{
	char a[30],t;
	int i,k,alen;
	scanf("%s",a);
	scanf("%d",&k);
	alen=strlen(a);
	while(k>0)
	{
		for(i=0;i<alen-1;i++)
		{
			if(a[i]<a[i+1])
			{
				t=a[i+1];
				a[i+1]=a[i];
				a[i]=t;
				k--;
				break;
			}
		}
	}
	printf("%s",a);
	return 0;
}

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

int main() {
	static char a[20], b[20], c[20];
	int i, j, l, k, k_;
	char tmp;

	scanf("%s", a);
	scanf("%d", &k);
	strcpy(b, a);
	strcpy(c, a);
	l = strlen(a);
	k_ = k;
	for (i = 0; i < l; i++)
		for (j = i; j >= 1; j--) {
			if (k_ == 0)
				break;
			if (b[j] > b[j - 1]) {
				tmp = b[j], b[j] = b[j - 1], b[j - 1] = tmp;
				k_--;
			}
		}
	k_ = k;
	for (i = l - 1; i >= 0; i--)
		for (j = i; j >= 1; j--) {
			if (k_ == 0)
				break;
			if (c[j] > c[j - 1]) {
				tmp = c[j], c[j] = c[j - 1], c[j - 1] = tmp;
				k_--;
			}
		}
	printf("%s\n", strcmp(b, c) > 0 ? b : c);
	return 0;
}

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

int main() {
	static char a[20];
	int i, j, l, k;
	char tmp;

	scanf("%s", a);
	scanf("%d", &k);
	l = strlen(a);
	for (i = 0; i < l; i++)
		for (j = i; j >= 1; j--) {
			if (k == 0)
				break;
			if (a[j] > a[j - 1]) {
				tmp = a[j], a[j] = a[j - 1], a[j - 1] = tmp;
				k--;
			}
		}
	printf("%s\n", a);
	return 0;
}

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

int main() {
	char tmp, max;
	int i, j, imax, l, k;
	static char a[20];

	scanf("%s", a);
	scanf("%d", &k);
	l = strlen(a);
	for (i = 0; i < l; i++) {
		if (k == 0)
			break;
		for (j = i + 1; j <= i + k && j < l; j++)
			if (max < a[j]) {
				imax = j;
				max = a[j];
			}
		if (a[i] < max)
			for (j = imax; j >= i + 1; j--) {
				if (k == 0)
					break;
				tmp = a[j], a[j] = a[j - 1], a[j - 1] = tmp;
				k--;
			}
	}
	printf("%s\n", a);
	return 0;
}

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

int main(void) {
	char a[50];
	int k;
	int len;
	char temp;
	int max;
	int idx;

	int i, j;

	scanf(" %s %d", a, &k);

	len = strlen(a);

	for (i = 0; i < len; i++) {
		max = -1;
		idx = -1;
		for (j = i; j < i + k + 1; j++) {
			if (a[j] > max) {
				idx = j;
				max = a[j];
			}
		}

		if (k > 0) {
			for (j = idx; j > i; j--) {
				k--;
				temp = a[j - 1];
				a[j - 1] = a[j];
				a[j] = temp;
			}
		}
	}

	printf("%s\n", a);

	return 0;
}

#include <stdio.h>

int main()
{
    char Str[20];
    int K, i, j, maxid;
    char max;
    scanf("%s %d", Str, &K);
    for(i=0; i<K && Str[i]!='\0'; ++i)
    {
        max = Str[i];
        maxid = i;
        for(j=i+1; j<i+1+K && Str[j]!='\0'; ++j)
        {
            if(Str[j] > max)
            {
                max = Str[j];
                maxid = j;
            }
        }
        if(maxid != i)
        {
            K -= maxid - i;
            for(j=maxid; j>i; --j)
            {
                Str[j] = Str[j-1];
            }
            Str[i] = max;
        }
    }
    puts(Str);
    return 0;
}

#include <stdio.h>

int main()
{
    char Str[20];
    int K, i, j;
    char temp;
    scanf("%s %d", Str, &K);
    for(i=0; i<K; ++i)
    {
        for(j=1; Str[j]!='\0'; ++j)
        {
            if(Str[j] > Str[j-1])
            {
                temp = Str[j];
                Str[j] = Str[j-1];
                Str[j-1] = temp;
                break;
            }
        }
    }
    puts(Str);
    return 0;
}

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

char a[20],c;
int i,j,k,mx,l,pos;
scanf("%s",a);
scanf("%d",&k);
for(i=0;i<strlen(a);i++){
	if(a[i]!='9'&&k>0){
		mx=a[i]-48;
		pos=i;
		for(j=i+1;j<=i+k;j++){
			if(a[j]-48>mx){
			mx=a[j]-48;
			pos=j;
			}
		}
		if(pos-i<=k){
			for(l=pos;l>i;l--){
				a[l]=a[l-1];

			}
			a[i]=mx+48;
			k=k-(pos-i);
		}
	}
}
printf("%s\n",a);

	return 0;
}

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

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//qsort (arr2, n, sizeof(int), compare);

int main (){
    char arr[100];
    int k;
    scanf("%s",arr);
    scanf("%d",&k);
    int i,j;
    for(i=0;i<strlen(arr);i++){
        for(j=0;j<strlen(arr)-1;j++){
            if(arr[j+1]>arr[j]){
                char temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                k--;
                break;
            }
            if(k==0)
                break;
        }
        if(k==0)
            break;
    }
    printf("%s\n",arr);
    return 0;
}

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

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//qsort (arr2, n, sizeof(int), compare);

int main (){
    char arr[100];
    int k,flag=0;
    scanf("%s",arr);
    scanf("%d",&k);
    int i,j;
    while(1){
        flag=0;
        if(k==0)
        break;
        for(j=0;j<strlen(arr)-1;j++){
            if(arr[j+1]>arr[j]){
                char temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                k--;
                flag=1;
                break;
            }

        }
        if(k==0 || !flag)
            break;
    }

    printf("%s\n",arr);
    return 0;
}

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

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//qsort (arr2, n, sizeof(int), compare);

int main (){
    char arr[100];
    int k;
    scanf("%s",arr);
    scanf("%d",&k);
    int i,j;
    for(i=0;i<strlen(arr);i++){
        for(j=0;j<strlen(arr)-1;j++){
            if(arr[j+1]>arr[j]){
                char temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                k--;
                break;
            }
            if(k==0)
                break;
        }
        i=-1;
        if(k==0)
            break;
    }

    printf("%s\n",arr);
    return 0;
}

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

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//qsort (arr2, n, sizeof(int), compare);

int main (){
    char arr[100];
    int k;
    scanf("%s",arr);
    scanf("%d",&k);
    int i,j;
    for(i=0;i<strlen(arr);i++){
        for(j=0;j<strlen(arr)-1;j++){
            if(arr[j+1]>arr[j]){
                char temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                k--;
                break;
            }
            if(k==0)
                break;
        }
        i=0;
        if(k==0)
            break;
    }
    printf("%s\n",arr);
    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char a[50];
	int k;
	scanf("%s%d",a,&k);
	int s=0,i,l=strlen(a);

	while(k--)
	{
		for(i=0;i<l-1;i++)
		{
			if(a[i]<a[i+1])
			{
				char temp;
				temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
				break;
			}
		}
	}
	printf("%s\n",a);
	return 0;
}

#include<stdio.h>
#include<string.h>
main()
{
      char a[20];
      int k,i,j,l,bar,temp,flag,var;
      scanf("%s",a);
      scanf("%d",&k);
      l=strlen(a);
      for(i=0;i<l;i++)
      a[i]=a[i]-'0';
      for(j=0;j<l;j++)
      {
        flag=0;
        for(i=j+1;i<(l>=k+j+1?k+j+1:l);i++)
         {
           if(a[i]>a[j])
          {
            var=i;
            flag=1;
          }
        }

        if(flag)
        {
          temp=a[var];
          for(bar=var-1;bar>=j;bar--)
          a[bar+1]=a[bar];
          a[j]=temp;
          k-=(var-j);
        }
      }
      for(i=0;i<l;i++)
      printf("%d",a[i]);
      printf("\n");
      //scanf("%d",&j);
      return 0;
}

#include<stdio.h>
#include<string.h>
main()
{
      char a[20];
      int k,i,j,l,bar,temp,flag,var;
      scanf("%s",a);
      scanf("%d",&k);
      l=strlen(a);
      for(i=0;i<l;i++)
      a[i]=a[i]-'0';
      for(j=0;j<l;j++)
      {
        flag=0;
        for(i=j+1;i<j+1+(l>=k?k:l);i++)
         {
           if(a[i]>a[j])
          {
            var=i;
            flag=1;
          }
        }

        if(flag)
        {
          temp=a[var];
          for(bar=var-1;bar>=j;bar--)
          a[bar+1]=a[bar];
          a[j]=temp;
          k-=(var-j);
        }
      }
      for(i=0;i<l;i++)
      printf("%d",a[i]);
      printf("\n");
      //scanf("%d",&j);
      return 0;
}

#include<stdio.h>
int main()
{
    char a[20];
    scanf("%s",a);
    int l=strlen(a);
    int k,i;
    scanf("%d",&k);
    for(i=0;i<k;++i)
    {
        int j,ch=0;
        for(j=0;j<l-1;++j)
        {
            if(a[j]<a[j+1])
            {
                ch=1;
                break;
            }
        }
        if(ch==1)
        {
            char t=a[j];
            a[j]=a[j+1];
            a[j+1]=t;
        }
    }
    printf("%s",a);
    return 0;
}

#include <stdio.h>

int a[20],i,j,k,top,tmp;
long long n;

int main()
{
	scanf("%I64d %d",&n,&k);
	top=0;
	while (n)
	{
		top++;
		a[top]=n%10;
		n/=10;
	}
	for (i=1; i<=k; i++)
	    for (j=top; j>1; j--)
	        if (a[j]<a[j-1]) {tmp=a[j]; a[j]=a[j-1]; a[j-1]=tmp; break;}
	for (i=top; i>1; i--) printf("%d",a[i]);
	printf("%d\n",a[1]);
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char num[1000];
    int n,m,i,j,k,len,max,t;
    while(scanf("%s%d",num,&n)!=-1)
    {
        len=strlen(num);
        while(n)
        {
            for(j=0;j<len;j++)
            {
                max=0;
                for(k=j+1;k<j+1+n;k++)
                {
                    if(num[k]-'0'>max)
                    {
                        m=k;
                        max=num[k]-'0';
                    }
                }
                if(max>(num[j]-'0'))
                {
                    for(i=m;i>j;i--)
                    {
                    t=num[i];
                    num[i]=num[i-1];
                    num[i-1]=t;
                    }
                    n=n-(m-j);
                    if(n<=0)
                        break;

                }
            }
            if(j==len)
                break;
            if(n<=0)
                break;
        }
        printf("%s\n",num);
    }
    return 0;
}

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

int main()
{
    int j,max,idx,n,k,i;
    char a[100],temp;
    scanf("%s%d",a,&k);
    n=strlen(a);
    for(i=0;i<n-1;i++)
    {
        idx=i;
        max=a[i];
        for(j=i+1;j<=i+k;j++)
            if(a[j]>max)
            {
                idx=j;
                max=a[j];
            }
        if(idx!=i)
        {
            temp=a[idx];
            for(j=idx;j>i;j--)
                a[j]=a[j-1];
            a[i]=temp;
            k=k-idx+i;
            if(k<0)
                break;
        }
    }
    printf("%s\n",a);
    return 0;
}

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

int main()
{
    int n,k,i;
    char a[100],temp;
    scanf("%s%d",a,&k);
    n=strlen(a);
    while(k--)
    {
        for(i=0;i<n-1;i++)
            if(a[i]<a[i+1])
            {
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
                break;
            }
        if(i==n-1)
            break;
    }
    printf("%s\n",a);

    return 0;
}

#include<stdio.h>
int main()
{
	char s[30];
	int k,i;
	scanf("%s %d",s,&k);
	for(i=0;s[i+1]&&k>0;i++)
	{
		if(s[i]<s[i+1])
		{
			char temp=s[i];
			s[i]=s[i+1];
			s[i+1]=temp;
			k--;
		}
	}
	printf("%s",s);
	return(0);
}

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

long long A;
int len, k;
char s[20];

int main()
{
    int temp, p = 0, i;
    scanf("%lld%d", &A, &k);
    sprintf(s, "%lld", A);
    len = strlen(s);
    for(i = 0; i < len; i++)
        s[i] -= 48;
    for(; k > 0 && p < len; )
    {
        temp = p;
        for(i = 0; i <= k; i++)
        if(s[temp] < s[p + i])
            temp = p + i;
        if(temp != p)
        {
            int n = s[temp];
            for(i = temp; i > p; i--)
            {
                s[i] = s[i - 1];
            }
            s[p] = n;
            k -= temp - p;
        }
        p++;
    }
    A = 0;
    for(i = 0; i < len; i++)
        A = A * 10 + s[i];
    printf("%lld", A);
}

#include <stdio.h>
#include <string.h>
#define min2(x,y) (x<y?x:y)

int p[30];

void f(int num, int len)
{
	int i, k = 1, sum = p[1];

	if (len == 1)
	{
		printf("%d", p[1]);
		return;
	}

	for (i = 1; i <= min2(num + 1, len); i++)
	{
		if (sum < p[i]) sum = p[i], k = i;
	}
	p[k] = p[1];
	for (i = 1; i <= len - 1; i++) p[i] = p[i + 1];
	printf("%d", sum);
	f(num - k + 1, len - 1);
}
int main()
{
	int i, n, m;
	char in[30];

	scanf("%s %d", &in[1], &m);
	n = strlen(&in[1]);
	for (i = 1; i <= n; i++) p[i] = in[i] - '0';

	f(m, n);

	return 0;
}

#include<stdio.h>
#include<string.h>
char a[32];
int l,b[32],st,m,swp;
int swap(int x,int y)
{
char ch;
int i;
if(y>x)
{
    ch=a[y];
    for(i=y;i>x;i--)
    {
        a[i]=a[i-1];
    }
    a[i]=ch;
}
return 0;
}
main()
{
int i,j,k;
scanf("%s %d",a,&k);
swp=k;
l=strlen(a);
st=0;
while(st<l-1)
{
    m=a[st];
    j=0;
    for(i=st+1;i<l;i++)
    {
        if(a[i]>m)
        {
            m=a[i];
            b[j]=i;
            j++;
        }
    }
    m=0;
    for(i=j-1;i>=0;i--)
    {
        if(swp>=b[i]-st)
        {
            swap(st,b[i]);
            swp=swp-(b[i]-st);
            m=1;
            break;
        }
    }
    if(m==0)
    {
        if(j>0)
        {
            if(b[0]-st>swp)
            {
                swap(b[0]-swp,b[0]);
                break;
            }

        }
    }
    st++;
}
for(i=0;i<l;i++)
{
printf("%c",a[i]);
}
return 0;
}

#include <stdio.h>

int main(void) {
	char number[20];
	int k;
	scanf("%s%d",number,&k);
	while((k--)>0) {
		int i;
		for(i=0;number[i+1]!='\0';i++) {
			if(number[i]<number[i+1]) {
				char temp=number[i];
				number[i]=number[i+1];
				number[i+1]=temp;
				break;
			}
		}
	}
	puts(number);
	return 0;
}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+1;m<i+k+1;m++)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;

ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0,p=k;
scanf("%s %I64d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+1;m<i+p+1 && m<strlen(s);m++)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;
p--;
ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind;
scanf("%s %d",s,&k);
for(i=0;i<strlen(s);i++)
{
for(m=i+k;m>i;m--)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>0)
{
s[ind]=s[ind-1];
ind--;
}
s[ind]=temp+'0';
break;
}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+k;m>i && m<strlen(s);m--)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;

ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %d",s,&k);

for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+1;m<i+k+1;m++)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;

ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+k;m>i && m<strlen(s);m--)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
swap++;

ind--;
}
s[ind]=temp+'0';
if(swap==k)
	break;

}
}
printf("%s\n",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %I64d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+1;m<i+k+1 && m<strlen(s);m++)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
s[ind-1]=temp+'0';
swap++;

ind--;
}

if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>
#include <strings.h>
main()
{
char s[20];
long long int i,j,k,m,temp=-1,ind,swap=0;
scanf("%s %d",s,&k);
for(i=0;i<strlen(s);i++)
{ temp=-1;
for(m=i+k;m>i && m<strlen(s);m--)
{
j=s[m]-'0';
if(j>s[i]-'0' && j>temp)
{
temp=j;
ind=m;

}

}
if(temp!=-1)
{
while(ind>i)
{
	if(swap==k)
	break;
s[ind]=s[ind-1];
swap++;

ind--;
}
s[ind]=temp+'0';
if(swap==k)
	break;

}
}
printf("%s",s);

}

#include <stdio.h>

int main(void) {
    int k,n,i=0,count,max,current=1,index,p,temp;
    int number[18],number1[18];
    long long int a,c;
    scanf("%lld %d",&a,&k);
    c=a;
    while(c>0)
    {
        number1[i]=c%10;
        c=c/10;
        i++;
    }
    count=i;
    for(i=0;i<count;i++)
    {
        number[i]=number1[count-i-1];
    }
    while(k!=0 && current!=count)
    {
        p=0;
        max=-1;
        for(i=current;i<=count && p<k;i++)
        {
            if(number[i]>max)
            {
                index=i;
                max=number[i];
            }
            p++;
        }
        if(max>number[current-1])
        {
            while(index!=current-1)
            {
                temp=number[index];
                number[index]=number[index-1];
                number[index-1]=temp;
                index--;
                k--;
            }
        }
        current++;
    }
    for(i=0;i<count;i++)
        printf("%d",number[i]);
    return 0;
}

#include <stdio.h>

int main(void) {
    int k,n,i=0,count,max,current=1,index,p,temp;
    int number[18],number1[18];
    long long int a,b;
    scanf("%lld %d",&a,&k);
    b=a;
    while(b>0)
    {
        number1[i]=b%10;
        b=b/10;
        i++;
    }
    count=i;
    for(i=0;i<count;i++)
    {
        number[i]=number1[count-i-1];
    }
    while(k!=0 && current!=count)
    {
        p=0;
        max=-1;
        for(i=current;i<=count && p<k;i++)
        {
            if(number[i]>max)
            {
                index=i;
                max=number[i];
            }
            p++;
        }
        if(max>number[current-1])
        {
            while(index!=current-1)
            {
                temp=number[index];
                number[index]=number[index-1];
                number[index-1]=temp;
                index--;
                k--;
            }
        }
        current++;
    }
    for(i=0;i<count;i++)
        printf("%d",number[i]);
    return 0;
}

#include <stdio.h>

int main(void) {
    int k,n,i=0,count,max,current=1,index,p,temp;
    int number[18],number1[18];
    long long int a,b;
    scanf("%lld %d",&a,&k);
    b=a;
    while(b>0)
    {
        number1[i]=b%10;
        b=b/10;
        i++;
    }
    count=i;
    for(i=0;i<count;i++)
    {
        number[i]=number1[count-i-1];
    }
    while(k!=0 && current!=count)
    {
        p=0;
        max=-1;
        for(i=current;i<=count-current && p<k;i++)
        {
            if(number[i]>max)
            {
                index=i;
                max=number[i];
            }
            p++;
        }
        if(max>number[current-1])
        {
            while(index!=current-1)
            {
                temp=number[index];
                number[index]=number[index-1];
                number[index-1]=temp;
                index--;
                k--;
            }
        }
        current++;
    }
    for(i=0;i<count;i++)
    printf("%d",number[i]);
    return 0;
}

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

int k;
char a[19];
int st;
int count;
int max;
int tmp;

int main(){

	int i;

	scanf("%s",a);
	scanf("%d",&k);

	for(i=0;i<strlen(a);i++){
		if(a[i]!='9')
			break;
		else
			st++;
	}

	while(k&&(st<strlen(a))){
		for(i=0;i<k;i++){
			if(a[st]<a[st+1+i])
				if(a[st+1+i]>max){
					max=a[st+1+i];
					count = i+1;
				}
		}

		if(max!=0){
			for(i=0;i<count;i++){
				tmp=a[st+count-i];
				a[st+count-i]=a[st+count-1-i];
				a[st+count-1-i]=tmp;
			}
			k-=count;
		}

		max=0;
		count=0;
		st++;

	}

	printf("%s",a);

	return 0;

}

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

int k;
char a[19];
int st;
int count;
int max;
int tmp;

int main(){

	int i;

	scanf("%s",a);
	scanf("%d",&k);

	for(i=0;i<sizeof(a);i++){
		if(a[i]!='9')
			break;
		else
			st++;
	}

	while(k||st==sizeof(a)){
		for(i=0;i<k;i++){
			if(a[st]<a[st+1+i])
				if(a[st+1+i]>max&&count<k){
					max=a[st+1+i];
					count = i+1;
				}
		}

		if(max!=0){
			for(i=0;i<count;i++){
				tmp=a[st+count-i];
				a[st+count-i]=a[st+count-1-i];
				a[st+count-1-i]=tmp;
			}
			k-=count;
			max=0;
			count=0;
		}
		st++;

	}

	printf("%s",a);

	return 0;

}


#define M 1000000007
inline int p(int s, int n){int a=1;for(;n;n&1?a=1ll*a*s%M:0,s=1ll*s*s%M,n>>=1);return a;}
main(n,m){scanf("%d%d",&n,&m),++n;return!printf("%d",1ll*(n-m)*p(n,M-2)%M*p(n<<1,m)%M);}

/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);

ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll multiply(ll a, ll b, ll mod)
{
   return ((a % mod) * (b % mod)) % mod;
}
int main()
{
	ll n,m;
	SC2(n,m);
	long long ans=0;
	n++;
	long long z=binpow(2,m,MOD);
	z*=binpow(n,m-1,MOD);
	long long z1=(n-m+MOD)%MOD;
	long long z2=multiply(z,z1,MOD);
	ans=(z2);
	ans=ans%MOD;
	printf("%lld\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}

/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
int main()
{
	ll n,m;
	SC2(n,m);
	unsigned long long ans=0;
	n++;
	ll x=2*n;
	unsigned long long z=binpow(x,m,MOD);
	z=z%MOD;
	unsigned long long z1=(n-m)%MOD;
	unsigned long long z2=(z*z1)%MOD;
	ans=(z2/n);
	ans=ans%MOD;
	printf("%llu\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}

/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll multiply(ll a, ll b, ll mod)
{
   return ((a % mod) * (b % mod)) % mod;
}
int main()
{
	ll n,m;
	SC2(n,m);
	unsigned long long ans=0;
	n++;
	ll x=2*n;
	unsigned long long z=binpow(x,m,MOD);
	z=z%MOD;
	unsigned long long z1=(n-m)%MOD;
	unsigned long long z2=multiply(z,z1,MOD);
	ans=(z2/n);
	ans=ans%MOD;
	printf("%llu\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}


#include <stdio.h>
char s[200005];
int main() {
	int n, c1, c2;
	scanf("%d%d%d", &n, &c1, &c2);
	scanf("%s", s);
	int m = 0;
	for (int i = 0; i < n; ++ i) m += s[i] == '1';
	n -= m;
	long long ans = -1;
	for (int x = 1; x <= m; ++ x) {
		int r = n + m - x;
		long long cost = 1LL * c1 * x + 1LL * (r / x) * (r / x) * c2 * (x - r % x) + 1LL * (r / x + 1) * (r / x + 1) * c2 * (r % x);
		if (ans == -1 || cost < ans) ans = cost;
	}
	printf("%I64d\n", ans);
return 0;
}

#include<stdio.h>
char s[200005];
long long X,XX;
long long cal(long long x,long long  all){
    long long t,tt;
    long long ANS;
    ANS=0;
    t=all/x;
    tt=all%x;
    ANS+=(x-tt)*(X+XX*(t-1)*(t-1));
    ANS+=tt*(X+XX*t*t);
    return ANS;
}
int main(void){
    long long i,j,n,m,P,A,L,R,M,MM;
    long long ANS,ANSS;
    scanf("%I64d %I64d %I64d",&n,&X,&XX);
    scanf("%s",s);
    P=A=0;
    for(i=0;i<n;i++){
        if(s[i]=='1') A++;
        else P++;
    }
    L=1;R=A;
    while(L<R){
        M=(L+R)/2;
        MM=(M+R)/2;
        if(MM==M) MM++;
        //cout<<M<<" "<<MM<<endl;
        ANS=cal(M,n);
        ANSS=cal(MM,n);
        //cout<<ANS<<" "<<ANSS<<endl;
        if(ANS<ANSS) R=MM-1;
        else L=M+1;
    }
    //cout<<L<<endl;
    ANS=cal(L,n);
    ANSS=cal(R,n);
    printf("%I64d\n",ANS<ANSS?ANS:ANSS);
}

#include <stdio.h>
typedef long long LL;
int n;
LL c1,c2,ans;
LL f(int x)
{
    int a=n%x,b=x-a;
    LL ans=c1*x;
    ans+=a*c2*(n/x)*(n/x);
    ans+=b*c2*(n/x-1)*(n/x-1);
    return ans;
}
LL min(LL a,LL b){return a<b?a:b;}
int main()
{
    scanf("%d%I64d%I64d ",&n,&c1,&c2);
    char c;
    ans=c1+c2*(n-1)*(n-1);
    int x=0,y=0,k,i;
    for(k=1;k<=n;++k)
    {
        c=getchar();
        if(c=='0')++x;
        else ++y;
    }
    for(i=1;i<=y;++i)
        ans=min(ans,f(i));
    printf("%I64d\n",ans);
    return 0;
}

#include <stdio.h>

char s[200100];
int main()
{
    int n;
    long long c1 , c2;
    scanf("%d%lld%lld" , &n , &c1 , &c2);
    scanf("%s" , s);
    long long sum1 = 0 , sum2  = 0;
    for(int i = 0 ; i<n ; i++)
    {
        sum1+= s[i]=='1';
        sum2+= s[i]=='0';
    }
    long long  x = sum1 , mini = 1e18;
    while(x>0)
    {
        long long z = sum2 / x;
        long long rem = sum2 % x;
        long long ans = rem * (c1 + (z+1)*(z+1)*c2) + (x-rem)*(c1 + (z)*(z)*c2);
        if(ans < mini) mini = ans;
        x--;
        sum2++;
    }
    printf("%lld\n" , mini);
    return 0;
}

#include <stdio.h>
#include <assert.h>

int N, C1, C2;
char seq[ ( int ) 2e5 ];
int adult, child;

long long sqr( int x ) {
  return 1LL * x * x;
}

long long calc( int g ) {
  int ln = N / g; // number of people in less group
  int lc = g - N % g; // number of groups of less people
  int gn = ln + 1;
  int gc = N % g;
  return ( sqr( ln - 1 ) * C2 + C1 ) * lc + ( sqr( gn - 1 ) * C2 + C1 ) * gc;
}

signed main() {
  scanf( "%d %d %d", &N, &C1, &C2 );
  scanf( "%s", seq );
  for( int i = 0; i < N; ++i ) {
    if( seq[ i ] == '1' ) {
      ++adult;
    } else {
      ++child;
    }
  }
  int lb = 1, ub = adult;
  while( ub - lb > 10 ) {
    int x = lb + ( ub - lb ) / 3;
    int y = lb + ( ub - lb ) * 2 / 3;
    long long a = calc( lb ), b = calc( x ), c = calc( y ), d = calc( ub );
    if( a <= b && b <= c && c <= d ) {
      ub = x;
    } else if( a >= b && b <= c && c <= d ) {
      ub = y;
    } else if( a >= b && b >= c && c <= d ) {
      lb = x;
    } else if( a >= b && b >= c && c >= d ) {
      lb = y;
    } else {
      assert( 0 );
    }
  }
  long long ans = 1LL << 60;
  for( int i = lb; i <= ub; ++i ) {
    long long t = calc( i );
    if( ans > t ) {
      ans = t;
    }
  }
  printf( "%lld\n", ans );
  return 0;
}

//created by missever

#include<stdio.h>
typedef long long LL;
char s[200005];

LL min(LL a,LL b)
{
    if(a > b) return b;
    else return a;
}

int main(){
    int n,c1,c2,i,b;
    LL ans;
    b = 0;
    scanf("%d%d%d",&n,&c1,&c2);
    scanf("%s",s);
    for(i = 0;i < n; i++)
    {
        if(s[i] == '1') b++;
    }
    ans = c1 + 1LL * c2 * (n - 1) * (n - 1);
    for(i = 2;i <= b; i++) ans = min(ans,(n % i) * (c1 + 1LL * c2 * (n / i) * (n / i)) +
                                    (i - n % i) * (c1 + 1LL * c2 * (n / i - 1) * (n / i - 1)));
    printf("%I64d\n",ans);
    return 0;
}

#include<stdio.h>

char s[200005];

int main() {
	long long n, c1, c2, i;
	scanf("%lld %lld %lld", &n, &c1, &c2);
	scanf("%s", s);

	int adult = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == '1') adult++;
	}

	long long res = 1e18;

	for (i = 1; i <= adult; i++) {
		long long g = (n - i) / i, rem = (n - i) % i;
		long long cur = i * c1;
		cur += rem * c2 * (g + 1) * (g + 1);
		cur += (i - rem) * c2 * g * g;
		if (res > cur) res = cur;
	}

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

	return 0;
}

#include <stdio.h>
#include <string.h>
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%lld%lld%lld", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 1e18;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '1')
            s1++;
    }
    long long a, b;
    for(i = 1; i <= s1; i++) {
        long long tmp = i * c1;
        tmp += (n % i) * (n / i) * (n / i) * c2  + (i - n % i) * (n / i - 1) * (n / i - 1) * c2;
        if(sum > tmp)
            sum = tmp;
    }
    printf("%lld\n", sum);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
int n, c1, c2;
char st[200010];
LL min(LL a, LL b){return a < b ? a : b;}

int main()
{
	int m, l, r, mid, i;
	LL ans, num, res;
	scanf("%d%d%d %s", &n, &c1, &c2, st);
	m = 0;
	for(i = 0; i < n; ++i)
		if(st[i] == '1')
			++m;
	ans = c1 + 1ll * c2 * (n - 1) * (n - 1);
	for(num = 2; num <= m; ++num) {
		res = num * c1;
		r = n  % num;
		l = n / num;
		res += 1ll * c2 * l * l * r + 1ll * c2 * (l - 1) * (l - 1) * (num - r);
		ans = min(ans, res);
	}
	printf("%I64d\n", ans);
	return 0;
}

#include <stdio.h>

char s[200005];

int main(){
    long long n, c1, c2;
    scanf("%I64d%I64d%I64d", &n, &c1, &c2);
    scanf("%s", s);
    long long adult=0;
    for(int i=0; s[i]; i++){
        if(s[i] == '1') adult++;
    }
    long long res = 1e18;
    for(int gr=1; gr<=adult; gr++){
        long long ppltoadd = n-gr;
        long long cur = 0;
        long long grsz = ppltoadd/gr;
        long long more = ppltoadd%gr;
        cur = ((grsz+1)*(grsz+1)*c2 + c1)*more;
        cur += (grsz*grsz*c2 + c1)*(gr-more);
        if(cur < res) res = cur;
    }
    printf("%I64d", res);
    return 0;
}

#include<stdio.h>
typedef long long ll;
char S[200010];
ll min(ll a,ll b){
        return a<b?a:b;
}
int main(){
	ll n,c1,c2,a=0,res=1e18;
	scanf("%lld%lld%lld",&n,&c1,&c2);
	scanf("%s",S);
	for(ll i=0;i<n;i++){
		if(S[i]=='1') a++;
	}
	for(ll i=1;i<=a;i++){
		res=min(res,  c1*i+c2*(  (n/i)*(n/i)*(n%i)  +  (n/i-1ll)*(n/i-1ll)*(i-n%i)  ) );
	}
	printf("%lld\n",res);
	return 0;
}

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

char st[(200000)+99];

int main()
{
	//freopen("a.in" , "r", stdin);
	//freopen("a.out", "w", stdout);
	long long n , c1 , c2 , mn = 1ll << 60 , cur;

	while(scanf("%I64d",&n) == 1)
    {
        mn = 1ll << 60;
        scanf("%I64d %I64d",&c1 , &c2);
        char ch;
        int big = 0;

        scanf("%s" ,st);
        for(int i = 0 ; i < n ; ++i){

            char ch = st[i];
            if(ch == '1') big++;
        }

        for(int i = 1 ; i <= big ; ++i){
            int sz1 = n;
            int rem = sz1 % i;
            int sz2 = sz1 / i;
            long long fn1 , fn2;
            fn1 = (i - rem) * (c1 + c2 * (sz2 - 1) * (sz2-1) );
            fn2 = rem * ( c1 + c2 * sz2 * sz2);

            if(mn > fn1 + fn2) mn = fn1 + fn2;

        }

        printf("%I64d\n",mn);

    }
	return 0;
}

#include<stdio.h>

#define ll long long

char s[200005];
ll n,c1,c2;
ll fr[2];

int main()
{
	int t,i,j,k;

	scanf("%I64d%I64d%I64d %s",&n,&c1,&c2,s);
	for(i=0;i<n;i++)
	{
		fr[ s[i]-'0' ]++;
	}

	ll rs=(1LL<<61);
	for(ll q=1;q<=fr[1];q++)
	{
		ll rem=fr[1]-q+fr[0];
		ll d=rem/q;
		ll rmx=rem%q;

		ll qx;

		qx=c1*q+c2*(d+1)*(d+1)*rmx+c2*d*d*(q-rmx);

		if(qx<rs)rs=qx;
	}
	printf("%I64d\n",rs);

	return 0;
}

#include <stdio.h>
#include <limits.h>

char S[500003];

int main() {
   long long int t,n;
   char str[101];
   long long int c1,c2;
   scanf("%lld%lld%lld",&n,&c1,&c2);
   scanf("%s",S);
   long long int i,a,b,c,d;
   a=b=0;
   for(i=0;i<n;i++){
    if(S[i]=='1') a++;
    else b++;
   }
   long long int z,ans = LLONG_MAX,orgA,orgB;
   orgA=a;
   orgB=b;
   for(i=1;i<=orgA;i++){
    a=i;
    b=orgB+(orgA-i);
    t=b/a;
    c=c1+c2*t*t;
    d=c1+c2*(t+1)*(t+1);
    z=d*(b%a)+c*(a-b%a);
    if(z<ans) ans=z;
   }
   printf("%lld\n",ans);
}

#include <limits.h>
#include <stdio.h>

long long solve(int n, int g, int c1, int c2) {
	long long a = n / g;
	long long r = n % g;
	long long p1 = r * (c1 + a * a * c2);
	long long p2 = (g - r) * (c1 + (a - 1) * (a - 1) * c2);

	return p1 + p2;
}

int main() {
	static char s[200001];
	long long min;
	int n, c1, c2, i, g;
	int k;

	scanf("%d%d%d", &n, &c1, &c2);
	scanf("%s", s);
	k = 0;
	for (i = 0; i < n; i++)
		if (s[i] == '1')
			k++;
	min = LLONG_MAX;
	for (g = 1; g <= k; g++) {
		long long cost = solve(n, g, c1, c2);

		if (min > cost)
			min = cost;
	}
	printf("%lld\n", min);
	return 0;
}

#include "stdio.h"

const int N = 2e5 + 5;

int n;
long long a, b;
char s[200100];
int p, c, i, j;
long long ans, cur;

int main() {
  scanf("%d %I64d %I64d", &n, &a, &b);
  scanf("%s", s);
  p = c = 0;
  for (i = 0; i < n; i++) {
    p += s[i] == '1';
    c += s[i] == '0';
  }
  ans = -1;
  for (i = 1; i <= p; i++) {
    cur = a * i;
    long long x = (n-i)/i, z = (n-i) % i;
    cur += x * x * b * (i-z);
    x++;
    cur += x * x * b * z;
    if (ans == -1 || ans > cur)
      ans = cur;
  }
  printf("%I64d\n", ans);
  return 0;
}

#include<stdio.h>
#define lli long long int

lli n,c1,c2,pr=0;

lli calc(lli gr)
{
    lli num=n/gr;
    lli r=n%gr;
    lli ret=gr*c1;
    ret+=r*(n/gr)*(n/gr)*c2;
    ret+=(gr-r)*(n/gr-1)*(n/gr-1)*c2;
    return ret;
}

int main() {
    scanf("%lld%",&n);
    scanf("%lld%",&c1);
    scanf("%lld%",&c2);
    char s[n+1];
    gets(s);
    int ch=0;
    int i;
    for(i=0;i<n;i++)
        if(s[i]=='1')
            pr++;
        else
            ch++;
    int l=1,h=pr;
    lli ans=calc(l);
    for(i=l+1;i<=h;i++)
    {
        lli cur=calc(i);
        if(cur<ans)
            ans=cur;
    }
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>
#include<string.h>
char s[200005];
long long cnt,n,c1,c2,ans;
long long f(long long x) {
	return c2*x*x;
}
int main() {
	scanf("%lld%lld%lld",&n,&c1,&c2);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='1')
			cnt++;
//	printf("%lld\n",cnt);
	ans=1e18;
	for(long long i=1;i<=cnt;i++) {
		long long tmp=n%i,o=n/i,res=0;
//		printf("%lld %lld %lld\n",i,tmp,o);
		res=i*c1+tmp*f(o)+(i-tmp)*f(o-1);
		if(ans>res)
			ans=res;
	}
	printf("%lld\n",ans);
}

#include<stdio.h>
#define lli long long int

lli n,c1,c2,pr=0;

lli calc(lli gr)
{
    if(gr==0 || gr>pr)
        return 1000000000000000;
    lli num=n/gr;
    lli r=n%gr;
    lli ret=gr*c1;
    ret+=r*(n/gr)*(n/gr)*c2;
    ret+=(gr-r)*(n/gr-1)*(n/gr-1)*c2;
    return ret;
}

int main() {
    scanf("%lld%",&n);
    scanf("%lld%",&c1);
    scanf("%lld%",&c2);
    char s[n+1];
    gets(s);
    int ch=0;
    int i;
    for(i=0;i<n;i++)
        if(s[i]=='1')
            pr++;
        else
            ch++;
    int l=1,h=pr;
    lli ans;
    while(l<=h)
    {
        int mid=(l+h)/2;
        lli n1=calc(mid-1);
        lli n2=calc(mid+1);
        lli nm=calc(mid);
        if(n1>nm && n2>nm)
            {ans=nm;
            break;}
        else if(n2<nm)
            l=mid+1;
        else
            h=mid-1;
    }
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>
#define lli long long int

lli n,c1,c2,pr=0;

lli calc(lli gr)
{
    if(gr==0 || gr>pr)
        return 1000000000000000;
    lli num=n/gr;
    lli r=n%gr;
    lli ret=gr*c1;
    ret+=r*(n/gr)*(n/gr)*c2;
    ret+=(gr-r)*(n/gr-1)*(n/gr-1)*c2;
    return ret;
}

int main() {
    scanf("%lld%",&n);
    scanf("%lld%",&c1);
    scanf("%lld%",&c2);
    char s[n+1];
    gets(s);
    int ch=0;
    int i;
    for(i=0;i<n;i++)
        if(s[i]=='1')
            pr++;
        else
            ch++;
    int l=1,h=pr;
    lli ans;
    while(l<=h)
    {
        int mid=(l+h)/2;
        lli n1=calc(mid-1);
        lli n2=calc(mid+1);
        lli nm=calc(mid);
        if(n1>nm && n2>nm)
            {ans=nm;
            break;}
        else if(n1>nm)
            ans=nm,l=mid+1;
        else
            h=mid-1;
    }
    printf("%lld",ans);
    return 0;
}

#include <stdio.h>
typedef long long LL;
int n;
LL c1,c2,ans;
LL f(int x)
{
    int a=n%x,b=x-a;
    LL ans=c1*x;
    ans+=a*c2*(n/x)*(n/x);
    ans+=b*c2*(n/x-1)*(n/x-1);
    return ans;
}
LL min(int a,int b){return a<b?a:b;}
int main()
{
    scanf("%d%I64d%I64d ",&n,&c1,&c2);
    char c;
    ans=c1+c2*(n-1)*(n-1);
    int x=0,y=0,k,i;
    for(k=1;k<=n;++k)
    {
        c=getchar();
        if(c=='0')++x;
        else ++y;
    }
    for(i=1;i<=y;++i)
        ans=min(ans,f(i));
    printf("%I64d\n",ans);
    return 0;
}

#include<stdio.h>

char s[200005];

int main() {
    int n, c1, c2, i;
    scanf("%d %d %d", &n, &c1, &c2);
    scanf("%s", s);

    int adult = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == '1') adult++;
    }

    long long res = 1e18;
    for (i = 1; i <= adult; i++) {
        int extra = n - i;
        int x = 1 + extra / i;

        int a = extra % i;
        int b = i - a;

        long long cur = i * c1;

        if (a > 0) {
            cur += a *  1LL * c2 * x * x;
        }
        if (x > 0) {
            cur += b * 1LL * c2 * (x - 1) * (x - 1);
        }

        if (res > cur) res = cur;
    }

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

    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 0x3f3f3f3f;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = 1; i <= s1; i++) {
        long long tmp = i * c1;
        tmp += (n % i) * ((n / i) * (n / i) * c2 ) + (i - n % i) * ( (n / i - 1) * (n / i - 1) * c2);
        sum = min(sum, tmp);
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 2147483647;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 1000000000000000000;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 0x3f3f3f3f;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%lld%lld%lld", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 0x3f3f3f3f;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%lld\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 200000010;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 0x3f3f3f3f;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = 1; i <= s1; i++) {
        long long tmp = i * c1;
        tmp += (n % i) * ((n / i) * (n / i) * c2 ) + (i - n % i) * ( (n / i - 1) * (n / i - 1) * c2);
        if(sum > tmp)
            sum = tmp;
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 200010;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 0xFFFFFFFF;
    long long s0 = 0;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    long long a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
int main() {
    long long n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    long long len = strlen(s);
    long long sum = 1e18;
    long long s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '1')
            s1++;
    }
    long long a, b;
    for(i = 1; i <= s1; i++) {
        long long tmp = i * c1;
        tmp += (n % i) * (n / i) * (n / i) * c2  + (i - n % i) * (n / i - 1) * (n / i - 1) * c2;
        if(sum > tmp)
            sum = tmp;
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define min(a,b) a<b?a:b
int main() {
    int n, c1, c2, i;
    char s[200010];
    scanf("%d%d%d", &n, &c1, &c2);
    scanf("%s", s);
    int len = strlen(s);
    int sum = 200010;
    int s0 = 0;
    int s1 = 0;
    for(i = 0; i < len; i++) {
        if(s[i] == '0')
            s0++;
        else
            s1++;
    }
    int a, b;
    for(i = s1; i >= 1; i--) {
        sum = min(sum, ((n % i) * (c1 + (n / i) * (n / i) * c2 )+ (i - n % i) *(c1 + (n / i - 1) * (n / i - 1) * c2)));
    }
    printf("%d\n", sum);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
int n, c1, c2;
char st[200010];
LL solve(LL x)
{
	LL a = n / x, b = n % x;
	LL res = (c1 + 1ll * c2 * (a - 1) * (a - 1)) * (x - b);
	res += (c1 + 1ll * c2 * a * a) * b;
	return res;
}
LL min(LL a, LL b){return a < b ? a : b;}

int main()
{
	int m, l, r, mid, i;
	LL ans;
	scanf("%d%d%d %s", &n, &c1, &c2, st);
	m = 0;
	for(i = 0; i < n; ++i)
		if(st[i] == '1')
			++m;
	ans = 1ll * n * c1;
	l = 2, r = m, mid;
	while(l <= r) {
		mid = (l + r) >> 1;
		LL res1 = solve(mid);
		LL res2 = solve(mid - 1);
		if(res1 <= res2) {
			ans = min(ans, res1);
			r = mid - 1;
		}
		else {
			ans = min(ans, res2);
			l = mid + 1;
		}
	}
	printf("%I64d\n", ans);
	return 0;
}

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

char st[(200000)+99];

int main()
{
	//freopen("a.in" , "r", stdin);
	//freopen("a.out", "w", stdout);
	long long n , c1 , c2 , mn = 1ll << 60 , cur;

	while(scanf("%I64d",&n) == 1)
    {
        mn = 1ll << 60;
        scanf("%I64d %I64d",&c1 , &c2);
        char ch;
        int big = 0;

        scanf("%s" ,st);
        for(int i = 0 ; i < n ; ++i){

            char ch = st[i];
            if(ch == '1') big++;
        }

        for(int i = 1 ; i <= big ; ++i){

            int sz2 = n % i; // have size e i+1
            int sz1 = i - sz2; // have size e i

            int fn1 = n / i;
            int fn2 = fn1 + 1;

            cur = 0;
            if(sz1 > 0){
                long long t = (c1 + c2*(fn1 - 1)*(fn1 - 1 ));
                cur += t * sz1;
            }
            ;
            if(sz2 > 0){
                long long t = (c1 + c2*(fn2)*(fn2));
                cur += t * sz2;
            }

            if(mn > cur) mn = cur;

        }

        printf("%I64d\n",mn);

    }
	return 0;
}