function _defineProperties(t,r){for(var e=0;e<r.length;e++){var i=r[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function _createClass(t,r,e){return r&&_defineProperties(t.prototype,r),e&&_defineProperties(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function _inheritsLoose(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,_setPrototypeOf(t,r)}function _setPrototypeOf(t,r){return _setPrototypeOf=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},_setPrototypeOf(t,r)}function _unsupportedIterableToArray(t,r){if(t){if("string"==typeof t)return _arrayLikeToArray(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(t,r):void 0}}function _arrayLikeToArray(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,i=new Array(r);e<r;e++)i[e]=t[e];return i}function _createForOfIteratorHelperLoose(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=_unsupportedIterableToArray(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var fs=require("fs"),configPath="./compe.config.json";function proc(t,r){if(global.MOD_=998244353,global.MOD_CUT=444595123,fs.existsSync(configPath)){if(!fs.existsSync(r))return void console.log("Input directory does not exist");var e=fs.readFileSync(r,{encoding:"utf-8"}),i=0;e=e.split(/ |\n|\r/g);for(var n,o=[],s=_createForOfIteratorHelperLoose(e);!(n=s()).done;){var a=n.value;a.length>0&&o.push(a)}global.rnum=function(t){return t?o.slice(i,i+=t).map((function(t){return+t})):+o[i++]},global.rstr=function(t){return t?o.slice(i,i+=t):o[i++]},global.rbig=function(t){return t?o.slice(i,i+=t).map((function(t){return BigInt(t)})):BigInt(o[i++])},global.print=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];for(var i=0,n=r;i<n.length;i++){var o=n[i];process.stdout.write(String(o))}},t()}else{var h="";process.stdin.on("data",(function(t){h+=t})),process.stdin.on("end",(function(){var r=0;h=h.split(/ |\n|\r/g);for(var e,i=[],n=_createForOfIteratorHelperLoose(h);!(e=n()).done;){var o=e.value;o.length>0&&i.push(o)}global.rnum=function(t){return t?i.slice(r,r+=t).map((function(t){return+t})):+i[r++]},global.rstr=function(t){return t?i.slice(r,r+=t):i[r++]},global.rbig=function(t){return t?i.slice(r,r+=t).map((function(t){return BigInt(t)})):BigInt(i[r++])};var s="";global.print=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];for(var i=0,n=r;i<n.length;i++){var o=n[i];s+=String(o)}},t(),console.log(s)}))}}function createCommonjsModule(t,r){return t(r={exports:{}},r.exports),r.exports}var runtime_1=createCommonjsModule((function(t){var r=function(t){var r,e=Object.prototype,i=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function h(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{h({},"")}catch(t){h=function(t,r,e){return t[r]=e}}function l(t,r,e,i){var n=r&&r.prototype instanceof g?r:g,o=Object.create(n.prototype),s=new E(i||[]);return o._invoke=function(t,r,e){var i=f;return function(n,o){if(i===p)throw new Error("Generator is already running");if(i===d){if("throw"===n)throw o;return F()}for(e.method=n,e.arg=o;;){var s=e.delegate;if(s){var a=k(s,e);if(a){if(a===v)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(i===f)throw i=d,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);i=p;var h=u(t,r,e);if("normal"===h.type){if(i=e.done?d:c,h.arg===v)continue;return{value:h.arg,done:e.done}}"throw"===h.type&&(i=d,e.method="throw",e.arg=h.arg)}}}(t,e,s),o}function u(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var f="suspendedStart",c="suspendedYield",p="executing",d="completed",v={};function g(){}function y(){}function m(){}var b={};h(b,o,(function(){return this}));var w=Object.getPrototypeOf,x=w&&w(w(S([])));x&&x!==e&&i.call(x,o)&&(b=x);var _=m.prototype=g.prototype=Object.create(b);function L(t){["next","throw","return"].forEach((function(r){h(t,r,(function(t){return this._invoke(r,t)}))}))}function z(t,r){function e(n,o,s,a){var h=u(t[n],t,o);if("throw"!==h.type){var l=h.arg,f=l.value;return f&&"object"==typeof f&&i.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,s,a)}),(function(t){e("throw",t,s,a)})):r.resolve(f).then((function(t){l.value=t,s(l)}),(function(t){return e("throw",t,s,a)}))}a(h.arg)}var n;this._invoke=function(t,i){function o(){return new r((function(r,n){e(t,i,r,n)}))}return n=n?n.then(o,o):o()}}function k(t,e){var i=t.iterator[e.method];if(i===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,k(t,e),"throw"===e.method))return v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var n=u(i,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,v;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,v):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function A(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function O(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function S(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,s=function e(){for(;++n<t.length;)if(i.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return s.next=s}}return{next:F}}function F(){return{value:r,done:!0}}return y.prototype=m,h(_,"constructor",m),h(m,"constructor",y),y.displayName=h(m,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===y||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,h(t,a,"GeneratorFunction")),t.prototype=Object.create(_),t},t.awrap=function(t){return{__await:t}},L(z.prototype),h(z.prototype,s,(function(){return this})),t.AsyncIterator=z,t.async=function(r,e,i,n,o){void 0===o&&(o=Promise);var s=new z(l(r,e,i,n),o);return t.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},L(_),h(_,a,"Generator"),h(_,o,(function(){return this})),h(_,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var i=r.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},t.values=S,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(i,n){return a.type="throw",a.arg=t,e.next=i,n&&(e.method="next",e.arg=r),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var s=this.tryEntries[o],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var h=i.call(s,"catchLoc"),l=i.call(s,"finallyLoc");if(h&&l){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(h){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=r,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),v},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),O(e),v}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var i=e.completion;if("throw"===i.type){var n=i.arg;O(e)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,i){return this.delegate={iterator:S(t),resultName:e,nextLoc:i},"next"===this.method&&(this.arg=r),v}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}})),Deque=function(t){function r(t){this.head=0,this.tail=0,this.mask=1,this.list=new Array(2),t&&this.extend(t)}var e=r.prototype;return e.extend=function(t){for(var r,e=_createForOfIteratorHelperLoose(t);!(r=e()).done;){var i=r.value;this.push(i)}return this},e.extendFront=function(t){for(var r,e=_createForOfIteratorHelperLoose(t);!(r=e()).done;){var i=r.value;this.pushFront(i)}return this},e._resize=function(t,r){var e=this.head,i=this.mask;if(this.head=0,this.tail=t,this.mask=r-1,0!==e){for(var n=new Array(r),o=0;o<t;o++)n[o]=this.list[e+o&i];this.list=n}else this.list.length=r},e.push=function(t){return this.list[this.tail]=t,this.tail=this.tail+1&this.mask,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.pushFront=function(t){return this.head=this.head-1&this.mask,this.list[this.head]=t,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.clear=function(){this.head=0,this.tail=0},e.at=function(t){var r=this.head,e=this.size,i=this.tail,n=this.list;if((0|t)!==t||t>=e||t<-e)throw new RangeError("deque index out of range");return n[(t>=0?r:i)+t&this.mask]},e.indexOf=function(t,r){void 0===r&&(r=0);for(var e=this.head,i=this.list,n=this.size,o=this.mask,s=r>=0?r:r<-n?0:n+r;s<n;s++)if(i[e+s&o]===t)return s;return-1},e.has=function(t){for(var r=this.head,e=this.list,i=this.size,n=this.mask,o=0;o<i;o++)if(e[r+o&n]===t)return!0;return!1},e.insert=function(t,r){var e=this.head+t&this.mask,i=this.tail;for(this.tail=this.tail+1&this.mask;i!==e;){var n=i-1&this.mask;this.list[i]=this.list[n],i=n}return this.list[e]=r,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.pop=function(){if(this.head===this.tail)throw new RangeError("pop from an empty deque");this.tail=this.tail-1&this.mask;var t=this.list[this.tail];return this.list[this.tail]=void 0,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),t},e.popFront=function(){if(this.head===this.tail)throw new RangeError("pop from an empty deque");var t=this.list[this.head];return this.list[this.head]=void 0,this.head=this.head+1&this.mask,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),t},e.delete=function(t){if(t>=this.size||t<0)throw new RangeError("deque index out of range");for(var r=this.head+t&this.mask;r!==this.tail;){var e=r+1&this.mask;this.list[r]=this.list[e],r=e}return this.tail=this.tail-1&this.mask,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),this},e.reverse=function(){for(var t=this.head,r=this.tail,e=this.size,i=this.mask,n=0;n<~~(e/2);n++){var o=r-n-1&i,s=t+n&i,a=this.list[o];this.list[o]=this.list[s],this.list[s]=a}return this},e.rotate=function(t){void 0===t&&(t=1);var r=this.head,e=this.tail;if(0===t||r===e)return this;if(this.head=r-t&this.mask,this.tail=e-t&this.mask,t>0)for(var i=1;i<=t;i++){var n=r-i&this.mask,o=e-i&this.mask;this.list[n]=this.list[o],this.list[o]=void 0}else for(var s=0;s>t;s--){var a=e-s&this.mask,h=r-s&this.mask;this.list[a]=this.list[h],this.list[h]=void 0}return this},e.entries=runtime_1.mark((function t(){var r,e,i,n,o;return runtime_1.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=this.head,e=this.size,i=this.list,n=this.mask,o=0;case 2:if(!(o<e)){t.next=8;break}return t.next=5,i[r+o&n];case 5:o++,t.next=2;break;case 8:case"end":return t.stop()}}),t,this)})),e.keys=function(){return this.entries()},e.values=function(){return this.entries()},e[t]=function(){return this.entries()},_createClass(r,[{key:"front",get:function(){if(this.size)return this.list[this.head];throw new RangeError("deque index out of range")}},{key:"back",get:function(){if(this.size)return this.list[this.tail-1&this.mask];throw new RangeError("deque index out of range")}},{key:"size",get:function(){return this.tail-this.head&this.mask}}]),r}(Symbol.iterator),multi=function(t){for(var r=arguments.length,e=new Array(r>1?r-1:0),i=1;i<r;i++)e[i-1]=arguments[i];if(0===e.length)throw new Error("Please insert integer dimensional values");var n=function r(i){return i===e.length-1?Array(e[i]).fill(t):Array(e[i]).fill(0).map((function(){return r(i+1)}))},o=function r(i){return i===e.length?t.slice():Array(e[i]).fill(0).map((function(){return r(i+1)}))},s=function r(i){return i===e.length?Object.assign({},t):Array(e[i]).fill(0).map((function(){return r(i+1)}))};return"object"!=typeof t?n(0):Array.isArray(t)?o(0):s(0)},DSU=function(){function t(t){this.p=multi(-1,t+1)}var r=t.prototype;return r.group=function(t){return this.p[t]<0?t:(this.p[t]=this.group(this.p[t]),this.p[t])},r.join=function(t,r){if((t=this.group(t))==(r=this.group(r)))return!1;if(this.p[t]>this.p[r]){var e=[r,t];t=e[0],r=e[1]}return this.p[t]+=this.p[r],this.p[r]=t,!0},r.size=function(t){return t=this.group(t),-this.p[t]},t}(),PriorityQueue=function(){function t(t){this.comparator=t||function(t,r){return t<r},this.elem=[]}var r=t.prototype;return r.swap=function(t,r){var e=[this.elem[r],this.elem[t]];this.elem[t]=e[0],this.elem[r]=e[1]},r.push=function(t){for(var r=this.elem.push(t)-1,e=0;r>0&&(e=r>>1,!this.comparator(this.elem[r],this.elem[e]));)this.swap(r,e),r=e},r.pop=function(){var t=this.top,r=this.elem.pop(),e=this.size;if(0==e)return t;this.elem[0]=r;for(var i=0,n=0,o=0,s=0;i<e&&(n=i,s=2+(i<<1),(o=1+(i<<1))<e&&!this.comparator(this.elem[o],this.elem[n])&&(n=o),s<e&&!this.comparator(this.elem[s],this.elem[n])&&(n=s),n!=i);)this.swap(n,i),i=n;return t},_createClass(t,[{key:"size",get:function(){return this.elem.length}},{key:"top",get:function(){if(0==this.elem.length)throw new Error("PriorityQueue is empty");return this.elem[0]}}]),t}(),SparseTable=function(){function t(t,r){var e=this;void 0===r&&(r=function(t,r){return t<r?t:r}),this.maxGap=0;var i=t.length;this.logFactor=this.floorLog2(i),this.merger=r,this.cont=Array(i).fill(0).map((function(){return Array(e.logFactor+1)}));for(var n=0;n<i;n++)this.cont[n][0]=t[n];for(var o=1;o<=this.logFactor;o++)for(var s=0;s+(1<<o)-1<i;s++)this.cont[s][o]=r(this.cont[s][o-1],this.cont[s+(1<<o-1)][o-1])}var r=t.prototype;return r.floorLog2=function(t){return 31-Math.clz32(t)},r.query=function(t,r){return this.maxGap=this.floorLog2(r-t+1),this.merger(this.cont[t][this.maxGap],this.cont[r-(1<<this.maxGap)+1][this.maxGap])},t}(),FenwickTree=function(){function t(t,r,e){void 0===r&&(r=0),void 0===e&&(e=function(t,r){return t+r}),this.identityValue=r,this.updateMethod=e,this.elemCount=t,this.cont=Array(t+1).fill(r)}var r=t.prototype;return r.query=function(t){for(var r=this.identityValue;t>=0;t=(t&t+1)-1)r=this.updateMethod(r,this.cont[t]);return r},r.update=function(t,r){for(;t<=this.elemCount;t|=t+1)this.cont[t]=this.updateMethod(this.cont[t],r)},t}(),SegmentTree=function(){function t(t,r,e,i){if(void 0===i&&(i=null),this.identityValue=r,this.merger=e,this.elemCount=t,this.log=Math.ceil(Math.log2(t)),this.size=1<<this.log,this.cont=Array(t<<1).fill(this.identityValue),i){for(var n=0;n<t;n++)this.cont[this.size+n]=i[n];for(var o=this.size-1;o>=1;o--)this.internalUpdate(o)}}var r=t.prototype;return r.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},r.set=function(t,r){t+=this.size,this.cont[t]=r;for(var e=1;e<=this.log;e++)this.internalUpdate(t>>e)},r.get=function(t){return t?this.cont[t+this.size]:this.cont.slice(this.size,this.size+this.elemCount)},r.query=function(t,r){void 0===t&&(t=0),void 0===r&&(r=this.elemCount-1),r++;var e=this.identityValue,i=this.identityValue;for(t+=this.size,r+=this.size;t<r;)1&t&&(e=this.merger(e,this.cont[t++])),1&r&&(i=this.merger(this.cont[--r],i)),t>>=1,r>>=1;return this.merger(e,i)},r.all=function(){return this.cont[1]},t}(),LazySegmentTree=function(){function t(t,r,e,i,n,o,s){if(void 0===s&&(s=null),this.identityValue=r,this.merger=e,this.identityLazy=i,this.pusher=n,this.modifier=o,this.log=Math.ceil(Math.log2(t)),this.size=1<<this.log,this.cont=Array(this.size<<1).fill(this.identityValue),this.lazyCont=Array(this.size).fill(i),s){for(var a=0;a<t;a++)this.cont[this.size+a]=s[a];for(var h=this.size-1;h>=1;h--)this.internalUpdate(h)}}var r=t.prototype;return r.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},r.internalModify=function(t,r){r!==this.identityLazy&&(this.cont[t]=this.modifier(this.cont[t],r),t<this.size&&(this.lazyCont[t]=this.pusher(this.lazyCont[t],r)))},r.internalPush=function(t){this.lazyCont[t]!==this.identityLazy&&(this.internalModify(t<<1,this.lazyCont[t]),this.internalModify(t<<1|1,this.lazyCont[t]),this.lazyCont[t]=this.identityLazy)},r.set=function(t,r){t+=this.size;for(var e=this.log;e>=1;e--)this.internalPush(t>>e);this.cont[t]=r;for(var i=1;i<=this.log;i++)this.internalUpdate(t>>i)},r.get=function(t){t+=this.size;for(var r=this.log;r>=1;r--)this.internalPush(t>>r);return this.cont[t]},r.query=function(t,r){r++,t+=this.size,r+=this.size;for(var e=this.log;e>=1;e--)t>>e<<e!=t&&this.internalPush(t>>e),r>>e<<e!=r&&this.internalPush(r-1>>e);for(var i=this.identityValue,n=this.identityValue;t<r;)1&t&&(i=this.merger(i,this.cont[t++])),1&r&&(n=this.merger(this.cont[--r],n)),t>>=1,r>>=1;return this.merger(i,n)},r.all=function(){return this.cont[1]},r.update=function(t,r,e){r++,t+=this.size,r+=this.size;for(var i=this.log;i>=1;i--)t>>i<<i!=t&&this.internalPush(t>>i),r>>i<<i!=r&&this.internalPush(r-1>>i);for(var n=t,o=r;t<r;)1&t&&this.internalModify(t++,e),1&r&&this.internalModify(--r,e),t>>=1,r>>=1;t=n,r=o;for(var s=1;s<=this.log;s++)t>>s<<s!=t&&this.internalUpdate(t>>s),r>>s<<s!=r&&this.internalUpdate(r-1>>s)},t}(),defaultComparator=function(t,r){return t<r},lowerBound=function(t,r,e,i,n){var o;for(void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=defaultComparator),i||(i=t.length);e<i;)n(t[o=e+(i-e>>>1)],r)?e=o+1:i=o;return e},upperBound=function(t,r,e,i,n){var o;for(void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=defaultComparator),i||(i=t.length);e<i;)n(r,t[o=e+(i-e>>>1)])?i=o:e=o+1;return e},binarySearch=function(t,r,e){for(var i,n=null;t<=r;)e(i=t+r>>1)?(n=i,r=i-1):t=i+1;return n},ternarySearch=function(t,r,e,i,n){var o,s;if(void 0===i&&(i=!1),void 0===n&&(n=200),i)for(;n--;)s=r-(r-t)/3,e(o=t+(r-t)/3)<e(s)?t=o:r=s;else for(;n--;)o=t+(r-t)/3,e(s=r-(r-t)/3)<e(o)?t=o:r=s;return e(o)},integralExtremumSearch=function(t,r,e,i){if(void 0===i&&(i=!1),i){var n,o,s=e(t);for(t++;t<=r;)o=e(n=t+r>>1),e(n-1)<o?(s=o,t=n+1):r=n-1;return s}var a,h,l=e(t);for(t++;t<=r;)h=e(a=t+r>>1),e(a-1)>h?(l=h,t=a+1):r=a-1;return l},Graph=function(){function t(t){this.g=multi([],t+1),this.vis=multi(!1,t+1),this.par=multi(-1,t+1)}var r=t.prototype;return r.addEdge=function(t,r,e){this.g[t].push({to:r,prop:e})},r.addBiEdge=function(t,r,e){this.addEdge(t,r,e),this.addEdge(r,t,e)},r.reset=function(){this.vis=multi(!1,this.g.length),this.par=multi(-1,this.g.length)},t}(),dfs=function(t,r,e,i){var n=new Deque;for(n.push(r);n.size;){var o=n.back;if(t.vis[o])i(o,t),n.pop();else{t.vis[o]=!0,e(o,t);for(var s,a=_createForOfIteratorHelperLoose(t.g[o]);!(s=a()).done;){var h=s.value;t.vis[h.to]||(t.par[h.to]=o,n.push(h.to))}}}},bfs=function(t,r,e){var i=new Deque;if(i.push(r),Array.isArray(r))for(var n,o=_createForOfIteratorHelperLoose(r);!(n=o()).done;){var s=n.value;t.vis[s]=!0,i.push(s)}else t.vis[r]=!0,i.push(r);for(;i.size;){var a=i.pop();e(a,t);for(var h,l=_createForOfIteratorHelperLoose(t.g[a]);!(h=l()).done;){var u=h.value;t.vis[u.to]||(t.par[u.to]=a,i.push(u.to),t.vis[u.to]=!0)}}},mst=function(t){for(var r=0,e=[],i=[],n=0;n<t.g.length;n++)for(var o,s=_createForOfIteratorHelperLoose(t.g[n]);!(o=s()).done;){var a=o.value;n<a.to&&e.push({from:n,to:a.to,weight:a.prop.weight})}var h=new DSU(t.g.length);e.sort((function(t,r){return t.weight-r.weight}));for(var l=0,u=e;l<u.length;l++){var f=u[l];h.join(f.from,f.to)&&(r+=f.weight,i.push(f))}return{mst:r,mstEdges:i}},spfa=function(t,r){t.reset();var e,i=Number.MAX_SAFE_INTEGER,n=multi(i,t.g.length),o=multi(!1,t.g.length),s=new Deque;if(Array.isArray(r))for(var a,h=_createForOfIteratorHelperLoose(r);!(a=h()).done;){var l=a.value;s.push(l),o[l]=!0,n[l]=0}else s.push(r),o[r]=!0,n[r]=0;for(;s.size;){o[e=s.pop()]=!1;for(var u,f=_createForOfIteratorHelperLoose(t.g[e]);!(u=f()).done;){var c=u.value;n[c.to]>n[e]+c.prop.weight&&(n[c.to]=n[e]+c.prop.weight,t.par[c.to]=e,o[c.to]||(o[c.to]=!0,s.push(c.to)))}}return{parArray:t.par,distArray:n}},dijkstra=function(t,r){t.reset();var e=new PriorityQueue((function(t,r){return t.dist>r.dist})),i=Number.MAX_SAFE_INTEGER,n=multi(i,t.g.length);if(Array.isArray(r))for(var o,s=_createForOfIteratorHelperLoose(r);!(o=s()).done;){var a=o.value;e.push({node:a,dist:0}),n[a]=0}else e.push({node:r,dist:0}),n[r]=0;for(;e.size;){var h=e.pop();if(n[h.node]===h.dist)for(var l,u=_createForOfIteratorHelperLoose(t.g[h.node]);!(l=u()).done;){var f=l.value;n[f.to]>n[h.node]+f.prop.weight&&(n[f.to]=n[h.node]+f.prop.weight,t.par[f.to]=h.node,e.push({node:f.to,dist:n[f.to]}))}}return{parArray:t.par,distArray:n}},setMod=function(t){global.MOD_=t,global.MOD_CUT=1099511627776%t},add=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];for(var i=r.length-1;i>=1;i--)r[0]+=r[i],r[0]=r[0]>=global.MOD_?r[0]-global.MOD_:r[0];return r[0]},sub=function(t,r){return(t+=global.MOD_-r)>=global.MOD_?t-global.MOD_:t},mul=function(){for(var t=arguments.length<=0?void 0:arguments[0],r=1;r<arguments.length;r++)t=((t>>20)*((r<0||arguments.length<=r?void 0:arguments[r])>>20)*global.MOD_CUT+(4293918720&t)*(1048575&(r<0||arguments.length<=r?void 0:arguments[r]))+(1048575&t)*(r<0||arguments.length<=r?void 0:arguments[r]))%global.MOD_;return t},pow=function(t,r){for(var e=1;r;)1&r&&(e=mul(e,t)),t=mul(t,t),r>>>=1;return e},inv=function(t){for(var r,e=1,i=0,n=global.MOD_;n;i=(o=[e,i-r*e])[0],e=o[1],o){var o,s;n=(s=[t,n-(r=n/t|0)*t])[0],t=s[1]}return e<0?e+global.MOD_:e},binomSetup=function(t,r){void 0===t&&(t=2e5),void 0===r&&(r=!1),global.factorial=Array(t+1).fill(1),global.invFactorial=Array(t+1).fill(1);for(var e=1;e<=t;e++)global.factorial[e]=mul(global.factorial[e-1],e);global.invFactorial[t]=inv(global.factorial[t]);for(var i=t-1;i>=1;i--)global.invFactorial[i]=mul(global.invFactorial[i+1],i+1);if(r){if(t>2e3)throw new Error("Fast Binomial is only available for under 2000 range");global.fastBinomEnabled=!0,global.fastBinom=multi(0,t+1,t+1);for(var n=0;n<=t;n++){global.fastBinom[n][0]=1;for(var o=1;o<=n;o++)global.fastBinom[n][o]=add(global.fastBinom[n-1][o-1],global.fastBinom[n-1][o])}}},binom=function(t,r){return r>t?0:global.fastBinomEnabled?global.fastBinom[t][r]:mul(global.factorial[t],global.invFactorial[r],global.invFactorial[t-r])},fact=function(t){return global.factorial[t]},Tree=function(t){function r(r,e){var i;return(i=t.call(this,r)||this).root=1,i.root=e,i.childCount=Array(r+1).fill(1),i.distRoot=Array(r+1).fill(0),i.distance=Array(r+1).fill(0),i}_inheritsLoose(r,t);var e=r.prototype;return e.setupDist=function(){var t=this;dfs(this,this.root,(function(r,e){for(var i,n=_createForOfIteratorHelperLoose(e.g[r]);!(i=n()).done;){var o=i.value;o.to!=e.par[r]&&(o.prop&&(t.distance[o.to]=t.distance[r]+o.prop.weight),t.distRoot[o.to]=t.distRoot[r]+1)}}),(function(r,e){for(var i,n=_createForOfIteratorHelperLoose(e.g[r]);!(i=n()).done;){var o=i.value;o.to!=e.par[r]&&(t.childCount[r]+=t.childCount[o.to])}}))},e.setupLCA=function(){this.setupDist();var t=31-Math.clz32(this.g.length);this.log=t,this.parentLift=Array(t+1),this.parentLift[0]=this.par;for(var r=1;r<=t;r++){this.parentLift[r]=Array(this.g.length).fill(-1);for(var e=0;e<this.g.length;e++)-1!=this.parentLift[r-1][e]&&(this.parentLift[r][e]=this.parentLift[r-1][this.parentLift[r-1][e]])}this.distRoot=this.distRoot},e.getLCA=function(t,r){if(this.distRoot[t]<this.distRoot[r]){var e=[r,t];t=e[0],r=e[1]}for(var i=this.log;i>=0;i--)this.distRoot[t]-(1<<i)>=this.distRoot[r]&&(t=this.parentLift[i][t]);if(t===r)return t;for(var n=this.log;n>=0;n--)this.parentLift[n][t]!=this.parentLift[n][r]&&(t=this.parentLift[n][t],r=this.parentLift[n][r]);return this.parentLift[0][t]},r}(Graph);exports.DSU=DSU,exports.Deque=Deque,exports.FenwickTree=FenwickTree,exports.Graph=Graph,exports.LazySegmentTree=LazySegmentTree,exports.PriorityQueue=PriorityQueue,exports.SegmentTree=SegmentTree,exports.SparseTable=SparseTable,exports.Tree=Tree,exports.add=add,exports.bfs=bfs,exports.binarySearch=binarySearch,exports.binom=binom,exports.binomSetup=binomSetup,exports.dfs=dfs,exports.dijkstra=dijkstra,exports.fact=fact,exports.integralExtremumSearch=integralExtremumSearch,exports.inv=inv,exports.lowerBound=lowerBound,exports.mst=mst,exports.mul=mul,exports.multi=multi,exports.pow=pow,exports.proc=proc,exports.setMod=setMod,exports.spfa=spfa,exports.sub=sub,exports.ternarySearch=ternarySearch;

function main() {
  // write your code from here
  let [n, x] = rnum(2);
  let dp = multi(0, n + 1, x + 1);
  let p = multi(0, n + 1, x + 1);
  dp[0][0] = 1;
  for (let i = 0; i <= n; i ++) {
    for (let j = 1; j <= x; j ++) {
      p[i][j] = pow(j, i);
    }
  }
  binomSetup(500, true);
  for (let i = 2; i <= n; i ++) {
    for (let j = 1; j < i; j ++) {
      dp[i][j] = mul(binom(n, i), sub(p[i][j], p[i][j - 1]));
    }
  }
  for (let i = 2; i <= n; i ++) {
    for (let j = 1; j <= x; j ++) {
      for (let k = 0; i + k <= n && i + j + k - 1 <= x; k ++) {
        dp[i + k][i + j + k - 1] = add(dp[i + k][i + j + k - 1], mul(dp[i][j], binom(n - i, k), p[k][i + k - 1]));
      }
    }
  }
  let ans = 0;
  for (let i = 1; i <= x; i ++)
    ans = add(ans, dp[n][i]);
  print(ans);
}
proc(main, 'input.txt');

// Generated with compe.js - https://github.com/polarity-cf/compe.js


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	const s = readLine().split('');
	const { length } = s;
	const match = 'hello'.split('');
	let current = 'h';
	let count = 0;

	for (let i = 0; i < length; ++i) {
		if (s[i] === current) {
			count++;
			current = match[count];
		}

		if (count >= 5) {
			break;
		}
	}

	count === 5 ? console.log('YES') : console.log('NO');
}


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

  let tmp=0, lngth=0, str='';

  rl.on('line', (input) => {
      if (tmp==0) {lngth=Number(input); tmp++;}
      else {str=input; rl.close(); therest();
    return 0;}

  });

  let therest=function() {
    let res='', step=1;
    for (let i=0; i<lngth; i++) {
        res+=str[i];
        i+=step;
        step++;
    }
console.log(res);}
//console.log(lngth, str);}

  /*
  rl.question('What do you think of Node.js? ', (answer) => {
    // TODO: Log the answer in a database
    console.log(`Thank you for your valuable feedback: ${answer}`);

    rl.close();
  });*/


let input;
process.stdin.on('data', c => input = c);
process.stdin.on('end', sol);

function f(x) {
  ++x;
  while (x % 10 === 0) {
    x /= 10;
  }
  return x;
}

function sol() {
  const visited = {};
  let x = Number(input);
  visited[x] = true;
  let count = 1;
  while (!visited[f(x)]) {
    x = f(x);
    visited[x] = true;
    ++count;
  }
  process.stdout.write(count.toString(), 'utf8', () => process.stdout.end());
}


const readline = require('readline');

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

var ans = 0,
    metColumn = false;

rl.on('line', (s) => {

    if (s == 'BBBBBBBB')
        ans++;
     else if (!metColumn) {
         //console.log("inside else if metColumn= &s",metColumn)
        let helper= s.match(/B/g);
        if(helper!=null)
        ans += helper.length;
        metColumn = true;
    }

}).on('close', () => {
    console.log(ans);
    rl.close();

});


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function printResult(x) {
    process.stdout.write(x);
}

function main() {
    const arrPoints = new Array(8);
    for (let i = 0; i < 8; i++) {
        let rl = readLine().split(' ').map(Number);
        arrPoints[i] = new Point(rl[0], rl[1]);
    }

    // console.log('eee',arrPoints[0].x);
    // const result = eightPointSet(arrPoints);
    eightPointSet(arrPoints);
    // printResult(result.toString());
}

function Point(x, y)
{
    this.x = x;
    this.y = y;
}

const comparePoints = (a, b) => {
    if (a.x < b.x || (a.x === b.x && a.y < b.y)) {
        return -1;
    }
    if (a.x > b.x || (a.x === b.x && a.y > b.y)) {
        return 1;
    }
    return 0;
}

const eightPointSet = (a) => {
    a.sort(comparePoints);
    if (a[0].x === a[1].x && a[1].x === a[2].x
        && a[2].x !== a[3].x
        && a[3].x === a[4].x
        && a[4].x !== a[5].x
        && a[5].x === a[6].x && a[6].x === a[7].x
        && a[0].y === a[3].y && a[3].y === a[5].y
        && a[5].y !== a[1].y
        && a[1].y === a[6].y
        && a[6].y !== a[2].y
        && a[2].y === a[4].y && a[4].y === a[7].y) {
        printResult('respectable');
    } else {
        printResult('ugly');
    }
};


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    inputs = inputs[0].split(' ');
    const n = parseInt(inputs[0]);
    const m = parseInt(inputs[1]);
    let moves = 0;

    if (n < m)
        return console.log(-1)

    moves = Math.floor(n / 2) + n % 2;

    while (moves%m !== 0 && moves < n) {
        moves +=1;
    }

    console.log(moves);

});


const readLine = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const luckyNumber = () => {
    let ar = [];
    let sum = 0;
    for (const x of input[0]) {
        ar.push(+x);
    }
    for (const y of ar) {
        if (y === 4 || y === 7) {
            sum ++;
        }
    }
    if (sum % 10 === 4 || sum % 10 === 7) {
        console.log('YES');
    }
    else {
        console.log('NO');
    }

};

readLine.on('close', luckyNumber);


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        let [n, k] = lines[l++].trim().split(' ')
        n = +n
        output[i] = solve(n, k)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k) {
    if (k.length >= n) return 0
    let has = 0
    for (let i = 0; i < k.length; i++) {
        if (+k[i] > 1) {
            has = 1
            break
        }
    }
    if (!has) return -1

    let q = {}
    q[k] = 1
    has = 1
    let count = 1
    const visited = {}
    while (has) {
        const nq = {}
        has = 0
        for (let s in q) {
            const bs = BigInt(s)
            for (let i = 0; i < s.length; i++) {
                const x = BigInt(s[i])
                const nx = bs * x
                if (visited[nx]) continue
                visited[nx] = 1
                // console.log(count, nx)
                if (String(nx).length >= n) return count
                nq[nx] = 1
                has = 1
            }
        }
        q = nq
        count++
    }
    return count
}


process.stdin.on('data', input => {
    let [ l, h, a ] = input.toString().split(' ');
    let ln = l % a == 0 ? l / a : (l / a) + 1;
    let hn = h % a == 0 ? h / a : (h / a) + 1;

    ln = ln | 0;
    hn = hn | 0;

    console.log(ln * hn);
});


var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    console.log(solve(+lines[l++]))
});

function solve(n) {
    const dp = Array(n + 1).fill(0)
    for (let i = 1; i < n; i++) {
        for (let j = i + i; j <= n; j += i) {
            dp[j]++
        }
    }
    let sum = 1
    for (let i = 1; i <= n; i++) {
        dp[i] = add(dp[i], sum)
        sum = add(sum, dp[i])
    }
    return dp[n]
}

function add(a, b) {
    return (a + b) % 998244353
}


"use strict";
let input = [];
const readline=require('readline');
const RL=readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
RL.on('line', (line)=>{
  input.push(line.trim());
});
RL.on('close', ()=>{
  let [n, k]=input[0].split(" ");
  const arr=input[1].split(" ");
  const scores=arr.map((str)=>{
    return Number(str);
  });

  let answer=0;
  const Kth=Number(k);
  scores.forEach(element => {
    if(element>0 && element>=scores[Kth-1]){
      answer++;
    }
  });
  console.log(answer);
});


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (str) => {
  if (c === 0) {
    c++;
    return;
  }

  let ans = 'YES';
  let sevens = 0;
  let fours = 0;

  for (let i = 0; i < str.length / 2; i++) {
    if (str[i] === '4') {
      fours++;
    }
    else if (str[i] === '7') {
      sevens++;
    }
    else {
      ans = 'NO';
    }
  }

  for (let i = str.length / 2; i < str.length; i++) {
    if (str[i] === '4') {
      fours--;
    }
    else if (str[i] === '7') {
      sevens--;
    }
    else {
      ans = 'NO';
    }
  }

  if (fours === 0 && sevens === 0) {
    console.log(ans);
  }
  else {
    console.log('NO');
  }

  c++;
});


// author: Oscar Ramos

/// Source Code
// const input = require('competitive-programming-js').inputReader
//
// const s1 = input.readLine().toLowerCase()
// const s2 = input.readLine().toLowerCase()
//
// console.log(s1 < s2? -1: s1===s2? 0: 1)
//

!function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){e.exports=t(1)},function(e,n){let t,r=0,o={readLine:function(){return t[r++]}};var u="";process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",(function(e){u+=e})).on("end",(function(){t=u.trim().split("\n").map(e=>e.trim());const e=o.readLine().toLowerCase(),n=o.readLine().toLowerCase();console.log(e<n?-1:e===n?0:1)}))}]);

/// package.json
// {
//   "name": "competitive",
//   "version": "1.0.0",
//   "description": "",
//   "main": "src/index.js",
//   "scripts": {
//     "test": "echo \"Error: no test specified\" && exit 1",
//     "convert": "cp-convert -s src/index.js -d output/converted.js",
//     "bundle": "webpack --config ./webpack.config.js",
//     "production": "npm run convert && npm run bundle && node src/getOutput.js",
//     "start": "node src/index.js"
//   },
//   "author": "Oscar Ramos",
//   "dependencies": {
//     "competitive-programming-js": "^1.0.10",
//     "mathball": "^0.4.0",
//     "ramda": "^0.27.1"
//   },
//   "devDependencies": {
//     "terser-webpack-plugin": "^4.1.0",
//     "webpack": "^4.44.1",
//     "webpack-cli": "^3.3.12"
//   }
// }
//


let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  const [n, m] = readLine().split(' ');
  console.log(Math.floor((n * m) / 2));
}


process.stdin.resume();
process.stdin.setEncoding('ascii');
var inputString="";
var currentLine=0;

process.stdin.on('data',function(data){
	inputString+=data;
});
process.stdin.on('end',function(){
	inputString=inputString.split('\n');
	main();
});
function readline(){
	return inputString[currentLine++];
}
function main(){
	 var[m,n,a]=(readline().split(' '));
	  var ans=Math.ceil(m/a)*Math.ceil(n/a);
	  console.log(ans);
}


var fs = require('fs')
var pb = fs.readFileSync(0, {encoding: "utf8"});

var [n, m, a] = pb.split(' ').map(x => parseInt(x, 10))

console.log(Math.ceil(n/a) * Math.ceil(m/a))


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let [number, n] = readline().split(" ").map(x => parseInt(x));

    for (var i = 0; i < n; i++) {
        if (number % 10 === 0) {
            number /= 10;
        } else {
            number--
        }
    }
    console.log(number);

}


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function multiply(a, b) {
	a = a.toString(10).split('').reverse();
	b = b.toString(10).split('').reverse();

	if (a.length < b.length) {
		[a, b] = [b, a];
	}

	let res = Array(a.length + b.length).fill(0);
	for (let i = 0, lb = b.length; i < lb; ++i) {
		let carry = 0;
		let scarry = 0;
		for (let j = 0, la = a.length; j < la; ++j) {
			let m = b[i] * a[j];
			m += carry;

			if (m > 9) {
				let [c, d] = m.toString(10).split('');
				res[i + j] += (scarry >> 0) + (d >> 0);
				carry = c >> 0;
			} else {
				res[i + j] += (scarry >> 0) + m;
				carry = 0;
			}

			if (res[i + j] > 9) {
				let [c, d] = res[i + j].toString(10).split('');
				res[i + j] = d >> 0;
				scarry = c;
			} else {
				scarry = 0;
			}
		}
		if (carry > 0) res[a.length + i] = carry;
		if (scarry > 0) res[a.length + i] = scarry;
	}

	res.reverse();
	let mulVal = '';
	let flag = false;
	res.forEach(d => {
		if (!flag && d !== 0) flag = true;
		if (flag) mulVal += d;
	});
	return mulVal;
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);
	let q = readLine()
		.split(' ')
		.map(x => x >> 0);
	q = q.map(x => (x <= m ? 0 : Math.ceil(x / m)));

	let max = 0,
		v = 0;
	for (let i = 0; i < n; ++i) {
		if (q[i] >= max) {
			max = q[i];
			v = i + 1;
		}
	}
	console.log(v);
}


let newString = '';

let transformString = ( character ) => {
    if( !character.match(/[aeiouy]/gi) ){
        newString += `.${character}`;
    }
};
process.stdin.once('data', (input) => {
    Array.from( input.toString().trim().toLowerCase() ).map( ( char ) => transformString( char ) );
    console.log(newString);
    process.exit();
});


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const s = readline();
  const t = readline();
  helper(s, t);
}

function helper(s, t) {
    if (s.length < t.length) {
        console.log('need tree');
        return;
    }
    if (s.indexOf(t) > -1) {
        console.log('automaton');
        return;
    }
    let need_tree = false;
    let automaton = false;
    let array = false;

    let cntT = new Array(26).fill(0);
    for (let i = 0; i < t.length; i++) {
        cntT[t.charCodeAt(i) - 97]++;
    }

    let cntS = new Array(26).fill(0);
    for (let i = 0; i < s.length; i++) {
        cntS[s.charCodeAt(i) - 97]++;
    }

    for (let i = 0; i < 26; i++) {
        if (cntT[i] > cntS[i]) {
            need_tree = true;
            break;
        }
        if (cntT[i] < cntS[i]) {
            automaton = true;
        }
    }

    if (need_tree) {
        console.log('need tree');
        return;
    }

    let match = -1;
    let found = 0
    for (let i = 0; i < t.length; i++) {
        found = s.indexOf(t.charAt(i), match + 1)
        if (found > match) {
            match = found;
        } else {
            array = true;
            break;
        }
    }

    if (automaton && array) {
        console.log('both');
        return;
    }
    if (automaton) {
        console.log('automaton');
        return;
    }
    console.log('array');
    return;
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

const solve = (row, col) => {
  if (row === 1 || col === 1) {
    return 1;
  }

  return solve(row - 1, col) + solve(row, col - 1);
}

rl.on('line', (d) => {
  console.log(solve(+d, +d));

  // const matrix = new Array(+d).fill(1).map(x => new Array(+d).fill(1));
  // let ans = 0;

  // for (let i = 0; i < matrix.length; i++) {
  //   for (let j = 0; j < matrix[i].length; j++) {
  //     let v = 0;
  //     if (Number.isInteger(matrix[i][j - 1])) {
  //       v += matrix[i][j - 1];
  //     }

  //     if (matrix[i - 1] && Number.isInteger(matrix[i - 1][j])) {
  //       v += matrix[i - 1][j]
  //     }

  //     matrix[i][j] = Math.max(1, v);
  //     ans += matrix[i][j];
  //   }
  // }

  // console.log(matrix);
  // console.log(matrix[matrix.length - 1][matrix.length - 1]);
});


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  let ans = 'NO';
  let count = 0;

  for (let i = 0; i < d.length; i++) {
    if (d[i] === '7' || d[i] === '4') {
      count++;
    }
  }

  if (count === 7 || count === 4) {
    ans = 'YES';
  }

  console.log(ans);
});


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
})

readline.question("", (word) => {
    let Ca=0,Sm=0;
    for(let i of word){
        if(i==i.toUpperCase()){
            Ca++;
        }else{
            Sm++;
        }
    }
    if(Ca>Sm){
        console.log(word.toUpperCase());
    }else{
        console.log(word.toLowerCase());
    }
    readline.close()
})


let readline = require('readline').createInterface({
  input: process.stdin,
});

readline.on('line', (line) => {
  let [a, b, c, d] = line.split(' ').map(Number);
  [a, b, c] = [a, b, c].sort((x,y)=> x-y)
  console.log(
    Math.max(0, d - (b - a)) + Math.max(0, d - (c - b))
  )
});


const readline = require('readline');
const r = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let n,k;
let input;
r.on('line', (line) => {
    if (!n) {
        [n,k] = line.split(" ").map(n=>+n);
     }
    else {
        let nums = line.split(" ").map(n => +n);
        let marks = nums[k-1];
        console.log(nums.filter(n => n >= marks && n > 0 ).length);
    }
});


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    logic();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    //console.log(x);  // with auto '\n' (newline)
}

function logic() {
    const line = readline();

    const params = line.split(' ');
    const number = parseInt(params[0]);
    const iterations = parseInt(params[1]);

    let result = number;
    for (let i=1; i <= iterations; i++) {

        if (result/10 !== parseInt(result/10)) {
            result--;
        }
        else {
            result /= 10;
        }
    }

    output(String(result));
}


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var inputs = [];
const PI = parseInt;

function main() {
    const [f, t] = inputs[0].split(" ").map(_ => parseInt(_));

    let reach = false;
    let min = Number.MAX_VALUE;
    const rec = (from, lvl) => {
        //console.log(from, lvl);
        if(from > t) return;
        if (reach === true) return;
        if (from === t) { reach = true; min = Math.min(min, lvl); return; };
        rec(from * 3, lvl + 1), rec(from * 2, lvl + 1);
    };
    rec(f, 0)
    console.log((reach) ? min : -1);
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// thats all what you have to write to get input from stdin, using readLine.

// Main code runs in main();

function main() {
const num = readline().split(" ").map(x => parseInt(x))
let k = parseInt(num[1]);
let x = `${num[0]}`.split('');
for (let i=0;i<k;i++){
  if (!x.length) return console.log(0);
  if (x[x.length-1] == 0) {
    x.pop();
  } else {
    x[x.length-1] -= 1;
  }
}
console.log(parseInt(x.join('')));
}


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [n] = input[0].split(' ').map(x => parseInt(x));
  const matrix = [];

  for (let i = 0; i < n; i += 1) matrix.push(Array(n).fill(1));

  for (let i = 1; i < n; i += 1) {
    for (let j = 1; j < n; j += 1) {
      matrix[i][j] = matrix[i][j-1]+matrix[i-1][j];
    }
  }

  console.log(matrix[n-1][n-1]);
});


const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let input = ''
let solution = function(x, arr) {
  let memo = {}
  let recur = function(n) {
    if (memo[n] != null) return memo[n]
    if (n < 0) return Number.MIN_SAFE_INTEGER
    if (n === 0) return 0
    let max = Number.MIN_SAFE_INTEGER
    for (let j of arr) {
      max = Math.max(max, 1 + recur(n - j))
    }
    memo[n] = max
    return max
  }
  return recur(x)
}
rl.on('line', (line) => {
  input += line
  input = input.split(' ').map(x => parseInt(x))

  let n = input[0]
  let arr = input.slice(0)
  console.log(solution(n, arr))
})


process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    let shoesArray = readLine().split(' ').map(Number);
    let selecTed = []; // [1, 7, 3, 3]
    for (let i = 0; i < shoesArray.length; i++) {
        if (selecTed.indexOf(shoesArray[i]) === -1) {
            selecTed.push(shoesArray[i]);
        }
    }
    let result = shoesArray.length - selecTed.length;
    console.log(result);
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  let [k, r] = d.split(' ').map(Number);
  let ans = 0;
  let coin = 10;
  let c = 1;
  let v = k;

  while (true) {
    if (v % coin === 0 || v % coin === r) {
      break;
    }
    else {
      ans++;
      v = k * c;
      c++;
    }
  }

  console.log(Math.max(1, ans));
});


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// thats all what you have to write to get input from stdin, using readLine.

// Main code runs in main();

function main() {
const num = readline().split(" ").map(x => parseInt(x))
let k = parseInt(num[1]);
let n = parseInt(num[0]);
for(let i=0;i<k;i++) {
  if(n%10===0) n = Math.floor(n/10);
  else n -= 1;
}
console.log(n)
}


const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
            return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
            let a = readline();
            var r = []
            var count = 0;
            for(var i=1;i*i<=a;i++) {
                var as = i*i;
            	if(r[as] == undefined) {
            	    count++;
            	    r[as] = true;
            	}
            	if(r[as*i] == undefined && as*i <= a) {
            	    count++;
            	    r[as*i] = true;
            	}
            }
            console.log(count)
}


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    const [n, k] = lines[0].split(' ').map(r => parseInt(r))
    const scores = n > 0 ? lines[1].split(' ').map(r => parseInt(r)) : []
    const v = scores[k - 1]
    const count = scores.reduce((s, r) => r >= v && r > 0 ? s + 1 : s, 0)

    console.log(count);
})


var fs = require('fs');
var input = fs.readFileSync(0, 'utf8').trim().split('\n');
var currentline = 0;
function readline() {
    return input[currentline++];
}
var T = readline();
for (var i = 0; i < T; i++) {
    var n = parseInt(readline());
    var ans = 0;
    for (var j = 0; j * j <= n; j++)
        ans++;
    for (var j = 0; j * j * j <= n; j++)
        ans++;
    for (var j = 0; j * j * j * j * j * j <= n; j++)
        ans--;
    console.log(ans - 1);
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (w) => {
  let lowerCount = 0;
  let upperCount = 0;

  for (let i = 0; i < w.length; i++) {
    if (w.charCodeAt(i) > 64 && w.charCodeAt(i) < 97) {
      upperCount++;
    }
    else {
      lowerCount++;
    }
  }

  if (upperCount > lowerCount) {
    console.log(w.toUpperCase());
  }
  else {
    console.log(w.toLowerCase());
  }
});


const readLine = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const matrix = () => {
    let oneStringRow;
    let oneColumn;
    let steps;
    for (let i = 0; i < input.length; i++) {
        if (input[i].includes('1')) {
            oneStringRow = i;
            oneColumn = input[i].indexOf('1') / 2;
        }
    }
    steps = Math.abs(2 - oneStringRow) + Math.abs(2 - oneColumn);
    console.log(steps);
};
readLine.on('close', matrix);


const start=(main, readlineFun, printFun) => {
  if (readlineFun && printFun) {
    main(readlineFun, printFun);
    return;
  }

  process.stdin.resume();
  process.stdin.setEncoding("utf8");

  let input = "",
    readline,
    print;

  process.stdin.on("data", function(chunk) {
    input += chunk;
  });

  process.stdin.on("end", function() {
    input = input.split("\n");
    print = function(data) {
      process.stdout.write(data + "\n");
    };
    let inputLineIndex = 0;
    readline = function() {
      return inputLineIndex >= input.length
        ? undefined
        : input[inputLineIndex++];
    };
    process.exit(main(readline, print) || 0);
  });
}
 function main(readline, print) {
  let a = readline().split(" ");
  print(Math.ceil(a[0] / a[2]) * Math.ceil(a[1] / a[2]));
}
 start(main);


var read = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function (input) { inLine.push(input); });
read.on('close', function () {
    obj = init(inLine);
    myerr("-----start-----");
    var start = new Date();
    Main();
    var end = new Date() - start;
    myerr("----- end -----");
    myerr("Time: " + (end) + "ms");
    myerr("Memory: " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt() { return myconv(next(), 1); }
function nextStrArray() { return myconv(next(), 2); }
function nextIntArray() { return myconv(next(), 4); }
function nextCharArray() { return myconv(next(), 6); }
function next() { return obj.next(); }
function hasNext() { return obj.hasNext(); }
function init(input) {
    var returnObj = {
        list: input, index: 0, max: input.length,
        hasNext: function () { return (this.index < this.max); },
        next: function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { var returnInput = this.list[this.index]; this.index++; return returnInput; } }
    };
    return returnObj;
}
function myout(s) { console.log(s); }
function myerr(s) { console.error("debug:" + require("util").inspect(s, false, null)); }
function myconv(i, no) { try { switch (no) { case 1: return parseInt(i); case 2: return i.split(" "); case 4: return i.split(" ").map(Number); case 6: return i.split(""); case 7: return i.split("").map(Number); 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 n = nextIntArray();

    return myout(Math.floor((n[0] * n[1]) / 2));
} // Use Terminal to debug, not Debug Console!


'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString='';
let currentLine=0;
process.stdin.on('data',inputStdin=>{
    inputString+=inputStdin;
});
process.stdin.on('end',_=>{
    inputString=inputString.trim().split("\n").map(string=>{
        return string.trim();
    });
    main();
});
function readLine()
{
    return inputString[currentLine++];
}
function ans(s)
{
    let zer=[-1,-1],tw=-1,se=-1,fi=-1,fnz=-1;
    for(let i=1;i<s.length;++i)
    {
        if(s[i]!='0')
        {
            fnz=i-1;
            break;
        }
    }
    for(let i=s.length-1;i>=0;--i)
    {
        if(s[i]=='7')
        {
            se=i;
            break;
        }
    }
    for(let i=s.length-1;i>=0;--i)
    {
        if(s[i]=='2')
        {
            tw=i;
            break;
        }
    }
    for(let i=s.length-1;i>=0;--i)
    {
        if(s[i]=='5')
        {
            fi=i;
            break;
        }
    }
    let k=0;
    for(let i=s.length-1;i>=0;--i)
    {
        if(s[i]=='0')
        {
            zer[k++]=i;
            if(k==2)
                break;
        }
    }
    zer.length=k;
    if(fi==-1)
    {
        if(zer.length<2)
            return -1;
        return (2*s.length-3-zer[0]-zer[1]);
    }
    else
    {
        let ac=[];
        if(zer.length>=2)
        {
            ac.push(2*s.length-3-zer[0]-zer[1]);
        }
        if((zer.length>=1)&&(fi!=-1))
        {
            ac.push(2*s.length-3-zer[0]-fi+(fi>zer[0]?1:0)+(fi===0?(zer[0]==1?0:fnz):0));
        }
        if((tw!=-1)&&(fi!=-1))
        {
            ac.push(2*s.length-3-tw-fi+(tw>fi?1:0)+(Math.min(fi,tw)===0?fnz:0));
        }
        if((se!=-1)&&(fi!=-1))
        {
            ac.push(2*s.length-3-se-fi+(se>fi?1:0)+(Math.min(fi,se)===0?fnz:0));
        }
        if(ac.length!==0)
            return Math.min.apply(Math,ac);
        else
            return -1;
    }
}
function main()
{
    let n=readLine().trim();
    console.log(ans(n));
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let s = readLine();
    let ans = 0;
    for (var i = 0; i < s.length; i++) {
        let oke = 1;
        for (var j = 7; j > 0; j--) {
            if (s[i + 7 - j] != s[i]) {
                oke = 0;
                break;
            }
        }
        if (oke == 1) {
            ans++;
            break;
        }
    }
    if (ans == 1) {
        console.log('YES')
    } else console.log('NO')
}


//Is your horseshoe on the other hoof?

const {EOL} = require('os');

let inp = '';

process.stdin.on('data', c => inp += c);

process.stdin.on('end', () => {
    let lines = inp.split(EOL)[0].split(' ');

    process.stdout.write((lines.length - (new Set(lines)).size) + '');

    return;
});


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const k = input[0];
  const l = input[1];
  const answ = [];

  for (let i = 0; i < k.length; i += 1) {
    if (k[i] !== l[i]) answ.push(1);
    else answ.push(0);
  }

  console.log(answ.join(''));
});


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const check = year =>
  String(year)[0] !== String(year)[1] && String(year)[1] !== String(year)[2] && String(year)[3] !== String(year)[2]
  && String(year)[0] !== String(year)[2] && String(year)[1] !== String(year)[3] && String(year)[0] !== String(year)[3];

readLine.on('close', () => {
  let answer = 0;
  let year = parseInt(input[0]) + 1;

  while (!check(year)) {
    year += 1;
  }

  console.log(year);
});


function main() {
  var n = +nxt(), m = +nxt(), k = +nxt() - 1;
  function ok(val) {
    var u = Math.min(k + val - 1, n - 1) - k + 1;
    var v = k - Math.max(k - val + 1, 0) + 1;
    var s1 = (val + val - u + 1) * u / 2;
    var s2 = (val + val - v + 1) * v / 2;
    return (s1 + s2 - val + n - u - v + 1) <= m;
  }
  var l = 1, r = m;
  while (l < r) {
    var mid = l + ((r - l + 1) >> 1);
    if (ok(mid)) l = mid;
    else r = mid - 1;
  }
  print(l);
}

var line = null, linepos = 0;
function nxt() {
  if (!line || linepos === line.length) {
    line = readline().split(' ');
    linepos = 0;
  }
  return line[linepos++];
}

if (typeof readline == 'undefined') {
  process.stdin.resume();
  process.stdin.setEncoding('ascii');

  var input_stdin = "";
  process.stdin.on('data', function (data) { input_stdin += data; });
  process.stdin.on('end', function () {
    // input_stdin = input_stdin.split(/\s/);
    input_stdin = input_stdin.split('\n');
    var curline = 0;
    readline = () => input_stdin[curline++];
    if (typeof print === 'undefined') print = console.log;
    main();
  });
} else main();


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const arr = readLine()
    .split("+")
    .map((n) => parseInt(n));
  console.log(arr.sort().join("+"));
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  let [n, v] = d.split(' ').map(Number);
  let ans = Math.min(n - 1, v);
  let price = 1;
  n -= v + 1;

  while (n > 0) {
    price++;
    ans += price;

    n--;
  }

  console.log(ans);

  c++;
});


let data = '';
process.stdin.on('data', c => data += c);

const solution = () => {
	let a = data.trim().split(/\n/g).map(v => v[0]).join('');
	let f = ['rss', 'prr', 'spp'];
	let m = ['srs', 'rpr', 'psp'];
	let s = ['ssr', 'rrp', 'pps'];
	let ans = '';
	switch(true) {
		case f.includes(a): ans = "F";
			break;
		case m.includes(a): ans = "M";
			break;
		case s.includes(a): ans = "S";
			break;
		default:
			ans = "?";
	}
	console.log(ans);

};

process.stdin.on('end', solution);


process.stdin.setEncoding('utf8');
let input = [];
process.stdin.on('readable', () => {
    const chunk = process.stdin.read();
    if (chunk !== null) {
        let re = /\n\s*| /;
        input = chunk.split(re).slice(0, 6);
        console.log(snowball.apply(null, input.map(value => parseInt(value))));
        process.exit(0);
    }
});

function snowball(weight, height, u1, d1, u2, d2) {
    let w = weight, h = height;
    for (; h >= 0; h--) {
        w += h;
        if (h == d1) w = Math.max(w - u1, 0);
        if (h == d2) w = Math.max(w - u2, 0);
    }
    return w;
}


const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const snowBall = lines[0].split(" ").map(x => parseInt(x));
    const stoneOne = lines[1].split(" ").map(x => parseInt(x));
    const stoneTwo = lines[2].split(" ").map(x => parseInt(x));

    let snowW = snowBall[0];
    let snowH = snowBall[1];

    for (let i = snowH; i>=0; i--) {
        snowW = snowW+i;
        if (i === stoneOne[1]) {
            snowW -= stoneOne[0];
        }

        if (i === stoneTwo[1]) {
            snowW -= stoneTwo[0];
        }
        if (snowW < 0)
            snowW = 0;
    }
    console.log(snowW);
}

readLines(3, doIt);


//Boy or Girl

const {EOL} = require('os');

let inp = '';

process.stdin.on('data', c => inp += c);

process.stdin.on('end', () => {
    process.stdout.write(((new Set(inp.split(EOL)[0].split(''))).size % 2) ? "IGNORE HIM!" : "CHAT WITH HER!");

    return;
});


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let k, l, m, n, d;
let ans = 0;

rl.on('line', (data) => {
  if (c === 0) {
    k = +data;
    c++;
    return;
  }

  if (c === 1) {
    l = +data;
    c++;
    return;
  }

  if (c === 2) {
    m = +data;
    c++;
    return;
  }

  if (c === 3) {
    n = +data;
    c++;
    return;
  }

  if (c === 4) {
    d = +data;
    c++;
  }

  for (let i = 1; i <= d; i++) {
    if (i % k === 0 || i % l === 0 || i % m === 0 || i % n === 0) {
      ans++;
    }
  }

  console.log(ans);

  c++;
});


process.stdin.on('data', input => {
    const [n, m, a] = String(input).split(' ').map(i => parseInt(i));

    n_neded = 0;
    m_neded = 0;

    if (n % a != 0) {
        n_neded = Math.floor(n / a) + 1;
    } else {
        n_neded = Math.floor(n / a);
    }

    if (m % a != 0) {
        m_neded = Math.floor(m / a) + 1;
    } else {
        m_neded = Math.floor(m / a);
    }

    console.log(n_neded * m_neded);
   }
)


function solve(input, target) {
  const D = [];
  for (let i = 0; i < target.length; i++) {
    D.push([]);
  }
  for (let i = 0; i < input.length; i++) {
    D[0][i] = input[i] === target[0] ? 1 : 0;
  }
  for (let j = 1; j < target.length; j++) {
    for (let i = 0; i < input.length; i++) {
      if (input[i] !== target[j]) {
        D[j][i] = 0;
        continue;
      }
      D[j][i] = D[j - 1].slice(0, i).reduce((acc, v) => acc + v, 0);
    }
  }
  return D.pop().reduce((acc, v) => acc + v);
}

function* main() {
  const input = yield;
  const r = solve(input, "QAQ");
  console.log(r);
  process.exit(0);
}

if (!module.parent) {
  (() => {
    const q = main();
    q.next();
    require("readline")
      .createInterface({
        input: process.stdin,
        output: null
      })
      .on("line", line => q.next(line));
  })();
}
exports.solve = solve;


function solution(num){
    var sf = num.match(/SF/g), fs = num.match(/FS/g)
    return (sf? sf.length: 0) > (fs? fs.length: 0)? "YES": "NO"
}
process.stdin.addListener("data", (data)=>{
    var num = data.toString().replace(/\d+\s+/, "");
    console.log(solution(num))
})


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)

    const weight = parseInt(lines[0]);
    const answer = (weight <= 2 || weight % 2 !== 0) ? "NO" : "YES";
    console.log(answer);
})


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const matrix = [];
  for (let i = 0; i < 3; i++) {
    let row = readLine()
      .split(" ")
      .map((n) => parseInt(n) % 2);
    matrix.push(row);
  }
  const dp = [...Array(3).fill(0)].map((_) => Array(3).fill(0));

  function addToAdjacent(row, col, val) {
    dp[row][col] += val;
    if (row + 1 < 3) {
      dp[row + 1][col] += val;
    }
    if (row - 1 >= 0) {
      dp[row - 1][col] += val;
    }
    if (col + 1 < 3) {
      dp[row][col + 1] += val;
    }
    if (col - 1 >= 0) {
      dp[row][col - 1] += val;
    }
  }

  for (let row = 0; row < 3; row++) {
    for (let col = 0; col < 3; col++) {
      addToAdjacent(row, col, matrix[row][col]);
    }
  }

  for (let row = 0; row < 3; row++) {
    let _row = "";
    for (let col = 0; col < 3; col++) {
      const val = dp[row][col];
      if (val % 2 === 0) _row += "1";
      else _row += "0";
    }

    console.log(_row);
  }
}


//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var s = nextCharArray();
	var N = s.length;
	var output = [];
	if(N % 2 == 0){
		while(s.length > 0){
			output.unshift(s.pop());
			output.unshift(s.shift());
		}
	}else{
		while(s.length > 1){
			output.unshift(s.shift());
			output.unshift(s.pop());
		}
		output.unshift(s.pop());
	}
	myout(myconv(output, 0));
}


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

  let l=0;
  rl.on('line', (input) => {
      if (l==0) {l++}
      else {
           rl.close();
           let strArray = input.split(" ")
           let s = strArray.map(function(item) {
            return parseInt(item, 10);
        });
           s = s.sort(function sortNumber(a,b) {
            return a - b;
        })
           let res=0;
           for(let i=0;i<input.length; i+=2){
            let d = s[i+1]-s[i]
            if(d>0) {
                res+=d
            }
        }
        console.log(res)
    return 0;
}
});


process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let t = readLine()
    let str = readLine()
    let count = 0

    for (let i = 0; i < str.length-1; i++) {
        if (str[i+1] === str[i]) count += 1
    }

    console.log(count)
}


function main() {
    const n = +stdin[0];
    var a = [];
    for (var z = 0; z < 20; z++) {
        a[z] = []
        for (var i = 0; i < 500000; i++) {
            a[z][i] = i * z;
        }
    }
    var s = 0;
    for (var z = 0; z < 20; z++) {
        for (var i = 0; i < 500000; i++) {
            s += a[z][i];
        }
    }
    console.log(n * 3 / 2);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});

var stdin = [];

rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


let readline  = require('readline');
let intInput = readline.createInterface({
	input: process.stdin,
	output: process.stdout
});
let arr;

intInput.on('line', (line) => {
	arr = line.split(" ").map(s => +s)
});
intInput.on('close', () => {
	let result = 'No';
	let [memb, pen, note] = arr;
	if ( pen >= memb && note >= memb ) {
		result = 'Yes'
	}
	console.log(result);
})


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
let charA = input[0].match(/(a)/g)
charA = charA ? charA.length : 1
const allChars = input[0].length
const anyCars = allChars - charA
let _result = allChars
if (anyCars >= charA)
  _result = (charA * 2) - 1
console.log(_result)
})


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n, x] = input[0].split(' ').map(x => parseInt(x));

  let answ = 0
  for (let i = 1; i <= n; i += 1) {
    if (x % i === 0 && x/i <= n) answ += 1;
  }

  console.log(answ);
});


const readline = require('readline');

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

let steps = 0;

rl.on('line', n => {
  if (n < 5) {
    console.log(++steps);
    rl.close();
  } else {
    steps += n / 5;
    console.log(Number.isInteger(steps) ? steps : Math.floor(steps) + 1);
    rl.close();
  }
});


var line_number = 0;
const cs = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

var lines = {};
cs.on("line", (input) => {
  if (input == "") {
    cs.close();
  }
  lines[line_number] = input.split(" ");
  line_number += 1;
}).on("close", () => {
  main();
  process.exit();
});

function isOp(str) {
  return str.length === 1 && str.match(/[<=>]/);
}
function isChr(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}
function isInt(str) {
  return str.length === 1 && str.match(/[0-9*]/);
}

function print(str) {
  console.log(str);
}

function exit(status = 0) {
  process.exit(status);
}

function predict(test) {
  let op = "";
  let ops = [];
  let opVariables = [];
  let limits = [];
  for (let t of test) {
    // console.log(t);
    for (let i = 0; i < t.length; i++) {
      if (isOp(t[i])) {
        op = t[i];
        if (isOp(t[i + 1])) {
          op += t[i + 1];
          i += 1;
        }
        ops.push(op);
        op = "";
      } else if (isChr(t[i])) {
        // console.log(t[i])
        op = t[i];
        for (var j = i + 1; j < t.length; j++) {
          if (isChr(t[j]) || isInt(t[j])) {
            op += t[j];
            i = j;
          } else break;
        }
        opVariables.push(op);
        op = "";
      } else {
        if (i == 0 || (i > 0 && isOp(t[i - 1]))) {
          op = t[i];
          let j = i + 1;
          for (; j < t.length; j++) {
            if (isInt(t[j])) {
              op += t[j];
              i = j;
            } else break;
          }
          limits.push(op);
          op = "";
        }
      }
    }
  }

  let min = limits[0];
  let max = limits[1];

  let pvs = ops.map((o, i) => [o, opVariables[i]]);

  for (let pv of pvs) {
    if (pv[1] == undefined) {
      pv[1] = max;
    }
    // print(`${min} ${pv[0]} ${pv[1]} ?`)
    if (eval(`${min}${pv[0]}${pv[1]}`)) {
      // print(` ${min} ${pv[0]} ${pv[1]} true`)
      min = pv[1];
    } else {
      print("input error");
      exit();
    }
  }
}

var n;
function main() {
  n = BigInt(lines[0][0])
  predict(["1<=n<=10**18"]);
  // print(n);
  let c = 0
  do {
    x = n % 10n;
    if (x == 4 || x == 7) {
      c += 1;
    }
  } while ((n = BigInt(n / 10n)) != 0);

  if( c == 4 || c == 7) {
    print("YES")
  }
  else{
    print("NO")
  }
}


const readline = require('readline');

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

rl.on('line', (input) => {
    //console.log(`Received: ${input}`);
    arr = input.split(' ');

    console.log(Math.floor(arr[0] * arr[1] / 2));

    rl.close();
});


function test(str){
    var l = str.match(/a/g).length;
    return (l + (str.length - l > l-1 ? l-1 : str.length - l));
}

var readline = (()=>{
    process.stdin.resume();
    process.stdin.setEncoding('utf-8');

    let inputString = '';
    let currentLine = 0;

    process.stdin.on('data', inputStdin => {
        inputString += inputStdin;
    });

    process.stdin.on('end', _ => {
        inputString = inputString.trim().split('\n').map(string => {
            return string.trim();
        });

        main();
    });

    function readline() {
        return inputString[currentLine++];
    }
    return readline;
})()

function main() {
    console.log(test(readline()))
}


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
})

//readline.question("a? b? c?\n",(abc)=>{
readline.question("",(abc)=>{
    //console.clear();
    abc=abc.split(" ");
    let x=Math.ceil(abc[0]/abc[2]);
    let y=Math.ceil(abc[1]/abc[2]);
    console.log(y*x);
    readline.close();
})


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readLine());
    let ans = 0;
    if (n % 2 == 0) {
        console.log(n / 2);
    } else {
        console.log(-(n + 1) / 2);
    }
}


const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

function input(){
    return new Promise ( (resolve , error) => {
       readline.question('', (data) => {
           readline.close();
           resolve(data);
       })
    });
}

async function main(){
    n  = await input();
    if(n == 2 || n % 2 == 1){
        console.log('NO');
    } else {
        console.log('YES');
    }
}

main();


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  const [a, b, c] = d.split(' ').map(Number);
  let ans = c*2 + Math.min(a, b) * 2;

  if (a !== b) {
    ans++;
  }

  console.log(ans);
});


var n, p, cnt=1;
var a=[];
const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
})

readline.question(``, (a) => {

     p = a.length;
    for (var i = 0; i < p; ++i)
    {
        if(cnt>=7) {
        	break;
        }
        else if(a[i]===a[i+1]) {
        	cnt++;
        }
        else if(a[i]!=a[i+1]) {
        	cnt=1;
        }
    }
    if(cnt===7) console.log("YES");
    else console.log("NO");
  readline.close()
})


function main(input) {

        let a,b,c,d =[];
        let l,i=1,v=1;
        input =input.split(/\n/g);
        a = input[0].split(' ');
        l = a.length;

          c=first(Number(a[1]),Number(a[2]),Number(a[0]));
          d=second(Number(a[3]),Number(a[4]),Number(a[0]));
          l=c.length

          while(i<l){

              if(c[i]==d[i]){
                  console.log("YES");
                  v=0;
                  break;
              }
              i++;

          }
          if(v==1){
              console.log("NO");
          }

}

function first (a,b,d){
               var x=[],t=0;
               x[0]=a;
               while(a!=b){
                   if(a!=d){
                   t++;
                   x[t]=++a;
                   }
                   else if(a==d){
                       a=1;
                       t++;
                       x[t]=1;
                   }
               }
               return x;
}

function second (b,c,d){
            var y=[],t=0;
            y.push(b);
            while(b!=c){
                if(b>1){
                    t++;
                    y[t]=--b;
                }
                else if(b!=d){
                    b=d;
                    y[++t]=b;
                }
                else{

                }
            }
            return y;
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
   main(stdin_input);
});


var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var n,k;
var expect = "begin";
var scores = [];
rl.on("line", function(line) {
    if ( expect == "begin"){
        n = parseInt(line.split(" ")[0]);
        k = parseInt(line.split(" ")[1]);
        expect = "scores";
    } else if (expect =="scores"){
        scores = line.split(" ");
        rl.close();
    }
}).on("close", function(){
    if(scores[0] != 0) {
        if(scores[k-1]> 0){
            while (scores[k-1] == scores[k]) {
                k++;
            }
        }else {
            while (scores[k-1] == 0) {
                k--;
            }
        }
    console.log(k);
    } else {
    console.log(0);
    }

});


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

rl.on('line', line => {
    const input = line.split(' ');
    console.log(solution(Number(input[0]), Number(input[1])));
});

function solution(weightLimak, weightBob) {
    let count = 0;
    while(weightLimak <= weightBob) {
        count++;
        weightLimak *= 3;
        weightBob *= 2;
    }

    return count;
}


"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
function gcd(a, b) {
    if (b == 0)
        return a;
    if (a < b)
        return gcd(b, a);
    return gcd(b, a % b);
}
(async () => {
    // var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [a, b] = inputs[0].split(' ').map(v => +v);
    var c = gcd(7 - Math.max(a, b), 6);
    console.log((7 - Math.max(a, b)) / c + '/' + 6 / c);
})();


function ProblemSolver() {
    this.HAS_TEST_CASES = false ;
    this.INPUT_FILE_NAME = "sample.in" ;
    this.OUTPUT_FILE_NAME = "sample.out" ;
    this.DO_OUTPUT_TO_FILE = false ;
    this.CLEAR_ARRAY_PER_CASE = false ;

    this.solveCase = function() {
        var res , i , j , fl , cn , a , b , c ;
        res = 0 ;

        if( this.a2 + this.a3 <= this.a1 && this.b2 + this.b3 <= this.b1 ) {
            res = 1 ;
        }
        if( this.a2 + this.a3 <= this.b1 && this.b2 + this.b3 <= this.a1 ) {
            res = 1 ;
        }

        if( this.a2 + this.b3 <= this.a1 && this.b2 + this.a3 <= this.b1 ) {
            res = 1 ;
        }
        if( this.a2 + this.b3 <= this.b1 && this.b2 + this.a3 <= this.a1 ) {
            res = 1 ;
        }

        if( Math.max( this.a2 , this.a3 ) <= this.a1 && this.b2 + this.b3 <= this.b1 ) {
            res = 1 ;
        }
        if( Math.max( this.a2 , this.a3 ) <= this.b1 && this.b2 + this.b3 <= this.a1 ) {
            res = 1 ;
        }

        if( Math.max( this.a2 , this.b3 ) <= this.a1 && this.b2 + this.a3 <= this.b1 ) {
            res = 1 ;
        }
        if( Math.max( this.a2 , this.b3 ) <= this.b1 && this.b2 + this.a3 <= this.a1 ) {
            res = 1 ;
        }

        if( Math.max( this.b2 , this.a3 ) <= this.a1 && this.a2 + this.b3 <= this.b1 ) {
            res = 1 ;
        }
        if( Math.max( this.b2 , this.a3 ) <= this.b1 && this.a2 + this.b3 <= this.a1 ) {
            res = 1 ;
        }

        if( Math.max( this.b2 , this.b3 ) <= this.a1 && this.a2 + this.a3 <= this.b1 ) {
            res = 1 ;
        }
        if( Math.max( this.b2 , this.b3 ) <= this.b1 && this.a2 + this.a3 <= this.a1 ) {
            res = 1 ;
        }

        if( res == 1 ) {
            print( "YES" ) ;
        }
        else {
            print( "NO" ) ;
        }
    } ;

    this.init = function() {
        this.lim1 = 100010 ;
        this.lim2 = 110 ;
        this.cc = 1 ;
        this.ind = 1 ;
        this.n = 0 ;
        this.cn = 0 ;
        this.declareAndFillArrays() ;
    } ;

    this.getInput = function( irObj ) {
        var hasMoreInput , i ;
        hasMoreInput = true ;
        try {
        	this.a1 = irObj.nextInt() ;
        	this.b1 = irObj.nextInt() ;
        	this.a2 = irObj.nextInt() ;
        	this.b2 = irObj.nextInt() ;
        	this.a3 = irObj.nextInt() ;
        	this.b3 = irObj.nextInt() ;
        }
        catch( ex ) {
            hasMoreInput = false ;
        }
        return hasMoreInput ;
    } ;

    this.clearArraysPerCase = function() {
        var i ;
        this.arr = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
    } ;

    this.clearPerCase = function() {
        this.cn = 0 ;
        this.cc++ ;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    } ;

    this.declareAndFillArrays = function() {
        var i , j ;
        this.srr = new Array() ;
        this.vis = new Array() ;
        this.arr = new Array() ;
        this.brr = new Array() ;
        this.memo = new Array() ;
        this.done = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( '' ) ;
            this.vis.push( 0 ) ;
            this.arr.push( 0 ) ;
            this.brr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() ) ;
            this.done.push( new Array() ) ;
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 ) ;
                this.done[ i ].push( 0 ) ;
            }
        }
    } ;

    this.init() ;
}

function InputReader() {
    var self = this ;
    this.allLines = new Array() ;
    this.currrentLineNumber = 0 ;
    this.currrentCharacterIndex = 0 ;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine ;
        while( true ) {
            try {
                singleLine = readline() ;
                if( singleLine == null ) {
                    break ;
                }
            }
            catch( ex ) {
                break ;
            }
            this.allLines.push( singleLine ) ;
        }
    } ;

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    } ;

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    } ;

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    } ;

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    } ;

    this.parseRawData = function( data ) {
        var len , i , currentString ;
        len = data.length ;
        currentString = '' ;
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString ) ;
                currentString = '' ;
            }
            else {
                currentString += data[ i ] ;
            }
        }
        if( currentString != '' ) {
            this.allLines.push( currentString ) ;
        }
    } ;

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData ;
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            inputFilePath = currentDirectory + '\\' + inputFileName ;
        }
        else {
            //on linux
            inputFilePath = currentDirectory + '/' + inputFileName ;
        }
        rawData = fsObj.readFileSync( inputFilePath , "utf8" ) ;
        this.parseRawData( rawData ) ;
    } ;

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx ;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            res = '' ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++ ;
            this.currrentCharacterIndex = 0 ;
            return res ;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( 'No more tokens available!' ) ;
            }
            startIdx = -1 ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i ;
                    break ;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
                continue ;
            }
            res = '' ;
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i ;
                    break ;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
                }
            }
            this.currrentCharacterIndex = endIdx ;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            return res ;
        }
    } ;

    this.nextInt = function() {
        return parseInt( this.next( 1 ) ) ;
    } ;

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) ) ;
    } ;

    this.nextString = function() {
        return this.next( 1 ) ;
    } ;

    this.nextLine = function() {
        return this.next( 0 ) ;
    } ;
}

function FileOutputHandler() {
    this.resultantStringArray = new Array() ;

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString ) ;
    } ;

    this.clearPercase = function() {
        this.resultantStringArray = new Array() ;
    } ;

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath ;
        res = '' ;
        sz = this.resultantStringArray.length ;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += '\n' ;
            }
            res += this.resultantStringArray[ i ] ;
        }
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            outputFilePath = currentDirectory + '\\' + outputFileName ;
        }
        else {
            //on linux
            outputFilePath = currentDirectory + '/' + outputFileName ;
        }
        fsObj.writeFileSync( outputFilePath , res ) ;
        this.clearPercase() ;
    } ;
}

function CodeExecutioner() {
    this.irObj = new InputReader() ;
    this.psObj = new ProblemSolver() ;
    this.fohObj = new FileOutputHandler() ;

    this.runCases = function() {
		var testCases , hasMoreTestCases , i ;
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt() ;
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase() ;
                this.psObj.getInput( this.irObj ) ;
                this.psObj.solveCase() ;
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase() ;
                hasMoreTestCases = this.psObj.getInput( this.irObj ) ;
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase() ;
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;
        }
    } ;

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {
                    environmentType = 'local-node-js' ;
                }
                else {
                    environmentType = 'server-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    } ;

    this.configureStreamsAndReadInput = function() {
        var localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj ;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments ) ;
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino() ;
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
    } ;

    this.configureStreamsAndReadInput() ;
}

new CodeExecutioner() ;