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. The Heaviest Non-decreasing Subsequence Problem

    最长非递减子序列变形题,把大于等于10000的copy五次放回去就可以了 ac代码: #include <cstdio> #include <cstring> #include ...

  2. TeamCity安装和配置

    目录 TeamCity安装和配置 前言 持续集成(CI) TeamCity 环境 安装 配置TeamCity 项目构建 效果展示 TeamCity自动构建项目及集成IDEA(待更新......) 结束 ...

  3. C++ DLL debug版本在其他PC上缺少依赖的处理方式

    1.正常情况提供给其他人的都是Release版本DLL 2.在需要提供Debug版本时,目标机器上可能会缺少环境,或者和生成DLL的环境不匹配导致DLL无法加载,提示DLL无法找到. 3.使用DLL依 ...

  4. IDEA安装及默认配置习惯配置(二)

    安装完后,接下来配置Idea使用习惯. 一.基本使用 1.字体设置 2.修改编码模式 3.显示行号和方法分割线 4. 格式化代码时候多行空行合并为1行 5.代码提示不区分大小写 6.自动导包设置 7. ...

  5. sql 给相同属性的数据排序

    UPDATE b SET OrderIndex = a.OrderIndex FROM ( SELECT RTRIM(ROW_NUMBER() OVER ( PARTITION BY [ItemID] ...

  6. vscode 使用ESLint 自动检查,保存时自动格式化

    1:全局安装eslint `npm install -g eslint`2: 打开vscode 点击 “文件”----->“首选项”---->“设置”,在右侧“用户设置/settings. ...

  7. c# 引用与对象举例

  8. jdk在window系统中的配置

    其实配置很简单,百度上很多配置的复杂化了,今天办公室的某小白百度了半天也没有配置好.   我使用的是Linux ,就很多简单了很多编译器都是集成的,尤其是现在kali linux 系统觉得做得越来也好 ...

  9. 如何利用while语句根据用户输入要求打印菱形图案

    需求:如何利用while语句根据用户输入要求打印菱形图案 diamond.py代码如下: x=int(input('Please input number: ')) i=1 j=1 while i&l ...

  10. TCP、Http和Socket 优劣比较

    转自:http://www.cnblogs.com/webwlsong/p/3198712.html 了解HTTP和Socket之前先对网络7层协议有个了解: 7 应用层6 表示层5 会话层 4 传输 ...