const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const gojo=(a:number,b:number):number=>{if(a%b===0)return b;return gojo(b,a%b)};
const bigInt=function(undefined){"use strict";var BASE=1e7,LOG_BASE=7,MAX_INT=9007199254740992,MAX_INT_ARR=smallToArray(MAX_INT),DEFAULT_ALPHABET="0123456789abcdefghijklmnopqrstuvwxyz";var supportsNativeBigInt=typeof BigInt==="function";function Integer(v,radix?,alphabet?,caseSensitive?){if(typeof v==="undefined")return Integer[0];if(typeof radix!=="undefined")return+radix===10&&!alphabet?parseValue(v):parseBase(v,radix,alphabet,caseSensitive);return parseValue(v)}function BigInteger(value,sign){this.value=value;this.sign=sign;this.isSmall=false}BigInteger.prototype=Object.create(Integer.prototype);function SmallInteger(value){this.value=value;this.sign=value<0;this.isSmall=true}SmallInteger.prototype=Object.create(Integer.prototype);function NativeBigInt(value){this.value=value}NativeBigInt.prototype=Object.create(Integer.prototype);function isPrecise(n){return-MAX_INT<n&&n<MAX_INT}function smallToArray(n){if(n<1e7)return[n];if(n<1e14)return[n%1e7,Math.floor(n/1e7)];return[n%1e7,Math.floor(n/1e7)%1e7,Math.floor(n/1e14)]}function arrayToSmall(arr){trim(arr);var length=arr.length;if(length<4&&compareAbs(arr,MAX_INT_ARR)<0){switch(length){case 0:return 0;case 1:return arr[0];case 2:return arr[0]+arr[1]*BASE;default:return arr[0]+(arr[1]+arr[2]*BASE)*BASE}}return arr}function trim(v){var i=v.length;while(v[--i]===0);v.length=i+1}function createArray(length){var x=new Array(length);var i=-1;while(++i<length){x[i]=0}return x}function truncate(n){if(n>0)return Math.floor(n);return Math.ceil(n)}function add(a,b){var l_a=a.length,l_b=b.length,r=new Array(l_a),carry=0,base=BASE,sum,i;for(i=0;i<l_b;i++){sum=a[i]+b[i]+carry;carry=sum>=base?1:0;r[i]=sum-carry*base}while(i<l_a){sum=a[i]+carry;carry=sum===base?1:0;r[i++]=sum-carry*base}if(carry>0)r.push(carry);return r}function addAny(a,b){if(a.length>=b.length)return add(a,b);return add(b,a)}function addSmall(a,carry){var l=a.length,r=new Array(l),base=BASE,sum,i;for(i=0;i<l;i++){sum=a[i]-base+carry;carry=Math.floor(sum/base);r[i]=sum-carry*base;carry+=1}while(carry>0){r[i++]=carry%base;carry=Math.floor(carry/base)}return r}BigInteger.prototype.add=function(v){var n=parseValue(v);if(this.sign!==n.sign){return this.subtract(n.negate())}var a=this.value,b=n.value;if(n.isSmall){return new BigInteger(addSmall(a,Math.abs(b)),this.sign)}return new BigInteger(addAny(a,b),this.sign)};BigInteger.prototype.plus=BigInteger.prototype.add;SmallInteger.prototype.add=function(v){var n=parseValue(v);var a=this.value;if(a<0!==n.sign){return this.subtract(n.negate())}var b=n.value;if(n.isSmall){if(isPrecise(a+b))return new SmallInteger(a+b);b=smallToArray(Math.abs(b))}return new BigInteger(addSmall(b,Math.abs(a)),a<0)};SmallInteger.prototype.plus=SmallInteger.prototype.add;NativeBigInt.prototype.add=function(v){return new NativeBigInt(this.value+parseValue(v).value)};NativeBigInt.prototype.plus=NativeBigInt.prototype.add;function subtract(a,b){var a_l=a.length,b_l=b.length,r=new Array(a_l),borrow=0,base=BASE,i,difference;for(i=0;i<b_l;i++){difference=a[i]-borrow-b[i];if(difference<0){difference+=base;borrow=1}else borrow=0;r[i]=difference}for(i=b_l;i<a_l;i++){difference=a[i]-borrow;if(difference<0)difference+=base;else{r[i++]=difference;break}r[i]=difference}for(;i<a_l;i++){r[i]=a[i]}trim(r);return r}function subtractAny(a,b,sign){var value;if(compareAbs(a,b)>=0){value=subtract(a,b)}else{value=subtract(b,a);sign=!sign}value=arrayToSmall(value);if(typeof value==="number"){if(sign)value=-value;return new SmallInteger(value)}return new BigInteger(value,sign)}function subtractSmall(a,b,sign){var l=a.length,r:any=new Array(l),carry=-b,base=BASE,i,difference;for(i=0;i<l;i++){difference=a[i]+carry;carry=Math.floor(difference/base);difference%=base;r[i]=difference<0?difference+base:difference}r=arrayToSmall(r);if(typeof r==="number"){if(sign)r=-r;return new SmallInteger(r)}return new BigInteger(r,sign)}BigInteger.prototype.subtract=function(v){var n=parseValue(v);if(this.sign!==n.sign){return this.add(n.negate())}var a=this.value,b=n.value;if(n.isSmall)return subtractSmall(a,Math.abs(b),this.sign);return subtractAny(a,b,this.sign)};BigInteger.prototype.minus=BigInteger.prototype.subtract;SmallInteger.prototype.subtract=function(v){var n=parseValue(v);var a=this.value;if(a<0!==n.sign){return this.add(n.negate())}var b=n.value;if(n.isSmall){return new SmallInteger(a-b)}return subtractSmall(b,Math.abs(a),a>=0)};SmallInteger.prototype.minus=SmallInteger.prototype.subtract;NativeBigInt.prototype.subtract=function(v){return new NativeBigInt(this.value-parseValue(v).value)};NativeBigInt.prototype.minus=NativeBigInt.prototype.subtract;BigInteger.prototype.negate=function(){return new BigInteger(this.value,!this.sign)};SmallInteger.prototype.negate=function(){var sign=this.sign;var small=new SmallInteger(-this.value);small.sign=!sign;return small};NativeBigInt.prototype.negate=function(){return new NativeBigInt(-this.value)};BigInteger.prototype.abs=function(){return new BigInteger(this.value,false)};SmallInteger.prototype.abs=function(){return new SmallInteger(Math.abs(this.value))};NativeBigInt.prototype.abs=function(){return new NativeBigInt(this.value>=0?this.value:-this.value)};function multiplyLong(a,b){var a_l=a.length,b_l=b.length,l=a_l+b_l,r=createArray(l),base=BASE,product,carry,i,a_i,b_j;for(i=0;i<a_l;++i){a_i=a[i];for(var j=0;j<b_l;++j){b_j=b[j];product=a_i*b_j+r[i+j];carry=Math.floor(product/base);r[i+j]=product-carry*base;r[i+j+1]+=carry}}trim(r);return r}function multiplySmall(a,b){var l=a.length,r=new Array(l),base=BASE,carry=0,product,i;for(i=0;i<l;i++){product=a[i]*b+carry;carry=Math.floor(product/base);r[i]=product-carry*base}while(carry>0){r[i++]=carry%base;carry=Math.floor(carry/base)}return r}function shiftLeft(x,n){var r=[];while(n-- >0)r.push(0);return r.concat(x)}function multiplyKaratsuba(x,y){var n=Math.max(x.length,y.length);if(n<=30)return multiplyLong(x,y);n=Math.ceil(n/2);var b=x.slice(n),a=x.slice(0,n),d=y.slice(n),c=y.slice(0,n);var ac=multiplyKaratsuba(a,c),bd=multiplyKaratsuba(b,d),abcd=multiplyKaratsuba(addAny(a,b),addAny(c,d));var product=addAny(addAny(ac,shiftLeft(subtract(subtract(abcd,ac),bd),n)),shiftLeft(bd,2*n));trim(product);return product}function useKaratsuba(l1,l2){return-.012*l1-.012*l2+15e-6*l1*l2>0}BigInteger.prototype.multiply=function(v){var n=parseValue(v),a=this.value,b=n.value,sign=this.sign!==n.sign,abs;if(n.isSmall){if(b===0)return Integer[0];if(b===1)return this;if(b===-1)return this.negate();abs=Math.abs(b);if(abs<BASE){return new BigInteger(multiplySmall(a,abs),sign)}b=smallToArray(abs)}if(useKaratsuba(a.length,b.length))return new BigInteger(multiplyKaratsuba(a,b),sign);return new BigInteger(multiplyLong(a,b),sign)};BigInteger.prototype.times=BigInteger.prototype.multiply;function multiplySmallAndArray(a,b,sign){if(a<BASE){return new BigInteger(multiplySmall(b,a),sign)}return new BigInteger(multiplyLong(b,smallToArray(a)),sign)}SmallInteger.prototype._multiplyBySmall=function(a){if(isPrecise(a.value*this.value)){return new SmallInteger(a.value*this.value)}return multiplySmallAndArray(Math.abs(a.value),smallToArray(Math.abs(this.value)),this.sign!==a.sign)};BigInteger.prototype._multiplyBySmall=function(a){if(a.value===0)return Integer[0];if(a.value===1)return this;if(a.value===-1)return this.negate();return multiplySmallAndArray(Math.abs(a.value),this.value,this.sign!==a.sign)};SmallInteger.prototype.multiply=function(v){return parseValue(v)._multiplyBySmall(this)};SmallInteger.prototype.times=SmallInteger.prototype.multiply;NativeBigInt.prototype.multiply=function(v){return new NativeBigInt(this.value*parseValue(v).value)};NativeBigInt.prototype.times=NativeBigInt.prototype.multiply;function square(a){var l=a.length,r=createArray(l+l),base=BASE,product,carry,i,a_i,a_j;for(i=0;i<l;i++){a_i=a[i];carry=0-a_i*a_i;for(var j=i;j<l;j++){a_j=a[j];product=2*(a_i*a_j)+r[i+j]+carry;carry=Math.floor(product/base);r[i+j]=product-carry*base}r[i+l]=carry}trim(r);return r}BigInteger.prototype.square=function(){return new BigInteger(square(this.value),false)};SmallInteger.prototype.square=function(){var value=this.value*this.value;if(isPrecise(value))return new SmallInteger(value);return new BigInteger(square(smallToArray(Math.abs(this.value))),false)};NativeBigInt.prototype.square=function(v){return new NativeBigInt(this.value*this.value)};function divMod1(a,b){var a_l=a.length,b_l=b.length,base=BASE,result=createArray(b.length),divisorMostSignificantDigit=b[b_l-1],lambda=Math.ceil(base/(2*divisorMostSignificantDigit)),remainder:any=multiplySmall(a,lambda),divisor=multiplySmall(b,lambda),quotientDigit,shift,carry,borrow,i,l,q;if(remainder.length<=a_l)remainder.push(0);divisor.push(0);divisorMostSignificantDigit=divisor[b_l-1];for(shift=a_l-b_l;shift>=0;shift--){quotientDigit=base-1;if(remainder[shift+b_l]!==divisorMostSignificantDigit){quotientDigit=Math.floor((remainder[shift+b_l]*base+remainder[shift+b_l-1])/divisorMostSignificantDigit)}carry=0;borrow=0;l=divisor.length;for(i=0;i<l;i++){carry+=quotientDigit*divisor[i];q=Math.floor(carry/base);borrow+=remainder[shift+i]-(carry-q*base);carry=q;if(borrow<0){remainder[shift+i]=borrow+base;borrow=-1}else{remainder[shift+i]=borrow;borrow=0}}while(borrow!==0){quotientDigit-=1;carry=0;for(i=0;i<l;i++){carry+=remainder[shift+i]-base+divisor[i];if(carry<0){remainder[shift+i]=carry+base;carry=0}else{remainder[shift+i]=carry;carry=1}}borrow+=carry}result[shift]=quotientDigit}remainder=divModSmall(remainder,lambda)[0];return[arrayToSmall(result),arrayToSmall(remainder)]}function divMod2(a,b){var a_l=a.length,b_l=b.length,result=[],part=[],base=BASE,guess,xlen,highx,highy,check;while(a_l){part.unshift(a[--a_l]);trim(part);if(compareAbs(part,b)<0){result.push(0);continue}xlen=part.length;highx=part[xlen-1]*base+part[xlen-2];highy=b[b_l-1]*base+b[b_l-2];if(xlen>b_l){highx=(highx+1)*base}guess=Math.ceil(highx/highy);do{check=multiplySmall(b,guess);if(compareAbs(check,part)<=0)break;guess--}while(guess);result.push(guess);part=subtract(part,check)}result.reverse();return[arrayToSmall(result),arrayToSmall(part)]}function divModSmall(value,lambda){var length=value.length,quotient=createArray(length),base=BASE,i,q,remainder,divisor;remainder=0;for(i=length-1;i>=0;--i){divisor=remainder*base+value[i];q=truncate(divisor/lambda);remainder=divisor-q*lambda;quotient[i]=q|0}return[quotient,remainder|0]}function divModAny(self,v){var value,n=parseValue(v);if(supportsNativeBigInt){return[new NativeBigInt(self.value/n.value),new NativeBigInt(self.value%n.value)]}var a=self.value,b=n.value;var quotient;if(b===0)throw new Error("Cannot divide by zero");if(self.isSmall){if(n.isSmall){return[new SmallInteger(truncate(a/b)),new SmallInteger(a%b)]}return[Integer[0],self]}if(n.isSmall){if(b===1)return[self,Integer[0]];if(b==-1)return[self.negate(),Integer[0]];var abs=Math.abs(b);if(abs<BASE){value=divModSmall(a,abs);quotient=arrayToSmall(value[0]);var remainder=value[1];if(self.sign)remainder=-remainder;if(typeof quotient==="number"){if(self.sign!==n.sign)quotient=-quotient;return[new SmallInteger(quotient),new SmallInteger(remainder)]}return[new BigInteger(quotient,self.sign!==n.sign),new SmallInteger(remainder)]}b=smallToArray(abs)}var comparison=compareAbs(a,b);if(comparison===-1)return[Integer[0],self];if(comparison===0)return[Integer[self.sign===n.sign?1:-1],Integer[0]];if(a.length+b.length<=200)value=divMod1(a,b);else value=divMod2(a,b);quotient=value[0];var qSign=self.sign!==n.sign,mod=value[1],mSign=self.sign;if(typeof quotient==="number"){if(qSign)quotient=-quotient;quotient=new SmallInteger(quotient)}else quotient=new BigInteger(quotient,qSign);if(typeof mod==="number"){if(mSign)mod=-mod;mod=new SmallInteger(mod)}else mod=new BigInteger(mod,mSign);return[quotient,mod]}BigInteger.prototype.divmod=function(v){var result=divModAny(this,v);return{quotient:result[0],remainder:result[1]}};NativeBigInt.prototype.divmod=SmallInteger.prototype.divmod=BigInteger.prototype.divmod;BigInteger.prototype.divide=function(v){return divModAny(this,v)[0]};NativeBigInt.prototype.over=NativeBigInt.prototype.divide=function(v){return new NativeBigInt(this.value/parseValue(v).value)};SmallInteger.prototype.over=SmallInteger.prototype.divide=BigInteger.prototype.over=BigInteger.prototype.divide;BigInteger.prototype.mod=function(v){return divModAny(this,v)[1]};NativeBigInt.prototype.mod=NativeBigInt.prototype.remainder=function(v){return new NativeBigInt(this.value%parseValue(v).value)};SmallInteger.prototype.remainder=SmallInteger.prototype.mod=BigInteger.prototype.remainder=BigInteger.prototype.mod;BigInteger.prototype.pow=function(v){var n=parseValue(v),a=this.value,b:any=n.value,value,x,y;if(b===0)return Integer[1];if(a===0)return Integer[0];if(a===1)return Integer[1];if(a===-1)return n.isEven()?Integer[1]:Integer[-1];if(n.sign){return Integer[0]}if(!n.isSmall)throw new Error("The exponent "+n.toString()+" is too large.");if(this.isSmall){if(isPrecise(value=Math.pow(a,b)))return new SmallInteger(truncate(value))}x=this;y=Integer[1];while(true){if((x & -x&1)===1){y=y.times(x);--b}if(b===0)break;b/=2;x=x.square()}return y};SmallInteger.prototype.pow=BigInteger.prototype.pow;NativeBigInt.prototype.pow=function(v){var n=parseValue(v);var a=this.value,b=n.value;var _0=BigInt(0),_1=BigInt(1),_2=BigInt(2);if(b===_0)return Integer[1];if(a===_0)return Integer[0];if(a===_1)return Integer[1];if(a===BigInt(-1))return n.isEven()?Integer[1]:Integer[-1];if(n.isNegative())return new NativeBigInt(_0);var x=this;var y=Integer[1];while(true){if((b&_1)===_1){y=y.times(x);--b}if(b===_0)break;b/=_2;x=x.square()}return y};BigInteger.prototype.modPow=function(exp,mod){exp=parseValue(exp);mod=parseValue(mod);if(mod.isZero())throw new Error("Cannot take modPow with modulus 0");var r=Integer[1],base=this.mod(mod);while(exp.isPositive()){if(base.isZero())return Integer[0];if(exp.isOdd())r=r.multiply(base).mod(mod);exp=exp.divide(2);base=base.square().mod(mod)}return r};NativeBigInt.prototype.modPow=SmallInteger.prototype.modPow=BigInteger.prototype.modPow;function compareAbs(a,b){if(a.length!==b.length){return a.length>b.length?1:-1}for(var i=a.length-1;i>=0;i--){if(a[i]!==b[i])return a[i]>b[i]?1:-1}return 0}BigInteger.prototype.compareAbs=function(v){var n=parseValue(v),a=this.value,b=n.value;if(n.isSmall)return 1;return compareAbs(a,b)};SmallInteger.prototype.compareAbs=function(v){var n=parseValue(v),a=Math.abs(this.value),b=n.value;if(n.isSmall){b=Math.abs(b);return a===b?0:a>b?1:-1}return-1};NativeBigInt.prototype.compareAbs=function(v){var a=this.value;var b=parseValue(v).value;a=a>=0?a:-a;b=b>=0?b:-b;return a===b?0:a>b?1:-1};BigInteger.prototype.compare=function(v){if(v===Infinity){return-1}if(v===-Infinity){return 1}var n=parseValue(v),a=this.value,b=n.value;if(this.sign!==n.sign){return n.sign?1:-1}if(n.isSmall){return this.sign?-1:1}return compareAbs(a,b)*(this.sign?-1:1)};BigInteger.prototype.compareTo=BigInteger.prototype.compare;SmallInteger.prototype.compare=function(v){if(v===Infinity){return-1}if(v===-Infinity){return 1}var n=parseValue(v),a=this.value,b=n.value;if(n.isSmall){return a==b?0:a>b?1:-1}if(a<0!==n.sign){return a<0?-1:1}return a<0?1:-1};SmallInteger.prototype.compareTo=SmallInteger.prototype.compare;NativeBigInt.prototype.compare=function(v){if(v===Infinity){return-1}if(v===-Infinity){return 1}var a=this.value;var b=parseValue(v).value;return a===b?0:a>b?1:-1};NativeBigInt.prototype.compareTo=NativeBigInt.prototype.compare;BigInteger.prototype.equals=function(v){return this.compare(v)===0};NativeBigInt.prototype.eq=NativeBigInt.prototype.equals=SmallInteger.prototype.eq=SmallInteger.prototype.equals=BigInteger.prototype.eq=BigInteger.prototype.equals;BigInteger.prototype.notEquals=function(v){return this.compare(v)!==0};NativeBigInt.prototype.neq=NativeBigInt.prototype.notEquals=SmallInteger.prototype.neq=SmallInteger.prototype.notEquals=BigInteger.prototype.neq=BigInteger.prototype.notEquals;BigInteger.prototype.greater=function(v){return this.compare(v)>0};NativeBigInt.prototype.gt=NativeBigInt.prototype.greater=SmallInteger.prototype.gt=SmallInteger.prototype.greater=BigInteger.prototype.gt=BigInteger.prototype.greater;BigInteger.prototype.lesser=function(v){return this.compare(v)<0};NativeBigInt.prototype.lt=NativeBigInt.prototype.lesser=SmallInteger.prototype.lt=SmallInteger.prototype.lesser=BigInteger.prototype.lt=BigInteger.prototype.lesser;BigInteger.prototype.greaterOrEquals=function(v){return this.compare(v)>=0};NativeBigInt.prototype.geq=NativeBigInt.prototype.greaterOrEquals=SmallInteger.prototype.geq=SmallInteger.prototype.greaterOrEquals=BigInteger.prototype.geq=BigInteger.prototype.greaterOrEquals;BigInteger.prototype.lesserOrEquals=function(v){return this.compare(v)<=0};NativeBigInt.prototype.leq=NativeBigInt.prototype.lesserOrEquals=SmallInteger.prototype.leq=SmallInteger.prototype.lesserOrEquals=BigInteger.prototype.leq=BigInteger.prototype.lesserOrEquals;BigInteger.prototype.isEven=function(){return(this.value[0]&1)===0};SmallInteger.prototype.isEven=function(){return(this.value&1)===0};NativeBigInt.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)};BigInteger.prototype.isOdd=function(){return(this.value[0]&1)===1};SmallInteger.prototype.isOdd=function(){return(this.value&1)===1};NativeBigInt.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)};BigInteger.prototype.isPositive=function(){return!this.sign};SmallInteger.prototype.isPositive=function(){return this.value>0};NativeBigInt.prototype.isPositive=SmallInteger.prototype.isPositive;BigInteger.prototype.isNegative=function(){return this.sign};SmallInteger.prototype.isNegative=function(){return this.value<0};NativeBigInt.prototype.isNegative=SmallInteger.prototype.isNegative;BigInteger.prototype.isUnit=function(){return false};SmallInteger.prototype.isUnit=function(){return Math.abs(this.value)===1};NativeBigInt.prototype.isUnit=function(){return this.abs().value===BigInt(1)};BigInteger.prototype.isZero=function(){return false};SmallInteger.prototype.isZero=function(){return this.value===0};NativeBigInt.prototype.isZero=function(){return this.value===BigInt(0)};BigInteger.prototype.isDivisibleBy=function(v){var n=parseValue(v);if(n.isZero())return false;if(n.isUnit())return true;if(n.compareAbs(2)===0)return this.isEven();return this.mod(n).isZero()};NativeBigInt.prototype.isDivisibleBy=SmallInteger.prototype.isDivisibleBy=BigInteger.prototype.isDivisibleBy;function isBasicPrime(v){var n=v.abs();if(n.isUnit())return false;if(n.equals(2)||n.equals(3)||n.equals(5))return true;if(n.isEven()||n.isDivisibleBy(3)||n.isDivisibleBy(5))return false;if(n.lesser(49))return true}function millerRabinTest(n,a){var nPrev=n.prev(),b=nPrev,r=0,d,t,i,x;while(b.isEven())b=b.divide(2),r++;next:for(i=0;i<a.length;i++){if(n.lesser(a[i]))continue;x=bigInt(a[i]).modPow(b,n);if(x.isUnit()||x.equals(nPrev))continue;for(d=r-1;d!=0;d--){x=x.square().mod(n);if(x.isUnit())return false;if(x.equals(nPrev))continue next}return false}return true}BigInteger.prototype.isPrime=function(strict){var isPrime=isBasicPrime(this);if(isPrime!==undefined)return isPrime;var n=this.abs();var bits=n.bitLength();if(bits<=64)return millerRabinTest(n,[2,3,5,7,11,13,17,19,23,29,31,37]);var logN=Math.log(2)*bits.toJSNumber();var t=Math.ceil(strict===true?2*Math.pow(logN,2):logN);for(var a=[],i=0;i<t;i++){a.push(bigInt(i+2))}return millerRabinTest(n,a)};NativeBigInt.prototype.isPrime=SmallInteger.prototype.isPrime=BigInteger.prototype.isPrime;BigInteger.prototype.isProbablePrime=function(iterations){var isPrime=isBasicPrime(this);if(isPrime!==undefined)return isPrime;var n=this.abs();var t=iterations===undefined?5:iterations;for(var a=[],i=0;i<t;i++){a.push(bigInt.randBetween(2,n.minus(2)))}return millerRabinTest(n,a)};NativeBigInt.prototype.isProbablePrime=SmallInteger.prototype.isProbablePrime=BigInteger.prototype.isProbablePrime;
BigInteger.prototype.modInv=function(n){var t=bigInt.zero,newT=bigInt.one,r=parseValue(n),newR=this.abs(),q,lastT,lastR;while(!newR.isZero()){q=r.divide(newR);lastT=t;lastR=r;t=newT;r=newR;newT=lastT.subtract(q.multiply(newT));newR=lastR.subtract(q.multiply(newR))}if(!r.isUnit())throw new Error(this.toString()+" and "+n.toString()+" are not co-prime");if(t.compare(0)===-1){t=t.add(n)}if(this.isNegative()){return t.negate()}return t};NativeBigInt.prototype.modInv=SmallInteger.prototype.modInv=BigInteger.prototype.modInv;BigInteger.prototype.next=function(){var value=this.value;if(this.sign){return subtractSmall(value,1,this.sign)}return new BigInteger(addSmall(value,1),this.sign)};SmallInteger.prototype.next=function(){var value=this.value;if(value+1<MAX_INT)return new SmallInteger(value+1);return new BigInteger(MAX_INT_ARR,false)};NativeBigInt.prototype.next=function(){return new NativeBigInt(this.value+BigInt(1))};BigInteger.prototype.prev=function(){var value=this.value;if(this.sign){return new BigInteger(addSmall(value,1),true)}return subtractSmall(value,1,this.sign)};SmallInteger.prototype.prev=function(){var value=this.value;if(value-1>-MAX_INT)return new SmallInteger(value-1);return new BigInteger(MAX_INT_ARR,true)};NativeBigInt.prototype.prev=function(){return new NativeBigInt(this.value-BigInt(1))};var powersOfTwo=[1];while(2*powersOfTwo[powersOfTwo.length-1]<=BASE)powersOfTwo.push(2*powersOfTwo[powersOfTwo.length-1]);var powers2Length=powersOfTwo.length,highestPower2=powersOfTwo[powers2Length-1];function shift_isSmall(n){return Math.abs(n)<=BASE}BigInteger.prototype.shiftLeft=function(v){var n=parseValue(v).toJSNumber();if(!shift_isSmall(n)){throw new Error(String(n)+" is too large for shifting.")}if(n<0)return this.shiftRight(-n);var result=this;if(result.isZero())return result;while(n>=powers2Length){result=result.multiply(highestPower2);n-=powers2Length-1}return result.multiply(powersOfTwo[n])};NativeBigInt.prototype.shiftLeft=SmallInteger.prototype.shiftLeft=BigInteger.prototype.shiftLeft;BigInteger.prototype.shiftRight=function(v){var remQuo;var n=parseValue(v).toJSNumber();if(!shift_isSmall(n)){throw new Error(String(n)+" is too large for shifting.")}if(n<0)return this.shiftLeft(-n);var result=this;while(n>=powers2Length){if(result.isZero()||result.isNegative()&&result.isUnit())return result;remQuo=divModAny(result,highestPower2);result=remQuo[1].isNegative()?remQuo[0].prev():remQuo[0];n-=powers2Length-1}remQuo=divModAny(result,powersOfTwo[n]);return remQuo[1].isNegative()?remQuo[0].prev():remQuo[0]};NativeBigInt.prototype.shiftRight=SmallInteger.prototype.shiftRight=BigInteger.prototype.shiftRight;function bitwise(x,y,fn){y=parseValue(y);var xSign=x.isNegative(),ySign=y.isNegative();var xRem=xSign?x.not():x,yRem=ySign?y.not():y;var xDigit=0,yDigit=0;var xDivMod=null,yDivMod=null;var result=[];while(!xRem.isZero()||!yRem.isZero()){xDivMod=divModAny(xRem,highestPower2);xDigit=xDivMod[1].toJSNumber();if(xSign){xDigit=highestPower2-1-xDigit}yDivMod=divModAny(yRem,highestPower2);yDigit=yDivMod[1].toJSNumber();if(ySign){yDigit=highestPower2-1-yDigit}xRem=xDivMod[0];yRem=yDivMod[0];result.push(fn(xDigit,yDigit))}var sum=fn(xSign?1:0,ySign?1:0)!==0?bigInt(-1):bigInt(0);for(var i=result.length-1;i>=0;i-=1){sum=sum.multiply(highestPower2).add(bigInt(result[i]))}return sum}BigInteger.prototype.not=function(){return this.negate().prev()};NativeBigInt.prototype.not=SmallInteger.prototype.not=BigInteger.prototype.not;BigInteger.prototype.and=function(n){return bitwise(this,n,function(a,b){return a&b})};NativeBigInt.prototype.and=SmallInteger.prototype.and=BigInteger.prototype.and;BigInteger.prototype.or=function(n){return bitwise(this,n,function(a,b){return a|b})};NativeBigInt.prototype.or=SmallInteger.prototype.or=BigInteger.prototype.or;BigInteger.prototype.xor=function(n){return bitwise(this,n,function(a,b){return a^b})};NativeBigInt.prototype.xor=SmallInteger.prototype.xor=BigInteger.prototype.xor;var LOBMASK_I=1<<30,LOBMASK_BI=(BASE&-BASE)*(BASE&-BASE)|LOBMASK_I;function roughLOB(n){var v=n.value,x:any=typeof v==="number"?v|LOBMASK_I:typeof v==="bigint"?v|BigInt(LOBMASK_I):v[0]+v[1]*BASE|LOBMASK_BI;return x&-x}function integerLogarithm(value,base){if(base.compareTo(value)<=0){var tmp=integerLogarithm(value,base.square(base));var p=tmp.p;var e=tmp.e;var t=p.multiply(base);return t.compareTo(value)<=0?{p:t,e:e*2+1}:{p:p,e:e*2}}return{p:bigInt(1),e:0}}BigInteger.prototype.bitLength=function(){var n=this;if(n.compareTo(bigInt(0))<0){n=n.negate().subtract(bigInt(1))}if(n.compareTo(bigInt(0))===0){return bigInt(0)}return bigInt(integerLogarithm(n,bigInt(2)).e).add(bigInt(1))};NativeBigInt.prototype.bitLength=SmallInteger.prototype.bitLength=BigInteger.prototype.bitLength;function max(a,b){a=parseValue(a);b=parseValue(b);return a.greater(b)?a:b}function min(a,b){a=parseValue(a);b=parseValue(b);return a.lesser(b)?a:b}function gcd(a,b){a=parseValue(a).abs();b=parseValue(b).abs();if(a.equals(b))return a;if(a.isZero())return b;if(b.isZero())return a;var c=Integer[1],d,t;while(a.isEven()&&b.isEven()){d=min(roughLOB(a),roughLOB(b));a=a.divide(d);b=b.divide(d);c=c.multiply(d)}while(a.isEven()){a=a.divide(roughLOB(a))}do{while(b.isEven()){b=b.divide(roughLOB(b))}if(a.greater(b)){t=b;b=a;a=t}b=b.subtract(a)}while(!b.isZero());return c.isUnit()?a:a.multiply(c)}function lcm(a,b){a=parseValue(a).abs();b=parseValue(b).abs();return a.divide(gcd(a,b)).multiply(b)}function randBetween(a,b){a=parseValue(a);b=parseValue(b);var low=min(a,b),high=max(a,b);var range=high.subtract(low).add(1);if(range.isSmall)return low.add(Math.floor(Math.random()*range));var digits=toBase(range,BASE).value;var result=[],restricted=true;for(var i=0;i<digits.length;i++){var top=restricted?digits[i]:BASE;var digit=truncate(Math.random()*top);result.push(digit);if(digit<top)restricted=false}return low.add(Integer.fromArray(result,BASE,false))}var parseBase=function(text,base,alphabet,caseSensitive){alphabet=alphabet||DEFAULT_ALPHABET;text=String(text);if(!caseSensitive){text=text.toLowerCase();alphabet=alphabet.toLowerCase()}var length=text.length;var i;var absBase=Math.abs(base);var alphabetValues={};for(i=0;i<alphabet.length;i++){alphabetValues[alphabet[i]]=i}for(i=0;i<length;i++){var c=text[i];if(c==="-")continue;if(c in alphabetValues){if(alphabetValues[c]>=absBase){if(c==="1"&&absBase===1)continue;throw new Error(c+" is not a valid digit in base "+base+".")}}}base=parseValue(base);var digits=[];var isNegative=text[0]==="-";for(i=isNegative?1:0;i<text.length;i++){var c=text[i];if(c in alphabetValues)digits.push(parseValue(alphabetValues[c]));else if(c==="<"){var start=i;do{i++}while(text[i]!==">"&&i<text.length);digits.push(parseValue(text.slice(start+1,i)))}else throw new Error(c+" is not a valid character")}return parseBaseFromArray(digits,base,isNegative)};function parseBaseFromArray(digits,base,isNegative){var val=Integer[0],pow=Integer[1],i;for(i=digits.length-1;i>=0;i--){val=val.add(digits[i].times(pow));pow=pow.times(base)}return isNegative?val.negate():val}function stringify(digit,alphabet){alphabet=alphabet||DEFAULT_ALPHABET;if(digit<alphabet.length){return alphabet[digit]}return"<"+digit+">"}function toBase(n,base){base=bigInt(base);if(base.isZero()){if(n.isZero())return{value:[0],isNegative:false};throw new Error("Cannot convert nonzero numbers to base 0.")}if(base.equals(-1)){if(n.isZero())return{value:[0],isNegative:false};if(n.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-n.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:false};var arr=Array.apply(null,Array(n.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);arr.unshift([1]);return{value:[].concat.apply([],arr),isNegative:false}}var neg=false;if(n.isNegative()&&base.isPositive()){neg=true;n=n.abs()}if(base.isUnit()){if(n.isZero())return{value:[0],isNegative:false};return{value:Array.apply(null,Array(n.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:neg}}var out=[];var left=n,divmod;while(left.isNegative()||left.compareAbs(base)>=0){divmod=left.divmod(base);left=divmod.quotient;var digit=divmod.remainder;if(digit.isNegative()){digit=base.minus(digit).abs();left=left.next()}out.push(digit.toJSNumber())}out.push(left.toJSNumber());return{value:out.reverse(),isNegative:neg}}function toBaseString(n,base,alphabet){var arr=toBase(n,base);return(arr.isNegative?"-":"")+arr.value.map(function(x){return stringify(x,alphabet)}).join("")}BigInteger.prototype.toArray=function(radix){return toBase(this,radix)};SmallInteger.prototype.toArray=function(radix){return toBase(this,radix)};NativeBigInt.prototype.toArray=function(radix){return toBase(this,radix)};BigInteger.prototype.toString=function(radix,alphabet){if(radix===undefined)radix=10;if(radix!==10)return toBaseString(this,radix,alphabet);var v=this.value,l=v.length,str=String(v[--l]),zeros="0000000",digit;while(--l>=0){digit=String(v[l]);str+=zeros.slice(digit.length)+digit}var sign=this.sign?"-":"";return sign+str};SmallInteger.prototype.toString=function(radix,alphabet){if(radix===undefined)radix=10;if(radix!=10)return toBaseString(this,radix,alphabet);return String(this.value)};NativeBigInt.prototype.toString=SmallInteger.prototype.toString;NativeBigInt.prototype.toJSON=BigInteger.prototype.toJSON=SmallInteger.prototype.toJSON=function(){return this.toString()};BigInteger.prototype.valueOf=function(){return parseInt(this.toString(),10)};BigInteger.prototype.toJSNumber=BigInteger.prototype.valueOf;SmallInteger.prototype.valueOf=function(){return this.value};SmallInteger.prototype.toJSNumber=SmallInteger.prototype.valueOf;NativeBigInt.prototype.valueOf=NativeBigInt.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};function parseStringValue(v){if(isPrecise(+v)){var x=+v;if(x===truncate(x))return supportsNativeBigInt?new NativeBigInt(BigInt(x)):new SmallInteger(x);throw new Error("Invalid integer: "+v)}var sign=v[0]==="-";if(sign)v=v.slice(1);var split=v.split(/e/i);if(split.length>2)throw new Error("Invalid integer: "+split.join("e"));if(split.length===2){var exp=split[1];if(exp[0]==="+")exp=exp.slice(1);exp=+exp;if(exp!==truncate(exp)||!isPrecise(exp))throw new Error("Invalid integer: "+exp+" is not a valid exponent.");var text=split[0];var decimalPlace=text.indexOf(".");if(decimalPlace>=0){exp-=text.length-decimalPlace-1;text=text.slice(0,decimalPlace)+text.slice(decimalPlace+1)}if(exp<0)throw new Error("Cannot include negative exponent part for integers");text+=new Array(exp+1).join("0");v=text}var isValid=/^([0-9][0-9]*)$/.test(v);if(!isValid)throw new Error("Invalid integer: "+v);if(supportsNativeBigInt){return new NativeBigInt(BigInt(sign?"-"+v:v))}var r=[],max=v.length,l=LOG_BASE,min=max-l;while(max>0){r.push(+v.slice(min,max));min-=l;if(min<0)min=0;max-=l}trim(r);return new BigInteger(r,sign)}function parseNumberValue(v){if(supportsNativeBigInt){return new NativeBigInt(BigInt(v))}if(isPrecise(v)){if(v!==truncate(v))throw new Error(v+" is not an integer.");return new SmallInteger(v)}return parseStringValue(v.toString())}function parseValue(v){if(typeof v==="number"){return parseNumberValue(v)}if(typeof v==="string"){return parseStringValue(v)}if(typeof v==="bigint"){return new NativeBigInt(v)}return v}for(var i=0;i<1e3;i++){Integer[i]=parseValue(i);if(i>0)Integer[-i]=parseValue(-i)}Integer.one=Integer[1];Integer.zero=Integer[0];Integer.minusOne=Integer[-1];Integer.max=max;Integer.min=min;Integer.gcd=gcd;Integer.lcm=lcm;Integer.isInstance=function(x){return x instanceof BigInteger||x instanceof SmallInteger||x instanceof NativeBigInt};Integer.randBetween=randBetween;Integer.fromArray=function(digits,base,isNegative){return parseBaseFromArray(digits.map(parseValue),parseValue(base||10),isNegative)};return Integer}();if(typeof module!=="undefined"&&module.hasOwnProperty("exports")){module.exports=bigInt}
const main=()=>{
  let n=tn()
  let l=[2,1]
  for(let i=0;i<n-1;i++){
    l.push(bigInt(l[i]).add(l[i+1]))
  }
  to(l[l.length-1].toString())
}
main()


import * as fs from "fs";

const input = fs.readFileSync("/dev/stdin", "utf8");
const N = +input;

const L: number[] = Array(N + 1);

if (N === 1) {
  L[N] = 1;
} else {
  L[0] = 2;
  L[1] = 1;

  for (let i = 2; i <= N; i++) {
    L[i] = L[i - 1] + L[i - 2];
  }
}

console.log(L[N]);


import * as fs from "fs";

const input = fs.readFileSync("/dev/stdin", "utf8");
const a = +input;

console.log(lucasNumber(a));

function lucasNumber(n: number): number {
  if (n === 0) {
    return 2;
  } else if (n === 1) {
    return 1;
  } else {
    return lucasNumber(n - 1) + lucasNumber(n - 2);
  }
}


import * as readline from "readline";

/* ここに処理を書く */
const main = (args: any[]) => {
  const N = args[0];
  const L0 = 2,
    L1 = 1;

  switch (N) {
    case 0:
      console.log(L0);
      break;
    case 1:
      console.log(L1);
      break;
    default:
      let l1 = L1,
        l2 = L0;
      let li;
      for (let i = 2; i <= N; i++) {
        li = l1 + l2;
        l2 = l1;
        l1 = li;
      }
      console.log(li);
  }
  return;
};

/* 標準入力処理 */
const stdin = (main: Function) => {
  const args: any[] = [];
  const reader = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  reader.on("close", function() {
    main(args);
  });
  reader.on("line", function(line: any) {
    if (line === "") {
      reader.close();
    }
    line.split(" ").forEach((arg: any) => {
      args.push(isNaN(arg) ? arg : Number(arg));
    });
  });
};
/* 実行 */
stdin(main);


h, w = map(int, input().split())
a = ''.join([input() for _ in range(h)])
c = ''
b = ''

for i in range(h):
    s = a[i*w:-~i*w]
    if s != '.' * w:
        b += s

nh = len(b) // w
for j in range(w):
    s = b[j::w]
    if s != '.' * nh:
        c += s

nw = len(c) // nh
for i in range(nh):
    print(c[i::nh])


h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
b=[x for x in a if "#" in x]
c=zip(*[y for y in zip(*b) if "#" in y])
for d in c:
    print("".join(d))


h, w = map(int, input().split())
# print(h, w)

# matrix = []
# for _ in range(h):
#     row = input()
#     if '#' not in row:
#         continue
#     else:
#         matrix.append(row)

# print(matrix)

matrix = [input() for _ in range(h)]
# print(matrix)
matrix = [row for row in matrix if '#' in row]
# print(matrix)

T_matrix = [col for col in zip(*matrix) if '#' in col]
# print(T_matrix)

# T_matrix = []

# for col in zip(*matrix):
#     if '#' not in col:
#         continue
#     else:
#         T_matrix.append(col)

# for row in matrix:
#     print(row)
# for row in zip(*T_matrix):
#     print(''.join(row))

print(*(''.join(row) for row in zip(*T_matrix)), sep='\n')


h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, w)]
list_tmp = []
for i in range(0, w):
    for j in range(0, h):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, h):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))


h,w=map(int,input().split())
A=[list(input()) for i in range(w)]
answ=[]
ansh=[]
for i in range(w):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(h):
  if not all([A[i][j]=="." for i in range(w)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("\n")


h, w = map(int,input().split())

A = [list(input()) for _ in range(h)]

row = [False] * h
col = [False] * w

for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(A[i][j], end = '')


import java.io.*;
import java.util.*;

public class Main {
  private static List<String> solve(int h, int w, char[][] am) {
    boolean[] has1 = new boolean[h];
    boolean[] has2 = new boolean[w];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        has1[i] |= am[i][j] == '#';
        has2[j] |= am[i][j] == '#';
      }
    }
    List<String> answers = new ArrayList<>();
    for (int i = 0; i < h; i++) {
      if (has1[i]) {
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < w; j++) {
          if (has2[j]) {
            sb.append(am[i][j]);
          }
        }
        answers.add(sb.toString());
      }
    }
    return answers;
  }

  private static void execute(ContestReader reader, PrintWriter out) {
    int h = reader.nextInt();
    int w = reader.nextInt();
    char[][] am = reader.nextCharArray(h);
    for (String line : solve(h, w, am)) {
      out.println(line);
    }
  }

  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;

  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }

  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }

  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }

  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }

  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }

  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }

  public char[] nextCharArray() {
    return next().toCharArray();
  }

  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }

  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }

  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }

  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] line1 = br.readLine().split(" ");
    int h = Integer.parseInt(line1[0]);
    int w = Integer.parseInt(line1[1]);

    char[][] c = new char[h][w];
    boolean[] viewLine = new boolean[h];
    boolean[] viewColumn = new boolean[w];

    for(int i=0; i<h; i++){
      c[i] = br.readLine().toCharArray();
    }
    for (int i=0; i<h; i++){
      for (int j=0; j<w; j++){
        if(c[i][j] == '#'){
          viewLine[i] = true;
          viewColumn[j] = true;
        }
      }
    }
    StringBuilder result =  new StringBuilder();
    for (int i=0; i<h; i++){
      if (!viewLine[i]) continue;
      for (int j=0; j<w; j++){
        if (viewColumn[j]) {
          result.append(c[i][j]);
        }
      }
      result.append("\n");
    }
    System.out.println(result.toString());
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        final byte h = Byte.parseByte(tok.nextToken());
        final byte w = Byte.parseByte(tok.nextToken());

        char[][] mat = new char[h][w];
        boolean[] row = new boolean[h];
        boolean[] col = new boolean[w];

        for (byte i = 0; i < h; i++) {
            String str = br.readLine();
            for (byte j = 0; j < w; j++) {
                char c = str.charAt(j);
                mat[i][j] = c;
                if (c == '#') {
                    row[i] = true;
                    col[j] = true;
                }
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        for (byte i = 0; i < h; i++) {
            if (!row[i]) continue;
            for (byte j = 0; j < w; j++) {
                if (col[j]) {
                    out.print(mat[i][j]);
                }
            }
            out.print("\n");
        }
        out.flush();
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];
        int acount=0;

        for(int i=0; i<h; i++){
            String  s = sc.next();
            for(int j=0; j<w; j++){
                c[i][j] = s.charAt(j);
            }
        }

        for(int i=0; i<h; i++){
            int flg = 0;
            for(int j=0; j<w; j++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                for(int j=0; j<w; j++){
                    c[i][j]='0';
                }
            }else{
                acount++;
            }
        }

        for(int j=0; j<w; j++){
            int flg = 0;
            for(int i=0; i<h; i++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                for(int i=0; i<h; i++){
                    c[i][j]='0';
                }
            }
        }

        for(int i=0; i<h; i++){
            int a=0;
            for(int j=0; j<w; j++){
                if(c[i][j]!='0'){
                    System.out.print(c[i][j]);
                    a++;
                }
            }
            if(a==acount){
                System.out.println();
            }
            //System.out.println(a);
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];
        int icount=h;

        for(int i=0; i<h; i++){
            String  s = sc.next();
            for(int j=0; j<w; j++){
                c[i][j] = s.charAt(j);
            }
        }

        for(int i=0; i<h; i++){
            int flg = 0;
            for(int j=0; j<w; j++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                icount--;
                for(int j=0; j<w; j++){
                    c[i][j]='0';
                }
            }
        }

        for(int j=0; j<w; j++){
            int flg = 0;
            for(int i=0; i<h; i++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                for(int i=0; i<h; i++){
                    c[i][j]='0';
                }
            }
        }

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(c[i][j]!='0'){
                    System.out.print(c[i][j]);
                    if(j==icount-1){
                        System.out.println();
                    }
                }
            }

        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];

        for(int i=0; i<h; i++){
            String  s = sc.next();
            for(int j=0; j<w; j++){
                c[i][j] = s.charAt(j);
            }
        }

        for(int i=0; i<h; i++){
            int flg = 0;
            for(int j=0; j<w; j++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                for(int j=0; j<w; j++){
                    c[i][j]='0';
                }
            }
        }

        for(int j=0; j<w; j++){
            int flg = 0;
            for(int i=0; i<h; i++){
                if(c[i][j]=='#'){
                    flg = 1;
                }
            }
            if(flg == 0){
                for(int i=0; i<h; i++){
                    c[i][j]='0';
                }
            }
        }

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(c[i][j]!='0'){
                    System.out.print(c[i][j]);
                    if(j==w-1){
                        System.out.println();
                    }
                }
            }

        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
string mat[110];
bool f[110], c[110];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i ++)
        cin >> mat[i];
    for(int i = 0; i < n; i ++)
    {
        bool flag = true;
        for(int j = 0; j < m; j ++)
            if(mat[i][j] == '#')
            {
                flag = false;
                break;
            }
        f[i] = flag;
    }
    for(int j = 0; j < m; j ++)
    {
        bool flag = true;
        for(int i = 0; i < n; i ++)
            if(mat[i][j] == '#')
            {
                flag = false;
                break;
            }
        c[j] = flag;
    }
    for(int i = 0; i < n; i ++)
    {
        if(f[i])
            continue;
        for(int j = 0; j < m; j ++)
            if(!c[j])
                cout << mat[i][j];
        cout << '\n';
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;const int N=110;bool book1[N];bool book2[N];
char mde[N][N];int n;int m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",mde[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)book1[i]|=(mde[i][j]=='#'),book2[j]|=(mde[i][j]=='#');
	for(int i=1;i<=n;i++)
		{
			if(book1[i]==false)continue;
			for(int j=1;j<=m;j++)if(book2[j])printf("%c",mde[i][j]);printf("\n");
		}return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int h,w;
  cin >> h>>w;
  vector<string> a;
  for (int i = 0; i < h; ++i) {
    string s;
    cin >> s;
    if (find(s.begin(), s.end(), '#') != s.end()) {
      a.push_back(s);
    }
  }
  vector<int> crash(w, 0);
  for (auto& e : a) {
    for (int i = 0; i < w; ++i) {
      crash[i] |= e[i] == '#';
    }
  }

  for (auto& e : a) {
    string row;
    for (size_t i = 0; i < e.size(); ++i) {
      if (crash[i] != 0) {
        row.push_back(e[i]);
      }
    }
    cout << row << "\n";
  }
}


#include <iostream>
#include <vector>
using namespace std;

void transform_columns( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < (int)arr[i].size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < (int)arr.size(); j++)
			if( arr[j][i] == '.' or arr[j][i] == 'X' )
				is_white++;
		if( is_white == (int)arr.size() )
			for(int j = 0; j < (int)arr.size(); j++)
				arr[j][i] = 'X';
	}
}

void transform_rows( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < (int)arr.size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < (int)arr[i].size(); j++)
			if( arr[i][j] == '.' or arr[i][j] == 'X' )
				is_white++;
		if( is_white == (int)arr[i].size() )
			for(int j = 0; j < (int)arr[i].size(); j++)
				arr[i][j] = 'X';
	}
}

void show_matrix( vector<vector<char> > & arr )
{
	int is_x;
	for(int i = 0 ; i < (int)arr.size(); i++)
	{
		is_x = 0;
		for(int j = 0; j < (int)arr[i].size(); j++)
		{
			if( arr[i][j] == 'X' )
				is_x++;
			else cout << arr[i][j];
		}

		if( is_x != (int)arr[i].size() )
			cout << "\n";
	}
}

int main()
{
	int h, w;
	cin >> h >> w;
	vector< vector <char> > arr;
	for(int i = 0; i < h; i++)
	{
		vector <char> tmp(w);
		for(int j = 0; j < w; j++)
			cin >> tmp[j];
		arr.push_back(tmp);
	}
	transform_rows(arr);
	transform_columns(arr);
	show_matrix(arr);
}


#include <iostream>
#include <vector>
using namespace std;

void transform_columns( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < (int)arr[i].size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < (int)arr.size(); j++)
			if( arr[j][i] == '.' or arr[j][i] == 'X' )
				is_white++;
		if( is_white == (int)arr.size() )
			for(int j = 0; j < (int)arr.size(); j++)
				arr[j][i] = 'X';
	}
}

void transform_rows( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < (int)arr.size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < (int)arr[i].size(); j++)
			if( arr[i][j] == '.' or arr[i][j] == 'X' )
				is_white++;
		if( is_white == (int)arr[i].size() )
			for(int j = 0; j < (int)arr[i].size(); j++)
				arr[i][j] = 'X';
	}
}

void show_matrix( vector<vector<char> > & arr )
{
	int is_x;
	for(int i = 0 ; i < (int)arr.size(); i++)
	{
		is_x = 0;
		for(int j = 0; j < (int)arr[i].size(); j++)
		{
			if( arr[i][j] == 'X' )
				is_x++;
			else cout << arr[i][j];
		}

		if( is_x != (int)arr[i].size() )
			cout << "\n";
	}
}

int main()
{
	int h, w, is_white;
	cin >> h >> w;
	vector< vector <char> > arr;
	for(int i = 0; i < h; i++)
	{
		vector <char> tmp(w);
		for(int j = 0; j < w; j++)
			cin >> tmp[j];
		arr.push_back(tmp);
	}
	transform_rows(arr);
	transform_columns(arr);
	show_matrix(arr);
}


#include <iostream>
#include <vector>
using namespace std;

void transform_columns( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < arr[i].size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < arr.size(); j++)
			if( arr[j][i] == '.' or arr[j][i] == 'X' )
				is_white++;
		if( is_white == arr.size() )
			for(int j = 0; j < arr.size(); j++)
				arr[j][i] = 'X';
	}
}

void transform_rows( vector<vector<char> > & arr )
{
	int is_white;
	for(int i = 0; i < arr.size(); i++)
	{
		is_white = 0;
		for(int j = 0; j < arr[i].size(); j++)
			if( arr[i][j] == '.' or arr[i][j] == 'X' )
				is_white++;
		if( is_white == arr[i].size() )
			for(int j = 0; j < arr[i].size(); j++)
				arr[i][j] = 'X';
	}
}

void show_matrix( vector<vector<char> > & arr )
{
	int is_x;
	for(int i = 0 ; i < arr.size(); i++)
	{
		is_x = 0;
		for(int j = 0; j < arr[i].size(); j++)
		{
			if( arr[i][j] == 'X' )
				is_x++;
			else cout << arr[i][j];
		}

		if( is_x != arr[i].size() )
			cout << "\n";
	}
}

int main()
{
	int h, w, is_white;
	cin >> h >> w;
	vector< vector <char> > arr;
	for(int i = 0; i < h; i++)
	{
		vector <char> tmp(w);
		for(int j = 0; j < w; j++)
			cin >> tmp[j];
		arr.push_back(tmp);
	}
	transform_rows(arr);
	transform_columns(arr);
	show_matrix(arr);
}


/*  ex5_3
    takafumi_ueki*/
#include <stdio.h>
    int main(void){
        int i,j,length,width;
        int row[100]={0};
        int col[100]={0};
        char field[100][100];
        //縦と横の長さを受け取る
        scanf("%d %d",&length,&width);
        //マス目が'.'か'#'かを受け取る
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                scanf(" %c",&field[i][j]);
            }
        }
        //列ごとに'#'が含まれているかどうかを調べる
        //もし含まれていたらrow[i]が1になる
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                if(field[i][j]=='#'){
                    row[i]=1;
                    break;
                }
            }
        }
        //次に行ごとに'#'が含まれていないか調べる
        for(j=0;j<width;j++){
            for(i=0;i<length;i++){
                if(field[i][j]=='#'){
                    col[j]=1;
                    break;
                }
            }
        }
        //もし,'#'がひとつでも含まれていたらその行、列は書き出すようにする
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                if(row[i]==1&&col[j]==1){
                    printf("%c",field[i][j]);
                }
            }
            printf("\n");
        }
        return 0;
    }


/*  ex5_3
    Graku   */
#include<stdio.h>

int main(void) {
    int height, width;
    scanf("%d %d", &height, &width);
    int blank_rows[height], blank_cols[width]; //blank -> 0, not blank -> 1
    char matrix[height][width];
    for (int row = 0; row < height; ++row) {
        for (int col = 0; col < width; ++col) {
            scanf(" %c", &matrix[row][col]); //don't read "\n"
        }
    }

    for (int row = 0; row < height; ++row) { //find blank rows
        int flag = 0;
        for (int col = 0; col < width; ++col) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_rows[row] = flag;
    }
    for (int col = 0; col < width; ++col) { //find blank columns
        int flag = 0;
        for (int row = 0; row < height; ++row) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_cols[col] = flag;
    }

    for (int row = 0; row < height; row++) {
        if (blank_rows[row]) { //if row is not blank
            for (int col = 0; col < width; ++col) {
                if (blank_cols[col]) { //if column is not blank
                    printf("%c", matrix[row][col]);
                }
            }
            printf("\n");
        }
    }

    return 0;
}


/* kadai5_3
   reo012 */

#include<stdio.h>

int main(void){
    int h, w, i, j;
    scanf("%d %d", &h, &w); //行数hと列数wの入力
    int row[h], col[w];  //h行目またはw列目に黒マスがあるかの情報を入れる配列
    char squares[h][w];  //h行w列の二次元配列squaresを定義

    //始めに配列row,colは全て0を入力
    for(i=0;i < h;i++){
        row[i] = 0;
    }
    for(j=0;j < w;j++){
        col[j] = 0;
    }

    //二次元配列squareに行ごとに入力
    for(i=0;i < h;i++){
        for(j=0;j < w;j++){
            scanf(" %c",&squares[i][j]);  //i行目j列目入力
            //黒が入力された場合その行と列の配列に１を入れる
            if(squares[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }

    //白い行、白い列を省いて出力していく。row[i]=1かつcol[j]=1のマスのみ出力
    for(i=0;i < h;i++){
        //行に黒が含まれる場合のみ表示する
        if(row[i] == 1){
            for(j=0;j < w;j++){
                //列に黒が含まれる場合のみ表示する
                if(col[j] == 1){
                    printf("%c",squares[i][j]);
                }
            }
            printf("\n");//行を出力したら改行
        }
    }

    return 0;
}


/*
    ex7_3
    takaoga
 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void delete_whiteline(char **board, int *hight, int *width);

int main(void){
    int i, width, hight;
    char **board;
    scanf("%d %d\n",&hight ,&width);
    board = (char**)calloc(hight, sizeof(char*));
    if(board == NULL){
        exit(1);
    }
    for(i = 0;i < hight; i++){
        board[i] = (char*)calloc(width, sizeof(char));
        if(board[i] == NULL){
            exit(1);
        }
    }
    for(i = 0;i < hight ; i++){
        scanf("%s", board[i]);
    }
    delete_whiteline(board, &hight, &width);
    for(i = 0; i < hight ; i++){
        board[i][width] = 0;
        printf("%s\n", board[i]);
    }
    for(i = 0; i < hight ; i++){
        free(board[i]);
    }
    free(board);

    return 0;
}

void delete_whiteline(char **board,int *hight,int *width){
    int i, j,k, counter_row, counter_column;
    for(i = 0 ; i < *hight ; i++){
        counter_row = 0;
        for(j = 0 ; j < *width ; j++){
            if(board[i][j] == '.') counter_row++;//行を調べて、白だけの物がないかチェック
        }
        if(counter_row == *width){
            free(board[i]);
            *hight = *hight - 1;
            for(k = i ; k < *hight ; k++){
                board[k] = board[k+1];//白だけの行があったらその行を消す
            }
        }
    }

    for(i = 0 ; i < *width ; i++){
        counter_column = 0;
        for(j = 0 ; j < *hight ; j++){
            if(board[j][i] == '.') counter_column++;//列を調べて、白だけの物がないかチェック
        }
        if(counter_column == *hight){
            *width = *width - 1;
            for(k = i ; k < *width ; k++){
                for(j = 0 ; j < *hight ; j++){
                    board[j][k] = board[j][k+1];//白だけの列があったらその行を消す
                }
                for(j = 0 ; j < *hight ; j++){
                    board[j] = (char *)realloc(board[j], *width);//最後にreallocする
                }

            }

        }
    }
}


#include <stdio.h>
#define LIMIT 100

int main(void){
    int row,col,i,j,rowjudge[LIMIT]={0},coljudge[LIMIT]={0};
    char matrix[LIMIT][LIMIT];
    scanf("%d %d",&row,&col);

    // 初期化
    for(i=0; i<LIMIT; i++){
        for(j=0; j<LIMIT; j++){
            matrix[i][j]='\0';
        }
    }

    // 入力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    // 各行、各列に黒が１つでもあるかを判別
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(matrix[i][j]=='#'){
                rowjudge[i]=1;
            }
        }
    }
    for(j=0; j<col; j++){
        for(i=0; i<row; i++){
            if(matrix[i][j]=='#'){
                coljudge[j]=1;
            }
        }
    }

    // 黒が１つでもある行と列の重なる要素のみを出力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(rowjudge[i]==1 && coljudge[j]==1){
                printf("%c",matrix[i][j]);
            }
        }
        if(rowjudge[i]==1){
            printf("\n");
        }
    }
    return 0;
}


/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)素因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
num(a,b)a-bを返します。ソート用です
isPrime(n)素数かどうか真偽値で返します
isNumber(n)数かどうか真偽値で返します
arrsum(arr)配列の合計値を返します
nibu(arr,n)n以下で最も大きい数の添字を返します(nを含みます)
br(input)入力を改行で区切ります
*/
const debugMode = false;
const inf = Number.MAX_SAFE_INTEGER;
const mod = 1000000007;
function Main(input) {
    input = input.split("\n");
    input.shift();
    for (var i = 0; i < input.length; i++) {
        if (input[i].indexOf("#") == -1) {
            input.splice(i, 1)
            i--;
        };
    }
    input = arr1dto2d(input);
    input = rotate(input);
    for (var i = 0; i < input.length; i++) {
        if (input[i].indexOf("#") == -1) {
            input.splice(i, 1)
            i--;
        };
    }
    input = rotate(input);
    input = rotate(input);
    input = rotate(input);
    for (var i = 0; i < input.length; i++) {
        input[i] = input[i].join("");
    }
    console.log(input.join("\n"))
} Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function zisyozyunn(a) {
    var arr = [];
    for (var i = 0; i < input[0]; i++) {
        arr.push(i + 1);
    }
    var sum = 0;
    for (var i = 0; i < a.length; i++) {
        var f = arr.findIndex(val => val == a[i]);
        sum += factorialize(a.length - 1 - i) * f;
        arr.splice(f, 1);
    }
    return sum;
}
function arrsum(arr) {
    var sum = 0;
    for (var i = 0, len = arr.length; i < len; ++i) {
        sum += arr[i] - 0;
    };
    return sum;
}
function debug(val) {
    if (debugMode == true) {
        console.log(val)
    }
}
function arrMaxPoint(arr) {
    var max = Number.MIN_SAFE_INTEGER;
    var point = -1;
    for (var i = 0; i < arr.length; i++) {
        if (max < arr[i]) {
            max = arr[i];
            point = i;
        }
    }
    return point;
}
function arrMinPoint(arr) {
    var min = Number.MAX_SAFE_INTEGER;
    var point = -1;
    for (var i = 0; i < arr.length; i++) {
        if (min > arr[i]) {
            min = arr[i];
            point = i;
        }
    }
    return point;
}
function arr1dto2d(arr) {
    for (var i = 0; i < arr.length; i++) {
        arr[i] = arr[i].split("");
    }
    return arr;
}
function isPrime(n) {
    if (false === Number.isInteger(n)) {
        return false;
    }
    if (n <= 1) {
        return false;
    }
    if (2 === n) {
        return true;
    }
    if (0 === n % 2) {
        return false;
    }
    var square_root = Math.floor(Math.sqrt(n));
    for (var i = 3; i <= square_root; i += 2) {
        if (0 === n % i) {
            return false;
        }
    }
    return true;
}
function isNumber(val) {
    const pat = /^([1-9]\d*|0)$/;
    return pat.test(val);
}
function factorialize(num) {
    if (num === 0) { return 1; }
    return num * factorialize(num - 1);
}
function rotate(array) {
    const ROW = array.length;
    const COL = array[0].length;
    const row = ROW - 1;
    var a = new Array(COL);
    for (var c = 0; c < COL; c++) {
        a[c] = new Array(ROW);
        for (var r = 0; r < ROW; r++) {
            a[c][r] = array[row - r][c];
        }
    }
    return a;
}
function part_in(base, push, st) {
    for (var i = st, p = 0; p < push.length; i++, p++) {
        base[i] = push[p];
    }
    return base;
}
function part_reverse(arr, s, g) {
    var push = arr.slice(s - 1, g);
    push.reverse();
    arr = part_in(arr, push, s - 1);
    return arr;
}
function zeroPadding(num, length) {
    return (num + '000000000000000000000000000000000').slice(0, length);
}
function arrsum(arr) {
    var sum = 0;
    for (var i = 0, len = arr.length; i < len; ++i) {
        sum += arr[i] - 0;
    };
    return sum;
}
function pf(n) {
    var result = {};

    if (n === 1) {
        return { "1": 1 }
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0) {
        return a
    }
    return gcd(b, a % b)
}
function lcm(a, b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
    return a - b;
}
function nibu(a, searchValue) {
    var index = -1;

    //調べる左端を表す添字(index)
    var left = 0;

    //調べる右端を表す添字(index)
    var right = a.length - 1;

    //左端と右端にデータがある間は処理を繰り返す
    while (left <= right) {

        //左右の真ん中を表す添字(index)
        middle = Math.floor((left + right) / 2);

        //真ん中の値と探す値を比較する
        if (a[middle] == searchValue) {
            //一致した場合、変数に入れて処理終了
            index = middle;
            break;
        } else if (a[middle] < searchValue) {
            //探す値より小さい場合、左側にはもっと小さい値しかないので左端の値を真ん中の値の右に移動する
            left = middle + 1;
        } else {
            //探す値より大きい場合、右側にはもっと大きい値しかないので右端の値を真ん中の値の左に移動する
            right = middle - 1;
        }
    }
    if (index != -1) return index;
    else return left;
}
function br(input) {
    return input.split("\n");
}
function is_sortred(arr) {
    var flag = true;
    for (var i = 1; i < arr.length; i++) {
        if (arr[i - 1] > arr[i]) {
            flag = false;
            break;
        }
    }
    return flag;
}
function primeFactorization(n) {

    // 平方根を保存
    var s = Math.floor(Math.sqrt(n));

    var r = 0;

    var result = {};

    // 2から平方根までの素因数を求める
    for (var i = 2; i <= s; i++) {

        if ((n % i) == 0) {

            r = 0; // 指数カウンタクリア

            do {

                r++; // 指数カウンタプラス

                n = n / i;

            } while ((n % i) == 0);

            // 素因数iを指数とともに保存
            result[i] = r;

        }

    }

    // 残った素数を追加
    if (n > s) {
        result[n] = 1;
    }

    return result;

}


function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var H = myconv(input[0],4)[0];
  var W = myconv(input[0],4)[1];
  input.shift();
  for(var i = 0; i < H; i++){
    if(input[i].indexOf("#") == -1){
       input.splice(i,1);
      H--;
      i--;
    }
  }
  var checkWidth = new Array(W).fill(0);
  for(var i = 0; i < H; i++){
    var tmp = myconv(input[i],6);
    for(var j = 0; j < W; j++){
      if(tmp[j] == "."){
         checkWidth[j]++;
      }
    }
  }
  for(var i = 0; i < H; i++){
    var tmp = myconv(input[i],6);
    for(var j = 0; j < W; j++){
      if(checkWidth[j] == H){
         tmp[j] = "";
      }
    }
    input[i] = tmp.join("");
  }
  myout(input.join("\n"));
}
Main(myin());


function Main(input){
	input = input.split("\n");
  var HW = input.shift().split(" ");

  var h = Array.from({length:HW[0]},()=>0);
  var w = Array.from({length:HW[1]},()=>0);

  for(var i = 0 ; i < HW[0] ; i++){
  	for(var j = 0; j < HW[1] ; j++){
    	if(input[i][j] == "#")h[i] = w[j] = 1;
    }
  }

  var result = "";

  for(var i = 0 ; i < HW[0] ; i++){
    var aaaaa = 0;
  	for(var j = 0; j < HW[1] ; j++){
    	if(h[i]*w[j]){
      	result += input[i][j];
        aaaaa++;
      }
    }
    if(aaaaa != 0 && i != HW[0]-1)result += "\n";
  }

  return result;
}

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

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


"use strict"
// inputに入力データ全体が入る
function Main(input) {
    let tmp = input.split("\n");
    let num = tmp[0].split(" ").map(e=>~~e);
    let arr = tmp.slice(1, num[1]+1);
    for(let i = 0;i < arr.length-1;i++) arr[i] = arr[i].slice(0, -1);
    arr = arr.filter(w=>!w.split("").every(a=>a=="."));
    let newArr = arr.map(e=>e.split(""));
    const transpose = a => a[0].map((_, c) => a.map(r => r[c]));
    let hoge = transpose(newArr);
    hoge = hoge.filter(w=>!w.every(a=>a=="."));
    let fuga = transpose(hoge);
    console.log(fuga.join("\n").replace(/,/g, ''));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("./input3.txt", "utf8"));


// inputに入力データ全体が入る
function Main(input) {
	const lines = str.split("\n");
	const arr1 = lines.filter(l => !l.split("").every(s => s === "."));
	const arr2 = arr1[0].split("").map((_, i) => arr1.map(l => l[i]));
	const arr3 = arr2.filter(l => !l.every(s => s === "."));
	const arr4 = arr3[0].map((_, i) => arr3.map(l => l[i]));
	console.log(arr4.map(l => l.join("")).join("\n"));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


// inputに入力データ全体が入る
function Main(input) {
    let tmp = input.split("\n");
    let num = tmp[0].split(" ").map(e=>~~e);
    let arr = tmp.slice(1, num[1]+1);
    // for(let i = 0;i < arr.length-1;i++) arr[i] = arr[i].slice(0, -1);
    arr = arr.filter(w=>!w.split("").every(a=>a=="."));
    let newArr = arr.map(e=>e.split(""));
    const transpose = a => a[0].map((_, c) => a.map(r => r[c]));
    let hoge = transpose(newArr);
    hoge = hoge.filter(w=>!w.every(a=>a=="."));
    let fuga = transpose(hoge);
    console.log(fuga.join("\n").replace(/,/g, ''));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(h, w int, a []string) [][]byte {
        memo := make([][]int, h+1)
        for i := range memo {
                memo[i] = make([]int, w+1)
        }

        for i := 0; i < h; i++ {
                for j := 0; j < w; j++ {
                        if a[i][j] == '.' {
                                memo[i][j]++
                        }
                }
        }

        for i := 0; i < h+1; i++ {
                sum := 0
                for j := 0; j < w+1; j++ {
                        sum += memo[i][j]
                        if j == w {
                                memo[i][j] = sum
                        }
                }
        }
        for j := 0; j < w+1; j++ {
                sum := 0
                for i := 0; i < h+1; i++ {
                        sum += memo[i][j]
                        if i == h {
                                memo[i][j] = sum
                        }
                }
        }

        b := make([][]byte, h)
        k := 0
        for i := 0; i < h; i++ {
                if memo[i][w] != w {
                        b[k] = []byte{}
                        k++
                }
                for j := 0; j < w; j++ {
                        if memo[i][w] != w && memo[h][j] != h {
                                b[k-1] = append(b[k-1], a[i][j])
                        }
                }
        }

        if k != h {
                b = b[:k]
        }
        return b
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var h, w int
        fmt.Fscan(r, &h, &w)
        a := make([]string, h)
        for i := range a {
                fmt.Fscan(r, &a[i])
        }
        for _, b := range solution(h, w, a) {
                fmt.Println(string(b))
        }
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	h, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	w, _ := strconv.Atoi(sc.Text())

	skipRows := makeTrues(h)
	skipCols := makeTrues(w)
	white := byte('.')

	matrix := make([][]byte, h)
	for i := 0; i < h; i++ {
		sc.Scan()
		row := sc.Text()
		matrix[i] = make([]byte, w)

		skipRow := true
		for j := 0; j < w; j++ {
			matrix[i][j] = row[j]
			skipRow = skipRow && matrix[i][j] == white
			skipCols[j] = skipCols[j] && matrix[i][j] == white
		}
		skipRows[i] = skipRow
	}

	colIdxs := make([]int, 0)
	for j, skip := range skipCols {
		if !skip {
			colIdxs = append(colIdxs, j)
		}
	}

	out := bufio.NewWriter(os.Stdout)
	for i, row := range matrix {
		if skipRows[i] {
			continue
		}
		for _, j := range colIdxs {
			fmt.Fprintf(out, string(row[j]))
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

func makeTrues(n int) []bool {
	bs := make([]bool, n)
	for i := 0; i < n; i++ {
		bs[i] = true
	}
	return bs
}


// by syu
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var in = NewScanner(os.Stdin, 0)

func main() {
	H, _ := in.Int(), in.Int()
	g := make([]string, H)
	for i := 0; i < H; i++ {
		g[i] = in.String()
	}
	g = FilterStrings(g, func(i int, bb string) bool {
		return strings.IndexByte(bb, '#') != -1
	})
	g = TransposeString(g)
	g = FilterStrings(g, func(i int, bb string) bool {
		return strings.IndexByte(bb, '#') != -1
	})
	g = TransposeString(g)
	PString(g)
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) String() string {
	s.Scan()
	return s.Text()
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func FilterStrings(a []string, f func(int, string) bool) (r []string) {
	for i, x := range a {
		if f(i, x) {
			r = append(r, x)
		}
	}
	return
}
func TransposeString(slice []string) []string {
	xl := len(slice[0])
	yl := len(slice)
	result := make([]string, xl)
	for i := 0; i < xl; i++ {
		r := make([]byte, yl)
		for j := 0; j < yl; j++ {
			r[j] = slice[j][i]
		}
		result[i] = string(r)
	}
	return result
}
func Pf(f string, s ...interface{}) {
	fmt.Printf(f, s...)
}
func PString(a []string) {
	for i := 0; i < len(a); i++ {
		Pf("%s\n", a[i])
	}
}


package main

import "fmt"

func main() {
	var h, w int
	fmt.Scanf("%d %d\n", &h, &w)

	grid := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scanf("%s\n", &grid[i])
	}

	hl, wl := map[int]bool{}, map[int]bool{}

	for i := 0; i < h; i++ {
		flg := true
		for j := 0; j < w; j++ {
			if string(grid[i][j]) != "." {
				flg = false
				break
			}
		}
		if flg {
			hl[i] = true
		}
	}

	for i := 0; i < w; i++ {
		flg := true
		for j := 0; j < h; j++ {
			if string(grid[j][i]) != "." {
				flg = false
				break
			}
		}
		if flg {
			wl[i] = true
		}
	}

	for i := 0; i < h; i++ {
		if !hl[i] {
			for j := 0; j < w; j++ {
				if !wl[j] {
					print(string(grid[i][j]))
				}
			}
			print("\n")
		}
	}

}


package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	// load and prepare
	h, w := scanInt(sc), scanInt(sc)
	grid := make([]string, h)
	whiteRow := make([]bool, h)
	whiteNum := make([]int, w)
	for i := 0; i < h; i++ {
		grid[i] = scanString(sc)
		whiteRow[i] = true
		for j := range grid[i] {
			if grid[i][j] != '.' {
				whiteRow[i] = false
			} else {
				whiteNum[j]++
			}
		}
	}

	// build output
	builder := &strings.Builder{}
	for i := 0; i < h; i++ {
		if whiteRow[i] {
			continue
		}
		for j := 0; j < w; j++ {
			if whiteNum[j] == h {
				continue
			}
			builder.WriteByte(grid[i][j])
		}
		builder.WriteByte('¥n')
	}
	// write answer
	fmt.Printf("%s", builder.String())
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


h, w = gets.split.map(&:to_i)
a = []
h.times do |i|
  s = gets.chomp
  a.push(s) if s.index('#')
end
(w - 1).downto(0) do |i|
  if a.all?{|x| x[i] == '.'}
    a.each do |x|
      x[i] = ''
    end
  end
end
puts a


h, w = gets.split.map(&:to_i)
a = []
h.times do |i|
  s = gets.chomp
  a.push(s) if s.count('.') != w
end
(w - 1).downto(0) do |i|
  if a.all?{|x| x[i] == '.'}
    a.each do |x|
      x[i] = ''
    end
  end
end
puts a


h, w = gets.split.map(&:to_i)
a = []
h.times do |i|
  s = gets.chomp
  a.push(s) if s.count('.') != w
end
(w - 1).downto(0) do |i|
  f = a.all?{|x| x[i] == '.'}
  if f
    a.each do |x|
      x[i] = ''
    end
  end
end
puts a


h, w = gets.chomp.split.map(&:to_i)
map = Array.new(h).map{Array.new(w)}
h.times do |i|
	map[i] = gets.chomp.split("")
end

ih = {}
jh = {}
h.times do |i|
	if map[i].uniq.length == 1
		ih[i] = true
	else
		ih[i] = false
	end
end
mapt = map.transpose
w.times do |i|
	if mapt[i].uniq.length == 1
		jh[i] = true
	else
		jh[i] = false
	end
end

h.times do |i|
	w.times do |j|
		print(map[i][j]) if ih[i] == false && jh[j] == false
	end
	puts if ih[i] == false
end


h, w = gets.chomp.split.map(&:to_i)
map = Array.new(h).map{Array.new(w)}
h.times do |i|
	map[i] = gets.chomp.split("")
end

ih = {}
jh = {}
h.times do |i|
	if map[i].uniq.length == 1
		ih[i] = true
	else
		ih[i] = false
	end
end
mapt = map.transpose
w.times do |i|
	if mapt[i].uniq.length == 1
		jh[i] = true
	else
		jh[i] = false
	end
end

puts
h.times do |i|
	w.times do |j|
		print(map[i][j]) if ih[i] == false && jh[j] == false
	end
	puts if ih[i] == false
end


h,w = gets.strip.split.map(&:to_i)
ary = []
h.times do
  a = gets.strip.to_s
  b = a.split("").map(&:to_s)
  unless b.uniq == ["."]
    ary << b
  end
end
arys = ary.transpose
w.times do |i|
  if arys[i].uniq == ["."]
    arys.delete_at(i)
  end
end
newary = arys.transpose
newary.size.times do |k|
  puts newary[k].join("")
end


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        v: [chars; h]
    }
    let v: Vec<Vec<char>> = v.iter().cloned().filter(|s| s.iter().any(|&x| x == '#')).collect();
    let mut ans = vec![vec![]; v.len()];
    for j in 0..w {
        let mut f = false;
        for i in 0..v.len() {
            if v[i][j] == '#' {
                f = true;
                break;
            }
        }
        if !f {
            continue;
        }
        for i in 0..v.len() {
            ans[i].push(v[i][j]);
        }
    }
    for s in &ans {
        println!("{}", s.iter().cloned().collect::<String>());
    }
}


use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let mut map: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let line: Vec<char> = iterator.next().unwrap().chars().collect();
        map.push(line);
    }

    for r in (0..h).rev() {
        let mut is_all_white = true;
        for c in 0..w {
            if map[r][c] == '#' {
                is_all_white = false;
                break;
            }
        }
        if is_all_white {
            map.remove(r);
        }
    }

    for c in (0..w).rev() {
        let mut is_all_white = true;
        for r in 0..map.len() {
            if map[r][c] == '#' {
                is_all_white = false;
                break;
            }
        }
        if is_all_white {
            for r in 0..map.len() {
                map[r].remove(c);
            }
        }
    }

    let mut result = String::new();
    for line in &map {
        for &c in line {
            result.push(c);
        }
        result.push('\n');
    }
    return result.trim().to_string();
}


// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, stdout, Write };
use my::WriteWith;

use std::collections::HashMap;

#[inline(always)]
fn abc107_b() {
  let stdin  = stdin();
  let stdout = stdout();
  let (mut scanner, mut writer) = my::rw(12, stdin.lock(), stdout.lock());

  let h = scanner.uint_until::<usize>(my::SP);
  let w = scanner.uint_until::<usize>(my::LF);

  let     black  = b'#';
  let     _white = b'.';
  let mut show   = HashMap::with_capacity_and_hasher(w, my::MyHasher::default());

  let mut vec = Vec::with_capacity(h);
  for _ in 0..h {
    let row = scanner.byte_until(my::LF);

    let mut flag = false;
    let mut i    = 0;
    while i < row.len() {
      if row[i] == black {
        show.insert(i, true);
        flag = true;
      }
      i += 1;
    }

    if flag {
      vec.push(row);
    }
  }

  for v in &vec {
    for (&i, _) in &show {
      writer.write(&[v[i]]).unwrap();
    }
    writer.write(b"\n").unwrap();
  }

  writer.flush().unwrap();
}

fn main() {
  abc107_b();
}

//------------------------------------------------------------------------
mod my {
  use std::hash::Hasher;
  use std::hash::BuildHasher;

  pub struct MyHasher(u64);

  impl Default for MyHasher {
    #[inline(always)]
    fn default() -> Self {
      MyHasher(0x00)
    }
  }

  impl BuildHasher for MyHasher {
    type Hasher = MyHasher;

    #[inline(always)]
    fn build_hasher(&self) -> Self::Hasher {
      Self::Hasher::default()
    }
  }

  impl Hasher for MyHasher {
    #[inline(always)]
    fn finish(&self) -> u64 {
      self.0
    }

    #[inline(always)]
    fn write(&mut self, bytes: &[u8]) {
      self.0 = 0;
      for i in 0..bytes.len() {
        self.0 ^= (bytes[i] as u64) << (8 * (i % 8));
      }
    }
  }

  //----------------------------------------------------------------------
  use std::io::{ self, BufRead, BufReader, Write, BufWriter };
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg, Rem };
  use std::str::{ self, FromStr };
  use std::mem;

  const PLUS_SIGN : u8 = b'+';
  const MINUS_SIGN: u8 = b'-';
  const ASCII_0   : u8 = b'0';
  const ASCII_9   : u8 = b'9';

  pub const SP    : u8 = b' ';
  pub const LF    : u8 = b'\n';

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_right<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[len];
    for i in 0..len {
      ary[len - i] = ary[len - i - 1];
    }
    ary[0] = tmp;
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn rotate_left<T>(ary: &mut [T])
    where T: Copy +
             Debug
  {
    if ary.len() <= 1 {
      return;
    }

    let len = ary.len() - 1;
    let tmp = ary[0];
    for i in 0..len {
      ary[i] = ary[i + 1];
    }
    ary[len] = tmp;
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn gcd<T>(x: T, y: T) -> T
    where T: Rem<Output=T> +
             Default +
             PartialEq +
             Copy +
             Debug
  {
    _if!(y == T::default(),
      x,
      gcd(y, x % y))
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn intersection<T>(mut x: (T, T), mut y: (T, T)) -> Option<(T, T)>
    where T: PartialOrd +
             Copy +
             Debug
  {
    if x.0 > x.1 {
      mem::swap(&mut x.0, &mut x.1);
    }
    if y.0 > y.1 {
      mem::swap(&mut y.0, &mut y.1);
    }

    if x.0 >= y.1 || x.1 <= y.0 {
      return None;
    }

    if x.0 < y.0 {
      x.0 = y.0;
    }
    if x.1 > y.1 {
      x.1 = y.1;
    }

    Some(x)
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_digit(b: u8) -> bool {
    _if!(b >= ASCII_0 && b <= ASCII_9,
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_uppercase(b: u8) -> bool {
    _if!(b >= b'A' && b <= b'Z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_lowercase(b: u8) -> bool {
    _if!(b >= b'a' && b <= b'z',
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn is_ascii_alphabetic(b: u8) -> bool {
    _if!(is_ascii_uppercase(b) || is_ascii_lowercase(b),
      true,
      false)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_lowercase(b: u8) -> u8 {
    _if!(is_ascii_uppercase(b),
      b + 0x20,
      b)
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn to_ascii_uppercase(b: u8) -> u8 {
    _if!(is_ascii_lowercase(b),
      b - 0x20,
      b)
  }

  //----------------------------------------------------------------------
  pub trait WriteWith {
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>;
  }

  impl<W> WriteWith for BufWriter<W>
    where W: io::Write
  {
    #[allow(dead_code)]
    #[inline(always)]
    fn write_with(&mut self, buf: &[u8], delim: &[u8]) -> io::Result<usize>
    {
      Ok(self.write(buf)? + self.write(delim)?)
    }
  } // impl<W> WriteWith for BufWriter<W>

  //----------------------------------------------------------------------
  macro_rules! pub_fn_ItoA_from_ty {
    (uint, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};

    (int, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      #[inline(always)]
      pub fn $name(&mut self, mut n: $_type) -> &[u8] {
        self.buf.clear();
        if n == 0 {
          self.buf.push(ASCII_0);
          return self.buf.as_slice();
        }

        let mut negative = false;
        if n.is_negative() {
          negative = true;
          n = n.abs();
        }

        while n > 0 {
          self.buf.push((n % 10) as u8 + ASCII_0);
          n /= 10;
        }
        if negative {
          self.buf.push(MINUS_SIGN);
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};
  }

  #[derive(Debug)]
  pub struct ItoA {
    buf: Vec<u8>,
  }

  impl ItoA {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new() -> Self {
      ItoA {
        buf: Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize) -> Self {
      ItoA {
        buf: Vec::with_capacity(cap),
      }
    }

    pub_fn_ItoA_from_ty!(
      uint,
      from_usize => usize,
      from_u8    => u8,
      from_u16   => u16,
      from_u32   => u32,
      from_u64   => u64
    );

    pub_fn_ItoA_from_ty!(
      int,
      from_isize => isize,
      from_i8    => i8,
      from_i16   => i16,
      from_i32   => i32,
      from_i64   => i64
    );
  } // impl ItoA

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  #[inline(always)]
  pub fn rw<R, W>(cap: usize, r: R, w: W) -> (Scanner<BufReader<R>>, BufWriter<W>)
    where R: BufRead,
          W: io::Write
  {
    (
      Scanner::with_capacity(cap, BufReader::new(r)),
      BufWriter::new(w)
    )
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn r<R>(cap: usize, r: R) -> Scanner<BufReader<R>>
    where R: BufRead
  {
    Scanner::with_capacity(cap, BufReader::new(r))
  }

  #[allow(dead_code)]
  #[inline(always)]
  pub fn w<W>(w: W) -> BufWriter<W>
    where W: io::Write
  {
    BufWriter::new(w)
  }

  //----------------------------------------------------------------------
  #[derive(Debug)]
  pub struct Scanner<R> {
    reader: R,
    buf   : Vec<u8>,
  }

  impl<R> Scanner<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    #[inline(always)]
    pub fn new(reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::new(),
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn with_capacity(cap: usize, reader: R) -> Self {
      Scanner {
        reader: reader,
        buf   : Vec::with_capacity(cap),
      }
    }

    //--------------------------------------------------------------------
    #[inline(always)]
    fn read_until(&mut self, delim: u8) {
      self.buf.clear();
      let mut len = self.reader
                      .read_until(delim, &mut self.buf)
                      .expect(&format!("read_until(): {}", line!()));
      if len == 0 {
        return;
      }

      len -= 1;
      if self.buf[len] == delim {
        self.buf.truncate(len);
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    fn read_until_delim(&mut self) {
      let mut buf: [u8; 1] = [0; 1];

      self.buf.clear();
      while self.reader
              .read(&mut buf)
              .expect(&format!("read(): {}", line!())) != 0 &&
            buf[0] != SP &&
            buf[0] != LF
      {
        self.buf.push(buf[0]);
      }
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn parse_until<T>(&mut self, delim: u8) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.read_until(delim);
      unsafe { str::from_utf8_unchecked(&self.buf) }
        .parse()
        .unwrap()
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn byte_until(&mut self, delim: u8) -> Vec<u8> {
      self.read_until(delim);
      self.buf.clone()
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn string_until(&mut self, delim: u8) -> String {
      unsafe { String::from_utf8_unchecked(self.byte_until(delim)) }
    }

    //--------------------------------------------------------------------
    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      let mut n = T::default();
      if self.buf.len() == 0 {
        return n;
      }

      let mut i = 0;
      if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      n
    }

    // s -> n
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_until<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      let mut n = T::default();
      if self.buf.len() == 0 {
        return n;
      }

      let mut i = 0;
      let mut negative = false;
      if self.buf[i] == MINUS_SIGN {
        negative = true;
        i += 1;
      } else if self.buf[i] == PLUS_SIGN {
        i += 1;
      }

      for b in &self.buf[i..] {
        n = (n * T::from(10)) + T::from(b - ASCII_0);
      }

      _if!(negative,
        n.neg(),
        n)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_to_end<T, F>(&mut self, n: usize, delim: u8, mut init: T, mut func: F) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug,
            F: ::std::ops::FnMut(T, T) -> T
    {
      for _ in 0..n - 1 {
        init = func(init, self.uint_until(delim));
      }
      func(init, self.uint_until(LF))
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_to_end<T, F>(&mut self, n: usize, delim: u8, mut init: T, mut func: F) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug,
            F: ::std::ops::FnMut(T, T) -> T
    {
      for _ in 0..n - 1 {
        init = func(init, self.int_until(delim));
      }
      func(init, self.int_until(LF))
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_n<T, F>(&mut self, n: usize, delim: u8, mut func: F)
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug,
            F: ::std::ops::FnMut(T)
    {
      for _ in 0..n {
        func(self.uint_until(delim));
      }
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_n<T, F>(&mut self, n: usize, delim: u8, mut func: F)
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug,
            F: ::std::ops::FnMut(T)
    {
      for _ in 0..n {
        func(self.int_until(delim));
      }
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec<T>(&mut self, n: usize, delim: u8) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.uint_until(delim));
      }
      vec.push(self.uint_until(LF));
      vec
    }

    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec<T>(&mut self, n: usize, delim: u8) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.int_until(delim));
      }
      vec.push(self.int_until(LF));
      vec
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.uint_vec(n, SP)
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.uint_until(LF);
      self.int_vec(n, SP)
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn uint_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.uint_vec(m, SP));
      }
      vec
    }

    // N M
    // s11 s12 s13 ... s1M
    // s21 s22 s23 ... s2M
    // s31 s32 s33 ... s3M
    //   :
    // sN1 sN2 sN3 ... sNM
    // -> [
    //      [n11, n12, n13, ..., n1M],
    //      [n21, n22, n23, ..., n2M],
    //      [n31, n32, n33, ..., n3M],
    //          :
    //      [nN1, nN2, nN3, ..., nNM],
    //    ]
    #[allow(dead_code)]
    #[inline(always)]
    pub fn int_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.int_vec(m, SP));
      }
      vec
    }

  } // impl<R> Scanner<R>

} // mod my