码迷,mamicode.com
首页 > 其他好文 > 详细

C Good String Codeforces Round #560 (Div. 3)

时间:2019-10-04 11:09:08      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:force   result   dash   ons   void   his   line   names   string   

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 (1n21051≤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 (0kn0≤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 <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
//
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
//
#define fi      first
#define se      second
#define pb      push_back
#define pq      priority_queue<int>
#define ok      return 0;
#define os(str) cout<<string(str)<<endl;
#define gcd __gcd
#define mem(s,t) memset(s,t,sizeof(s))
#define debug(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define debug1(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";  cout<<endl;
#define debug02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" ";   cout<<endl; }
#define read11(a,k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i];}
#define read02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; }
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);

using namespace std;
inline void NO()
{
    cout<<"NO"<<endl;
}
inline void YES()
{
    cout<<"YES"<<endl;
}
const  int  mxn = 2e5+10;
#define oi(x)   cout<<x<<endl;
#define rep(k)    for (int i=0;i<n;i++)
#define rep1(j,k) for (int i=j;i<=k;  i++)
#define per(j,k)  for (int i=j;i>=k; i--)
#define per(k)    for (int i=k-1;i>=0;i--)
string str,ch;
int n;
int main()
{
    int n;
    while(cin>>n)
    {
        ch="";
        cin>>str;
                int j;
        for(int i=0; i<n;)
        {
            if( str[i]!=str[i+1] && i+1<n )
            {
                ch+=str[i];
                ch+=str[i+1];
                i+=2;
            }
            else
            {

                for(j=i+2;j<n && j<n;)
                {
                    if(str[i]!=str[j])
                    {
                        ch+=str[i];
                        ch+=str[j];
                        i=j+1;
                        j++;
                        break;
                    }
                    else
                        j++;
                }
                i=j;
            }
        }
        cout<<str.size()-ch.size()<<endl;
        cout<<ch<<endl;
    }
    ok;
}

 

C Good String Codeforces Round #560 (Div. 3)

标签:force   result   dash   ons   void   his   line   names   string   

原文地址:https://www.cnblogs.com/Shallow-dream/p/11621443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!