YAPP - Yet Another Permutations Problem

How many permutations of the first N numbers exist such that the maximum element between the indices [i..j] is either present at index i, or at index j ?


Input

The first line contains the number of test cases T. Each of the next T lines contains an integer N


Output

Output T lines containing the required answer for the corresponding test case. Since the answers can get really big, output the result modulo 1000000007.

Example

Sample Input:
1
2

Sample Output:
2

Constraints

1 <= T <= 10000

1 <= N <= 1000000000


Added by:Varun Jalan
Date:2010-01-25
Time limit:1.690s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:own problem used for Technovanza

hide comments
2018-06-16 21:54:00
Use modular exponentiation.
2016-11-30 23:00:38 paras meena
@[bitthal] N >= 1
2016-06-20 20:34:00 KD
AC in one go :D
my 200th :)
2016-06-02 19:21:16 Arpit Gupta
Anyone Help... used exponentiation... used ans=1 for n=0 and 1, tests where my code might go wrong ans for n=10 is 512... i got that...
EDIT: Did a silly mistake in precompuation :D

Last edit: 2016-06-02 19:48:33
2016-06-02 19:18:51 Arpit Gupta
Some sample tests where my program goes wrong... used exponentiation.... for n=0,1 ans=1 also.. even then wrong ans... Help anyone??
2015-12-13 16:05:13 cegprakash
For those who feel the problem statement is not clear, you have to find the number of permutations such that for all i,j 1<=i<=j<=n the maximum element between the indices [i..j] is either present at index i, or at index j

Last edit: 2015-12-13 19:28:16
2015-06-20 12:47:21 prateek goyal
no need of permutation and combination
2014-08-17 18:22:55 [bitthal]
for n=0...ans is 1.
simple maths but test case 0 can costs a lot..

Last edit: 2014-08-17 18:23:52
2014-06-30 13:34:41 L
if getting TLE use modular arithmetic..
for n=10 ans is 512 .
easy when you understand the question..

Last edit: 2014-06-30 13:35:57
2014-05-29 16:53:55 appy
More test cases pls
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.