process.stdin.resume();
process.stdin.setEncoding('utf8');
var iters = 1000000;
var withRegex = function( string ) {
return string.replace( /[^a-z0-9]/ig, '' );
};
var withRegex2 = function( string ) {
return string.replace( /[^a-z0-9]+/ig, '' );
};
var withPureJS = function( string ) {
var result = "";
var length = string.length;
for ( var pos = 0; pos < length; pos++ ) {
c = string.charCodeAt( pos );
if ( ( c > 47 && c < 58 ) || ( c > 64 && c < 91 ) || ( c > 96 && c < 123 ) ) {
result += string[pos];
};
};
return result;
};
function test( func, string, iters ) {
var tStart = Date.now();
var etalon = withRegex( string );
for ( var i=0; i<iters; i++ ) {
if ( func( string ) != etalon ) {
console.log( "error" );
break;
};
};
var tEnd = Date.now();
console.log( "test "+counter, tEnd - tStart );
counter++;
};
console.log( "Test started" );
var counter = 1;
test( withRegex, "abc0123$%^&*", iters );
test( withRegex2, "abc0123$%^&*", iters );
test( withPureJS, "abc0123$%^&*", iters );
cHJvY2Vzcy5zdGRpbi5yZXN1bWUoKTsKcHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZygndXRmOCcpOwoKdmFyIGl0ZXJzID0gMTAwMDAwMDsKdmFyIHdpdGhSZWdleCA9IGZ1bmN0aW9uKCBzdHJpbmcgKSB7CiAgcmV0dXJuIHN0cmluZy5yZXBsYWNlKCAvW15hLXowLTldL2lnLCAnJyApOwp9Owp2YXIgd2l0aFJlZ2V4MiA9IGZ1bmN0aW9uKCBzdHJpbmcgKSB7CiAgcmV0dXJuIHN0cmluZy5yZXBsYWNlKCAvW15hLXowLTldKy9pZywgJycgKTsKfTsKdmFyIHdpdGhQdXJlSlMgPSBmdW5jdGlvbiggc3RyaW5nICkgewogIHZhciByZXN1bHQgPSAiIjsKICB2YXIgbGVuZ3RoID0gc3RyaW5nLmxlbmd0aDsKICBmb3IgKCB2YXIgcG9zID0gMDsgcG9zIDwgbGVuZ3RoOyBwb3MrKyApIHsKICAgIGMgPSBzdHJpbmcuY2hhckNvZGVBdCggcG9zICk7CiAgICBpZiAoICggYy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