ACM--C - Good String

    xiaoxiao2022-07-06  214

    苍茫大地一剑尽挽破,何处繁华笙歌落。斜倚云端千壶掩寂寞,纵使他人空笑我。

    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.

    Input

    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.

    Output

    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.

    Examples

    Input

    4 good

    Output

    0 good

    Input

    4 aabc

    Output

    2 ab

    Input

    3 aaa

    Output

    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; }

     

    最新回复(0)