CF #504 div2 A.B.C

A. Single Wildcard Pattern Matching

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two strings ss and tt. The string ss consists of lowercase Latin letters and at most one wildcard character '*', the string ttconsists only of lowercase Latin letters. The length of the string ss equals nn, the length of the string tt equals mm.

The wildcard character '*' in the string ss (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of ss can be replaced with anything. If it is possible to replace a wildcard character '*' in ss to obtain a string tt, then the string tt matches the pattern ss.

For example, if s=s="aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".

If the given string tt matches the given string ss, print "YES", otherwise print "NO".

Input

The first line contains two integers nn and mm (1≤n,m≤2⋅10^5) — the length of the string ss and the length of the string tt, respectively.

The second line contains string ss of length nn, which consists of lowercase Latin letters and at most one wildcard character '*'.

The third line contains string tt of length mm, which consists only of lowercase Latin letters.

Output

Print "YES" (without quotes), if you can obtain the string tt from the string ss. Otherwise print "NO" (without quotes).

Examples

input

6 10
code*s
codeforces

output

YES

input

6 5
vk*cup
vkcup

output

YES

input

1 1
v
k

output

NO

input

9 6
gfgf*gfgf
gfgfgf

output

NO

Note

In the first example a wildcard character '*' can be replaced with a string "force". So the string ss after this replacement is "codeforces" and the answer is "YES".

In the second example a wildcard character '*' can be replaced with an empty string. So the string ss after this replacement is "vkcup" and the answer is "YES".

There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".

In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string tt so the answer is "NO".

题目大意:给出2个串,第一个串里可能有*,对比2个串,若相同输出YES否则NO。*比较特殊,可以变成任何的字符串,空格也行。这个变什么由你决定。

思路:样例解释的非常清楚,所以顺着做就行了,没*号直接判断,有*号先顺次判断,然后倒着判断就行了。

代码如下:

#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
	int n,m,i,j;
	while(cin>>n>>m)
	{
		string s,t;
		int flag=0;
		int p=-1;
		cin>>s>>t;		
		for(i=0;i<n;i++)//顺序匹配 
		{
			if(s[i]=='*') {p=i;break;} 
			else{
				if(s[i]!=t[i])
					flag=1;
			}
			if(flag==1) break;//不匹配弹出 
		}		
		for(i=n-1,j=m-1;i>p;i--,j--)//逆序匹配 
		{
			if(s[i]!=t[j]) flag=1;//不匹配			
			if(flag==1) break;
		}		
		if(p==-1)//无星 
		{
			if(n!=m) flag=1;
		}
		else if(n-m>1) flag=1;		
		if(flag==0) cout<<"YES";
		else cout<<"NO";	
		cout<<endl;
	}
	return 0;
}

B. Pair of Toys

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Tanechka is shopping in the toy shop. There are exactly nn toys in the shop for sale, the cost of the ii-th toy is ii burles. She wants to choose two toys in such a way that their total cost is kk burles. How many ways to do that does she have?

Each toy appears in the shop exactly once. Pairs (a,b) and (b,a) are considered equal. Pairs (a,b), where a=b, are not allowed.

Input

The first line of the input contains two integers nn, kk (1≤n,k≤10^14) — the number of toys and the expected total cost of the pair of toys.

Output

Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is kk burles.

Examples

input

8 5

output

2

input

8 15

output

1

input

7 20

output

0

input

1000000000000 1000000000001

output

500000000000

Note

In the first example Tanechka can choose the pair of toys (1,4) or the pair of toys (2,3).

In the second example Tanechka can choose only the pair of toys (7,87,8).

In the third example choosing any pair of toys will lead to the total cost less than 2020. So the answer is 0.

In the fourth example she can choose the following pairs: (1,1000000000000), (2,999999999999), (3,999999999998)(3,999999999998), ..., (500000000000,500000000001). The number of such pairs is exactly 500000000000.

题目大意:给出2个数n,k。要求在1-n中取2个数ab,使a+b=k,问有多少种取法。(例如 n=8 k=15,则只有一种a=7,b=8(a=8 b=7算一种,且a!=b)。

思路:水题,稍微想一下就行。考虑2种情况,大于k/2和大于k。详情看代码吧。

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
	long long int n,k,i,j,s;
	cin>>n>>k;
	if(n<k/2) cout<<"0"<<endl;
	else {
		if(n>=k) n=k-1;
		cout<<n-k/2<<endl; 
	}
	return 0;
}

C. Bracket Subsequence

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given a regular bracket sequence ss and an integer number kk. Your task is to find a regular bracket sequence of length exactly kksuch that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Input

The first line contains two integers nn and kk (2≤k≤n≤2⋅10^5, both nn and kk are even) — the length of ss and the length of the sequence you are asked to find.

The second line is a string ss — regular bracket sequence of length nn.

Output

Print a single string — a regular bracket sequence of length exactly kk such that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Examples

input

6 4
()(())

output

()()

input

8 8
(()(()))

output

(()(()))

题目大意:给出这个字符串和a,b数字,a是字符串长度,b为所求子串长度。条件:使子串符合运算法则,操作:加1和+。

思路:搞不清楚题意,然后瞎搞了一发,就过了....过了.....

代码如下:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[200005];
int main()
{
  int k,n,a,b;
  while(~scanf("%d%d",&n,&k))
  {
    a=0,b=0;
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
	{
        if(s[i]=='('&&a<k/2)
	    {
            a++;
            printf("(");
        }
		else if(s[i]==')'&&b<k/2)
		{
           b++;
           printf(")");
        }
    }
    printf("\n");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/PleasantlY1/article/details/81806365