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

博客围绕Codeforces上的一道题目展开,定义了一种“好字符串”,即长度为偶数且奇数位置字符与下一个字符不同。给定字符串,需删除最少字符使其成为好字符串,给出了输入输出要求及示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接: http://codeforces.com/contest/1165/problem/C

time limit per test 1 second

memory limit per test 256 megabytes

input

standard input

output

standard output

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 ?

, you have to delete minimum number of characters from this string so that it becomes good.

Input

The first line contains one integer ?

(1≤?≤2⋅10^5) — the number of characters in ?

.

The second line contains the string ?

, consisting of exactly ?

lowercase Latin letters.

Output

In the first line, print one integer ?

(0≤?≤?) — the minimum number of characters you have to delete from ?

to make it good.

In the second line, print the resulting string ?

. If it is empty, you may leave the second line blank, or not print it at all.

Examples

Input

Copy

4
good

Output

Copy

0
good

Input

Copy

4
aabc

Output

Copy

2
ab

Input

Copy

3
aaa

Output

Copy

3

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5+10;
char s[N];
int main() {
    int n;
    ios_base::sync_with_stdio(false);
    cin>>n>>s;
    string str = "";
    int i = 0;
    while(i < n-1) {
        if(s[i]!=s[i+1]){
            str += s[i];
            str += s[i+1];
            i += 2;
        }
        else i++;
    }
    cout<<n-str.size()<<endl;
    cout<<str<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值