#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#define LOCAL
#ifdef LOCAL
#define cin in
#endif
#define FOREACH(i, n) for (typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define MEMSET(p, c) memset(p, c, sizeof(p))
using namespace std;
template < class T,class T2 >
T2 fac( T n)
{
return n< 2 ? 1 : fac< T,T2> ( n- 1 ) * n;
}
template < class T>
T nb_combinaisons( T k,T n)
{
if ( n< k)
return nb_combinaisons< T> ( n,k) ;
return fac< T,long long int > ( n) / ( fac< T,long long int > ( n- k) * fac< T,long long int > ( k) ) ;
}
string itoa_2( long long int n)
{
string s;
stringstream ss;
ss<< n;
ss>> s;
while ( s.size ( ) ! = 9 )
s= '0' + s;
return s;
}
int main( )
{
#ifdef LOCAL
ifstream in( "input.txt" ) ;
#endif
int n,k;
cin >> n>> k;
string s;
cin >> s;
string s3= s;
sort( s.begin ( ) ,s.end ( ) ) ;
int mini_global= 10000000 ;
string resultat_mini;
for ( int c= 0 ; c< 10 ; c++ )
{
string s2= s3;
int c2;
for ( c2= 0 ; c2< s.size ( ) && s[ c2] < c+ '0' ; c2++ ) ;
int total= abs ( s[ c2] - '0' - c) ;
for ( int c3= 0 ; c3< s2.size ( ) ; c3++ )
if ( s2[ c3] == s[ c2] )
{
s2[ c3] = c+ '0' ;
break ;
}
int bas= c2- 1 ,haut= c2+ 1 ;
for ( c2= 0 ; c2< k- 1 ; c2++ )
{
if ( haut>= s.size ( ) || ( bas>= 0 && abs ( s[ bas] - '0' - c) <= abs ( s[ haut] - '0' - c) ) )
{ for ( int c3= 0 ; c3< s2.size ( ) ; c3++ ) if ( s2[ c3] == s[ bas] ) {
s2[ c3] = c+ '0' ; break ; }
total+ = abs ( s[ bas] - '0' - c) ;
bas-- ;
}
else
{
for ( int c3= 0 ; c3< s2.size ( ) ; c3++ )
if ( s2[ c3] == s[ haut] ) {
s2[ c3] = c+ '0' ; break ; }
total+ = abs ( s[ haut] - '0' - c) ;
haut++ ;
}
}
if ( mini_global> total)
{
mini_global= total;
resultat_mini= s2;
}
}
cout << mini_global<< endl<< resultat_mini;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG1hcD4KI2RlZmluZSBMT0NBTAojaWZkZWYgTE9DQUwKI2RlZmluZSBjaW4gaW4KI2VuZGlmCgojZGVmaW5lIEZPUkVBQ0goaSwgbikgZm9yICh0eXBlb2Yobi5iZWdpbigpKSBpID0gbi5iZWdpbigpOyBpICE9IG4uZW5kKCk7ICsraSkKI2RlZmluZSBNRU1TRVQocCwgYykgbWVtc2V0KHAsIGMsIHNpemVvZihwKSkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0ZW1wbGF0ZSA8IGNsYXNzIFQsY2xhc3MgVDIgPgpUMiBmYWMoVCBuKQp7CiAgICByZXR1cm4gbjwyPzE6ZmFjPFQsVDI+KG4tMSkqbjsKfQoKdGVtcGxhdGUgPGNsYXNzIFQ+ClQgbmJfY29tYmluYWlzb25zKFQgayxUIG4pCnsKICAgIGlmKG48aykKICAgICAgICByZXR1cm4gbmJfY29tYmluYWlzb25zPFQ+KG4sayk7CiAgICByZXR1cm4gZmFjPFQsbG9uZyBsb25nIGludD4obikvKGZhYzxULGxvbmcgbG9uZyBpbnQ+KG4taykqZmFjPFQsbG9uZyBsb25nIGludD4oaykpOwp9CgpzdHJpbmcgaXRvYV8yKGxvbmcgbG9uZyBpbnQgbikKewogICAgc3RyaW5nIHM7CiAgICBzdHJpbmdzdHJlYW0gc3M7CiAgICBzczw8bjsKICAgIHNzPj5zOwogICAgd2hpbGUocy5zaXplKCkhPTkpCiAgICAgICAgcz0nMCcrczsKICAgIHJldHVybiBzOwp9CgoKaW50IG1haW4oKQp7CiAgICAjaWZkZWYgTE9DQUwKICAgICAgICBpZnN0cmVhbSBpbigiaW5wdXQudHh0Iik7CiAgICAjZW5kaWYKICAgaW50IG4sazsKICAgY2luPj5uPj5rOwogICBzdHJpbmcgczsKICAgY2luPj5zOwogICBzdHJpbmcgczM9czsKICAgc29ydChzLmJlZ2luKCkscy5lbmQoKSk7CiAgIGludCBtaW5pX2dsb2JhbD0xMDAwMDAwMDsKICAgc3RyaW5nIHJlc3VsdGF0X21pbmk7CiAgIGZvcihpbnQgYz0wO2M8MTA7YysrKQogICB7CiAgICAgICBzdHJpbmcgczI9czM7CiAgICBpbnQgYzI7CiAgICBmb3IoYzI9MDtjMjxzLnNpemUoKSYmc1tjMl08YysnMCc7YzIrKyk7CiAgICBpbnQgdG90YWw9YWJzKHNbYzJdLScwJy1jKTsKICAgIGZvcihpbnQgYzM9MDtjMzxzMi5zaXplKCk7YzMrKykKICAgICAgICBpZihzMltjM109PXNbYzJdKQogICAgICAgIHsKICAgICAgICAgICAgczJbYzNdPWMrJzAnOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CgogICAgaW50IGJhcz1jMi0xLGhhdXQ9YzIrMTsKICAgIGZvcihjMj0wO2MyPGstMTtjMisrKQogICAgewogICAgICAgIGlmKGhhdXQ+PXMuc2l6ZSgpfHwoYmFzPj0wJiZhYnMoc1tiYXNdLScwJy1jKTw9YWJzKHNbaGF1dF0tJzAnLWMpKSkKICAgICAgICB7Zm9yKGludCBjMz0wO2MzPHMyLnNpemUoKTtjMysrKWlmKHMyW2MzXT09c1tiYXNdKXsKICAgICAgICAgICAgICAgICAgICBzMltjM109YysnMCc7YnJlYWs7fQogICAgICAgICAgICB0b3RhbCs9YWJzKHNbYmFzXS0nMCctYyk7CiAgICAgICAgICAgIGJhcy0tOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGMzPTA7YzM8czIuc2l6ZSgpO2MzKyspCiAgICAgICAgICAgICAgICBpZihzMltjM109PXNbaGF1dF0pewogICAgICAgICAgICAgICAgICAgIHMyW2MzXT1jKycwJzticmVhazt9CiAgICAgICAgICAgIHRvdGFsKz1hYnMoc1toYXV0XS0nMCctYyk7CiAgICAgICAgICAgIGhhdXQrKzsKICAgICAgICB9CiAgICB9CiAgICBpZihtaW5pX2dsb2JhbD50b3RhbCkKICAgIHsKICAgICAgICBtaW5pX2dsb2JhbD10b3RhbDsKICAgICAgICByZXN1bHRhdF9taW5pPXMyOwogICAgfQogICB9CiAgIGNvdXQ8PG1pbmlfZ2xvYmFsPDxlbmRsPDxyZXN1bHRhdF9taW5pOwp9CgoKCg==
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:62: warning: comparison between signed and unsigned integer expressions
prog.cpp:64: warning: comparison between signed and unsigned integer expressions
prog.cpp:74: warning: comparison between signed and unsigned integer expressions
prog.cpp:75: warning: comparison between signed and unsigned integer expressions
prog.cpp:82: warning: comparison between signed and unsigned integer expressions
stdout