欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

A. Diverse Substring,diversesubstring

来源: javaer 分享于  点击 48990 次 点评:181

A. Diverse Substring,diversesubstring


time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string ss, consisting of nn lowercase Latin letters.

A substring of string ss is a continuous segment of letters from ss. For example, "defor" is a substring of "codeforces" and "fors" is not.

The length of the substring is the number of letters in it.

Let's call some string of length nn diverse if and only if there is no letter to appear strictly more than n2n2 times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.

Your task is to find any diverse substring of string ss or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the length of string ss.

The second line is the string ss, consisting of exactly nn lowercase Latin letters.

Output

Print "NO" if there is no diverse substring in the string ss.

Otherwise the first line should contain "YES". The second line should contain any diverse substring of string ss.

Examples

input

Copy

10
codeforces

output

Copy

YES
code

input

Copy

5
aaaaa

output

Copy

NO

Note

The first example has lots of correct answers.

Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

解题说明:此题只需要找到一个不连续出现相同字母的子串,遍历枚举即可。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main() 
{
	int l, i, j, k, m, ans = 0;
	char a[1002];
	scanf("%d", &l);
	scanf("%s", a);
	for (i = 1; i<l; i++) 
	{
		if (a[i] != a[i - 1]) 
		{
			ans++;
			printf("YES\n%c%c\n", a[i - 1], a[i]);
			break;
		}
	}
	if (ans != 1)
	{
		printf("NO\n");
	}
	return 0;
}

 

相关文章

    暂无相关文章

用户点评