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 n={};!function(t){"use strict";(n["Control.Apply"]=n["Control.Apply"]||{}).arrayApply=function(n){return function(t){for(var r=n.length,a=t.length,e=new Array(r*a),o=0,i=0;i<r;i++)for(var u=n[i],c=0;c<a;c++)e[o++]=u(t[c]);return e}}}(),function(t){"use strict";(n["Data.Boolean"]=n["Data.Boolean"]||{}).otherwise=!0}(),function(t){"use strict";(n["Data.Eq"]=n["Data.Eq"]||{}).refEq=function(n){return function(t){return n===t}}}(),function(t){"use strict";(n["Data.Unit"]=n["Data.Unit"]||{}).unit={}}(),function(t){"use strict";(n["Data.Show"]=n["Data.Show"]||{}).showIntImpl=function(n){return n.toString()}}(),function(t){"use strict";var r=n["Data.Show"],a=(n["Data.Symbol"],n["Record.Unsafe"],n["Type.Data.RowList"],function(n){this.show=n}),e=new a(r.showIntImpl);t.Show=a,t.show=function(n){return n.show},t.showInt=e}(n["Data.Show"]=n["Data.Show"]||{}),function(t){"use strict";var r=n["Data.Unit"];n["Data.Show"];t.unit=r.unit}(n["Data.Unit"]=n["Data.Unit"]||{}),function(t){"use strict";var r=n["Data.Eq"],a=(n["Data.HeytingAlgebra"],n["Data.Symbol"],n["Data.Unit"],n["Data.Void"],n["Record.Unsafe"],n["Type.Data.RowList"],function(n){this.eq=n}),e=new a(r.refEq);t.Eq=a,t.eq=function(n){return n.eq},t.eqInt=e}(n["Data.Eq"]=n["Data.Eq"]||{}),function(t){"use strict";(n["Data.Ord.Unsafe"]=n["Data.Ord.Unsafe"]||{}).unsafeCompareImpl=function(n){return function(t){return function(r){return function(a){return function(e){return a<e?n:a===e?t:r}}}}}}(),function(t){"use strict";n["Data.Eq"],n["Data.Semigroup"],n["Data.Show"];var r=function(){function n(){}return n.value=new n,n}(),a=function(){function n(){}return n.value=new n,n}(),e=function(){function n(){}return n.value=new n,n}();t.LT=r,t.GT=a,t.EQ=e}(n["Data.Ordering"]=n["Data.Ordering"]||{}),function(t){"use strict";var r=n["Data.Ord.Unsafe"],a=n["Data.Ordering"],e=r.unsafeCompareImpl(a.LT.value)(a.EQ.value)(a.GT.value);t.unsafeCompare=e}(n["Data.Ord.Unsafe"]=n["Data.Ord.Unsafe"]||{}),function(t){"use strict";n["Data.Ord"];var r=n["Data.Eq"],a=n["Data.Ord.Unsafe"],e=(n["Data.Ordering"],n["Data.Ring"],n["Data.Semiring"],n["Data.Symbol"],n["Data.Unit"],n["Data.Void"],n["Record.Unsafe"],n["Type.Data.RowList"],function(n,t){this.Eq0=n,this.compare=t}),o=new e(function(){return r.eqInt},a.unsafeCompare),i=function(n){return n.compare};t.Ord=e,t.compare=i,t.comparing=function(n){return function(t){return function(r){return function(a){return i(n)(t(r))(t(a))}}}},t.ordInt=o}(n["Data.Ord"]=n["Data.Ord"]||{}),function(t){"use strict";n["Control.Category"],n["Data.Boolean"],n["Data.Ord"],n["Data.Ring"];t.flip=function(n){return function(t){return function(r){return n(r)(t)}}},t.const=function(n){return function(t){return n}}}(n["Data.Function"]=n["Data.Function"]||{}),function(t){"use strict";(n["Data.Functor"]=n["Data.Functor"]||{}).arrayMap=function(n){return function(t){for(var r=t.length,a=new Array(r),e=0;e<r;e++)a[e]=n(t[e]);return a}}}(),function(t){"use strict";var r=n["Data.Functor"],a=(n["Control.Semigroupoid"],n["Data.Function"]),e=n["Data.Unit"],o=function(n){this.map=n},i=function(n){return n.map},u=new o(r.arrayMap);t.Functor=o,t.map=i,t.void=function(n){return i(n)(a.const(e.unit))},t.functorArray=u}(n["Data.Functor"]=n["Data.Functor"]||{}),function(t){"use strict";var r=n["Control.Apply"],a=(n["Control.Category"],n["Data.Function"],n["Data.Functor"]),e=function(n,t){this.Functor0=n,this.apply=t},o=new e(function(){return a.functorArray},r.arrayApply);t.Apply=e,t.apply=function(n){return n.apply},t.applyArray=o}(n["Control.Apply"]=n["Control.Apply"]||{}),function(t){"use strict";n["Control.Apply"],n["Data.Functor"],n["Data.Unit"];t.Applicative=function(n,t){this.Apply0=n,this.pure=t},t.pure=function(n){return n.pure}}(n["Control.Applicative"]=n["Control.Applicative"]||{}),function(t){"use strict";(n["Control.Bind"]=n["Control.Bind"]||{}).arrayBind=function(n){return function(t){for(var r=[],a=0,e=n.length;a<e;a++)Array.prototype.push.apply(r,t(n[a]));return r}}}(),function(t){"use strict";var r=n["Control.Bind"],a=(n["Control.Applicative"],n["Control.Apply"]),e=(n["Control.Category"],n["Data.Function"]),o=(n["Data.Functor"],n["Data.Unit"],function(n,t){this.Apply0=n,this.bind=t}),i=function(n){this.discard=n},u=new o(function(){return a.applyArray},r.arrayBind),c=function(n){return n.bind},f=new i(function(n){return c(n)});t.Bind=o,t.bind=c,t.bindFlipped=function(n){return e.flip(c(n))},t.Discard=i,t.discard=function(n){return n.discard},t.bindArray=u,t.discardUnit=f}(n["Control.Bind"]=n["Control.Bind"]||{}),function(n){"use strict";n.map_=function(n){return function(t){return function(){return n(t())}}},n.pure_=function(n){return function(){return n}},n.bind_=function(n){return function(t){return function(){return t(n())()}}},n.while=function(n){return function(t){return function(){for(;n();)t()}}},n.new=function(n){return function(){return{value:n}}},n.read=function(n){return function(){return n.value}},n.write=function(n){return function(t){return function(){return t.value=n}}}}(n["Control.Monad.ST.Internal"]=n["Control.Monad.ST.Internal"]||{}),function(t){"use strict";var r=n["Control.Applicative"],a=(n["Control.Apply"],n["Control.Bind"]);n["Data.Functor"],n["Data.Unit"];t.Monad=function(n,t){this.Applicative0=n,this.Bind1=t},t.ap=function(n){return function(t){return function(e){return a.bind(n.Bind1())(t)(function(t){return a.bind(n.Bind1())(e)(function(a){return r.pure(n.Applicative0())(t(a))})})}}}}(n["Control.Monad"]=n["Control.Monad"]||{}),function(t){"use strict";n["Control.Alt"],n["Control.Alternative"],n["Control.Applicative"];var r=n["Control.Apply"],a=n["Control.Bind"],e=(n["Control.Category"],n["Control.Extend"],n["Control.Monad"],n["Control.MonadZero"],n["Control.Plus"],n["Data.Bounded"],n["Data.Eq"],n["Data.Function"],n["Data.Functor"]),o=(n["Data.Functor.Invariant"],n["Data.Monoid"],n["Data.Ord"],n["Data.Ordering"],n["Data.Semigroup"],n["Data.Show"],n["Data.Unit"],n.Prelude,function(){function n(){}return n.value=new n,n}()),i=function(){function n(n){this.value0=n}return n.create=function(t){return new n(t)},n}(),u=new e.Functor(function(n){return function(t){return t instanceof i?new i(n(t.value0)):o.value}}),c=new r.Apply(function(){return u},function(n){return function(t){if(n instanceof i)return e.map(u)(n.value0)(t);if(n instanceof o)return o.value;throw new Error("Failed pattern match at Data.Maybe (line 67, column 1 - line 67, column 35): "+[n.constructor.name,t.constructor.name])}}),f=new a.Bind(function(){return c},function(n){return function(t){if(n instanceof i)return t(n.value0);if(n instanceof o)return o.value;throw new Error("Failed pattern match at Data.Maybe (line 125, column 1 - line 125, column 33): "+[n.constructor.name,t.constructor.name])}});t.Nothing=o,t.Just=i,t.maybe=function(n){return function(t){return function(r){if(r instanceof o)return n;if(r instanceof i)return t(r.value0);throw new Error("Failed pattern match at Data.Maybe (line 217, column 1 - line 217, column 51): "+[n.constructor.name,t.constructor.name,r.constructor.name])}}},t.functorMaybe=u,t.applyMaybe=c,t.bindMaybe=f}(n["Data.Maybe"]=n["Data.Maybe"]||{}),function(t){"use strict";n["Control.Alt"];var r=n["Control.Applicative"],a=n["Control.Apply"],e=n["Control.Bind"],o=(n["Control.Extend"],n["Control.Monad"],n["Control.Semigroupoid"],n["Data.Bifoldable"],n["Data.Bifunctor"],n["Data.Bitraversable"],n["Data.Bounded"],n["Data.Eq"],n["Data.Foldable"],n["Data.FoldableWithIndex"],n["Data.Function"],n["Data.Functor"]),i=(n["Data.Functor.Invariant"],n["Data.FunctorWithIndex"],n["Data.Maybe"]),u=(n["Data.Monoid"],n["Data.Ord"],n["Data.Ordering"],n["Data.Semigroup"],n["Data.Show"],n["Data.Traversable"],n["Data.TraversableWithIndex"],n["Data.Unit"],n.Prelude,function(){function n(n){this.value0=n}return n.create=function(t){return new n(t)},n}()),c=function(){function n(n){this.value0=n}return n.create=function(t){return new n(t)},n}(),f=new o.Functor(function(n){return function(t){if(t instanceof u)return new u(t.value0);if(t instanceof c)return new c(n(t.value0));throw new Error("Failed pattern match at Data.Either (line 38, column 8 - line 38, column 52): "+[t.constructor.name])}}),l=function(n){return function(t){return function(r){if(r instanceof u)return n(r.value0);if(r instanceof c)return t(r.value0);throw new Error("Failed pattern match at Data.Either (line 238, column 1 - line 238, column 64): "+[n.constructor.name,t.constructor.name,r.constructor.name])}}},s=new a.Apply(function(){return f},function(n){return function(t){if(n instanceof u)return new u(n.value0);if(n instanceof c)return o.map(f)(n.value0)(t);throw new Error("Failed pattern match at Data.Either (line 82, column 1 - line 82, column 41): "+[n.constructor.name,t.constructor.name])}}),d=new e.Bind(function(){return s},l(function(n){return function(t){return new u(n)}})(function(n){return function(t){return t(n)}})),p=new r.Applicative(function(){return s},c.create);t.Left=u,t.Right=c,t.either=l,t.note=function(n){return i.maybe(new u(n))(c.create)},t.functorEither=f,t.applyEither=s,t.applicativeEither=p,t.bindEither=d}(n["Data.Either"]=n["Data.Either"]||{}),function(t){"use strict";(n["Partial.Unsafe"]=n["Partial.Unsafe"]||{}).unsafePartial=function(n){return n()}}(),function(t){"use strict";(n["Partial"]=n["Partial"]||{}).crashWith=function(){return function(n){throw new Error(n)}}}(),function(t){"use strict";var r=n.Partial;t.crashWith=r.crashWith}(n.Partial=n.Partial||{}),function(t){"use strict";var r=n["Partial.Unsafe"],a=n.Partial;t.unsafeCrashWith=function(n){return r.unsafePartial(function(t){return a.crashWith(t)(n)})}}(n["Partial.Unsafe"]=n["Partial.Unsafe"]||{}),function(t){"use strict";n["Control.Applicative"],n["Control.Bind"],n["Control.Monad"],n["Control.Semigroupoid"],n["Data.Bifunctor"],n["Data.Either"],n["Data.Functor"],n["Data.Identity"],n["Data.Maybe"],n["Data.Unit"],n.Effect,n["Effect.Ref"],n["Partial.Unsafe"],n.Prelude;var r=function(){function n(n){this.value0=n}return n.create=function(t){return new n(t)},n}(),a=function(){function n(n){this.value0=n}return n.create=function(t){return new n(t)},n}(),e=function(n){return n.tailRecM};t.Loop=r,t.Done=a,t.MonadRec=function(n,t){this.Monad0=n,this.tailRecM=t},t.tailRecM=e,t.tailRecM2=function(n){return function(t){return function(r){return function(a){return e(n)(function(n){return t(n.a)(n.b)})({a:r,b:a})}}}}}(n["Control.Monad.Rec.Class"]=n["Control.Monad.Rec.Class"]||{}),function(t){"use strict";var r=n["Control.Monad.ST.Internal"],a=n["Control.Applicative"],e=n["Control.Apply"],o=n["Control.Bind"],i=n["Control.Monad"],u=n["Control.Monad.Rec.Class"],c=n["Data.Functor"],f=n["Data.Unit"],l=(n["Partial.Unsafe"],n.Prelude,new c.Functor(r.map_)),s=new i.Monad(function(){return D},function(){return d}),d=new o.Bind(function(){return p},r.bind_),p=new e.Apply(function(){return l},i.ap(s)),D=new a.Applicative(function(){return p},r.pure_),m=new u.MonadRec(function(){return s},function(n){return function(t){var e=function(n){return n instanceof u.Loop},i=function(n){if(n instanceof u.Done)return n.value0;throw new Error("Failed pattern match at Control.Monad.ST.Internal (line 54, column 32 - line 54, column 46): "+[n.constructor.name])};return o.bind(d)(o.bindFlipped(d)(r.new)(n(t)))(function(t){return o.discard(o.discardUnit)(d)(r.while(c.map(l)(e)(r.read(t)))(o.bind(d)(r.read(t))(function(e){if(e instanceof u.Loop)return o.bind(d)(n(e.value0))(function(n){return c.void(l)(r.write(n)(t))});if(e instanceof u.Done)return a.pure(D)(f.unit);throw new Error("Failed pattern match at Control.Monad.ST.Internal (line 46, column 18 - line 50, column 28): "+[e.constructor.name])})))(function(){return c.map(l)(i)(r.read(t))})})}});t.functorST=l,t.applyST=p,t.applicativeST=D,t.bindST=d,t.monadST=s,t.monadRecST=m}(n["Control.Monad.ST.Internal"]=n["Control.Monad.ST.Internal"]||{}),function(n){"use strict";n.range=function(n){return function(t){for(var r=n>t?-1:1,a=new Array(r*(t-n)+1),e=n,o=0;e!==t;)a[o++]=e,e+=r;return a[o]=e,a}},n.length=function(n){return n.length},n.indexImpl=function(n){return function(t){return function(r){return function(a){return a<0||a>=r.length?t:n(r[a])}}}},n.slice=function(n){return function(t){return function(r){return r.slice(n,t)}}},n.drop=function(n){return function(t){return n<1?t:t.slice(n)}},n.zipWith=function(n){return function(t){return function(r){for(var a=t.length<r.length?t.length:r.length,e=new Array(a),o=0;o<a;o++)e[o]=n(t[o])(r[o]);return e}}},n.unsafeIndexImpl=function(n){return function(t){return n[t]}}}(n["Data.Array"]=n["Data.Array"]||{}),function(n){"use strict";n.empty=function(){return[]},n.pushAll=function(n){return function(t){return function(){return t.push.apply(t,n)}}},n.sortByImpl=function(n){return function(t){return function(){return t.sort(function(t,r){return n(t)(r)})}}}}(n["Data.Array.ST"]=n["Data.Array.ST"]||{}),function(t){"use strict";(n["Unsafe.Coerce"]=n["Unsafe.Coerce"]||{}).unsafeCoerce=function(n){return n}}(),function(t){"use strict";var r=n["Unsafe.Coerce"];t.unsafeCoerce=r.unsafeCoerce}(n["Unsafe.Coerce"]=n["Unsafe.Coerce"]||{}),function(t){"use strict";var r=n["Data.Array.ST"],a=n["Control.Applicative"],e=(n["Control.Bind"],n["Control.Monad.ST"],n["Control.Monad.ST.Internal"]),o=(n["Control.Semigroupoid"],n["Data.Maybe"],n["Data.Ord"]),i=n["Data.Ordering"],u=(n["Data.Ring"],n.Prelude,n["Unsafe.Coerce"],function(n){return r.sortByImpl(function(t){return function(r){var a=n(t)(r);if(a instanceof i.GT)return 1;if(a instanceof i.EQ)return 0;if(a instanceof i.LT)return-1;throw new Error("Failed pattern match at Data.Array.ST (line 94, column 15 - line 99, column 1): "+[a.constructor.name])}})});t.push=function(n){return r.pushAll([n])},t.sortBy=u,t.sortWith=function(n){return function(t){return u(o.comparing(n)(t))}},t.unsafeFreeze=function(n){return a.pure(e.applicativeST)(n)},t.unsafeThaw=function(n){return a.pure(e.applicativeST)(n)},t.empty=r.empty}(n["Data.Array.ST"]=n["Data.Array.ST"]||{}),function(t){"use strict";var r=n["Data.Array"],a=(n["Control.Alt"],n["Control.Alternative"],n["Control.Applicative"]),e=(n["Control.Apply"],n["Control.Bind"]),o=(n["Control.Category"],n["Control.Lazy"],n["Control.Monad.Rec.Class"]),i=(n["Control.Monad.ST"],n["Control.Monad.ST.Internal"],n["Control.Semigroupoid"],n["Data.Array.NonEmpty.Internal"],n["Data.Array.ST"],n["Data.Array.ST.Iterator"],n["Data.Boolean"]),u=(n["Data.Eq"],n["Data.Foldable"],n["Data.Function"]),c=(n["Data.Functor"],n["Data.HeytingAlgebra"],n["Data.Maybe"]),f=(n["Data.Ord"],n["Data.Ordering"],n["Data.Ring"],n["Data.Semigroup"],n["Data.Semiring"],n["Data.Traversable"],n["Data.Tuple"],n["Data.Unfoldable"],n["Partial.Unsafe"],n.Prelude,n["Unsafe.Coerce"],function(n){return r.unsafeIndexImpl}),l=function(n){return[n]},s=r.indexImpl(c.Just.create)(c.Nothing.value),d=u.flip(e.bind(e.bindArray));t.singleton=l,t.head=function(n){return s(n)(0)},t.index=s,t.concatMap=d,t.mapMaybe=function(n){return d(function(t){return c.maybe([])(l)(n(t))})},t.mapWithIndex=function(n){return function(t){return r.zipWith(n)(r.range(0)(r.length(t)-1|0))(t)}},t.foldRecM=function(n){return function(t){return function(u){return function(c){return o.tailRecM2(n)(function(u){return function(l){if(l>=r.length(c))return a.pure(n.Monad0().Applicative0())(new o.Done(u));if(i.otherwise)return e.bind(n.Monad0().Bind1())(t(u)(f()(c)(l)))(function(t){return a.pure(n.Monad0().Applicative0())(new o.Loop({a:t,b:l+1|0}))});throw new Error("Failed pattern match at Data.Array (line 1099, column 3 - line 1103, column 42): "+[u.constructor.name,l.constructor.name])}})(u)(0)}}}},t.unsafeIndex=f,t.drop=r.drop}(n["Data.Array"]=n["Data.Array"]||{}),function(t){"use strict";(n["Data.Int"]=n["Data.Int"]||{}).fromStringAsImpl=function(n){return function(t){return function(r){var a;a=r<11?"[0-"+(r-1).toString()+"]":11===r?"[0-9a]":"[0-9a-"+String.fromCharCode(86+r)+"]";var e=new RegExp("^[\\+\\-]?"+a+"+$","i");return function(a){if(e.test(a)){var o=parseInt(a,r);return(0|o)===o?n(o):t}return t}}}}}(),function(t){"use strict";var r=n["Data.Int"],a=(n["Control.Category"],n["Control.Semigroupoid"],n["Data.Boolean"],n["Data.Bounded"],n["Data.CommutativeRing"],n["Data.DivisionRing"],n["Data.Eq"],n["Data.EuclideanRing"],n["Data.HeytingAlgebra"],n["Data.Int.Bits"],n["Data.Maybe"]),e=(n["Data.Ord"],n["Data.Ordering"],n["Data.Ring"],n["Data.Semiring"],n["Data.Show"],n.Global,n.Math,n.Prelude,r.fromStringAsImpl(a.Just.create)(a.Nothing.value)),o=e(10);t.fromString=o,t.fromStringAs=e}(n["Data.Int"]=n["Data.Int"]||{}),function(t){"use strict";(n["Data.String.CodeUnits"]=n["Data.String.CodeUnits"]||{}).length=function(n){return n.length}}(),function(t){"use strict";var r=n["Data.String.CodeUnits"];n["Control.Semigroupoid"],n["Data.Boolean"],n["Data.Eq"],n["Data.Function"],n["Data.HeytingAlgebra"],n["Data.Maybe"],n["Data.Ord"],n["Data.Ring"],n["Data.Semiring"],n["Data.String.Pattern"],n["Data.String.Unsafe"],n.Prelude;t.length=r.length}(n["Data.String.CodeUnits"]=n["Data.String.CodeUnits"]||{}),function(n){"use strict";n.split=function(n){return function(t){return t.split(n)}},n.trim=function(n){return n.trim()},n.joinWith=function(n){return function(t){return t.join(n)}}}(n["Data.String.Common"]=n["Data.String.Common"]||{}),function(t){"use strict";var r=n["Data.String.Common"];n["Data.Eq"],n["Data.Ordering"],n["Data.String.Pattern"],n.Prelude;t.split=r.split,t.trim=r.trim,t.joinWith=r.joinWith}(n["Data.String.Common"]=n["Data.String.Common"]||{}),function(t){"use strict";var r=n["Control.Applicative"],a=n["Control.Bind"],e=(n["Control.Monad.ST"],n["Control.Monad.ST.Internal"]),o=n["Data.Array"],i=n["Data.Array.ST"],u=n["Data.Either"],c=(n["Data.Eq"],n["Data.Functor"]),f=n["Data.Int"],l=n["Data.Maybe"],s=n["Data.Ord"],d=n["Data.Ordering"],p=(n["Data.Ring"],n["Data.Semigroup"],n["Data.Semiring"],n["Data.Show"]),D=(n["Data.String"],n["Data.String.CodeUnits"]),m=n["Data.String.Common"],h=(n["Data.String.Pattern"],n["Partial.Unsafe"]),C=(n.Prelude,function(n){var t=m.split("\n")(m.trim(n));return a.bind(u.bindEither)(u.note("n m")(a.bind(l.bindMaybe)(o.head(t))(function(n){var t=o.mapMaybe(f.fromString)(m.split(" ")(n));return 2===t.length?new l.Just({n:t[0],m:t[1]}):l.Nothing.value})))(function(n){var a=o.mapMaybe(function(n){var t=o.mapMaybe(f.fromString)(m.split(" ")(n));return 2===t.length?new l.Just({p:t[0],y:t[1]}):l.Nothing.value})(o.drop(1)(t));return r.pure(u.applicativeEither)(m.joinWith("\n")((n.n,function(n){return function(n){var t,r,a,u,f=function(n){var t=p.show(p.showInt)(n),r=D.length(t);return 0===r?"000000":1===r?"00000"+t:2===r?"0000"+t:3===r?"000"+t:4===r?"00"+t:5===r?"0"+t:t};return t=i.unsafeThaw(o.mapWithIndex(function(n){return function(t){return{p:t.p,y:t.y,i:n}}})(n))(),i.sortBy(function(n){return function(t){var r=s.compare(s.ordInt)(n.p)(t.p);if(r instanceof d.LT)return d.LT.value;if(r instanceof d.GT)return d.GT.value;if(r instanceof d.EQ)return s.compare(s.ordInt)(n.y)(t.y);throw new Error("Failed pattern match at AtCoder.ABC113.C (line 58, column 9 - line 61, column 30): "+[r.constructor.name])}})(t)(),r=i.unsafeFreeze(t)(),a=i.empty(),o.foldRecM(e.monadRecST)(function(n){return function(t){var r=(n["p'"]!==t.p?0:n.x)+1|0;return function(){return i.push({s:f(t.p)+f(r),i:t.i})(a)(),{"p'":t.p,x:r}}}})({"p'":-1,x:0})(r)(),i.sortWith(s.ordInt)(function(n){return n.i})(a)(),u=i.unsafeFreeze(a)(),c.map(c.functorArray)(function(n){return n.s})(u)}})(n.m)(a)))})});t.solve=function(n){var t=C(n);if(t instanceof u.Left)return h.unsafeCrashWith(t.value0);if(t instanceof u.Right)return t.value0;throw new Error("Failed pattern match at AtCoder.ABC113.C (line 20, column 3 - line 22, column 24): "+[t.constructor.name])}}(n["AtCoder.ABC113.C"]=n["AtCoder.ABC113.C"]||{}),function(t){"use strict";(n["Effect.Console"]=n["Effect.Console"]||{}).log=function(n){return function(){return console.log(n),{}}}}(),function(t){"use strict";var r=n["Effect.Console"];n["Data.Show"],n["Data.Unit"],n.Effect;t.log=r.log}(n["Effect.Console"]=n["Effect.Console"]||{}),function(t){"use strict";n["Node.Encoding"];var r=n["Data.Show"],a=(n.Prelude,function(){function n(){}return n.value=new n,n}()),e=function(){function n(){}return n.value=new n,n}(),o=function(){function n(){}return n.value=new n,n}(),i=function(){function n(){}return n.value=new n,n}(),u=function(){function n(){}return n.value=new n,n}(),c=function(){function n(){}return n.value=new n,n}(),f=function(){function n(){}return n.value=new n,n}(),l=function(){function n(){}return n.value=new n,n}(),s=new r.Show(function(n){if(n instanceof a)return"ASCII";if(n instanceof e)return"UTF8";if(n instanceof o)return"UTF16LE";if(n instanceof i)return"UCS2";if(n instanceof u)return"Base64";if(n instanceof c)return"Latin1";if(n instanceof f)return"Binary";if(n instanceof l)return"Hex";throw new Error("Failed pattern match at Node.Encoding (line 19, column 1 - line 19, column 39): "+[n.constructor.name])});t.ASCII=a,t.UTF8=e,t.UTF16LE=o,t.UCS2=i,t.Base64=u,t.Latin1=c,t.Binary=f,t.Hex=l,t.showEncoding=s}(n["Node.Encoding"]=n["Node.Encoding"]||{}),function(t){"use strict";(n["Node.FS.Internal"]=n["Node.FS.Internal"]||{}).unsafeRequireFS=require("fs")}(),function(t){"use strict";var r=n["Node.FS.Internal"],a=(n.Effect,n.Prelude,n["Unsafe.Coerce"].unsafeCoerce);t.mkEffect=a,t.unsafeRequireFS=r.unsafeRequireFS}(n["Node.FS.Internal"]=n["Node.FS.Internal"]||{}),function(t){"use strict";n["Control.Bind"],n["Control.Semigroupoid"],n["Data.DateTime"],n["Data.DateTime.Instant"],n["Data.EuclideanRing"],n["Data.Function"],n["Data.Function.Uncurried"],n["Data.Functor"],n["Data.Int"],n["Data.Maybe"],n["Data.Nullable"];var r=n["Data.Show"],a=(n["Data.Time.Duration"],n.Effect,n["Node.Buffer"],n["Node.Encoding"]),e=(n["Node.FS"],n["Node.FS.Internal"]),o=(n["Node.FS.Perms"],n["Node.FS.Stats"],n["Node.Path"],n.Prelude,e.unsafeRequireFS);t.readTextFile=function(n){return function(t){return e.mkEffect(function(e){return o.readFileSync(t,{encoding:r.show(a.showEncoding)(n)})})}}}(n["Node.FS.Sync"]=n["Node.FS.Sync"]||{}),function(t){"use strict";var r=n["AtCoder.ABC113.C"],a=(n["Control.Applicative"],n["Control.Bind"],n.Effect,n["Effect.Console"]),e=n["Node.Encoding"],o=n["Node.FS.Sync"];n.Prelude;t.main=function(){var n=o.readTextFile(e.UTF8.value)("/dev/stdin")(),t=r.solve(n);return a.log(t)()}}(n.Main=n.Main||{}),n.Main.main();
},{}]},{},["Focm"], null)


function getLines(input){
	return input.split("\n").map((s)=>s.trim())
}
function parseLine(line){
	return line.split(" ").map((s)=>s.trim());
}
function parseLineToInt(line){
	return line.split(" ").map((s)=>parseInt(s.trim()));
}
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	input = input.trim();
	if(input.length==2)
		console.log(input)
	else{
		var s='';
		for (var i = 0; i < input.length; i++) {
			s=s+input[input.length-1-i];
		}
		console.log(s)
	}

}
// Don't edit this line!
//Main(require("fs").readFileSync(__dirname+'/in.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

Constraints

The length of S is 2 or 3.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If the length of S is 2, print S as is; if the length is 3, print S after reversing it.

Sample Input 1

abc

Sample Output 1

cba

As the length of S is 3, we print it after reversing it.

Sample Input 2

ac

Sample Output 2

ac

As the length of S is 2, we print it as is.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


input = require('fs').readFileSync('/dev/stdin', 'utf8');
console.log(input.length == 2 ? input : input.split('').reverse().join(''));


var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  var K = one[2];
  for(var i = 0; i < K; i++){
    if(i % 2 == 0){
       if(A % 2 == 1){
          A--;
       }
       B += A / 2;
       A /= 2;
    }else{
       if(B % 2 == 1){
          B--;
       }
       A += B / 2;
       B /= 2;
    }
  }
  myout(A + " " + B);
}

Score : 200 points

Problem Statement

In the beginning, Takahashi has A cookies, and Aoki has B cookies.
They will perform the following operation alternately, starting from Takahashi:

If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.

Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.

Constraints

1 \leq A,B \leq 10^9

1 \leq K \leq 100

A,B and K are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.

Sample Input 1

5 4 2

Sample Output 1

5 3

The process will go as follows:

In the beginning, Takahashi and Aoki have 5 and 4 cookies, respectively.

Takahashi eats one cookie and gives two cookies to Aoki. They now have 2 and 6 cookies, respectively.

Aoki gives three cookies to Takahashi. They now have 5 and 3 cookies, respectively.

Sample Input 2

3 3 3

Sample Output 2

1 3

Sample Input 3

314159265 358979323 84

Sample Output 3

448759046 224379523


function Main(input){
 const lines = input.split('\n');
  if (lines[0] === 1){
  return 'HELLO WORLD'
  }
  if (lines[0] === 2){
  return (lines[1]*1) + (lines[2]*1)
  }
}
console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Score: 100 points

Problem Statement

In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.

One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.

Takahashi, who is taking this exam, suddenly forgets his age.

He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.

Write this program for him.

Constraints

N is 1 or 2.

A is an integer between 1 and 9 (inclusive).

B is an integer between 1 and 9 (inclusive).

Input

Input is given from Standard Input in one of the following formats:

1

2
A
B

Output

If N=1, print Hello World; if N=2, print A+B.

Sample Input 1

1

Sample Output 1

Hello World

As N=1, Takahashi is one year old. Thus, we should print Hello World.

Sample Input 2

2
3
5

Sample Output 2

8

As N=2, Takahashi is two years old. Thus, we should print A+B, which is 8 since A=3 and B=5.


// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(tmp[0], 10);
	var M = parseInt(tmp[1], 10);

    var divisors = divisor(M);
    var max = 0;
            for (var i =0;i < divisors.length;i++) {
                var d = divisors[i];
                if (M / d >= N) {
                    max = Math.max(max, d);
                }
            }

	//出力
	console.log('%d',max);
}
function divisor(n) {
        var res = [];
        for (var i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                res.push(i);
                if (n / i != i) {
                    res.push(n / i);
                }
            }
        }
        return res;
    }

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 400 points

Problem Statement

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Sample Input 1

3 14

Sample Output 1

2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000


function Main(input){
  var n = input.split("");
  for(i=0;i<=2;i++){
    if(n[i]=="1"){
      n[i] = 9;
    }else if(n[i]=="9"){
      n[i] = 1;
    }
  }
  console.log(n.join(""));

}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Score : 100 points

Problem Statement

Cat Snuke is learning to write characters.
Today, he practiced writing digits 1 and 9, but he did it the other way around.

You are given a three-digit integer n written by Snuke.
Print the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.

Constraints

111 \leq n \leq 999

n is an integer consisting of digits 1 and 9.

Input

Input is given from Standard Input in the following format:

n

Output

Print the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.

Sample Input 1

119

Sample Output 1

991

Replace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.

Sample Input 2

999

Sample Output 2

111


'use strict';
const main = input => {
  const n = parseInt(input[0]), v = input[1].split(' ').map(val => parseInt(val));
  // console.log(n, v);
  let even = [], odd = [];
  for(let i=0; i<n; i++) {
    if(i%2) odd.push(v[i]);
    else even.push(v[i]);
  }
  // console.log(even, odd);

  let oddmode = (new Array(100000)).fill(0);
  odd.map(val => oddmode[val]++);
  let Omax = Math.max.apply(null, oddmode);
  let OmaxId = oddmode.indexOf(Math.max.apply(null, oddmode));
  oddmode[OmaxId] = 0;
  let Osec = Math.max.apply(null, oddmode);
  let OsecId = oddmode.indexOf(Math.max.apply(null, oddmode));

  let evenmode = (new Array(100000)).fill(0);
  even.map(val => evenmode[val]++);
  let Emax = Math.max.apply(null, evenmode);
  let EmaxId = evenmode.indexOf(Math.max.apply(null, evenmode));
  evenmode[EmaxId] = 0;
  let Esec = Math.max.apply(null, evenmode);
  let EsecId = evenmode.indexOf(Math.max.apply(null, evenmode));

  // console.log(oddmode, evenmode);
  // console.log(Omax, Emax, Osec, Esec);

  if (OmaxId == EmaxId) {
    if (odd.length-Omax == even.length-Emax) {
      if (odd.length-Osec > even.length-Esec) {
        console.log(n-Esec-Omax);
      } else {
        console.log(n-Osec-Emax);
      }
    } else if (odd.length-Omax > even.length-Emax) {
      console.log(n-Omax-Esec);
    } else {
      console.log(n-Emax-Osec);

    }
  } else {
    console.log(n-Omax-Emax);
  }
  // console.log(even.length, odd.length);

}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.


function main(input) {
  var N = input[0].split(" ")[0]-0;
  var list = input[1].split(" ").map(v=>v-0);
  var a = {};
  var b = {};
  list.forEach((v,i)=>{
    if(i%2==0){
      a[v] = (a[v]||0)+1;
    }else{
      b[v] = (b[v]||0)+1;
    }
  });
  var alist = Object.keys(a).sort((aa,bb)=>a[bb]-a[aa]);
  var blist = Object.keys(b).sort((aa,bb)=>b[bb]-b[aa]);
  var ans = 0;
  var abase,bbase = 0;
  if(alist[0] == blist[0]){
    if(alist[1] > blist[1]){
      abase = 0, bbase = 1;
    }else {
      abase = 1, bbase = 0;
    }
  }else{
    abase = 0, bbase=0;
  }
  alist.filter((v,i)=>i!=abase).forEach(v=>ans+=a[v]);
  blist.filter((v,i)=>i!=bbase).forEach(v=>ans+=b[v]);
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


// 解説をそのまま写経した感じです

function Main(input){
  input = input.split("\n");
  var n = ~~input[0]
  var v = input[1].split(" ");
  var even = [];
  var odd = [];
  for(var i = 0; i < n; i++){
  	var h = v[i];
    var a = (i%2?odd:even)[h];
    a = a || {val:h,count:0};
    a.count++;
    if(i%2){odd[h]=a}else{even[h]=a};
  }
  even = even.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  odd = odd.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  // filter : nullを消去

  if(even[0].val!=odd[0].val){
  	return n - even[0].count - odd[0].count;
    // 最頻値が異なる
  }
  if(!even[1] && !even[2]){
  	return n/2;
    // 偶奇どちらの副最頻値も存在しない
    // （すべての数字が同じ）
  }
  if(!even[1]){
  	return n - even[0].count - odd[1].count;
    // 偶数番目の副最頻値が存在しない
  }
  if(!odd[1]){
  	return n - even[1].count - odd[0].count;
    // 奇数番目の副最頻値が存在しない
  }
  return Math.min(
  	n - even[0].count - odd[1].count,
    n - even[1].count - odd[0].count
  );
}

if(typeof require !== 'undefined')console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));


(function(input) {
  'use strict';
  const INPUT = input.split("\n")
  for(let i = 0; i<INPUT.length; i=i+2){
    if(!INPUT[i] || !INPUT[i+1]) continue
    if (INPUT[i] === 2) {
      console.log('0')
      continue
    }
    const length = INPUT[i]
    const line = INPUT[i+1].split(" ")
    let Max = 0
    let MaxPair = ''
    let countHash = {}
    for(let j=0; j< length; j=j+2){
      countHash[[line[j],line[j+1]].toString()]
      ? countHash[[line[j],line[j+1]].toString()]++
      : countHash[[line[j],line[j+1]].toString()]=1
      if(countHash[[line[j],line[j+1]].toString()] > Max){
        Max = countHash[[line[j],line[j+1]].toString()]
        MaxPair = [line[j],line[j+1]].toString()
      }
    }

    MaxPair = MaxPair.split(',')
    let res = 0
    for(let j=0; j< length; j=j+2){
      if(MaxPair[0] != line[j]) res++
      if(MaxPair[1] != line[j+1]) res++
    }
    console.log(res)
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<v)v=rest[i];return v}
function max(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>v)v=rest[i];return v}
function gcd(){var rest=arguments,v=rest[0],temp=(a,b)=>b?temp(b,a%b):a;for(var i=1;i<rest.length;i++)v=temp(v,rest[i]);return v}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var vs = toIntArr(input[1].split(' '));
	var odd = [];
	var even = [];
	for(var i = 0; i < n; i++){
		if(i%2===1){
			even[vs[i]] = !even[vs[i]]? 1: even[vs[i]] + 1;
		}else{
			odd[vs[i]] = !odd[vs[i]]? 1: odd[vs[i]] + 1;
		}
	}
	var xs = odd.map((e,ind,arr)=>({el:e,ind:ind})).filter(el=>el.el>0).sort((a,b)=>b.el-a.el);
	var ys = even.map((e,ind,arr)=>({el:e,ind:ind})).filter(el=>el.el>0).sort((a,b)=>b.el-a.el);
	var ans = 0;
	if(xs[0].ind === ys[0].ind){
		if(xs.length === 1){
			if(ys.length === 1){
				ans = n/2;
			}else{
				ans = n/2 - ys[1].el;
			}
		}else{
			if(ys.length === 1){
				ans = n/2 - xs[1].el;
			}else{
				ans = min(n - xs[0].el - ys[1].el, n - xs[1].el - ys[0].el);
			}
		}
	}else{
		ans = n - xs[0].el - ys[0].el;
	}

	console.log(ans);
	return 0;
}


var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<v)v=rest[i];return v}
function max(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>v)v=rest[i];return v}
function gcd(){var rest=arguments,v=rest[0],temp=(a,b)=>b?temp(b,a%b):a;for(var i=1;i<rest.length;i++)v=temp(v,rest[i]);return v}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var xys = [];
	for(var i = 0; i < n; i++){
		xys[i] = toIntArr(input[i+1].split(' '));
		if((xys[i][0]+xys[i][1]+xys[0][0]+xys[0][1])%2 !== 0){
			console.log(-1);
			return 0;
		}
	}
	var po = (xys[0][0]+xys[0][1])%2;
	if(po===1){
		xys = xys.map(e=>e[0]%2===0?e:e.reverse());
	}
	/*
	even
	m = 10
	di = 1*10
	2n -> 4:+ (10-4)/2:+,-
	*/
	var m = 20;
	if(xys[0][0]%2===1) m++;
	if(xys[0][1]%2===1) m++;
	console.log(m);
	var ds = [];
	ds.length = m;
	ds.fill(1);
	ds = ds.join(' ');
	console.log(ds);

	for(var i = 0; i < n; i++){
		var str = '';
		var xy = xys[i];
		if(xy[0]%2===1){
			str += 'R';
			xy[0]++;
		}
		if(xy[1]%2===1){
			str += 'R';
			xy[1]++;
		}
	str += ''.padEnd((10+xy[0])/2,'R');
	str += ''.padEnd((10-xy[0])/2,'L');
	str += ''.padEnd((10+xy[1])/2,'U');
	str += ''.padEnd((10-xy[1])/2,'D');
	console.log(str);
	}

	return 0;
}

Score : 600 points

Problem Statement

Snuke is introducing a robot arm with the following properties to his factory:

The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i-1 and Joint i. The length of Section i is d_i.

For each section, its mode can be specified individually. There are four modes: L, R, D and U. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint i will be determined as follows (we denote its coordinates as (x_i, y_i)):

(x_0, y_0) = (0, 0).

If the mode of Section i is L, (x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1}).

If the mode of Section i is R, (x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1}).

If the mode of Section i is D, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i}).

If the mode of Section i is U, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i}).

Snuke would like to introduce a robot arm so that the position of Joint m can be matched with all of the N points (X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N) by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint m to each point (X_j, Y_j).

Constraints

All values in input are integers.

1 \leq N \leq 1000

-10^9 \leq X_i \leq 10^9

-10^9 \leq Y_i \leq 10^9

Partial Score

In the test cases worth 300 points, -10 \leq X_i \leq 10 and -10 \leq Y_i \leq 10 hold.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

Output

If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print -1.

m
d_1 d_2 ... d_m
w_1
w_2
:
w_N

m and d_i are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, 1 \leq m \leq 40 and 1 \leq d_i \leq 10^{12} must hold. Also, m and d_i must all be integers.

w_j is a string of length m that represents the way to bring Joint m of the robot arm to point (X_j, Y_j).
The i-th character of w_j should be one of the letters L, R, D and U, representing the mode of Section i.

Sample Input 1

3
-1 0
0 3
2 -1

Sample Output 1

2
1 2
RL
UU
DR

In the given way to bring Joint m of the robot arm to each (X_j, Y_j), the positions of the joints will be as follows:

To (X_1, Y_1) = (-1, 0): First, the position of Joint 0 is (x_0, y_0) = (0, 0). As the mode of Section 1 is R, the position of Joint 1 is (x_1, y_1) = (1, 0). Then, as the mode of Section 2 is L, the position of Joint 2 is (x_2, y_2) = (-1, 0).

To (X_2, Y_2) = (0, 3): (x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3).

To (X_3, Y_3) = (2, -1): (x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1).

Sample Input 2

5
0 0
1 0
2 0
3 0
4 0

Sample Output 2

-1

Sample Input 3

2
1 1
1 1

Sample Output 3

2
1 1
RU
UR

There may be duplicated points among (X_j, Y_j).

Sample Input 4

3
-7 -3
7 3
-3 -7

Sample Output 4

5
3 1 4 1 5
LRDUL
RDULR
DULRD


function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var x = o.m(n);
  var t = (x[0][0]+x[0][1]) & 1;
  for(var i = 1; i < n; i++){
    var u = (x[i][0]+x[i][1]) & 1;
    if(u !== t)return -1;
  }
  var m = 20 - t;
  var d = Array(m).fill(1);
  var w = [];
  for(i = 0; i < n; i++){
    w[i] = "";
    for(var j = 0; j < m; j++){
      if(x[i][0] > 0){x[i][0]--; w[i] += "L";}
      else if(x[i][0] < 0){x[i][0]++; w[i] += "R";}
      else if(x[i][1] > 0){x[i][1]--; w[i] += "D";}
      else{x[i][1]++; w[i] += "U";}
    }
  }
  return m + "\n" + d.join(" ") + "\n" + w.join("\n");
}


const MOD = 10**9+7
// factors[f].e+n-1、において max(n)=10**5, max(factors[f].e)=log(M)=log(10**9)=21
const N = 10**5+30

let fac = [...new Array(N)].fill(0)
let ifac = [...new Array(N)].fill(0)
const mul = (a,b) => ((a>>16)*b%MOD*65536+(a&65535)*b)%MOD;

const factorization = (n) => {
    let primes= []
    for(let i=2; i*i<=n; i++) {
        let exponent = 0
        while(n%i===0) {
            n /= i
            exponent++
        }
        if(exponent) {
            primes.push({p:i, e:exponent})
        }
    }

    if(n!==1) {
        primes.push({p:n, e:1})
    }
    return primes
}

const mpow = (x, n) => {
    ans = 1;
    let _x = x
    while(n != 0){
        if(n & 1) ans = mul(ans,_x);
        _x = mul(_x,_x);
        n = n >> 1;
    }
    return ans;
}

const comb = (n, r) => {
    if(n == 0 && r == 0) return 1;
    if(n < r || n < 0) return 0;
    const tmp = mul(ifac[n-r],ifac[r])
    return mul(tmp,fac[n])
}

const init = () => {
    fac[0] = 1;
    ifac[0] = 1;
    for(let i=0; i<N; i++){
        fac[i+1] = mul(fac[i],(i+1));
        ifac[i+1] = mpow(fac[i+1], MOD - 2)
    }
}

const main = (arg) => {
    let [n, m] = arg.split(" ").map(Number)
    let factors = factorization(m)
    let ans = 1
    init()
    Object.keys(factors).forEach(f=>{
        let a = factors[f].e+n-1
        let b = factors[f].e
        ans = mul(ans,comb(a, b))
    })
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 400 points

Problem Statement

You are given positive integers N and M.

How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.

Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.

Sample Input 1

2 6

Sample Output 1

4

Four sequences satisfy the condition: \{a_1, a_2\} = \{1, 6\}, \{2, 3\}, \{3, 2\} and \{6, 1\}.

Sample Input 2

3 12

Sample Output 2

18

Sample Input 3

100000 1000000000

Sample Output 3

957870001


var s = require("fs").readFileSync("/dev/stdin", "utf8");
var n = parseInt(s.split("\n")[0].split(" ")[0], 10);
var x = parseInt(s.split("\n")[0].split(" ")[1], 10);
var a = s.split("\n")[1].split(" ").map(e => parseInt(e, 10)).sort((a, b) => a - b);
var cnt = 0;
for (var i = 0; i < n; i++) {
  if (x >= a[i]) {
    x -= a[i];
    cnt++;
  } else {
    break;
  }
}
if (x > 0 && cnt >= n) {
  cnt--;
}
console.log(cnt);

Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.


function Main(input) {
  var inputs = input.split("\n");
  var n = parseInt(inputs[0].split(" ")[0], 10);
  var x = parseInt(inputs[0].split(" ")[1], 10);
  var a = inputs[1].split(" ").map(e => parseInt(e, 10)).sort();
  var cnt = 0;
  var i = 0;
  while(true) {
    if (x > a[i]) {
      x -= a[i];
      cnt++;
      if (i === n - 1) {
        cnt--;
        break;
      }
    } else if (x === a[i]) {
      x -= a[i];
      cnt++;
      break;
    } else {
      break;
    }
    i++;
  }
  console.log(cnt);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0].split(" ")[0]);
  let x = parseInt(arg[0].split(" ")[1]);
  let a = new Array(N);
  let tmp = arg[1].split(" ");
  let sum =0;
  for(let i=0;i<N;i++){
	  a[i]=parseInt(tmp[i]);
	sum+=a[i];
  }
  let num=x;
  a.sort(function(a,b){return a-b});

  let ans = 0;

  for(let i=0;i<N;i++){
	  if(x>=a[i]){
		ans++;
		x-=a[i];
	  }else{
		  break;
	  }
  }

  if(num>sum){
	  ans=N-1;
  }
  console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict';

const main = (input) => {
    const nums = input.split(' ');
    const x1 = parseInt(nums[0], 10);
    const y1 = parseInt(nums[1], 10);
    const x2 = parseInt(nums[2], 10);
    const y2 = parseInt(nums[3], 10);
    const xdiff = x2 - x1;
    const ydiff = y2 - y1;
    const x3 = x2 - ydiff;
    const y3 = y2 + xdiff;
    const x4 = x3 - xdiff;
    const y4 = y3 - ydiff;
    console.log(x3 + ' ' + y3 + ' ' + x4 + ' ' + y4);
};

const isTest = false;

if (isTest) {
    main('0 0 0 1');
    main('2 3 6 6');
    main('31 -41 -59 26');
} else {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
}

Score : 200 points

Problem Statement

There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.
(Assume that the positive x-axis points right, and the positive y-axis points up.)

Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).

Given x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.

Constraints

|x_1|,|y_1|,|x_2|,|y_2| \leq 100

(x_1,y_1) ≠ (x_2,y_2)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

x_1 y_1 x_2 y_2

Output

Print x_3,y_3,x_4 and y_4 as integers, in this order.

Sample Input 1

0 0 0 1

Sample Output 1

-1 1 -1 0

(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.
Note that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.

Sample Input 2

2 3 6 6

Sample Output 2

3 10 -1 7

Sample Input 3

31 -41 -59 26

Sample Output 3

-126 -64 -36 -131


"use strict"

function main(input) {
  input = input.split(/\n|\s/).map(v => ~~v)
  const N = input[0]
  const K = input[1]

  let ans = 0

  if (K % 2 === 1) {
    //奇数
    for (let i = 1; i <= N; i++) {
      if (i % K === 0) ans++
    }
    ans = Math.pow(ans, 3)
  } else {
    //偶数
    let tmp = 0
    let tmp2 = 0
    for (let i = 1; i <= N; i++) {
      if (i % K === K / 2) {
        tmp++
      }
      if (i % K === 0) {
        tmp2++
      }
    }
    ans += Math.pow(tmp, 3)
    ans += Math.pow(tmp2, 3)
  }

  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))

Score : 300 points

Problem Statement

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

Constraints

1 \leq N,K \leq 2\times 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Sample Input 1

3 2

Sample Output 1

9

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

Sample Input 2

5 3

Sample Output 2

1

Sample Input 3

31415 9265

Sample Output 3

27

Sample Input 4

35897 932

Sample Output 4

114191


const main = stdin => {
  const input = stdin.trim().split('\n')
  const [N, i] = input[0].split(' ').map(x => parseInt(x))

  console.log(N - i + 1)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))

Score : 100 points

Problem Statement

There is an N-car train.

You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."

Constraints

1 \leq N \leq 100

1 \leq i \leq N

Input

Input is given from Standard Input in the following format:

N i

Output

Print the answer.

Sample Input 1

4 2

Sample Output 1

3

The second car from the front of a 4-car train is the third car from the back.

Sample Input 2

1 1

Sample Output 2

1

Sample Input 3

15 11

Sample Output 3

5


function get_run_length(min, max){
  var result = 0;

  var right = Math.abs(max-min)+Math.abs(max);
  var left = Math.abs(max-min)+Math.abs(min);

  return Math.min(...[left, right]);;
}

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines[0].split(' ')[0]);
  const K = parseInt(lines[0].split(' ')[1]);
  const Xs = lines[1].split(' ').map(x => parseInt(x))

  var result = 1e7;
  for(var i=0;i<N-K+1;i++){
    var min = Xs[i];
    var max = Xs[i+K-1];

   var tmp = get_run_length(min, max);
    result = Math.min(tmp, result);
    //console.log([i,result,min,max]);
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 300 points

Problem Statement

There are N candles placed on a number line.
The i-th candle from the left is placed on coordinate x_i.
Here, x_1 < x_2 < ... < x_N holds.

Initially, no candles are burning.
Snuke decides to light K of the N candles.

Now, he is at coordinate 0.
He can move left and right along the line with speed 1.
He can also light a candle when he is at the same position as the candle, in negligible time.

Find the minimum time required to light K candles.

Constraints

1 \leq N \leq 10^5

1 \leq K \leq N

x_i is an integer.

|x_i| \leq 10^8

x_1 < x_2 < ... < x_N

Input

Input is given from Standard Input in the following format:

N K
x_1 x_2 ... x_N

Output

Print the minimum time required to light K candles.

Sample Input 1

5 3
-30 -10 10 20 50

Sample Output 1

40

He should move and light candles as follows:

Move from coordinate 0 to -10.

Light the second candle from the left.

Move from coordinate -10 to 10.

Light the third candle from the left.

Move from coordinate 10 to 20.

Light the fourth candle from the left.

Sample Input 2

3 2
10 20 30

Sample Output 2

20

Sample Input 3

1 1
0

Sample Output 3

0

There may be a candle placed at coordinate 0.

Sample Input 4

8 5
-9 -7 -4 -3 1 2 3 4

Sample Output 4

10


'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0].split(' ')[0])
    const K = parseInt(input[0].split(' ')[1])
    const arr = input[1].split(' ').map(v => parseInt(v))

    let dist = 100000000000
    // 通るべき点を調べ上げる
    for(let i = 0; i <= arr.length - K; i++){
        let left = arr[i]
        let right = arr[i + K - 1]
        // 左端からスタートするときの距離
        const a = Math.abs(left) + Math.abs(left - right)
        // 右端からスタートするときの距離
        const b = Math.abs(right) + Math.abs(right - left)
        const min = Math.min(a, b)
        if(dist > min){
            dist = min
        }
    }
    console.log(dist)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const K=input[0].split(' ')[1]-0;
  const x=input[1].split(' ').map(e=>{
    return e-0;
  });
  var pointer=x.findIndex(e=>{
    return e=>0;
  })-K;
  if(pointer<0){
    pointer=0;
  }
  var temp;
  var ret=Infinity;
  for(var i=0;i<K;i++){
    if(pointer+i+K-1>=x.length){
      break;
    }
    if(x[pointer+i]*x[pointer+i+K-1]<0){
      temp=Math.min(-x[pointer+i],x[pointer+i+K-1])-x[pointer+i]+x[pointer+i+K-1];
    }else{
      temp=Math.max(Math.abs(x[pointer+i]),Math.abs(x[pointer+i+K-1]));
    }
    ret=Math.min(ret,temp);
  }
  console.log(ret);

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

function inv(a){
  this._a = Array(a).fill(0);
}
inv.prototype = {
  u:function(x,w){for(;x<this._a.length;x+=x&-x)this._a[x]+=w;},
  q:function(x){for(var r=0;x;x-=x&-x)r+=this._a[x];return r;},
}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  if(n <= 2)return Math.max(...a);
  var p = Math.floor(n * (n+1) / 4 + 1);
  var l = 2, r = 1e9+1;
  while(l < r){
    var m = l + r >> 1;
    var b = n+1, k = 0, z = new inv(b*2);
    z.u(b,1);
    for(var i = 0; i < n; i++){
      k += z.q(a[i] < m ? --b : ++b);
      z.u(b,1);
    }
    k = n * (n+1) / 2 - k;
    if(k < p)l = m+1; else r = m;
  }
  return l-1;
}

Score : 700 points

Problem Statement

We will define the median of a sequence b of length M, as follows:

Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.

For example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.

Snuke comes up with the following problem.

You are given a sequence a of length N.
For each pair (l, r) (1 \leq l \leq r \leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.
We will list m_{l, r} for all pairs (l, r) to create a new sequence m.
Find the median of m.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the median of m.

Sample Input 1

3
10 30 20

Sample Output 1

30

The median of each contiguous subsequence of a is as follows:

The median of (10) is 10.

The median of (30) is 30.

The median of (20) is 20.

The median of (10, 30) is 30.

The median of (30, 20) is 30.

The median of (10, 30, 20) is 20.

Thus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.

Sample Input 2

1
10

Sample Output 2

10

Sample Input 3

10
5 9 5 9 8 9 3 5 4 3

Sample Output 3

8


function Main(input) {
  input = input.trim()
  input = input.split(" ")
  console.log((input[0]-1)*(input[1]-1))
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score: 100 points

Problem Statement

There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)

What is the area of this yard excluding the roads? Find it.

Note

It can be proved that the positions of the roads do not affect the area.

Constraints

A is an integer between 2 and 100 (inclusive).

B is an integer between 2 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

A B

Output

Print the area of this yard excluding the roads (in square yards).

Sample Input 1

2 2

Sample Output 1

1

In this case, the area is 1 square yard.

Sample Input 2

5 7

Sample Output 2

24

In this case, the area is 24 square yards.


function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0],10);
  let ans = 0;
  for (var n = 0; n <= N; n++) {
    if (n % 2 === 0) continue;
    let count = 0;
    for (var i = 1; i <= n; i++) {
      if (n % i === 0) {
        count++;
      }
    }
    if (count === 8) {
      ans++;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score: 200 points

Problem Statement

The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

Constraints

N is an integer between 1 and 200 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the count.

Sample Input 1

105

Sample Output 1

1

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.

Sample Input 2

7

Sample Output 2

0

1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.


function Divisor(num) {
    var ret = 0;
    for (var p = 1; p <= num; p++) if (num % p == 0) ret++;
    return ret;
}
function Main(input) {
    var cnt = 0;
    N = Number(input);
    for (var i = 1; i <= N; i+=2) if (Divisor(i) == 8) cnt++;
    console.log(cnt);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input){
  var int = Number.parseInt(input);
  var sum = 0;
  var result = 'No';

  CakeDonut:
  for(let i=0;sum<int;i++){
    for(let j=0;sum<int;j++){
      sum = 4*i+7+j;
      if(sum === int){
        result = 'Yes';
        break CakeDonut;
      }
    }
  }
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 100 points

Problem Statement

Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.
When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

Constraints

1 \leq N,K \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

Sample Input 1

7 3

Sample Output 1

1

When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.

Sample Input 2

100 10

Sample Output 2

0

The crackers can be distributed evenly.

Sample Input 3

1 1

Sample Output 3

0


'use strict'

const main = (input) => {
    const N = parseInt(input)

    for(let i = 0; i <= 25; i++){
        for(let j = 0; j <= 25; j++){
            let total = i * 4 + j * 7
            if(total === N){
                console.log('Yes')
                return
            }
        }
    }
    console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Score : 200 points

Problem Statement

La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.
Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.

Constraints

N is an integer between 1 and 100, inclusive.

Input

Input is given from Standard Input in the following format:

N

Output

If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.

Sample Input 1

11

Sample Output 1

Yes

If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.

Sample Input 2

40

Sample Output 2

Yes

If you buy ten cakes, the total will be 4 \times 10 = 40 dollars.

Sample Input 3

3

Sample Output 3

No

The prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.


'use strict'
function Main(input) {
  input = input.split("\n")
  let N = parseInt(input[0])
  if (N === 1 || N === 5) {
    console.log('No')
    return
  }
  if (N % 4 === 0 || N % 4 === 1) {
    console.log('Yes')
    return
  }
  console.log('No')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))


var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);

	for(var i = 0; i < 26; i++){
		for(var j = 0; j < 15; j++){
			if(4*i + 7*j === n){
				console.log('Yes');
				return 0;
			}
		}
	}
	console.log('No');

}


function Main(input){

    if(input < 1200){
    console.log('ABC');
    }else if(input < 2800){
    console.log('ARC');
    }else{
    console.log('AGC');
    }
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Score : 100 points

Problem Statement

A programming competition site AtCode regularly holds programming contests.

The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.

The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.

The contest after the ARC is called AGC, which is rated for all contestants.

Takahashi's rating on AtCode is R. What is the next contest rated for him?

Constraints

0 ≤ R ≤ 4208

R is an integer.

Input

Input is given from Standard Input in the following format:

R

Output

Print the name of the next contest rated for Takahashi (ABC, ARC or AGC).

Sample Input 1

1199

Sample Output 1

ABC

1199 is less than 1200, so ABC will be rated.

Sample Input 2

1200

Sample Output 2

ARC

1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.

Sample Input 3

4208

Sample Output 3

AGC


function Main(input) {
        if (input < 1200){
            console.log('ABC');
        }
        if (input >= 1200 && input < 2800){
            console.log('ARC');
        }
        if (input <= 4208){
            console.log('AGC');
        }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(arg) {
    // 処理

    if (arg[0] === 'A' && arg[1] !== 'A') {
        var top = arg.slice(0,2)
        top = top.split("A").join("a")
        var tmp = arg.slice(2, -1)
        var bot = arg.slice(-1)
        if (tmp.split("C").length === 2) {
            var text = top + tmp.split("C").join("c") + bot
            if (/^[A-Z]+$/.test(text)){
                console.log('AC')
                return
            }
        }
    }
    console.log('WA')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

You are given a string S. Each character of S is uppercase or lowercase English letter.
Determine if S satisfies all of the following conditions:

The initial character of S is an uppercase A.

There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).

All letters except the A and C mentioned above are lowercase.

Constraints

4 ≤ |S| ≤ 10 (|S| is the length of the string S.)

Each character of S is uppercase or lowercase English letter.

Input

Input is given from Standard Input in the following format:

S

Output

If S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.

Sample Input 1

AtCoder

Sample Output 1

AC

The first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.

Sample Input 2

ACoder

Sample Output 2

WA

The second letter should not be C.

Sample Input 3

AcycliC

Sample Output 3

WA

The last letter should not be C, either.

Sample Input 4

AtCoCo

Sample Output 4

WA

There should not be two or more occurrences of C.

Sample Input 5

Atcoder

Sample Output 5

WA

The number of C should not be zero, either.


"use strict"
// inputに入力データ全体が入る
function Main(input){
    let sum = 0;
    input = input.split(" ").map(e=>parseInt(e)).sort((a, b)=>a<b ? 1 : -1);
    let topvalue = input.shift();
    for(let val of input){
        sum += topvalue - val;
        topvalue = val;
    }
    console.log(sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

You have three tasks, all of which need to be completed.

First, you can complete any one task at cost 0.

Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.

Here, |x| denotes the absolute value of x.

Find the minimum total cost required to complete all the task.

Constraints

All values in input are integers.

1 \leq A_1, A_2, A_3 \leq 100

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

Print the minimum total cost required to complete all the task.

Sample Input 1

1 6 3

Sample Output 1

5

When the tasks are completed in the following order, the total cost will be 5, which is the minimum:

Complete the first task at cost 0.

Complete the third task at cost 2.

Complete the second task at cost 3.

Sample Input 2

11 5 5

Sample Output 2

6

Sample Input 3

100 100 100

Sample Output 3

0


function main(input) {
  var source = input[0];
  var target = input[1];

  var flag = false;
  for (var i = 0; i < source.length; i++) {
    var source = shift(source);
    if (source === target) {
      flag = true;
      break;
    }
  }

  console.log(flag ? 'Yes' : 'No');
}

const shift = (str) => {
  if (str.length === 0) {
    return "";
  }

  const tailHead = str.substr(-1);
  const heads = str.substr(0, str.length-1);

  return tailHead + heads;
};

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'));

Score : 200 points

Problem Statement

You are given string S and T consisting of lowercase English letters.

Determine if S equals T after rotation.

That is, determine if S equals T after the following operation is performed some number of times:

Operation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.

Here, |X| denotes the length of the string X.

Constraints

2 \leq |S| \leq 100

|S| = |T|

S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S equals T after rotation, print Yes; if it does not, print No.

Sample Input 1

kyoto
tokyo

Sample Output 1

Yes

In the first operation, kyoto becomes okyot.

In the second operation, okyot becomes tokyo.

Sample Input 2

abc
arc

Sample Output 2

No

abc does not equal arc after any number of operations.

Sample Input 3

aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab

Sample Output 3

Yes


const main = function(input){
  var nums = input.split("\n")[1].split(" ").map(i=>parseInt(i));
  var len = nums.length;
  var ans = nums.reduce((s,i)=>s+(i-1))-1;
  console.log(ans);

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

You are given N positive integers a_1, a_2, ..., a_N.

For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N).

Here, X\ mod\ Y denotes the remainder of the division of X by Y.

Find the maximum value of f.

Constraints

All values in input are integers.

2 \leq N \leq 3000

2 \leq a_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum value of f.

Sample Input 1

3
3 4 6

Sample Output 1

10

f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f.

Sample Input 2

5
7 46 11 20 11

Sample Output 2

90

Sample Input 3

7
994 518 941 851 647 2 581

Sample Output 3

4527


Score : 400 points

Problem Statement

There are N islands lining up from west to east, connected by N-1 bridges.

The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.

One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:

Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.

You decided to remove some bridges to meet all these M requests.

Find the minimum number of bridges that must be removed.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq a_i < b_i \leq N

All pairs (a_i, b_i) are distinct.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the minimum number of bridges that must be removed.

Sample Input 1

5 2
1 4
2 5

Sample Output 1

1

The requests can be met by removing the bridge connecting the second and third islands from the west.

Sample Input 2

9 5
1 8
2 7
3 5
4 6
7 9

Sample Output 2

2

Sample Input 3

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

Sample Output 3

4


function main(input) {
    var array = input.split('\n');
    array.shift();
    var bridgeList = [];
    var cut = 1;

    for(var i = 0; i < array.length; i++){
        bridgeList[i]=[];
        for(var j = array[i][0]; j < array[i][2]; j++){
            bridgeList[i].push(parseInt(j));
        }
    }

    for(var i = 0; i < bridgeList.length-1; i++){
        console.log(bridgeList);
        if(sameArray(bridgeList[i], bridgeList[i+1]).length != 0){
            bridgeList[i] = sameArray(bridgeList[i], bridgeList[i+1]);
            bridgeList.splice(i+1, 1);
            i--;
        }
        else{
            cut++;
        }
    }
    console.log(parseInt(cut));
}

function sameArray(arr1, arr2) {
    var newArr = [];
    for(var i = 0 ; i < arr1.length; i++){
      if(arr2.indexOf(arr1[i]) >= 0 ){
        newArr.push(arr1[i]);
      }
    }
    return newArr;
  }

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
  var a = input[0];

  if(a % 2 === 0) {
    console.log(a);
  } else {
    console.log(a * 2);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

You are given a positive integer N.
Find the minimum positive integer divisible by both 2 and N.

Constraints

1 \leq N \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum positive integer divisible by both 2 and N.

Sample Input 1

3

Sample Output 1

6

6 is divisible by both 2 and 3.
Also, there is no positive integer less than 6 that is divisible by both 2 and 3.
Thus, the answer is 6.

Sample Input 2

10

Sample Output 2

10

Sample Input 3

999999999

Sample Output 3

1999999998


function Main(input) {
    var rest = input % 2
    if (rest === 0) {
        console.log(input);
    }else{
        console.log(input * 2);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  var input = input.split('\n')[1];
  var max = 0;
  var min = 10000000000;
  for (var i=0;i<input.length;i++){
  	var tmp = parseInt(input[i]);
  	if (tmp > max) {
  		max = tmp;
  	}
  	if (tmp < min) {
  		min = tmp;
  	}

  }
  console.log('0');


function main(input){
	var x = 2, y = Number(input), z, a = x * y;
	if (x < y) {
		t = x;
		x = y;
		y = t;
	}

	z = x % y;
	for (;;) {
		x = y;
		y = z;
		z = x % y;
		if (z === 0) break;
	}

	console.log(a / y);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input){
	var x = 2, y = Number(input), z, a = x * y;
	if (x < y) [x, y] = [y, x];

	z = x % y;
	while (z !== 0) {
		x = y;
		y = z;
		z = x % y;
	}

	console.log(a/y);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  let inputs = input.split(/\n/);
  let args = inputs[1].split(/\s/);
  console.log(Math.max(...args) - Math.min(...args));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

You are given an integer sequence A of length N.
Find the maximum absolute difference of two elements (with different indices) in A.

Constraints

2 \leq N \leq 100

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum absolute difference of two elements (with different indices) in A.

Sample Input 1

4
1 4 6 3

Sample Output 1

5

The maximum absolute difference of two elements is A_3-A_1=6-1=5.

Sample Input 2

2
1000000000 1

Sample Output 2

999999999

Sample Input 3

5
1 1 1 1 1

Sample Output 3

0


function Main(input) {
    line = input.split('\n');
    var n = parseInt(line[0]);
    var a = line[1].split(' ').map((n) => Number(n));

    var ma = -100;
    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            ma = Math.max(ma, Math.abs(a[i] - a[j]));
        }
    }
    console.log(ma);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(n, input) {
    var m = n - 1;
    var max;
    var min;
    while(m--){
        if(input[m] - input[m - 1] < 0){
            max = input[m - 1];
            min = input[m];
        }else{
            max = input[m];
            min = input[m - 1];
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
inp = input.split('\n')
n = inp[0]
ina = inp[1].split(' ')
for(i=0;i<ina.length;i++)ina[i]=~~ina[i]
nums = ina.sort()
console.log('%d',nums[0] - nums[n-1]);
}

//a.map(function (element) { return Number(element); })

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var result = 0;

    var N = lines.shift();
    const spans = lines[0].split(" ").map(value => Number(value));

    var i = 1; var cnt = [];
    for (const span of spans) {

        cnt[i - 1] = span - i;
        i++;
    }
    cnt.sort((a, b) => a - b);

    for (const array of cnt) {
        result += Math.abs(array - cnt[Math.floor(Number(N) / 2)]);
    }

    console.log(result);
});

Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b.
Here, he will get sad if A_i and b+i are far from each other.
More specifically, the sadness of Snuke is calculated as follows:

abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.
Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6


function Main(input){
	input = input.split("");
  var sum = 0;
  for(var i = 0; i < 4;i++){
  	input[i]=="+"?sum++:sum--;
  }
  return sum
}

// If you are interested in the algorithms I used,
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
-+--
`);

Score : 100 points

Problem Statement

There is always an integer in Takahashi's mind.

Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.

The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.

Find the integer in Takahashi's mind after he eats all the symbols.

Constraints

The length of S is 4.

Each character in S is + or -.

Input

Input is given from Standard Input in the following format:

S

Output

Print the integer in Takahashi's mind after he eats all the symbols.

Sample Input 1

+-++

Sample Output 1

2

Initially, the integer in Takahashi's mind is 0.

The first integer for him to eat is +. After eating it, the integer in his mind becomes 1.

The second integer to eat is -. After eating it, the integer in his mind becomes 0.

The third integer to eat is +. After eating it, the integer in his mind becomes 1.

The fourth integer to eat is +. After eating it, the integer in his mind becomes 2.

Thus, the integer in Takahashi's mind after he eats all the symbols is 2.

Sample Input 2

-+--

Sample Output 2

-2

Sample Input 3

----

Sample Output 3

-4


"use strict";

function main(arg) {
    const minus = arg.split("\n")[0].split("").filter(n=>n=="-").length;
    const plus  = 4 - minus;
    console.log(plus - minus);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(str){
    var splited = [];
    var goukei = 0;
    splited = str.split("");
    console.log(splited);
    for(var i = 0; i < splited.length - 1; i++){
      if(splited[i] == '+'){
          goukei = goukei + 1;
      }
      if(splited[i] == '-'){
          goukei = goukei - 1;
      }
    }
console.log(goukei);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
  var s = 0;
  var result = input.split('');

  for (var i = 0; i < 4; i++) {
    if(result[i] === '+') {
      s++;
    } else if(result[i] === '-') {
      s--;
    }
  }
  console.log(s);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(str) {
  str = str.split("");
  for(var i = 0; i < str.length; i++){
    var s = 0
    if(str[i] == '+'){
      s = s + 1;
    }
    if(str[i] == '-'){
      s = s - 1;
    }
  }
  console.log(s);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  var inputA = input.toString().split('');
  var sum = 0;
  for (var i=0;i<inputA.length;i++){
   	sum += parseInt(inputA[i]);
  }
  if (parseInt(input) % sum == 0) {
  	console.log('Yes');
  } else {
  	console.log('No');
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Score : 200 points

Problem Statement

Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(101) = 1 + 0 + 1 = 2.

Given an integer N, determine if S(N) divides N.

Constraints

1 \leq N \leq 10^9

Input

Input is given from Standard Input in the following format:

N

Output

If S(N) divides N, print Yes; if it does not, print No.

Sample Input 1

12

Sample Output 1

Yes

In this input, N=12.
As S(12) = 1 + 2 = 3, S(N) divides N.

Sample Input 2

101

Sample Output 2

No

As S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.

Sample Input 3

999999999

Sample Output 3

Yes


function Main(input){

input=input.split("\n");
inp = input[0].split(" ");
inA = input[1].split(" ");
N = inp[0];
K = inp[1];

answer = 0;
index = 0;
len = inA.length;
a = 1;
b = 1;
c = 0;

for (i = 0; i < len; i++) {
    if (inA[i] == "1") {
        index = i;
        break;
    }
}

a = index;
b = len - 1 - index;

if (a + b + 1 <= K) {
    console.log(1);
    process.exit(0);
}

for (; a > 0;) {
    answer = answer + 1;
    a = a - (K - 1);
}
for (; b > 0;) {
    answer = answer + 1;
    b = b - (K - 1);
}

//if (answer != 0) {
//    answer = answer + c;
//}

console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4


function Main(input) {
	input = input.trim();
	var n = Number(input[0]);
	var k = Number(input[2]);
	if(n == k){
		console.log(1);
	} else {
		console.log(n/(k-1));
	}

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let K = cin.getInt();
    const S = (n) => n.toString().split('').reduce((ac, v) => ac + (v - 0), 0);
    const compare = (x, y) => !(x * S(y) <= y * S(x));

    let n = 0, a = 1;
    for (let i = 0; i < K; i++) {
        if (compare(n + a, n + 10 * a)) a *= 10;
        n += a;
        console.log(n);
    }
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 500 points

Problem Statement

Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.

We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.

Given an integer K, list the K smallest Snuke numbers.

Constraints

1 \leq K

The K-th smallest Snuke number is not greater than 10^{15}.

Input

Input is given from Standard Input in the following format:

K

Output

Print K lines. The i-th line should contain the i-th smallest Snuke number.

Sample Input 1

10

Sample Output 1

1
2
3
4
5
6
7
8
9
19


function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const K=input[0].split(' ')[1]-0;
  var key=input[1].split(' ').map(e=>{
    return e-0;
  }).findIndex(e=>{
    return e===1;
  });
  console.log(Math.ceil((N-1)/(K-1));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function permutation(n,k){
    var ret=[[]];
    var next;
    for(var i=0;i<k;i++){
        next=[];
        ret.forEach(e=>{
            for(var k=1;k<=n;k++){
                if(!e.includes(k)){
                    next.push(e.concat([k]));
                }
            }
        });
        ret=next.concat([]);
    }
    return ret;
}


function Main(input) {
  console.log((input[0][0]<=8 && input[0][1] <= 8) ? 'Yay!' : ':(')
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Score: 100 points

Problem Statement

E869120's and square1001's 16-th birthday is coming soon.

Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.

E869120 and square1001 were just about to eat A and B of those pieces, respectively,

when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".

Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

Constraints

A and B are integers between 1 and 16 (inclusive).

A+B is at most 16.

Input

Input is given from Standard Input in the following format:

A B

Output

If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.

Sample Input 1

5 4

Sample Output 1

Yay!

Both of them can take desired number of pieces as follows:

Sample Input 2

8 8

Sample Output 2

Yay!

Both of them can take desired number of pieces as follows:

Sample Input 3

11 4

Sample Output 3

:(

In this case, there is no way for them to take desired number of pieces, unfortunately.


var main = function(input){
input = input.split('\n')
  var A = parseInt(input[0]);
  var B = parseInt(input[1]);
  if(A<9){
    if(B<9){
    	console.log('Yay!');
    } else {
      console.log(':(');
  }
  } else{
    console.log(':(');
    return 0;

}
main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


var main = function(input){
input = input.split('\n')
  var A = parseInt(input[0]);
  var B = parseInt(input[1]);
  if(A<9&&B<9){
    console.log('Yay!');
  } else{
    console.log(':(');
    return 0;
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (x) => {
    lines.push(x);
});

rl.on('close', () => {
    var N = Number(lines[0]);
    var a = lines[1].split(" ").map(value => Number(value));

    var counter = 0;

    for (var i = 0; i < N; i++) {
        for (var j = 1; j < 30; j++) {
            if (a[i] % 2 === 0) {
                a[i] = a[i] / 2
                counter++;
            }
        }
    }

    console.log(counter);
});

Score: 300 points

Problem Statement

As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.

Snuke, an employee, would like to play with this sequence.

Specifically, he would like to repeat the following operation as many times as possible:

For every i satisfying 1 \leq i \leq N, perform one of the following: "divide a_i by 2" and "multiply a_i by 3".
Here, choosing "multiply a_i by 3" for every i is not allowed, and the value of a_i after the operation must be an integer.

At most how many operations can be performed?

Constraints

N is an integer between 1 and 10 \ 000 (inclusive).

a_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 a_3 ... a_N

Output

Print the maximum number of operations that Snuke can perform.

Sample Input 1

3
5 2 4

Sample Output 1

3

The sequence is initially {5, 2, 4}. Three operations can be performed as follows:

First, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.

Next, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.

Finally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.

Sample Input 2

4
631 577 243 199

Sample Output 2

0

No operation can be performed since all the elements are odd. Thus, the answer is 0.

Sample Input 3

10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776

Sample Output 3

39


"use strict"
function Main(input) {
    if (!input.match(/([\n])/)){
        input = input.split(" ");
    } else {
        input = input.split("\n");
        for (var i = 0; i < input.length; i++){
            input[i] = input[i].split(" ");
        }
    }
    //中身↓
    let end = "D";
    if(input[0]<=999){
        end = "C";
    }
    console.log("AB"+end);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Score : 100 points

Problem Statement

Decades have passed since the beginning of AtCoder Beginner Contest.

The contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?

In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.

You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

Constraints

1 \leq N \leq 1998

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

Sample Input 1

999

Sample Output 1

ABC

The 999-th round of AtCoder Beginner Contest is labeled as ABC999.

Sample Input 2

1000

Sample Output 2

ABD

The 1000-th round of AtCoder Beginner Contest is labeled as ABD001.

Sample Input 3

1481

Sample Output 3

ABD

The 1481-th round of AtCoder Beginner Contest is labeled as ABD482.


"use strict";
function Main(input) {
  input = input.split("\n");
  const withdrawMoney = parseInt(input[0], 10);

  for(let nineCount = 0; nineCount < 6; nineCount++){
      if((withdrawMoney - 9**nineCount) < 0){
          let nineCounts = nineCount;
          let a = withdrawMoney - 9**nineCount;
      }
      for(let sixCount = 0; sixCount < 7; sixCount++){
          if(a - 6**sixCount < 0){
              let sixCounts = sixCount;
              let b = a - 6**sixCount;
          }
      }
  }
  console.log(nineCounts);
}

Main(require("fs").readFileSync("/dev/stdin", "utf-8"));

Score : 300 points

Problem Statement

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

1 yen (the currency of Japan)

6 yen, 6^2(=36) yen, 6^3(=216) yen, ...

9 yen, 9^2(=81) yen, 9^3(=729) yen, ...

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

Constraints

1 \leq N \leq 100000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Sample Input 1

127

Sample Output 1

4

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

Sample Input 2

3

Sample Output 2

3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.

Sample Input 3

44852

Sample Output 3

16