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. sqlite3 下载和安装步骤

    1 下载地址 https://www.sqlite.org/2019/sqlite-tools-win32-x86-3300100.zip 2 添加系统变量 path中添加  sqlite3.exe所 ...

  2. ASP.NET 使用 SyndicationFeed 输出 Rss

    以前生成 RSS 都是使用拼接 Xml 的方式生成的,不仅麻烦而且还不规范. #region 输出指定分类编号的消息源内容... /// <summary> /// 输出指定分类编号的消息 ...

  3. string和char*

    string转const char* string s = "hello furong."; const char *c = s.c_str(); string转char* str ...

  4. iOS开发 iOS10推送必看(基础篇)-转

    iOS10更新之后,推送也是做了一些小小的修改,下面我就给大家仔细说说.希望看完我的这篇文章,对大家有所帮助. 一.简单入门篇---看完就可以简单适配完了 相对简单的推送证书以及环境的问题,我就不在这 ...

  5. elementUI .native修饰符

    用第三方组件或者UI框架会自带自身封装的事件,如keyup等,会覆盖原生的组件而无法起效果 .native 修饰符就是用来注册元素的原生事件而不是组件自定义事件的 如elementUI的:<el ...

  6. SPFA找负环(DFS) luogu3385

    SPFA找负环的基本思路就是如果一个点被访问两次说明成环,如果第二次访问时所用路径比第一次短说明可以通过一直跑这个圈将权值减为负无穷,存在负环 有bfs和dfs两种写法,看了一些博客,在bfs和dfs ...

  7. c# Format() 方法

  8. 解决pynq联网问题

    注:本文只在一种环境下实验!不一定能适用很多环境 一.由于校园网的限制,pynq之间连接路由器存在无法联网的情况! 因此本文主要针对需要登录认证问题提供一种解决方案: 网络环境:校园网络 网络登录:锐 ...

  9. 用js刷剑指offer(二叉树的镜像)

    题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...

  10. 使用C#的Flags特性

    举个例子:我有如下的一个需求,当我想要取得用户信息的时候,会先从本地缓存中查找,找不到然后从分布式缓存中查找,最后找不到再从数据库中查询.但是有些场景我又不需要查询数据库. 所以我想建立如下这种模型. ...