Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and Thave different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.

Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.

Help him do this!

Input

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

The second line contains string S.

The third line contains string T.

Each of the lines only contains lowercase Latin letters.

Output

In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.

In the second line, either print the indexes i and j (1 ≤ i, j ≤ ni ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.

If there are multiple possible answers, print any of them.

Example

Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1

Note

In the second test it is acceptable to print i = 2, j = 3.

还是万年吐槽,这英语没救了。题目都看不懂的我和瞎子已经没有什么区别了。

题意:

给你两个长度为n的字符串,你有一次机会,将一个字符串的两个字母互换位置。

(要求:要使这两个字符串的元素不同的最少)

如果能互换使得不同之处变少,则输出互换后有多少个不同的元素,

并且输出所交换的元素的位置,如不能则输出-1 -1。

这题是一个非常灵活的思维题,如果思路简单则可以复杂度很小的求出答案。

如果是复杂的思路那就tle了。

这题亮点是用一个二维数组tu[30][30]去维护这两个字符串不同点。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char a[],b[];
int tu[][];
int main() {
while(scanf("%d%s%s",&n,a,b)!=EOF) {
int sum=;
memset(tu,,sizeof(tu));
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
tu[a[i]-'a'][b[i]-'a']=i+;
sum++;
}
}
int flag=;
if (flag) {
for (int i= ; i<n ; i++) {
if (a[i]!=b[i] && tu[b[i]-'a'][a[i]-'a']) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][a[i]-'a'],tu[a[i]-'a'][b[i]-'a']);
flag=;
break;
} }
}
if (flag) {
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
for (int j= ; j< ; j++) {
if (tu[b[i]-'a'][j]) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][j],i+);
flag=;
break;
}
}
if (flag==) break;
}
}
}
if (flag) printf("%d\n-1 -1\n",sum);
}
return ;
46}

Error Correct System CodeForces - 527B的更多相关文章

  1. CodeForces 527B Error Correct System

    Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  2. Codeforces Round #296 (Div. 2) B. Error Correct System

    B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Error Correct System(模拟)

     Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  4. CF Error Correct System

    Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. B. Error Correct System (CF Round #296 (Div. 2))

    B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. 【codeforces 527B】Error Correct System

    [题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...

  7. Codeforces Round #296 (Div. 2B. Error Correct System

    Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta ...

  8. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  9. codeforce Error Correct System

    题目大意: 给出两串n(1 ≤ n ≤ 200 000)个字母的字符串, 求出最多交换一对数, 使得不相同对数变少,求出不相同的对数以及交换的数的位置,若不需交换则输出-1,-1. 分析: 用矩阵记录 ...

随机推荐

  1. HEOI2016 题解

    HEOI2016 题解 Q:为什么要在sdoi前做去年的heoi题 A:我省选药丸 http://cogs.pro/cogs/problem/index.php?key=heoi2016 D1T1 树 ...

  2. ubunt tftp服务器搭建

    默认安装的Ubuntu系统没有包含TFTP的服务端和客户端,可以通过命令行来下载安装,步骤如下: (1)安装客户端. root@ www.linuxidc.com:~# apt-get install ...

  3. bootloader总体操作设计

    bootloarder设计蓝图(不想做设计师的程序员不是好程序员):bootloarder的作用:将linux内核启动起来设计方法:模仿u-bootu-boot:支持多种嵌入式cpu的bootloar ...

  4. mysql 修改默认字符集为utf8

    MySQL 5.5, all you need is: [mysqld] character_set_client=utf8 character_set_server=utf8 collation_s ...

  5. NOIP2017滚粗记

    NOIP2017滚粗记 扯淡 考完联赛后一直在搞文化... 联赛过去了不知道多少天了才来写这东西.... Day0 早自习知道了要期中考试. 感觉心态炸裂了. 上午在乱敲板子.... 打了一堆莫名其妙 ...

  6. 记一次 bug 修复 , 未将对象引用实例化

    我们对默认值的使用技巧中,同一个组件, 升级版本,增加新的配置字段,执行新的逻辑. 老版本,没有类似的配置字段,走原始逻辑. 在类的构造中,添加了这么一句代码, 运行后,报错,没看出问题原因: boo ...

  7. mac清除某个端口的占用

    lsof -i:8080查找某个应用的pid kill  pid就可以了

  8. Spring中的applicationContext.xml实现自动装配

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. java库中的具体的集合

    1.ArrayList  一种可以动态增长和缩减的索引序列:速度较慢适合用于不修改太多的元素    采用的数组 2.LinkEdList  一种可以在任何位置进行高效的插入和删除操作的有序序列,适合于 ...

  10. Windows下Nginx的启动、停止等基本命令

    在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍. 1.启动: C:\server\nginx-1.0 ...