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 T have 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 ≤ n, i ≠ 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.


-----Examples-----
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.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
s = input()
t = input()

def ff(ch):
    return ord(ch) - ord('a')

def answer(a, b, sc):
    print(cans + sc)
    print(a+1, b+1)
    return

cans = 0
matrix = [[None] * 26 for i in range(26)]
for i in range(n):
    matrix[ff(s[i])][ff(t[i])] = i
    if s[i] != t[i]:
        cans += 1

for i in range(26):
    for j in range(i):
        if matrix[i][j] is not None and matrix[j][i] is not None:
            answer(matrix[i][j], matrix[j][i], -2)

for i in range(26):
    for h in range(26):
        if h == i:
            continue
        for v in range(26):
            if v == i:
                continue
            if matrix[h][i] is not None and matrix[i][v] is not None:
                answer(matrix[h][i], matrix[i][v], -1)

answer(-2, -2, 0)


import sys
n = int(input())
a = input()
b = input()
l = 0
c = [[0 for j in range(26)] for i in range(26)]
for i in range(n):
    if a[i] != b[i]:
        l += 1
        c[ord(a[i]) - ord('a')][ord(b[i]) - ord('a')] = i+1

for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or c[j][i] == 0:
            continue
        print(l-2)
        print(c[i][j], c[j][i])
        return
for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or max(c[j]) == 0:
            continue
        print(l-1)
        print(c[i][j], end=' ')
        for k in range(26):
            if c[j][k] > 0:
                print(c[j][k])
        return
print(l)
print(-1, -1)


import unittest


def solve(S, T):
    pos_s = {}
    pos_t = {}
    wrongs = []
    distance = 0

    for i, (s, t) in enumerate(zip(S,T)):
        if s != t:
            pos_t[(s,t)] = i
            pos_s[s] = i
            wrongs.append((s,t,i))
            distance += 1

    for wrong, need, i in wrongs:
        j = pos_t.get((need, wrong))
        if j is not None:
            return (distance-2, i + 1, j + 1)

    for wrong, need, i in wrongs:
        if need in pos_s:
            return (distance-1, i + 1, pos_s[need] + 1)

    return distance, -1, -1



class Test_solution(unittest.TestCase):
    def test_case(self):
        self.assertEqual(solve("pergament", "permanent"), (1, 4, 6))
        self.assertEqual(solve("wookie", "cookie"), (1, -1, -1))
        self.assertEqual(solve("petr", "egor"), (2,1,2))
        self.assertEqual(solve("double", "bundle"), (2,1,4))
        self.assertEqual(solve("", ""), (0,-1,-1))


def __starting_point():
    #unittest.main()
    input()
    S = input()
    T = input()
    distance, i, j = solve(S, T)
    print(distance)
    print(i,j)

__starting_point()

alth = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
S = input()
T = input()
heming = 0
first = [-1] * 26
second = [-1] * 26
first_second = [-1] * 676
for i in range(n):
    if S[i] != T[i]:
        heming += 1
        temp = alth.find(S[i])
        temp2 = alth.find(T[i])
        first[temp] = i
        second[temp2] = i
        first_second[temp*26+temp2] = i
error_1 = 0
error_2 = 0
for i in range(676):
    temp = i % 26
    temp2 = i // 26
    if first_second[i] != -1 and first_second[temp * 26 + temp2]!= -1:
        error_1 = 1
        print(heming - 2)
        print(first_second[i]+1,first_second[temp * 26 + temp2]+1)
        break
if error_1 == 0:
    for i in range(26):
        if first[i] != -1 and second[i] != -1:
            error_2 = 2
            print(heming - 1)
            print(first[i]+1,second[i]+1)
            break
    if error_2 == 0:
        print(heming)
        print(-1,-1)


from pprint import pprint
from operator import itemgetter

def main():
    _ = int(input().strip())
    w1 = input().strip()
    w2 = input().strip()
    
    if len(w1) != len(w2):
        return -1
    
    hdis, fpos, lpos = one_replace_hamming(w1, w2)
    print(hdis)
    print(min(fpos + 1, lpos + 1), max(fpos + 1, lpos + 1))

def ham_wt(w1, w2):
    diff_pairs1 = []
    rev_assoc = dict()
    pos_indicator = dict()
    for i in range(len(w1)):
        if w2[i] != w1[i]:
            diff_pairs1.append((w1[i], w2[i]))
            rev_assoc[w2[i]] = w1[i]
            pos_indicator[w1[i], w2[i]] = i
    return (diff_pairs1, rev_assoc, pos_indicator)

def one_replace_hamming(w1, w2):
    diff_pairs, rev_assoc, pos_indicator = ham_wt(w1, w2)

    for fst, snd in diff_pairs:
        if fst in rev_assoc and rev_assoc[fst] == snd:
            return (len(diff_pairs) - 2, pos_indicator[fst, snd], pos_indicator[snd, fst])
    
    for fst, snd in diff_pairs:
        if fst in rev_assoc:
            return (len(diff_pairs) - 1, pos_indicator[fst, snd], pos_indicator[rev_assoc[fst], fst])
    
    
    return (len(diff_pairs), -2, -2)
        
    

def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python
# coding=utf-8

import sys
n = int(input())
a, b = input(), input()
l = 0
c = [[0 for j in range(26)] for i in range(26)]
for i in range(n):
    if a[i] != b[i]:
        l += 1
        c[ord(a[i]) - ord('a')][ord(b[i]) - ord('a')] = i + 1
for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or c[j][i] == 0:
            continue
        print(l - 2)
        print(c[i][j], c[j][i])
        return
for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or max(c[j]) == 0:
            continue
        print(l - 1)
        print(c[i][j], end = ' ')
        for k in range(26):
            if c[j][k] > 0:
                print(c[j][k])
        return
print(l)
print(-1, -1)


#!/c/Python34/python
# coding: utf-8
#Anser


def main():
    n = int(input())
    s, t = str(input()), str(input())
    p = [[0] * 26 for _ in range(26)]
    dist = 0

    for i in range(n):
        if s[i] != t[i]:
            j = ord(s[i]) - ord('a')
            k = ord(t[i]) - ord('a')
            p[j][k] = i + 1
            dist += 1

    for i in range(26):
        for j in range(26):
            if i != j and p[i][j] > 0 and p[j][i] > 0:
                print(dist-2)
                print(p[i][j], p[j][i])
                return

    for i in range(26):
        for j in range(26):
            if i != j and p[i][j] > 0 and max(p[j]) > 0:
                print(dist-1)

                for k in range(26):
                    if p[j][k] > 0:
                        print(p[i][j], p[j][k])
                        return

    print(dist)
    print(-1, -1)

def __starting_point():
    main()

__starting_point()

n, s, t = int(input()), input(), input()

t_dict = dict()
diffs = list()
res_i, res_j = -1, -1
res_d = 0

for i in range(n):
    if s[i] == t[i]:
        continue
    res_d += 1
    diffs.append(i)
    t_dict[t[i]] = i

perfect_swapped = False
swapped = False
for i in diffs:
    if s[i] not in t_dict:
        continue
    swapped = True
    res_i = i + 1
    j = t_dict[s[i]]
    res_j = j + 1
    if s[j] == t[i]:
        perfect_swapped = True
        break

print(res_d - (2 if perfect_swapped else 1 if swapped else 0))
print(res_i, res_j)


n, s, t = int(input()), input(), input()

t_dict = dict()
diffs = list()
res_i, res_j = -1, -1
res_d = 0

for i in range(n):
    if s[i] == t[i]:
        continue
    res_d += 1
    diffs.append(i)
    t_dict[t[i]] = i

perfect_swapped = False
swapped = False
for i in diffs:
    if s[i] not in t_dict:
        continue
    swapped = True
    res_i = i + 1
    j = t_dict[s[i]]
    res_j = j + 1
    if s[j] == t[i]:
        perfect_swapped = True
        break

print(res_d - (2 if perfect_swapped else 1 if swapped else 0))
print(res_i, res_j)


n,s,t = int(input()),input(),input()

d = {}
wrongs = []
ansD,ansI,ansJ = 0,-1,-1
for i in range(n) :
    if s[i]!=t[i] :
        ansD+=1
        wrongs.append(i)
        d[t[i]] = i

perfectSwapped = False
swapped = False
for i in wrongs :
    if s[i] in d :
        swapped = True
        ansI = i+1
        j = d[s[i]]
        ansJ = j+1
        if s[j]==t[i] :
            perfectSwapped = True
            break

print(ansD-(2 if perfectSwapped else 1 if swapped else 0))
print(ansI, ansJ)
        


import sys
n = int(input())
s = input()
t = input()

def ff(ch):
    return ord(ch) - ord('a')

def answer(a, b, sc):
    print(res + sc)
    print(a + 1, b + 1)
    return
    
matrix = [[None] * 26 for _ in range(26)]
res = 0

for i in range(len(s)):
    matrix[ff(s[i])][ff(t[i])] = i
    if s[i] != t[i]:
        res += 1

for i in range(26):
    for j in range(i):
        if matrix[i][j] is not None and matrix[j][i] is not None:
            answer(matrix[i][j], matrix[j][i], -2)

for i in range(26):
    for h in range(26):
        if h == i:
            continue
        for v in range(26):
            if v == i:
                continue
            if matrix[h][i] is not None and matrix[i][v] is not None:
                answer(matrix[h][i], matrix[i][v], -1)
                
answer(-2, -2, 0)

n=int(input())
s=input()
t=input()
q={}
osh=[]
rez1=0
rez2=-1
rez3=-1
for i in range(n):
    if s[i]!=t[i]:
        rez1+=1
        osh.append(i)
        q[t[i]]=i
p=False
sq=False
for i in osh:
    if s[i] in q:
        p=True
        rez2=i+1
        f=q[s[i]]
        rez3=f+1
        if s[f]==t[i]:
            sq=True
            break
print(rez1-(2 if sq else 1 if p else 0))
print(rez2,rez3)

n = int(input())
s = input()
t = input()
p = 0           #used as a pointer
dist = 0        #used as hamming distance
m = [[] for i in range(0,26)]
sr = []
while p < len(s):
    #print('...1')
    if s[p] != t[p]:
        m[ord(s[p])-ord('a')].append((t[p], p))
        dist += 1
    p += 1

#print(m)
p = 0
while p < len(s):
    #print('...2')
    if s[p] != t[p]:
        flag = False
        for i in sr:
            if i[0] == s[p] and i[1] == t[p]:
                flag = True
                break
        if flag == True:
            p += 1
            continue
        sr.append((s[p], t[p]))
        for i in m[ord(t[p]) - ord('a')]:
            if i[0] == s[p]:
                dist -= 2
                print(dist)
                print(p+1, i[1]+1)
                quit()
    p += 1

p = 0
while p < len(s):
    #print('...3')
    if s[p] != t[p]:
        if len(m[ord(t[p]) - ord('a')]) > 0:
            dist -= 1
            print(dist)
            print(p+1, m[ord(t[p]) - ord('a')][0][1]+1)
            quit()
    p += 1
print(dist)
print(-1, -1)

import sys
n = int(input())
a = input()
b = input()
l = 0
c = [[0 for j in range(26)] for i in range(26)]
for i in range(n):
    if a[i] != b[i]:
        l += 1
        c[ord(a[i]) - ord('a')][ord(b[i]) - ord('a')] = i+1

for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or c[j][i] == 0:
            continue
        print(l-2)
        print(c[i][j], c[j][i])
        return
for i in range(26):
    for j in range(26):
        if i == j or c[i][j] == 0 or max(c[j]) == 0:
            continue
        print(l-1)
        print(c[i][j], end=' ')
        for k in range(26):
            if c[j][k] > 0:
                print(c[j][k])
        return
print(l)
print(-1, -1)

# -*- coding: utf-8 -*-
"""
Created on Sat Mar 21 00:34:22 2015

@author: NEC-PCuser
"""

def solve(n, S, T):
    st = dict()
    ts = dict()
    s = dict()
    t = dict()
    dist = 0
    for i, (si, ti) in enumerate(zip(S, T), 1):
        if si != ti:
            st[si, ti] = i
            ts[ti, si] = i
            s[si] = i
            t[ti] = i
            dist += 1
    for key, i in st.items():
        if key in ts:
            j = ts[key]
            return dist - 2, min(i, j), max(i, j)
    for si, i in s.items():
        if si in t:
            j = t[si]
            return dist - 1, min(i, j), max(i, j)
    return dist, -1, -1

n = int(input())
S = input()
T = input()
dist, i, j = solve(n, S, T)
print(dist)
print(i, j)

import string

n, s, t = int(input()), input(), input()
x, i, j = 0, -1, -1
sc_dict = {c: set() for c in string.ascii_lowercase}
tc_dict = {c: set() for c in string.ascii_lowercase}
sti_dict, tsi_dict = dict(), dict()

for ci, sc, tc in zip(list(range(n)), s, t):
    if sc == tc:
        continue
    sc_dict[sc].add(tc)
    tc_dict[tc].add(sc)
    sti_dict[sc + tc] = ci
    tsi_dict[tc + sc] = ci
    x += 1

for c in string.ascii_lowercase:
    cs = sc_dict[c] & tc_dict[c]
    if not cs:
        continue
    c2 = cs.pop()
    x -= 2
    i = sti_dict[c + c2] + 1
    j = tsi_dict[c + c2] + 1
    break
else:
    for c in string.ascii_lowercase:
        if not sc_dict[c] or not tc_dict[c]:
            continue
        x -= 1
        i = sti_dict[c + sc_dict[c].pop()] + 1
        j = tsi_dict[c + tc_dict[c].pop()] + 1
        break

print(x)
print(i, j)


import string

n, s, t = int(input()), input(), input()
x, i, j = 0, -1, -1
sc_dict = {c: set() for c in string.ascii_lowercase}
tc_dict = {c: set() for c in string.ascii_lowercase}
sti_dict, tsi_dict = dict(), dict()

for ci, sc, tc in zip(list(range(n)), s, t):
    if sc == tc:
        continue
    sc_dict[sc].add(tc)
    tc_dict[tc].add(sc)
    sti_dict[sc + tc] = ci
    tsi_dict[tc + sc] = ci
    x += 1

for c in string.ascii_lowercase:
    cs = sc_dict[c] & tc_dict[c]
    if not cs:
        continue
    c2 = cs.pop()
    x -= 2
    i = sti_dict[c + c2] + 1
    j = tsi_dict[c + c2] + 1
    break
else:
    for c in string.ascii_lowercase:
        if not sc_dict[c] or not tc_dict[c]:
            continue
        x -= 1
        i = sti_dict[c + sc_dict[c].pop()] + 1
        j = tsi_dict[c + tc_dict[c].pop()] + 1
        break

print(x)
print(i, j)


#compute hamming distance
# mark indexes that differ
#m_benefit=0,s_i,s_j
#for each i in index
#   for each j in i+1
#       swap i & j and see what is the benefit
#       if benefit > m_benefit:
#           m_ben=ben
#           record m_i and m_j
#if m_ben = 0 then -1 -1 
#else distance-benefit and print s_i+1&s_j+1
diff = []
wrong_t = {}

def distance(n,s,t):
    count = 0
    for i in range(n):
        if s[i] != t[i]:
            diff.append(i)
            wrong_t[t[i]] = i
            count+=1
    return count

def minDistance():
    m_ben = 0
    m_i = -2
    m_j = -2
    for i in diff:
        v = wrong_t[s[i]] if (s[i] in wrong_t) else None
        if v != None:
            m_ben = 1
            m_i = i
            m_j = v
            if s[v] == t[i]:
                return (2,i,v)
    return (m_ben,m_i,m_j)

n = int(input())
s = input()
t = input()
d = distance(n,s,t)
m_ben,m_i,m_j = minDistance()
print(d - m_ben)
print("{0} {1}".format(m_i + 1,m_j + 1))



import time

class Profiler(object):
    def __enter__(self):
        self._startTime = time.time()

    def __exit__(self, type, value, traceback):
        print("Elapsed time: {:.3f} sec".format(time.time() - self._startTime))


n = int(input())
a = input()
b = input()
#a= 'x'*200000 +'ab'
#b= 'b'*200000 +'xx'
indexes = list()
d = {}
f1 = False
f2 = False
df = 0
i1 = 0
i2 = 0
#with Profiler() as p:
for i in range(n):
    if a[i] != b[i]:
        df += 1
        indexes.append(i)
        d[b[i]] = i
for i in indexes:
    if a[i] in d:
        f1 = True
        j = d[a[i]]
        i1 = i+1
        i2 = j+1
        if a[j] == b[i]:
            f2 = True
            break
if f2:
    print(str(df-2))
    print(i1.__str__() + ' ' + i2.__str__())
elif f1:
    print(str(df-1))
    print(i1.__str__() + ' ' + i2.__str__())
else:
    print(str(df))
    print('-1 -1')

def gao():
	n = int(input())
	a = input()
	b = input()
	mp = {}
	cnt = 0
	for i in range(n):
		if a[i] != b[i]:
			cnt += 1
			mp[(a[i], b[i])] = i + 1
	l = [chr(ord('a') + i) for i in range(26)]
	for i in l:
		for j in l:
			if (i, j) in mp and (j, i) in mp:
				print(cnt - 2)
				print(mp[(i, j)], mp[(j, i)])
				return
	for i in l:
		for j in l:
			for k in l:
				if (i, j) in mp and (j, k) in mp:
					print(cnt - 1)
					print(mp[(i, j)], mp[(j, k)])
					return
	print(cnt)
	print(-1, -1)


gao()


n=int(input())
s=input()
t=input()
dis=0
d=[[False for i in range(30)] for i in range(30)]
x=[[0 for i in range(30)] for i in range(30)]
for i in range(n):
	if s[i]!=t[i]:
		dis+=1
		d[ord(s[i])-ord('a')][ord(t[i])-ord('a')]=True
		x[ord(s[i])-ord('a')][ord(t[i])-ord('a')]=i+1
def progress():
	for i in range(26):
		for j in range(26):
			if (d[i][j]) and (d[j][i]):
				print("{}\n{} {}".format(dis-2,x[i][j],x[j][i]))
				return 0
	for i in range(26):
		for j in range(26):
			if d[i][j]:
				for t in range(26):
					if d[j][t]:
						print("{}\n{} {}".format(dis-1,x[i][j],x[j][t]))
						return 0
	print("{}\n{} {}".format(dis,-1,-1))
progress()




n = input()
s1,s2 = input(),input()
l1 = [[x,[s1[x],s2[x]]] for x in range(len(s1)) if s1[x] != s2[x]]
d1,d2 = dict([(y[1][0] + y[1][1],y[0]) for y in l1]),dict([(y[1][1] + y[1][0],y[0]) for y in l1])
ins = set(d1.keys()) & set(d2.keys())
if ins:
    e = ins.pop()
    print (len(l1) - 2)
    print (d1[e] + 1,d2[e] + 1)
    return
s1,s2 = dict([(y[1][0],y[0]) for y in l1]),dict([(y[1][1],y[0]) for y in l1])
ins = set(s1.keys()) & set(s2.keys())
if ins:
    e = ins.pop()
    print (len(l1) - 1)
    print (s1[e] + 1,s2[e] + 1)
    return
print (len(l1))
print (-1,-1)

n = input()
s1,s2 = input(),input()
l2,l3 = [],[]
l1 = [[l2.append((s1[x] + s2[x],x)),l3.append((s2[x] + s1[x],x))] for x in range(len(s1)) if s1[x] != s2[x]]
d1,d2 = dict(l2),dict(l3)
ins = set(d1.keys()) & set(d2.keys())
if ins:
    e = ins.pop()
    print (len(l1) - 2)
    print (d1[e] + 1,d2[e] + 1)
    return
s1,s2 = {y[0][0]:y[1] for y in l2},{y[0][1]:y[1] for y in l2}
ins = set(s1.keys()) & set(s2.keys())
if ins:
    e = ins.pop()
    print (len(l1) - 1)
    print (s1[e] + 1,s2[e] + 1)
    return
print (len(l1))
print (-1,-1)