CodeChef: Codechef
Site under maintenance
  • Register
  • Forgot Password?
  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • August Mini Challenge
    • August Algorithm Challenge
    • July Algorithm Challenge
    • June Algorithm Challenge
    • May Gamers Challenge
  • DISCUSS
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef TechTalks
    • CodeChef Meetups
    • Campus Chapters
    • Host Your Contest
    • User Groups
  • HELP
    • Frequently Asked Questions
    • FAQ for Problem Setters
    • Tutorial: Paying Up
    • Tutorial: Small Factorials
    • Tutorial: Input and Output(I/O)
    • Tutorial: Your First Non-Trivial Problem
  • ABOUT
    • About CodeChef
    • About Directi
    • CEO's Corner
    • Press Room
    • Careers

Home » Problems (medium) » Chess Pushing Game

Chess Pushing Game

Problem code: CHESSGM

  • Submit
  • All submissions

All submissions for this problem are available.

Dave is playing a game with three pawns on a long board. The board can be seen as an (semi-)infinitely long sequence of grid squares numbered starting from 0 with width 3. Thus, the squares on the board can be referred to using (i,j) where i >= 0 and j = 0, 1 or 2. For this problem, the distance between two pawns is the distance along the first coordinate. For example, distance between pawns at (0,2) and (10,0) is 10.

The pawns are numbered 0, 1 and 2. Pawn j starts off at square (0, j) initially. In one move, a pawn can move one square to the right (increasing first coordinate, while second coordinate remains same). For example, a pawn can move from (4, 2) to (5,2). Another restriction is that if p < q, then pawn q can never be to the right(higher first coordinate) of pawn p. Yet another restriction is that at any point of time, pawns p and p+1 (for p=0 or p=1) should not be separated by a distance more than D.

At the end of K moves, all the pawns should end up at the same first coordinate. Dave wants to know how many ways there are to complete this game. Help him!

Input

The first and only line contains two integers D, K (0 ≤ D ≤ 7; 0 ≤ K ≤ 109).

Output

Output an only integer which is the result calculated, by modulo of 1,000,000,007.

Example

Input:
1 3
Output:
1

Input:
2 6
Output:
5


Date:2010-10-29
Time limit:3s
Source limit:50000B
Languages:All except: TCL


  • Submit

Comments

Loading Comments...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Loading Submissions...

RECENT ACTIVITY FOR THIS PROBLEM:

Loading Recent Activity...

HELP

Program should read from standard input and write to standard output.

After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

If you are still having problems, see a sample solution here.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com

© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs

Sponsors
The time now is: