Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.
You are given a string ss, you have to delete minimum number of characters from this string so that it becomes good.
The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of characters in ss.
The second line contains the string ss, consisting of exactly nn lowercase Latin letters.
In the first line, print one integer kk (0≤k≤n0≤k≤n) — the minimum number of characters you have to delete from ss to make it good.
In the second line, print the resulting string ss. If it is empty, you may leave the second line blank, or not print it at all.
Input
4 goodOutput
0 goodInput
4 aabcOutput
2 abInput
3 aaaOutput
3 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<string> #include<map> #include<algorithm> #include<iomanip> #include<queue> #include<set> #include<stack> char s[200005],t[200005]; using namespace std; int main() { int n,i=0,j=1,k=0; cin>>n; for(i=0;i<n;i++) cin>>s[i]; i=0; while(j<n) { if(s[i]!=s[j]) { t[k]=s[i]; k++; t[k]=s[j]; k++; i=j+1; j+=2; } else j++; } cout<<n-k<<endl; for(i=0;i<k;i++) cout<<t[i]; return 0; }
