Arcadia Computing Contest 1 P3 - ScanTron

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

William is preparing for his AP exams and is doing a practice multiple-choice exam. He hurriedly scribbles through the exam, bubbling in his answers and then immediately handing it to his teacher without double-checking.

Unfortunately, in his haste, William forgot to bubble in exactly 1 answer, causing all subsequent answers to be shifted left by one position. Upon noticing this mistake, his teacher gives him a chance to correct it by identifying the question he skipped. He can then shift all answers from that point onward one position to the right. William, wanting to maximize his score, illegally obtains a copy of the answer key and his answers. He then looks to you to help him determine the maximum score he can get!

Constraints

All characters in both William's ScanTron and the answer key are either A, B, C, or D.

Subtask 1 [25%]

2 \leq N \leq 1000

Subtask 2 [75%]

2 \leq N \leq 10^6

Input Specification

The first line will contain a single integer N, the number of questions on the exam.

The second line will contain a string of length N, denoting the answer key to the exam.

The third and final line will contain a string of length N-1, denoting William's answers.

Output Specification

Output the maximum score William can obtain after correcting his mistake.

Sample Input 1

5
ABCDA
ACDA

Sample Output 1

4

Explanation for Sample 1

William points out that he missed question 2, and shifts all answers 1 position to the right. His ScanTron now looks like A_CDA, therefore getting him a score of 4 correct answers.

Sample Input 2

15
DACAABCACCAADBA
DCDBDADACCBDDC

Sample Output 2

5

Comments

There are no comments at the moment.