Problem:
Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484

Solution in JavaScript (node.js v5.12) (judge verdict: Accepted)

parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"Focm":[function(require,module,exports) {
var t={};!function(t){"use strict";var n=function(t){this.compose=t},a=new n(function(t){return function(n){return function(a){return t(n(a))}}});t.compose=function(t){return t.compose},t.Semigroupoid=n,t.semigroupoidFn=a}(t["Control.Semigroupoid"]=t["Control.Semigroupoid"]||{}),function(n){"use strict";var a=t["Control.Semigroupoid"],r=function(t,n){this.Semigroupoid0=t,this.identity=n},e=new r(function(){return a.semigroupoidFn},function(t){return t});n.Category=r,n.identity=function(t){return t.identity},n.categoryFn=e}(t["Control.Category"]=t["Control.Category"]||{}),function(n){"use strict";(t["Data.Boolean"]=t["Data.Boolean"]||{}).otherwise=!0}(),function(n){"use strict";(t["Data.Eq"]=t["Data.Eq"]||{}).refEq=function(t){return function(n){return t===n}}}(),function(n){"use strict";(t["Data.Unit"]=t["Data.Unit"]||{}).unit={}}(),function(n){"use strict";(t["Data.Show"]=t["Data.Show"]||{}).showIntImpl=function(t){return t.toString()}}(),function(n){"use strict";var a=t["Data.Show"],r=(t["Data.Symbol"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.show=t}),e=new r(a.showIntImpl);n.Show=r,n.show=function(t){return t.show},n.showInt=e}(t["Data.Show"]=t["Data.Show"]||{}),function(n){"use strict";var a=t["Data.Unit"];t["Data.Show"];n.unit=a.unit}(t["Data.Unit"]=t["Data.Unit"]||{}),function(n){"use strict";var a=t["Data.Eq"],r=(t["Data.HeytingAlgebra"],t["Data.Symbol"],t["Data.Unit"],t["Data.Void"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t){this.eq=t}),e=new r(a.refEq),o=new r(a.refEq);n.Eq=r,n.eq=function(t){return t.eq},n.eqInt=e,n.eqChar=o}(t["Data.Eq"]=t["Data.Eq"]||{}),function(n){"use strict";(t["Data.Ord.Unsafe"]=t["Data.Ord.Unsafe"]||{}).unsafeCompareImpl=function(t){return function(n){return function(a){return function(r){return function(e){return r<e?t:r===e?n:a}}}}}}(),function(n){"use strict";t["Data.Eq"],t["Data.Semigroup"],t["Data.Show"];var a=function(){function t(){}return t.value=new t,t}(),r=function(){function t(){}return t.value=new t,t}(),e=function(){function t(){}return t.value=new t,t}();n.LT=a,n.GT=r,n.EQ=e}(t["Data.Ordering"]=t["Data.Ordering"]||{}),function(n){"use strict";var a=t["Data.Ord.Unsafe"],r=t["Data.Ordering"],e=a.unsafeCompareImpl(r.LT.value)(r.EQ.value)(r.GT.value);n.unsafeCompare=e}(t["Data.Ord.Unsafe"]=t["Data.Ord.Unsafe"]||{}),function(n){"use strict";(t["Data.Ring"]=t["Data.Ring"]||{}).intSub=function(t){return function(n){return t-n|0}}}(),function(t){"use strict";t.intAdd=function(t){return function(n){return t+n|0}},t.intMul=function(t){return function(n){return t*n|0}}}(t["Data.Semiring"]=t["Data.Semiring"]||{}),function(n){"use strict";var a=t["Data.Semiring"],r=(t["Data.Symbol"],t["Data.Unit"],t["Record.Unsafe"],t["Type.Data.Row"],t["Type.Data.RowList"],function(t,n,a,r){this.add=t,this.mul=n,this.one=a,this.zero=r}),e=new r(a.intAdd,a.intMul,1,0);n.Semiring=r,n.add=function(t){return t.add},n.zero=function(t){return t.zero},n.mul=function(t){return t.mul},n.one=function(t){return t.one},n.semiringInt=e}(t["Data.Semiring"]=t["Data.Semiring"]||{}),function(n){"use strict";var a=t["Data.Ring"],r=t["Data.Semiring"],e=(t["Data.Symbol"],t["Data.Unit"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t,n){this.Semiring0=t,this.sub=n}),o=new e(function(){return r.semiringInt},a.intSub);n.Ring=e,n.sub=function(t){return t.sub},n.ringInt=o}(t["Data.Ring"]=t["Data.Ring"]||{}),function(n){"use strict";t["Data.Ord"];var a=t["Data.Eq"],r=t["Data.Ord.Unsafe"],e=(t["Data.Ordering"],t["Data.Ring"],t["Data.Semiring"],t["Data.Symbol"],t["Data.Unit"],t["Data.Void"],t["Record.Unsafe"],t["Type.Data.RowList"],function(t,n){this.Eq0=t,this.compare=n}),o=new e(function(){return a.eqInt},r.unsafeCompare),i=new e(function(){return a.eqChar},r.unsafeCompare);n.Ord=e,n.compare=function(t){return t.compare},n.ordInt=o,n.ordChar=i}(t["Data.Ord"]=t["Data.Ord"]||{}),function(n){"use strict";t["Control.Category"],t["Data.Boolean"],t["Data.Ord"],t["Data.Ring"];n.const=function(t){return function(n){return t}}}(t["Data.Function"]=t["Data.Function"]||{}),function(n){"use strict";t["Data.Functor"],t["Control.Semigroupoid"],t["Data.Function"],t["Data.Unit"];n.Functor=function(t){this.map=t},n.map=function(t){return t.map}}(t["Data.Functor"]=t["Data.Functor"]||{}),function(n){"use strict";t["Control.Apply"],t["Control.Category"],t["Data.Function"],t["Data.Functor"];n.Apply=function(t,n){this.Functor0=t,this.apply=n},n.apply=function(t){return t.apply}}(t["Control.Apply"]=t["Control.Apply"]||{}),function(n){"use strict";t["Control.Apply"],t["Data.Functor"],t["Data.Unit"];n.Applicative=function(t,n){this.Apply0=t,this.pure=n},n.pure=function(t){return t.pure}}(t["Control.Applicative"]=t["Control.Applicative"]||{}),function(n){"use strict";t["Control.Bind"],t["Control.Applicative"],t["Control.Apply"],t["Control.Category"],t["Data.Function"],t["Data.Functor"],t["Data.Unit"];n.Bind=function(t,n){this.Apply0=t,this.bind=n},n.bind=function(t){return t.bind}}(t["Control.Bind"]=t["Control.Bind"]||{}),function(t){"use strict";t.topInt=2147483647,t.bottomInt=-2147483648,t.topChar=String.fromCharCode(65535),t.bottomChar=String.fromCharCode(0)}(t["Data.Bounded"]=t["Data.Bounded"]||{}),function(n){"use strict";var a=t["Data.Bounded"],r=t["Data.Ord"],e=(t["Data.Ordering"],t["Data.Unit"],function(t,n,a){this.Ord0=t,this.bottom=n,this.top=a}),o=new e(function(){return r.ordInt},a.bottomInt,a.topInt),i=new e(function(){return r.ordChar},a.bottomChar,a.topChar);n.Bounded=e,n.bottom=function(t){return t.bottom},n.top=function(t){return t.top},n.boundedInt=o,n.boundedChar=i}(t["Data.Bounded"]=t["Data.Bounded"]||{}),function(n){"use strict";t["Control.Alt"],t["Control.Alternative"],t["Control.Applicative"];var a=t["Control.Apply"],r=t["Control.Bind"],e=t["Control.Category"],o=(t["Control.Extend"],t["Control.Monad"],t["Control.MonadZero"],t["Control.Plus"],t["Data.Bounded"],t["Data.Eq"],t["Data.Function"]),i=t["Data.Functor"],u=(t["Data.Functor.Invariant"],t["Data.Monoid"],t["Data.Ord"],t["Data.Ordering"],t["Data.Semigroup"],t["Data.Show"],t["Data.Unit"],t.Prelude,function(){function t(){}return t.value=new t,t}()),c=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),f=function(t){return function(n){return function(a){if(a instanceof u)return t;if(a instanceof c)return n(a.value0);throw new Error("Failed pattern match at Data.Maybe (line 217, column 1 - line 217, column 51): "+[t.constructor.name,n.constructor.name,a.constructor.name])}}},l=f(!0)(o.const(!1)),s=f(!1)(o.const(!0)),d=new i.Functor(function(t){return function(n){return n instanceof c?new c(t(n.value0)):u.value}}),D=new a.Apply(function(){return d},function(t){return function(n){if(t instanceof c)return i.map(d)(t.value0)(n);if(t instanceof u)return u.value;throw new Error("Failed pattern match at Data.Maybe (line 67, column 1 - line 67, column 35): "+[t.constructor.name,n.constructor.name])}}),m=new r.Bind(function(){return D},function(t){return function(n){if(t instanceof c)return n(t.value0);if(t instanceof u)return u.value;throw new Error("Failed pattern match at Data.Maybe (line 125, column 1 - line 125, column 33): "+[t.constructor.name,n.constructor.name])}});n.Nothing=u,n.Just=c,n.maybe=f,n.fromMaybe=function(t){return f(t)(e.identity(e.categoryFn))},n.isJust=s,n.isNothing=l,n.fromJust=function(t){return function(t){if(t instanceof c)return t.value0;throw new Error("Failed pattern match at Data.Maybe (line 268, column 1 - line 268, column 46): "+[t.constructor.name])}},n.functorMaybe=d,n.applyMaybe=D,n.bindMaybe=m}(t["Data.Maybe"]=t["Data.Maybe"]||{}),function(n){"use strict";t["Control.Alt"];var a=t["Control.Applicative"],r=t["Control.Apply"],e=t["Control.Bind"],o=(t["Control.Extend"],t["Control.Monad"],t["Control.Semigroupoid"],t["Data.Bifoldable"],t["Data.Bifunctor"],t["Data.Bitraversable"],t["Data.Bounded"],t["Data.Eq"],t["Data.Foldable"],t["Data.FoldableWithIndex"],t["Data.Function"],t["Data.Functor"]),i=(t["Data.Functor.Invariant"],t["Data.FunctorWithIndex"],t["Data.Maybe"]),u=(t["Data.Monoid"],t["Data.Ord"],t["Data.Ordering"],t["Data.Semigroup"],t["Data.Show"],t["Data.Traversable"],t["Data.TraversableWithIndex"],t["Data.Unit"],t.Prelude,function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}()),c=function(){function t(t){this.value0=t}return t.create=function(n){return new t(n)},t}(),f=new o.Functor(function(t){return function(n){if(n instanceof u)return new u(n.value0);if(n instanceof c)return new c(t(n.value0));throw new Error("Failed pattern match at Data.Either (line 38, column 8 - line 38, column 52): "+[n.constructor.name])}}),l=function(t){return function(n){return function(a){if(a instanceof u)return t(a.value0);if(a instanceof c)return n(a.value0);throw new Error("Failed pattern match at Data.Either (line 238, column 1 - line 238, column 64): "+[t.constructor.name,n.constructor.name,a.constructor.name])}}},s=new r.Apply(function(){return f},function(t){return function(n){if(t instanceof u)return new u(t.value0);if(t instanceof c)return o.map(f)(t.value0)(n);throw new Error("Failed pattern match at Data.Either (line 82, column 1 - line 82, column 41): "+[t.constructor.name,n.constructor.name])}}),d=new e.Bind(function(){return s},l(function(t){return function(n){return new u(t)}})(function(t){return function(n){return n(t)}})),D=new a.Applicative(function(){return s},c.create);n.Left=u,n.Right=c,n.either=l,n.note=function(t){return i.maybe(new u(t))(c.create)},n.functorEither=f,n.applyEither=s,n.applicativeEither=D,n.bindEither=d}(t["Data.Either"]=t["Data.Either"]||{}),function(t){"use strict";t.fromNumberImpl=function(t){return function(n){return function(a){return(0|a)===a?t(a):n}}},t.toNumber=function(t){return t},t.fromStringAsImpl=function(t){return function(n){return function(a){var r;r=a<11?"[0-"+(a-1).toString()+"]":11===a?"[0-9a]":"[0-9a-"+String.fromCharCode(86+a)+"]";var e=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(r){if(e.test(r)){var o=parseInt(r,a);return(0|o)===o?t(o):n}return n}}}}}(t["Data.Int"]=t["Data.Int"]||{}),function(n){"use strict";var a=t["Data.Ring"],r=(t["Data.Semiring"],t["Data.Symbol"],t["Data.Unit"],function(t){this.Ring0=t}),e=new r(function(){return a.ringInt});n.CommutativeRing=r,n.commutativeRingInt=e}(t["Data.CommutativeRing"]=t["Data.CommutativeRing"]||{}),function(t){"use strict";t.intDegree=function(t){return Math.min(Math.abs(t),2147483647)},t.intDiv=function(t){return function(n){return 0===n?0:n>0?Math.floor(t/n):-Math.floor(t/-n)}},t.intMod=function(t){return function(n){if(0===n)return 0;var a=Math.abs(n);return(t%a+a)%a}}}(t["Data.EuclideanRing"]=t["Data.EuclideanRing"]||{}),function(n){"use strict";var a=t["Data.EuclideanRing"],r=(t["Data.BooleanAlgebra"],t["Data.CommutativeRing"]),e=(t["Data.Eq"],t["Data.HeytingAlgebra"],t["Data.Ring"],t["Data.Semiring"],function(t,n,a,r){this.CommutativeRing0=t,this.degree=n,this.div=a,this.mod=r}),o=new e(function(){return r.commutativeRingInt},a.intDegree,a.intDiv,a.intMod);n.EuclideanRing=e,n.degree=function(t){return t.degree},n.div=function(t){return t.div},n.mod=function(t){return t.mod},n.euclideanRingInt=o}(t["Data.EuclideanRing"]=t["Data.EuclideanRing"]||{}),function(n){"use strict";(t["Global"]=t["Global"]||{}).infinity=1/0}(),function(n){"use strict";var a=t.Global;n.infinity=a.infinity}(t.Global=t.Global||{}),function(t){"use strict";t.ceil=Math.ceil,t.log=Math.log,t.log10e=Math.LOG10E}(t.Math=t.Math||{}),function(n){"use strict";var a=t.Math;n.ceil=a.ceil,n.log=a.log,n.log10e=a.log10e}(t.Math=t.Math||{}),function(n){"use strict";var a=t["Data.Int"],r=(t["Control.Category"],t["Control.Semigroupoid"],t["Data.Boolean"]),e=t["Data.Bounded"],o=(t["Data.CommutativeRing"],t["Data.DivisionRing"],t["Data.Eq"],t["Data.EuclideanRing"],t["Data.HeytingAlgebra"],t["Data.Int.Bits"],t["Data.Maybe"]),i=(t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semiring"],t["Data.Show"],t.Global),u=t.Math,c=(t.Prelude,a.fromStringAsImpl(o.Just.create)(o.Nothing.value)),f=c(10),l=a.fromNumberImpl(o.Just.create)(o.Nothing.value);n.fromNumber=l,n.ceil=function(t){return function(t){if(t===i.infinity)return 0;if(t===-i.infinity)return 0;if(t>=a.toNumber(e.top(e.boundedInt)))return e.top(e.boundedInt);if(t<=a.toNumber(e.bottom(e.boundedInt)))return e.bottom(e.boundedInt);if(r.otherwise)return o.fromMaybe(0)(l(t));throw new Error("Failed pattern match at Data.Int (line 66, column 1 - line 66, column 29): "+[t.constructor.name])}(u.ceil(t))},n.fromString=f,n.fromStringAs=c,n.toNumber=a.toNumber}(t["Data.Int"]=t["Data.Int"]||{}),function(t){"use strict";var n="function"==typeof Array.from,a="undefined"!=typeof Symbol&&null!=Symbol&&void 0!==Symbol.iterator&&"function"==typeof String.prototype[Symbol.iterator],r="function"==typeof String.prototype.fromCodePoint,e="function"==typeof String.prototype.codePointAt;t._unsafeCodePointAt0=function(t){return e?function(t){return t.codePointAt(0)}:t},t._singleton=function(t){return r?String.fromCodePoint:t},t._take=function(t){return function(n){return a?function(t){for(var a="",r=t[Symbol.iterator](),e=0;e<n;++e){var o=r.next();if(o.done)return a;a+=o.value}return a}:t(n)}},t._toCodePointArray=function(t){return function(a){return n?function(t){return Array.from(t,a)}:t}}}(t["Data.String.CodePoints"]=t["Data.String.CodePoints"]||{}),function(n){"use strict";(t["Data.Array"]=t["Data.Array"]||{}).length=function(t){return t.length}}(),function(n){"use strict";t["Control.Applicative"],t["Control.Apply"],t["Control.Biapplicative"],t["Control.Biapply"],t["Control.Bind"],t["Control.Comonad"],t["Control.Extend"],t["Control.Lazy"],t["Control.Monad"],t["Control.Semigroupoid"],t["Data.Bifoldable"],t["Data.Bifunctor"],t["Data.Bitraversable"],t["Data.BooleanAlgebra"],t["Data.Bounded"],t["Data.CommutativeRing"],t["Data.Distributive"],t["Data.Eq"],t["Data.Foldable"],t["Data.FoldableWithIndex"],t["Data.Function"],t["Data.Functor"],t["Data.Functor.Invariant"],t["Data.FunctorWithIndex"],t["Data.HeytingAlgebra"],t["Data.Maybe"],t["Data.Maybe.First"],t["Data.Monoid"],t["Data.Newtype"],t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semigroup.Foldable"],t["Data.Semigroup.Traversable"],t["Data.Semiring"],t["Data.Show"],t["Data.Traversable"],t["Data.TraversableWithIndex"],t["Data.Unit"],t.Prelude,t["Type.Equality"];var a=function(){function t(t,n){this.value0=t,this.value1=n}return t.create=function(n){return function(a){return new t(n,a)}},t}();n.Tuple=a,n.fst=function(t){return t.value0},n.snd=function(t){return t.value1}}(t["Data.Tuple"]=t["Data.Tuple"]||{}),function(n){"use strict";(t["Data.Unfoldable"]=t["Data.Unfoldable"]||{}).unfoldrArrayImpl=function(t){return function(n){return function(a){return function(r){return function(e){return function(o){for(var i=[],u=o;;){var c=e(u);if(t(c))return i;var f=n(c);i.push(a(f)),u=r(f)}}}}}}}}(),function(n){"use strict";(t["Data.Unfoldable1"]=t["Data.Unfoldable1"]||{}).unfoldr1ArrayImpl=function(t){return function(n){return function(a){return function(r){return function(e){return function(o){for(var i=[],u=o;;){var c=e(u);i.push(a(c));var f=r(c);if(t(f))return i;u=n(f)}}}}}}}}(),function(n){"use strict";(t["Partial.Unsafe"]=t["Partial.Unsafe"]||{}).unsafePartial=function(t){return t()}}(),function(n){"use strict";(t["Partial"]=t["Partial"]||{}).crashWith=function(){return function(t){throw new Error(t)}}}(),function(n){"use strict";var a=t.Partial;n.crashWith=a.crashWith}(t.Partial=t.Partial||{}),function(n){"use strict";var a=t["Partial.Unsafe"],r=t.Partial;n.unsafeCrashWith=function(t){return a.unsafePartial(function(n){return r.crashWith(n)(t)})}}(t["Partial.Unsafe"]=t["Partial.Unsafe"]||{}),function(n){"use strict";var a=t["Data.Unfoldable1"],r=(t["Data.Boolean"],t["Data.Eq"],t["Data.Maybe"]),e=(t["Data.Ord"],t["Data.Ring"],t["Data.Semigroup.Traversable"],t["Data.Semiring"],t["Data.Tuple"]),o=(t["Partial.Unsafe"],t.Prelude,function(t){this.unfoldr1=t}),i=new o(a.unfoldr1ArrayImpl(r.isNothing)(r.fromJust())(e.fst)(e.snd));n.Unfoldable1=o,n.unfoldr1=function(t){return t.unfoldr1},n.unfoldable1Array=i}(t["Data.Unfoldable1"]=t["Data.Unfoldable1"]||{}),function(n){"use strict";var a=t["Data.Unfoldable"],r=(t["Data.Function"],t["Data.Functor"],t["Data.Maybe"]),e=(t["Data.Ord"],t["Data.Ring"],t["Data.Traversable"],t["Data.Tuple"]),o=t["Data.Unfoldable1"],i=(t["Data.Unit"],t["Partial.Unsafe"],t.Prelude,function(t,n){this.Unfoldable10=t,this.unfoldr=n}),u=new i(function(){return o.unfoldable1Array},a.unfoldrArrayImpl(r.isNothing)(r.fromJust())(e.fst)(e.snd));n.Unfoldable=i,n.unfoldr=function(t){return t.unfoldr},n.unfoldableArray=u}(t["Data.Unfoldable"]=t["Data.Unfoldable"]||{}),function(n){"use strict";(t["Unsafe.Coerce"]=t["Unsafe.Coerce"]||{}).unsafeCoerce=function(t){return t}}(),function(n){"use strict";var a=t["Unsafe.Coerce"];n.unsafeCoerce=a.unsafeCoerce}(t["Unsafe.Coerce"]=t["Unsafe.Coerce"]||{}),function(n){"use strict";var a=t["Data.Array"];t["Control.Alt"],t["Control.Alternative"],t["Control.Applicative"],t["Control.Apply"],t["Control.Bind"],t["Control.Category"],t["Control.Lazy"],t["Control.Monad.Rec.Class"],t["Control.Monad.ST"],t["Control.Monad.ST.Internal"],t["Control.Semigroupoid"],t["Data.Array.NonEmpty.Internal"],t["Data.Array.ST"],t["Data.Array.ST.Iterator"],t["Data.Boolean"],t["Data.Eq"],t["Data.Foldable"],t["Data.Function"],t["Data.Functor"],t["Data.HeytingAlgebra"],t["Data.Maybe"],t["Data.Ord"],t["Data.Ordering"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semiring"],t["Data.Traversable"],t["Data.Tuple"],t["Data.Unfoldable"],t["Partial.Unsafe"],t.Prelude,t["Unsafe.Coerce"];n.length=a.length}(t["Data.Array"]=t["Data.Array"]||{}),function(t){"use strict";t.toCharCode=function(t){return t.charCodeAt(0)},t.fromCharCode=function(t){return String.fromCharCode(t)}}(t["Data.Enum"]=t["Data.Enum"]||{}),function(n){"use strict";var a=t["Data.Enum"],r=(t["Control.Apply"],t["Control.Bind"],t["Control.MonadPlus"],t["Control.MonadZero"],t["Control.Semigroupoid"],t["Data.Boolean"],t["Data.Bounded"]),e=(t["Data.Either"],t["Data.Eq"],t["Data.Function"],t["Data.Functor"],t["Data.HeytingAlgebra"],t["Data.Maybe"]),o=(t["Data.Newtype"],t["Data.Ord"]),i=(t["Data.Ordering"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semiring"],t["Data.Show"],t["Data.Tuple"],t["Data.Unfoldable"],t["Data.Unfoldable1"],t["Data.Unit"],t["Partial.Unsafe"],t.Prelude,function(t,n,a){this.Ord0=t,this.pred=n,this.succ=a}),u=function(t,n,a,r,e){this.Bounded0=t,this.Enum1=n,this.cardinality=a,this.fromEnum=r,this.toEnum=e},c=function(t){return t.toEnum},f=function(t){return t.fromEnum},l=function(t){return function(n){return function(a){return t(n(a)+1|0)}}},s=function(t){return function(n){return function(a){return t(n(a)-1|0)}}},d=function(t){return t>=r.bottom(r.boundedInt)&&t<=r.top(r.boundedInt)?new e.Just(a.fromCharCode(t)):e.Nothing.value},D=new i(function(){return o.ordChar},s(d)(a.toCharCode),l(d)(a.toCharCode)),m=new u(function(){return r.boundedChar},function(){return D},a.toCharCode(r.top(r.boundedChar))-a.toCharCode(r.bottom(r.boundedChar))|0,a.toCharCode,d);n.Enum=i,n.succ=function(t){return t.succ},n.pred=function(t){return t.pred},n.BoundedEnum=u,n.cardinality=function(t){return t.cardinality},n.toEnum=c,n.fromEnum=f,n.toEnumWithDefaults=function(t){return function(n){return function(a){return function(o){var i=c(t)(o);if(i instanceof e.Just)return i.value0;if(i instanceof e.Nothing)return o<f(t)(r.bottom(t.Bounded0()))?n:a;throw new Error("Failed pattern match at Data.Enum (line 158, column 33 - line 160, column 62): "+[i.constructor.name])}}}},n.defaultSucc=l,n.defaultPred=s,n.enumChar=D,n.boundedEnumChar=m}(t["Data.Enum"]=t["Data.Enum"]||{}),function(t){"use strict";t.singleton=function(t){return t},t.length=function(t){return t.length},t._indexOf=function(t){return function(n){return function(a){return function(r){var e=r.indexOf(a);return-1===e?n:t(e)}}}},t.take=function(t){return function(n){return n.substr(0,t)}},t.drop=function(t){return function(n){return n.substring(t)}}}(t["Data.String.CodeUnits"]=t["Data.String.CodeUnits"]||{}),function(n){"use strict";(t["Data.String.Unsafe"]=t["Data.String.Unsafe"]||{}).charAt=function(t){return function(n){if(t>=0&&t<n.length)return n.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}}}(),function(n){"use strict";var a=t["Data.String.Unsafe"];n.charAt=a.charAt}(t["Data.String.Unsafe"]=t["Data.String.Unsafe"]||{}),function(n){"use strict";var a=t["Data.String.CodeUnits"],r=(t["Control.Semigroupoid"],t["Data.Boolean"],t["Data.Eq"],t["Data.Function"],t["Data.HeytingAlgebra"],t["Data.Maybe"]),e=(t["Data.Ord"],t["Data.Ring"],t["Data.Semiring"],t["Data.String.Pattern"],t["Data.String.Unsafe"],t.Prelude,a._indexOf(r.Just.create)(r.Nothing.value));n.indexOf=e,n.singleton=a.singleton,n.length=a.length,n.take=a.take,n.drop=a.drop}(t["Data.String.CodeUnits"]=t["Data.String.CodeUnits"]||{}),function(n){"use strict";(t["Data.String.Common"]=t["Data.String.Common"]||{}).trim=function(t){return t.trim()}}(),function(n){"use strict";var a=t["Data.String.Common"];t["Data.Eq"],t["Data.Ordering"],t["Data.String.Pattern"],t.Prelude;n.trim=a.trim}(t["Data.String.Common"]=t["Data.String.Common"]||{}),function(n){"use strict";var a=t["Data.String.CodePoints"],r=(t["Control.Semigroupoid"],t["Data.Array"]),e=(t["Data.Boolean"],t["Data.Bounded"]),o=t["Data.Enum"],i=(t["Data.Eq"],t["Data.EuclideanRing"]),u=t["Data.Functor"],c=(t["Data.HeytingAlgebra"],t["Data.Int"],t["Data.Maybe"]),f=(t["Data.Ord"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semiring"],t["Data.Show"],t["Data.String.CodeUnits"]),l=(t["Data.String.Common"],t["Data.String.Pattern"],t["Data.String.Unsafe"]),s=t["Data.Tuple"],d=t["Data.Unfoldable"],D=(t.Prelude,function(t){return function(n){return 65536+((1024*(t-55296|0)|0)+(n-56320|0)|0)|0}}),m=function(t){return 56320<=t&&t<=57343},g=function(t){return 55296<=t&&t<=56319},h=function(t){var n=f.length(t);if(0===n)return c.Nothing.value;if(1===n)return new c.Just({head:o.fromEnum(o.boundedEnumChar)(l.charAt(0)(t)),tail:""});var a=o.fromEnum(o.boundedEnumChar)(l.charAt(1)(t)),r=o.fromEnum(o.boundedEnumChar)(l.charAt(0)(t));return g(r)&&m(a)?new c.Just({head:D(r)(a),tail:f.drop(2)(t)}):new c.Just({head:r,tail:f.drop(1)(t)})},C=function(t){return u.map(c.functorMaybe)(function(t){return new s.Tuple(t.head,t.tail)})(h(t))},p=a._unsafeCodePointAt0(function(t){var n=o.fromEnum(o.boundedEnumChar)(l.charAt(0)(t));if(g(n)&&f.length(t)>1){var a=o.fromEnum(o.boundedEnumChar)(l.charAt(1)(t));return m(a)?D(n)(a):n}return n}),b=a._toCodePointArray(function(t){return d.unfoldr(d.unfoldableArray)(C)(t)})(p),v=function(t){return r.length(b(t))},S=function(t){return f.singleton(o.toEnumWithDefaults(o.boundedEnumChar)(e.bottom(e.boundedChar))(e.top(e.boundedChar))(t))},y=a._singleton(function(t){if(t<=65535)return S(t);var n=i.div(i.euclideanRingInt)(t-65536|0)(1024)+55296|0,a=i.mod(i.euclideanRingInt)(t-65536|0)(1024)+56320|0;return S(n)+S(a)}),w=function(t){return function(n){if(t<1)return"";var a=h(n);return a instanceof c.Just?y(a.value0.head)+w(t-1|0)(a.value0.tail):n}},E=a._take(w);n.singleton=y,n.toCodePointArray=b,n.uncons=h,n.length=v,n.indexOf=function(t){return function(n){return u.map(c.functorMaybe)(function(t){return v(f.take(t)(n))})(f.indexOf(t)(n))}},n.take=E,n.drop=function(t){return function(n){return f.drop(f.length(E(t)(n)))(n)}}}(t["Data.String.CodePoints"]=t["Data.String.CodePoints"]||{}),function(n){"use strict";var a=t["Control.Applicative"],r=t["Control.Bind"],e=t["Data.Either"],o=t["Data.Int"],i=t["Data.Maybe"],u=(t["Data.Ord"],t["Data.Ring"],t["Data.Semigroup"],t["Data.Semiring"],t["Data.Show"]),c=(t["Data.String"],t["Data.String.CodePoints"]),f=t["Data.String.Common"],l=(t["Data.String.Pattern"],t["Data.Unit"]),s=t.Math,d=t["Partial.Unsafe"],D=(t.Prelude,function(t){return function(n){return i.isJust(r.bind(i.bindMaybe)(c.indexOf("3")(n))(function(a){return r.bind(i.bindMaybe)(c.indexOf("5")(n))(function(a){return r.bind(i.bindMaybe)(c.indexOf("7")(n))(function(a){return r.bind(i.bindMaybe)(o.fromString(n))(function(n){return n<=t?new i.Just(l.unit):i.Nothing.value})})})}))}}),m=function(t){return function(n){return function(a){if(0===n)return D(t)(a)?1:0;var r=m(t)(n-1|0)(a+"7"),e=m(t)(n-1|0)(a+"5"),o=m(t)(n-1|0)(a+"3");return(((D(t)(a)?1:0)+o|0)+e|0)+r|0}}};n.solve=function(t){var n=function(t){return r.bind(e.bindEither)(e.note("n")(o.fromString(f.trim(t))))(function(t){var n=o.ceil(s.log(o.toNumber(t))*s.log10e);return a.pure(e.applicativeEither)(u.show(u.showInt)(m(t)(n)("")))})}(t);if(n instanceof e.Left)return d.unsafeCrashWith(n.value0);if(n instanceof e.Right)return n.value0;throw new Error("Failed pattern match at AtCoder.ABC114.C (line 17, column 3 - line 19, column 24): "+[n.constructor.name])}}(t["AtCoder.ABC114.C"]=t["AtCoder.ABC114.C"]||{}),function(n){"use strict";(t["Effect.Console"]=t["Effect.Console"]||{}).log=function(t){return function(){return console.log(t),{}}}}(),function(n){"use strict";var a=t["Effect.Console"];t["Data.Show"],t["Data.Unit"],t.Effect;n.log=a.log}(t["Effect.Console"]=t["Effect.Console"]||{}),function(n){"use strict";t["Node.Encoding"];var a=t["Data.Show"],r=(t.Prelude,function(){function t(){}return t.value=new t,t}()),e=function(){function t(){}return t.value=new t,t}(),o=function(){function t(){}return t.value=new t,t}(),i=function(){function t(){}return t.value=new t,t}(),u=function(){function t(){}return t.value=new t,t}(),c=function(){function t(){}return t.value=new t,t}(),f=function(){function t(){}return t.value=new t,t}(),l=function(){function t(){}return t.value=new t,t}(),s=new a.Show(function(t){if(t instanceof r)return"ASCII";if(t instanceof e)return"UTF8";if(t instanceof o)return"UTF16LE";if(t instanceof i)return"UCS2";if(t instanceof u)return"Base64";if(t instanceof c)return"Latin1";if(t instanceof f)return"Binary";if(t instanceof l)return"Hex";throw new Error("Failed pattern match at Node.Encoding (line 19, column 1 - line 19, column 39): "+[t.constructor.name])});n.ASCII=r,n.UTF8=e,n.UTF16LE=o,n.UCS2=i,n.Base64=u,n.Latin1=c,n.Binary=f,n.Hex=l,n.showEncoding=s}(t["Node.Encoding"]=t["Node.Encoding"]||{}),function(n){"use strict";(t["Node.FS.Internal"]=t["Node.FS.Internal"]||{}).unsafeRequireFS=require("fs")}(),function(n){"use strict";var a=t["Node.FS.Internal"],r=(t.Effect,t.Prelude,t["Unsafe.Coerce"].unsafeCoerce);n.mkEffect=r,n.unsafeRequireFS=a.unsafeRequireFS}(t["Node.FS.Internal"]=t["Node.FS.Internal"]||{}),function(n){"use strict";t["Control.Bind"],t["Control.Semigroupoid"],t["Data.DateTime"],t["Data.DateTime.Instant"],t["Data.EuclideanRing"],t["Data.Function"],t["Data.Function.Uncurried"],t["Data.Functor"],t["Data.Int"],t["Data.Maybe"],t["Data.Nullable"];var a=t["Data.Show"],r=(t["Data.Time.Duration"],t.Effect,t["Node.Buffer"],t["Node.Encoding"]),e=(t["Node.FS"],t["Node.FS.Internal"]),o=(t["Node.FS.Perms"],t["Node.FS.Stats"],t["Node.Path"],t.Prelude,e.unsafeRequireFS);n.readTextFile=function(t){return function(n){return e.mkEffect(function(e){return o.readFileSync(n,{encoding:a.show(r.showEncoding)(t)})})}}}(t["Node.FS.Sync"]=t["Node.FS.Sync"]||{}),function(n){"use strict";var a=t["AtCoder.ABC114.C"],r=(t["Control.Applicative"],t["Control.Bind"],t.Effect,t["Effect.Console"]),e=t["Node.Encoding"],o=t["Node.FS.Sync"];t.Prelude;n.main=function(){var t=o.readTextFile(e.UTF8.value)("/dev/stdin")(),n=a.solve(t);return r.log(n)()}}(t.Main=t.Main||{}),t.Main.main();
},{}]},{},["Focm"], null)