Codeforces Round #512 (Div. 2) A B C D题解

传送门

A. In Search of an Easy Problem

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked nn people about their opinions. Each person answered whether this problem is easy or hard.

If at least one of these nn people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.

Input

The first line contains a single integer nn (1≤n≤1001≤n≤100) — the number of people who were asked to give their opinions.

The second line contains nn integers, each integer is either 00 or 11. If ii-th integer is 00, then ii-th person thinks that the problem is easy; if it is 11, then ii-th person thinks that the problem is hard.

Output

Print one word: "EASY" if the problem is easy according to all responses, or "HARD" if there is at least one person who thinks the problem is hard.

You may print every letter in any register: "EASY", "easy", "EaSY" and "eAsY" all will be processed correctly.

Examples

input

Copy

3
0 0 1

output

Copy

HARD

input

Copy

1
0

output

Copy

EASY

Note

In the first example the third person says it's a hard problem, so it should be replaced.

In the second example the problem easy for the only person, so it doesn't have to be replaced.

水题 不想多说。

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		int c;
		cin>>c;
		if(c==1)
		flag=1;
	}
	if(flag)
	cout<<"HARD"<<endl;
	else
	cout<<"EASY"<<endl;
	return 0;	
}

B. Vasya and Cornfield

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya owns a cornfield which can be defined with two integers nn and dd. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d)(0,d),(d,0),(n,n−d) and (n−d,n)(n−d,n).

An example of a cornfield with n=7n=7 and d=2d=2.

Vasya also knows that there are mm grasshoppers near the field (maybe even inside it). The ii-th grasshopper is at the point (xi,yi)(xi,yi). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers nn and dd (1≤d<n≤1001≤d<n≤100).

The second line contains a single integer mm (1≤m≤1001≤m≤100) — the number of grasshoppers.

The ii-th of the next mm lines contains two integers xixi and yiyi (0≤xi,yi≤n0≤xi,yi≤n) — position of the ii-th grasshopper.

Output

Print mm lines. The ii-th line should contain "YES" if the position of the ii-th grasshopper lies inside or on the border of the cornfield. Otherwise the ii-th line should contain "NO".

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

Examples

input

Copy

7 2
4
2 4
4 1
6 3
4 5

output

Copy

YES
NO
NO
YES

input

Copy

8 7
4
4 4
2 8
8 1
6 1

output

Copy

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 11 (coordinates (2,4)(2,4)) and 44 (coordinates (4,5)(4,5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 11 (coordinates (4,4)(4,4)), 33 (coordinates (8,1)(8,1)) and 44(coordinates (6,1)(6,1)) are inside the cornfield.

题意: 给你两个数n,d 然后根据给出的n,d 找到 (0,d),(d,0),(n,n−d),(n−d,n) 这四个点 连成一个图形。然后给你m个点

问你这些点是不是在这个图形之内,在 = YES 不在 =NO

题解:数学题求四条线的方程 然后判断

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	int maxx=max(n,d);
	int t;
	cin>>t;
	while(t--)
	{
		int a,b;
		cin>>a>>b;
		if(-a+d<=b&&-a+d+(n-d)*2>=b&&a+d>=b&&a-d<=b)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;	
}

C. Vasya and Golden Ticket

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Vasya found a golden ticket — a sequence which consists of nn digits a1a2…ana1a2…an. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178350178 is lucky since it can be divided into three segments 350350, 1717 and 88: 3+5+0=1+7=83+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.

Help Vasya! Tell him if the golden ticket he found is lucky or not.

Input

The first line contains one integer nn (2≤n≤1002≤n≤100) — the number of digits in the ticket.

The second line contains nn digits a1a2…ana1a2…an (0≤ai≤90≤ai≤9) — the golden ticket. Digits are printed without spaces.

Output

If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).

Examples

input

Copy

5
73452

output

Copy

YES

input

Copy

4
1248

output

Copy

NO

Note

In the first example the ticket can be divided into 77, 3434 and 5252: 7=3+4=5+27=3+4=5+2.

In the second example it is impossible to divide ticket into segments with equal sum.

题意:给你n位数 问相邻几位相加能否使他们值相等 举例 5 73452  7=3+4=5+2

题解:首先将所有位的数相加(sum) 然后从1->n看sum能够分成 i 个数 然后逐个判断 首先求他们组成n位的平均数 如果相邻几位相加大于平均数则不符合条件 如果等于平均数 继续查找

#include <iostream>
#include <string.h>
#define ll long long
using namespace std;
int a[150];
int main()
{
	int n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		a[i]=c-'0';
		sum+=a[i];
	}
	int flag=0; 
	for(int i=2;i<=n;i++)
	{
		if(sum%i==0)
		{
			int h=0;
			int flag1=0;
			for(int j=1;j<=n;j++)
			{
				h=h+a[j];
				if(h==sum/i)
				h=0;
				if(h>sum/i)
				{
					flag1=1;
					break;
				}
			}
			if(!flag1)
			flag=1;
		} 
	}
	if(flag)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;	
}

D. Vasya and Triangle

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has got three integers nn, mm and kk. He'd like to find three integer points (x1,y1)(x1,y1), (x2,y2)(x2,y2), (x3,y3)(x3,y3), such that 0≤x1,x2,x3≤n0≤x1,x2,x3≤n, 0≤y1,y2,y3≤m0≤y1,y2,y3≤m and the area of the triangle formed by these points is equal to nmknmk.

Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.

Input

The single line contains three integers nn, mm, kk (1≤n,m≤1091≤n,m≤109, 2≤k≤1092≤k≤109).

Output

If there are no such points, print "NO".

Otherwise print "YES" in the first line. The next three lines should contain integers xi,yixi,yi — coordinates of the points, one point per line. If there are multiple solutions, print any of them.

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

Examples

input

Copy

4 3 3

output

Copy

YES
1 0
2 3
4 1

input

Copy

4 4 7

output

Copy

NO

Note

In the first example area of the triangle should be equal to nmk=4nmk=4. The triangle mentioned in the output is pictured below:

In the second example there is no triangle with area nmk=167nmk=167.

题意:给你三个整数 n,m,k 面具为n*m/k是否能够在图中表示出来 如果能输出YES 并 任意输出满足的三个点 否则输出 NO

x*y/2=n*m/k

#include<iostream>  
#include<string> 
#include<algorithm> 
#define ll long long
using namespace std;
// x*y/2=n*m/k 
// 很明显 我们要将这三个点分别放在 原点 x轴 y轴上 
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	if((2*n*m)%k)// 若不能整除 则输出NO 
	{
		cout<<"NO"<<endl;
		return 0;
	}
	int flag=1;
	if(k%2==0)// 若k等够被2整除 则 x*y/2=n*m/(k/2) 
	k/=2;
	else
	flag=0;
	ll g=__gcd(n,k);// 将 x*y=n*m/k 化简  
	ll x=n/g;// 
	k/=g;
	ll y=m/k;
	if(!flag)
	{
		if(g>=2)
		// 如果一开始 并没有提前/2 则值大了 
		//且 x 或 y 中必定有一个能够被2整除 
		x=x*2;
		else
		y=y*2;
	}
	cout<<"YES"<<endl;
	cout<<0<<" "<<0<<endl;
	cout<<x<<" "<<0<<endl;
	cout<<0<<" "<<y<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值