fork download
import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	static int MAX = 100010;
	static int f[] = new int[MAX];
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		f[1] = 2; 
		f[2] = 4; 
		f[3] = 7;
		for(int i = 4; i <= n; i++) {
			f[i] = (f[i-1] + f[i-2] + f[i-3]) % 12345;
		}
		System.out.println(f[n]);
	}
}
Success #stdin #stdout 0.06s 2184192KB
stdin
10000
stdout
8872