We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Combinatorics
  4. Towers

Towers

Problem
Submissions
Leaderboard
Discussions
Editorial

One day John had to take care of his little nephew Jim. He was very busy, so he gave Jim a big bag full of building bricks. The bricks are of various heights: at most 15 different heights. For each height, the bag contains infinitely many bricks.

Now, Jim’s task is to build every possible tower of height from the given bricks. Bricks are stacked vertically only and stand in an upright position. Two towers are different if their brick height sequences are different.
Jim is good at building towers and can build one tower in exactly 2 minutes, regardless of its height. John wants to know the time Jim requires to build all possible towers.

Input Format
There are lines of input. First line contains an integer, , the height of tower to be built. Second line contains another integer, , which represents different heights of bricks available in the bag. Third line contains distinct integers representing the available heights.

Output Format
In one line print the number of minutes Jim requires to build all possible towers. As this number can be very large, print the number modulo .

Constraints


All heights will be unique.
Height of each brick will lie in range [1, 15].

Sample Input#00

10
1
1

Sample Output#00

2

Explanation#00: There is exactly one type of brick, so there is exactly one tower of height 10. Building any tower takes 2 minutes, so the answer is 2.

Sample Input#01

5
2
2 3

Sample Output#01

4

Explanation #01: There are two types of bricks. There are two different towers of height 5 which can be build from these types of bricks: and . They are different, because the sequence of bricks in them is different. Building any tower takes 2 minutes, so the answer is .

Sample Input#03

19
2
4 5

Sample Output#03

8

Explanation #03: There are two types of bricks. Jim can build 4 different towers of height from these bricks: , , and . Building any tower takes 2 minutes, so the answer is .

Author

pkacprzak

Difficulty

Hard

Max Score

80

Submitted By

368

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

Join us

Create a HackerRank account

Be part of a 26 million-strong community of developers

Please signup or login in order to view this challenge

or
Already have an account?Log in