B - B

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
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0

Note

In the first example the desired positions might be 6 and 8or 7 and 8. Positions 6 and 7 contain letters 'a', position 8contains 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 7, 8 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.

题意:求连续的小写字母中不同字母的最大数量

题解:运用set,set可以去掉重复的字母,存到一个字符串数组里,同时记录下长度,找到最长的输出

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[1000];
int n,ct=0;
set<char>b;
cin>>n>>s;
for(int i=0;i<n;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
b.insert(s[i]);
}
else{
if(ct<b.size())ct=b.size();
b.clear();
}
}
if(ct<b.size)ct=b.size();
b.clear();
cout<<ct<<endl;
}

E - E

Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

Input

The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

  • 'R' — the light bulb is red,
  • 'B' — the light bulb is blue,
  • 'Y' — the light bulb is yellow,
  • 'G' — the light bulb is green,
  • '!' — the light bulb is dead.

The string s can not contain other symbols except those five which were described.

It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

Output

In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

Examples

Input
RYBGRYBGR
Output
0 0 0 0
Input
!RGYB
Output
0 1 0 0
Input
!!!!YGRB
Output
1 1 1 1
Input
!GB!RG!Y!
Output
2 1 1 0

Note

In the first example there are no dead light bulbs.

In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

题解:每四个一循环,同时记录下每种缺少的字母的个数,我是特判了字符串长度为4的时候,看是否有不存在的字母,若有则直接设为一,长度大于4时,每四个一循环对比看缺少的是哪个,同时另为“!”的值等于相应的字母,继续重复对比循环

#include<bits/stdc++.h>
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
string s,k;
int r=0,b=0,y=0,g=0;
cin>>s;
int m,i,j;
m=s.size();
if(m==4)
{
for(i=0;i<4;i++)
{
if(s[i]=='R')r++;
else if(s[i]=='B')b++;
else if(s[i]=='Y')y++;
else if(s[i]=='G')g++;
}
if(r==0)r=1;else r=0;
if(b==0)b=1;else b=0;
if(y==0)y=1;else y=0;
if(g==0)g=1;else g=0; cout<<r<<" "<<b<<" "<<y<<" "<<g<<endl;
}
else{
for(i=0;i<m;i++)
{
if(i+4<m)
{
if(s[i]=='!')
{
for(j=i+4;j<m;j+=4)
{
if(s[j]!='!')
{
if(s[j]=='R')s[i]='R',r++;
else if(s[j]=='B')s[i]='B',b++;
else if(s[j]=='Y')s[i]='Y',y++;
else if(s[j]=='G')s[i]='G',g++;
break;
}
}
}
}
if(i-4>=0)
{
if(s[i]=='!')
{
for(j=i-4;j>=0;j-=4)
{
if(s[j]!='!')
{
if(s[j]=='R')s[i]='R',r++;
else if(s[j]=='B')s[i]='B',b++;
else if(s[j]=='Y')s[i]='Y',y++;
else if(s[j]=='G')s[i]='G',g++;
break;
}
}
}
}
}
cout<<r<<" "<<b<<" "<<y<<" "<<g<<endl;
}
}

2020.10.23-vj个人赛补题的更多相关文章

  1. 2020.10.17-pta天梯练习赛补题

    7-5敲笨钟 微博上有个自称"大笨钟V"的家伙,每天敲钟催促码农们爱惜身体早点睡觉.为了增加敲钟的趣味性,还会糟改几句古诗词.其糟改的方法为:去网上搜寻压"ong&quo ...

  2. 2020.11.1--pta阶梯练习赛补题

    7-5 古风排版 中国的古人写文字,是从右向左竖向排版的.本题就请你编写程序,把一段文字按古风排版. 输入格式: 输入在第一行给出一个正整数N(<),是每一列的字符数.第二行给出一个长度不超过1 ...

  3. 2020.10.30--vj个人赛补题

    D - D CodeForces - 743A Vladik is a competitive programmer. This year he is going to win the Interna ...

  4. 2020.10.16--vj个人赛补题

    D - Drinks Choosing Old timers of Summer Informatics School can remember previous camps in which eac ...

  5. 2020.10.9--vj个人赛补题

    B - A Tide of Riverscape 题意:给出一组字符串,由'0','1',' . '组成,' . '可以换成 0或1,判断第 i  个和第 i+p 个字符是否可以不相等,如果可以则输出 ...

  6. QFNU-ACM 2020.04.05个人赛补题

    A.CodeForces-124A (简单数学题) #include<cstdio> #include<algorithm> #include<iostream> ...

  7. 2020.12.3--vj个人赛补题

    A Vasya studies music.He has learned lots of interesting stuff. For example, he knows that there are ...

  8. 2020.12.20-Codeforces Round #105补题

    B - Escape The princess is going to escape the dragon's cave, and she needs to plan it carefully. Th ...

  9. 2020.11.14-pta天梯练习赛补题

    7-7 矩阵A乘以B 给定两个矩阵A和B,要求你计算它们的乘积矩阵AB.需要注意的是,只有规模匹配的矩阵才可以相乘.即若A有R​a​​行.C​a​​列,B有R​b​​行.C​b​​列,则只有C​a​​ ...

随机推荐

  1. C# - 音乐小闹钟_BetaV1.0

    时间:2017-11-20 作者:byzqy 介绍: 前段时间看到别人利用Timer控件实现了检查电脑本地时间,然后对时间进行比较,最终实现闹钟功能.感觉有点意思,于是自己也做了一个小闹钟! 先看一下 ...

  2. Python - 如何将 list 列表作为数据结构使用

    列表作为栈使用 栈的特点 先进后出,后进先出 如何模拟栈? 先在堆栈尾部添加元素,使用 append() 然后从堆栈顶部取出一个元素,使用 pop() # 模拟栈 stack = [1, 2, 3, ...

  3. Linux上使用设置printf显示的颜色

    我们经常看到别的屏幕五颜六色的很是羡慕,看着很炫是吧.其实我们也可以自己做一个简单的修改,是我们的显示结果也呈现出不同的颜色.shell脚本可能设置的比较多,但是我们平常使用C语言却很少设置它的颜色, ...

  4. FileWriter文件文件字符输出流写入存储数据

    1.FileWriter文件字符输出流-写入-存储数据 其中,流关闭之后再调用会报IOException; 其中,与文件字符输入流-写出-读取数据 和 字节输出流-写入-存储数据 不同的是,要先flu ...

  5. Activiti 学习(三)—— Activiti 流程启动并完成

    Activiti 流程启动 流程定义部署后,就可以通过工作流管理业务流程了,也就是说前文部署的出差申请流程可以使用了.针对该流程,启动一个流程表示发起一个新的出差申请单,这就相当于 java 类与 j ...

  6. Windows中nginx多次启动的问题

    在Windows上做开发环境中的nginx服务器.为了使nginx在后台运行,使用如下命令来启停nginx: cd <nginx安装目录> # 开启nginx并在后台运行 start ng ...

  7. 第二十次CSP考试有感

    这是第二次参加csp考试了,大二上学期参加了第17次csp,160分.刚刚下午结束了第20次csp,200分. 这次比赛规则和以往不同,以前可以携带纸质书籍和usb,提交上去的答案不能实时出成绩.现在 ...

  8. Shell系列(8)- 变量与变量分类(1)

    变量命名规则 开头为字符或下划线,名字中间中能有字母.数字和下划线组成; 变量的长度不超过255个字符; 变量名在有效的范围内必须是唯一的; 如再次定义则会替换上一个变量的值 在Bash中,变量的默认 ...

  9. fillder 抓包工具详解

    一.安装详解 直接点击.exe可执行文件,一直下一步直到安装完成即可.打开主要为5个部分: 二.安装jmeter插件详解 三.工具详解 3.1:工具条:,可以给指定的请求添加备注信息,在导出后可以查看 ...

  10. django class类即视图类添加装饰器的几种方法

    根据别人发布整理,个人爱好收集(原文:https://blog.csdn.net/mydistance/article/details/83958655 ) 第一种:定义函数装饰器,在函数,类中使用函 ...