You are given an array of $$$n$$$ integers: $$$a_1, a_2, \ldots, a_n$$$. Your task is to find some non-zero integer $$$d$$$ ($$$-10^3 \leq d \leq 10^3$$$) such that, after each number in the array is divided by $$$d$$$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least $$$\lceil\frac{n}{2}\rceil$$$). Note that those positive numbers do not need to be an integer (e.g., a $$$2.5$$$ counts as a positive number). If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.Recall that $$$\lceil x \rceil$$$ represents the smallest integer that is not less than $$$x$$$ and that zero ($$$0$$$) is neither positive nor negative.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the array. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^3 \le a_i \le 10^3$$$).

Print one integer $$$d$$$ ($$$-10^3 \leq d \leq 10^3$$$ and $$$d \neq 0$$$) that satisfies the given condition. If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.

NoteIn the first sample, $$$n = 5$$$, so we need at least $$$\lceil\frac{5}{2}\rceil = 3$$$ positive numbers after division. If $$$d = 4$$$, the array after division is $$$[2.5, 0, -1.75, 0.5, 1.5]$$$, in which there are $$$3$$$ positive numbers (namely: $$$2.5$$$, $$$0.5$$$, and $$$1.5$$$).In the second sample, there is no valid $$$d$$$, so $$$0$$$ should be printed.

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

let l = 0;
let n = 0

rl.on('line', (input) => {
    if (l === 0) {
        n = parseInt(input)
    } else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        for (let i = 1; i <= 1000; i++) {
            let p = 0;
            for (let j = 0; j < n; j++) {
                if ((arr[j] / i) > 0) {
                    p++
                }
            }
            if (p >= Math.ceil(n / 2)) {
                console.log(i)
                return
            }

            p = 0;
            for (let j = 0; j < n; j++) {
                if (arr[j] / (i * -1) > 0) {
                    p++
                }
            }
            if (p >= Math.ceil(n / 2)) {
                console.log(i * -1)
                return
            }
        }

        console.log(0)
        return
    }
    l++
});

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

var inputs = [];
const PI = parseInt;

function main() {
    pos = inputs[1].split(" ").filter(_ => PI(_) > 0);
    neg = inputs[1].split(" ").filter(_ => PI(_) < 0);

    const ln = inputs[1].split(" ").length;
    if(pos.length >= ln / 2) console.log(1);
    else if(neg.length >= ln / 2) console.log(-1);
    else console.log(0)
}

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

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var plus = 0;
  var minus = 0;
  var zero = 0;
  for(var i = 0; i < N; i++){
    if(list[i] < 0){
      minus++;
    }else if(list[i] > 0){
      plus++;
    }else{
      zero++;
    }
  }
  if(minus >= N / 2){
    myout(-1);
  }else if(plus >= N / 2){
    myout(1);
  }else{
    myout(0);
  }
}

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

let c = 0;

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

  let pos = 0;
  let neg = 0;
  const arr = d.split(" ").map(Number);
  let min = Math.ceil(arr.length / 2);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > 0) {
      pos++;
    } else if (arr[i] < 0) {
      neg++;
    }
  }

  if (pos >= min) {
    console.log(1);
  } else if (Math.abs(neg) >= min) {
    console.log(-1);
  } else {
    console.log(0);
  }
  c++;
});

let rawInput = '';
process.stdin.on('data', c => rawInput += c);
let inputByLinesOnRslv = new Promise((resolve, reject) => {
    process.stdin.on('end', () => {
        const { EOL } = require('os');
        resolve(rawInput.split(EOL));
    });
});

(async function(){

    let lines = await inputByLinesOnRslv;
    let n = parseInt(lines[0]);
    let items = lines[1].split(" ");
    let ls = parseFloat(n) / 2.0;
    let found = 0;

    for (let d = -1000; d <= 1000; ++d) {
        if (!d) { continue; }
        let many = 0;
        for (let i = 0; i < n; ++i) {
            let curd = parseFloat(items[i]) / parseFloat(d);
            if (curd > 0) { many++; }
        }
        if (many < ls) { continue; }
        found = 1;
        console.log(d);
        break;
    }
    if (!found) { console.log(0); }

})();

let rawInput = '';
process.stdin.on('data', c => rawInput += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = rawInput.split(EOL);
    let n = parseInt(lines[0]);
    let items = lines[1].split(" ");
    //console.log(items);
    let ls = parseFloat(n) / 2.0;
    //console.log(ls);
    let found = 0;
    for (let d = -1000; d <= 1000; ++d) {
        if (!d) { continue; }
        let many = 0;
        for (let i = 0; i < n; ++i) {
            let curd = 0.0;
            curd = parseFloat(items[i]) / parseFloat(d);
            //console.log(curd);
            if (curd > 0) { many++; }
        }
        if (many < ls) { continue; }
        found = 1;
        console.log(d);
        break;
    }
    if (!found) { console.log(0); }
});

var n = readline();
var x = readline().split(" ");
var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    if(x[i] > 0)
        nPositive++;
    if(x[i] < 0)
        nNegative++;
}

if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

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

var inputs = [];
const PI = parseInt;

function main() {
    pos = inputs[1].split(" ").filter(_ => PI(_) > 0);
    neg = inputs[1].split(" ").filter(_ => PI(_) < 0);

    const ln = inputs[1].split(" ").length;
    if(pos > ln / 2) console.log(1);
    else if(neg > ln / 2) console.log(-1);
    else console.log(0)
}

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

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var plus = 0;
  var minus = 0;
  var zero = 0;
  for(var i = 0; i < N; i++){
    if(list[i] < 0){
      minus++;
    }else if(list[i] > 0){
      plus++;
    }else{
      zero++;
    }
  }
  if(minus > zero && minus > plus){
    myout(-1);
  }else if(plus > zero && plus > minus){
    myout(1);
  }else{
    myout(0);
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var plus = 0;
  var minus = 0;
  var zero = 0;
  for(var i = 0; i < N; i++){
    if(list[i] < 0){
      minus++;
    }else if(list[i] > 0){
      plus++;
    }else{
      zero++;
    }
  }
  if(minus > N / 2){
    myout(-1);
  }else if(plus > N / 2){
    myout(1);
  }else{
    myout(0);
  }
}

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

let c = 0;

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

  let ans = 0;
  const arr = d.split(" ").map(Number);
  let min = Math.ceil(arr.length / 2);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > 0) {
      ans++;
    }
  }

  if (ans >= min) {
    console.log(1);
  } else {
    console.log(0);
  }
  c++;
});

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

let c = 0;

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

  let ans = 0;
  const arr = d.split(" ").map(Number);
  let min = Math.ceil(arr.length / 2);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > 0) {
      ans++;
    }
  }

  if (ans >= min) {
    console.log(ans);
  } else {
    console.log(0);
  }
  c++;
});

var n = readline();
var x;
var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    x = readline();
    print(x);

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}
print(number);
print(nPositive);
print(nNegative);
if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();
var x;
var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    x = readline();

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative++;
}

if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x = readline();

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}

if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x;
    x = readline();

    if(x > 0)
    {
        nPositive++;
        print("hello");
    }

    if(x < 0)
        nNegative--;
}
print(number);
print(nPositive);
print(nNegative);
if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x;
    x = readline();
    print(x);

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}
print(number);
print(nPositive);
print(nNegative);
if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x;
    x = readline();

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}
print(number);
print(nPositive);
print(nNegative);
if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x;
    x = readline();

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}

if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);

var n = readline();

var nPositive = 0;
var nNegative = 0;

number = Math.ceil(n / 2);

for(var i = 0; i < n; i++)
{
    var x = readline();
    print(x);

    if(x > 0)
        nPositive++;
    if(x < 0)
        nNegative--;
}
print(number);
print(nPositive);
print(nNegative);
if(nPositive >= number)
    print(1);
else if(nNegative >= number)
    print(-1);
else
    print(0);


After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.

The first line of the input contains two space-separated integers n and bx (1 ≤ n ≤ 10, 2 ≤ bx ≤ 40), where n is the number of digits in the bx-based representation of X.  The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi < bx) — the digits of X. They are given in the order from the most significant digit to the least significant one. The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10, 2 ≤ by ≤ 40, bx ≠ by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1, y2, ..., ym (0 ≤ yi < by) — the digits of Y. There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.

Output a single character (quotes for clarity):    '<' if X < Y  '>' if X > Y  '=' if X = Y

NoteIn the first sample, X = 1011112 = 4710 = Y.In the second sample, X = 1023 = 215 and Y = 245 = 1123, thus X < Y.In the third sample,  and Y = 48031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y.

function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return +readline(); }

var inp = rda();
var n = inp[0], bx = inp[1];
var x = rda();
inp = rda();
var m = inp[0], by = inp[1];
var y = rda();

var x10 = 0, y10 = 0;

var pows = [];
for(var i = 0, s = 1; i < n; i++, s *= bx){
    pows.push(s);
}
pows.reverse();
for(var i = 0; i < n; i++){
    x10 += pows[i]*x[i];
}

pows = [];
for(var i = 0, s = 1; i < m; i++, s *= by){
    pows.push(s);
}
pows.reverse();
for(var i = 0; i < m; i++){
    y10 += pows[i]*y[i];
}

if(x10 == y10){
    write("=");
}else if(x10 > y10){
    write(">");
}else{
    write("<");
}

var xParams = readline().split(' '),
    xRepresentation = readline();
    yParams = readline().split(' '),
    yRepresentation = readline();

// var xParams = "7 16".split(' '),
//     xRepresentation = "15 15 4 0 0 7 10";
//     yParams = "7 9".split(' '),
//     yRepresentation = "4 8 0 3 1 5 0";

var n = Number(xParams[0]),
    xNumSys = Number(xParams[1]),
    m = Number(yParams[0]),
    yNumSys = Number(yParams[1]);

function solver() {
    var x = transformBaseRepToDecimal(xRepresentation.split(' ').map(function (item) {
        return Number(item);
    }), xNumSys);
    var y = transformBaseRepToDecimal(yRepresentation.split(' ').map(function (item) {
        return Number(item);
    }), yNumSys);

    var res = '=';
    if (x < y) {
        return '<';
    } else if (x > y) {
        return '>';
    }

    return res;
}

function transformBaseRepToDecimal(arr, base) {
    var decimalValue = 0;

    for (var i = arr.length - 1, val = 1; i >= 0; i--) {
        decimalValue += ((val * arr[i]));
        val *= base;
    }

    return decimalValue;
}

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

var x = readline().split(' ');
var n = parseInt(x[0]);
var bx = parseInt(x[1]);
x = readline().split(' ');
var a = []
for(var i = 0; i < n; i++) {
    a[i] = parseInt(x[i]);
}
x = readline().split(' ');
var m = parseInt(x[0]);
var by = parseInt(x[1]);
x = readline().split(' ');
var b = []
for(var i = 0; i<m;i ++) {
    b[i] = parseInt(x[i]);
}
var a1 = 0;
for(var i=0;i<n;i++) {
    a1 = a1 * bx + a[i];
}
var a2 = 0;
for(var i = 0; i < m; i ++) {
    a2 = a2 * by + b[i];
}
if(a1 < a2) print("<");
else if(a1 == a2) print("=");
else print(">");


Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:  Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.

The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).

Print single integer: the number of columns the table should have.

NoteThe first example corresponds to the January 2017 shown on the picture in the statements.In the second example 1-st January is Monday, so the whole month fits into 5 columns.In the third example 1-st November is Saturday and 5 columns is enough.

var m, d, out;

m=readline().split(' ')
d=parseInt(m[1])
m=parseInt(m[0])

out=(d==7)?6:5;

switch (m){
    case 2: out=(d==1)?4:5; break;
    case 1: out=(d==6)?6:out; break;
    case 3: out=(d==6)?6:out; break;
    case 5: out=(d==6)?6:out; break;
    case 7: out=(d==6)?6:out; break;
    case 8: out=(d==6)?6:out; break;
    case 10: out=(d==6)?6:out; break;
    case 12: out=(d==6)?6:out; break;
}

print (out)

var input = readline().split(' ').map(Number);

var month = input[0];
var firstday = input[1];

var month_days = 0;

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
	month_days = 31;
} else if (month == 2) {
	month_days = 28;
} else {
	month_days = 30;
}

var wasted_days = (firstday - 1) % 7;

var total_days = wasted_days + month_days;

var weeks = Math.ceil(total_days / 7);

print(weeks);

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

const daysInMonth = (month) => new Date(2017, month, 0).getDate();

rl.on('line', (data) => {
  const [m, d] = data.split(' ').map(Number);
  const days = daysInMonth(m);
  const ans = Math.ceil((days + (d - 1)) / 7);

  console.log(ans);
});

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.num = function() {
		return Number(this.next().value);
	};
nl.nums = function() {
		return this.next().value.split(/\s/g).map(Number);
	};
nl.line = function() {
		return this.next().value;
	}

const sol = () => {
	let [m, d] = nl.nums();
	let month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	console.log(Math.trunc((d - 1 + month[m-1] + 6)/7));

};

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

var input = readline().split(' ').map(Number);

var month = input[0];
var firstday = input[1];

var month_days = 0;

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
	month_days = 31;
} else if (month == 2) {
	month_days = 29;
} else {
	month_days = 30;
}

var wasted_days = (firstday - 1) % 7;

var total_days = wasted_days + month_days;

var weeks = Math.ceil(total_days / 7);

print(weeks);

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

const daysInMonth = (month) => new Date(2017, month, 0).getDate();

rl.on('line', (data) => {
  const [m, d] = data.split(' ').map(Number);
  const days = daysInMonth(m);
  const ans = Math.ceil((days + d - (7 - d)) / 7);

  console.log(ans);
});

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

const daysInMonth = (month) => new Date(2017, month, 0).getDate();

rl.on('line', (data) => {
  const [m, d] = data.split(' ').map(Number);
  const days = daysInMonth(m);
  const ans = Math.ceil(days / 7);

  console.log(ans);
});


PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.

The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.

Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.

NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.

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

const isPrime = (n) => {
  for (let i = 2; i*i <= n; i++) {
    if (n % i === 0) {
      return false;
    }
  }

  return true;
}

rl.on('line', (d) => {
  let ans = 1;

  while (isPrime(+d * ans + 1)) {
    ans++;
  }

  console.log(ans);
});

function is_prime(n){
        for (var i=2;i*i<=n;i++)
            if (n%i==0)
                return false;
        return true;
    }
    var n = +readline();
    for (var m = 1;; m++)
        if (!is_prime(n*m+1))
        {
            print(m);
            break;
        }

var n = parseInt(readline()),
    found = false

//console.log('n',n)
for (var m = 1 ; m < 1000 && !found ; m++) {
  var res = n * m + 1
  //console.log("a",m,res,Math.sqrt(res))
  for (var div = 2 ; div <= Math.sqrt(res) && !found ; div++) {
    //console.log("b",m)
    //console.log(m,res,div,res%div)
    if (!(res%div)) found = m
  }
}

print(found)

function isPrime(temp) {
	for (var j = 2; j * j <= temp; j++) {
		if (temp % j === 0) {
			return true;
		}
	}
}
var n = Number(readline()), result;
for (var i = 1; ; i++) {
	var temp = n * i + 1;
	if (isPrime(temp)) {
	    result = i;
		break;
	}
}
print(result);

var n = parseInt(readline());
for (var m = 1; m <= 1000; m++) {
    var theoreticResult = n * m + 1;
    if (isPrime(theoreticResult)) {
        print(m);
        break;
    }
}

function isPrime(n) {
    for (var i = 2; i <= Math.sqrt(n); i++) {
        if (n % i === 0) {
            return true;
        }
    }

    return false;
}

function main() {
	var n = Number(readline());

	if (n == 1) {
		print(3);
	} else if (n == 2) {
		print(4);
	} else {
		print(n - 2);
	}

	return 0;
}

main();

var n = readline(),
lastDigit = Number(n[n.length - 1]),
secondToLastDigit = n.length >= 2 ? Number(n[n.length - 2]) : 0,
severalLastDigits = secondToLastDigit * 10 + lastDigit,
result;
if (severalLastDigits === 0) {
	severalLastDigits = Number(/[1-9]0+$/.exec(n)[0]);
}
for (var i = 1; ; i++) {
	var temp = severalLastDigits * i + 1;
	if (temp % 2 === 0 && temp != 2 || temp % 3 === 0 && temp != 3  ||
		temp % 5 === 0 && temp != 5 || temp % 7 === 0 && temp != 7 ) {
		result = i;
		break;
	}
}
print(result);


Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.

The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109).

If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function descendA(hash, a, steps) {
	if (hash[a] !== undefined && hash[a] <= steps) {
		return;
	}
	hash[a] = steps;
	if (a%2 == 0) {
		descendA(hash, a/2, steps+1);
	}
	if (a%3 == 0) {
		descendA(hash, a/3, steps+1);
	}
	if (a%5 == 0) {
		descendA(hash, a/5, steps+1);
	}
}

function descendB(hashA, hashB, b, steps, best) {
	if (hashB[b] !== undefined && hashB[b] <= steps) {
		return;
	}
	hashB[b] = steps;
	if (hashA[b] !== undefined) {
		if (best.value == -1 || hashA[b]+steps < best.value) {
			best.value = hashA[b]+steps;
		}
	}
	if (b%2 == 0) {
		descendB(hashA, hashB, b/2, steps+1, best);
	}
	if (b%3 == 0) {
		descendB(hashA, hashB, b/3, steps+1, best);
	}
	if (b%5 == 0) {
		descendB(hashA, hashB, b/5, steps+1, best);
	}
}

function main() {
	var integers = tokenizeIntegers(readline());
	var a = integers[0], b = integers[1];

	var hashA = {};
	descendA(hashA, a, 0);

	var hashB = {};
	var best = {value: -1};
	descendB(hashA, hashB, b, 0, best);

	print(best.value);
}

main();

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) { console.log(0); return; }

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let min = Infinity;
 while (true) {
  if (qa.length) {
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r] != undefined) { min = Math.min(mb[r]+sa+1, min); }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }
 }

 if (qb.length) {

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r] != undefined) { min = Math.min(ma[r]+sb+1, min); }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sb+1);
   }
  }
 }

 if (isFinite(min)) { console.log(min); return; }

  if (!qa.length && !qb.length) { console.log(-1); return; }

 }
}

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) { console.log(0); return; }

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let min = Infinity;
 while (true) {
  if (qa.length) {
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r]) { min = Math.min(mb[r]+sa+1, min); }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }
 }

 if (qb.length) {

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r]) { min = Math.min(ma[r]+sb+1, min); }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sb+1);
   }
  }
 }

 if (isFinite(min)) { console.log(min); return; }

  if (!qa.length && !qb.length) { console.log(-1); return; }

 }
}

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) return 0

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let iter = 0;
 while (true) {
  if (!qa.length && !qb.length) { console.log(-1); return; }
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r]) { console.log(mb[r]+sa+1); return; }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }

 if (!qb.length) { continue; }

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r]) { console.log(ma[r]+sb+1); return; }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sb+1);
   }
  }

  if (!qa.length) { console.log(-1); return; }

 }
}

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) return 0

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let iter = 0;
 while (true) {
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r]) { console.log(mb[r]+sa+1); return; }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }

 if (!qb.length) { console.log(-1); return; }

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r]) { console.log(ma[r]+sb+1); return; }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sa+1);
   }
  }

  if (!qa.length) { console.log(-1); return; }

 }
}

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) return 0

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let iter = 0;
 while (true) {
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r]) { console.log(mb[r]+sa+1); return; }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }

 if (!qb.length) { console.log(-1); return; }

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r]) { console.log(ma[r]+sb+1); return; }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sb+1);
   }
  }

  if (!qa.length) { console.log(-1); return; }

 }
}

const readline = require('readline')

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

rl.on('line', line => {
  const [a, b] = line.split(' ').map(v => parseInt(v, 10))
  solve(a, b)
})

function solve(a, b) {
 if (a == b) { console.log(0); return; }

 const m = {}
 if (b > a) {
  const t = a; a = b; b = t;
 }
 const ma = { [a]: 0 }
 const mb = { [b]: 0 }

 const qa = [[a, 0]]
 const qb = [[b, 0]]

 let iter = 0;
 while (true) {
  if (qa.length) {
  const [aa, sa] = qa.shift()

  for (const d of [2,3,5]) {
   if (aa%d == 0) {
     const r = aa/d
     if (mb[r]) { console.log(mb[r]+sa+1); return; }
     if (!ma[r]) { qa.push([r, sa+1]) }
     ma[r] = ma[r] || (sa+1);
   }
  }
 }

 if (qb.length) {

  const [bb, sb] = qb.shift()
  for (const d of [2,3,5]) {
   if (bb%d == 0) {
     const r = bb/d
     if (ma[r]) { console.log(ma[r]+sb+1); return; }
     if (!mb[r]) { qb.push([r, sb+1]) }
     mb[r] = mb[r] || (sb+1);
   }
  }
 }

  if (!qa.length && !qb.length) { console.log(-1); return; }

 }
}


Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≤ 1.Iahub thinks that point x belongs to segment [l, r], if inequality l ≤ x ≤ r holds.Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing.

The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤ 100) — the borders of the i-th segment. It's guaranteed that all the points are distinct.

If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		pointNum = data[0], segmentNum = data[1],
		points = tokenizeIntegers(readline());
	for (var i = 0; i < segmentNum; ++i) {
		data = tokenizeIntegers(readline());
	}
	var pointInfo = [];
	for (var i = 0; i < pointNum; ++i) {
		pointInfo.push({ index: i, value: points[i] });
	}
	pointInfo.sort(function(a, b) {
		return a.value - b.value;
	});
	var result = new Array(pointNum);
	for (var i = 0; i < pointNum; ++i) {
		result[pointInfo[i].index] = i%2;
	}
	print(result.join(' '));
}

main();

function main() {

    var input1= readline().split(' ').map(Number);

    var arr = readline().split(' ').map(Number);

    var n=input1[0];
    var temparr=arr.slice();
    var sortarr=temparr.sort(function(a, b){return a-b});
    var newarr=[];
    var result=[];
    var col=0;
    var res;

    for(var i=0;i<n;i++){
        if(i%2===0){
            col=0;
        }else {
            col=1;
        }
        var temp=[sortarr[i],col];
        newarr.push(temp);
    }

    for(var j=0;j<n;j++){
        for(var k=0;k<n;k++) {
            if (arr[j] === newarr[k][0]) {
                result.push(newarr[k][1]);
            }
        }
    }

    res=result.join(" ");
    print(res);

}

main();

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function sortNumber(a, b) {
    return a - b;
}

function main() {
    var n = nextInt();
    var m = nextInt();
    var arr = [];
    var pos = [];
    var r = [];
    for (var i = 0; i < 101; i++) {
        r[i] = -1;
    }
    for (var i = 0; i < n; i++) {
        arr[i] = nextInt();
        pos[arr[i]] = i;
    }
    for (var i = 0; i < m; i++) {
        var x = nextInt();
        var y = nextInt();
    }
    var s = "";
    arr.sort(sortNumber);
    for (var i = 0; i < n; i++) {
        r[pos[arr[i]]] = i % 2;
    }
    for (var i = 0; i < 101; i++) {
        if (r[i] != -1) {
            s += r[i] + " ";
        }
    }
    print(s);
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		pointNum = data[0], segmentNum = data[1],
		points = tokenizeIntegers(readline()),
		segments = [],
		colors = new Array(101);
	for (var i = 0; i < colors.length; ++i) {
		colors[i] = 0;
	}
	for (var i = 0; i < pointNum; ++i) {
		colors[points[i]] = (i%2 == 0 ? -1 : 1);
	}
	for (var i = 0; i < segmentNum; ++i) {
		data = tokenizeIntegers(readline());
		segments.push({ left: data[0], right: data[1] });
	}
	for (var i = 0; i < segmentNum; ++i) {
		var segment = segments[i],
			count = 0;
		for (var j = segment.left; j <= segment.right; ++j) {
			count += colors[j];
		}
		if (count < -1 || count > 1) {
			print(-1);
			return;
		}
	}
	var result = [];
	for (var i = 0; i < pointNum; ++i) {
		result.push(i%2);
	}
	print(result.join(' '));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		pointNum = data[0], segmentNum = data[1],
		points = tokenizeIntegers(readline());
	for (var i = 0; i < segmentNum; ++i) {
		data = tokenizeIntegers(readline());
	}
	var result = [];
	for (var i = 0; i < pointNum; ++i) {
		result.push(i%2 == 0 ? 1 : 0);
	}
	print(result.join(' '));
}

main();

function main() {

    var input1= readline().split(' ').map(Number);

    var arr = readline().split(' ').map(Number);

    var n=input1[0];
    var temparr=arr.slice();
    var sortarr=temparr.sort(function(a, b){return a-b});
    var newarr=[];
    var result=[];
    var col=0;

    for(var i=0;i<n;i++){
        if(i%2===0){
            col=0;
        }else {
            col=1;
        }
        var temp=[sortarr[i],col];
        newarr.push(temp);
    }

    for(var j=0;j<n;j++){
        for(var k=0;k<n;k++) {
            if (arr[j] === newarr[k][0]) {
                result.push(newarr[k][1]);
            }
        }
    }

    print(result);

}

main();

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function main() {
    var n = nextInt();
    var m = nextInt();
    var arr = [];
    var pos = [];
    var r = [];
    for (var i = 0; i < 101; i++) {
        r[i] = -1;
    }
    for (var i = 0; i < n; i++) {
        arr[i] = nextInt();
        pos[arr[i]] = i;
    }
    for (var i = 0; i < m; i++) {
        var x = nextInt();
        var y = nextInt();
    }
    var s="";
    arr.sort();
    for (var i = 0; i < n; i++) {
        r[pos[arr[i]]] = i % 2;
    }
    for (var i = 0; i < 101; i++) {
        if (r[i] != -1) {
            s += r[i] + " ";
        }
    }
    print(s);
}

main();

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function main() {
    var n = nextInt();
    var m = nextInt();
    var arr = [];
    for (var i = 0; i < n; i++) {
        arr[i] = nextInt();
    }
    for (var i = 0; i < m; i++) {
        var x = nextInt();
        var y = nextInt();
    }
    var s = "";
    var r = [];
    for (var i = 0; i < 101; i++) {
        r[i] = i % 2;
    }
    for (var i = 0; i < n; i++) {
        s += r[arr[i]] + " ";
    }
    print(s);
}

main();

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

var Point = (function () {
    function Point(x) {
        this.pre = 0;
        this.pos = 0;
        this.color = -1;
        this.pos = x;
        this.pre = x;
    }
    Point.prototype.putSeg = function (left, right) {
        if (left < this.pre) {
            this.pre = left;
        }
        if (right > this.pos) {
            this.pos = right;
        }
    };
    return Point;
})();

function main() {
    var arr = [];
    var arrC = [];
    var n = nextInt();
    var m = nextInt();
    for (var i = 0; i < n; i++) {
        arr[i] = nextInt();
    }
    for (var i = 0; i <= 100; i++) {
        arrC[i] = new Point(i);
    }
    for (var i = 0; i < m; i++) {
        var l = nextInt();
        var r = nextInt();
        for (var j = l; j <= r; j++) {
            arrC[j].putSeg(l, r);
        }
    }
    for (var i = 0; i < n; i++) {
        for (var j = arrC[arr[i]].pre; j <= arrC[arr[i]].pos; j++) {
            arrC[j].color++;
        }
    }
    var s = "";
    for (var i = 0; i < n; i++) {
        s += (arrC[arr[i]].color % 2) + " ";
    }
    print(s);
}

main();

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

function main() {
    var n = nextInt();
    var m = nextInt();
    for (var i = 0; i < n; i++) {
        var x = nextInt();
    }
    for (var i = 0; i < m; i++) {
        var x = nextInt();
        var y = nextInt();
    }
    var s = "0";
    for (var i = 1; i < n; i++) {
        s = s + " " + (i % 2);
    }
    print(s);
}

main();


A group of $$$n$$$ dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.

The first line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n \leq 20$$$, $$$1 \leq a, b \leq 100$$$) — the number of dancers, the cost of a white suit, and the cost of a black suit. The next line contains $$$n$$$ numbers $$$c_i$$$, $$$i$$$-th of which denotes the color of the suit of the $$$i$$$-th dancer. Number $$$0$$$ denotes the white color, $$$1$$$ — the black color, and $$$2$$$ denotes that a suit for this dancer is still to be bought.

If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.

NoteIn the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.In the third sample, all suits are already bought and their colors form a palindrome.

var ip = readline().split(' ').map(Number);
var n = ip[0],line = readline().split(' ').map(Number),sum = 0,ar = new Array(3),match = true;
ar[0] = ip[1];ar[1] = ip[2];ar[2] = 101;
for (var i =0;i<=(n-1)/2;i++){
    if (line[i] !== line[n-1-i]){
        if (line[i] === 2 || line[n-i-1] === 2){
            sum += Math.min(ar[line[i]],ar[line[n-1-i]]);
        } else {
            sum = -1;
            break;
        }
    } else if (line[i] === 2 && line[n-1-i] === 2){
            sum += Math.min(ar[0],ar[1]) * (i === n-1-i ? 1:2);
    }
}
print(sum)

var x = readline()
  .split(" ")
  .map(x => Number(x));
var n = x[0],
  a = x[1],
  b = x[2];
var c = readline()
  .split(" ")
  .map(x => Number(x));

var min = Math.min(a, b);

var price = 0;
var possible = true;

for (var i = 0; i < c.length; i++) {
  var j = c.length - i - 1;

  if (c[i] === 2) {
    if (c[j] === 0) {
      price += a;
    } else if (c[j] === 1) {
      price += b;
    } else {
      price += min;
    }
  } else if (c[i] !== c[j] && c[j] !== 2) {
    possible = false;
  }
}

if (possible) {
  print(price);
} else {
  print(-1);
}

var input=readline().split(' ').map(Number);
var arr=readline().split(' ').map(Number);
var long=(input[0]-1),white=input[1],black=input[2],result=0,check=true;
for(var i=0;i<=long/2;i++){
    if(arr[i]!=arr[long-i]&&arr[i]!=2&&arr[long-i]!=2){
        check=false;
        break;
    }else
        if(arr[i]+arr[long-i]===4){
            if(i!=(long-i))
                result+=black>white?2*white:2*black;
            else
                result+=black>white?white:black;
        }else if(arr[i]===2){
            result+=arr[long-i]===0?white:black;
        }else if(arr[long-i]===2)
            result+=arr[i]===0?white:black;
}
print(check?result:"-1");

var par = readline().split(" ").map( (x) => parseInt(x));
var n = par[0];
var price = [par[1], par[2]]
var minPrice = par[1]<par[2]?par[1]:par[2];
var arr = readline().split(" ").map( (x) => parseInt(x));
var result = 0;
var fail = false;
for(var i = 0; i<parseInt(n/2); i++) {
    if(arr[i]!==2&&arr[n-1-i]!==2) {
        if(arr[i]!==arr[n-1-i]) {
            fail = true;
            break;
        } else {
            continue;
        }
    }
    if(arr[i]===2&&arr[n-1-i]===2) {
        result+=2*minPrice;
        continue;
    }
    if(arr[i]===2) {
        result += price[arr[n-1-i]]
    }
    else {
        result += price[arr[i]]
    }
}
if(fail) {
    result = -1;
} else if(n%2===1&&arr[parseInt(n/2)]===2) {
    result += minPrice;
}
print(result);

var Readcount = readline().split(' ').map(Number);
  var ArrayReadcount = new Array(3)
      ArrayReadcount[0] = Readcount[0];  ArrayReadcount[1] = Readcount[1];  ArrayReadcount[2] = Readcount[2];
           var cheapest = 0;
           var calc = 0;

if(ArrayReadcount[1] < ArrayReadcount[2] ){
    cheapest = ArrayReadcount[1]
} else{
  cheapest = ArrayReadcount[2]
}

    //  var j = document.getElementById('i').value;
      var Values = readline().split(' ');

 var limit = 0;
//alert(parseInt(Values.length/2) + " " + (Values.length/2))
if ( parseInt(Values.length/2) != (Values.length/2) ){

limit = Math.floor(Values.length/2);
}else{
limit = parseInt(Values.length/2);
}

      for (var x = 0; x < limit; x++)
       {

var y = x + 1;

if (Values[x] + Values[Values.length - y] == "01" ){
 calc = -1;
 break; }

else if ( Values[x] + Values[Values.length - y] == "10"){
 calc = -1;
 break; }

//alert( x + " " + Values[x] + Values[Values.length - y]  );

if(Values[x] + Values[Values.length - y] == "22"){calc = calc + (cheapest * 2)}

if(Values[x] + Values[Values.length - y] == "21"){calc = calc + ArrayReadcount[2]}
if(Values[x] + Values[Values.length - y] == "12" ){calc = calc + ArrayReadcount[2]}

if(Values[x] + Values[Values.length - y] == "20") {calc = calc + ArrayReadcount[1]}
if(Values[x] + Values[Values.length - y] == "02" ) {calc = calc + ArrayReadcount[1]}

      }

        if (calc != "-1") {

        if (limit != (Values.length / 2)){
        if (Values[limit] == "2") {calc = calc + cheapest}
        }
        }

        print(calc);

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = "./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./helpers/input-manager.js":
/*!**********************************!*\
  !*** ./helpers/input-manager.js ***!
  \**********************************/
/*! exports provided: InputManager */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "InputManager", function() { return InputManager; });
const fs = __webpack_require__(/*! fs */ "fs");

class InputManager {
    static getInput() {
        return new Promise((resolve) => {
            let input = '';

            if (fs.existsSync('./input.txt')) {
                input = fs.readFileSync('./input.txt').toString();
                resolve(this.parseInputString(input));
            } else {
                process.stdin.resume();
                process.stdin.setEncoding('utf-8');
                process.stdin.on('data', inputStdin => {
                    input += inputStdin;
                });

                process.stdin.on('end', () => {
                    resolve(this.parseInputString(input));
                });
            }
        });
    }

    static parseInputString(input) {
        return input.replace(/\s*$/, '')
            .split('\n')
            .map(str => str.replace(/\s*$/, ''));
    }
}

/***/ }),

/***/ "./helpers/solution-manager.js":
/*!*************************************!*\
  !*** ./helpers/solution-manager.js ***!
  \*************************************/
/*! exports provided: SolutionManager */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SolutionManager", function() { return SolutionManager; });
class SolutionManager {
    static printSolution(solutionFn) {
        let result = solutionFn();
        if (typeof result !== 'undefined') {
            if (Array.isArray(result)) {
                result.forEach(v => console.log(v));
            } else {
                console.log(result);
            }
        }
    }
}

/***/ }),

/***/ "./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js":
/*!***********************************************************************************************!*\
  !*** ./sources/hackerrank/algorithms/practice/strings/highest-value-palindrome-copy/index.js ***!
  \***********************************************************************************************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _helpers_solution_manager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../../../helpers/solution-manager */ "./helpers/solution-manager.js");
/* harmony import */ var _helpers_input_manager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../../../helpers/input-manager */ "./helpers/input-manager.js");

_helpers_input_manager__WEBPACK_IMPORTED_MODULE_1__["InputManager"].getInput().then((input) => _helpers_solution_manager__WEBPACK_IMPORTED_MODULE_0__["SolutionManager"].printSolution(() => {
    let [n, a, b] = input.shift().split(' ').map(v => Number(v));
    let suits = input.shift().split(' ').map(v => Number(v));
    let costs = [a, b];
    let totalCost = 0;
    let i = 0;

    for (i = 0; i < Math.floor(n / 2); i++) {
        let mirrorIndex = n - 1 - i;

        if (suits[i] !== suits[mirrorIndex]) {
            if (suits[mirrorIndex] !== 2 && suits[i] !== 2) {
                return -1;
            }

            let colorIndex = suits[mirrorIndex] === 2 ? mirrorIndex : i;
            totalCost += costs[mirrorIndex === colorIndex ? suits[i] : suits[mirrorIndex]];
        } else if (suits[mirrorIndex] === 2 && suits[i] === 2) {
            totalCost += Math.min(a, b) * 2;
        }
    }

    if (suits[i] === 2 && n % 2 !== 0) {
        totalCost += Math.min(a, b);
    }

    return totalCost;
}));

/***/ }),

/***/ "fs":
/*!*********************!*\
  !*** external "fs" ***!
  \*********************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = require("fs");

/***/ })

/******/ });
//# sourceMappingURL=index.built.js.map

const x = readline()
  .split(" ")
  .map(x => Number(x));
const n = x[0],
  a = x[1],
  b = x[2];
const c = readline()
  .split(" ")
  .map(x => Number(x));

const min = Math.min(a, b);

var price = 0;
var possible = true;

for (var i = 0; i < c.length / 2 - 1; i++) {
  const j = c.length - i - 1;
  if (c[i] === 2 && c[j] === 2) {
    price += min * 2;
  } else if (c[i] === 2) {
    price += add(c[j]);
  } else if (c[j] === 2) {
    price += add(c[i]);
  } else if (c[i] !== c[j]) {
    possible = false;
  }
}

if (c.length % 2 === 1 && c[Math.floor(c.length / 2)] === 2) {
  price += min;
}

if (possible) {
  print(price);
} else {
  print(-1);
}

function add(color) {
  if (color === 0) {
    return a;
  } else {
    return b;
  }
}

var input=readline().split(' ').map(Number);
var arr=readline().split(' ').map(Number);
var long=(input[0]-1),white=input[1],black=input[2],result=0,check=true;
for(var i=0;i<=(long+1)/2;i++){
    if(arr[i]!=arr[long-i]&&arr[i]!=2&&arr[long-i]!=2){
        check=false;
        break;
    }else
        if(arr[i]+arr[long-i]===4){
            if(i!=(long-i))
                result+=black>white?2*white:2*black;
            else
                result+=black>white?white:black;
        }else if(arr[i]===2){
            result+=arr[long-i]===0?white:black;
        }else if(arr[long-i]===2)
            result+=arr[i]===0?white:black;
}
print(check?result:"-1");

var par = readline().split(" ").map( (x) => parseInt(x));
var n = par[0];
var price = [par[1], par[2]]
var minPrice = par[1]<par[2]?par[1]:par[2];
var arr = readline().split(" ").map( (x) => parseInt(x));
var result = 0;
for(var i = 0; i<parseInt(n/2); i++) {
    if(arr[i]!==2&&arr[n-1-i]!==2) continue;
    if(arr[i]===2&&arr[n-1-i]===2) {
        result+=2*minPrice;
        continue;
    }
    if(arr[i]===2) {
        result += price[arr[n-1-i]]
    }
    else {
        result += price[arr[i]]
    }
}
if(n%2===1&&arr[parseInt(n/2)]===2) {
    result += minPrice;
}
print(result);


Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen. There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move. Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.

The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.

On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.  If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.

NoteIn the first sample test the white queen can capture the black queen at the first move, so the white player wins.In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1). Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3). In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.

n=readline()
if (n%2)
{
    print("black")
}
else
{
    print("white")
    print("1 2")
}

var n = parseInt(readline());
if (n % 2 == 0)
	print("white\n1 2");
else
	print("black");