SMILEY1807 - 1807


There is a SmileyLand of angels. The queen of all angels Smiley1807 loves the number 1807. She is so much obsessed with 1807 that she asked her programmer friend to write a program to find the length of the largest sub sequence having digits 1, 8, 0 and 7 in order. For example if given sequence is 1800777700088888000777 then one of the largest sub sequence satisfying the above condition is 1800000000777 (there is one more possibility of 1888888000777) and hence the length of largest sub sequence is 13.

Input

The input contains only one test case.

The test case consist of only one sequence which may be as long as 10^6. There are only 1, 8, 0 or 7 present in the input sequence.

Output

Output contains only one line containing the length of the largest sub-sequence.

Example

Input:
1800777700088888000777

Output:
13

Explanation

1800000000777 is the largest sub-sequence


hide comments
Saksham : 2015-08-29 21:45:19

nice problem,my 150th!!

shikhargarg: 2015-08-29 12:59:19

Sometimes ... dp is not necessary ;)

mehmetin: 2015-08-29 10:40:36

@Amitayush, I disqualified only my AC solutions, because they contained too much code or used too much memory :))

(Reply)
@mehmetin, It is nice to see that :) Actually I saw many disqualification status by various users. There is a tricky case which many of them missed on first go. That is why I said that. Btw it is good to see that you disqualified your AC soultions making good use of the feature of disqualification :))

Last edit: 2015-08-31 12:35:39
Amitayush Thakur: 2015-08-28 18:26:41

It is sad to see that most of the people disqualify their solution just to increase their AC rates.

:.Mohib.:: 2015-08-26 17:45:32

One Observation and AC :D...Nice Problem...!!

Akhilesh Anandh: 2015-08-24 18:04:24

Should there be at least one each of 1,8,0,7? What is the answer for "187"?

(reply)
You have to find the length of the largest sub sequence having digits 1,8,0 and 7 in order. In case of 1,8,7 the order is not maintained 8 has to be followed by 0 and not 7 .

Last edit: 2015-08-25 10:09:35
Garima: 2015-08-22 22:57:43

Nice Question :)
What a coincidence, 1807 stands for my birthday :D

Last edit: 2015-08-26 13:04:35
Min_25: 2015-08-22 20:15:21

We cannot submit our solutions.
Please check the "Testable" checkbox.

@Min_25: Changes made.. I missed that as it is my first problem. Please remove it from the hidden category :)

(reply from Min_25)
@Amitayush Thakur: Thanks. Unhidden.

Last edit: 2015-08-23 10:24:14

Added by:Amitayush Thakur
Date:2015-08-22
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:MAWK BC C NCSHARP CSHARP C++ 4.3.2 CPP CPP14 C99 COFFEE LISP sbcl LISP clisp DART FORTH HASK JAVA JULIA KTLN OCT PROLOG PYTHON PYPY3 PYTHON3 PY_NBC R RACKET SCALA SQLITE SWIFT UNLAMBDA
Resource:Own problem made for college competition CodeNite-1