Problem:
Score : 800 points

Problem Statement

Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.

Constraints

1 \leq N \leq 3000

1 \leq X \leq 2N

N and X are integers.

Input

Input is given from Standard Input in the following format:

N X

Output

Print the number, modulo 998244353, of sequences that satisfy the condition.

Sample Input 1

3 3

Sample Output 1

14

14 sequences satisfy the condition: (0,0,0),(0,0,1),(0,0,2),(0,1,0),(0,1,1),(0,2,0),(0,2,2),(1,0,0),(1,0,1),(1,1,0),(2,0,0),(2,0,2),(2,2,0) and (2,2,2).

Sample Input 2

8 6

Sample Output 2

1179

Sample Input 3

10 1

Sample Output 3

1024

Sample Input 4

9 13

Sample Output 4

18402

Sample Input 5

314 159

Sample Output 5

459765451

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

    /* package whatever; // don't place package name! */
     
    import java.util.*;
    import java.lang.*;
    import java.io.*;
     
    /* Name of the class has to be "Main" only if the class is public. */
   public class Main
    {
    	public static void main (String[] args) throws java.lang.Exception
    	{
    	 Scanner s = new Scanner(System.in);
       int len = s.nextInt();
       int target = s.nextInt();
       List<Integer> l = new ArrayList<Integer>();
       List<List<Integer>> result = new ArrayList<>();
       getSeq(l,result,len,target,0,0);
       System.out.print(result.size());
     }
      static void getSeq(List<Integer> l, List<List<Integer>> result, int len, int target, int sum, int srtlen){
     
     int revsum =0;
       
     
        if(sum==target){
         return; 
        }
     
     for(int j=l.size()-1; j>=0; j--){
     	revsum = revsum + l.get(j);
     	if(revsum == target){
     		return;
     	}
     }
        if(srtlen ==len){
         
         
          result.add(new ArrayList<>(l));
          return;
          
        }
     
        for(int i=0; i<=2 && srtlen<=len; i++){
          l.add(i);
          getSeq(l,result,len,target, i+sum,srtlen + 1);
          l.remove(l.size()-1);
        }
     
      }
    }