Correcting Mistakes

CodeForces - 533E

Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.

Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word.

Implement a program that can, given two distinct words S and T of the same length ndetermine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and Tconsist of lowercase English letters. Word W also should consist of lowercase English letters.

Input

The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T.

The second line contains word S.

The third line contains word T.

Words S and T consist of lowercase English letters. It is guaranteed that S and Tare distinct words.

Output

Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.

Examples

Input
7
reading
trading
Output
1
Input
5
sweet
sheep
Output
0
Input
3
toy
try
Output
2

Note

In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).

In the second sample test the two given words couldn't be obtained from the same word by removing one letter.

In the third sample test the two given words could be obtained from either word "tory" or word "troy".

题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。

sol:首先把首尾两端相等的去掉,容易发现答案最大是2,

一开始睿智了,写了个XJB玩意,只判了两个位置,就会被这样的卡掉

aaab

baaa

于是就爆枚两种情况,一是S1的[L,R-1]等于S2的[L+1,R],还有一种就是类比一下

/*
题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,p[N],ans=,l,r,len;
char S[][N];
inline void Jud(int o)
{
int i;
for(i=l;i<r;i++)
{
if(S[o][i]!=S[o^][i+]) return;
}
ans++;
}
int main()
{
int i;
R(n);
scanf("%s%s",S[]+,S[]+);
l=; r=n;
while(S[][l]==S[][l]) l++;
while(S[][r]==S[][r]) r--;
if(l==n+&&r==)
{
Wl((n+)*); return ;
}
// cout<<l<<" "<<r<<endl;
len=r-l+;
Jud();
Jud();
Wl(ans);
return ;
}
/*
input
4
aaab
baaa
output
1
*/

codeforces533E的更多相关文章

随机推荐

  1. [jquery]ajax最最常用的七个属性

    1.url 类型:String 默认值: 当前页地址.发送请求的地址. 2.data 类型:String 发送到服务器的数据.将自动转换为请求字符串格式.GET 请求中将附加在 URL 后.查看 pr ...

  2. (八)shiro之jdbcRealm

    pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...

  3. jvm的内存区域介绍

    什么是jvm? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的 ...

  4. What's new in C# 7.0

    1.数字分隔符(Digit Separators ) 数字分隔符使代码更具可读性.在声明变量时,可以将_添加到单独的数字中.编译器只删除_.以下代码片段在C#7中看起来更具可读性: In C# 6 l ...

  5. 3D数学基础_图形与游戏开发

    https://blog.csdn.net/popy007/article/list/2?t=1&  //向量计算相关文章 https://www.baidu.com/link?url=48C ...

  6. 利用Supervisor 管理自己部署的应用程序

    首先,在centos7下安装supervisor yum install python-setuptools easy_install supervisor 然后新建配置文件 #新建superviso ...

  7. require.js 加载 js 文件 404 处理(配置无效)

    main.js 是 配置文件,data-main 是异步加载,如果在main.js未加载完成的时候,使用了require去加载文件,就会导致配置无效  main.js

  8. 【Struts2】Json插件使用

    一.使用步骤 1.1 引入依赖 1.2 在struts.xml文件中配置 一.使用步骤 1.1 引入依赖 <!-- https://mvnrepository.com/artifact/org. ...

  9. vscode 插件备忘

    由于不喜欢嵌入式c语言开发IDE,所以一致就当IDE是编译器,编辑工作都是使用其他文本编辑器替代的,最开始使用source insight,但是乱码问题和新建工程的不便利(也许不太会用),让我很纠结, ...

  10. MySQL授权(用户权限)

    一.mysql查询与权限 (二)授权 用户管理: 设置用户密码 前期准备工作: 停止服务 将配置文件当中的skip-grant-tables删除掉 重启服务: 执行修改命令 查看用户状态(如果数据过多 ...