Lonely String

0

0 votes
Medium
Problem

String Valentino is super lonely today and therefore he decides to fall in love with other strings. Valentino wants to calculate a value called SUM, which is initially 0. He has 2 strings s1 and s2.

Now Valentino takes both the strings (s1 and s2) and adds 1 to his SUM, if the corresponding elements are not equal, otherwise he adds 0.

The 1st string s1 is made by repeating string a , p number of times. The 2nd string s2 is made by repeating string b , q number of times.

Help Valentino in calculating SUM.

Input The first line contains two integers p and q (1 ≤ p, q ≤ 10^11). The second line contains a non-empty string a. The third line contains a non-empty string b.

a and b will always have < 2*10^6 characters.

It will be made sure that strings s1 and s2 will always have the same length. a and b will always consist of lower case alphabets .

Output Print the value of SUM

Sample Input
2 3
apa
xp
Sample Output
5
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

s1 = apaapa and s2 = xpxpxp. Only the second character is same. Therefore SUM = 1+0+1+1+1+1 = 5

Editor Image

?