You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.It is allowed to leave a as it is.

The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.

Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsBigger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    var origE = e;
    if (bIsLonger || typeof prevIsBigger === 'number') {
        // print("wtf..." + prevIsBigger)
        e = 9;
    }
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            // print(result + e);
            return e;
        }
        e--;
        if (prevIsBigger === false) {
            prevIsBigger = result.length;
        }
    }
    var prev = result[result.length - 1];
    map[prev]++;
    // print("ye boi" + prevIsBigger + " " + (result.length))
    if (prevIsBigger === result.length) {
        prevIsBigger = false;
    }
    result = result.substring(0, result.length - 1);
    // print(result);
    //THIS S***!!!!!!!!!!
    var q = findMax(prev - 1);
    result += q;
    // print(">> " + result);
    prevIsBigger = result.length;
    return findMax(origE);

}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => {
    var c = findMax(e);
    result += c;
    //2 lines above are not the same as below!!!!!!
    //result += findMax(e);
    // print("> " + result)
});

print(result);

// if (!readline) { var { readline, print } = require('./index.js'); }

const
	ZERO_CHAR_CODE = '0'.charCodeAt();

/**
 * Returns an array of length 10
 * that stores the number of occurrences of each digit in the number
 * @param { string } number
 * @returns { [number] }
 */
function getDigitsNumber(num) {
	var result = new Array(10).fill(0);
	for (var char of num) {
		var digit = char.charCodeAt() - ZERO_CHAR_CODE;
		if (digit >= 0 && digit <= 9) {
			result[digit]++;
		}
	}
	return result;
}

/**
 * Returns an array of digits of number
 * @param { string } number
 * @returns { [number] }
 */
function getDigits(num) {
	var result = new Array(num.length).fill(0);
	for (var i = 0; i < num.length; i++) {
		var digit = num.charCodeAt(i) - ZERO_CHAR_CODE;
		if (digit < 0 || digit > 9) throw 'is not number';
		result[i] = digit;
	}
	return result;
}

/**
 * Returns a number (as string) consisting of digits of a and not exceeding b
 * @param { string } a
 * @param { string } b
 * @returns { string }
 */
function rearrangeNumbers(a, b) {
	var aNums = getDigitsNumber(a);
	var bNums = getDigits(b);
	var result = '';
	if (a.length != b.length) {
		for (var i = 9; i >= 0; i--) result += ('' + i).repeat(aNums[i]);
	} else {
		var rNums = new Array(a.length);
		var ind, lastInd;
		ind = lastInd = 0;
		var isLess = false;
		for (var i = 0; i < a.length; i++) {
			var needToBreak = true;
			var iFrom = isLess ? 9 : bNums[i];
			for (var j = iFrom; j >= 0; j--) {
				if (aNums[j] > 0) {
					if (j < bNums[i]) {
						isLess = true;
						lastInd = i;
					}
					ind = i;
					rNums[i] = j;
					aNums[j]--;
					needToBreak = false;
					break;
				}
			}
			if (needToBreak) break;
		}
		var backStep = false;
		while (ind + 1 < a.length) {
			var needToStepBack = true;
			var iFrom = backStep ? rNums[ind + 1] - 1 : isLess ? 9 : bNums[ind + 1];
			for (var i = iFrom; i >= 0; i--) {
				if (aNums[i] > 0) {
					aNums[i]--;
					ind++;
					if (!isLess && i < bNums[ind]) {
						isLess = true;
						lastInd = ind;
					}
					rNums[ind] = i;
					backStep = false;
					needToStepBack = false;
					break;
				}
			}
			if (needToStepBack) {
				aNums[rNums[ind]]++;
				ind--;
				backStep = true;
				// if (isLess && ind < lastInd) {
				if (isLess && ind == lastInd) {
					isLess = false;
				}
			}
		}
		for (var i = 0; i < a.length; i++) {
			result += '' + rNums[i]
		}
	}
	return result;
}

function main() {
	var a = readline();
	var b = readline();
	print(rearrangeNumbers(a, b));
}

main();

a = readline();
b = readline();
cnt = Array(10).fill(0);
for (c of a) cnt[c]++;
lo = hi = "";
for (c of a.length < b.length ? "9999999999999999999" : b) {
    for (i = c - 1; i >= 0; i--)
        if (cnt[i]) {
            lo = hi + i;
            cnt[i]--;
            for (j = 9; j >= 0; j--) {
                for (k = cnt[j]; k; k--) lo += j;
            }
            cnt[i]++;
            break;
        }
    if (!cnt[c]) break;
    hi += c;
    cnt[c]--;
}
print(lo.length > hi.length ? lo : hi);

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsBigger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    var origE = e;
    if (bIsLonger || prevIsBigger) {
        e = 9;
    }
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            // print(result + e);
            return e;
        }
        e--;
        if (!prevIsBigger) {
            prevIsBigger = result.length - 1;
        }
    }
    var prev = result[result.length - 1];
    // print("===");
    map[prev]++;
    if (prevIsBigger >= result.length - 2) {
        prevIsBigger = false;
    }
    result = result.substring(0, result.length - 1);
    // print(result);
    result += findMax(prev - 1);
    // print(">> " + result);
    prevIsBigger = result.length - 2;
    return findMax(origE);

}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => {
    var c = findMax(e);
    result += c;
    //2 lines above are not the same as below!!!!!!
    //result += findMax(e);
    // print("> " + result)
});

print(result);

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsLonger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    if (bIsLonger || prevIsLonger) {
        e = 9;
    }
    var origE = e;
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            if (origE === e) {
                prevIsLonger = false;
            }
            return e;
        }
        e--;
        prevIsLonger = true;
        if (e < 0) {
            e = 9;
        }
    }
}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => result += findMax(e));

print(result);

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsBigger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    var origE = e;
    if (bIsLonger || typeof prevIsBigger === 'number') {
        // print("wtf..." + prevIsBigger)
        e = 9;
    }
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            // print(result + e);
            return e;
        }
        e--;
        if (prevIsBigger === false) {
            prevIsBigger = result.length;
        }
    }
    var prev = result[result.length - 1];
    // print("===");
    // if(result) {
    //
    //     print(result);
    // }
    map[prev]++;
    if (prevIsBigger >= result.length - 1) {
        prevIsBigger = false;
    }
    result = result.substring(0, result.length - 1);
    // print(result);
    result += findMax(prev - 1);
    // print(">> " + result);
    prevIsBigger = result.length - 2;
    return findMax(origE);

}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => {
    var c = findMax(e);
    result += c;
    //2 lines above are not the same as below!!!!!!
    //result += findMax(e);
    // print("> " + result)
});

print(result);

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsBigger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    var origE = e;
    if (bIsLonger || prevIsBigger) {
        e = 9;
    }
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            if (origE === e) {
                prevIsBigger = false;
            }
            return e;
        }
        e--;
        prevIsBigger = true;
    }
    map[result[result.length - 1]]++;
    var prev = result[result.length - 1];
    result = result.substring(0, result.length - 1);
    result += findMax(prev - 1);
    return findMax(origE - 1);

}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => result += findMax(e));

print(result);

var aOrig = readline();
var bOrig = readline();
var bIsLonger = false;
var prevIsLonger = false;

if (aOrig.length < bOrig.length) {
    bOrig = bOrig.substr(0, aOrig.length);
    bIsLonger = true;
}

var a = aOrig.split('');
var b = bOrig.split('');

var map = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
};

var result = '';

function findMax(e) {
    var origE = e;
    if (bIsLonger || prevIsLonger) {
        e = 9;
    }
    while(e > -1) {
        if (map[e]) {
            map[e]--;
            if (origE === e) {
                prevIsLonger = false;
            }
            return e;
        }
        e--;
        prevIsLonger = true;
        if (e < 0) {
            e = 9;
        }
    }
}

a.forEach(e => {
    map[e]++;
});
b.forEach(e => result += findMax(e));

print(result);

// if (!readline) { var { readline, print } = require('./index.js'); }

const
	ZERO_CHAR_CODE = '0'.charCodeAt();

/**
 * Returns an array of length 10
 * that stores the number of occurrences of each digit in the number
 * @param { string } number
 * @returns { [number] }
 */
function getDigitsNumber(num) {
	var result = new Array(10).fill(0);
	for (var char of num) {
		var digit = char.charCodeAt() - ZERO_CHAR_CODE;
		if (digit >= 0 && digit <= 9) {
			result[digit]++;
		}
	}
	return result;
}

/**
 * Returns an array of digits of number
 * @param { string } number
 * @returns { [number] }
 */
function getDigits(num) {
	var result = new Array(num.length).fill(0);
	for (var i = 0; i < num.length; i++) {
		var digit = num.charCodeAt(i) - ZERO_CHAR_CODE;
		if (digit < 0 || digit > 9) throw 'is not number';
		result[i] = digit;
	}
	return result;
}

/**
 * Returns a number (as string) consisting of digits of a and not exceeding b
 * @param { string } a
 * @param { string } b
 * @returns { string }
 */
function rearrangeNumbers(a, b) {
	var aNums = getDigitsNumber(a);
	var bNums = getDigits(b);
	var result = '';
	if (a.length != b.length) {
		for (var i = 9; i >= 0; i--) result += ('' + i).repeat(aNums[i]);
	} else {
		var rNums = new Array(a.length);
		var ind, lastInd;
		ind = lastInd = 0;
		var isLess = false;
		for (var i = 0; i < a.length; i++) {
			var needToBreak = true;
			var iFrom = isLess ? 9 : bNums[i];
			for (var j = iFrom; j >= 0; j--) {
				if (aNums[j] > 0) {
					if (j < bNums[i]) {
						isLess = true;
						lastInd = i;
					}
					ind = i;
					rNums[i] = j;
					aNums[j]--;
					needToBreak = false;
					break;
				}
			}
			if (needToBreak) break;
		}
		var backStep = false;
		while (ind + 1 < a.length) {
			var needToStepBack = true;
			var iFrom = backStep ? rNums[ind + 1] - 1 : isLess ? 9 : bNums[ind + 1];
			for (var i = iFrom; i >= 0; i--) {
				if (aNums[i] > 0) {
					aNums[i]--;
					if (!isLess && i < bNums[ind]) {
						isLess = true;
						lastInd = ind;
					}
					ind++;
					rNums[ind] = i;
					backStep = false;
					needToStepBack = false;
					break;
				}
			}
			if (needToStepBack) {
				aNums[rNums[ind]]++;
				ind--;
				backStep = true;
				// if (isLess && ind < lastInd) {
				if (isLess && ind == lastInd) {
					isLess = false;
				}
			}
		}
		for (var i = 0; i < a.length; i++) {
			result += '' + rNums[i]
		}
	}
	return result;
}

function main() {
	var a = readline();
	var b = readline();
	print(rearrangeNumbers(a, b));
}

main();

// if (!readline) { var { readline, print } = require('./index.js'); }

const
	ZERO_CHAR_CODE = '0'.charCodeAt();

/**
 * Returns an array of length 10
 * that stores the number of occurrences of each digit in the number
 * @param { string } number
 * @returns { [number] }
 */
function getDigitsNumber(num) {
	var result = new Array(10).fill(0);
	for (var char of num) {
		var digit = char.charCodeAt() - ZERO_CHAR_CODE;
		if (digit >= 0 && digit <= 9) {
			result[digit]++;
		}
	}
	return result;
}

/**
 * Returns an array of digits of number
 * @param { string } number
 * @returns { [number] }
 */
function getDigits(num) {
	var result = new Array(num.length).fill(0);
	for (var i = 0; i < num.length; i++) {
		var digit = num.charCodeAt(i) - ZERO_CHAR_CODE;
		if (digit < 0 || digit > 9) throw 'is not number';
		result[i] = digit;
	}
	return result;
}

/**
 * Returns a number (as string) consisting of digits of a and not exceeding b
 * @param { string } a
 * @param { string } b
 * @returns { string }
 */
function rearrangeNumbers(a, b) {
	var aNums = getDigitsNumber(a);
	var bNums = getDigits(b);
	var result = '';
	if (a.length != b.length) {
		for (var i = 9; i >= 0; i--) result += ('' + i).repeat(aNums[i]);
	} else {
		var rNums = new Array(a.length);
		var ind, lastInd;
		ind = lastInd = 0;
		var isLess = false;
		for (var i = 0; i < a.length; i++) {
			var needToBreak = true;
			var iFrom = isLess ? 9 : bNums[i];
			for (var j = iFrom; j >= 0; j--) {
				if (aNums[j] > 0) {
					if (j < bNums[i]) {
						isLess = true;
						lastInd = i;
					}
					ind = i;
					rNums[i] = j;
					aNums[j]--;
					needToBreak = false;
					break;
				}
			}
			if (needToBreak) break;
		}
		var backStep = false;
		while (ind + 1 < a.length) {
			var needToStepBack = true;
			var iFrom = backStep ? rNums[ind + 1] - 1 : isLess ? 9 : bNums[ind + 1];
			for (var i = iFrom; i >= 0; i--) {
				if (aNums[i] > 0) {
					aNums[i]--;
					ind++;
					rNums[ind] = i;
					if (!isLess && i < iFrom) {
						isLess = true;
						lastInd = ind;
					}
					backStep = false;
					needToStepBack = false;
					break;
				}
			}
			if (needToStepBack) {
				aNums[rNums[ind]]++;
				ind--;
				backStep = true;
				// if (isLess && ind < lastInd) {
				if (isLess && ind == lastInd) {
					isLess = false;
				}
			}
		}
		for (var i = 0; i < a.length; i++) {
			result += '' + rNums[i]
		}
	}
	return result;
}

function main() {
	var a = readline();
	var b = readline();
	print(rearrangeNumbers(a, b));
}

main();

// if (!readline) { var { readline, print } = require('./index.js'); }

const
	ZERO_CHAR_CODE = '0'.charCodeAt();

/**
 * Returns an array of length 10
 * that stores the number of occurrences of each digit in the number
 * @param { string } number
 * @returns { [number] }
 */
function getDigitsNumber(num) {
	var result = new Array(10).fill(0);
	for (var char of num) {
		var digit = char.charCodeAt() - ZERO_CHAR_CODE;
		if (digit >= 0 && digit <= 9) {
			result[digit]++;
		}
	}
	return result;
}

/**
 * Returns an array of digits of number
 * @param { string } number
 * @returns { [number] }
 */
function getDigits(num) {
	var result = new Array(num.length).fill(0);
	for (var i = 0; i < num.length; i++) {
		var digit = num.charCodeAt(i) - ZERO_CHAR_CODE;
		if (digit < 0 || digit > 9) throw 'is not number';
		result[i] = digit;
	}
	return result;
}

/**
 * Returns a number (as string) consisting of digits of a and not exceeding b
 * @param { string } a
 * @param { string } b
 * @returns { string }
 */
function rearrangeNumbers(a, b) {
	var aNums = getDigitsNumber(a);
	var bNums = getDigits(b);
	var result = '';
	if (a.length != b.length) {
		for (var i = 9; i >= 0; i--) result += ('' + i).repeat(aNums[i]);
	} else {
		var rNums = new Array(a.length);
		var ind, lastInd;
		ind = lastInd = 0;
		var isLess = false;
		for (var i = 0; i < a.length; i++) {
			var needToBreak = true;
			var iFrom = isLess ? 9 : bNums[i];
			for (var j = iFrom; j >= 0; j--) {
				if (aNums[j] > 0) {
					if (j < bNums[i]) {
						isLess = true;
						lastInd = i;
					}
					ind = i;
					rNums[i] = j;
					aNums[j]--;
					needToBreak = false;
					break;
				}
			}
			if (needToBreak) break;
		}
		while (ind + 1 < a.length) {
			var needToStepBack = true;
			var iFrom = isLess ? 9 : bNums[ind + 1];
			for (var i = iFrom; i >= 0; i--) {
				if (aNums[i] > 0) {
					aNums[i]--;
					ind++;
					rNums[ind] = i;
					if (!isLess && i < iFrom) {
						isLess = true;
						lastInd = ind;
					}
					needToStepBack = false;
				}
			}
			if (needToStepBack) {
				aNums[rNums[ind]]++;
				ind--;
				if (isLess && ind == lastInd) {
					isLess = false;
				}
			}
		}
		for (var i = 0; i < a.length; i++) {
			result += '' + rNums[i]
		}
	}
	return result;
}

function main() {
	var a = readline();
	var b = readline();
	print(rearrangeNumbers(a, b));
}

main();

a = readline();
b = readline();
if (a.length < b.length) b = Array(a.length).fill(9);
cnt = Array(10).fill(0);
for (c of a) cnt[+c]++;
lo = hi = 0;
for (c of b) {
    d = +c;
    for (i = d - 1; i >= 0; i--) {
        if (cnt[i]) {
            lo = hi * 10 + i;
            cnt[i]--;
            for (j = 9; j >= 0; j--) {
                for (k = cnt[j]; k; k--) lo = lo * 10 + j;
            }
            cnt[i]++;
            break;
        }
    }
    if (cnt[d]) {
        hi = hi * 10 + d;
        cnt[d]--;
    } else break;
}
print(lo < hi ? hi : lo);


Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively.    Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2, 4, 6], and Sasha writes down [1, 5, 7]. There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.

The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length.  The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively. The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively.

Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).

NoteThe first test is analyzed in the statement.

function main(){
  var line = readline().split(" ").map(Number);
  var barriers = line[0];
  var trackLength = line[1];

  if(barriers === 1)
    return print("YES");

  var kefaBarriers = readline().split(" ").map(Number).map(function(e, i, ar){
    return i === ar.length - 1 ? trackLength + ar[0] - e : ar[i+1] - e;
  });
  var sashaBarriers = readline().split(" ").map(Number).map(function(e, i, ar){
    return i === ar.length - 1 ? trackLength + ar[0] - e : ar[i+1] - e;
  });

  for(var i = 0; i < barriers; i++){
    if(sashaBarriers[i] === kefaBarriers[0])
      for(j = i + 1; j < barriers + i; j++){
        if(sashaBarriers[j%barriers] !== kefaBarriers[j-i])
          break;
        else
            if(j-i === barriers - 1)
              return print("YES");
      }
  }

  return print("NO");
}

main();

function main() {
    var data = readline().split(' ').map(Number);
    var first = readline().split(' ').map(Number);
    var second = readline().split(' ').map(Number);
    var L = data[1];
    var n = data[0];

   for(var i=0;i<L;i++){
       var newArray = [];
       for(var j=0;j<n;j++){
           var value =first[j] - i
           if(value < 0){
               value += L
           }

           newArray.push(value);
       }
       newArray.sort((a,b) => a -b);
       var good = true;
       for(var j=0;j<n;j++){
           if(second[j] != newArray[j]){
               good = false;
               break;
           }
       }
       if(good){
           return print("YES");
       }
   }
    return print("NO");
}

main()


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() {
    myout("No");
}

var x = readline();
x && print('standard output')

var x = readline();
(x === 'standard input') ? print('standard output') : print('');

//var input = readline();
print("Is it rated");

//var input = readline();
print("Is it rated?");


Madoka decided to entrust the organization of a major computer game tournament "OSU"!In this tournament, matches are held according to the "Olympic system". In other words, there are $$$2^n$$$ participants in the tournament, numbered with integers from $$$1$$$ to $$$2^n$$$. There are $$$n$$$ rounds in total in the tournament. In the $$$i$$$-th round there are $$$2^{n - i}$$$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament — is the last remaining participant.But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win — the participant on the left or right.But Madoka knows that tournament sponsors can change the winner in matches no more than $$$k$$$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change).  So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $$$1$$$ and $$$3$$$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $$$10^9 + 7$$$. Note that we need to minimize the answer, and only then take it modulo.

The first and the only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$$$) — the number of rounds in the tournament and the number of outcomes that sponsors can change.

Print exactly one integer — the minimum number of the winner modulo $$$10^9 + 7$$$

NoteIn the first example, there is only one match between players $$$1$$$ and $$$2$$$, so the sponsors can always make player $$$2$$$ wins.The tournament grid from the second example is shown in the picture in the statement.

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        k = rn();
  const MOD = 10 ** 9 + 7;
  const f = new Array(n);
  f[0] = f[1] = 1;
  for (let i = 2; i <= n; i++) {
    f[i] = mul(f[i - 1], i);
  }
  const g = new Array(n);
  g[n] = power(f[n], MOD - 2);
  g[0] = 1;
  for (let i = n; i >= 2; i--) {
    g[i - 1] = mul(g[i], i);
  }
  let res = 0,
      max = Math.min(n, k);
  for (let i = 0; i <= max; i++) {
    res = (res + mul(f[n], g[i], g[n - i])) % MOD;
  }
  return res;
}
const MOD = 10 ** 9 + 7;
function power(a, b) {
  let res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b = b >> 1;
  }
  return res;
}
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= limit) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.

The only line of the input contains a string s (1 ≤ |s| ≤ 10). Each character in s is a lowercase English letter.

If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.

NoteFor the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".For the second sample, there is more than one solution. For example, "eve" will also be accepted.For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.

String.prototype.insert = function (index, string) {
  if (index > 0)
    return this.substring(0, index) + string + this.substring(index, this.length);
  else
    return string + this;
};
String.prototype.reverse= function(){
    return this.split('').reverse().join('');
}

function solve(){
    var s = readline();
    var alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
    for(var i = 0; i <= s.length; ++i){
        for(var j = 0; j < alphabet.length; ++j){
            var s1 = s.insert(i,alphabet[j]);
            var s2 = s1.reverse();
            if(s1 == s2){
                print(s1);
                return;
            }
        }
    }
    print("NA");
}
solve();

(function() {

var alpha = "abcdefghijklmnopqrstuvwxyz";
var str = readline();

for(var i = 0; i <= str.length; i++) {
    for(var j = 0; j < alpha.length; j++) {
        var res = str.substr(0,i)+alpha[j]+str.substr(i);
        if(isPalin(res))
            return print(res);
    }
}

print("NA");

function isPalin(s) {
    for(var i = 0; i < s.length/2; i++) {
        if(s[i] !== s[s.length-1-i])
            return false;
    }
    return true;
}

})();

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", function(word) {
    let ans = word.split('')
    let j = ans.length - 1;
    let ans2 = ans.join('');
    let found = false
    for(let i = 0; !found  && i < ans.length; i++){
        for(let j = 0; j < ans.length; j++){
            let ans1 = ans2.slice(0, i) + ans[j] + ans2.slice(i, ans.length )
            if(checkPolindrom(ans1)){
                found = true;
                console.log(ans1);
                break;
            }
        }
    }

    for(let i = 0; !found  && i < ans.length; i++){
        if(ans[i] !== ans[j]){
            let ans1 = ans2 + ans[j];
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans[j] + ans2;
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans[i] + ans2;
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
            ans1 = ans2 + ans[i];
            if(checkPolindrom(ans1)){
                found = true
                console.log(ans1)
                break;
            }
        }
    }
    if(!found)
        console.log('NA')
    process.exit(0)
})

rl.on("close", function() {
    console.log("\nBYE BYE !!!");
    process.exit(0);
});

function checkPolindrom(ans1){
    var splitString = ans1.split("");
    var reverseArray = splitString.reverse();
    let check = reverseArray.join("");
    return check === ans1;
}


You are given three integers $$$a$$$, $$$b$$$ and $$$x$$$. Your task is to construct a binary string $$$s$$$ of length $$$n = a + b$$$ such that there are exactly $$$a$$$ zeroes, exactly $$$b$$$ ones and exactly $$$x$$$ indices $$$i$$$ (where $$$1 \le i < n$$$) such that $$$s_i \ne s_{i + 1}$$$. It is guaranteed that the answer always exists.For example, for the string "01010" there are four indices $$$i$$$ such that $$$1 \le i < n$$$ and $$$s_i \ne s_{i + 1}$$$ ($$$i = 1, 2, 3, 4$$$). For the string "111001" there are two such indices $$$i$$$ ($$$i = 3, 5$$$).Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.

The first line of the input contains three integers $$$a$$$, $$$b$$$ and $$$x$$$ ($$$1 \le a, b \le 100, 1 \le x < a + b)$$$.

Print only one string $$$s$$$, where $$$s$$$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.

NoteAll possible answers for the first example:   1100;  0011. All possible answers for the second example:   110100;  101100;  110010;  100110;  011001;  001101;  010011;  001011.

var firstLine = readline().split(' ').map(function(v){return +v;});

var zeroCount = firstLine[0] - 1;
var oneCount = firstLine[1] - 1;
var xCount = firstLine[2] - 1;

var zero = "0";
var one = "1";
var param = false;
var resultString = one + zero;

while(xCount > 0) {
    if (oneCount === 0 || zeroCount === 0) break;

    if (param) {
        param = !param;
        resultString = resultString + zero;
        zeroCount -= 1;
    } else {
        param = !param;
        resultString = resultString + one;
        oneCount -= 1;
    }

    xCount -= 1;
}

if (xCount > 0 && zeroCount > 0) {
    resultString = zero + resultString;
    zeroCount -= 1;
}

if (xCount > 0 && oneCount > 0) {
    resultString = resultString + one;
    oneCount -= 1;
}

if (xCount === 0 && resultString[resultString.length - 1] === one) {
    resultString = one.repeat(oneCount) + resultString.slice(0, -1) + zero.repeat(zeroCount) + resultString[resultString.length - 1];
} else {
    resultString = one.repeat(oneCount) + resultString + zero.repeat(zeroCount);
}

print(resultString);

var line = readline ();
line = line.trim ().split ( ' ' );
var a = (+ line [ 0 ]), b = (+ line [ 1 ]), x = (+ line [ 2 ]);
var result = [ ];
var cnt = 0;
if ( a > b ) {
    result.push ( '0' );
    a --;
    while ( cnt < x ) {
        if ( cnt % 2 == 1 ) {
            result.push ( '0' );
            a --;
        } else {
            result.push ( '1' );
            b --;
        }
        cnt ++;
    }
} else {
    result.push ( '1' );
    b --;
    while ( cnt < x ) {
        if ( cnt % 2 == 0 ) {
            result.push ( '0' );
            a --;
        } else {
            result.push ( '1' );
            b --;
        }
        cnt ++;
    }
}
var pos;
pos = result.indexOf ( '0' );
while ( a > 0 ) {
    result.splice ( pos, 0, '0' );
    a --;
}
pos = result.indexOf ( '1' );
while ( b > 0 ) {
    result.splice ( pos, 0, '1' );
    b --;
}
var str = '';
for ( var g = 0; g < result.length; g ++ ) { str += result [ g ]; }
print ( str );

"use strict";

// var inp = prompt().split(" ").map(function(x) { return parseInt(x); });
var inp = readline().split(" ").map(function(x) { return parseInt(x); });
var a = inp[0];
var b = inp[1];
var x = inp[2];
var s = ""

var flag;
if (a <= b)
    flag = "1"
    else
    flag = "0";

    for(var i = 0; i < x; i++){
        s+=flag;

        if (flag == "0") flag = "1"
        else flag = "0";
    }

    flag = s[s.length - 1];
    var flagCount = 0;
    for (var i = 0; i < s.length; i++)
        if (s[i] == flag) flagCount++;

    var q = (flag == "0") ? a : b;
    for (var i = flagCount; i < q; i++)
        s += flag;

    if (flag == "0") flag = "1"
        else flag = "0";
    q = (flag == "0") ? a : b;

    flagCount = 0;
    for (var i = 0; i < s.length; i++)
        if (s[i] == flag) flagCount++;
    for (var i = flagCount; i < q; i++)
        s += flag;

// console.log(s);
print(s);

function main() {
  const is = new Scanner();
  let [a, b, x] = is.nextArray().map(Number);
  const binaryString = new Int32Array(x + 1);

  for (let i = a > b ? 1 : 0; i < binaryString.length; i += 2)
    binaryString[i] = 1;

  let zeros = 0, ones = 0;
  binaryString.forEach((item) => {
    if (item)
      ones++;
    else
      zeros++;
  });

  a -= zeros;
  b -= ones;

  for (let i = 0; i < 2; i++) {
    if (binaryString[i] === 0) {
      for (let j = 0; j < a; j++)
        process.stdout.write('0');
    } else {
      for (let j = 0; j < b; j++)
        process.stdout.write('1');
    }
    process.stdout.write(String(binaryString[i]));
  }

  for (let i = 2; i < binaryString.length; i++)
    process.stdout.write(String(binaryString[i]));
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

var firstLine = readline().split(' ').map(function(v){return +v;});

var zeroCount = firstLine[0] - 1;
var oneCount = firstLine[1] - 1;
var xCount = firstLine[2] - 1;

var zero = "0";
var one = "1";
var param = false;
var resultString = one + zero;

while(xCount > 0) {
    if (oneCount === 0 || zeroCount === 0) break;

    if (param) {
        param = !param;
        resultString = resultString + zero;
        zeroCount -= 1;
    } else {
        param = !param;
        resultString = resultString + one;
        oneCount -= 1;
    }

    xCount -= 1;
}

if (xCount > 0 && zeroCount > 0) {
    resultString = zero + resultString;
    zeroCount -= 1;
}

if (xCount > 0 && oneCount > 0) {
    resultString = resultString + one;
    oneCount -= 1;
}

if (xCount === 0 && resultString[resultString.length - 1] !== one) {
    resultString = one.repeat(oneCount) + resultString + zero.repeat(zeroCount);
} else {
    resultString = one.repeat(oneCount) + resultString.slice(0, -1) + zero.repeat(zeroCount) + resultString[resultString.length - 1];
}

print(resultString);

var firstLine = readline().split(' ').map(function(v){return +v;});

var zeroCount = firstLine[0] - 1;
var oneCount = firstLine[1] - 1;
var xCount = firstLine[2] - 1;

var zero = "0";
var one = "1";
var param = false;
var resultString = one + zero;

while(xCount > 0) {
    if (oneCount === 0 || zeroCount === 0) break;

    if (param) {
        param = !param;
        resultString = resultString + zero;
        zeroCount -= 1;
    } else {
        param = !param;
        resultString = resultString + one;
        oneCount -= 1;
    }

    xCount -= 1;
}

if (xCount > 0 && zeroCount > 0) {
    resultString = zero + resultString;
    zeroCount -= 1;
}

if (xCount > 0 && oneCount > 0) {
    resultString = resultString + one;
    oneCount -= 1;
}

resultString = one.repeat(oneCount) + resultString + zero.repeat(zeroCount);

print(resultString);

function main() {
  const is = new Scanner();
  let [a, b, x] = is.nextArray().map(Number);
  console.log(a, b, x);
  const binaryString = new Int32Array(x + 1);

  for (let i = a > b ? 1 : 0; i < binaryString.length; i += 2)
    binaryString[i] = 1;

  let zeros = 0, ones = 0;
  binaryString.forEach((item) => {
    if (item)
      ones++;
    else
      zeros++;
  });

  a -= zeros;
  b -= ones;

  for (let i = 0; i < 2; i++) {
    if (binaryString[i] === 0) {
      for (let j = 0; j < a; j++)
        process.stdout.write('0');
    } else {
      for (let j = 0; j < b; j++)
        process.stdout.write('1');
    }
    process.stdout.write(String(binaryString[i]));
  }

  for (let i = 2; i < binaryString.length; i++)
    process.stdout.write(String(binaryString[i]));
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });


Santa Claus has n candies, he dreams to give them as gifts to children.What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.

The only line contains positive integer number n (1 ≤ n ≤ 1000) — number of candies Santa Claus has.

Print to the first line integer number k — maximal number of kids which can get candies. Print to the second line k distinct integer numbers: number of candies for each of k kid. The sum of k printed numbers should be exactly n. If there are many solutions, print any of them.

var n = parseInt(readline());
var k = 0;
var num = [];

while(n > k) {

    k++;
    n -= k;
}

for(var i = 1; i < k; i++)
    num.push(i);

num.push(n + k); // push last element

print(k);
print(num.join(" "));

/*
    The idea to solve this problem is:

    repeatedly increase k until n is exhausted, while push value of k to array.
    Add remainder of n to last element of array since it cannot be broken down
    anymore.
*/

var n = parseInt(readline());
var k = 0;
var num = [];

while(n > k) {

    k++;
    n-=k;
    num.push(k);
}

num[num.length - 1] += n;

print(num.length);
print(num.join(" "));

var input = Number(readline());
var quantity = Math.floor((Math.pow(1 + 4 * 2 * input, 0.5) - 1) / 2);
var sum = 0;
var numbers = [];
for (var i = 1; i < quantity; i++) {
	sum += i;
	numbers.push(i);
}
numbers.push(input - sum);
print("" + quantity);
print(numbers.join(" "));

function sa(n){
    var i =1;
    for (; ; i++) {
        if (n < i) return i - 1;
        else n -= i;
    }
}

    var n = Number(readline());
    var res = sa(n)
    print(res);
    var r = ""
    var sum = 0;
    for(var i=0;i<res;i++){
        if(i == res-1){
            r += (n - sum)
            break;
        }
        sum += (i+1);
        r += (i+1) + " ";
    }
    print(r)

var n = parseInt(readline());
var s = 0;
var res = [];
var k = 0;
if(n === 1) {
  print(1);
  print(1);
} else {
  for(var i = 1; i < n; i ++ ) {
    if(i + 1 > n - s - i) {
      res.push(n - s);
      k += 1;
      break;
    } else {
    res.push(i);
      s += i;
      k += 1;
    }
  }
  print(k);
  print(res.join(' '));
}

var input = readline();
var current = 1;
var sum = 0;

recurse();

var output = [];

for(var i = 1; i < current; i++){
    output.push(i);
}

if(sum > input){
    var diff = sum - input;
    output.splice(output.indexOf(diff), 1);
}

function recurse(){
    if(sum < input){
        sum = sum + current;
        current = current + 1;
        recurse();
    }
}

print(output.length);
print(output.join(" "));

var n = parseInt(readline());
var i = 1;
var sum = 0;
var num = [];

while((n - sum) > sum) {

    sum += i;
    num.push(i);
    i++;
}

if((n - sum) === num[num.length - 1])
    num[num.length - 1] += (n - sum);
else
    num.push(n - sum);

print(num.length);
print(num.join(" "));

var n = parseInt(readline());
var i = 1;
var sum = 0;
var num = [];

while((n - sum) > sum) {

    sum += i;
    num.push(i);
    i++;
}

if((n - sum) === num[num.length - 1])
    num[num.length - 1] += (n - sum);
else {

    if(n - sum > 0)
        num.push(n - sum);
}

print(num.length);
print(num.join(" "));

var input = Number(readline());
print(Math.floor((Math.pow(1 + 4 * 2 * input, 0.5) - 1) / 2).toString());

var n = parseInt(readline());
var s = 1;
var res = [1];
var k = 1;
for(var i = 2; i < n; i ++ ) {
  if(i + 1 >= n - s - i) {
    res.push(n - s);
    k += 1;
    break;
  } else {
    res.push(i);
    s += i;
    k += 1;
  }
}

print(k);
print(res.join(' '));

var n = parseInt(readline());
var s = 0;
var res = [];
var k = 0;
if(n === 1) {
  print(1);
  print(1);
} else {
  for(var i = 1; i < n; i ++ ) {
    if(i + 1 >= n - s - i) {
      res.push(n - s);
      k += 1;
      break;
    } else {
    res.push(i);
      s += i;
      k += 1;
    }
  }

  print(k);
  print(res.join(' '));

}


It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:  Each piece of each cake is put on some plate;  Each plate contains at least one piece of cake;  No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.Help Ivan to calculate this number x!

The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.

Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.

NoteIn the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.

function f(n, u, v) {
    var t = Math.trunc(u * n / (u + v));
    return Math.trunc(t ? v / (n - t) : u);
}

var l = readline().split(' ').map(Number);
var x = f(l[0], l[1], l[2]), y = f(l[0], l[2], l[1]);
print(x > y ? x : y);

var arr = readline().split(' ')
var max = -1;

for (var i = 1; i < arr[0]; i++)
    max = Math.max(max, Math.min(Math.trunc(arr[1]/i), Math.trunc(arr[2]/(arr[0]-i))));

print(max);

const
    conditions = readline().split(' '),
    platesCount = +conditions[0],
    cakes_1 = +conditions[1],
    cakes_2 = +conditions[2];

var
    minCakes = Math.min(cakes_1, cakes_2),
    maxCakes = Math.max(cakes_1, cakes_2);
    minPieces = Math.ceil(maxCakes / Math.ceil(platesCount / 2)),
    plates = [];

while (minPieces > cakes_1 || minPieces > cakes_2) {
    minPieces--;
}

function putCakes() {
    var
        plates = [],
        tmpMinCakes = minCakes,
        tmpMaxCakes = maxCakes;
    for (var i = 0; i < platesCount; i++) {
        if (tmpMaxCakes) {
            if (tmpMaxCakes >= minPieces) {
                plates.push(minPieces)
                tmpMaxCakes -= minPieces;
                if (Math.floor(tmpMaxCakes / minPieces) < 1) {
                    plates[i] += tmpMaxCakes
                    tmpMaxCakes = 0;
                }
            }
        } else {
            if (tmpMinCakes >= minPieces) {
                if (i === platesCount - 1) {
                    plates.push(tmpMinCakes);
                } else {
                    plates.push(minPieces)
                    tmpMinCakes -= minPieces;
                }
            } else {
                plates.push(tmpMinCakes);
            }
        }
    }
    pieces = plates.reduce((a, b) => {return Math.min(a, b)})
    if (pieces < minPieces) {
        minPieces --;
        putCakes();
    } else {
        print(pieces)
    }
}

putCakes()

function main() {
  var data = readline().split(" ");
  var plates = data[0];
  var firstCake = data[1];
  var secondCake = data[2];

  var maxPieces = Math.floor((firstCake + secondCake) / plates);
  var smallCake = Math.min(firstCake, secondCake);
  maxPieces = maxPieces > smallCake ? smallCake : maxPieces;
  if (
    firstCake === 1 ||
    secondCake === 1 ||
    firstCake + secondCake < 2 * plates
  )
    maxPieces = 1;
  else {
    while (
      Math.floor(firstCake / maxPieces) + Math.floor(secondCake / maxPieces) <
      plates
    ) {
      maxPieces--;
    }
  }
  print(maxPieces);
}

main();

var inputData = readline().split(' ');
var n = parseInt(inputData[0]);
var a = parseInt(inputData[1]);
var b = parseInt(inputData[2]);
var result = 0;
for (var i = n - 1; i > 0; i--) {
    var maxResult;
    var maxA = Math.floor(a/(n-i));
    var maxB = Math.floor(b/i);
    maxResult = maxA < maxB ? maxA : maxB;
    if (result <= maxResult) {
        result = maxResult;
    } else {
        break;
    }
}
print(result);

const getMaxPiecesOnPlate = (N, a, b) => {
  var maxPieces = 0;

  for (var i = 1; i < N; i++) {
    maxPieces = Math.max(
      maxPieces,
      Math.min(Math.floor(a / i), Math.floor(b / (N - i)))
    );
  }

  return maxPieces;
};

const main = () => {
  const input = readline()
    .split(" ")
    .map((i) => Number(i));

  return getMaxPiecesOnPlate(input[0], input[1], input[2]);
};

print(main());

var data = readline();
print('\n');

var platesCount = data.split(' ')[0];
var firstCaceParts = data.split(' ')[1];
var secondCakeParts = data.split(' ')[2];

function getMax(n, a, b) {
    var count = 0;

    for (var i = 1; i < n; i++) {
        var current = Math.min(Math.floor(a / i), Math.floor(b / (n - i)));
        if (current > count) {
            count = current;
        }
    }

    return count;
}

print(getMax(platesCount, firstCaceParts, secondCakeParts));

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

print(tort(args[0], args[1], args[2]));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      var curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

print(tort(firstLine.split(' ')[0], firstLine.split(' ')[1], firstLine.split(' ')[2]));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      var curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

print(tort(...args));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      var curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

'use strict';
var incomingData = readline().split(' ');
var n = incomingData[0];
var a = incomingData[1];
var b = incomingData[2];

function f(n, a, b) {
    var x = -1;
    for (var i = 1; i < n; i++) {
        var part_a = Math.trunc(a / i);
        var part_b = Math.trunc(b / (n-i));
        x = Math.max(x, Math.min(part_a, part_b));
    }
    print(x);
}

f(n, a, b);

function tes(e){
    var t911b = e.split(' ');
    var sumPlate = t911b[0];
    var fCake = t911b[1];
    var sCake = t911b[2];
    var res = -1;
    for (var i = 1; i < sumPlate; i++) {
        var f = Math.trunc(fCake / i);
        var s = Math.trunc(sCake / (sumPlate-i));
        res = Math.max(res, Math.min(f, s));
    }
    print(res);
}
tes(readline());

var inputData = readline().split(' ');//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.trunc(kyskiTorta1/i);
        var calcTort2 = Math.trunc(kyskiTorta2/(tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ');//prompt("enter 3 argymentf").split(' ');
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.trunc(kyskiTorta1/i);
        var calcTort2 = Math.trunc(kyskiTorta2/(tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.trunc(kyskiTorta1/i);
        var calcTort2 = Math.trunc(kyskiTorta2/(tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = -1;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.trunc(kyskiTorta1/i);
        var calcTort2 = Math.trunc(kyskiTorta2/(tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

_=readline().split(' ').map(Number)
n=_[0],a=_[1],b=_[2]
x=-1
for (var i=1;i<n;++i) {
  var ai=Math.trunc(a/i),
    bi=Math.trunc(b/(n-i))
  if (ai && bi) {
    var y=Math.min(ai, bi)
    x=Math.max(x,y)
  }
}
print(x)

function f(n, u, v) {
    var t = Math.trunc(u * n / (u + v));
    u /= t;
    v /= n - t;
    return Math.trunc(u < v ? u : v);
}

var l = readline().split(' ').map(Number);
var x = f(l[0], l[1], l[2]), y = f(l[0], l[2], l[1]);
print(x > y ? x : y);

var arr = readline().split(' ')
var max = -1;

for (var i = 1; i < arr[0]; i++) max = Math.max(max, Math.min(arr[1]/i, arr[2]/(arr[0]-i)));

print(max);

const
    conditions = readline().split(' '),
    platesCount = +conditions[0],
    cakes_1 = +conditions[1],
    cakes_2 = +conditions[2];

var
    plates = [],
    pieces = 0,
    minPieces = Math.floor((cakes_1 + cakes_2) / platesCount);

while (minPieces > cakes_1 || minPieces > cakes_2) {
    minPieces--;
}

if (minPieces === 1) {
    print(minPieces);
} else {
    var
        tmpCakes_1 = Math.min(cakes_1, cakes_2),
        tmpCakes_2 = Math.max(cakes_1, cakes_2);
    for (var i = 0; i < platesCount; i++) {
        if (tmpCakes_1) {
            if (tmpCakes_1 >= minPieces) {
                plates.push(minPieces)
                tmpCakes_1 -= minPieces;
            } else {
                plates.push(tmpCakes_1);
                tmpCakes_1 = 0;
            }
        } else {
            if (tmpCakes_2 >= minPieces) {
                if (i === platesCount - 1) {
                    plates.push(tmpCakes_2);
                } else {
                    plates.push(minPieces)
                    tmpCakes_2 -= minPieces;
                }
            } else {
                plates.push(tmpCakes_2);
            }
        }
    }
    pieces = plates.reduce((a, b) => {return Math.min(a, b)})
}
print(pieces)

const
    conditions = readline().split(' '),
    platesCount = +conditions[0],
    cakes_1 = +conditions[1],
    cakes_2 = +conditions[2];

var
    plates = [],
    pieces = 0,
    minPieces = Math.floor((cakes_1 + cakes_2) / platesCount);

while (minPieces > cakes_1 || minPieces > cakes_2) {
    minPieces--;
}

function putCakes() {
    var
        plates = [],
        tmpCakes_1 = Math.min(cakes_1, cakes_2),
        tmpCakes_2 = Math.max(cakes_1, cakes_2);
    for (var i = 0; i < platesCount; i++) {
        if (tmpCakes_1) {
            if (tmpCakes_1 >= minPieces) {
                plates.push(minPieces)
                tmpCakes_1 -= minPieces;
            } else {
                plates.push(tmpCakes_1);
                tmpCakes_1 = 0;
            }
        } else {
            if (tmpCakes_2 >= minPieces) {
                if (i === platesCount - 1) {
                    plates.push(tmpCakes_2);
                } else {
                    plates.push(minPieces)
                    tmpCakes_2 -= minPieces;
                }
            } else {
                plates.push(tmpCakes_2);
            }
        }
    }
    pieces = plates.reduce((a, b) => {return Math.min(a, b)})
    if ((pieces + 1) < minPieces) {
        minPieces --;
        putCakes();
    } else {
        print(pieces)
    }
}

if (minPieces === 1) {
    print(minPieces);
} else {
    putCakes();
}

const
    conditions = readline().split(' '),
    platesCount = +conditions[0],
    cakes_1 = +conditions[1],
    cakes_2 = +conditions[2];

var
    plates = [],
    pieces = 0,
    minPieces = Math.floor((cakes_1 + cakes_2) / platesCount);

while (minPieces > cakes_1 || minPieces > cakes_2) {
    minPieces--;
}

function putCakes() {
    var
        plates = [],
        tmpCakes_1 = Math.min(cakes_1, cakes_2),
        tmpCakes_2 = Math.max(cakes_1, cakes_2);
    for (var i = 0; i < platesCount; i++) {
        if (tmpCakes_1) {
            if (tmpCakes_1 >= minPieces) {
                plates.push(minPieces)
                tmpCakes_1 -= minPieces;
            } else {
                plates.push(tmpCakes_1);
                tmpCakes_1 = 0;
            }
        } else {
            if (tmpCakes_2 >= minPieces) {
                if (i === platesCount - 1) {
                    plates.push(tmpCakes_2);
                } else {
                    plates.push(minPieces)
                    tmpCakes_2 -= minPieces;
                }
            } else {
                plates.push(tmpCakes_2);
            }
        }
    }

    pieces = plates.reduce((a, b) => {return Math.min(a, b)})
    if (pieces < minPieces) {
        minPieces --;
        putCakes();
    } else {
        print(minPieces);
    }
}

if (minPieces === 1) {
    print(minPieces);
} else {
    putCakes();

}

const
    conditions = readline().split(' '),
    platesCount = +conditions[0],
    cakes_1 = +conditions[1],
    cakes_2 = +conditions[2];

var
    plates = [],
    pieces = 0,
    minPieces = Math.floor((cakes_1 + cakes_2) / platesCount);

while (minPieces > cakes_1 || minPieces > cakes_2) {
    minPieces--;
}

if (minPieces === 1) {
    print(minPieces);
} else {
    var
        tmpCakes_1 = Math.min(cakes_1, cakes_2),
        tmpCakes_2 = Math.max(cakes_1, cakes_2);
    for (var i = 0; i < platesCount; i++) {
        if (tmpCakes_1) {
            if (tmpCakes_1 >= minPieces) {
                plates.push(minPieces)
                tmpCakes_1 -= minPieces;
            } else {
                plates.push(tmpCakes_1);
                tmpCakes_1 = 0;
            }
        } else {
            if (tmpCakes_2 >= minPieces) {
                if (i === platesCount - 1) {
                    plates.push(tmpCakes_2);
                } else {
                    plates.push(minPieces)
                    tmpCakes_2 -= minPieces;
                }
            } else {
                plates.push(tmpCakes_2);
            }
        }
    }
    pieces = plates.reduce((a, b) => {return Math.min(a, b)})
    print(pieces)
}

function main() {
  var data = readline().split(" ");
  var plates = data[0];
  var firstCake = data[1];
  var secondCake = data[2];

  var maxPieces = Math.floor((firstCake + secondCake) / plates);
  if (
    firstCake === 1 ||
    secondCake === 1 ||
    firstCake + secondCake < 2 * plates
  )
    maxPieces = 1;
  else {
    while (
      Math.floor(firstCake / maxPieces) + Math.floor(secondCake / maxPieces) <
      plates
    ) {
      maxPieces--;
    }
  }
  print(maxPieces);
}

main();

var inputData = readline().split(' ');
var guests = parseInt(inputData[0]);
var a = parseInt(inputData[1]);
var b = parseInt(inputData[2]);
var aPart = Math.round(guests / (a + b) * a);
var bPart = Math.round(guests / (a + b) * b);
    if (aPart < 1) {
        aPart++;
        bPart--;
    } else if (bPart < 1) {
        bPart++;
        aPart--;
    }
if (a < b) {
    print(Math.floor(a / aPart));
} else {
    print(Math.floor(b / bPart));
}

var inputData = readline().split(' ');
var guests = parseInt(inputData[0]);
var a = parseInt(inputData[1]);
var b = parseInt(inputData[2]);
var index = guests / (a + b);
var aPart = index * a;
var bPart = index * b;
if (aPart < bPart) {
    aPart = Math.ceil(aPart);
    bPart = Math.floor(bPart);
    print(Math.floor(a / aPart));
} else {
    bPart = Math.ceil(bPart);
    aPart = Math.floor(aPart);
    print(Math.floor(b / bPart));
}

var inputData = readline().split(' ');
var guests = parseInt(inputData[0]);
var a = parseInt(inputData[1]);
var b = parseInt(inputData[2]);
var aPart = Math.round(guests / (a + b) * a);
var bPart = Math.round(guests / (a + b) * b);
    if (aPart < 1) {
        aPart++;
        bPart--;
    } else if (bPart < 1) {
        bPart++;
        aPart--;
    }
var minAPart = Math.floor(a / aPart);
var minBPart = Math.floor(b / bPart);
print(minAPart < minBPart ? minAPart : minBPart);

var firstLine = readline();
print('\n');

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;

  if (plateForFirst ===  plate && secondCake > 0) {
    --plateForFirst;
    ++plateForSecond;
  } else if (plateForSecond ===  plate && firstCake > 0) {
    ++plateForFirst;
    --plateForSecond;
  }

  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);
  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print('\n');

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

// console.log(tort(100, 100, 100));
function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.round(x / i), Math.round(y / (k - i)));
      if (curr >= maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
// print('\n');

var args = firstLine.split(' ');

print(tort(...args));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var rezult = 0;
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;

  if (plateForFirst ===  plate && secondCake > 0) {
    --plateForFirst;
    ++plateForSecond;
  } else if (plateForSecond ===  plate && firstCake > 0) {
    ++plateForFirst;
    --plateForSecond;
  }

  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);
  if (pathOfFirst < pathOfSecond) {
    rezult = pathOfFirst;
  } else {
    rezult = pathOfSecond;
  }

  return rezult;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.floor(plate * procentFirst / 100) === 0 ? 1 : Math.floor(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);

  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  const allCake = firstCake + secondCake;
  const procentFirst = firstCake / allCake * 100 ;
  const plateForFirst = Math.round(plate * procentFirst / 100);
  const plateForSecond = plate - plateForFirst;
  const pathOfFirst = Math.floor(firstCake / plateForFirst);
  const pathOfSecond = Math.floor(secondCake / plateForFirst);

  return pathOfFirst < pathOfSecond ? pathOfFirst : pathOfSecond;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForFirst);

  return pathOfFirst < pathOfSecond ? pathOfFirst : pathOfSecond;
}

const firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  const allCake = firstCake + secondCake;
  const procentFirst = firstCake / allCake * 100 ;
  const plateForFirst = Math.round(plate * procentFirst / 100);
  const plateForSecond = plate - plateForFirst;
  const pathOfFirst = Math.floor(firstCake / plateForFirst);
  const pathOfSecond = Math.floor(secondCake / plateForFirst);
  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print('\n');

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

// console.log(tort(100, 100, 100));
function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.round(x / i), Math.round(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

const firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  const allCake = firstCake + secondCake;
  const procentFirst = firstCake / allCake * 100 ;
  const plateForFirst = Math.round(plate * procentFirst / 100);
  const plateForSecond = plate - plateForFirst;
  const pathOfFirst = Math.floor(firstCake / plateForFirst);
  const pathOfSecond = Math.floor(secondCake / plateForFirst);

  return pathOfFirst < pathOfSecond ? pathOfFirst : pathOfSecond;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);

  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var rezult = 0;
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;

  if (plateForFirst ===  plate && secondCake > 0) {
    --plateForFirst;
    ++plateForSecond;
  } else if (plateForSecond ===  plate && firstCake > 0) {
    ++plateForFirst;
    --plateForSecond;
  }

  pathOfFirst = Math.floor(firstCake / plateForFirst);
  pathOfSecond = Math.floor(secondCake / plateForSecond);
  if (pathOfFirst < pathOfSecond) {
    rezult <= pathOfFirst ? pathOfFirst : rezult;;
  } else {
    rezult <= pathOfSecond ? pathOfSecond : rezult;;
  }

  --plateForFirst;
  ++plateForSecond;

  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);
  if (pathOfFirst < pathOfSecond) {
    rezult <= pathOfFirst ? pathOfFirst : rezult;;
  } else {
    rezult <= pathOfSecond ? pathOfSecond : rezult;;
  }

  return rezult;
}

var firstLine = readline();
print('\n');

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.round(x / i), Math.round(y / (k - i)));
      if (curr >= maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  debugger;
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.floor(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForSecond);

  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]);

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.round(x / i), Math.round(y / (k - i)));
      if (curr >= maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

var args = firstLine.split(' ');

print(tort(args[0], args[111], args[2]));

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      var curr = Math.min(Math.floor(x / i), Math.floor(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

var firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  var allCake = firstCake + secondCake;
  var procentFirst = firstCake / allCake * 100 ;
  var plateForFirst = Math.round(plate * procentFirst / 100);
  var plateForSecond = plate - plateForFirst;
  var pathOfFirst = Math.floor(firstCake / plateForFirst);
  var pathOfSecond = Math.floor(secondCake / plateForFirst);

  if (pathOfFirst < pathOfSecond) {
    return pathOfFirst;
  }
  return  pathOfSecond;
}

var firstLine = readline();
print('\n');

print(tort(+firstLine.split(' ')[0], +firstLine.split(' ')[1], +firstLine.split(' ')[2]))

function tort(k, x, y) {
  var maxMin = 0;

  for (var i = 1; i < k; i++) {
      const curr = Math.min(Math.round(x / i), Math.round(y / (k - i)));
      if (curr > maxMin) {
          maxMin = curr;
      }
  }

  return maxMin;
}

const firstLine = readline();
print('\n');

print(getRezult(+firstLine.split(' ')[0], +firstLine.split(' ')[1], firstLine.split(' ')[2]))

function getRezult (plate, firstCake, secondCake) {
  const allCake = firstCake + secondCake;
  const procentFirst = firstCake / allCake * 100 ;
  const plateForFirst = Math.round(plate * procentFirst / 100);
  const plateForSecond = plate - plateForFirst;
  const pathOfFirst = Math.floor(firstCake / plateForFirst);
  const pathOfSecond = Math.floor(secondCake / plateForFirst);

  if (pathOfFirst < pathOfSecond) {
    return 5;
  }
  return  20;
}

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = -1;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.round(kyskiTorta1/i);
        var calcTort2 = Math.round(kyskiTorta2/(tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

function calculate(){
    for( var i = 1; i < tarelkiTortu; i++){
        var calcTort1 = Math.round(this.kyskiTorta1/i);
        var calcTort2 = Math.round(this.kyskiTorta2/(this.tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       this.bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}
}
print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; ++i){
        var calcTort1 = Math.round(this.kyskiTorta1/i);
        var calcTort2 = Math.round(this.kyskiTorta2/(this.tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       this.bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

var inputData = readline().split(' ').map(Number);//prompt("enter 3 argymentf").split(' ').map(Number);
var bigestDigit = 0;
var tarelkiTortu = inputData[0], kyskiTorta1 = inputData[1], kyskiTorta2 = inputData[2];

    for( var i = 1; i < tarelkiTortu; i++){
        var calcTort1 = Math.round(this.kyskiTorta1/i);
        var calcTort2 = Math.round(this.kyskiTorta2/(this.tarelkiTortu - i));
    if(calcTort1 && calcTort2){
        var smallerDigit = Math.min(calcTort1, calcTort2);
       this.bigestDigit = Math.max(smallerDigit, bigestDigit);
    }
}

print(bigestDigit);//alert("bigestDigit");

_=readline().split(' ').map(Number)
n=_[0],a=_[1],b=_[2]
x=1000000000
for (var i=1;i<n-1;++i) {
  var ai=Math.trunc(a/i),
    bi=Math.trunc(b/(n-i))
  if (ai && bi)
    x=Math.min(x, ai, bi)
}
print(x)


Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero:  Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 15$$$) — the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \leq a_i \leq 180$$$) — the angle of the $$$i$$$-th rotation in degrees.

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).

NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again.

function padStart(value,targetLength,padString) {
    targetLength = targetLength>>0;
    padString = String(padString || ' ');
    if (value.length > targetLength) {
        return value;
    }
    else {
        targetLength = targetLength-value.length;
        if (targetLength > padString.length) {
            padString += padString.repeat(targetLength/padString.length);
        }
        return padString.slice(0,targetLength) +value;
    }
}

function main() {
    var n = +readline();
    var a = [];

    for(var i = 0; i < n; i++) {
        a.push(+readline());
    }

    var sum = a.reduce((sum,i) => sum +i, 0);

    if(sum % 360 === 0) {
        print('YES');
        return;
    }

    if(sum % 2 != 0) {
        print('NO');
        return;
    }

    var k = parseInt(padStart('', n , '1'), 2);
    for(var i = 1; i < k; i++) {
        var dv = padStart(i.toString(2), n, '0');
        s = a.reduce(function(res, item, index) {
            return res + (dv[index] == 1 ? '+': '-') + item;
        }, '');
        if(eval(s) % 360 === 0) {
            print ('YES');
            return;
        }
    }
    print('NO');
}
main();

var n = +readline();

var mas = [];
var i = 0;

while(i < n) {
	mas[i] = +readline();
	i++;
}
i = 0;
var max = Math.pow(2, n);
var result = 'NO';

while(i <= max) {
	var rrr = summ(convert(i));
	if(rrr %360 === 0) {
		result = 'YES';
		break;
    }
	i++;
}

print(result);

function convert(input) {
	var s = input.toString(2);
	while(n > s.length) { s = "0"+s; }
	return s;
}

function summ(st) {
	var x = 0;
	var p = 0;
	while(p < n) {
		x += (mas[p] * (+st[p] ? 1 : -1));
		p++;
    }
	return x;
}

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

let inputString = '';
let currentLine = 0;

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

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

	main();
});

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

function main() {
	let n = +readline();
	let a = [];
	while (n--) {
		let m = +readline();
		a.push(m);
	}
	let flag = calc(a, 0);
	if (flag == 0) console.log('NO');
	else console.log('YES');
}

calc = (a, sum) => {
	if (a.length == 0) {
		if (sum % 360 == 0) return 1;
		else return 0;
	} else {
		return calc(a.slice(1), sum + a[0]) + calc(a.slice(1), sum - a[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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));

    if ((arr.reduce((a, v) => a + v, 0) % 360) === 0) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
			const n = arr.length;
			const res = [];
			let j = 0;

			for (let mask = 0; mask < (1 << n); mask++) {
				let num = 0;

				for (let i = 0; i < n; i++) {
					if (mask & (1 << i)) {
						num++;
					}
				}

				if (num === k) {
					res[j] = [0, 0];

					for (let i = 0; i < n; i++) {
						if (mask & (1 << i)) {
							res[j][0] = (res[j][0] + arr[i]) % 360;
						} else {
							res[j][1] = (res[j][1] + arr[i]) % 360;
						}
					}

					j++;
				}
			}

			return res;
		}

	for (let i = 1; i < arr.length / 2 + 1; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("NO");
});

// const lines = `15
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168
// 168`.split('\n');
//
// const k = lines[0];
// const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));
//
// if ((arr.reduce((a, v) => a + v, 0) % 360) === 0) {
// 	console.log("YES");
// 	proccess.exit(0);
// }
//
// function subseqs(arr, k) {
// 	const n = arr.length;
// 	const res = [];
// 	let j = 0;
//
// 	for (let mask = 0; mask < (1 << n); mask++) {
// 		let num = 0;
//
// 		for (let i = 0; i < n; i++) {
// 			if (mask & (1 << i)) {
// 				num++;
// 			}
// 		}
//
// 		if (num === k) {
// 			res[j] = [0, 0];
//
// 			for (let i = 0; i < n; i++) {
// 				if (mask & (1 << i)) {
// 					res[j][0] = (res[j][0] + arr[i]) % 360;
// 				} else {
// 					res[j][1] = (res[j][1] + arr[i]) % 360;
// 				}
// 			}
//
// 			j++;
// 		}
// 	}
//
// 	return res;
// }
//
// for (let i = 1; i < arr.length; i++) {
// 	for (const ss of subseqs(arr, i)) {
// 		if (ss[0] === ss[1]) {
// 			console.log("YES");
// 			proccess.exit(0);
// 		}
// 	}
// }
//
// console.log("NO");
//

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

const lines = [];

readline.on('line', (line) => {
  lines.push(Number(line));
});

const processAngles = (n, angles) => {
  for (let i = 0; i < 2 ** (n - 1); i += 1) {
    const bitbask = i.toString(2).padStart(angles.length, '0');
    const rotation = angles.reduce((acc, angle, idx) => {
      if (bitbask[idx] === '0') {
        return acc + angle;
      }

      return acc - angle;
    }, 0);

    if (rotation % 360 === 0) {
      return 'YES';
    }
  }

  return 'NO';
};

readline.on('close', () => {
  const [n, ...angles] = lines;

  console.log(processAngles(n, angles));
});

function padStart(value,targetLength,padString) {
    targetLength = targetLength>>0;
    padString = String(padString || ' ');
    if (value.length > targetLength) {
        return value;
    }
    else {
        targetLength = targetLength-value.length;
        if (targetLength > padString.length) {
            padString += padString.repeat(targetLength/padString.length);
        }
        return padString.slice(0,targetLength) +value;
    }
}

function main() {
    var n = +readline();
    var a = [];

    for(var i = 0; i < n; i++) {
        a.push(+readline());
    }

    var sum = a.reduce((sum,i) => sum +i, 0);

    if(sum % 360 === 0) {
        print('YES');
        return;
    }

    if(sum % 2 != 0) {
        print('NO');
        return;
    }

    var k = parseInt(padStart('', n , '1'), 2);
    for(var i = 1; i < k; i++) {
        var dv = padStart(i.toString(2), n, '0');
        s = a.reduce(function(res, item, index) {
            return res + (dv[index] == 1 ? '+': '-') + item;
        }, '');
        if(eval(s) === 0) {
            print ('YES');
            return;
        }
    }
    print('NO');
}
main();

var arr = [];

var n = +readline();
var i = 0;
var sum = 0;

while(i < n) {
	arr[i] = +readline();
	sum += arr[i];
	i++;
}
if(sum == 360) {
	arr = sortt(arr);

	while(n != 1) {
		arr[i-2] = arr[i-1] - arr[i-2];
		arr.pop();
		arr = sortt(arr);
		n = arr.length;
	}

	if(arr[0] === 0) { print('YES'); }
	else { print('NO'); }

	function sortt(arr) {
		return arr.sort(function(a, b) { return a - b; });
	}
} else {
	print('YES');
}

var n = +readline();

var mas = [];
var i = 0;

while(i < n) {
	mas[i] = +readline();
	i++;
}
i = 0;
var max = Math.pow(2, n);
var result = 'NO';

while(i <= max) {
	var rrr = summ(convert(i));
	if(rrr == 360 || rrr === 0) {
		result = 'YES';
		break;
    }
	i++;
}

print(result);

function convert(input) {
	var s = input.toString(2);
	while(n > s.length) { s = "0"+s; }
	return s;
}

function summ(st) {
	var x = 0;
	var p = 0;
	while(p < n) {
		x += (mas[p] * (+st[p] ? 1 : -1));
		p++;
    }
	return x;
}

var arr = [];

var n = +readline();
var i = 0;
var sum = 0;

while(i < n) {
	arr[i] = +readline();
	sum += arr[i];
	i++;
}
if(sum != 360) {
	arr = sortt(arr);

	while(n != 1) {
		arr[n-2] = arr[n-1] - arr[n-2];
		arr.pop();
		arr = sortt(arr);
		n = arr.length;
	}

	if(arr[0] === 0) { print('YES'); }
	else { print('NO'); }

	function sortt(ar) {
		return ar.sort(function(a, b) { return a - b; });
	}
} 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*/
    const k = lines[0];
    const arr = lines.slice(1);

    console.log(arr);

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
	  subseqs(arr, i).map(ss => console.log(ss[0] == ss[1] ? "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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length - 1);

    console.log(arr);

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
	  subseqs(arr, i).map(ss => console.log(ss[0] == ss[1] ? "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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).map(l => l).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length - 1).map(l => parseInt(l));

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1);

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
	  subseqs(arr, i).map(ss => console.log(ss[0] == ss[1] ? "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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length - 1).map(l => parseInt(l));

    console.log(arr);

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
	  subseqs(arr, i).map(ss => console.log(ss[0] == ss[1] ? "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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length / 2; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length - 1).map(l => parseInt(l));

    console.log(arr);

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length - 1).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
			const n = arr.length;
			const res = [];
			let j = 0;

			for (let mask = 0; mask < (1 << n); mask++) {
				let num = 0;

				for (let i = 0; i < n; i++) {
					if (mask & (1 << i)) {
						num++;
					}
				}

				if (num === k) {
					res[j] = [0, 0];

					for (let i = 0; i < n; i++) {
						if (mask & (1 << i)) {
							res[j][0] = (res[j][0] + arr[i]) % 360;
						} else {
							res[j][1] = (res[j][1] + arr[i]) % 360;
						}
					}

					j++;
				}
			}

			return res;
		}

	for (let i = 1; i < arr.length / 2 + 1; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length / 2 + 1; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("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*/
    const k = lines[0];
    const arr = lines.slice(1, lines.length).filter(l => l).map(l => parseInt(l));

    if (arr.reduce((a, v) => a + v, 0) === 360) {
    	console.log("YES");
    	return;
    }

   	function subseqs(arr, k) {
	  const n = arr.length;
	  const res = [];
	  let j = 0;

	  for (let mask = 0; mask < (1 << n); mask++) {
	    let num = 0;

	    for (let i = 0; i < n; i++) {
	      if (mask & (1 << i)) {
	        num++;
	      }
	    }

	    if (num === k) {
	      res[j] = [0, 0]

	      for (let i = 0; i < n; i++) {
	        if (mask & (1 << i)) {
	          res[j][0] += arr[i]
	        } else {
	          res[j][1] += arr[i];
	        }
	      }

	      j++;
	    }
	  }

	  return res;
	}

	for (let i = 1; i < arr.length; i++) {
		for (const ss of subseqs(arr, i)) {
			if (ss[0] === ss[1]) {
				console.log("YES");
				return;
			}
		}
	}

	console.log("NO");
});

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

const lines = [];

readline.on('line', (line) => {
  lines.push(Number(line));
});

const processAngles = (n, angles) => {
  for (let i = 0; i < 2 ** (n - 1); i += 1) {
    const bitbask = i.toString(2).padStart(angles.length, '0');
    const rotation = angles.reduce((acc, angle, idx) => {
      if (bitbask[idx] === '0') {
        return acc + angle;
      }

      return acc - angle;
    }, 0);

    if (rotation === 0 || rotation === 360) {
      return 'YES';
    }
  }

  return 'NO';
};

readline.on('close', () => {
  const [n, ...angles] = lines;

  console.log(processAngles(n, angles));
});