寒假-first-week

Calculate a+b

Input

Two integer a,b (0<=a,b<=10)

Output

Output a+b

Sample Input

1 2

Sample Output

3

解析:直接输出a+b

#include<iostream>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d",a+b);
 } 

假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。 

Input

输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数。然后是n行数据,每行包括m个整数(即:考试分数)。 

Output

对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数;第二行包含m个数据,表示m门课的平均成绩,结果保留两位小数;第三行是一个整数,表示该班级中各科成绩均大于等于平均成绩的学生数量。 
每个测试实例后面跟一个空行。 

Sample Input

2 2
5 10
10 20

Sample Output

7.50 15.00
7.50 15.00
1

解析:这个题注意格式就可以了,每个样例之间多加一个换行;每行最后没有多余的空格。

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 54
struct node{
	int a[5];
	double avers;
	int sum = 0;
}s[maxn];
double aver[5];
int main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		memset(s,0,sizeof(s));
		memset(aver,0,sizeof(aver));
		int sumcourse[5] = {0};
		for(int i = 0; i < n; i ++)
	{
		for(int j = 0; j < m; j ++)
		{
			scanf("%d",&s[i].a[j]);
			s[i].sum += s[i].a[j];
			sumcourse[j] += s[i].a[j];
		}
	}
	for(int i = 0; i < n; i ++)
	{
		s[i].avers = 1.0*s[i].sum/m;
		if(i!=n-1)
			printf("%.2lf ",s[i].avers);
		else
			printf("%.2lf\n",s[i].avers);
	}
	for(int i = 0; i < m; i ++)
	{
		aver[i] = 1.0*sumcourse[i]/n;
		if(i!=m-1)
			printf("%.2lf ",aver[i]);
		else
			printf("%.2lf\n",aver[i]);
	}
	int count = 0;
	for(int i = 0; i < n; i ++)
	{
		int flag = 0;
		for(int j = 0; j < m; j ++)
		{
			if(s[i].a[j]<aver[j])
				flag = 1;
		}
		if(!flag)
			count++;
	}
	printf("%d\n\n",count);
	}

	
 } 

有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?

Input

输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。 
n=0表示输入数据的结束,不做处理。

Output

对于每个测试实例,输出在第n年的时候母牛的数量。 
每个输出占一行。

Sample Input

2
4
5
0

Sample Output

2
4
6

解析:设一岁的小牛为a,两岁的小牛为b,三岁的小牛为c,成年母牛为d;

            所以前四年母牛的数量就是年份。

            从第五年开始 a = b =c =d = 1; n = n -4

           b = a;c =b;d=c+d;a = d;

#include<iostream>
using namespace std;
int main()
{
	int n;
	
	while(~scanf("%d",&n)&&n)
	{
		int a = 1,b = 1,c = 1,d = 1;
		if(n<=4)
			printf("%d\n",n);
		else
		{
			for(int i = 1; i <= n-4; i ++)
			{
			d = c+d;
			c = b;
			b = a;
			a = d; 
			 
			}
			printf("%d\n",a+b+c+d);
		}
		
	}
}

有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序。

Input

输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束,本行不做处理。

Output

对于每个测试实例,输出插入新的元素后的数列。

Sample Input

3 3
1 2 4
0 0

Sample Output

1 2 3 4

解析:插入后排序输出

#include<iostream>
#include<algorithm>
using namespace std;
int a[1005];
int main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		if(!m&&!n)
			break;
		for(int i = 0; i < n; i ++)
			scanf("%d",&a[i]);
		a[n] = m;
		sort(a,a+n+1);
		for(int i = 0; i <= n; i ++)
		{
			if(i != 0)
				printf(" %d",a[i]);
			else
				printf("%d",a[i]);
		}
		printf("\n");
	}
}

输入n(n<=100)个整数,按照绝对值从大到小排序后输出。题目保证对于每一个测试实例,所有的数的绝对值都不相等。

Input

输入数据有多组,每组占一行,每行的第一个数字为n,接着是n个整数,n=0表示输入数据的结束,不做处理。 

Output

对于每个测试实例,输出排序后的结果,两个数之间用一个空格隔开。每个测试实例占一行。

Sample Input

3 3 -4 2
4 0 1 2 -3
0

Sample Output

-4 3 2
-3 2 1 0

解析:用结构体

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
struct node{
	int a;
	int b;
}s[106];
int cmp(struct node x,struct node y)
{
	return x.b > y.b;
}
int main()
{
	int n;
	while(~scanf("%d",&n)&&n)
	{
		memset(s,0,sizeof(s));
		for(int i = 0; i < n; i ++)
		{
			scanf("%d",&s[i].a);
			if(s[i].a < 0)
				s[i].b = -s[i].a;
			else
				s[i].b = s[i].a;
		}
		sort(s,s+n,cmp);
		for(int i = 0; i < n; i ++)
		{
			if(i!=n-1)
				printf("%d ",s[i].a);
			else
				printf("%d\n",s[i].a);
		}
	}
}

作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵 
但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每个老师的工资额都知道,最少需要准备多少张人民币,才能在给每位老师发工资的时候都不用老师找零呢? 
这里假设老师的工资都是正整数,单位元,人民币一共有100元、50元、10元、5元、2元和1元六种。 

Input

输入数据包含多个测试实例,每个测试实例的第一行是一个整数n(n<100),表示老师的人数,然后是n个老师的工资。 
n=0表示输入的结束,不做处理。 

Output

对于每个测试实例输出一个整数x,表示至少需要准备的人民币张数。每个输出占一行。 

Sample Input

3
1 2 3
0

Sample Output

4

解析:贪心

#include<iostream>
using namespace std;
int a[6] = {100,50,10,5,2,1};
int main()
{
	int n;
	while(~scanf("%d",&n)&&n)
	{	
		int count = 0;
		for(int i = 0; i < n; i ++)
		{
			int x;
			scanf("%d",&x);
			int j = 0;
			while(x>0)
			{
				if(x>=a[j])
				{
					x -= a[j]; 
					count++;
				}
				else 
					j++;
			}
		}
			
		printf("%d\n",count);
	}

输入一个字符串,判断其是否是C的合法标识符。 

Input

输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。 

Output

对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。 

Sample Input

3
12ajf
fi8x_a
ff  ai_2

Sample Output

no
yes
no

解析:字符串问题

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		getchar();
		while(n--)
		{
			string s;
			getline(cin,s);
			int flag = 0;
			if(s[0]=='_'||(s[0]>='a'&&s[0]<='z')||(s[0]>='A'&&s[0]<='Z'))
			{
				for(int i = 1; i < s.length(); i ++)
				{
					if(s[i]=='_'||(s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||s[i]>='0'&&s[i]<='9')
						continue;
					else
					{
						flag = 1;
						break;
					}
				}
				if(flag)
					printf("no\n");
				else
					printf("yes\n");
			}
			else
			{
				printf("no\n");
				continue;
			}
		}
	}
}

输入一个英文句子,将每个单词的第一个字母改成大写字母。 

Input

输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。 

Output

请输出按照要求改写后的英文句子。 

Sample Input

i like acm
i want to get an accepted

Sample Output

I Like Acm
I Want To Get An Accepted
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	char a[105];
	while(cin.getline(a,105))
	{
		
		printf("%c",a[0]-'a'+'A');
		for(int i = 1; i < strlen(a); i ++)
		{
			if(a[i]!=' '&&a[i-1]==' ')
			{
				a[i] = a[i] - 'a' + 'A';
				printf("%c",a[i]);
			}
			else
				printf("%c",a[i]);
		}
		printf("\n");
	}
}

Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.

The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.

Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color xx such that there are currently at least two puppies of color xx and recolor all puppies of the color xx into some arbitrary color yy. Luckily, this operation can be applied multiple times (including zero).

For example, if the number of puppies is 77 and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose xx='c' right now, because currently only one puppy has the color 'c'.

Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of puppies.

The second line contains a string ss of length nn consisting of lowercase Latin letters, where the ii-th symbol denotes the ii-th puppy's color.

Output

If it's possible to recolor all puppies into one color, print "Yes".

Otherwise print "No".

Output the answer without quotation signs.

Examples

Input

6
aabddc

Output

Yes

Input

3
abc

Output

No

Input

3
jjj

Output

Yes

Note

In the first example Slava can perform the following steps:

  1. take all puppies of color 'a' (a total of two) and recolor them into 'b';
  2. take all puppies of color 'd' (a total of two) and recolor them into 'c';
  3. take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.

In the second example it's impossible to recolor any of the puppies.

In the third example all the puppies' colors are the same; thus there's no need to recolor anything.

解析:如果此字符串有两个及两个以上相同的字母,那么输出yes.

还有特判n=1;

#include<iostream>
#include<cstring>
#include<algorithm>
#include<string.h>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n;
	int a[26]={0};
	scanf("%d",&n);
	getchar();
	char s[100005];
	cin>>s; 
	int flag = 0;
	for(int i = 0; i < strlen(s); i ++)
	{
		a[s[i]-'0']++;
		if(a[s[i]-'0']>=2)
		{
			flag = 1;
			break;
		}
	}	
	if(flag||n==1)
		printf("Yes\n");
	else
		printf("No\n");
}

Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.

There are nn flowers in a row in the exhibition. Sonya can put either a rose or a lily in the ii-th position. Thus each of nn positions should contain exactly one flower: a rose or a lily.

She knows that exactly mm people will visit this exhibition. The ii-th visitor will visit all flowers from lili to riri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.

Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

Input

The first line contains two integers nn and mm (1≤n,m≤1031≤n,m≤103) — the number of flowers and visitors respectively.

Each of the next mm lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n), meaning that ii-th visitor will visit all flowers from lili to riri inclusive.

Output

Print the string of nn characters. The ii-th symbol should be «0» if you want to put a rose in the ii-th position, otherwise «1» if you want to put a lily.

If there are multiple answers, print any.

Examples

Input

5 3
1 3
2 4
2 5

Output

01100

Input

6 3
5 6
1 4
4 6

Output

110010

解析:其实是一个贪心,只要达到最优即可,最优的条件就是1、0交替

#include<iostream>
using namespace std;
int main()
{
	int n,m;
	int l,r;
	scanf("%d %d",&n,&m);
	for(int i = 0; i < m; i ++)
		scanf("%d %d",&l,&r);
	for(int i = 0; i < n; i ++)
		if(i%2)
			printf("1");
		else
			printf("0");
	printf("\n");
 } 

You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

Input

The first line contains a single positive integer n (2 ≤ n ≤ 105).

The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Output

Print "Yes" if there is such a point, "No" — otherwise.

You can print every letter in any case (upper or lower).

Examples

Input

3
1 1
-1 -1
2 -1

Output

Yes

Input

4
1 1
2 2
-1 1
-2 2

Output

No

Input

3
1 2
2 1
4 60

Output

Yes

Note

In the first example the second point can be removed.

In the second example there is no suitable for the condition point.

In the third example any point can be removed.

解析:根据四个象限,来判断。如果y右边的两个象限的数量和y左边的两个象限的数量均大于2,那么不存在这种去掉某个点就可以实现的情况。

#include<iostream>
using namespace std;
int rights,lefts;
int main()
{
	int n;
	scanf("%d",&n);
	
	for(int i = 0; i < n; i ++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		if(x>0&&y>=0||x>0&&y<=0)
			rights++;
		else if(x<0&&y<=0||x<0&&y>=0)
			lefts++;
	}
	if(lefts>=2&&rights>=2)
		printf("No\n");
	else
		printf("Yes\n");
}

Pig is visiting a friend.

Pig's house is located at point 0, and his friend's house is located at point m on an axis.

Pig can use teleports to move along the axis.

To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.

Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds.

Determine if Pig can visit the friend using teleports only, or he should use his car.

Input

The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house.

The next n lines contain information about teleports.

The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where aiis the location of the i-th teleport, and bi is its limit.

It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n).

Output

Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).

Examples

Input

3 5
0 2
2 4
3 5

Output

YES

Input

3 7
0 4
2 5
6 7

Output

NO

Note

The first example is shown on the picture below:

Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.

The second example is shown on the picture below:

You can see that there is no path from Pig's house to his friend's house that uses only teleports.

解析:建一个二维数组,可以通过的两个点设为1,其余设为0,最后判断从起点到终点能否一直是1.断了则表示不能到达,否则可以到达。

#include<iostream>
using namespace std;
int a[105][105];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0; i < n; i ++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		for(int j = l; j < r; j ++)
			a[j][j+1] = 1;
	}
	int flag = 0;
	for(int i = 0; i < m; i ++)
		if(!a[i][i+1])
		{
			flag = 1;
			break;
		} 
	if(!flag)
		printf("YES\n");
	else
		printf("NO\n")	;
}

Tonio has a keyboard with only two letters, "V" and "K".

One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.

Input

The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.

Output

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

Examples

Input

VK

Output

1

Input

VV

Output

1

Input

V

Output

0

Input

VKKKKKKKKKVVVVVVVVVK

Output

3

Input

KVKV

Output

1

Note

For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.

For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.

For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.

解析:至多改变一个,可以得到的最大vk数目。

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int a[100005];
int main()
{
	string s;
	getline(cin,s); 
	int len = s.length();
	if(len==1)
	{
		printf("0\n");
		return 0;
	}
	int count = 0;
	int flag = 0;
	for(int i = 0; i < len-1; i ++)
	{
		if(s[i]=='V'&&s[i+1]=='K')
		{
			a[i] = a[i+1] = 1;
			count++;
			i++;
		}
	}
	for(int i = 0; i < len-1; i ++)
	{
		if((s[i]=='V'||s[i+1]=='K')&&a[i]==0&&a[i+1]==0)  
           {  
               count++;  
               break;  
           }  
	}
	printf("%d",count);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值