using
System;
using
System.Collections;
using
System.Collections.Generic;
class
GFG
{
static
string
stringLen(
string
str)
{
int
[]m =
new
int
[100000];
m[0] = -1;
int
count_0 = 0;
int
count_1 = 0;
int
start = 0;
int
end = 0;
int
res = 0;
for
(
int
i = 0; i < str.Length; i++) {
if
(str[i] ==
'0'
)
count_0++;
else
count_1++;
if
(m[count_1 - count_0]!= 0) {
if
((i - m[count_1 - count_0]) > res) {
start = m[count_1 - count_0];
end = i;
res = end - start;
}
}
else
m[count_1 - count_0] = i;
}
if
(count_0 == 0 || count_1 == 0)
return
"-1"
;
return
str.Substring(start, end - start + 2);
}
public
static
void
Main ()
{
string
str =
"110101010"
;
Console.Write(stringLen(str));
}
}