import
java.io.*;
class
GFG {
static
String getXOR(String a, String b)
{
int
aLen = a.length();
int
bLen = b.length();
if
(aLen > bLen) {
b = addZeros(b, aLen - bLen);
}
else
if
(bLen > aLen) {
a = addZeros(a, bLen - aLen);
}
int
len = Math.max(aLen, bLen);
String res =
""
;
for
(
int
i =
0
; i < len; i++) {
if
(a.charAt(i) == b.charAt(i))
res +=
"0"
;
else
res +=
"1"
;
}
return
res;
}
static
String addZeros(String s,
int
numZeros)
{
for
(
int
i =
0
; i < numZeros; i++) {
s =
"0"
+ s;
}
return
s;
}
static
String maxValue(String S)
{
int
n = S.length();
boolean
f =
true
;
int
Idx =
0
, Count0 =
0
, Count1 =
0
;
for
(
int
i =
0
; i < n; i++) {
if
(S.charAt(i) ==
'1'
) {
Count1++;
}
else
{
if
(f) {
Idx = i;
f =
false
;
}
Count0++;
}
}
if
(Count1 == n) {
return
getXOR(S,
"1"
);
}
if
(Count0 == n) {
return
"0"
;
}
String t = S.substring(Idx, n);
int
size = t.length();
String dec = t;
String Max =
""
;
String t1 =
""
, t2 =
""
;
for
(
int
j =
0
; j < n; j++) {
if
(j < size) {
t1 += S.charAt(j);
}
else
{
String dec1 = t1;
String res = getXOR(dec, dec1);
if
(res.compareTo(Max) >
0
) {
Max = res;
t2 = t1;
}
t1 = t1.substring(
1
);
t1 += S.charAt(j);
}
}
String dec1 = t1;
String res = getXOR(dec1, dec);
if
(res.compareTo(Max) >
0
) {
Max = res;
t2 = t;
}
String d1 = S;
String d2 = t2;
String ans = getXOR(d1, d2);
Idx = -
1
;
for
(
int
i =
0
; i < ans.length(); i++) {
if
(ans.charAt(i) !=
'0'
) {
Idx = i;
break
;
}
}
if
(Idx == -
1
) {
return
"0"
;
}
return
ans.substring(Idx);
}
static
String solve(String s,
int
K)
{
int
i =
0
;
while
(i < K) {
s = maxValue(s);
i++;
}
return
s;
}
public
static
void
main(String[] args)
{
String s =
"1010010"
;
int
K =
2
;
System.out.println(solve(s, K));
}
}