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. Unity插件研究-EasyTouch V5

    抽空研究了下Easy Touch 5插件,发现确实很好用,下面是相应的用法: 1. Easy Touch Controls:实现虚拟摇杆的组件 在项目的"Hierarchy"窗口下 ...

  2. hdu 2089 入手数位dp问题

    数位dp解决的问题是指求在一段数的区间里面 满足条件的数的个数 核心为两点 http://wenku.baidu.com/link?url=tpfIYzhx_MzevpIM58UZ66pr-87MCF ...

  3. nodejs入门API之path模块

    Path模块在各个系统上的差异 Path模块API解析 一.Path模块在各个系统上的差异 path模块提供用于处理文件路径和目录路径的使用工具. let path = require('path') ...

  4. javamail "535 5.7.3 Authentication unsuccessful" 问题排查

    有一家odm的服务器用Javamail发邮件的时候报错  Authentication unsuccessful  其他的有些又是正常的 网上查了一下解决方法如下 JavaMailSenderImpl ...

  5. selenium重定向新窗口

    1.跳转新窗口 # 浏览器跳转新窗口后,selenium绑定新窗口 print('页面跳转后重新绑定selenium.') time.sleep(3) search_window = driver.c ...

  6. 作为一个java高级工程师的进阶之路

    本文可能可能更偏向于是内心的独白篇和面试技巧总结 一.独白 之前也面试别人,现在轮到自己找工作,怎么说呢,每个面试官的看法不一样,面试的方式就不一样,比如我面试别人我喜欢问项目中他用到了那些,然后针对 ...

  7. mesos-master启动失败,报错Failed to load unknown flag 'quorum.rpmsave'

    [现象] mesos启动失败,查看mesos状态报错: [root@hps102 ~]# systemctl status mesos-master ● mesos-master.service - ...

  8. Codeforces Round #590 (Div. 3) 万恶的自己WAC

    C题:一道简单的C题卡了半天,我太菜了 题意:给你一个n*2的矩阵,每个位置有一个数字,对应一种管道,要求通道可不可以从左上通到右下 由提议可以看出,1,2对应的是直管道,3,4,5,6对应弯管道,只 ...

  9. 登录授权、TCP/IP、HTTPS

    今天继续纯理论的东东,比较枯燥,但是又很重要,坚持.. 登录和授权 登录和授权的区别: 登录:身份认证,即确认「你是你」的过程. 授权:由身份或持有的令牌确认享有某些权限(例如获取用户信息).登录过程 ...

  10. nuxt入门

    之前一直都是做vue-spa单页面,不利于SEO.而便于SEO的SSR(服务器端渲染)多页应用,可以使用nuxt.js这个框架来实现 (0)nuxt安装 npx create-nuxt-app < ...