赛前练习(百度之星资格赛及初赛真题+Codeforces(div2级别))

今夕何夕(日期问题)

 

今天是2017年8月6日,农历闰六月十五。

小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。

为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星期数一样?比如今天是8月6日,星期日。下一个也是星期日的8月6日发生在2023年。

小贴士:在公历中,能被4整除但不能被100整除,或能被400整除的年份即为闰年。

Input

第一行为T,表示输入数据组数。

每组数据包含一个日期,格式为YYYY-MM-DD。

1 ≤ T ≤ 10000

YYYY ≥ 2017

日期一定是个合法的日期
 

Output

对每组数据输出答案年份,题目保证答案不会超过四位数。

Sample Input

3
2017-08-06
2017-08-07
2018-01-01

Sample Output

2023
2023
2024
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int y,m,d,sum,same;
bool check(int y){
	if(y%400==0||y%100!=0&&y%4==0) return true;
	else return false;
}
bool judge(int yy,int mm,int dd){
	if(same==1) return false;//第一次判断的是自己same=1直接false返回
	else if(mm==m&&dd==d&&sum%7==0) return true;
	else return false;
}
void deal(){
	sum=0,same=1;
	int yy=y,mm=m,dd=d;
	while(!judge(yy,mm,dd)){
		same=0;
		dd++;
		sum++;
		if(check(yy)) a[2]=29;
		else a[2]=28;
		if(dd>a[mm]){
			dd=1;
			mm++;
			if(mm>12){
				mm=1;
				yy++;
			}
		}
	}
	printf("%04d\n",yy,mm,dd);                         
}
int main(){
	int n;
	cin>>n;
	while(n--){
		scanf("%d-%d-%d",&y,&m,&d);
		deal();
	}    
	return 0;
} 

 

 

 

 

度度熊的01世界(连通块+思维)

 

度度熊是一个喜欢计算机的孩子,在计算机的世界中,所有事物实际上都只由0和1组成。

现在给你一个n*m的图像,你需要分辨他究竟是0,还是1,或者两者均不是。

图像0的定义:存在1字符且1字符只能是由一个连通块组成,存在且仅存在一个由0字符组成的连通块完全被1所包围。

图像1的定义:存在1字符且1字符只能是由一个连通块组成,不存在任何0字符组成的连通块被1所完全包围。

连通的含义是,只要连续两个方块有公共边,就看做是连通。

完全包围的意思是,该连通块不与边界相接触。

Input

本题包含若干组测试数据。
每组测试数据包含:
第一行两个整数n,m表示图像的长与宽。
接下来n行m列将会是只有01组成的字符画。

满足1<=n,m<=100

Output

如果这个图是1的话,输出1;如果是0的话,输出0,都不是输出-1。

Sample Input

32 32
00000000000000000000000000000000
00000000000111111110000000000000
00000000001111111111100000000000
00000000001111111111110000000000
00000000011111111111111000000000
00000000011111100011111000000000
00000000111110000001111000000000
00000000111110000001111100000000
00000000111110000000111110000000
00000001111110000000111110000000
00000001111110000000011111000000
00000001111110000000001111000000
00000001111110000000001111100000
00000001111100000000001111000000
00000001111000000000001111000000
00000001111000000000001111000000
00000001111000000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000001111000000000011110000000
00000001111000000000011110000000
00000000111000000000011110000000
00000000111110000011111110000000
00000000111110001111111100000000
00000000111111111111111000000000
00000000011111111111111000000000
00000000111111111111100000000000
00000000011111111111000000000000
00000000001111111000000000000000
00000000001111100000000000000000
00000000000000000000000000000000
32 32
00000000000000000000000000000000
00000000000000001111110000000000
00000000000000001111111000000000
00000000000000011111111000000000
00000000000000111111111000000000
00000000000000011111111000000000
00000000000000011111111000000000
00000000000000111111110000000000
00000000000000111111100000000000
00000000000001111111100000000000
00000000000001111111110000000000
00000000000001111111110000000000
00000000000001111111100000000000
00000000000011111110000000000000
00000000011111111110000000000000
00000001111111111111000000000000
00000011111111111111000000000000
00000011111111111111000000000000
00000011111111111110000000000000
00000000001111111111000000000000
00000000000000111111000000000000
00000000000001111111000000000000
00000000000111111110000000000000
00000000000011111111000000000000
00000000000011111111000000000000
00000000000011111111100000000000
00000000000011111111100000000000
00000000000000111111110000000000
00000000000000001111111111000000
00000000000000001111111111000000
00000000000000000111111111000000
00000000000000000000000000000000
3 3
101
101
011

Sample Output

0
1
-1

题目分析:我们用cnt1代表1的连通块的个数,cnt0代表内层的0的连通块的个数,那么要识别出0,就要内层的cnt0=1且1的连通块的个数为1,要识别出1,那么就应该没有内层的连通块,且1的连通块个数为1。其余情况输出-1

注意只抓关键部分——只看1和内部0的连通块的个数,而不关心1外的0的连通块数

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int n,m,cnt1,cnt0,in;
char mp[105][105];
int vis[105][105];
int mov[4][2]= {0,1,0,-1,1,0,-1,0};
void dfs(int x,int y,char ch) {
	for(int i=0; i<4; i++) {
		int nx=x+mov[i][0];
		int ny=y+mov[i][1];
		if(nx>=n||nx<0||ny>=m||ny<0) {//如果它的下一步超出边界,那么它就是边界
			if(ch=='0') {
				in=0;
				continue;
			}
		}
		if(mp[nx][ny]==ch&&vis[nx][ny]==0) {//若字符相同且未被标记
			vis[nx][ny]=1;
			dfs(nx,ny,ch);
		}
	}
}
int main() {
	while(~scanf("%d%d",&n,&m)) {
		cnt1=cnt0=0;
		memset(mp,0,sizeof mp);
		memset(vis,0,sizeof vis);
		for(int i=0; i<n; i++)
			scanf("%s",&mp[i]);
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				if(!vis[i][j]) {
					if(mp[i][j]=='0') {
						in=1;
						vis[i][j]=1;
						dfs(i,j,mp[i][j]);
						if(in) cnt0++;
					} else if(mp[i][j]=='1') {
						vis[i][j]=1;
						dfs(i,j,mp[i][j]);
						cnt1++;
					}
				}
			}
		}
		if(cnt1!=1) cout<<"-1\n";//无论是1还是0,1的连通块的个数必定是1
		else {
			if(cnt0==0) cout<<"1\n";//1內不含0的连通块
			else if(cnt0==1) cout<<"0\n";//1内仅含一个0的连通块
			else cout<<"-1\n";
		}
	}
	return 0;
}

 

 

 

 

 

度度熊的王国战略(连通图)

 

度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族。

哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士。

所以这一场战争,将会十分艰难。

为了更好的进攻哗啦啦族,度度熊决定首先应该从内部瓦解哗啦啦族。

第一步就是应该使得哗啦啦族内部不能同心齐力,需要内部有间隙。

哗啦啦族一共有n个将领,他们一共有m个强关系,摧毁每一个强关系都需要一定的代价。

现在度度熊命令你需要摧毁一些强关系,使得内部的将领,不能通过这些强关系,连成一个完整的连通块,以保证战争的顺利进行。

请问最少应该付出多少的代价。

Input

本题包含若干组测试数据。

第一行两个整数n,m,表示有n个将领,m个关系。

接下来m行,每行三个整数u,v,w。表示u将领和v将领之间存在一个强关系,摧毁这个强关系需要代价w

数据范围:

2<=n<=3000

1<=m<=100000

1<=u,v<=n

1<=w<=1000

Output

对于每组测试数据,输出最小需要的代价。

Sample Input

2 1
1 2 1
3 3
1 2 5
1 2 4
2 3 3

Sample Output

1
3

题目分析:求隔断某些点需要的最小代价——未指出具体几个,只说最小,当然就是隔断一个点的情况了

但这题有特殊情况——隔断的两条边没有公共点即不合题意,但改代码也不失为一种解题策略,仅供参考

#include<bits/stdc++.h>
using namespace std;
vector<string> vs;
int num[3005];
int main() {
	int n,m,u,v,val;
	while(~scanf("%d%d",&n,&m)) {
		memset(num,0,sizeof num);
		for(int i=0; i<m; i++) {
			scanf("%d%d%d",&u,&v,&val);
			if(u==v) continue;
			num[u]+=val;
			num[v]+=val;
		}
		sort(num+1,num+1+n);//将领编号从一开始 
		cout<<num[1]<<endl;
	}
	return 0;
}

 

 

 

 

 

P1m2(二分)

 

度度熊很喜欢数组!

我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件:

1. 数组里面的元素都是非负整数。
2. 数组里面最大的元素跟最小的元素的差值不超过 1。

举例而言,[1,2,1,2][1,2,1,2] 是稳定的,而 [−1,0,−1][−1,0,−1] 跟 [1,2,3][1,2,3] 都不是。

现在,定义一个在整数数组进行的操作:

* 选择数组中两个不同的元素 a以及 b ,将 a 减去 2 ,以及将 b 加上 1 。

举例而言,[1,2,3][1,2,3] 经过一次操作后,有可能变为 [−1,2,4][−1,2,4] 或 [2,2,1][2,2,1] 。

现在给定一个整数数组,在任意进行操作后,请问在所有可能达到的稳定数组中,拥有最大的『数组中的最小值』的那些数组,此值是多少呢?

Input

输入的第一行有一个正整数 TT ,代表接下来有几组测试数据。

对于每组测试数据:
第一行有一个正整数 NN 。
接下来的一行有 NN 个非负整数 xixi ,代表给定的数组。

* 1≤N≤3×1051≤N≤3×105
* 0≤xi≤1080≤xi≤108
* 1≤T≤181≤T≤18
* 至多 11 组测试数据中的 N>30000N>30000

Output

对于每一组测试数据,请依序各自在一行内输出一个整数,代表可能到达的平衡状态中最大的『数组中的最小值』,如果无法达成平衡状态,则输出 −1−1 。

Sample Input

2
3
1 2 4
2
0 100000000

Sample Output

2
33333333

 

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int MAX=3e5;
ll a[MAX+5];
int n;
bool judge(ll mid){//你要求的是一个最小值 
	ll cnt1=0,cnt2=0;
	for(int i=0;i<n;i++){
		if(a[i]<mid) cnt1+=mid-a[i];//所有比mid小的至少要达到mid 
		else if(a[i]>mid) cnt2+=(a[i]-mid)/2;//所有比mid大的要达到mid或mid+1 
	}//注意这个状态一定会达到 
	if(cnt2>=cnt1) return true;
	return false;
}
int main() {
	int t;
	cin>>t;
	while(t--) {
		cin>>n;
		ll l=99999999,r=-1;
		for(int i=0; i<n; i++){
			scanf("%lld",&a[i]);
			l=min(l,a[i]);
			r=max(r,a[i]);
		}
		ll mid,sum=0;
		while(l<=r){
			mid=(l+r)>>1;
			if(judge(mid)) l=mid+1;
			else r=mid-1;
 		}
		cout<<(l+r)/2<<endl;
	}
	return 0;
}

 

 

 

 

 

King Moves(情况考虑)

 

The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king.

Check the king's moves here https://en.wikipedia.org/wiki/King_(chess).

King moves from the position e4

Input

The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.

Output

Print the only integer x — the number of moves permitted for the king.

Example

Input

e4

Output

8

思路:三种情况——四个点、除此之外的四条边上的点、剩下的点

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]=='a'&&s[1]=='8'||s[0]=='h'&&s[1]=='8'||s[0]=='a'&&s[1]=='1'||s[0]=='h'&&s[1]=='1') cout<<"3\n";
	else if(s[1]=='8'||s[1]=='1'||s[0]=='a'||s[0]=='h') cout<<"5\n";
	else cout<<"8\n";
	return 0;
} 

 

 

 

 

 

Optimal Point on a Line(“举一反三”的思维题目)

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.

The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.

Output

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

Example

Input

4
1 2 3 4

Output

2

思路:选一个点,使其他所有点到该点距离之和最小——选排序后位于中间位置的点

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm> 
#define ll long long
using namespace std;
const int MAX=3e5;
ll a[MAX+5];
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	if(n%2) cout<<a[n/2];
	else cout<<a[n/2-1];
	return 0;
}

 

 

 

 

 

Magic Odd Square(规律题)

Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

Input

The only line contains odd integer n (1 ≤ n ≤ 49).

Output

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

Examples

Input

1

Output

1

Input

3

Output

2 1 4
3 5 7
6 9 8

题意:将1到n个不同数字放到一个nn的方格里,并保证每行、列、主对角线之和为奇数。由于题目要求到n为奇数,并且两奇数相乘也为奇数,则1到n*n里面的奇数总数比偶数多1。

构造幻方——规律如图

 

#include<bits/stdc++.h>
using namespace std;
#define eps 1e-6
int mp[55][55];
int main() {
	int n,col,num=1;
	cin>>n;
	for(int i=1;i<=n/2;i++){//填上半部分奇数
		col=n/2+i;
		for(int j=n/2-i+2;j<=col;j++){
			mp[i][j]=num;
			num+=2;
		}
	}
	int cnt=0;
	for(int i=n/2+1;i<=n;i++){ //填下半部分奇数
		col=1+cnt;
		for(int j=col;j<=n-col+1;j++){
			mp[i][j]=num;
			num+=2;
		}
		cnt++;
	}
	num=2;
	for(int i=1;i<=n;i++){//补充偶数并直接输出
		for(int j=1;j<=n;j++){
			if(mp[i][j]==0){
				cout<<num<<' ';
				num+=2;
			} 
			else cout<<mp[i][j]<<' ';
		}
		cout<<endl;
	}
	return 0;
}

 

 

 

 

 

Fashion in Berland(读懂题就OK)

According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.

You are given a jacket with n buttons. Determine if it is fastened in a right way.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.

The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.

Output

In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".

Examples

Input

3
1 0 1

Output

YES

Input

3
1 0 0

Output

NO

题意:检查安全带是否系对(只有一个没系上或者当且仅当只有一个安全带并系上)

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
	int n,x;
	cin>>n;
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x==0) cnt0++;
		else if(x==1) cnt1++;
	}
	if(n==1&&cnt1==1||n>1&&cnt0==1) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
} 

 

 

 

 

 

s-palindrome(认真读题&查看样例)

Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.

English alphabet

You are given a string s. Check if the string is "s-palindrome".

Input

The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.

Output

Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.

Examples

Input

oXoxoXo

Output

TAK

Input

bod

Output

TAK

Input

ER

Output

NIE
#include<iostream>
#include<cstring>
#include<string>
#include<map>
using namespace std;
map<char,char> mp;
int main() {
	mp['A']='A';
	mp['b']='d';
	mp['d']='b';//样例已知
	mp['H']='H';
	mp['I']='I';
	mp['M']='M';
	mp['O']='O';
	mp['o']='o';
	mp['p']='q';//看图得知
	mp['q']='p';
	mp['T']='T';
	mp['U']='U';
	mp['V']='V';
	mp['v']='v';
	mp['W']='W';
	mp['w']='w';
	mp['X']='X';
	mp['x']='x';
	mp['Y']='Y';

	string s;
	cin>>s;
	int len=s.size();
	for(int i=0; i<=len/2; i++) {//前后比对是否“对称”即可
		if(mp[s[i]]!=s[len-1-i]) {
			cout<<"NIE\n";
			return 0;
		}
	}
	cout<<"TAK\n";
	return 0;
}

如果嫌输入的“匹配”太多,下例也是一种很好的选择  

          

 

 

 

 

Exponential notation(数据的处理——情况考虑)

You are given a positive decimal number x.

Your task is to convert it to the "simple exponential notation".

Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b.

Input

The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.

Output

Print the only line — the "simple exponential notation" of the given number x.

Examples

Input

16

Output

1.6E1

Input

01.23400

Output

1.234

Input

.100

Output

1E-1

Input

100.

Output

1E2

 

思路:分别找小数点的位置、从左数第一个非零数的位置、从右数第一个非零数的位置

  • 若小数点没有——放到字符串最后
  • 若左数第一位不为零的数没有则直接输出0
  • 输出第一位,若只有一位不输出’.‘
  • 做差判断科学计数法中的指数情况,指数为零不输出’E‘
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int main() {
	string s;
	getline(cin,s);
	int len=s.size();
	int l=-1,r=len-1,n=0,pos=-1;
	for(int i=0; i<len; i++) { //求小数点的位置
		if(s[i]=='.') {
			pos=i;
			break;
		}
	}
	if(pos==-1) pos=len;//如果没有小数点放在最后
	for(int i=0; i<len; i++) { //找左边第一个不是0的数的位置
		if(s[i]!='0'&&s[i]!='.') {
			l=i;
			break;
		}
	}
	for(int i=len-1; i>=0; i--) { //找右边第一个不是0的数的位置
		if(s[i]!='0'&&s[i]!='.') {
			r=i;
			break;
		}
	}
	if(l==-1) cout<<"0\n";
	else {
		if(pos>l)	n=pos-l-1; //指数为正数
		else n=pos-l; //指数为负数
		cout<<s[l];
		if(l!=r) cout<<'.';//若只有一位不输出'.'
		for(int i=l+1; i<=r; i++)
			if(s[i]!='.') cout<<s[i];//原来的'.'不输出
		if(n!=0) cout<<'E'<<n<<endl;
	}
	return 0;
}

 

 

 

 

 

Night at the Museum(贪心)

Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

Input

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.

Output

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Examples

Input

zeus

Output

18

Input

map

Output

35

Input

ares

Output

34

Note

 

To print the string from the first sample it would be optimal to perform the following sequence of rotations:

  1. from 'a' to 'z' (1 rotation counterclockwise),
  2. from 'z' to 'e' (5 clockwise rotations),
  3. from 'e' to 'u' (10 rotations counterclockwise),
  4. from 'u' to 's' (2 counterclockwise rotations).

In total, 1 + 5 + 10 + 2 = 18 rotations are required.

 

 注意区分何时贪心何时dp
因为每次旋转起点都取决于上一次地址(输入字符串即已知)故可用贪心

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main() {
	string s;
	int ans=0;
	cin>>s;
	char cur='a';
	for(int i=0; i<s.size(); i++) {
		ans+=min(abs(s[i]-cur),26-abs(s[i]-cur));
		cur=s[i];
	}
	cout<<ans;
	return 0;
}

 

 

 

 

 

Links and Pearls(情况判断)

A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.

You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.

Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.

Note that the final necklace should remain as one circular part of the same length as the initial necklace.

Input

The only line of input contains a string ss (3≤|s|≤1003≤|s|≤100), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.

Output

Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".

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

Examples

Input

-o-o--

Output

YES

Input

-o---

Output

YES

Input

-o---o-

Output

NO

Input

ooo

Output

YES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main() {
	string s;
	cin>>s;
	int cnt0=0,cnt1=0;
	for(int i=0; i<s.size(); i++) {
		if(s[i]=='-') cnt1++;
		else if(s[i]=='o') cnt0++;
	}
	if(cnt1==0||cnt0==0||cnt0==1) cout<<"YES\n";
	else if(cnt1%cnt0==0) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

 

 

 

 

 

Marlin(数据范围->思维)

The city of Fishtopia can be imagined as a grid of 44 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1)(1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4,n)(4,n). The second village is located at (4,1)(4,1) and its people love the Salmon pond at (1,n)(1,n).

The mayor of Fishtopia wants to place kk hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.

A person can move from one cell to another if those cells are not occupied by hotels and share a side.

Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

Input

The first line of input contain two integers, nn and kk (3≤n≤993≤n≤99, 0≤k≤2×(n−2)0≤k≤2×(n−2)), nn is odd, the width of the city, and the number of hotels to be placed, respectively.

Output

Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".

If it is possible, print an extra 44 lines that describe the city, each line should have nn characters, each of which is "#" if that cell has a hotel on it, or "." if not.

Examples

Input

7 2

Output

YES
.......
.#.....
.#.....
.......

Input

5 3

Output

YES
.....
.###.
.....
.....

这道题不存在NO的情况,都是YES。所以如果K是偶数就先放左边,如果K是奇数就从中间开始放;
题意:
有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民的活动地点是(4,n);
有一个村庄在(4,1),村民的活动地点是(1,n);
现在要修建k个宾馆,不能修建在边界上,问能否给出一种安排方案使得两个村庄的村民到他们各自的活动地点的最短路的条数相等。
思路:
画了几个实例就应该知道,无论n和k是多少,都可以构建出合理的方案,所以全是YES。
如果k为偶数,那么就上下对称,这个比较好构造;当k为奇数,我采用的是首先把第二排从中间开始向两边填满,然后第三排则是从中间一格的两边开始填。

#include<bits/stdc++.h>
using namespace std;
#define eps 1e-6
char mp[5][105];
int main() {
	int col,k,l,r;
	memset(mp,'.',sizeof mp);
	cin>>col>>k;
	if(k%2) {
		mp[2][col/2+1]='#';
		k--;
		l=col/2,r=col/2+2;
		while(l>1&&r<col&&k) {
			mp[2][l]=mp[2][r]='#';
			l--,r++;
			k-=2;
		}
		l=col/2,r=col/2+2;
		while(l>1&&r<col&&k) {
			mp[3][l]=mp[3][r]='#';
			l--,r++;
			k-=2;
		}
	} else {
		for(int j=2; j<=k/2+1; j++)
			mp[2][j]=mp[3][j]='#';
	}
	cout<<"YES\n";
	for(int i=1; i<=4; i++) {
		for(int j=1; j<=col; j++)
			cout<<mp[i][j];
		cout<<endl;
	}
	return 0;
}

 

 

 

 

 

Sasha and Sticks

It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.

Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 1018, k ≤ n) — the number of sticks drawn by Sasha and the number k — the number of sticks to be crossed out on each turn.

Output

If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).

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

Examples

Input

1 1

Output

YES

Input

10 4

Output

NO

Note

In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.

In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.

 数据范围要切记!!!

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	ll n,k;
	cin>>n>>k;
	ll turn=n/k;
	if(turn%2) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

 

 

 

 

 

 

Petya and Exam(思维)

It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..

There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.

Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.

Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.

A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.

The good letters are given to Petya. All the others are bad.

Input

The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.

The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once.

The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.

n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.

It is guaranteed that the total length of all query strings is not greater than 105.

Output

Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.

You can choose the case (lower or upper) for each letter arbitrary.

Examples

Input

ab
a?a
2
aaa
aab

Output

YES
NO

Input

abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax

Output

NO
YES
NO
YES

Note

In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.

Explanation of the second example.

  • The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
  • The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
  • The third query: "NO", because characters "?" can't be replaced with bad letters.
  • The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define eps 1e-6
int vis[200];
int main() {
	string good,bef,aft;
	int n;
	cin>>good;
	for(int i=0; i<good.size(); i++)
		vis[good[i]]=1;//标记“好字母”
	cin>>bef;
	int len1=bef.size();
	int havestar=0;
	for(int i=0; i<len1; i++) {//检查是否含*
		if(bef[i]=='*') {
			havestar=1;
			break;
		}
	}
	int flag,nowpos;
	cin>>n;
	while(n--) {
		flag=0,nowpos=0;
		cin>>aft;
		int len2=aft.size();
		if(havestar==0&&len1!=len2) { //若不含*且长度不等 No
			cout<<"No\n";
			continue;
		} else if(havestar==1&&len1-1>len2) { //若含*但长度-1(减掉*的长度,其最多出现一次) 大于len2 No
			cout<<"No\n";
			continue;
		}
		for(int i=0; i<len1; i++) {
			if(bef[i]=='?') {  //如果是问号但aft中不是好字母 No 
				if(vis[aft[i+nowpos]]==0)//为防止之前匹配过'*',增设变量nowaft为二者长度之差,以保证匹配对应 
					flag=1;
			}
			else if(bef[i]=='*') { //如果是*从此开始到i+len2-len1 必须都是坏字母 
				int tmp=len2-len1;
				nowpos=tmp;
				for(int j=i; j<=i+tmp; j++){
					if(vis[aft[j]]){
						flag=1;
						break;
					}
				}
			} else {  //为防止之前匹配过'*',增设变量nowaft为二者长度之差,以保证匹配对应 
				if(bef[i]!=aft[i+nowpos])
					flag=1;
			}
			if(flag) break;
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";
	}
	return 0;
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值