DCEPCA01 - Good Luck

A number is called lucky if it consists of only digits 4 and 7 ie. 4, 7, 44, 47 are lucky numbers while 3, 45, 4478 are not lucky. For a given lucky number the functions F(i) and G(i) are defined as follows

F(i) = the number of 4’s from 0th to ith position in the number including positions 0 and i.
G(i) = the number of 7’s from 0th to ith position in the number including positions 0 and i.

Let H(i)= absolute(F(i)-F(i+1)-F(i+2)+F(i+3))

A "Dynamic Number" is a lucky number which has maximum of summation(H(i)) from i = 0 to n-4 amongst all lucky numbers of length N.

Given a number N , you need to find out the sum of the two smallest Dynamic Numbers of length N.If only one Dynamic Number is possible, then only that number is the answer.

Note : Most significant bit is defined as the 0th position of the number.

Constraints

0 < T <= 100
4 <= N <= 10^5

Input

It consists of T+1 lines. T denotes the number of test cases. Followed by T lines, each containing one number N.

Output

Output T lines, each containing a number as required.

Example

Input:
1
4

Output: 8924

Added by:dce coders
Date:2012-12-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Own Problem

hide comments
2014-02-07 13:52:26 anurag garg
very nice question...
2013-05-26 12:31:34 Kartik Khare
ya i got it actually i was taking last digit as 0th digit

Last edit: 2013-05-26 12:31:48
2013-05-26 09:55:04 Sandeep Pathry
@kartik its 1 buddy...
|1-2-3+3|=1
2013-05-26 08:54:26 Kartik Khare
how can 4447 be a dynamic number the summation for it is 0.
2012-12-17 16:47:37 Abhilash Kumar
@Tjandra Satria Gunawan thanks a lot..i dont know why but i didnt noticed it :)
2012-12-17 11:46:52 (Tjandra Satria Gunawan)(曾毅昆)
@Abhilash Kumar: You're wrong. h(i) never negative, because of absolute() function...

Last edit: 2012-12-17 11:47:11
2012-12-17 11:37:37 Abhilash Kumar
8924=4447+4477
right..but submation(h(i)) for them are -1 .but if we use 7774 we get 1..i m wrong??
2012-12-16 13:43:50 triveni
Thanks dce coders, this problem tought me about the difference in fastness of putchar and printf.. :)
2012-12-07 09:03:46 (Tjandra Satria Gunawan)(曾毅昆)
thanks dce coders, I like most of your problem ;-)
so far 14 DCE problems solved :-D
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.