七月六日训练总结

补两道下午看过之后感觉可以过的题,但是上午比赛并没有过的题目

You are given an array aa consisting of nn integers.

You can remove at most one element from this array. Thus, the final length of the array is n−1n−1 or nn.

Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.

Recall that the contiguous subarray aa with indices from ll to rr is a[l…r]=al,al+1,…,ara[l…r]=al,al+1,…,ar. The subarray a[l…r]a[l…r] is called strictly increasing if al<al+1<⋯<aral<al+1<⋯<ar.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the ii-th element of aa.

Output

Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array aa after removing at most one element.

Examples

Input

5
1 2 5 3 4

Output

4

Input

2
1 2

Output

2

Input

7
6 5 4 3 2 4 3

Output

2

Note

In the first example, you can delete a3=5a3=5. Then the resulting array will be equal to [1,2,3,4][1,2,3,4] and the length of its largest increasing subarray will be equal to 44.

第一道就是这个b题,这个题目乍一眼看上去并没有什么难度,但是直接模拟就会面临解决边界的问题,即使废了半天劲解决了边界问题又会出现超时的问题,因为数据量是很大的。所以换一种思路解决这种最大数量的问题就需要动态规划。

可以设dp[i][j]为以第i个数为结尾删掉j个数的最长连续上升子序列的长度。

然后确定边界每个值初始为零即可,最后确定状态转移方程,会分为四种情况

1、(j=0 || j=1)&& a[i]>a[i-1]      dp[i][j]=dp[i-1][j]+1

2、j=0 && a[i]<=a[i-1]      dp[i][j]=1

3、j=1 && a[i]<=a[i-1]      dp[i][j]=1

4、j=1 && a[i]>a[i-2]      dp[i][j]=max(dp[i-2][j-1]+1,dp[i][j])     //这种情况就是跳过了某一个元素

#include<cstdio>
#include<iostream>
using namespace std;
int dp[200005][2],a[200005];
int ans;
int main()
{
	int n;
	cin>>n;
	for(int i=2;i<=n+1;++i)
		scanf("%d",a+i);
	for(int i=2;i<=n+1;++i)
	{
		if(a[i]>a[i-1])
			dp[i][0]=dp[i-1][0]+1;
		else
			dp[i][0]=1;
		if(a[i]>a[i-1])
			dp[i][1]=dp[i-1][1]+1;
		else
			dp[i][1]=1;
		if(a[i]>a[i-2])
		    dp[i][1]=max(dp[i][1],dp[i-2][0]+1);
		ans=max(ans,dp[i][0]);
		ans=max(ans,dp[i][1]);
	}
	cout<<ans<<endl;
	return 0;
}

 

Recently, Norge found a string s=s1s2…sns=s1s2…sn consisting of nn lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string ss. Yes, all n(n+1)2n(n+1)2 of them!

A substring of ss is a non-empty string x=s[a…b]=sasa+1…sbx=s[a…b]=sasa+1…sb (1≤a≤b≤n1≤a≤b≤n). For example, "auto" and "ton" are substrings of "automaton".

Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only kk Latin letters c1,c2,…,ckc1,c2,…,ck out of 2626.

After that, Norge became interested in how many substrings of the string ss he could still type using his broken keyboard. Help him to find this number.

Input

The first line contains two space-separated integers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 1≤k≤261≤k≤26) — the length of the string ss and the number of Latin letters still available on the keyboard.

The second line contains the string ss consisting of exactly nn lowercase Latin letters.

The third line contains kk space-separated distinct lowercase Latin letters c1,c2,…,ckc1,c2,…,ck — the letters still available on the keyboard.

Output

Print a single number — the number of substrings of ss that can be typed using only available letters c1,c2,…,ckc1,c2,…,ck.

Examples

Input

7 2
abacaba
a b

Output

12

Input

10 3
sadfaasdda
f a d

Output

21

Input

7 1
aaaaaaa
b

Output

0

Note

In the first example Norge can print substrings s[1…2]s[1…2], s[2…3]s[2…3], s[1…3]s[1…3], s[1…1]s[1…1], s[2…2]s[2…2], s[3…3]s[3…3], s[5…6]s[5…6], s[6…7]s[6…7], s[5…7]s[5…7], s[5…5]s[5…5], s[6…6]s[6…6], s[7…7]s[7…7].

这个题目求每一部分的子串和,也就是说策略就是找出连续的k字符有多长然后直接丢进题目给出的公式再丢进sum就行了,思路并不难,上午没做出来原因就是题意没看懂,然后误以为是很复杂的题目,其实这就是一道很简单的思维题目,并没有什么难的地方

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
string s,s1;
int a[105];
ll sum=0,num=0;

int main(){
	cin>>n>>k;
	cin>>s;
	while(k--){
		cin>>s1;
		a[s1[0]-'a']=1;
	}	
	for(int i=0;i<=n;i++){
		if(a[s[i]-'a']==1){
			num++;
		}else{
			sum = sum + num*(num+1)/2;
			num=0;
		}
	}
	cout<<sum;
	return 0;
}

其实做这个题跟平时做cf从简单到难这样做不同,刚开始两道题目说实话并没有那么简单,我看对应着d或者f题,就导致刚开始就卡住了,心态有点崩,做后面简单的题目也有点着急,没有合理安排好时间就导致出题数目并不多,结果也并不理想,还是希望不管怎样的顺序做题,总要相信这个题目按现在我已知的知识点是可以解决的,不能充满畏难的心理。

最后明天就是高考了,希望所有好考学子都可以考出理想成绩,这一路太不易,加油!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值