(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var input = rdArN();
    var n = input[0];
    var m = input[1];
    var A = [];
    for (var i = 0; i < n; ++i) {
        A.push(rdArN());
    }
    var dx = [0,1,0,1];
    var dy = [0,0,1,1];
    var check = function(x, y) {
        var f = true;
        for (var k = 0; k < 4; ++k) {
            f = f && (A[x + dx[k]][y + dy[k]] > 0);
        }
        return f;
    };
    var fill = function (x, y) {
        for (var k = 0; k < 4; ++k) {
            A[x + dx[k]][y + dy[k]] = 2;
        }
    };
    var fillOrder = []
    for (var i = 0; i < n-1; ++i) {
        for (var j = 0; j < m-1; ++j) {
            if (check(i, j)) {
                fill(i, j);
                fillOrder.push([i+1, j+1]);
            }
        }
    }
    var isFilled = true;
    for (var i = 0; i < n; ++i) {
        for (var j = 0; j < m; ++j) {
            if (A[i][j] === 1) {
                isFilled = false;
            }
        }
    }
    if (isFilled) {
        pr(fillOrder.length);
        for (var i = 0; i < fillOrder.length; ++i) {
            prAr(fillOrder[i]);
        }
    } else {
        pr(-1);
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

// let n = 3;
// let m = 3;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

// console.log(squareFilling(n, m, resultArray));

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;

  function getSquare (x, y) {
    try {
      return {
        topLeft: resultArray[x][y],
        topRight: resultArray[x + 1][y],
        bottomLeft: resultArray[x][y + 1],
        bottomRight: resultArray[x + 1][y + 1]
      }
    } catch (e) {
      return null
    }

  }

  function isConform (x, y) {
    let square = getSquare(x, y)
    if (!square) {
      return false
    }
    let { topLeft, topRight, bottomLeft, bottomRight } = square;
    return (topLeft * topRight * bottomLeft * bottomRight === 1);
  }

  while (x < n) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    } else if (resultArray[x][y] === 1) {
      // 看周围有没有可以满足的，如果没有，return -1
      if (!isConform(x-1, y-1) && !isConform(x, y-1) && !isConform(x-1, y)) {
        return -1;
      }
    }
    // 从0 开始，也就是偶数开始
    if (x % 2 === 0) {
      // 偶数 向右
      y+=1;
      if (y === m) {
        x += 1;
      }
    } else {
      // 奇数 向左
      y-=1;
      if (y === -1) {
        x += 1;
      }
    }
  }
  if (!operateSelect.length) {
    return 0;
  }
  let resStr = `${operateCount}\n`
  let resArr = []
  operateSelect.forEach((item) => {
    resArr.push(item.join(' '))
  });
  return resStr + resArr.join('\n');
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

return

// let n = 3;
// let m = 2;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function isConform(x, y) {
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  let operateIndex = 0;
// 变成一个方阵之后的总长度
  let len = (n -1) * (m - 1);

  while (operateIndex < len) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    let curIdx = Math.floor((operateIndex + 1)/n);

    // 从0 开始，也就是偶数开始
    if (curIdx % 2 === 0) {
      // 偶数 向下
      x+=1;
      if (x === (n - 1)) {
        x -=1;
        y += 1;
      }
    } else {
      // 奇数 向上
      x-=1;
    }
    operateIndex++;
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return '';
    }
    return - 1;
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

return

// let n = 3;
// let m = 2;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;

  function isConform(x, y) {
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  let operateIndex = 0;
// 变成一个方阵之后的总长度
  let len = (n -1) * (m - 1);

  while (operateIndex < len) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    let curIdx = Math.floor((operateIndex + 1)/n);

    // 从0 开始，也就是偶数开始
    if (curIdx % 2 === 0) {
      // 偶数 向下
      x+=1;
      if (x === (n - 1)) {
        x -=1;
        y += 1;
      }
    } else {
      // 奇数 向上
      x-=1;
    }
    operateIndex++;
  }
  if (!operateSelect.length) {
    return - 1;
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

// let n = 3;
// let m = 3;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

// console.log(squareFilling(n, m, resultArray));

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function getSquare (x, y) {
    return {
      topLeft: resultArray[x][y],
      topRight: resultArray[x + 1][y],
      bottomLeft: resultArray[x][y + 1],
      bottomRight: resultArray[x + 1][y + 1]
    }
  }

  function isConform (x, y) {
    let { topLeft, topRight, bottomLeft, bottomRight } = getSquare(x, y);

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft * topRight * bottomLeft * bottomRight !== 0);
  }

  while (x < n - 1) {
    if (
      x < n -1
      && x > 0
      && y > 0
      && y < m -1
      && resultArray[x][y] == 1
      && !isConform(x, y-1)
      && !isConform(x-1, y-1)
      && !isConform(x-1, y)
    ) {
      // 孤点
      return -1;
    }
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    // 从0 开始，也就是偶数开始
    if (x % 2 === 0) {
      // 偶数 向右
      y+=1;
      if (y === (m - 1)) {
        y -=1;
        x += 1;
      }
    } else {
      // 奇数 向左
      y-=1;
      if (y === -1) {
        y = 0;
        x += 1;
      }
    }
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return -1;
    }
    return 0;
  }
  let resStr = `${operateCount}\n`
  let resArr = []
  operateSelect.forEach((item) => {
    resArr.push(item.join(' '))
  });
  return resStr + resArr.join('\n');
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

// let n = 3;
// let m = 3;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

// console.log(squareFilling(n, m, resultArray));

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function isConform(x, y) {
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  while (x < n - 1) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    // 从0 开始，也就是偶数开始
    if (x % 2 === 0) {
      // 偶数 向右
      y+=1;
      if (y === (m - 1)) {
        y -=1;
        x += 1;
      }
    } else {
      // 奇数 向左
      y-=1;
      if (y === -1) {
        y = 0;
        x += 1;
      }
    }
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return -1;
    }
    return 0;
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

return

// let n = 3;
// let m = 2;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function isConform(x, y) {
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  let operateIndex = 0;
// 变成一个方阵之后的总长度
  let len = (n -1) * (m - 1);

  while (operateIndex < len) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    let curIdx = Math.floor((operateIndex + 1)/n);

    // 从0 开始，也就是偶数开始
    if (curIdx % 2 === 0) {
      // 偶数 向下
      x+=1;
      if (x === (n - 1)) {
        x -=1;
        y += 1;
      }
    } else {
      // 奇数 向上
      x-=1;
    }
    operateIndex++;
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return -1;
    }
    return '';
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

// let n = 3;
// let m = 2;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function isConform(x, y) {
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  let operateIndex = 0;
// 变成一个方阵之后的总长度
  let len = (n -1) * (m - 1);

  while (operateIndex < len) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    let curIdx = Math.floor((operateIndex + 1)/n);

    // 从0 开始，也就是偶数开始
    if (curIdx % 2 === 0) {
      // 偶数 向下
      x+=1;
      if (x === (n - 1)) {
        x -=1;
        y += 1;
      }
    } else {
      // 奇数 向上
      x-=1;
      if (x === -1) {
        x = 0
      }
    }
    operateIndex++;
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return -1;
    }
    return 0;
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0, n, m, resultArr = [];
rl.on('line', function(line){
  if (lineCount === 0) {
    let resOne = line.trim().split(' ');
    n = parseInt(resOne[0]);
    m = parseInt(resOne[1]);
  } else {
    resultArr.push(line.trim().split(' ').map((item) => parseInt(item)));
  }
  if (lineCount === n) {
    console.log(squareFilling(n, m, resultArr))
    rl.close();
  }
  lineCount ++;
});

// let n = 3;
// let m = 2;

// let resultArray = [
//     [1,1,1],
//     [1,1,1],
//     [0,1,1]
// ];
// let resultArray = [
//   [1,0,1],
//   [1,0,1],
//   [0,0,0]
// ];
// let resultArray = [
//   [0,0],
//   [0,0],
//   [0,0]
// ];

function squareFilling (n, m, resultArray) {
  let operateCount = 0;
  let operateSelect = [];
  let x = 0;
  let y = 0;
  let hasOne = false;

  function isConform(x, y) {
    console.log(x)
    let topLeft = resultArray[x][y];
    let topRight = resultArray[x + 1][y];
    let bottomLeft = resultArray[x][y + 1];
    let bottomRight = resultArray[x + 1][y + 1];

    if (!hasOne && (topLeft === 1 || topRight === 1 || bottomLeft === 1 || bottomRight === 1)) {
      hasOne = true;
    }

    return (topLeft === 1 && topRight === 1 && bottomLeft === 1 && bottomRight === 1)
  }

  let operateIndex = 0;
// 变成一个方阵之后的总长度
  let len = (n -1) * (m - 1);

  while (operateIndex < len) {
    if (isConform(x, y)) {
      operateCount+=1;
      operateSelect.push([x + 1,y + 1]);
    }

    let curIdx = Math.floor((operateIndex + 1)/n);

    // 从0 开始，也就是偶数开始
    if (curIdx % 2 === 0) {
      // 偶数 向下
      x+=1;
      if (x === (n - 1)) {
        x -=1;
        y += 1;
      }
    } else {
      // 奇数 向上
      x-=1;
      if (x === -1) {
        x = 0
      }
    }
    operateIndex++;
  }
  if (!operateSelect.length) {
    if (hasOne) {
      return -1;
    }
    return 0;
  }
  let resStr = `${operateCount}\n`
  operateSelect.forEach((item, idx) => {
    resStr += `${item[0]} ${item[1]}` + ((idx < operateSelect.length - 1) ? '\n' : '')
  });
  return resStr;
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var input = rdArN();
    var n = input[0];
    var m = input[1];
    var A = [];
    for (var i = 0; i < n; ++i) {
        A.push(rdArN());
    }
    var dx = [0,1,0,1];
    var dy = [0,0,1,1];
    var check = function(x, y) {
        var f = true;
        for (var k = 0; k < 4; ++k) {
            f = f && (A[x + dx[k]][y + dy[k]] > 0);
        }
        return f;
    };
    var fill = function (x, y) {
        for (var k = 0; k < 4; ++k) {
            A[x + dx[k]][y + dy[k]] = 2;
        }
    };
    var fillOrder = []
    for (var i = 0; i < n-1; ++i) {
        for (var j = 0; j < m-1; ++j) {
            if (check(i, j)) {
                fill(i, j);
                fillOrder.push([i+1, j+1]);
            }
        }
    }
    var isFilled = true;
    for (var i = 0; i < n-1; ++i) {
        for (var j = 0; j < m-1; ++j) {
            if (A[i][j] === 1) {
                isFilled = false;
            }
        }
    }
    if (isFilled) {
        pr(fillOrder.length);
        for (var i = 0; i < fillOrder.length; ++i) {
            prAr(fillOrder[i]);
        }
    } else {
        pr(-1);
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();


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.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let n = nl.num();
	let a = nl.nums();
	a = a.concat(a);
	let cnt = 0;
	let c = 0;
	for(let i of a){
		if (i === 1){
			c++;
		} else if (c > cnt){
			cnt = c;
			c = 0;
		} else {
			c = 0;
		}
	}
	if (c > cnt) cnt = c;
	console.log(cnt);

};

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

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 arr = d.split(' ').map(Number);
  let ans = 0;
  let count = 0;

  for (let i = 0; i < 2 * arr.length; i++) {
    if (arr[i % arr.length] === 1) {
      count++;
    }
    else {
      count = 0;
    }

    ans = Math.max(ans, count);
  }

  console.log(ans);

  // const idxZero = arr.indexOf(0);

  // if (idxZero !== -1) {
  //   arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];
  // }

  // for (let i = 0; i < arr.length; i++) {
  //   if (arr[i] === 1) {
  //     count++;
  //   }
  //   else {
  //     count = 0;
  //   }

  //   ans = Math.max(ans, count);
  // }

  // console.log(ans);

  c++;
});

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    str = str + " " + str;
    //console.log(str);
    let count = 0, mn = 0;
    str.split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

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

     var n = readline()
   var arr = readline().split(' ').map(Number)
   var ans = 0,cnt = 0
   var p = 0
   var f = true
   for(var i=0; i<n; i++) {
        if(arr[i]===0){
            if(f) {
                p = cnt
            }
            ans = Math.max(ans,cnt)
            cnt = 0
            f = false
        }
        else {
            cnt++
        }
    }
    p = p + cnt
    ans = Math.max(ans,p)
    print(ans)

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 arr = d.split(' ').map(Number);
  const idxZero = arr.indexOf(0);
  let ans = 0;
  let count = 0;

  if (idxZero !== -1) {
    arr = [...arr.slice(idxZero + 1), ...arr.slice(0, idxZero + 1)];
  }

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === 1) {
      count++;
    }
    else {
      count = 0;
    }

    ans = Math.max(ans, count);
  }

  console.log(ans);

  c++;
});

     var n = readline()
   var arr = readline().split(' ').map(Number)
   var ans = 0,cnt = 0
   for(var i=0; i<n; i++) {
        if(arr[i]===0){
            ans = Math.max(ans,cnt)
            cnt = 0
        }
        else {
            cnt++
        }
    }
    ans = Math.max(ans,cnt)
    print(ans)

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    const arr = inputs[1].split(" ").map(_ => parseInt(_));
    let s = arr[n - 1];
    let count = s;
    let i = 0;
    let mn = 0;
    while(i < n) {
        mn = Math.max(count, mn);
        if(arr[i] === 1) count++;
        if(arr[i] === 0) {
            count = 0;
        }
        i++;
    }
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    let s = str[str.length - 1];
    let count = parseInt(s);
    let mn = 0;
    str.split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let str = "";
    for(let i = 1 ; i < inputs.length ; i++) {
        str += " " + inputs[i];
    }
    str = str + " " + str;
    let count = 0, mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val == 1) count++;
        else if(val == 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split().map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let i = 0;
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        mn = Math.max(count, mn);
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    let s = inputs[1][inputs[1].length - 1];
    let count = parseInt(s);
    let i = 0;
    let mn = 0;
    inputs[1].split(" ").map(_ => parseInt(_)).forEach( val => {
        if(val === 1) count++;
        else if(val === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    });
    console.log(Math.min(n, mn));
}

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

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

var inputs = [];
const PI = parseInt;

function main() {
    const n = inputs[0].split(" ").map(_ => parseInt(_))[0];
    const arr = inputs[1].split(" ").map(_ => parseInt(_));
    let s = arr[n - 1];
    let count = s;
    let i = 0;
    let mn = 0;
    while(i < n) {
        mn = Math.max(count, mn);
        if(arr[i] === 1) count++;
        if(arr[i] === 0) {
            count = 0;
        }
        mn = Math.max(count, mn);
        i++;
    }
    console.log(Math.min(n, mn));
}

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


#!/usr/bin/env node

/**
 * Module dependencies.
 */

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

rl.on("line", function(line) {
    var a, b, c;
    a = b = c = 0;
    if (line.indexOf('a') < 0 ||
        line.indexOf('b') < 0 ||
        line.indexOf('c') < 0) {
        console.log("NO");
        rl.close();
    }
    if (!(line.lastIndexOf('a') < line.indexOf('b') &&
            line.lastIndexOf('b') < line.indexOf('c'))) {
        console.log("NO");
        rl.close();
    }
    for (var i = 0; i < line.length; i++) {
        switch (line.charAt(i)) {
            case 'a': a++; break;
            case 'b': b++; break;
            case 'c': c++; break;
        }
    }
    console.log((a === c || b === c) ? "YES" : "NO");
    rl.close();
}).on("close", function() {
    process.exit();
});

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');
// edge case

function checkString(s) {

  // var ans = '';
  if (s.indexOf('a') === -1
      || s.indexOf('b') === -1
      || s.indexOf('c') === -1
      || s.indexOf('a') > s.indexOf('b')
      || s.indexOf('b') > s.indexOf('c')
      || s.indexOf('a') > s.indexOf('c')
    ) {
    // print('NO')
    return 'NO';
  } else {
    var countA = null, countB = null, countC = null;

    for (var i = 0; i < s.length; i++) {
      if (s[i + 1] < s[i]) {
        // print('NO')
        return 'NO';
      }
      if (s[i] === 'a') countA += 1;
      if (s[i] === 'b') countB += 1;
      if (s[i] === 'c') countC += 1;
    }

    if ((countC === countA || countC === countB) /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {
      if (s[s.length - 1] !== 'c') {
        // print('NO');
        return 'NO';
      } else {
        // print('YES');
        return 'YES';
      }
    } else {
      // print('NO');
      return 'NO';
    }
  }
}

print(checkString(s));

var s = readline()
if (s != s.split('').sort().join('')) {
  print('NO')
} else {
  var a =0, b=0, c=0;
  for(var i=0; i<s.length; i++) {
    if (s[i] == 'a') a++
    else if (s[i] == 'b') b++
    else if (s[i] == 'c') c++
  }
  if (a == 0 || b == 0 || c == 0)  print('NO')
  else if (c == a || c == b) print('YES')
  else print('NO')
}

var inp = readline();

var spread = inp.split('').reduce(
    function(res, cur) {
        var lastItem = res[res.length - 1];

        if (lastItem && lastItem.char === cur) {
            lastItem.count++;
        } else {
            res.push({
                char: cur,
                count: 1,
            });
        }

        return res;
    },
    []
);

if (
    spread.map(function(item) {
        return item.char.toLowerCase();
    }).join('') !== 'abc'
) {
    print('NO');
} else {
    var aCount = spread[0].count;
    var bCount = spread[1].count;
    var cCount = spread[2].count;

    if (
        (!aCount || !bCount || !cCount) ||
        cCount !== aCount && cCount !== bCount
    ) {
        print('NO');
    } else {
        print('YES');
    }
}

var s = readline()
if (s != s.split('').sort().join('')) {
  print('NO')
} else {
  var a =0, b=0, c=0;
  for(var i=0; i<s.length; i++) {
    if (s[i] == 'a') a++
    else if (s[i] == 'b') b++
    else if (s[i] == 'c') c++
  }
  if (c == a || c == b) print('YES')
  else print('NO')
}

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');

// edge case

if (s.indexOf('a') === -1
    || s.indexOf('b') === -1
    || s.indexOf('c') === -1
    || s.indexOf('a') > s.indexOf('b')
    || s.indexOf('b') > s.indexOf('c')
    || s.indexOf('a') > s.indexOf('c')
  ) {
  print('NO')
} else {

  var countA = null, countB = null, countC = null;

  for (var i = 0; i < s.length; i++) {
    if (s[i] === 'a') countA += 1;
    if (s[i] === 'b') countB += 1;
    if (s[i] === 'c') countC += 1;
  }

  if (countC === countA || countC === countB && s[s.length - 1] === 'c') {
    print('YES');
  } else {
    print('NO');
  }
}

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');

// edge case

if (s.indexOf('a') === -1
    || s.indexOf('b') === -1
    || s.indexOf('c') === -1
    || s.indexOf('a') > s.indexOf('b')
    || s.indexOf('b') > s.indexOf('c')
    || s.indexOf('a') > s.indexOf('c')
  ) {
  print('NO')
} else {

  var countA = null, countB = null, countC = null;

  for (var i = 0; i < s.length; i++) {
    if (s[i] === 'a') countA += 1;
    if (s[i] === 'b') countB += 1;
    if (s[i] === 'c') countC += 1;
  }

  if (countC === countA || countC === countB) {
    print('YES');
  } else {
    print('NO');
  }
}

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');
// edge case

if (s.indexOf('a') === -1
    || s.indexOf('b') === -1
    || s.indexOf('c') === -1
    || s.indexOf('a') > s.indexOf('b')
    || s.indexOf('b') > s.indexOf('c')
    || s.indexOf('a') > s.indexOf('c')
  ) {
  print('NO')
} else {

  var countA = null, countB = null, countC = null;

  for (var i = 0; i < s.length; i++) {
    if (s[i] === 'a') countA += 1;
    if (s[i] === 'b') countB += 1;
    if (s[i] === 'c') countC += 1;
  }

  if ((countC === countA || countC === countB) /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {
    if (s[s.length - 1] !== 'c') {
      print('NO');
    } else {
      print('YES');
    }
  } else {
    print('NO');
  }
}

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');
// edge case

if (s.indexOf('a') === -1
    || s.indexOf('b') === -1
    || s.indexOf('c') === -1
    || s.indexOf('a') > s.indexOf('b')
    || s.indexOf('b') > s.indexOf('c')
    || s.indexOf('a') > s.indexOf('c')
  ) {
  print('NO')
} else {

  var countA = null, countB = null, countC = null;

  for (var i = 0; i < s.length; i++) {
    if (s[i] === 'a') countA += 1;
    if (s[i] === 'b') countB += 1;
    if (s[i] === 'c') countC += 1;
  }

  if (countC === countA || countC === countB /*&& s[s.length - 1] === 'c' */&& s[s.indexOf('c') - 1] === 'b') {
    if (s[s.length - 1] !== 'c') {
      print('NO');
    } else {
      print('YES');
    }
  } else {
    print('NO');
  }
}

// A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

// B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

// You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
// Input

// The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
// Output

// Print "YES" or "NO", according to the condition.

var s = readline().split('');

// edge case

if (s.indexOf('a') === -1
    || s.indexOf('b') === -1
    || s.indexOf('c') === -1
    || s.indexOf('a') > s.indexOf('b')
    || s.indexOf('b') > s.indexOf('c')
    || s.indexOf('a') > s.indexOf('c')
  ) {
  print('NO')
} else {

  var countA = null, countB = null, countC = null;

  for (var i = 0; i < s.length; i++) {
    if (s[i] === 'a') countA += 1;
    if (s[i] === 'b') countB += 1;
    if (s[i] === 'c') countC += 1;
  }

  if (countC === countA || countC === countB && s[s.length - 1] === 'c' && s[s.indexOf('c') - 1] === 'b') {
    print('YES');
  } else {
    print('NO');
  }
}

var inp = readline();

var spread = inp.split('').reduce(
    function(res, cur) {
        var lastItem = res[res.length - 1];

        if (lastItem && lastItem.char === cur) {
            lastItem.count++;
        } else {
            res.push({
                char: cur,
                count: 1,
            });
        }

        return res;
    },
    []
);

if (
    spread.map(function(item) {
        return item.char.toLowerCase();
    }).join('') !== 'abc'
) {
    print('NO');
} else {
    var aCount = spread[0].count;
    var bCount = spread[1].count;
    var cCount = spread[2].count;

    if (
        (!aCount || !bCount || !cCount) ||
        cCount !== aCount && cCount !== bCount
    ) {
        print('NO');
    }

    print('YES');
}

#!/usr/bin/env node

/**
 * Module dependencies.
 */

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

rl.on("line", function(line) {
    var a, b, c;
    a = b = c = 0;
    if (line.indexOf('a') < 0 ||
        line.indexOf('b') < 0 ||
        line.indexOf('c') < 0) {
        console.log("NO");
        rl.close();
    }
    var ap = line.indexOf('a');
    var bp = line.indexOf('b');
    var cp = line.indexOf('c');
    if (!(ap < bp && bp < cp)) {
        console.log("NO");
        rl.close();
    }
    for (var i = 0; i < line.length; i++) {
        switch (line.charAt(i)) {
            case 'a': a++; break;
            case 'b': b++; break;
            case 'c': c++; break;
        }
    }
    console.log((a === c || b === c) ? "YES" : "NO");
    rl.close();
}).on("close", function() {
    process.exit();
});


const mod = (k, n) => k >= 0 ? k % n : (n + (k%n))%n

const processData = (lines) => {
  const nums = +lines[0]
  for (let i =0; i<nums;i++) {
    const n = +lines[i*2 + 1]
    const arr = lines[i*2 + 2].split(' ').map(x => +x)

    const producedArr = arr.map(
      x => mod(x, n)
    )
    const res = {}
    for (let j=0; j<arr.length; j++) {
      const t = mod(j + producedArr[j], n)
      res[t] = 1
    }
    console.log(Object.keys(res).length === n ? 'YES' : 'NO')
  }
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
   6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        let n = parseInt(readline());
        let h = readline().split(" ").map(Number);

        for(let i=0;i<n;i++) {
            h[i] = (i + n + (h[i] % n)) % n;
        }

        let nonD = [...new Set(h)]

        if(nonD.length !== n) {
            console.log('No');
        } else {
            console.log('Yes');
        }

    }
}

const processData = (lines) => {
  const nums = +lines[0]
  for (let i =0; i<nums;i++) {
    const n = +lines[i*2 + 1]
    const arr = lines[i*2 + 2].split(' ').map(x => +x)

    const producedArr = arr.map(
      x => {
        if (x >= 0) return x % arr.length
        return (arr.length * Math.ceil(Math.abs(x) / arr.length) - x) % arr.length
      }
    )
    const res = []
    for (let j=0; j<arr.length*2; j++) {
      res[j] = j + producedArr[j % arr.length]
    }
    console.log(Array.from(new Set(res)).length === res.length ? 'YES' : 'NO')
  }
}

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

const processData = (lines) => {
  const nums = +lines[0]
  for (let i =0; i<nums;i++) {
    const n = +lines[i*2 + 1]
    const arr = lines[i*2 + 2].split(' ').map(x => +x)

    const producedArr = arr.map(
      x => {
        if (x >= 0) return x % arr.length
        return (arr.length * Math.ceil(Math.abs(x) / arr.length) - x) % arr.length
      }
    )
    const res = []
    for (let j=0; j<arr.length*3; j++) {
      res[j] = j + producedArr[j % arr.length]
    }
    console.log(Array.from(new Set(res)).length === res.length ? 'YES' : 'NO')
  }
}

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

const processData = (lines) => {
  const nums = +lines[0]
  for (let i =0; i<nums;i++) {
    const n = +lines[i*2 + 1]
    const arr = lines[i*2 + 2].split(' ').map(x => +x)

    const producedArr = arr.map(
      x => x % arr.length
    )
    const res = {}
    for (let j=0; j<arr.length; j++) {
      const t = j + producedArr[j]
      res[t % n] = 1
    }
    console.log(Object.keys(res).length === n ? 'YES' : 'NO')
  }
}

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


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

let input = [];
let ans = [];

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    for (let i = 2; i < input.length; i+=2) {
        let nums = input[i].split(' ').map(Number);

        let chkOdd = nums[0]%2;
        let chkEven = nums[1]%2;

        for (let j = 0; j < nums.length; j++) {
            if (j%2===0 && nums[j]%2!==chkOdd || j%2===1 && nums[j]%2!==chkEven) {
                ans.push('NO');
                break;
            }
            if (j === nums.length-1) ans.push('YES');
        }
    }

    console.log(ans.join('\n'));
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j += 2){
                if(k[j] % 2 != k[0] % 2){
                    ok = false;
                    break;
                }
            }
            for(j = 1; j < e; j += 2){
                if(k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            if(ok){
                console.log('YES');
            }else{
                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);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j += 2){
                if(k[j] % 2 != k[0] % 2){
                    ok = false;
                    break;
                }
            }
            for(j = 1; j < e; j += 2){
                if(k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            if(ok){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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 t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var c = 0;
		for(var i = 0; i < N; i += 2){
			if(list[i] % 2 == 0){
				c |= 1;
			}else{
				c |= 2;
			}
		}
		if(c == 3){
			myout("NO");
			continue;
		}
		var c = 0;
		for(var i = 1; i < N; i += 2){
			if(list[i] % 2 == 0){
				c |= 1;
			}else{
				c |= 2;
			}
		}
		if(c == 3){
			myout("NO");
			continue;
		}
		myout("YES");
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readline();
    while(t--) {
        const [n, arr] = [Number(readline()), readline().split(" ")];

        const typeOfevenIndex = arr[0] % 2, typeOfOddIndex = arr[1] % 2;

        let ans = "YES";

        loop:
        for(let i = 0; i < n; i++) {
            if(i % 2 === 0 && arr[i] % 2 !== typeOfevenIndex) {
                ans = "NO";
                break loop;
            }
            if(i % 2 === 1 && arr[i] % 2 !== typeOfOddIndex) {
                ans = "NO";
                break loop;
            }
        }
        console.log(ans);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = readline().split(' ').map(Number);

        let odd = arr.filter((v, i) => i % 2 === 0);
        let even = arr.filter((v, i) => i % 2 === 1);

        let no =false;
        for (let i = 0; i < odd.length; i++) {
            if (odd[i] % 2 !== odd[0] % 2) {
                no = true;
                break;
            }
        }

        for (let i = 0; i < even.length; i++) {
            if (even[i] % 2 !== even[0] % 2) {
                no = true;
                break;
            }
        }

        output(no ? 'NO' : 'YES');
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
        const n = readline()
        const A = readline().split(' ').map(x => +x)
        solve(A)
    }
}
function solve(A) {

    for (let i = 0; i < 2; i++) {
        let remain = A[i] % 2
        for (let j = i; j < A.length; j += 2) {
            if (A[j] % 2 !== remain) {
                console.log('NO')
                return
            }
        }
    }

    console.log('YES')
}

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

let lines = [];

async function main() {
  for await (let line of rl) {
	  lines.push(line);
  }

	let inputs = +lines[0]; // dirty javascript typecasting to number
  let arrays = [];

  for (let i = 0; i < inputs; i++) {
    let numOfElements = +lines[2 * i + 1];
    arrays.push([]);

    for (let j = 0; j < numOfElements; j++) {
      arrays[i].push(lines[2 * i + 2].split(" ")[j]);
    }
  }

  for (array of arrays) {
    let evenParity = array[0] % 2;
    let oddParity = array[1] % 2;

    let evenParitySuccess = true;
    let oddParitySuccess = true;

    for (let i = 0; i < array.length; i += 2) {
      evenParitySuccess = evenParitySuccess && array[i] % 2 == evenParity;
    }

    for (let i = 1; i < array.length; i += 2) {
      oddParitySuccess = oddParitySuccess && array[i] % 2 == oddParity;
    }

    if (evenParitySuccess && oddParitySuccess) console.log("YES");
    else console.log("NO");
  }
}

main();

const processData = (lines) => {
    let count = +lines[0]
    let cur = 0
    while(count--) {
        cur++
        // let [n] = lines[cur].split(' ').map(x => +x)
        cur++
        let nums = lines[cur].split(' ').map(x => +x)

        let patternBreak = false;
        for (const t of [0, 1]) {
            let pattern = nums[t] ? nums[t] %2 : 0;
            if (!patternBreak) {
                for (let i=t; i<nums.length; i+=2) {

                    if (nums[i]%2 !== pattern) {
                        patternBreak = true;
                        break;
                    }
                }
            }
        }

        console.log(patternBreak ? 'NO' : 'YES');
    }
}

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

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, a) {
  for (let i = 0; i < n; i++) {
    if (i > 1) {
      if ((a[i] & 1) !== (a[i - 2] & 1)) {
        console.log('NO');
        return;
      }
    }
  }
  console.log('YES');
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    solve(n, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		let ok = 1;
		for (let i = 0; i < n; i++) {
			if (i - 2 >= 0 && (a[i] & 1) != (a[i - 2] & 1)) ok = 0;
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, a)=>{
    let parity0 = a[0] % 2;
    let parity1 = a[1] % 2;
    for (let i = 0; i < n; i++) {
        if (i % 2 === 0 && a[i] % 2 !== parity0) return 'NO';
        if (i % 2 === 1 && a[i] % 2 !== parity1) return 'NO';
    }

    return "YES";
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const odd = arr[1] & 1
    const even = arr[0] & 1
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i] & 1
        if (i & 1) {
            if (x !== odd) return false
        } else {
            if (x !== even) return false
        }
    }
    return true
}

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, A)=>{
  let p1 = A[0]&1;
  for (let i=0; i<n; i+=2){
    if (p1!= (A[i]&1))
      return false;
  }
  let p2 = A[1]&1
  for (let i=1; i<n; i+=2){
    if (p2!= (A[i]&1))
      return false;
  }
  return true
};

function main() {
    let T = +readline()
    while (T--){
      let [n, m] = ra();
      let A = ra();
      L('Ans:')
      print(calc(n, A) ? 'yes' : 'no');
    }
}

E.calc = calc;

var t = +readline()

for(var i = 0; i< t; i ++) {
    var a = readline()
    var arr1 = readline().split(" ").map(x => +x);
    print(oddAndEven(arr1));
}

function oddAndEven(n){

   var evenIdx = n[0] % 2 === 0;
   var oddIdx = n[1] % 2 === 0;
   for(var i = 0; i<n.length;i++){
      if (i % 2 === 0 && ((n[i] % 2 === 0) != evenIdx)){
         return 'No';
      }
      else if (i % 2 === 1 && ((n[i] % 2 === 0) != oddIdx)){
         return 'No';
      }
   }

   return 'YES';

}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j += 2){
                if(k[j] % 2 != k[0] % 2){
                    ok = false;
                    break;
                }
            }
            for(j = 1; j < e; j += 2){
                if(k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(ok ? 'YES' : 'NO');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j++){
                if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(ok ? 'YES' : 'NO');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split('').map(Number);
            var ok = true;
            for(j = 0; j < e; j++){
                if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(ok ? 'YES' : 'NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){
                if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            if(ok){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j++){
                if(k[j] % 2 != k[0] % 2 || k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(!ok ? 'YES' : 'NO');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j ++){
                if(k[j] % 2 != k[0] % 2){
                    ok = false;
                    break;
                }
            }
            for(j = 1; j < e; j += 2){
                if(k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(ok ? 'YES' : 'NO');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0; j < e; j += 2){
                if(k[j] % 2 != k[0] % 2){
                    ok = false;
                    break;
                }
            }
            for(j = 1; j < e; j ++){
                if(k[j] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            console.log(ok ? 'YES' : 'NO');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = Number(lines[i]);
        }else{
            var ar = lines[i].split(' ').map(Number);
            var a = 0, b = n - 1;
            var a1 = ar[0], b1 = ar[b];
            var ans = 0;
            while(a < b){
                if(a1 == b1){
                    ans = a + 1 + n - b;
                    a++;
                    a1 += ar[a];
                }else if(a1 > b1){
                    b--;
                    b1 += ar[b];
                }else if(a1 < b1){
                    a++;
                    a1 += ar[a];
                }
            }
            console.log(ans);
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0].split('').sort();
    var e = n[n.length - 1];
    var ans = '';
    for(i = 0; i < n.length; i++){
        if(n[i] == e){
            ans += n[i];
        }
    }
    console.log(ans);
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i], a = new Map(), flag = false;
        }else{
            k = lines[i].split(' ').map(Number);
            for(j = 0; j < n; j++){
                if(a.has(k[j])){
                    flag = true;
                    break;
                }else{
                    a.set(k[j]);
                }
            }
            console.log(flag === true ? 'NO' : 'YES');
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var a = lines[i].split('').map(Number);
        var x = 0;
        var y = 0;
        for(j = 0; j < 6; j++){
            if(j >= 3){
                x += a[j];
            }else{
                y += a[j];
            }
        }
        console.log(x == y ? 'YES' : 'NO');
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){
                if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            if(ok === true){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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 t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var c = 0;
		for(var i = 0; i < N; i += 2){
			if(list[i] % 2 == 0 && c == 0){
				c++;
			}else if(list[i] % 2 == 1 && c == 1){
				c++;
			}
		}
		if(c == 2){
			myout("NO");
			continue;
		}
		var c = 0;
		for(var i = 1; i < N; i += 2){
			if(list[i] % 2 == 0 && c == 0){
				c++;
			}else if(list[i] % 2 == 1 && c == 1){
				c++;
			}
		}
		if(c == 2){
			myout("NO");
			continue;
		}
		myout("YES");
	}
}


var n = parseInt(readline());
var out = 'O' + Array(n).join('o');

String.prototype.replaceAt = function(index, replacement) {
  return this.substr(0, index) + replacement + this.substr(index + replacement.length);
}

var fibo = [0, 1, 1];
function f() {
  var i = fibo.length;
  fibo.push(fibo[i-1] + fibo[i-2]);
  if (fibo[i] <= n) {
    out = out.replaceAt(fibo[i]-1, 'O');
    f();
  }
}
f();

print(out);

const n = parseInt(readline());
var out = 'O' + Array(n).join('o');

String.prototype.replaceAt = function(index, replacement) {
  return this.substr(0, index) + replacement + this.substr(index + replacement.length);
}

var fibo = [0, 1, 1];
function f() {
  const i = fibo.length;
  fibo.push(fibo[i-1] + fibo[i-2]);
  if (fibo[i] <= n) {
    out = out.replaceAt(fibo[i]-1, 'O');
    f();
  }
}
f();

print(out);

n = readline();

var i = 1, arr = [1, 1], resArr = [];

while (arr[i] < n) {
	arr.push(arr[i - 1] + arr[i]);

	i++;
};

for (var j = 1; j <= n; j++) {
	var count = 0;

	for (var k = 0; k < arr.length; k++) {
		if (j == arr[k]) {
			count++;
		};
	};

	if (count > 0) {
		resArr.push('O');
	} else {
		resArr.push('o');
	};
};

print(resArr.join(''));

//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 = [0,1];
  var set = new Set(list);
  while(list[list.length - 1] < 1000){
    var add = list[list.length - 2] + list[list.length - 1];
    list.push(add);
    set.add(add);
  }
  var output = "";
  for(var i = 0; i < N; i++){
    if(set.has(i + 1)){
      output += "O";
    }else{
      output += "o";
    }
  }
  myout(output);
}

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

rl.on('line', (d) => {
  const seq = [1, 1];

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

  let ans = '';

  for (let i = 1; i <= d; i++) {
    if (seq.includes(i)) {
      ans += 'O';
    }
    else {
      ans += 'o';
    }
  }

  console.log(ans);

  c++;
});

function a(n) {
  return n % Math.sqrt(n) === 0;
}

function b(n) {
  return a(5 * n * n + 4) || a(5 * n * n - 4);
}

function main() {
  var n = readline();
  var x = '';

  for (var i = 1; i <= n; i++) {
    x = x + (b(i) ? 'O' : 'o');
  }

  print(x);
}

main();

n = +readline()
fib = []
fib.push(1)
fib.push(1)
for (i = 2; i < 20; i++)
  fib[i] = fib[i - 1] + fib[i - 2]
ans = ''
for (i = 1; i <= n; i++)
  ans += (fib.includes(i) ? 'O' : 'o')
print(ans)

var t = readline();
el(t);
function el(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    write(f.includes(i) ? 'O' : i > 0 ? 'o' : '');
  }
  return print();
}

var t = readline();
print(el(t));

function el(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  var s = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    if(f.includes(i)){
        s.push('O');
       }else if(i > 0){
         s.push('o');
       }
  }
  s = s.join('');
  return s;
}

'use strict';

let n = parseInt(readline(), 10);
const isFibo = new Array(n + 1);
const fibo = [0, 1];
for (let i = 2; fibo[fibo.length - 1] <= n; i++) {
  fibo.push(fibo[i - 2] + fibo[i - 1]);
}

fibo.pop();

for (const i of fibo) {
  isFibo[i] = true;
}

for (let i = 1; i <= n; i++)
  write(isFibo[i] ? 'O' : 'o');
print()

var el = function(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  var s = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    if(f.includes(i)){
        s.push('O');
       }else if(i > 0){
         s.push('o');
       }
  }
  s = s.join('');
  return s;
};
el(8);

function el(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  var s = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    if(f.includes(i)){
        s.push('O');
       }else if(i > 0){
         s.push('o');
       }
  }
  s = s.join('');
  return s;
};
el(8);

'use strict';

let n = parseInt(readline(), 10);
const isFibo = new Array(n + 1);
const fibo = [0, 1];
for (let i = 2; fibo[fibo.length - 1] <= n; i++) {
  fibo.push(fibo[i - 2] + fibo[i - 1]);
}

fibo.pop();

for (const i of fibo) {
  isFibo[i] = true;
}

for (let i = 1; i <= n; i++)
  write(isFibo[i] ? '0' : 'o');
print()

var el = function(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  var s = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    if(f.includes(i)){
        s.push('O');
       }else if(i > 0){
         s.push('o');
       }
  }
  return s.join('');
};

function el(n){
  var a = 0;
  var b = 1;
  var c;
  var f = [];
  var s = [];
  for(var i = 0;i <= n;i++){
    c = a + b;
    a = b;
    b = c;
    f.push(a);
    if(f.includes(i)){
        s.push('O');
       }else if(i > 0){
         s.push('o');
       }
  }
  s = s.join('');
  return s;
}
print(el(8));


function main() {
    var n = parseInt(readline());
    var bs = readline().split(' ').map(x => parseInt(x));
    var as = Array(n).fill(0);
    as[0] = bs[0];
    var mx = bs[0];
    print(as[0])
    for(var i = 1; i < n; i++){
        as[i] = bs[i] + mx;
        mx = Math.max(mx, as[i]);
        print(as[i])
    }
}
main();

var times = parseInt(readline());
var b = readline().split(" ").map(function(x) { return parseInt(x); });

var a =[];
var mx = 0;
for(var i = 0; i < times; i++)
{
    a.push(mx + b[i]);
    write(a[i] + " ");
    mx = Math.max(mx, a[i]);
}

var n = parseInt(readline());
var b = readline().split(" ").map(function(x) {
  return parseInt(x);
});
var a = []
var mx = 0;
for (var i = 0; i < n; i++) {
  a.push(b[i] + mx);
  print(a[i])
  mx = Math.max(mx, a[i]);
}

//var input = readline();
var T = parseInt(readline());

var s = 0, b = [];
var ar = readline().split(' ').map(x => parseInt(x));
for (var i = 0; i < T; i++) {
    b[i] = ar[i] + s;
    s = Math.max(s, b[i]);
    print(b[i]);
}

var t = Number(readline());
var inp = readline().split(' ').map(cur => Number(cur));

var out = []
var max = 0;
inp.forEach((cur, i) => {
    if(cur < 0)
        out.push(max+cur)
    else{
        max += cur;
    out.push(max);
    }

});
print(out.join(' '));

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

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

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

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

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  const n = readInt()
  const b = readInts()
  let m = 0
  const a = new Array(n)
  a[0] = b[0]
  m = a[0]
  for(let i = 1;i < n; i++) {
    m = Math.max(m, a[i - 1])
    // wr(a, m)
    a[i] = b[i] + m
  }
  wr(a.join(' '))
}

// Alternative
// https://www.npmjs.com/package/competitive-programming-js
"use strict"

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
});
function input() { return inputString[currentLine++]; }
const println = (x = "") => process.stdout.write(String(x) + "\n");
const print = x => { process.stdout.write(String(x)); }
// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<

function main() {
    let n = parseInt(input());
    let x = input().split(' ').map(v => parseInt(v));
    // let b = [], a = [];
    let b = new Array(n);
    let a = new Array(n);
    // b.push(0);
    // a.push(x[0]);
    b[0] = 0;
    a[0] = x[0];
    let mx = x[0];
    for (let i = 1; i < n; ++i) {
        // b.push(mx);
        b[i] = mx;
        a[i] = (b[i] + x[i]);
        mx = Math.max(a[i], mx);
    }
    a.forEach(v => print(v + ' '));
    println();
}

// Alternative
// https://www.npmjs.com/package/competitive-programming-js
"use strict"

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
});
function input() { return inputString[currentLine++]; }
const println = (x = "") => process.stdout.write(String(x) + "\n");
const print = x => { process.stdout.write(String(x)); }
// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<

function main() {
    let n = parseInt(input());
    let x = input().split(' ').map(v => parseInt(v));
    let b = [], a = [];
    b.push(0);
    a.push(x[0]);
    let mx = x[0];
    for (let i = 1; i < n; ++i) {
        b.push(mx);
        a.push(b[i] + x[i]);
        mx = Math.max(a[i], mx);
    }
    a.forEach(v => print(v + ' '));
    println();
}

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;
  }

  const arr = d.split(' ').map(Number);
  let curr = Math.max(0, arr[0]);
  const ans = [curr];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] <= 0) {
      ans.push(Math.max(0, curr + arr[i]));
    }
    else {
      curr += arr[i];
      ans.push(curr);
    }
  }

  console.log(ans.join(' '));

  c++;
});

process.stdin.resume();
process.stdin.setEncoding('utf-8')
let inputString = '';
let currentLine = 0;
process.stdin.on('data', input => { inputString += input; })
process.stdin.on('end', _ => { inputString = inputString.split('\n'); main(); })
const readline = () => { return inputString[currentLine++] }

function main() {
    let n = parseInt(readline());
    let bs = readline().split(' ').map(x => parseInt(x));
    let as = Array(n).fill(0);
    as[0] = bs[0];
    let mx = bs[0];
    for(let i = 1; i < n; i++){
        as[i] = bs[i] + mx;
        mx = Math.max(mx, as[i]);
    }
    console.log(as.join(' '));
}

const processData = (lines) => {
  const nums = lines[1].split(' ').map(x => +x)
  const res = []
  let curMax = 0
  for (let i=0; i<nums.length; i++) {
    res.push(nums[i] + curMax)
    curMax = Math.max(curMax, nums[i] + curMax)
  }
  console.log(res.join(' '))
}

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

var t = Number(readline());
var inp = readline().split(' ').map(cur => Number(cur));

var out = []
var max = 0;
inp.forEach((cur, i) => {
    if(i !== inp.length-1){
    if(cur >= 0)
    max += cur;
    }else max += cur;

    out.push(max);
});
print(out.join(' '));

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;
  }

  const arr = d.split(' ').map(Number);
  let curr = Math.max(0, arr[0]);
  const ans = [curr];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] <= 0) {
      ans.push(0);
    }
    else {
      curr += arr[i];
      ans.push(curr);
    }
  }

  console.log(ans.join(' '));

  c++;
});