Problem:
Score : 200 points

Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.

The first N characters equal to the string s.

The last N characters equal to the string t.

Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100

The lengths of s and t are both N.

s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5

The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2

The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4

The shortest string is expr.

Solution in Java7 (OpenJDK 1.7.0) (judge verdict: Runtime Error)

package Main;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	

	private static Scanner in;
	

	public static void main(String[] args)
	{
		
		in = new Scanner(System.in);
		BigInteger sum,y,x,nn;
		int viz[]= new int [300000];
		int i,n,yy,a = 0,b=0;
		
		 n=in.nextInt();
		 x=in.nextBigInteger();
		nn=BigInteger.valueOf(2).multiply(BigInteger.valueOf(n).subtract(BigInteger.valueOf(1)));
		 sum=(nn.multiply(nn.add(BigInteger.valueOf(1))));
		    y=sum.subtract(x.multiply((nn.multiply(BigInteger.valueOf(2))).subtract(BigInteger.valueOf(2))));
		    yy=y.intValue();
		    int ok;
		    ok=0;
		    if(yy%2==0)
		    	yy++;
		    if(yy>2*n-1)
		    {
		    	System.out.print("No\n");
		  		return;
		    }
		    
		    for(i=1;i<yy;i++)
		    {
		    	a=i;
		    	b=yy-i;
		    	if(a!=b)
		    	{
		    		ok=1;
		    		break;
		    	}
		    	}
		    
		  	if(ok==0)
		  	{
		  		System.out.print("No\n");
		  		return;
		  	}
		    System.out.print("Yes\n");
		   System.out.print(a+" ");
		   viz[a]=1;
		   viz[b]=1;
		   for(i=1;i<2*n;i++)
			   if(viz[i]==0)
				   System.out.print(i+" ");
		   System.out.print(b+" ");
		//System.out.println(" \n");
	}
	}