B. Polycarp and Letters

来源:互联网 发布:半包包括哪些 知乎 编辑:程序博客网 时间:2024/05/22 06:42

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.

Let A be a set of positions in the string. Let's call it pretty if following conditions are met:

  • letters on positions from A in the string are all distinct and lowercase;
  • there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).

Write a program that will determine the maximum number of elements in a pretty set of positions.

Input

The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.

The second line contains a string s consisting of lowercase and uppercase Latin letters.

Output

Print maximum number of elements in pretty set of positions for string s.

Examples
input
11aaaaBaabAbA
output
2
input
12zACaAbbaazzC
output
3
input
3ABC
output
0
Note

In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.

In the second example desired positions can be 78 and 11. There are other ways to choose pretty set consisting of three elements.

In the third example the given string s does not contain any lowercase letters, so the answer is 0.



解题说明:题意是给定一个长度为n的字符串,求最大的位置集合,每个位置都是小写字母且各不相同,每两个位置之间没有大写字母。可以采用暴力枚举来判断。


#include<cstdio>#include<iostream>#include<string>#include <ctype.h>#include<cstring>using namespace std;int occ[256];int main() {int n,i;int best = 0;int cnt = 0;scanf("%d", &n);getchar();unsigned char c;for (i = 0; i < n; ++i) {scanf("%c", &c);if (isupper(c)) {memset(occ, 0, 256 * 4);if (cnt > best){best = cnt;}cnt = 0;}else {cnt += (1 - occ[c]);occ[c] = 1;}}printf("%d\n", best > cnt ? best : cnt);return 0;}