Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.

The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively.

If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:   the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,  the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,  the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,  Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them. See the samples to better understand the statement.

6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}

/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var List = __webpack_require__(1);
	var xy = List.map(parseInt, readline().split(' '));
	var Rect = (function () {
	    function Rect(width, height, label) {
	        this.width = width;
	        this.height = height;
	        this.label = label;
	    }
	    Rect.prototype.rotated = function () {
	        return new Rect(this.height, this.width, this.label);
	    };
	    return Rect;
	})();
	var rects = [];
	var label = ["A", "B", "C"];
	for (var i = 0; i < 3; i++) {
	    rects.push(new Rect(xy[2 * i], xy[2 * i + 1], label[i]));
	}
	var infinity = 100000000;
	function square(n) {
	    return List.map(function (_) { return List.replicate(n, "."); }, List.replicate(n, []));
	}
	function draw(canvas, x, y, r) {
	    for (var i = x; i < x + r.width; i++) {
	        for (var j = y; j < y + r.height; j++) {
	            canvas[i][j] = r.label;
	        }
	    }
	}
	function output(canvas) {
	    print(canvas.length);
	    print(List.map(function (s) { return s.join(""); }, canvas).join("\n"));
	}
	function fit(rect) {
	    var width = rect[0].width;
	    var height = rect[0].height;
	    if (rects[1].width > width)
	        return false;
	    height += rect[1].height;
	    if (rect[2].width + rect[1].width === width) {
	        if (rect[2].height !== rect[1].height)
	            return false;
	        if (height !== width)
	            return false;
	        var canvas = square(width);
	        draw(canvas, 0, 0, rect[0]);
	        draw(canvas, 0, rect[0].height, rect[1]);
	        draw(canvas, rect[1].width, rect[0].height, rect[2]);
	        output(canvas);
	        return true;
	    }
	    else {
	        if (rect[1].width != width || rect[2].width != width)
	            return false;
	        height += rect[2].height;
	        if (height != width)
	            return false;
	        var canvas = square(width);
	        draw(canvas, 0, 0, rect[0]);
	        draw(canvas, 0, rect[0].height, rect[1]);
	        draw(canvas, 0, rect[0].height + rect[1].height, rect[2]);
	        output(canvas);
	        return true;
	    }
	}
	var found = false;
	for (var rotation = 0; rotation < 8 && !found; rotation++) {
	    var rotated = [];
	    for (var i = 0; i < 3; i++) {
	        var should_rotate = ((rotation >> i) & 1) !== 0;
	        rotated.push(should_rotate ? rects[i].rotated() : rects[i]);
	    }
	    var p = List.range(0, 2);
	    do {
	        found = found || fit(List.apply_permutation(p, rotated));
	    } while ((p = List.next_permutation(p)) && !found);
	}
	if (!found)
	    print("-1");

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(2);
	function add(xs, ys) {
	    return xs.concat(ys);
	}
	exports.add = add;
	function head(xs) {
	    return xs[0];
	}
	exports.head = head;
	function last(xs) {
	    return xs[xs.length - 1];
	}
	exports.last = last;
	function tail(xs) {
	    return xs.slice(1);
	}
	exports.tail = tail;
	function init(xs) {
	    return xs.slice(0, xs.length - 1);
	}
	exports.init = init;
	function map(f, xs) {
	    var result = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        result[i] = f(xs[i]);
	    }
	    return result;
	}
	exports.map = map;
	function reverse(xs) {
	    return xs.slice().reverse();
	}
	exports.reverse = reverse;
	function intersperse(x, xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = new Array(xs.length + xs.length - 1);
	    for (var i = 0; i + 1 < xs.length; i++) {
	        result[i + i] = xs[i];
	        result[i + i + 1] = x;
	    }
	    result[result.length - 1] = xs[xs.length - 1];
	    return result;
	}
	exports.intersperse = intersperse;
	function intercalate(xs, xss) {
	    return concat(intersperse(xs, xss));
	}
	exports.intercalate = intercalate;
	function foldl(f, initial, xs) {
	    var result = initial;
	    for (var i = 0; i < xs.length; i++) {
	        result = f(result, xs[i]);
	    }
	    return result;
	}
	exports.foldl = foldl;
	function foldr(f, initial, xs) {
	    var result = initial;
	    for (var i = xs.length - 1; i >= 0; i--) {
	        result = f(xs[i], result);
	    }
	    return result;
	}
	exports.foldr = foldr;
	function concat(xss) {
	    var total = sum(map(function (xs) { return xs.length; }, xss));
	    var result = new Array(total);
	    var m = 0;
	    for (var i = 0; i < xss.length; i++) {
	        var xs = xss[i];
	        for (var j = 0; j < xs.length; j++) {
	            result[m++] = xs[j];
	        }
	    }
	    return result;
	}
	exports.concat = concat;
	function sum(xs) {
	    var result = 0;
	    for (var i = 0; i < xs.length; i++) {
	        result += xs[i];
	    }
	    return result;
	}
	exports.sum = sum;
	function product(xs) {
	    var result = 1;
	    for (var i = 0; i < xs.length; i++) {
	        result *= xs[i];
	    }
	    return result;
	}
	exports.product = product;
	function maximum(xs) {
	    var result = xs[0];
	    for (var i = 1; i < xs.length; i++) {
	        if (result < xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.maximum = maximum;
	function minimum(xs) {
	    var result = xs[0];
	    for (var i = 1; i < xs.length; i++) {
	        if (result > xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.minimum = minimum;
	function replicate(n, x) {
	    var result = new Array(n);
	    for (var i = 0; i < result.length; i++) {
	        result[i] = x;
	    }
	    return result;
	}
	exports.replicate = replicate;
	function take(n, xs) {
	    return xs.slice(0, n);
	}
	exports.take = take;
	function drop(n, xs) {
	    return xs.slice(n);
	}
	exports.drop = drop;
	function splitAt(n, xs) {
	    return [take(n, xs), drop(n, xs)];
	}
	exports.splitAt = splitAt;
	function takeWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(0, i);
	        }
	    }
	    return xs.slice();
	}
	exports.takeWhile = takeWhile;
	function dropWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(i);
	        }
	    }
	    return [];
	}
	exports.dropWhile = dropWhile;
	function group(xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = [];
	    var last = [xs[0]];
	    for (var i = 1; i < xs.length; i++) {
	        if (last[0] === xs[i]) {
	            last.push(xs[i]);
	        }
	        else {
	            result.push(last);
	            last = [xs[i]];
	        }
	    }
	    result.push(last);
	    return result;
	}
	exports.group = group;
	function filter(f, xs) {
	    var result = [];
	    for (var i = 0; i < xs.length; i++) {
	        if (f(xs[i]))
	            result.push(xs[i]);
	    }
	    return result;
	}
	exports.filter = filter;
	function zip(xs, ys) {
	    var n = Prelude_1.min(xs.length, ys.length);
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = [xs[i], ys[i]];
	    }
	    return result;
	}
	exports.zip = zip;
	function unzip(xs) {
	    var r1 = new Array(xs.length);
	    var r2 = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        r1[i] = xs[i][0];
	        r2[i] = xs[i][1];
	    }
	    return [r1, r2];
	}
	exports.unzip = unzip;
	function range(from, to) {
	    var result = Array(to - from + 1);
	    for (var i = from; i <= to; i++) {
	        result[i - from] = i;
	    }
	    return result;
	}
	exports.range = range;
	function copy(xs) {
	    return xs.slice(0);
	}
	exports.copy = copy;
	function apply_permutation(p, xs) {
	    var n = xs.length;
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = xs[p[i]];
	    }
	    return result;
	}
	exports.apply_permutation = apply_permutation;
	function next_permutation(p) {
	    var n = p.length;
	    if (n < 2)
	        return null;
	    var r = copy(p);
	    var k = n - 2;
	    for (; k >= 0 && r[k] >= r[k + 1]; k--)
	        ;
	    if (k < 0)
	        return null;
	    for (var i = k + 1, j = n - 1; i < j; i++, j--) {
	        var t_1 = r[i];
	        r[i] = r[j];
	        r[j] = t_1;
	    }
	    var next = k + 1;
	    for (; r[next] <= r[k]; next++)
	        ;
	    var t = r[k];
	    r[k] = r[next];
	    r[next] = t;
	    return r;
	}
	exports.next_permutation = next_permutation;

/***/ },
/* 2 */
/***/ function(module, exports) {

	function min(a, b) {
	    return a < b ? a : b;
	}
	exports.min = min;
	function max(a, b) {
	    return a < b ? b : a;
	}
	exports.max = max;
	function curry(f) {
	    return function (x) { return function (y) { return f(x, y); }; };
	}
	exports.curry = curry;
	function uncurry(f) {
	    return function (x, y) { return f(x)(y); };
	}
	exports.uncurry = uncurry;
	function id(x) {
	    return x;
	}
	exports.id = id;
	function constant(x) {
	    return function (_) { return x; };
	}
	exports.constant = constant;
	function flip(f) {
	    return function (y) { return function (x) { return f(x)(y); }; };
	}
	exports.flip = flip;
	function flip2(f) {
	    return function (y, x) { return f(x, y); };
	}
	exports.flip2 = flip2;
	function compose(g, f) {
	    return function (x) { return g(f(x)); };
	}
	exports.compose = compose;

/***/ }
/******/ ]);

Array.prototype.sub_reverse = function(x,y) {
	var a = this;
	var n = a.length;
	for (var i = 0; i+i < (y - x); i++) {
		var temp = a[x+i];
		a[x+i] = a[y-1-i];
		a[y-1-i] = temp;
	}
}

Array.prototype.next_permutation = function(){
	var a = this;
	var n = a.length;
	if (n < 2) return false;

	//Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
	for (var k = n-2; k >= 0 && a[k] >= a[k+1]; --k){}
	if (k == -1) return false;

	//Find the largest index l greater than k such that a[k] < a[l].
	for (var l = n-1;  k < l && a[k] >= a[l]; --l){}
	if (k == l) return false;

	//Swap the value of a[k] with that of a[l].
	var temp = a[k];
	a[k] = a[l];
	a[l] = temp;

	//Reverse the sequence from a[k + 1] up to and including the final element a[n].
	a.sub_reverse(k+1,n);
	return true;
}

function solve(a,order) {
	var letter = ["A","B","C"];
	var A = {x:a[0][0], y:a[0][1], letter:letter[order[0]]};
	var B = {x:a[1][0], y:a[1][1], letter:letter[order[1]]};
	var C = {x:a[2][0], y:a[2][1], letter:letter[order[2]]};

	// AA
	// BB
	// CC
	if (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {
		write(A.x + "\n");
		for (var i = 0; i < A.y; i++) {
			for (var j = 0; j < A.x; j++)
				write(A.letter);
			write("\n");
		}
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < B.x; j++)
				write(B.letter);
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < C.x; j++)
				write(C.letter);
			write("\n");
		}
		return true;
	}

	// ABB
	// ACC
	if (B.x == C.x && A.y == (B.y+C.y) && A.y == (A.x + B.x)) {
		write(A.y + "\n");
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < A.x; j++) write(A.letter);
			for (var j = 0; j < B.x; j++) write(B.letter);
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < A.x; j++) write(A.letter);
			for (var j = 0; j < C.x; j++) write(C.letter);
			write("\n");
		}
		return true;
	}
	return false;
}

function main() {
	a = readline().split(" ").map(Number);

	var order = [0,1,2];
	do {
		// 2d array
		var b = [];
		for (var i = 0; i < 3; i++) {
			b.push([ a[2*order[i]], a[2*order[i]+1] ]);
		}

		for (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {
			var c = [];
			// rotate
			for (var i = 0; i < 3; i++)
				if (rotation_mask & (1<<i)) {
					c[i] = b[i].slice(0).reverse();
				} else {
					c[i] = b[i].slice();
				}
			result = solve(c, order);
			if (result) break;
		}
		if (result) break;
	} while (order.next_permutation());

	if (!result) {
		write("-1\n");
	}
}

main();

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}

/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var List = __webpack_require__(1);
	var xy = List.map(parseInt, readline().split(' '));
	var Rect = (function () {
	    function Rect(width, height, label) {
	        this.width = width;
	        this.height = height;
	        this.label = label;
	    }
	    Rect.prototype.rotated = function () {
	        return new Rect(this.height, this.width, this.label);
	    };
	    return Rect;
	})();
	var rects = [];
	var label = ["A", "B", "C"];
	for (var i = 0; i < 3; i++) {
	    rects.push(new Rect(xy[2 * i], xy[2 * i + 1], label[i]));
	}
	var infinity = 100000000;
	function square(n) {
	    return List.map(function (_) { return List.replicate(n, "."); }, List.replicate(n, []));
	}
	function draw(canvas, x, y, r) {
	    for (var i = x; i < x + r.width; i++) {
	        for (var j = y; j < y + r.height; j++) {
	            canvas[i][j] = r.label;
	        }
	    }
	}
	function output(canvas) {
	    print(List.map(function (s) { return s.join(""); }, canvas).join("\n"));
	}
	function fit(rect) {
	    var width = rect[0].width;
	    var height = rect[0].height;
	    if (rects[1].width > width)
	        return false;
	    height += rect[1].height;
	    if (rect[2].width + rect[1].width === width) {
	        if (rect[2].height !== rect[1].height)
	            return false;
	        if (height !== width)
	            return false;
	        var canvas = square(width);
	        draw(canvas, 0, 0, rect[0]);
	        draw(canvas, 0, rect[0].height, rect[1]);
	        draw(canvas, rect[1].width, rect[0].height, rect[2]);
	        output(canvas);
	        return true;
	    }
	    else {
	        if (rect[1].width != width || rect[2].width != width)
	            return false;
	        height += rect[2].height;
	        if (height != width)
	            return false;
	        var canvas = square(width);
	        draw(canvas, 0, 0, rect[0]);
	        draw(canvas, 0, rect[0].height, rect[1]);
	        draw(canvas, 0, rect[0].height + rect[1].height, rect[2]);
	        output(canvas);
	        return true;
	    }
	}
	var found = false;
	for (var rotation = 0; rotation < 8 && !found; rotation++) {
	    var rotated = [];
	    for (var i = 0; i < 3; i++) {
	        var should_rotate = ((rotation >> i) & 1) !== 0;
	        rotated.push(should_rotate ? rects[i].rotated() : rects[i]);
	    }
	    var p = List.range(0, 2);
	    do {
	        found = found || fit(List.apply_permutation(p, rotated));
	    } while ((p = List.next_permutation(p)) && !found);
	}
	if (!found)
	    print("-1");

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(2);
	function add(xs, ys) {
	    return xs.concat(ys);
	}
	exports.add = add;
	function head(xs) {
	    return xs[0];
	}
	exports.head = head;
	function last(xs) {
	    return xs[xs.length - 1];
	}
	exports.last = last;
	function tail(xs) {
	    return xs.slice(1);
	}
	exports.tail = tail;
	function init(xs) {
	    return xs.slice(0, xs.length - 1);
	}
	exports.init = init;
	function map(f, xs) {
	    var result = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        result[i] = f(xs[i]);
	    }
	    return result;
	}
	exports.map = map;
	function reverse(xs) {
	    return xs.slice().reverse();
	}
	exports.reverse = reverse;
	function intersperse(x, xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = new Array(xs.length + xs.length - 1);
	    for (var i = 0; i + 1 < xs.length; i++) {
	        result[i + i] = xs[i];
	        result[i + i + 1] = x;
	    }
	    result[result.length - 1] = xs[xs.length - 1];
	    return result;
	}
	exports.intersperse = intersperse;
	function intercalate(xs, xss) {
	    return concat(intersperse(xs, xss));
	}
	exports.intercalate = intercalate;
	function foldl(f, initial, xs) {
	    var result = initial;
	    for (var i = 0; i < xs.length; i++) {
	        result = f(result, xs[i]);
	    }
	    return result;
	}
	exports.foldl = foldl;
	function foldr(f, initial, xs) {
	    var result = initial;
	    for (var i = xs.length - 1; i >= 0; i--) {
	        result = f(xs[i], result);
	    }
	    return result;
	}
	exports.foldr = foldr;
	function concat(xss) {
	    var total = sum(map(function (xs) { return xs.length; }, xss));
	    var result = new Array(total);
	    var m = 0;
	    for (var i = 0; i < xss.length; i++) {
	        var xs = xss[i];
	        for (var j = 0; j < xs.length; j++) {
	            result[m++] = xs[j];
	        }
	    }
	    return result;
	}
	exports.concat = concat;
	function sum(xs) {
	    var result = 0;
	    for (var i = 0; i < xs.length; i++) {
	        result += xs[i];
	    }
	    return result;
	}
	exports.sum = sum;
	function product(xs) {
	    var result = 1;
	    for (var i = 0; i < xs.length; i++) {
	        result *= xs[i];
	    }
	    return result;
	}
	exports.product = product;
	function maximum(xs) {
	    var result = xs[0];
	    for (var i = 1; i < xs.length; i++) {
	        if (result < xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.maximum = maximum;
	function minimum(xs) {
	    var result = xs[0];
	    for (var i = 1; i < xs.length; i++) {
	        if (result > xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.minimum = minimum;
	function replicate(n, x) {
	    var result = new Array(n);
	    for (var i = 0; i < result.length; i++) {
	        result[i] = x;
	    }
	    return result;
	}
	exports.replicate = replicate;
	function take(n, xs) {
	    return xs.slice(0, n);
	}
	exports.take = take;
	function drop(n, xs) {
	    return xs.slice(n);
	}
	exports.drop = drop;
	function splitAt(n, xs) {
	    return [take(n, xs), drop(n, xs)];
	}
	exports.splitAt = splitAt;
	function takeWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(0, i);
	        }
	    }
	    return xs.slice();
	}
	exports.takeWhile = takeWhile;
	function dropWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(i);
	        }
	    }
	    return [];
	}
	exports.dropWhile = dropWhile;
	function group(xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = [];
	    var last = [xs[0]];
	    for (var i = 1; i < xs.length; i++) {
	        if (last[0] === xs[i]) {
	            last.push(xs[i]);
	        }
	        else {
	            result.push(last);
	            last = [xs[i]];
	        }
	    }
	    result.push(last);
	    return result;
	}
	exports.group = group;
	function filter(f, xs) {
	    var result = [];
	    for (var i = 0; i < xs.length; i++) {
	        if (f(xs[i]))
	            result.push(xs[i]);
	    }
	    return result;
	}
	exports.filter = filter;
	function zip(xs, ys) {
	    var n = Prelude_1.min(xs.length, ys.length);
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = [xs[i], ys[i]];
	    }
	    return result;
	}
	exports.zip = zip;
	function unzip(xs) {
	    var r1 = new Array(xs.length);
	    var r2 = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        r1[i] = xs[i][0];
	        r2[i] = xs[i][1];
	    }
	    return [r1, r2];
	}
	exports.unzip = unzip;
	function range(from, to) {
	    var result = Array(to - from + 1);
	    for (var i = from; i <= to; i++) {
	        result[i - from] = i;
	    }
	    return result;
	}
	exports.range = range;
	function copy(xs) {
	    return xs.slice(0);
	}
	exports.copy = copy;
	function apply_permutation(p, xs) {
	    var n = xs.length;
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = xs[p[i]];
	    }
	    return result;
	}
	exports.apply_permutation = apply_permutation;
	function next_permutation(p) {
	    var n = p.length;
	    if (n < 2)
	        return null;
	    var r = copy(p);
	    var k = n - 2;
	    for (; k >= 0 && r[k] >= r[k + 1]; k--)
	        ;
	    if (k < 0)
	        return null;
	    for (var i = k + 1, j = n - 1; i < j; i++, j--) {
	        var t_1 = r[i];
	        r[i] = r[j];
	        r[j] = t_1;
	    }
	    var next = k + 1;
	    for (; r[next] <= r[k]; next++)
	        ;
	    var t = r[k];
	    r[k] = r[next];
	    r[next] = t;
	    return r;
	}
	exports.next_permutation = next_permutation;

/***/ },
/* 2 */
/***/ function(module, exports) {

	function min(a, b) {
	    return a < b ? a : b;
	}
	exports.min = min;
	function max(a, b) {
	    return a < b ? b : a;
	}
	exports.max = max;
	function curry(f) {
	    return function (x) { return function (y) { return f(x, y); }; };
	}
	exports.curry = curry;
	function uncurry(f) {
	    return function (x, y) { return f(x)(y); };
	}
	exports.uncurry = uncurry;
	function id(x) {
	    return x;
	}
	exports.id = id;
	function constant(x) {
	    return function (_) { return x; };
	}
	exports.constant = constant;
	function flip(f) {
	    return function (y) { return function (x) { return f(x)(y); }; };
	}
	exports.flip = flip;
	function flip2(f) {
	    return function (y, x) { return f(x, y); };
	}
	exports.flip2 = flip2;
	function compose(g, f) {
	    return function (x) { return g(f(x)); };
	}
	exports.compose = compose;

/***/ }
/******/ ]);

Array.prototype.sub_reverse = function(x,y) {
	var a = this;
	var n = a.length;
	for (var i = 0; i+i < (y - x); i++) {
		var temp = a[x+i];
		a[x+i] = a[y-1-i];
		a[y-1-i] = temp;
	}
}

Array.prototype.next_permutation = function(){
	var a = this;
	var n = a.length;
	if (n < 2) return false;

	//Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
	for (var k = n-2; k >= 0 && a[k] >= a[k+1]; --k){}
	if (k == -1) return false;

	//Find the largest index l greater than k such that a[k] < a[l].
	for (var l = n-1;  k < l && a[k] >= a[l]; --l){}
	if (k == l) return false;

	//Swap the value of a[k] with that of a[l].
	var temp = a[k];
	a[k] = a[l];
	a[l] = temp;

	//Reverse the sequence from a[k + 1] up to and including the final element a[n].
	a.sub_reverse(k+1,n);
	return true;
}

function solve(a) {
	var A = {x:a[0][0], y:a[0][1]};
	var B = {x:a[1][0], y:a[1][1]};
	var C = {x:a[2][0], y:a[2][1]};

	// line
	// AA
	// BB
	// CC
	if (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {
		write(A.x + "\n");
		for (var i = 0; i < A.y; i++) {
			for (var j = 0; j < A.x; j++)
				write("A");
			write("\n");
		}
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < B.x; j++)
				write("B");
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < C.x; j++)
				write("C");
			write("\n");
		}
		return true;
	}

	// ABB
	// ACC

	if (B.x == C.x && A.y == (B.y+C.y)) {
		write(A.y + "\n");
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < A.x; j++) write("A");
			for (var j = 0; j < B.x; j++) write("B");
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < A.x; j++) write("A");
			for (var j = 0; j < C.x; j++) write("C");
			write("\n");
		}
		return true;
	}
	return false;
}

function main() {
	a = readline().split(" ").map(Number);

	var order = [0,1,2];
	do {
		// 2d array
		var b = [];
		for (var i = 0; i < 3; i++) {
			b.push([ a[2*order[i]], a[2*order[i]+1] ]);
		}

		for (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {
			var c = [];
			// rotate
			for (var i = 0; i < 3; i++)
				if (rotation_mask & (1<<i)) {
					c[i] = b[i].slice(0).reverse();
				} else {
					c[i] = b[i].slice();
				}
			result = solve(c);
			if (result) break;
		}
		if (result) break;
	} while (order.next_permutation());

	if (!result) {
		write("-1\n");
	}
}

main();

Array.prototype.sub_reverse = function(x,y) {
	var a = this;
	var n = a.length;
	for (var i = 0; i+i < (y - x); i++) {
		var temp = a[x+i];
		a[x+i] = a[y-1-i];
		a[y-1-i] = temp;
	}
}

Array.prototype.next_permutation = function(){
	var a = this;
	var n = a.length;
	if (n < 2) return false;

	//Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
	for (var k = n-2; k >= 0 && a[k] >= a[k+1]; --k){}
	if (k == -1) return false;

	//Find the largest index l greater than k such that a[k] < a[l].
	for (var l = n-1;  k < l && a[k] >= a[l]; --l){}
	if (k == l) return false;

	//Swap the value of a[k] with that of a[l].
	var temp = a[k];
	a[k] = a[l];
	a[l] = temp;

	//Reverse the sequence from a[k + 1] up to and including the final element a[n].
	a.sub_reverse(k+1,n);
	return true;
}

function solve(a,order) {
	var letter = ["A","B","C"];
	var A = {x:a[0][0], y:a[0][1], letter:letter[order[0]]};
	var B = {x:a[1][0], y:a[1][1], letter:letter[order[1]]};
	var C = {x:a[2][0], y:a[2][1], letter:letter[order[2]]};

	// AA
	// BB
	// CC
	if (A.x == B.x && B.x == C.x && A.x == (A.y + B.y + C.y) ) {
		write(A.x + "\n");
		for (var i = 0; i < A.y; i++) {
			for (var j = 0; j < A.x; j++)
				write(A.letter);
			write("\n");
		}
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < B.x; j++)
				write(B.letter);
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < C.x; j++)
				write(C.letter);
			write("\n");
		}
		return true;
	}

	// ABB
	// ACC

	if (B.x == C.x && A.y == (B.y+C.y)) {
		write(A.y + "\n");
		for (var i = 0; i < B.y; i++) {
			for (var j = 0; j < A.x; j++) write(A.letter);
			for (var j = 0; j < B.x; j++) write(B.letter);
			write("\n");
		}
		for (var i = 0; i < C.y; i++) {
			for (var j = 0; j < A.x; j++) write(A.letter);
			for (var j = 0; j < C.x; j++) write(C.letter);
			write("\n");
		}
		return true;
	}
	return false;
}

function main() {
	a = readline().split(" ").map(Number);

	var order = [0,1,2];
	do {
		// 2d array
		var b = [];
		for (var i = 0; i < 3; i++) {
			b.push([ a[2*order[i]], a[2*order[i]+1] ]);
		}

		for (var rotation_mask = 0; rotation_mask < 8; rotation_mask++) {
			var c = [];
			// rotate
			for (var i = 0; i < 3; i++)
				if (rotation_mask & (1<<i)) {
					c[i] = b[i].slice(0).reverse();
				} else {
					c[i] = b[i].slice();
				}
			result = solve(c, order);
			if (result) break;
		}
		if (result) break;
	} while (order.next_permutation());

	if (!result) {
		write("-1\n");
	}
}

main();


You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints.

For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists.

NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$.

var tc = Number(readline());
while(tc--)
{
	var arr = readline().split(' ').map(Number);
	var x = arr[0];
	var y = arr[1];
	var n = arr[2];
	n=n-y;
	print( Math.floor(n/x)*x + y );
}

function solve() {
   var xyn = read().split(' ').map(Number);
   var x = xyn[0], y = xyn[1], n = xyn[2];
   var z = n % x;
   var k = n + y - z;
   if (k > n) {
      k -= x;
   }
   write(k);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

function solve(x,y,n) {
    var res = (Math.floor(n/x)*x)-(x-y);
    return res+x <= n ? res+x : res;
}
var t = Number(readline());
while (t--) {
    var arr = readline().split(' ').map(Number);
    var x = arr[0];
    var y = arr[1];
    var n = arr[2];
    print(solve(x,y,n));
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [x, y, n] = readLine()
      .split(" ")
      .map((num) => parseInt(num));

    if (n % x < y) {
      console.log(n - ((n % x) + (x - y)));
    } else if (n % x > y) {
      console.log(n - ((n % x) - y));
    } else {
      console.log(n);
    }
  }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;

  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var x = one[0];
		var y = one[1];
		var n = one[2];
		if(n % x == y){
			output[i] = n;
		}else{
			if(n % x > y){
				output[i] = n - (n % x - y);
			}else{
				var tmp = y - (n % x);
				output[i] = n - x + tmp;
			}
		}
	}
	myout(myconv(output,9));
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      let s = data[i].trim().split(' ');
      let x = +s[0];
      let y = +s[1];
      let n = +s[2];
      let mod = n % x;
      if (mod === y) {
        console.log(n);
        i += 1;
        continue;
      }
      if (mod > y) {
        console.log(n - (mod - y));
        i += 1;
        continue;
      }
      n -= mod;
      mod = n % x;
      n -= (x - y);
      console.log(n);
      i += 1;
    }
  }

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const testCases = parseInt(readline());
    function getAnswer(x, y, n) {
        const quotient = Math.floor(n / x);
        const remainder = n % x;
        var starting_cand = (quotient - 3) * x + y;
        while (starting_cand <= n) {
            starting_cand += x;
        }
        return starting_cand - x;
    }
    for (var tc=0; tc<testCases; tc++) {
        [a, b, c] = readline().split(" ").map(number => parseInt(number));
        console.log(getAnswer(a, b, c));
    }
}

const readline = require('readline');

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

var lineCount = 0
var testCount = 0
var outputStr = ''

rl.on('line', (input) => {
    if (lineCount == 0) {
        // first line
        testCount = parseInt(input)
    }
    else if (lineCount >= testCount) {
        outputStr += compute(input) + '\n'
        console.log(outputStr)
        rl.close()
    }
    else {
        // data
        outputStr += compute(input) + '\n'
    }
    lineCount++
});

function compute(str) {
    list = str.split(' ')
    var x = parseInt(list[0])
    var y = parseInt(list[1])
    var n = parseInt(list[2])
    var r = n % x

    if(r>=y){
        return (n - r + y)
    }
    else{
        return (n - r - x + y)
    }
}


This is an interactive problem.I want to play a game with you...We hid from you a cyclic graph of $$$n$$$ vertices ($$$3 \le n \le 10^{18}$$$). A cyclic graph is an undirected graph of $$$n$$$ vertices that form one cycle. Each vertex belongs to the cycle, i.e. the length of the cycle (the number of edges in it) is exactly $$$n$$$. The order of the vertices in the cycle is arbitrary.You can make queries in the following way: "? a b" where $$$1 \le a, b \le 10^{18}$$$ and $$$a \neq b$$$. In response to the query, the interactor outputs on a separate line the length of random of two paths from vertex $$$a$$$ to vertex $$$b$$$, or -1 if $$$\max(a, b) > n$$$. The interactor chooses one of the two paths with equal probability. The length of the path —is the number of edges in it.You win if you guess the number of vertices in the hidden graph (number $$$n$$$) by making no more than $$$50$$$ queries.Note that the interactor is implemented in such a way that for any ordered pair $$$(a, b)$$$, it always returns the same value for query "? a b", no matter how many such queries. Note that the "? b a" query may be answered differently by the interactor.The vertices in the graph are randomly placed, and their positions are fixed in advance.Hacks are forbidden in this problem. The number of tests the jury has is $$$50$$$.

NoteIn the first example, the graph could look like this  The lengths of the simple paths between all pairs of vertices in this case are $$$1$$$ or $$$2$$$.   The first query finds out that one of the simple paths from vertex $$$1$$$ to vertex $$$2$$$ has a length of $$$1$$$.  With the second query, we find out that one of the simple paths from vertex $$$1$$$ to vertex $$$3$$$ has length $$$2$$$.  In the third query, we find out that vertex $$$4$$$ is not in the graph. Consequently, the size of the graph is $$$3$$$.

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

const rl = readline.createInterface({ input, output });

let i = 0, j = 1, a1 = 0, a2 = 0

const question = () => {
  if (i & 1) {
    console.log(`? ${j} ${j + 1}`)
  } else {
    console.log(`? ${j + 1} ${j}`)
  }
}
question()
rl.on('line', line => {
  if (i & 1) {
    a2 = BigInt(line)
    if(a1===-1||a2===-1){
      console.log(`! ${j-1}`)
      return
    }
    if (a1 !== a2) {
      console.log(`! ${a1 + a2}`)
      return
    }
    j++
  } else {
    a1 = BigInt(line)
  }
  i++
  question()
})

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // const n = yield* binarySearch(3n, 5n)
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(1, i + 1)
        const b = yield* ask(i + 1, 1)
        if (a === '-1') {
            return answer(i)
        } else if (a !== b) {
            return answer(BigInt(a) + BigInt(b))
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return r
}

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

const rl = readline.createInterface({ input, output });

let i = 0, j = 1, a1 = 0, a2 = 0

const question = () => {
  if (i & 1) {
    console.log(`? ${j} ${j + 1}`)
  } else {
    console.log(`? ${j + 1} ${j}`)
  }
}
question()
rl.on('line', line => {
  if (i & 1) {
    a2 = Number(line)
    if(a1===-1||a2===-1){
      console.log(`! ${j-1}`)
      return
    }
    if (a1 !== a2) {
      console.log(`! ${a1 + a2}`)
      return
    }
    j++
  } else {
    a1 = Number(line)
  }
  i++
  question()
})

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

const rl = readline.createInterface({ input, output });

let i = 0, j = 1, a1 = 0, a2 = 0

const question = () => {
  if (i & 1) {
    console.log(`? ${j} ${j + 1}`)
  } else {
    console.log(`? ${j + 1} ${j}`)
  }
}
question()
rl.on('line', line => {
  if (i & 1) {
    a2 = Number(line)
    if (a1 !== a2) {
      console.log(`! ${a1 + a2}`)
      return
    }
    j++
  } else {
    a1 = Number(line)
    if (a1 === -1) {
      console.log(`! ${j-1}`)
      return
    }
  }
  i++
  question()
})

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

const rl = readline.createInterface({ input, output });

let i = 0, j = 1, a1 = 0, a2 = 0

const question = () => {
  if (i & 1) {
    console.log(`? ${j} ${j + 1}`)
  } else {
    console.log(`? ${j + 1} ${j}`)
  }
}
question()
rl.on('line', line => {
  if (i & 1) {
    a2 = Number(line)
    if (a1 !== a2) {
      console.log(`! ${a1 + a2}`)
      return
    }
    j++
  } else {
    a1 = Number(line)
    if (a1 === -1) {
      console.log(`! ${j}`)
      return
    }
  }
  i++
  question()
})

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

const rl = readline.createInterface({ input, output });

let i = 0, j = 1, a1 = 0, a2 = 0

const question = () => {
  if (i & 1) {
    console.log(`? ${j} ${j + 1}`)
  } else {
    console.log(`? ${j + 1} ${j}`)
  }
}
question()
rl.on('line', line => {
  if (i & 1) {
    a2 = Number(line)
    if (a1 !== a2) {
      console.log(a1 + a2)
      return
    }
    j++
  } else {
    a1 = Number(line)
    if (a1 === -1) {
      console.log(j)
      return
    }
  }
  i++
  question()
})

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

const rl = readline.createInterface({ input, output });

let i = 2, j = 1

const question = () => {
  console.log(`? ${i} ${j}`)
}
question()
rl.on('line', line => {
  const a = Number(line)
  if (a === -1) {
    console.log(`! ${i - 1}`)
  } else if (a !== i - j) {
    console.log(`! ${a + i - j}`)
  } else {
    if (j + 1 < i) j++
    else i++
    question()
  }
})

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

const rl = readline.createInterface({ input, output });

let i = 1

const question = () => {
  console.log(`? ${i} ${i + 1}`)
}
question()
rl.on('line', line => {
  const a = Number(line)
  if (a === -1) {
    console.log(`! ${i - 1}`)
  } else if (a !== 1) {
    console.log(`! ${a + 1}`)
  } else {
    i++
    question()
  }
})

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

void async function main(){
for(let i=2;i<=50;i++){
 for(let j=1;j<i;j++){
 const d=i-j
 let ans=Number(await rl.question(`? ${j} ${i}`))
 if(ans!==d){
  console.log('! '+ans+d)
  return
 }
 ans=Number(await rl.question(`? ${i} ${j}`))
 if(ans!==d){
  console.log('! '+ans+d)
  return
 }
}
}
}()

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

void async function main(){
for(let i=2;i<=50;i++){
 for(let j=1;j<i;j++){
 const d=i-j
 let ans=Number(await rl.question(`? ${j} ${i}`))
 if(ans!==d){
  console.log(ans+d)
  return
 }
 ans=Number(await rl.question(`? ${i} ${j}`))
 if(ans!==d){
  console.log(ans+d)
  return
 }
}
}
}()

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    const log = []
    for (let i = 1; i <= 25; i++) {
        const u = rn(i + 1)
        const a = yield* ask(u, i + 3)
        const b = yield* ask(i + 3, u)
        if (a < 0 || b < 0) {
            return answer(i + 2)
        } else if (a !== b) {
            return answer(a + b)
        }
        log.push([u, i + 3, a, b].join(' '))
    }
    throw log.join(';')
}
function rn(n) {
    return Math.floor(Math.random() * n) + 1
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    for (let i = 1; i <= 25; i++) {
        const u = rn(i + 2)
        const a = yield* ask(u, i + 3)
        const b = yield* ask(i + 3, u)
        if (a < 0 || b < 0) {
            return answer(i + 2)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function rn(n) {
    return Math.floor(Math.random() * n) + 1
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(1, i + 3)
        const b = yield* ask(i + 3, 1)
        if (a < 0 || b < 0) {
            return answer(i + 2)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // hash v2
    // const n = yield* binarySearch(3n, 5n)
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(3, i + 3)
        const b = yield* ask(i + 3, 3)
        if (a < 0 || b < 0) {
            return answer(i + 2)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // hash v2
    // const n = yield* binarySearch(3n, 5n)
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(2, i + 1)
        const b = yield* ask(i + 1, 2)
        if (a < 0 || b < 0) {
            return answer(i)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // hash v2
    // const n = yield* binarySearch(3n, 5n)
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(1, i + 1)
        const b = yield* ask(i + 1, 1)
        if (a < 0 || b < 0) {
            return answer(i)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // const n = yield* binarySearch(3n, 5n)
    for (let i = 1; i <= 25; i++) {
        const a = yield* ask(1, i + 1)
        const b = yield* ask(i + 1, 1)
        if (a < 0 || b < 0) {
            return answer(i)
        } else if (a !== b) {
            return answer(a + b)
        }
    }
}
function answer(n) {
    console.log('! ' + n)
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // const n = yield* binarySearch(3n, 5n)
    const n = yield* binarySearch(3n, BigInt(1e9) * BigInt(1e9))
    console.log(`! ${n}`)
}
function* binarySearch(l, r) {
    while (l <= r) {
        const m = l + ((r - l) / 4n)
        const ok = (yield* ask(1, m)) > 0
        if (ok) {
            l = m + 1n
        } else {
            r = m - 1n
        }
    }
    return r
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    // input = yield 1
    const t = 1//+input
    for (let i = 0; i < t; i++) {
        // input = yield 1
        yield* solve()
    }
    process.exit(0)
}

function* solve() {
    // const n = yield* binarySearch(3n, 5n)
    const n = yield* binarySearch(3n, BigInt(1e9) * BigInt(1e9))
    console.log(`! ${n}`)
}
function* binarySearch(l, r) {
    while (l <= r) {
        const m = l + ((r - l) / 3n)
        const ok = (yield* ask(1, m)) > 0
        if (ok) {
            l = m + 1n
        } else {
            r = m - 1n
        }
    }
    return r
}
function* ask(a, b) {
    console.log(`? ${a} ${b}`)
    const r = yield 1
    return +r
}


3R2 - Standby for ActionOur dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. $$$n$$$"!The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).For each question JOE answers, if there are $$$s$$$ ($$$s > 0$$$) opponents remaining and $$$t$$$ ($$$0 \le t \le s$$$) of them make a mistake on it, JOE receives $$$\displaystyle\frac{t}{s}$$$ dollars, and consequently there will be $$$s - t$$$ opponents left for the next question.JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?

The first and single line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), denoting the number of JOE's opponents in the show.

Print a number denoting the maximum prize (in dollars) JOE could have. Your answer will be considered correct if it's absolute or relative error won't exceed $$$10^{-4}$$$. In other words, if your answer is $$$a$$$ and the jury answer is $$$b$$$, then it must hold that $$$\frac{|a - b|}{max(1, b)} \le 10^{-4}$$$.

NoteIn the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be $$$\displaystyle \frac{1}{2} + \frac{1}{1} = 1.5$$$ dollars.

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const n = readInt(input)

  let sum = 0
  for(let i = 1; i <= n; i++) {
    sum += (1 / i)
  }

  wr(sum)
}

let fs=require('fs');
let txt=fs.readFileSync(0,"utf-8").split(/[\n\r]/).filter(data=>data.length>0);

txt.forEach(data=>{
    doit(data*1);
});

function doit(data){
    let score=0;
    for (let index = data; index >0; index--) {
        score+=1/index;
    }
    console.log(score);
}

var val = readline().split(' ').map((val)=>{
    return parseInt(val);
})
var sum = 0;
for(var i = 0 ;i < val ;i++){
  sum += 1/(1+i);
}
print(sum);

var n = parseInt(readline(), 10),
    sum = 0;

for(var i=1; i<=n; i++) {
    sum += 1/i;
}

print(sum);

var n = readline().split(' ');
var ans = 0;
for(var k = 1; k <= n; k++) {
  ans += 1/k;
}
print(ans);

var num_oponents = readline();
var earns = [];
for (var t = 0; t < num_oponents; t++) {
  earns.push(1 / (num_oponents - t));
}
var sum = 0;
for(var i=0;i<earns.length;i++){
	sum = sum+earns[i];
}
print(sum);

var n = readline().split(' ');
var arr = 0;
for(var k = 1; k <= n; k++) {
  arr += 1/k;
}
print(k);


You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.

Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.

4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim

NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.

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

    function foo (a, b, c) {
        for (let i = 0; i<a.length; i++) {
            if (c[i] !== a[i] && c[i] !== b[i]) return 'NO';
        }
        return 'YES'
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let a = lines[testCount * 3 - 2].split('');
        let b = lines[testCount * 3 - 1].split('');
        let c = lines[testCount * 3].split('');

        let result = foo(a, b, c);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

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

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

  if (c % 3 !== 0) {
    arr.push(str);
    c++;
    return;
  }

  let r = 'YES';
  for (let j = 0; j < arr[0].length; j++) {
    if (arr[0][j] !== str[j] && arr[1][j] !== str[j]) {
      r = 'NO';
      break;
    }
  }

  arr = [];
  console.log(r);

  c++;
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readline();

    while(t--)
    {
        let a = readline();
        let b = readline();
        let c = readline();
        let cnt = 0;

        for(let i = 0;i<a.length;i++)
        {
           if(c[i]==a[i]||c[i]==b[i]) cnt++;
        }

        if(cnt==a.length) console.log("YES");
        else console.log("NO");
    }

}

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++){
    const [a, b, c] = [lines[j*3+1], lines[j*3+2], lines[j*3+3]]
    let isOk = true
    for (let i = 0; i<c.length; i++) {
      if (c[i] === a[i] || c[i] === b[i]) {

      } else {
        isOk = false
        break;
      }
    }
    console.log(isOk ? 'YES' : 'NO')
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

var tests= readline();

for(var n=0;n<tests;n++){
    //print(`n: ${n} tests:${tests}`)
    var res="YES";
    var a = readline();
    var b = readline();
    var c = readline();
    for(var i=0;i<a.length;i++){
        if(a[i]===c[i]||b[i]===c[i]){continue;}
        res="NO";break;
    }//go through each character of str a

    print(res);
}//tests loop

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var t = myconv(next(),1);
  var output = new Array(t);
  for(var i = 0; i < t; i++){
      var a = myconv(next(),6);
      var b = myconv(next(),6);
      var c = myconv(next(),6);
      var isNG = false;
      for(var j = 0; j < a.length; j++){
          if((a[j] != b[j] && (a[j] == c[j] || b[j] == c[j])) || (a[j] == c[j] && a[j] == b[j])){

          }else{
              isNG = true;
              break;
          }
      }
      if(isNG){
          output[i] = "NO";
      }else{
          output[i] = "YES";
      }

  }
  myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var t = myconv(next(),1);
  var output = new Array(t);
  for(var i = 0; i < t; i++){
      var a = myconv(next(),6);
      var b = myconv(next(),6);
      var c = myconv(next(),6);
      var isNG = false;
      for(var j = 0; j < a.length; j++){
          if(a[j] != b[j] && (a[j] == c[j] || b[j] == c[j])){

          }else{
              isNG = true;
              break;
          }
      }
      if(isNG){
          output[i] = "NO";
      }else{
          output[i] = "YES";
      }

  }
  myout(myconv(output,9));
}


Nastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.In total, Nastya dropped $$$n$$$ grains. Nastya read that each grain weighs some integer number of grams from $$$a - b$$$ to $$$a + b$$$, inclusive (numbers $$$a$$$ and $$$b$$$ are known), and the whole package of $$$n$$$ grains weighs from $$$c - d$$$ to $$$c + d$$$ grams, inclusive (numbers $$$c$$$ and $$$d$$$ are known). The weight of the package is the sum of the weights of all $$$n$$$ grains in it.Help Nastya understand if this information can be correct. In other words, check whether each grain can have such a mass that the $$$i$$$-th grain weighs some integer number $$$x_i$$$ $$$(a - b \leq x_i \leq a + b)$$$, and in total they weigh from $$$c - d$$$ to $$$c + d$$$, inclusive ($$$c - d \leq \sum\limits_{i=1}^{n}{x_i} \leq c + d$$$).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$  — the number of test cases.  The next $$$t$$$ lines contain descriptions of the test cases, each line contains $$$5$$$ integers: $$$n$$$ $$$(1 \leq n \leq 1000)$$$  — the number of grains that Nastya counted and $$$a, b, c, d$$$ $$$(0 \leq b < a \leq 1000, 0 \leq d < c \leq 1000)$$$  — numbers that determine the possible weight of one grain of rice (from $$$a - b$$$ to $$$a + b$$$) and the possible total weight of the package (from $$$c - d$$$ to $$$c + d$$$).

For each test case given in the input print "Yes", if the information about the weights is not inconsistent, and print "No" if $$$n$$$ grains with masses from $$$a - b$$$ to $$$a + b$$$ cannot make a package with a total mass from $$$c - d$$$ to $$$c + d$$$.

NoteIn the first test case of the example, we can assume that each grain weighs $$$17$$$ grams, and a pack $$$119$$$ grams, then really Nastya could collect the whole pack.In the third test case of the example, we can assume that each grain weighs $$$16$$$ grams, and a pack $$$128$$$ grams, then really Nastya could collect the whole pack.In the fifth test case of the example, we can be assumed that $$$3$$$ grains of rice weigh $$$2$$$, $$$2$$$, and $$$3$$$ grams, and a pack is $$$7$$$ grams, then really Nastya could collect the whole pack.In the second and fourth test cases of the example, we can prove that it is impossible to determine the correct weight of all grains of rice and the weight of the pack so that the weight of the pack is equal to the total weight of all collected grains.

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline().split(" ");
  var n = parseInt(input[0]);
  var a = parseInt(input[1]);
  var b = parseInt(input[2]);
  var c = parseInt(input[3]);
  var d = parseInt(input[4]);
  var minGrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;

  if (
    maxGrainWeight * n < minTotalWeight ||
    minGrainWeight * n > maxTotalWeight
  ) {
    print("No");
  } else print("Yes");
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var tmp = nextIntArray();
		var n = tmp[0];
		var a = tmp[1];
		var b = tmp[2];
		var c = tmp[3];
		var d = tmp[4];
		var singleMin = (a - b) * n;
		var singleMax = (a + b) * n;
		var packMin = c - d;
		var packMax = c + d;
		if(singleMin > packMax){
			output[i] = "NO";
		}else if(singleMax < packMin){
			output[i] = "NO";
		}else{
			output[i] = "YES";
		}
	}
	myout(myconv(output,9));
}

// your code goes here
var tst;
tst = parseInt(readline());

for(var tc = 0; tc < tst; tc++)
{
    var input = readline().split(" ");
    var n = parseInt(input[0]);
    var a = parseInt(input[1]);
    var b = parseInt(input[2]);
    var c = parseInt(input[3]);
    var d = parseInt(input[4]);
    var minGrainWeight = a - b;
    var maxGrainWeight = a + b;
    var minTotalWeight = c - d;
    var maxTotalWeight = c + d;
    if(maxGrainWeight * n < minTotalWeight ||
        minGrainWeight * n > maxTotalWeight) print("No");
    else print("Yes");
}

var n = Number(readline());

var inp ;

for (var i = 0; i < n ; i++){
    inp = readline().split(' ').map(cur => Number(cur));
    var gl = (inp[1] - inp [2])*inp[0];
    var gu = (inp[1] + inp [2])*inp[0];
    var bl = inp[3] - inp [4];
    var bu = inp[3] + inp [4];

((gu >= bu || (gu <= bu && gu >= bl)) && (gl <= bl || (gl <= bu && gl >= bl)))?print("YES"):print("NO");

}

var t = parseInt(readline());

function mapper(s) { return +s; }

for(var qq = 0; qq < t; qq++) {
    var line = readline().split(' ').map(mapper);
    var n = line[0];
    var a = line[1];
    var b = line[2];
    var c = line[3];
    var d = line[4];

    var minW = a - b;
    var maxW = a + b;

    var minC = c - d;
    var maxC = c + d;

    if (maxW * n < minC || minW * n > maxC) {
        print('No');
    } else {
        print('Yes');
    }
}

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        let args = thing.split(" ").map(parseFloat)
        console.log(nastya(args[0], args[1], args[2], args[3], args[4]))
    }

})

function nastya(n, a, b, c, d) {
    const iWeightLowerBound = (a - b) * n
    const iWeightUpperBound = (a + b) * n

    const totalWeightUpperBound = c + d
    const totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "No";
    }

    return "Yes";

}

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

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

  let [n, a, b, c, d] = data.split(' ').map(Number);
  let x = (a - b) * n;
  let y = (a + b) * n;

  if ( (x >= c - d || y >= c - d) && (x <= c + d || y <= c + d) ) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  count++;
});

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () => x[y++];

// ************************ Code Start ***************************

function main() {

 var Tc = parseInt(readline());
  while (Tc--) {
    var ar1 = readline().split(" ").map((x) => parseInt(x));
    var n = ar1[0], a = ar1[1], b = ar1[2], c = ar1[3], d = ar1[4];
    if ((a - b) * n > c + d || (a + b) * n < c - d) print("NO");
    else print("YES");
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    var range = readline();
    for(let r=0;r<range;r++) {
        var data = readline().split(" ").map(x => parseInt(x));
        var n = data[0];
        var x1 = data[1] - data[2];
        var x2 = data[1] + data[2];
        var y1 = data[3] + data[4];
        var y2 = data[3] - data[4];

        if(n * x1 > y1 || n * x2 < y2) {
            console.log("No");
        } else {
            console.log("Yes");
        }

    }

}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var n = parseInt(readline());
  var a = parseInt(readline());
  var b = parseInt(readline());
  var c = parseInt(readline());
  var d = parseInt(readline());
  var minGrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;
  var result = "Yes";
  if (
    maxGrainWeight * n < minTotalWeight ||
    minGrainWeight * n > maxTotalWeight
  )
    result = "No";
  print(result);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var n = parseInt(readline());
  var a = parseInt(readline());
  var b = parseInt(readline());
  var c = parseInt(readline());
  var d = parseInt(readline());
  var mingrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;
  var result = "No";
  for (var i = mingrainWeight; i <= maxGrainWeight; i++) {
    if (i * n >= minTotalWeight && i <= maxTotalWeight) {
      result = "Yes";
      break;
    }
  }
  print(result);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var n = parseInt(readline());
  var a = parseInt(readline());
  var b = parseInt(readline());
  var c = parseInt(readline());
  var d = parseInt(readline());
  var minGrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;

  if (
    maxGrainWeight * n < minTotalWeight ||
    minGrainWeight * n > maxTotalWeight
  ) {
    print("No");
  } else print("Yes");
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var n = parseInt(readline());
  var a = parseInt(readline());
  var b = parseInt(readline());
  var c = parseInt(readline());
  var d = parseInt(readline());
  var minGrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;
  var result = "Yes";
  if (
    maxGrainWeight * n < minTotalWeight ||
    minGrainWeight * n > maxTotalWeight
  ) {
    result = "No";
  }
  print(result);
}

var t = parseInt(readline());
for (var tc = 0; i < t; tc++) {
  var n = parseInt(readline());
  var a = parseInt(readline());
  var b = parseInt(readline());
  var c = parseInt(readline());
  var d = parseInt(readline());
  var mingrainWeight = a - b;
  var maxGrainWeight = a + b;
  var minTotalWeight = c - d;
  var maxTotalWeight = c + d;
  var result = "No";
  for (var i = mingrainWeight; i <= maxGrainWeight; i++) {
    if (i * n >= minTotalWeight && i <= maxTotalWeight) {
      result = "Yes";
      break;
    }
  }
  print(result);
}

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        let args = thing.split(" ").map(parseFloat)
        console.log(nastya(args))
    }

})

function nastya(n, a, b, c, d) {
    const iWeightLowerBound = (a - b) * n
    const iWeightUpperBound = (a + b) * n

    const totalWeightUpperBound = c + d
    const totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "No";
    }

    return "Yes";

}

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

    for (let i = 1; i < lines.length; i++) {
        let thing = lines[i]
        console.log(thing.split(" "))
    }

})

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        let args = thing.split(" ").map(parseFloat)
        console.log(nastya(args), args)
    }

})

function nastya(n, a, b, c, d) {
    var iWeightLowerBound = (a - b) * n
    var iWeightUpperBound = (a + b) * n

    var totalWeightUpperBound = c + d
    var totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "No";
    }

    return "Yes";

}

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

    for (let i = 1; i < lines.length; i++) {
        console.log("lines[i]")
    }

})

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        let args = thing.split(" ").map(parseFloat)
        console.log(nastya(args), args)
    }

})

function nastya(n, a, b, c, d) {
    const iWeightLowerBound = (a - b) * n
    const iWeightUpperBound = (a + b) * n

    const totalWeightUpperBound = c + d
    const totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "No";
    }

    return "Yes";

}

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        console.log(nastya(thing.split(" ").map(parseFloat)))
    }

})

function nastya(n, a, b, c, d) {
    var iWeightLowerBound = (a - b) * n
    var iWeightUpperBound = (a + b) * n

    var totalWeightUpperBound = c + d
    var totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return false;
    }

    return true;

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    console.log("hello", lines);

    console.log(lines[0])

})

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

    for (let i = 1; i < lines.length; i++) {
        let thing = lines[i]
        console.log(thing.split(" ").map(parseFloat))
    }

})

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

    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        console.log(nastya(thing.split(" ").map(parseFloat)))
    }

})

function nastya(n, a, b, c, d) {
    var iWeightLowerBound = (a - b) * n
    var iWeightUpperBound = (a + b) * n

    var totalWeightUpperBound = c + d
    var totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "NO";
    }

    return "YES";

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    console.log("hello", lines);
})

function nastya(n, a, b, c, d) {
    var iWeightLowerBound = (a - b) * n
    var iWeightUpperBound = (a + b) * n

    var totalWeightUpperBound = c + d
    var totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return false;
    }

    return true;

}

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

    for (let i = 1; i < lines.length; i++) {
        let thing = lines[i]
        console.log(thing.split(" ").map(parseInt))
    }

})

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

    console.log(nastya(11, 11, 10, 234, 2))
    for (let i = 1; i < lines.length - 1; i++) {
        let thing = lines[i]
        let args = thing.split(" ").map(parseFloat)
        console.log(nastya(args))
    }

})

function nastya(n, a, b, c, d) {
    const iWeightLowerBound = (a - b) * n
    const iWeightUpperBound = (a + b) * n

    const totalWeightUpperBound = c + d
    const totalWeightLowerBound = c - d

    if ((totalWeightUpperBound < iWeightLowerBound) || (iWeightUpperBound < totalWeightLowerBound)) {
        return "No";
    }

    return "Yes";

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    var range = readline();
    for(let r=0;r<range;r++) {
        var data = readline().split(" ").map(x => parseInt(x));

        var x1 = data[1] - data[2];
        var x2 = data[1] + data[2];
        var y1 = data[3] + data[4];
        var y2 = data[3] - data[4];

        if(Math.floor(y1/x1) === data[0]) {
            console.log("Yes");
        } else if(Math.ceil(y2/x2) === data[0]) {
            console.log("Yes");
        } else {
            console.log("No");
        }

    }

}


An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full.Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000"  →  "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address.Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below:  "a56f:00d3:0000:0124:0001:0000:0000:0000"  →  "a56f:00d3:0000:0124:0001::";  "a56f:0000:0000:0124:0001:0000:1234:0ff0"  →  "a56f::0124:0001:0000:1234:0ff0";  "a56f:0000:0000:0000:0001:0000:1234:0ff0"  →  "a56f:0000::0000:0001:0000:1234:0ff0";  "a56f:00d3:0000:0124:0001:0000:0000:0000"  →  "a56f:00d3:0000:0124:0001::0000";  "0000:0000:0000:0000:0000:0000:0000:0000"  →  "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon.The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short.You've got several short records of IPv6 addresses. Restore their full record.

The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100). Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.

For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.

var inp = +readline(), ip, count, i, ans, x;

while (inp > 0) {
    inp--;
    ip = readline();
    count = ip === "::" ? 0 : ip.replace(/^::|::$/g, "").split(/::?/g).length;

    if (count < 8) {
        ip = ip.replace("::", function() {
            var ins = ":";
            for (i = 0; i < 8 - count; i++) {
                ins += "0000:";
            }
            return ins;
        });
        ip = ip.replace(/^:/, "").replace(/:$/, "");
    }

    ip = ip.split(":");
    ans = "";
    for (x in ip) {
        y = ip[x];
        while (y.length < 4) y = "0" + y;
        ans += y + ":";
    }
    print(ans.substring(0, ans.length - 1));
}

var addressCount = Number(readline());
while (addressCount--) {
  var parts = readline().split(":");
  if (!parts[0].length) parts.shift();
  if (!parts[parts.length - 1].length) parts.pop();
  var index = parts.indexOf("");
  if (index != -1) parts.splice(index, 1, ...new Array(9 - parts.length).fill("0000"));
  print(parts.map(x => "0".repeat(4 - x.length) + x).join(":"));
}

var n = Number(readline());
while (n--) {
    var str = readline();
    var arr = str.split(':');
    var result = '';
    var flag = false;
    for (var i = 0; i < arr.length; i++) {
        if (arr[i].length === 0 && !flag) {
            for (var j = 0; j < 9 - arr.length; j++) result += '0000:';
            flag = true;
        } else {
            if (arr[i].length === 4) result += ((arr[i]) + ':');
            else if (arr[i].length === 3) result += ('0' + arr[i]+':');
            else if (arr[i].length === 2) result += ('00' + arr[i]+':');
            else if (arr[i].length === 1) result += ('000' + arr[i]+':');
            else if (arr[i].length === 0) result += ('0000:');
        }
    }
    write(result.substr(0,result.length - 1)+'\n');
}


Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.

The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.

Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".

Note  First example: you can simply swap two letters in string "ab". So we get "ba".  Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  const str1 = readLine();
  const str2 = readLine();
  let count = 0;

  const r1 = str1.split("").sort().join("");
  const r2 = str2.split("").sort().join("");

  if (r1 === r2) {
    for (let i = 0; i < str1.length; i++) {
      const [char1, char2] = [str1[i], str2[i]];
      if (char1 !== char2) count++;
    }
    if (count === 2) {
      console.log("YES");
    } else {
      console.log("NO");
    }
  } else console.log("NO");
}

first = readline();
second = readline();
i = -1;
var pos = -1;
var flag = undefined;

if (first.length != second.length) print('NO');
else {
    while (++i < first.length) {
        if (first[i] != second[i] && flag !== undefined) { flag = false; break; }
        if (first[i] != second[i] && pos === -1) pos = i;
        else if (first[i] != second[i] && pos > -1) {
            flag = (first[i] == second[pos] && second[i] == first[pos]);
            if (!flag) break;
        }
    }
    print(flag ? 'YES' : 'NO');
}


This is yet another problem dealing with regular bracket sequences.We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.

The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.

Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".

var line = readline();

var l = 0;
var la=[];
var max = 0;
var c = 0;
for(var i=0;i<line.length;i++){
	if(line[i] == '('){
		if( la[l] === undefined){
			la[l]=i;
		}
		l++;
	}else{
		l--;
		if(l>=0){
			var j = i-la[l]+1;
			if( j > max){
				max = j;
				c=1;
			}else if( j==max){
				c++;
			}
		}
		for(var k=l+1; la[k]!==undefined; k++){
			la[k]=undefined;
		}
	}
	if(l<0){
		l=0;
		la=[];
	}
}

if(max==0){
	c=1;
}
print(max+' '+c);

var line = readline();

var l = 0;
var la=[];
var max = 0;
var c = 0;
for(var i=0;i<line.length;i++){
	if(line[i] == '('){
		if( la[l] === undefined){
			la[l]=i;
		}
		l++;
	}else{
		l--;
		if(l>=0){
			var j = i-la[l]+1;
			if( j > max){
				max = j;
				c=1;
			}else if( j==max){
				c++;
			}
		}
		la[l+1] = undefined;
	}
	if(l<0){
		l=0;
		la=[];
	}
}

if(max==0){
	c=1;
}
print(max+' '+c);

// Generated by CoffeeScript 1.4.0
(function() {
  var c, i, istack, len, match, max_count, max_len, min_i, mlp, s;

  s = readline();

  match = new Array(s.length);

  max_len = 0;

  max_count = 0;

  istack = [];

  for (i in s) {
    c = s[i];
    if (c === '(') {
      istack.push(+i);
    } else if (istack.length > 0) {
      mlp = istack.pop();
      min_i = match[mlp - 1] != null ? match[mlp - 1] : mlp;
      match[+i] = min_i;
      len = +i - min_i + 1;
      if (len > max_len) {
        max_len = len;
        max_count = 1;
      } else if (len === max_len) {
        max_count++;
      }
    }
  }

  if (max_count === 0) {
    print("0 1");
  } else {
    print(max_len + ' ' + max_count);
  }

}).call(this);

var i, j, lb = [], counter = 0, max = [0], input = readline().split('');

function update(){
    if (counter > max[0]) {
        max = [counter];
    } else if (counter && counter == max[0]) {
        max.push(counter);
    }
    counter = 0;
}

for (i=0; i<input.length; i++){
    if (input[i] === '(') {
        lb.push(i);
    } else if (input[i] === ')') {
        if (lb.length) {
            input[i] = '.';
            input[lb.pop()] = '.';
        }
    }
}

for (i=0; i<input.length; i++){
    if (input[i] === '.'){
        counter++;
    } else {
        update();
    }
}

if (counter) update();

print(max[0] + ' ' + max.length);

var i, lb = [], counter = 0, max = [0], input = readline().split('');

function update(){
    if (counter > max[0]) {
        max = [counter];
    } else if (counter && counter == max[0]) {
        max.push(counter);
    }
    counter = 0;
}

for (i = 0; i < input.length; i++){
    if (input[i] === '(') {
        lb.push(i);
    } else {
        if (lb.length) {
            input[i] = '.';
            input[lb.pop()] = '.';
        }
    }
}

for (i = 0; i < input.length; i++){
    if (input[i] === '.'){
        counter++;
    } else {
        update();
    }
}

if (counter) update();

print(max[0] + ' ' + max.length);

var line = readline();

var l = 0;
var la=[];
var max = 0;
var c = 0;
for(var i=0;i<line.length;i++){
	if(line[i] == '('){
		if( la[l] === undefined){
			la[l]=i;
		}
		l++;
	}else{
		l--;
		if(l>=0){
			var j = i-la[l]+1;
			if( j > max){
				max = j;
				c=1;
			}else if( j==max){
				c++;
			}
		}
	}
	if(l<0){
		l=0;
		la=[];
	}
}

if(max==0){
	c=1;
}
print(max+' '+c);

var line = readline();

var l = 0;
var a = 0;
var ret1 = 0;
var ret2 = 0;
for( var i=0; i<line.length; i++){
	if(line[i]=='('){
		l++;
	}else{
		l--;
	}

	if(l<0){
		if( a>ret1 ){
			ret1=a;
			ret2=1;
		}else if(a==ret1){
			ret2++
		}
		a = 0;
		l = 0;
	}else{
		a++;
	}
}

if(l==0){
	if( a>ret1 ){
		ret1=a;
		ret2=1;
	}else if(a==ret1){
		ret2++
	}
}else if(l>0&&ret1==0){
	ret1=0;
	ret2=1;
}

print(ret1+' '+ret2)

var line = readline();

function go(line){
	var l = 0;
	var ret1 = 0;
	var ret2 = 0;
	var ll = [];
	for( var i=0; i<line.length; i++){
		if(line[i]=='('){
			l++;
			ll.push(i);
		}else{
			//if(l>=0){
				var j = i-ll.pop()+1;
				if(j>ret1){
					ret1=j;
					ret2=1;
				}else if(j==ret1){
					ret2++;
				}
			//}
			l--;
		}

		if(l<0){
			l = 0;
			ll=[];
		}
	}
	return [ret1, ret2];
}

var ret = go(line.split(''));
if(ret[0]==0){
	ret[1]=1;
}
print(ret[0]+' '+ret[1]);

var line = readline();

function go(line){
	var l = 0;
	var ret1 = 0;
	var ret2 = 0;
	var ll = [];
	for( var i=0; i<line.length; i++){
		if(line[i]=='('){
			l++;
			ll.push(i);
		}else{
			if(l>0){
				var j = i-ll.pop()+1;
				if(j>ret1){
					ret1=j;
					ret2=1;
				}else if(j==ret1){
					ret2++;
				}
			}
			l--;
		}

		if(l<0){
			l = 0;
			ll=[];
		}
	}
	print(ll)
	return [ret1, ret2];
}

line = line.split('');
line.unshift('(');
line.push(')');
var ret = go( line );
ret[0] -= 2;
if(ret[0]==0){
	ret[1]=1;
}
print(ret[0]+' '+ret[1]);

var i, lb = [0,0], max = 0, rpt = 0, input = readline();

function closing(){
    rpt++;
    if (lb[1] > max) {
        max = lb[1];
        lb[1] = 0;
    }
}

for (i=0; i<input.length; i++){
    if (input[i] === '(') {
        lb[0]++;
    } else if (input[i] === ')') {
        if (lb[0] > 0) {
            lb[0]--;
            lb[1]+=2;
        } else {
            if (lb[1] > 0) {
                closing();
            }
        }
    }
}

if (lb[1] > 0) {
    closing();
}

if (max)
    print(max + ' ' + rpt);
else
    print('0 1');

var i, lb = [0,0], max = 0, rpt = 0, input = readline();

function closing(){
    rpt++;
    if (lb[1] > max) {
        max = lb[1];
        lb[1] = 0;
    }
}

for (i=0; i<input.length; i++){
    if (input[i] === '(') {
        lb[0]++;
        lb[1]++;
    } else if (input[i] === ')') {
        if (lb[0] > 0) {
            lb[0]--;
            lb[1]++;
        } else {
            if (lb[1] > 0) {
                closing();
            }
        }
    }
}

if (lb[1] > 0) {
    closing();
}

if (max)
    print(max + ' ' + rpt);
else
    print('0 1');