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

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

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

时间: 2024-08-30 06:13:07

C Good String Codeforces Round #560 (Div. 3)的相关文章

D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

http://codeforces.com/contest/862/problem/D 询问题 fflush(stdout) 调试: 先行给出结果,函数代替输入 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <se

Codeforces Round #560 Div. 3

题目链接:戳我 于是...风浔凌弱菜又去写了一场div.3 总的来说,真的是比较简单.......就是.......不开long long见祖宗 贴上题解-- A 给定一个数,为01串,每次可以翻转一个位置上的数,问最少几步可以使得它模\(10^x\)余\(10^y\) 从后往前贪心即可. #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<c

Codeforces Round #560 (Div. 3) B题

题目网址:http://codeforces.com/contest/1165/problem/B 题目大意:给出n个数,问有多少个数满足连续大于等于自然数集中的数,即以此大于等于1,2,3…… 题解:直接sort一下,然后从小到大和1,2,3……比较 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=2e5+7; 4 int a[maxn]; 5 int main() 6 { 7 int n,tot=1,ans

Codeforces Round #560 (Div. 3) A题

题目网址:http://codeforces.com/contest/1165/problem/A 题目大意:给定一行01串,开头必是1,length为n,可对串进行变化,0变成1,1变成0,问经过最少的变化,该串mod 10^x==10^y.(^是乘方),输出变化次数. 题解:简单分析可知,比如串是1001000,则mod 1000 == 0,mod 10000 == 1000,所以直接在n-x之和判断即可. 1 #include<bits/stdc++.h> 2 #define ll lo

贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

题目传送门 1 /* 2 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 3 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <iostream> 10 using namespace std; 11 12 const int MAX

Codeforces Round #402 (Div. 2) D. String Game

题目链接:Codeforces Round #402 (Div. 2) D. String Game 题意: 给你两个字符串a,b,然后给你n=strlen(a)个数字n1,n2,...,nn,表示依次删a[ni-1]个字符. 当a串删到有k(k任意)个子串组合起来(顺序不变)刚好等于b串时,就不能删了. 比如 abba->(ab a) 刚好包括 aba ,bba不包括aab. 问最多能删多少次. 题解: 最开始还以为是要用某种数据结构啥的,结果都想复杂了,直接二分答案就行. 然后线性判断删掉后

Codeforces Round #286 (Div. 2)A. Mr. Kitayuta&#39;s Gift(暴力,string的应用)

由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一步一步的优化,不能盲目的想. 这道题要AC的快需要熟悉string的各种用法.这里做个简单总结:C++中string的常见用法. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin

Codeforces Round #598 (Div. 3) D - Binary String Minimizing

原文链接:https://www.cnblogs.com/xwl3109377858/p/11797618.html Codeforces Round #598 (Div. 3) D - Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1'). In one move you can swap two adj

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f