One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Print a single integer — the number of problems the friends will implement on the contest.

NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

var n = parseInt(readline());
var output = 0;

for(var i = 0; i < n; i++)
{
	var sures = readline();
	if(sures.indexOf('1') != sures.lastIndexOf('1')) output++;
}

print(output);

var n = parseInt(readline());

var input = [];

for (var i = 1; i <= n; i++) {
    input.push(readline().split(' '));
}

var solvedCount = 0;
var sureCount = 0;

input.forEach(function(line) {
    sureCount = 0;

    line.forEach(function(value) {
        if (parseInt(value)) {
            sureCount++;
        }
    });

    if (sureCount >= 2) {
        solvedCount++;
    }

});

print(solvedCount);

const readline = require("readline");

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

function enterNumberOfTasks() {
  rl.question("", (num) => {
    const numberOfTasks = parseInt(num);
    enterLine(numberOfTasks);
  });
}

/**
 *
 * @param {number} numberOfTasks
 */
function enterLine(numberOfTasks) {
  const lines = [];
  rl.on("line", (line) => {
    lines.push(line);

    if (lines.length === numberOfTasks) {
      getAnswer(lines);
      rl.close();
      return;
    }
  });
}

/**
 *
 * @param {string[]} lines
 */
function getAnswer(lines) {
  let numberOfTasks = 0;
  lines.forEach((line) => {
    const numbers = line.split(" ").map((numStr) => parseInt(numStr));
    const sum = numbers.reduce((acc, cur) => acc + cur, 0);

    if (sum > 1) {
      numberOfTasks++;
    }
  });

  console.log(numberOfTasks);
}

enterNumberOfTasks();

var noOfProblems = +readline();

var noOfSolutions = 0;

for (var i = 0; i < noOfProblems; i++) {
    var opinions = readline().split(" ");
    if (+opinions[0] === 1 && +opinions[1] === 1) {
        noOfSolutions += 1;
    } else if (+opinions[0] === 1 && +opinions[2] === 1) {
        noOfSolutions += 1;
    } else if (+opinions[1] === 1 && +opinions[2] === 1) {
        noOfSolutions += 1;
    }
}
print(noOfSolutions);

const n = Number(readline());
var c ;
var q = 0;
for(var i = 0; i < n ; i++){
    c = readline().split(" ");
    var k = c.reduce((acc, cur) => {
       if(cur == 1)
       return (acc + 1);
       else
        return acc;
    },0);
    (k >= 2) ? q++ : null;
}
print(q);

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

let input = [];
rl.on('line', function(line) {
	input.push(line);
	if (input.length === input[0] * 1 + 1) {
		//n m a
		input.shift();
		team(input);
		rl.close();
	}
});

let team = (array) => {
	const reducer = (accumulator, currentValue) => 1 * accumulator + 1 * currentValue;
	let result = array
		.map((el) => {
			return el.split(' ').reduce(reducer);
		})
		.filter((el) => {
			return el >= 2;
		});
	console.log(result.length);
};

var problemas = readline();
var datos = new Array();
var contador = 0;
var linea = 0;

for (var x = 0; x < problemas; x++){
	linea = readline().split(' ').map(Number);
	if (linea[0]+linea[1]+linea[2] >= 2){
		contador++;
	}
}

print(contador);

var numberOfProblems = parseInt(readline());
var arrOfAnswers = [];
for(var i = 0; i < numberOfProblems; ++i) {
    arrOfAnswers[i] = readline().split(" ").map(function(val){
        return parseInt(val);
    });
}
var friendsNum = 3;
var sureOfSolutions = 0
var countOfWhoSure = 0;

for(i = 0; i < parseInt(numberOfProblems); ++i) {
    countOfWhoSure = 0;
    for(var j = 0; j < friendsNum; ++j) {
        if(arrOfAnswers[i][j] == 1) {
            ++countOfWhoSure;
            if(countOfWhoSure == 2) {
                ++sureOfSolutions;
                break;
            }

        }
    }
}

print(sureOfSolutions);

const main = () => {
  const N = Number(readline());

  var result = 0;

  for (var i = 0; i < N; i++) {
    var confidenceLevel = 0;

    readline()
      .split(" ")
      .forEach((opinion) => {
        if (opinion === "1") {
          confidenceLevel++;
        }
      });

    if (confidenceLevel >= 2) {
      result++;
    }
  }

  print(result);
};

main();

const n = Number(readline());
var c ;
var q = 0;
for(var i = 0; i < n ; i++){
    c = readline().split(" ");
    var k = c.reduce((acc, cur) => {
       if(cur == 1)
       return (acc + 1);
       else
        return acc;
    },0);
    (k >= 2) ? q++ : null;
}
print(q);
//

var numberOfProblems = readline();
var result = 0;

for(var i = 0; i < numberOfProblems; i++){
    var decisions = readline().split(' ');
    var numberOfCanSolve = 0;

    for(var j = 0; j < decisions.length; j++){
        if(parseInt(decisions[j]) === 1){
            numberOfCanSolve++;
        }

    }
    if(numberOfCanSolve > 1){
            result++;
        }

}

print(result);

'use strict';

const count = readline();
let answer = 0;

for (let i=0; i<count; i++){
    const regex = /\s+/;
    const input = readline();
    const splitted = input.split(regex);

    let sureCnt = 0;

    for(let i=0; i<splitted.length; i++){
        if (splitted[i] == 1){
            sureCnt += 1;
        }
    }

    if(sureCnt >= 2){
        answer += 1;
    }
}

print(answer);

'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();
});

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let ty = parseInt(readLine())
	let solCount=0
	while(ty--){
		let [petya,vasya,tonya] = readLine().split(" ").map(n=>+n)
		if(petya && vasya || vasya && tonya || petya && tonya)
			solCount++
	}
	console.log(solCount)
}

var count = readline();

var ans = 0;
for(var i = 0; i< count; i++){
    var nums = readline();
    nums = nums.split(' ');
    var sum = 0;
    nums.map(a => {
        a = parseInt(a,10);
        if(a>0){
            sum++;
        }
    });
    if(sum>1){
        ans++;
    }
    sum=0;
}

print(ans);

readline()
var values;
var count = 0;
while(values = readline()){
    if(values.replace(/[ 0]/g, "").length > 1) count++
}

print(count)

var x = parseInt(readline());

var total = 0;
for (var i=0 ; i<x;i++){
    var sum = 0;
    var a = readline().split('');

    a.forEach(function(i){
        var r = parseInt(i);
        if(r==1){sum+=1;}})
    if(sum ==2 || sum==3){total++}
}
print(total);

var problems = parseInt(readline());
var unsolved = 0;
while(problems--){
    var problem = readline().split(" ");
    var solution = 0;
    for(var i = 0; i < problem.length; i++){
        if(problem[i] == "1"){
            solution++;
        }
    }

   if(solution >= 2){
    unsolved++;
   }
}
print(unsolved);

//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");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return 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 output = 0;
  for(var i = 0; i < N; i++){
    var list = nextIntArray();
    var count = 0;
    for(var j = 0; j < list.length; j++){
      count += list[j];
    }
    if(count >= 2){
      output++;
    }
  }
  myout(output);
}

'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 solve=(A)=>{
        let n=A.length,result=0
        for(let i=0;i<n;i++){
            let total=A[i].reduce((a,c)=>a+Number(c),0)
            if(total>=2){
                result++
            }
        }
        return result
    }

    let n=readline()
    let A=[]
    for (let i = 0; i < n; i++) {
        A.push(readline().split(" ").map(d=>Number(d)))
    }

    let result=solve(A)
    console.log(result.toString())

}

var n = parseInt(readline()), output = 0, sures;

for(var i = 0; i < n; i++)
{
	sures = readline();
	if(sures.indexOf('1') != sures.lastIndexOf('1')) output++;
}

print(output);

;(function () {
    var n = readline(), r = 0;
    for (var i = 0; i < n; i++)
        r += readline().split(' ').filter(function(v){ return v == 1;}).length > 1;
    print(r);

}).call(this);

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

var idx = 0;
var out = 0;
rl.on("line", (theLine) => {
    if (idx === 0) {
        lines = parseInt(theLine);
    }
    else {
        var scores =  theLine.split(" ");
        var currentCount = 0;
        scores.forEach(element => {
            if (element === "1")
                currentCount++
        });
        if (currentCount>1)
            out++;
    }
    idx++;
    if (idx > lines)
    {
        rl.close();
          console.log(out.toString());
    }

})

var input = readline().split(' ');
var result=0;
for(var i = 0; i<parseInt(input);i++)
{
  var line =readline();
  if(line[0]==1 && (line[2] == 1 || line[4] ==1))
    result++;
  else if(line[2]==1 && line[4] ==1)
    result++;

}
print(result);

var a  =  readline();
var jami = 0;
for(i = 1; i <= a; i ++ ) {
	var cin = readline().split(" ").sort(function(a,b){return a-b});
	if(cin[1] == 1) {
		jami += 1;
	}

}

print(jami);

var counter=0;
var problems = readline();
var array2D=[];
for(var i=0;i<problems;i++){
    array2D.push(readline().split(" ").map(x => parseInt(x)));
}
for (var i = 0 ; i < problems ; i++)
{
    if ((array2D[i][0]==array2D[i][1] && array2D[i][0]==1) ||
        (array2D[i][0]==array2D[i][2] && array2D[i][0]==1) ||
        (array2D[i][1]==array2D[i][2] && array2D[i][1]==1)){
            counter++;
    }
}
print (counter)

var problems = readline();

function resolve(prb) {
    var problSolv=0;
    for (var i=0; i<prb; i++) {
        var persons = readline().split(" ");
        var total = parseInt(persons[0])+parseInt(persons[1])+parseInt(persons[2]);
        if (total>=2) {
            problSolv++;
        }
    }
    return problSolv;
}
print (resolve(parseInt(problems)));

function getSum(nums){
	var total = 0;
	for(var i = 0; i < nums.length; i++)
		total += Number(nums[i]);
	return total;
}

var n = Number(readline());

var ans = 0;
for(var i = 0; i < n; i++){
	var votes = readline().split(" ");
	var sumOfVotes = getSum(votes);
	if(sumOfVotes > 1) ans++;
}

print(ans);

var q = parseInt(readline());

var result = 0;
for (var i = 0; i < q; i++) {
    var known = readline().split(" ").map(x => parseInt(x));

    if (known[0] + known[1] + known[2] >= 2) {
        result++;
    }
}

print(result);

var count = parseInt(readline()),
current = [], currentMas, sum = 0, answer = 0;

for(var i = 0; i < count; i++) {
    current[i] = readline().split(" ");
}

for(var i = 0; i < count; i++) {
    currentMas = current[i];
    sum = 0;

    for(var j = 0; j < 3; j++) {
        sum+=parseInt(currentMas[j]);
    }

    if(sum >= 2) {
        answer+=1;
    }
}

write(answer);

var n = parseInt(readline());
var output = 0;

for(var i = 0; i < n; i++)
{
	var tmp = 0;
	var sures = readline().split(' ').map(function(c){
		if(c == 1) tmp++;
	});
	if(tmp >= 2) output++;
}

print(output);

if (process.argv[2] === "test") {
  lines = ["3", "1 0 0", "1 1 0", "0 1 1"];
  solve(lines);
} else {
  let i = "";
  process.stdin.on("data", (c) => (i += c));
  process.stdin.on("end", () => {
    const { EOL } = require("os");
    const lines = i.split(EOL);

    solve(lines);
  });
}

function solve(lines) {
  const problemCount = lines[0];
  let answerCount = 0;
  for (let x = 0; x < problemCount; ++x) {
    const answers = lines[x + 1].split(" ");
    const score = answers.filter((x) => x === "1").length;
    if (score >= 2) {
      ++answerCount;
    }
  }
  console.log(answerCount);
}

numOfLines = readline();
        num = parseInt(numOfLines);
        output = 0;
        outputInOneLine = 0;
        for (i = 0; i < num; i++) {
            line = readline();
            val = line.split(" ");
            val.map(el => {
                if (el == 1) {
                    outputInOneLine++;
                }
            })
            if (outputInOneLine > 1) {
                output++;
            }
            outputInOneLine = 0;
        }
        print(output);

// Generated by CoffeeScript 2.5.1
var lines, mainAux, nprobs, print, readline, rl, rli, sum, write;

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

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

sum = function(items) {
  return items.reduce((function(a, b) {
    return a + b;
  }), 0);
};

nprobs = function(n, ps) {
  return ps.filter(function(p) {
    return sum(p) > 1;
  }).length;
};

mainAux = function() {
  var count, i, items, j, ref;
  count = parseInt(readline());
  items = [];
  for (i = j = 0, ref = count; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
    items.push(readline().split(' ').map(function(i) {
      return parseInt(i);
    }));
  }
  return print(nprobs(count, items));
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=testsums.js.map

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

function processData(data) {
     const input =  data.trim().split('\n').map(string => {
        return string.trim();
    });

        let res = 0

for (let i=1;i<=parseInt(input[0]);i++) {
    if ((input[i].split("1").length-1) > 1) {
        res++;
      }
  }
       console.log(res);

}

var n = readline();
var count = 0
for(var i = 0; i<n; i++){
    if (readline().split(' ').map(x => parseInt(x)).reduce((a,b) => a + b) >=2){
        count += 1
    }
}
print(count)

var r = readline()

var count = 0

for(var i = 0; i < r; i++) {

    count += readline().split(" ").map((x) => Number(x)).reduce((a,b) => a+b) >= 2 ? 1 : 0;

}

print(count)

var readline = require ("readline");
rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var expect = 'n';
var s= 0;
rl.on("line", function(line){
    if (expect =="n"){
        n = parseInt(line);
        case_counter = 1;
        expect = 'solution';
    } else if (expect=="solution"){
        solutions = line.split(" ");
        var r = 0;

        for(var i = 0; i<3; i++){

            if(solutions[i] == '1'){
                r++;
            }
        }
        if (r > 1){
            s++;
        }
        ++case_counter === n +1 ? rl.close() : 0;
        expect="solution";
    }
}).on('close', function(){
    console.log(s);
    process.exit(0);

});

let fs = require('fs')

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter((data) => {
    return data.length > 0;
});
// txt.shift()

for (let index = 0; index < txt.length; index++) {
    if (!isNaN(txt[index]*1)) {
        let tab = []
        for (let i = 1; i <= txt[index]; i++) {
            tab.push(txt[index + i].split(" ").filter(data=>{return data.length>0}));
        }
        square(tab)
    }

}

function square(tab) {
    let score = 0;
    tab.forEach(element => {
        if (element.filter(data => {
                return data == 1
            }).length >= 2) {
            ++score;
        }
    });
    console.log(score);
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  let result = 0;
  while (t--) {
    let count = 0;
    const [a, b, c] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    a === 1 && count++;
    b === 1 && count++;
    c === 1 && count++;
    count >= 2 && result++;
  }
  console.log(result);
}

var quantity = parseInt(readline()),
    arr = [],
    count = 0;

for (var i = 0; i < quantity; i++) {
    var s = 0;
    arr[i] = readline().split(' ').map(x => parseInt(x) && s++);
    s > 1 && count++;
}

print(count);

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(arr) {
    let nLines = arr.split('\n');
    let problems = +nLines[0].trim();
    let problemSolArr = nLines;
    let solution = 0;
    for (let solProb of problemSolArr.slice(1)) {

        let bits = solProb.trim().split(' ');

        let sum = bits.reduce(function (acc, value) {
            return acc + parseInt(value);
        }, 0);
        if (sum > 1) {
            solution++;
        }
    }

    return solution.toString();

}

"use strict";
let input = [];
const readline=require('readline');
const RL=readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
RL.on('line', (line)=>{
  input.push(line.trim());
});
RL.on('close', ()=>{
  const n=parseInt(input[0]);
  let answer=0;
  for(let i=1; i<=n; ++i){
    let cnt=0;
    const arr=input[i].split(' ');
    arr.map((ch)=>{
      let digit=parseInt(ch);
      if(digit===1){
        cnt++;
      }
    });
    if(cnt>=2){
      answer++;
    }
  }

  console.log(answer);
});

var input;
var count ;
var problem = 0;
var n = parseInt(readline());

for(var i=0 ; i<n ; i++){
   input = readline();
   count = 0;
   for(var j=0 ; j<5 ; j++){
       if(input.charAt(j)=='1'){
           count++;
       }
   }
   if(count>1)
        problem++;
}
print(problem);

var lines = Number(readline());
var outp = 0;
for (var i = 0; i < lines; i++) {
    var str = readline();
    var count = Number(str.charAt(0)) + Number(str.charAt(2)) + Number(str.charAt(4));
    if (count > 1) outp ++;
}
print(outp);

var input;
var count ;
var problem = 0;
var n = parseInt(readline());

for(var i=0 ; i<n ; i++){
   input = readline().split(' ').map(x=>parseInt(x));
   count = 0;
   for(var j=0 ; j<5 ; j++){
       if(input[j]=='1'){
           count++;
       }
   }
   if(count>1)
        problem++;
}
print(problem);

'use strict'
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var inp, nb, sum = 0, tt = 0, count = 0, sum = 0;
rl.question('', (nb) => {
  rl.on('line', (inp) => {
    sum = Number(inp[0]) + Number(inp[2]) + Number(inp[4]);
    if (sum >= 2){
      tt++;
    }
    count++;
    if (count == nb) {
      console.log(tt);
      rl.close();
    }
  });
});

var problems = parseInt(readline());
var unsolved = 0;
while(problems--){
    var problem = readline().split(" ");
    var solution = 0;
    for(var i = 0; i < problem.length; i++){
        if(problem[i] == "1"){
            solution++;
        }
    }

   if(solution >= 2){
    unsolved++;
   }
}
print(unsolved);

var n = Number(readline());
var count = 0;
for (var i = 0; i < n; i++) {
	if (readline().split(" ").map(x => Number(x)).reduce((a, b) => a + b) > 1) count++;
}
print(count);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  var T = readLine();
  var count = 0;
  while (T--) {
    var str = readLine();
    var strSingle = str.split(" ");
    for (let i = 0; i <= T; i++) {
      if (
        (strSingle[0] == 1 && strSingle[1] == 1) ||
        (strSingle[0] == 1 && strSingle[2] == 1) ||
        (strSingle[1] == 1 && strSingle[2] == 1)
      ) {
        count++;
        break;
      }
    }
  }
  if (count) {
    console.log(count);
  } else {
    console.log(0);
  }
}

readline();
var ans = 0;
for (var s; s = readline(); ) {
    var count = s.split( ' ' ).reduce( function(last, it) {
        return (it - '') + last;
    }, 0 );
    count > 1 && ans++;
}

print( ans );

'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 problems= readline();
    let count =0;
    for (let i=0;i<problems;i++){
        let [A,B,C]= readline().split(" ");
        if(parseInt(A) + parseInt(B) + parseInt(C) >= 2){
            count++
        }
    }
    console.log(count);

    return ;
}

const readline = require('readline');

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

let data = [];
rl.on('line', (input) => {
   data.push(input);
});

rl.on('close', () => {
   solve(data);
});

function solve(data) {

   const reducer = (acc, curr) => {
      if (curr == "1") {
         return acc + 1;
      } else {
         return acc;
      };
   }

   total = 0;
   for (let i = 1; i < data.length; i++) {
      n = data[i].split(" ").reduce(reducer, 0);
      if (n >= 2) total++;
   }
   console.log(total);

}

var n = readline();
var ans = 0;
for (i = 0; i < n; ++i) {
  l = readline().split(' ').map(function(x) {
    return parseInt(x);
  });
  ans += (l[0] + l[1] + l[2] >= 2);
}
print(ans);

const n = Number(readline());
var c ;
var q = 0;
for(var i = 0; i < n ; i++){
    c = readline().split(" ");
    var k = c.reduce((acc, cur) => {
       if(cur == 1)
       return (acc + 1);
       else
        return acc;
    },0);
    (k >= 2) ? q++ : null;
}
print(q);
//

function getSum(nums){
	var total = 0;
	for(var i = 0; i < nums.length; i++)
		total += parseInt(nums[i]);
	return total;
}

var n = readline().split(" ");

var ans = 0;
for(var i = 0; i < n; i++){
	var votes = readline().split(" ");
	var sumOfVotes = getSum(votes);
	if(sumOfVotes > 1) ans++;
}

print(ans);

n = readline();
var tedad = 0;
while(n--)
{
 	s=readline().replace(new RegExp('0' , 'g'), '')

	if(s.length > 3){tedad++}

}
print(tedad)

var n = parseInt(readline());
var output = 0;

for(var i = 0; i < n; i++)
{
	var tmp = 0;
	var sures = readline().split(' ').map(function(c){
		if(c == 1) tmp += 1;
	});
	if(tmp >= 2) output += 1;
}

print(output);

var n = parseInt(readline());

var input = [];

for (var i = 1; i <= n; i++) {
    input.push(readline().split(' '));
}

var solvedCount = 0;
var sureCount = 0;

input.forEach(function(line) {
    sureCount = 0;

    line.forEach(function(value) {
        if (parseInt(value)) {
            sureCount++;
        }
    });

    if (sureCount >= 2) {
        solvedCount++;
    }

});

print(solvedCount);

'use strict';

const count = readline();
let answer = 0;

for (let i=0; i<count; i++){
    const regex = /\s+/;
    const input = readline();
    const splitted = input.split(regex);

    let sureCnt = 0;

    for(let i=0; i<splitted.length; i++){
        if (splitted[i] == 1){
            sureCnt += 1;
        }
    }

    if(sureCnt >= 2){
        answer += 1;
    }
}

print(answer);

numOfLines = readline();
        num = parseInt(numOfLines);
        output = 0;
        outputInOneLine = 0;
        for (i = 0; i < num; i++) {
            line = readline();
            val = line.split(" ");
            val.map(el => {
                if (el == 1) {
                    outputInOneLine++;
                }
            })
            if (outputInOneLine > 1) {
                output++;
            }
            outputInOneLine = 0;
        }
        print(output);

var numberOfSolutions = 0,
    count = +readline();
while(count--){
    var views = readline().split(" ");
    var sum = 0;
    for(var i = 0; i<3; i++){
        sum += +views[i];
    }
    if(sum >=2){
        numberOfSolutions++;
    }
}
print(numberOfSolutions);

//Team

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let c = 0;
    for(let i = 1; i <= +lines[0]; i++)  {
    	c += Math.floor(lines[i].split(' ').reduce((a, b) => (+a) + (+b)) / 2);
    }

    process.stdout.write(c + "");

    return;
});

var answer = readline();
var result = 0;
for(var i = 0; i < answer; i++){
    var input = readline().split('');
    var sum = 0;
    for(var x = 0; x < input.length; x++){
        if(input[x] == 1){
            sum ++;
        }
    }
    if(sum > 1){
        result ++;
    }
}
print(result);

//231A
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let i = 0
let problems;
let numberOfProblems = 0;
rl.on('line', (input) => {
i++
    if(i==1) {
        problems = parseInt(input)
    } else if (i - 1 <= problems) {

        let thingyarray = input.split(" ")
        let formatarray = [];
        thingyarray.forEach(function(number) {
            let dieh = parseInt(number)
            formatarray.push(dieh)
        })

        let answer = formatarray[0] + formatarray[1] + formatarray[2]

        if (answer > 1) {
            numberOfProblems++
        }
        if (i > problems) {

            rl.close()
            console.log(numberOfProblems)
        }

    }

});

'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();
});

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let t = parseInt(readLine())
	let solCount=0
	while(t--){
		let [petya,vasya,tonya] = readLine().split(" ").map(n=>+n)
		if(petya && vasya || vasya && tonya || petya && tonya)
			solCount++
	}
	console.log(solCount)
}

var n = readline();
var count = 0
for(var i = 0; i<n; i++){
    count += readline().split(' ').map(x => parseInt(x)).reduce((a,b) => a + b) >=2 ? 1 : 0
}
print(count)

var AtLeastTwoAgreed = array => {
  var howManyAgreed = 0;
  for(var number of array)
  {
    howManyAgreed += number === 1 ? 1 : 0;

    if(howManyAgreed === 2)
      return 1;
  }

  return 0;
}

print(
  [...Array(+readline())].map(x => readline().split(' ').map(n => +n))
    .map(values => AtLeastTwoAgreed(values))
    .reduce((result, current) => result + current, 0)
);

var n = Number(readline());
var count = 0;
for (var i = 0; i < n; i++) {
	if (readline().split(" ").map(x => Number(x)).reduce((a, b) => a + b) > 1) count++;
}
print(count);

const rows = parseToInt(readline())

var arr = [];

for(var i=0;i<rows;i++) {
  arr.push(parseToIntArray(readline()))
}

compute(arr)

function parseToInt(str) {
  return Number.parseInt(str);
}

function parseToIntArray(str) {
  return str.split(" ").map(x=>Number.parseInt(x))
}

function compute(arr) {

  var sum = 0;
  for(var i=0;i<arr.length;i++) {
    var a = arr[i][0];
    var b = arr[i][1];
    var c = arr[i][2];

    if(a+b+c > 1) {
      sum++;
    }

  }

  print(sum)

}

function getSum(nums){
	var total = 0;
	for(var i = 0; i < nums.length; i++)
		total += parseInt(nums[i]);
	return total;
}

var n = readline();

var ans = 0;
for(var i = 0; i < n; i++){
	var votes = readline().split(" ");
	var sumOfVotes = getSum(votes);
	if(sumOfVotes > 1) ans++;
}

print(ans);

var n = readline(), ans = 0;
while(n--){
    var temp=readline();
    if((temp.split(" ").toString().match(/1/g) !=null) &&(temp.split(" ").toString().match(/1/g).length>=2)){
        ans+=1;
    }
}
print(ans);

var num_problemas = readline(); // Leemos el número de problemas que debemos tratar
var respuestas = 0;
var respuesta_individual;
// Por cada problema propuesto:
for (var i = 0; i < num_problemas; i++) {
    var problema = readline().split(" "); // Leemos y transformamos en un array las soluciones del equipo
    // Por cada solución individual propuesta:
    respuesta_individual = 0;
    for (var j = 0; j < problema.length; j++) {
        if (problema[j] == 1) {
            respuesta_individual++;
        }
    }
    // Si hay más de una respuesta afirmativa:
    if (respuesta_individual > 1) {
        respuestas++;
    }
}
print(respuestas);

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

const input = [];
readLine.on('line', line => input.push(line));

const aTeam = (a) => {
    +input.shift();
    let common = 0;
    for (let x of input) {
       const ar =  x.split(' ').map(x => +x);
        let score = 0;
        for (let y of ar) {
            score += y;
        }
        if (score >= 2) {
            common ++;
        }
    }
    console.log(common);
};

readLine.on('close', aTeam);

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

let inp = 0
process.stdin.on("data",input=>{
    inp = input
})
process.stdin.on("end",input=>{
    inp = inp.replace(/\s*$/, '').split("\n").map(str => str.replace(/\s*$/, ''));

    main();

})

function main(){
    let sure = 0;
    for (let i=1;i<=inp[0];i++){
        if(inp[i].split(" ").filter(item=>{return item>0}).length>1){sure += 1}
    }
    console.log(sure)
}

'use strict';

// let inpArr = `
// 3
// 1 1 0
// 1 1 1
// 1 0 0
// `.trim().split('\n').map(x => x.trim()), inpLine = 0;
// function readline() {
//   return inpArr[inpLine++];
// }
// function print(x) {
//   console.log(x);
// }

let n = Number(readline()), count = 0;
for (var i = 0; i < n; i++) {
  if (readline().split(' ').map(Number).reduce((a,b)=>a+b) >= 2) {
    count++
  }
}
print(count);

var n = readline()
var out = 0
for (var i = 0; i < n; i++) {if (readline().split(' ').map(x => Number(x)).reduce((a, b) => a + b) >=2) out++}
print(out)

var r = readline();
var c = 0;
for(var i = 0; i<r; i++){
    var l = readline().split(' ');
    var d = 0;
    for (var j = 0; j<l.length; j++){
        if(l[j] == 1){
            d++;
        }
    }
    if (d >= 2){
        c++;
    }
}
print(c);

y = readline().split(" ").map(each=>Number(each))

counter = 0
n = 0

while (counter < y) {
    x = readline()
    if (
    x == '1 1 0'||
    x == '1 1 1'||
    x == '0 1 1'||
    x == '1 0 1'
    )
    { n = n + 1 }
  counter = counter + 1 }

print ( n )

const n = Number(readline());
var c ;
var q = 0;
for(var i = 0; i < n ; i++){
    c = readline().split(" ");
    var k = c.reduce((acc, cur) => {
       if(cur == 1)
       return (acc + 1);
       else
        return acc;
    },0);
    (k >= 2) ? q++ : null;
}
print(q);
//

const readline = require('readline');

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

var count = 0;
var tasksCount;
var linesToSolve = [];

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

    linesToSolve.push(line);
    count++;

    if (count === tasksCount + 1) {
        rl.close();
        return;
    }
});

rl.on('close', () => {
    var result = 0;

    linesToSolve.forEach(item => {
        result += solveLine(item);
    });

    console.log(result);
    rl.close();
});

function solveLine(line) {
    return (line.match(/1/g) || []).length >= 2 ? 1 : 0;
}

var x=parseInt(readline());
var res=0;

while(x--){
    var z = readline().split(' ');
    var sum=findSum(z);
    // print("Sum:",sum);
    res+=Math.floor(sum/2);
}

function findSum(z){
    return z.reduce((a,b) => parseInt(a)+parseInt(b),0);
}

print(res);

'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 print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = readline().split(' ').map(x => parseInt(x));
  let result = 0;
  for (let i = 0; i < n; i++) {
    const vote = readline().split(' ').map(x => parseInt(x))
      .reduce((a, b) => a + b, 0);
    if (vote > 1) {
      result++;
    }
  }

  // output
  print(result);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
var a, b, c, n, r, g;
r = 0;
g = 0;
n = readline();
while ((n-- > 0)) {
  var vavl = readline().split(" ").map(x => parseInt(x));
  a = vavl[0];
  b = vavl[1];
  c = vavl[2];
  r = (a + b + c);
  if(r >= 2)
    g += 1;
}
console.log(g);
}

var n = readline();

var result = 0;

for(var i = 0 ; i < n; i++){
  var string = readline();
  string = string.replace(/\s/g,'');
  var decision = 0;

  for(var j =0; j < string.length;j++){
    if(string[j] == 1)
      decision++;
  }

  if(decision >= 2)
  result++;
}

print(result);

var lines = Number(readline());
var outp = 0;
for (var i = 0; i < lines; i++) {
    var str = readline();
    var count = Number(str.charAt(0)) + Number(str.charAt(2)) + Number(str.charAt(4));
    if (count > 1) outp ++;
}
print(outp);

var n = parseInt(readline());
var arr = [];
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] === 1 && w[i + 1] === 1 || w[i + 1] === 1 && w[i + 2] === 1 || w[i] === 1 && w[i + 2] === 1) {
               result++;
               result += result;
               print(result.length);
            }else {
                result += result
                print(result.length);
            }

         }
}
//print (arr[0]);

var problems = readline();

function resolve(prb) {
    var problSolv=0;
    for (var i=0; i<parseInt(prb); i++) {
        var count=0;
        var persons = readline().split(' ');

        if (persons[0]===1) {
            count++;
        } else if (persons[1]===1) {
            count++;
        } else if (persons[2]===1) {
            count++;
        }

        if (count>=2) {
            problSolv++;
        }
    }
    return problSolv;
}

print (resolve(problems));

var input = readline().split("\n");
var count = 0;
for(var i = 1;i < input.length; i++){
    var sures = input[i].split(" ").filter(function(element){return element == 1});
    if(sures.length > 1) count++;
}
print(count);

process.stdin.on('data', input => {
  const testArguments = input.toString().split('\n').splice(1);
  let count = 0;
  testArguments.forEach(test => {
    count += checkIfSolveProblem(test.split(' '))
  })
  console.log(count);
});

function checkIfSolveProblem(arr) {
  const result = arr.reduce((acc, curr) => {
    if (curr) {
      acc++
    }

    return acc;
  }, 0)

  return result > 0 ? 1 : 0;
}

readline();
var ans = 0;
for (var s; s = readline(); ) {
    1 < s.split( ' ' ).reduce( function(it, last) { return it - '' + last; }, 0 ) && ans++;
}

print( ans );

var n = parseInt(readline()),
    p = readline().split(' ').map(function(x) { return parseInt(x); }),
    i,
    s = 0,
    c = 0;

for(i = 0; i < n; i++) {
    c += p[i];
}
if(c>=2) s=c;
write(s);

const readline = require('readline')

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

rl.on("line", main)
let i = 0
let n;
let imp = 0
function main(input){
	if(i == 0 ){
		n = input
		i++
		return
	}
	if(n == i){
		console.log(imp)
		return
	}
	let p, v, t

	const arr = input.split(' ')

	p = arr[0]
	v = arr[1]
	t = arr[2]

	let result = parseInt(p) + parseInt(v) + parseInt(t)
	if(result >= 2){
		//they will imp
		imp++
	}

	i++

}

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = parseInt(readline());
var datos = new Array();
var contador = 0;

for (var x = 0; x < problemas; x++){
	datos.push(readline().split(' '));
}

for (var y = 0; y <datos.length-1;y++){
	if(datos[y] == 1){
		contador++;
	}
}

print(contador);

/*
var problemas = 3;
var datos = [1,1,0,1,1,1,1,0,0];
var contador = 0;

for (var x = 0; x <= datos.length-1; x++){
	if(datos[x] == 1){
		contador++;
	}
}

document.write(contador/problemas);
*/

var outp = 1;
for (var i = 0; i < Number(readline()); i++) {
    var str = readline().split(' ');
    var count = Number(str[0]) + Number(str[1]) + Number(str[2]);
    if (count > 1) outp ++;
}
print(outp);

var problems = readline();

function resolve(prb) {
    var problSolv=0;

    for (var i=0; i<prb; i++) {
        var count=0;
        var persons = readline().split(' ');

        if (persons[0]===1) {
            count++;
        } else if (persons[1]===1) {
            count++;
        } else if (persons[2]===1) {
            count++;
        }

        if (count>=2) {
            problSolv++;
        }
    }

    return problSolv;
}

print (resolve(parseInt(problems)));

var count = parseInt(readline()),
    current = [], currentMas, sum, answer = 0;

for(var i = 0; i < count; i++) {
    current[i] = readline().split(" ");
}

for(var i = 0; i < count; i++) {
    currentMas = current[i];
    sum = 0;

    for(var j = 0; j < 3; j++) {
        sum+=currentMas[j];
    }

    if(sum >= 2) {
        answer+=1;
    }
}

print(answer);

var n = readline()
var zad = 0;

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

	var str = readline().split(' ');
	var sum = str.reduce((sum, current)=> parseInt(sum+current));

	if(sum=>2)
	zad++;
};
print(zad);

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = readline();
var input = [];

var resueltos = 0;

for (var x = 0; x < problemas; x++){
	input.push(readline().split(' '));

}

print(input);

n = readline();
var tedad = 0;
while(n--)
{
 	s=readline().split('0')

	if(s.length > 3){tedad++}

}
print(tedad)

var problems = readline();

function resolve(prb) {
    for (var i=0; i<prb; i++) {
        var problSolv=0;
        var persons = readline().split(' ');
        var total = parseInt(persons[0])+parseInt(persons[1])+parseInt(persons[2]);
        if (total>=2) {
            problSolv++;
        }
    }
    return problSolv;
}
print (resolve(parseInt(problems)));

var n = readline()
var zad = 0;

for (var i=0; i<n; i++){
	var sum=0;
	var str = readline().split(' ');
	sum = str.reduce((sum, current)=> +sum+ +current);

	if(sum=>2)
	++zad;
};
print(zad);
//console.log(zad);

var n = parseInt(readline());
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {
               result++;
               result += result;
               write(result[0]);
            }else {
                write(result[0]);
            }

         }
}

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = parseInt(readline());
var datos = new Array();
var contador = 0;

for (var x = 0; x < problemas; x++){
	datos.push(readline().split(' '));
}

for (var y = 0; y <datos.length-1;y++){
	if(datos[x] == 1){
		contador++;
	}
}

print(contador);

/*
var problemas = 3;
var datos = [1,1,0,1,1,1,1,0,0];
var contador = 0;

for (var x = 0; x <= datos.length-1; x++){
	if(datos[x] == 1){
		contador++;
	}
}

document.write(contador/problemas);
*/

var n = parseInt(readline());
while (n--) {
        var w = readline();
        var result = 0;
         var arr = [];
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {
               result++;
               result += result;
               arr.push(result);
            }else {
                result += result
                arr.push(result);
            }
         print (arr[0]);
         }
}

var n = readline()
var zad = 0;

for (var i=0; i<n; i++){
	var str = readline().split(' ');
	var sum = str.reduce((sum, current)=> +sum+ +current);

	if(sum=>2)
	++zad;
};
print(zad);
//console.log(zad);

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = readline();
var datos = new Array();
var contador = 0;

for (var x = 0; x < problemas; x++){
	datos.push(readline().split(' '));
}

for (var y = 0; y<datos.length-1;y++){
	if(datos[x] == 1){
		contador++;
	}
}

print(contador/problemas);

/*
var problemas = 3;
var datos = [1,1,0,1,1,1,1,0,0];
var contador = 0;

for (var x = 0; x <= datos.length-1; x++){
	if(datos[x] == 1){
		contador++;
	}
}

document.write(contador/problemas);
*/

var q = parseInt(readline());

var result = 0;
for (var i = 0; i < q; i++) {
    var known = readline().split(" ").map(x => parseInt(x));

    var res = 0;
    for (var j = 0; j < known; j++) {
        if (known[j] === 1) {
            res++;
        }
    }

    if (res >= 2) {
        result++;
    }
}

print(result);

const readline = require('readline')

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

rl.on("line", main)
let i = 0
let n = 0
let imp = 0
function main(input){
	if(n == 0 ){
		n = input
		return
	}
	if(n == i){
		console.log(imp)
		return
	}
	let p, v, t

	const arr = input.split(' ')

	p = arr[0]
	v = arr[1]
	t = arr[2]

	let result = parseInt(p) + parseInt(v) + parseInt(t)
	if(result >= 2){
		//they will imp
		imp++
	}

	i++

}

var t = readline();
count = 0;
for(var i=1;i<t;i++){
    var x=readline().split(' ');
    var a=Number(x[0]);
    var b=Number(x[1]);
    var c=Number(x[2]);
    if((+a)+(+b)+(+c)>=2){
    count++;
    }
}
print(count);

var nProblems = readline().split(" ").map(function(x) { return parseInt(x); })[0];

var result = 0;

for (var i = 0; i < nProblems; i++)
{
    var randomRussians = readline().split(" ").map(function(x) { return parseInt(x); });

    var implement = 0;

    for (var j = 0; j < randomRussians.length; j++)
    {
        if (randomRussians[i] == 1)
            implement++;

        if (implement >= 2)
        {
            result++;

            break;
        }
    }
}

print(result);

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = readline();
var datos = new Array();
var contador = 0;
var linea = 0;

for (var x = 0; x < problemas; x++){
	linea = readline().split(' ');
	if (linea[0]+linea[1]+linea[2] >= 2){
		contador++;
	}
}

print(contador);

var lines = readline();
var outp = 0;
for (var i = 0; i < lines; i++) {
    var str = readline().split(' ');
    var count = 0;
    for (var j = 0; j < 3; j++) {
        count += str[j];
    }
    if (count >= 2) outp ++;
}
print(outp);

var numberOfProblems = readline();
var arrOfAnswers = [];
for(var i = 0; i < numberOfProblems; ++i) {
    arrOfAnswers[i] = readline();
}
var friendsNum = 3;
var sureOfSolutions = 0
var countOfWhoSure = 0;

for(var i = 0; i < numberOfProblems; ++i) {
    countOfWhoSure = 0;
    for(var j = 0; j < friendsNum; ++j) {
        if(parseInt(arrOfAnswers[i][j])) {
            ++countOfWhoSure;
            if(countOfWhoSure == 2) {
                ++sureOfSolutions;
                break;
            }
        }
    }
}

print(sureOfSolutions);

'use strict';

// let inpArr = `
// 3
// X--
// --X
// X++
// `.trim().split('\n').map(x => x.trim()), inpLine = 0;
// function readline() {
//   return inpArr[inpLine++];
// }
// function print(x) {
//   console.log(x);
// }

let n = Number(readline()), X = 0;
for (var i = 0; i < n; i++) {
  let str = readline();
  if (str.indexOf('+') !== -1) {
    X++;
  } else {
    X--;
  }
}
print(X);

var count = readline()
var totalRightAnswers = 0;

while(count){
    var round = readline()
    const haveAnswers = round.split(" ")
    const res = haveAnswers.reduce((accumulator, currentValue) => {
        if (currentValue == '1') return accumulator++
    });
    if(res >= 2){
        totalRightAnswers++
    }
    count--
}

print(totalRightAnswers)

var n = parseInt(readline());
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {
               result++;
               result += result;
               write(result);
            }else {
                write(result);
            }

         }
}

var t = readline();
t=+t+1;
print(t);
count = 0;
for(var i=1;i<t;i++){
    var x=readline().split(' ');
    var a=+x[0];
    var b=+x[1];
    var c=+x[2];
    print(a+b+c);
    if(a+b+c>=2){
    count++;
    }
}
print(count);

var numberOfTestCases = parseInt(readline());

var input;

var ans = 0;

for(var i = 0 ; i < numberOfTestCases ; i++) {

input = readline().split(" ");

var counter = 0;

for (var j=0; j<input.length; j++){
    if (input[j] == 1){
        counter++;
    }
}

if (counter > 2){
    ans++;
}

}

print(ans);

var loop = readline();
var correct = 0;
for (var i = 0; i < loop; i++){
    var total = readline().split(" ");
    if(total[0] + total[1] + total[2] > 2){
        correct++;
    }
}

print(correct);

var t = readline();
count = 0;
for(var i=1;i<t;i++){
    var x=readline().split(' ');
    var a=x[0];
    var b=x[1];
    var c=x[2];
    if((+a)+(+b)+(+c)>=2){
    count++;
    }
}
print(count);

var n = +readline(),
	result = 0;
while (n--) {
	var array = readline().split(' ').map(function (item) { return item > 0; });
    result += array.length > 1 ? 1 : 0;
}
print(result);

/*
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.
*/

var problemas = parseInt(readline());
var datos = new Array();
var contador = 0;

for (var x = 0; x < problemas; x++){
	datos.push(readline().split(' '));
}

for (var y = 0; y <datos.length-1;y++){
	if(parseInt(datos[y]) == 1){
		contador++;
	}
}

print(contador);

/*
var problemas = 3;
var datos = [1,1,0,1,1,1,1,0,0];
var contador = 0;

for (var x = 0; x <= datos.length-1; x++){
	if(datos[x] == 1){
		contador++;
	}
}

document.write(contador/problemas);
*/

var count = readline()
var totalRightAnswers = 0;

while(count){
    var round = readline()
    const haveAnswers = round.split(" ")
    var accumulator = 0
    haveAnswers.forEach(element => {
        if (element == '1') return accumulator++
    });
    if(accumulator >= 2){
        totalRightAnswers++
    }
    count--
}

print(totalRightAnswers)

var n=readline();
var int=parseInt(n);
var count=0;

for(var i=1; i<=int; i++){

    for(var j=1; j<=int; ++j){
     var question=readline();
     var newint=parseInt(question);
     var sum=0;
      sum=sum+newint;

   }
    if(sum==2 || sum==3){
      count++;
}
 print(count);
}

var n = parseInt(readline());
var arr = [];
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] === 1 && w[i + 1] === 1 || w[i + 1] === 1 && w[i + 2] === 1 || w[i] === 1 && w[i + 2] === 1) {
               result++;
               result += result;
               arr.push(result);
            }else {
                result += result
                arr.push(result);
            }

         }
}
print (arr[0]);

'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 testcases=Number(readline())

    let solve=(A)=>{
        let n=A.length,result=0
        for(let i=0;i<n;i++){
            let total=A[i].reduce((a,c)=>a+c)
            if(total>=2){
                result++
            }
        }
        return result
    }

    for (let i = 0; i <testcases; i++) {
        let n=readline()
        let A=[]
        for (let i = 0; i < n; i++) {
            A.push(readline().split(" ").map(d=>Number(d)))
        }

        let result=solve(A)
        console.log(result.toString())
    }

}

var t = readline(),
    a = 0;
while(t--){
    var x = readline().split(' ');
    var count = 0;
    for(var i = 0;i<3;i++){
        if(x[i] === 1){count++;}
    }
    if(count>=2){
    a++;
    }
}
print(a);

var problems = readline();

function resolve(prb) {
    for (var i=0; i<prb; i++) {
        var problSolv=0;
        var persons = readline().split(' ');
        if ((persons[0]+persons[0]+persons[0])>=2) {
            problSolv++;
        }
    }
    return problSolv;
}
print (resolve(parseInt(problems)));

var pro = readline();
var tot = 0;
function getSum(total, num) {
    return total + num;
}
for (i = 0; i < pro; i++) {
   var arr = readline().split(' ');
    var col = arr.reduce(getSum);
    if (col >= pro) {
        var out = tot + 1;

    }

}
print(out);

var problems = readline();

function resolve(prb) {
    for (var i=0; i<prb; i++) {
        var problSolv=0;
        var persons = readline().split(' ');
        if ((persons[0]+persons[1]+persons[2])>=2) {
            problSolv++;
        }
    }
    return problSolv;
}
print (resolve(parseInt(problems)));

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let numberOfProblems = 0
let numberofSolvedProblems = 0 ;
let counter = 0;
let arrofInputs = [];
let getuserInputs = ()=>{
  rl.on("line",(input)=>{
    if(!numberOfProblems) {
      numberOfProblems = parseInt(input)
      console.log("Problems We Got Today :"+numberOfProblems + "\n")
    }
    else
    {
      counter++
      arrofInputs = input.split(" ").map(Number)
      if(!arrofInputs.includes(0))numberofSolvedProblems++
      else{
        let temp = 0
        arrofInputs.forEach(element => {
          if(element===1) temp++
        });
        if (temp>=2) numberofSolvedProblems++
      }
      if (counter>=numberOfProblems){
         console.log(numberofSolvedProblems)
         rl.close();
        }
    }
 })}
getuserInputs()
// })
// let numberofSolvedProblems = 0;
// let numberOfProblems = parseInt(prompt());
// for(let i=0 ;i<numberOfProblems;i++){
//   let temp  = (prompt().split(" ")).map(Number)
//   if (!temp.includes(0))
//   {
//     numberofSolvedProblems++
//   }
//   else{
//     //console.log("First Else Fired")
//     let zeroCounter = 0 ;
//     temp.forEach(element => {
//       if(element === 0)
//       {
//         zeroCounter++
//       }
//     })
//     if(zeroCounter>1)
//     numberofSolvedProblems = numberofSolvedProblems
//     else
//     numberofSolvedProblems++
//   }
// }
// console.log(numberofSolvedProblems)

//// rl.close()

var count = parseInt(readline()),
    current = [], currentMas, sum, answer = 0;

for(var i = 0; i < count; i++) {
    current[i] = readline().split(" ");
}

for(var i = 0; i < count; i++) {
    currentMas = current[i];
    sum = 0;
    for(var j = 0; j < 3; j++) {
        sum+=currentMas[j];
    }

    if(sum>=2) {
        answer+=1;
    }
}

var lines = Number(readline());
var outp = 0;
for (var i = 0; i < lines; i++) {
    var str = readline().split(' ');
    var count = str[0] + str[1] + str[2];
    if (count >= 2) outp ++;
}
print(outp);

var result = 0;
  var count = parseInt(readline().split(''));
  function canResolve(value){
    return value === '1';
  }
  for (var i = 0; i < count; i++) {
    var array = readline().split(' ');
    result += array.filter(canResolve).length >= 2 ? 1 : 0;
  }
  print(result);

var n = parseInt(readline());

var input = [];

for (var i = 1; i <= n; i++) {
    input.push(readline().split(' '));
}

var solvedCount = 0;
input.forEach(function(line) {
    var sureCount = 0;
    line.forEach(function(value) {
        if (value) {
            sureCount++;
        }
    });
    if (sureCount >= 2) {
        solvedCount++;
    }
});

print(solvedCount);

var t = readline();
while(t--){
    var x = readline().split(' ');
    var a = 0,
        count = 0;
        for(var i = 0;i<3;i++){
            if(x[i] === 1){count++}
        }
        if(count=>2){
        a++
        }
}
print(a);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  var T = readLine();
  var count = 0;
  while (T--) {
    var str = readLine();
    var strSingle = str.split(" ");
    for (let i = 0; i <= T; i++) {
      if ((strSingle[0] == 1 && strSingle[1] == 1) || (strSingle[1] == 1 && strSingle[2] == 1)) {
        count++;
        break;
      }
    }
  }
  if (count) {
    console.log(count);
  } else {
    console.log(0);
  }
}

const stdin = process.openStdin();
let n;
let i = 0;
let output = 0;

process.stdin.on('data', function (chunk) {
  lines = chunk.toString().split('\n');
  lines.map(line => processLine(line));
});

function processLine(text) {
  if (n) { i += 1; }
  if (!n) { n = parseInt(text.toString()) }

  if (i > 0) {
    const solve = text.toString().trim().split(' ').reduce((a, b) => a + b, 0) > 1;
    console.log(solve)
    if (solve) { output += 1; }
  }

  if (i === n) { console.log(output); }
}

var n = readline()
var zad = 0;

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

	var str = readline().split(' ');
	var sum = str.reduce((sum, current)=> parseInt(sum+current));

	if(sum=>2)
	zad++;
};
print(zad);

var n = readline();
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1) {
               result++;
               result += result;
               if (result < w.length - 2) {
               print (result);
               }
            }else{
                print(result);
            }

         }
}

var n = parseInt(readline());
var output = 0;

for(var i = 0; i < n; i++)
{
	var tmp = 0;
	var sures = readline().split(' ').map(function(c){
		if(c == 1) tmp += 1;
	});
	if(tmp >= 2) output += 1;
}

var n = readline();
var zad = 0;

for (var i=0; i<n; i++){
	var sum = 0;
	var str = readline().split(' ');
	sum = str[0]+str[1]+str[2];

	if(sum>1)
	++zad;
};
print(zad);

var cases = readline();
var winMatch = 0;
for(var i = 0; i < cases; ++i){
    var points = readline();
    if(points.includes('1 1')){
        ++winMatch;
    }
}

print(winMatch);

var n = parseInt(readline());
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {
               result++;
               result += result;
               write(result[0]);
            }else {
                write(result[0]);
            }

         }
}

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

	var str = readline().split(' ');
	var sum = str.reduce((sum, current)=> parseInt(sum+current));

	if(sum=>2)
	zad++;
};
print(zad);

var n=readline();
var int=parseInt(n);
var count=0;

for(var i=1; i<=int; i++){

     var question=readline();
     var numbers = question.split(" ");
     var sum=0;
     for(var j = 0; j < int; ++j) {
        var newint=parseInt(numbers[j]);

        sum=sum+newint;
     }

    if(sum==2 || sum==3){
      count++;
}
 print(count);
}

var problems = readline();

function resolve(prb) {
    var problSolv=0;
    for (var i=0; i<parseInt(prb); i++) {
        var count=0;
        var persons = readline().split(' ');

        if (persons[0]===1) {
            count++;
        } else if (persons[1]===1) {
            count++;
        } else if (persons[2]===1) {
            count++;
        }

        if (count>=2) {
            problSolv++;
        }
    }
    return problSolv;
}

print (resolve(problems));

var loop = readline();
var correct = 0;
for (var i = 0; i < loop; i++){
    var total = readline().split(" ");
    if(total[0] + total[1] + total[2] >= 2){
        correct++;
    }
}

print(correct);

var lines = Number(readline());
var outp = 0;
for (var i = 0; i < lines; i++) {
    var str = readline().split(' ');
    var count = str[0] + str[1] + str[2];
    if (count >= 2) {
        outp ++;
    }
}
print(outp);

var count = readline()
var totalRightAnswers = 0;

while(count){
    var round = readline()
    var haveAnswers = round.split(" ")
    var res = haveAnswers.reduce((accumulator, currentValue) => accumulator + currentValue);
    if(res >= 2){
        totalRightAnswers++
    }
    count--
}

print(totalRightAnswers)

var n = readline();
var zad = 0;

for (var i=0; i<n; i++){
	var sum = 0;
	var str = readline().split(' ');
	sum = str[0]+str[1]+str[2];

	if(sum>1)
	{++zad;};
};
print(zad);

var t = readline();
count = 0;
for(var i=1;i<t;i++){
    var x=readline().split(' ');
    var a=x[0];
    var b=x[1];
    var c=x[2];
    if((+a)+(+b)+(+c)>=2){
    count++;
    }
}
print(count);

var n = parseInt(readline()),
    p = readline().split(' ').map(function(x) { return parseInt(x); }),
    i,
    s = 0,
    c = 0;

for(i = 0; i < n; i++) {
    c += p[i];
}
if(c>=2) s=c;
write(s);

process.stdin.on('data', input => {
  const testArguments = input.toString().split('\n').splice(1);
  let count = 0;
  testArguments.forEach(test => {
    count += checkIfSolveProblem(test.split(' '))
  })
  console.log(count);
});

function checkIfSolveProblem(arr) {
  const result = arr.reduce((acc, curr) => {
    if (curr) {
      acc++
    }

    return acc;
  }, 0)

  return result > 1 ? 1 : 0;
}

var a  =  readline();
var jami = 0;
for(i = 1; i < a; i ++ ) {
	var cin = readline().split(" ").sort(function(a,b){return a-b});
	if(cin[1] == 1) {
		jami += 1;
	}
        else {
                jami += 0;
        }
}

print(jami);

var input=readline();
var int = parseInt(input);
var varr;
var c = 0 ;
var count1 = 0;
var count0 = 0;

for(var i = 0 ; i < int ; i++){

   varr = readline();
   count(varr);

    if (count1 > count0) {
        c++;
    }

}

function count(str)
{
    for (var i = 0 ; i < str.length ; i++)
    {

        if(str[i] == 1){
            count1++;

        }
        else{
       count0++;
        }
    }
}

print(c);

var n = readline().split(' ')[0];
var solutions = 0;
while(n) {
    var state = readline().split(' ');
    var a = state[0],
        b = state[1],
        c = state[2];

    if ((a && b) || (b && c) || (c && a)) {
        ++solutions;
    }

    --n;
}

print(solutions);

var n = parseInt(readline());
var s = 0;
var i;
for (i=0;i<n;i++){
    x=readline().split(' ');
    if ((x[0]+x[1]+x[2]) >= 2){
        s++;
    }
}
print(s);

var n = readline();

var result = 0;

for(var i = 0 ; i < n; i++){
  var string = readline();
  string = string.replace(/\s/g,'');
  var decision = 0;

  for(var j =0; j < string.length;j++){
    if(string[i] == 1)
      decision++;
  }

  if(decision >= 2)
  result++;
}

print(result);

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

for (var i=0; i<n; i++) {
    var line = readline().split(' ');
    var u = 1;
    for (var m=0; m<line.length; m++) {
         u = u*line[m];
    }
    sum = sum + u;

}
    print (sum);

var n=parseInt(readline());
var k=0;
for(var i=0;i<n;i++){
    var s=parseInt(readline())+parseInt(readline())+parseInt(readline());
    if(s>=2)
        k++;
}
print(k+1);

var problems = readline();

function resolve(prb) {
    var problSolv=0;

    for (var i=0; i<prb; i++) {
        var count=0;
        var persons = readline().split(' ');

        if (persons[0]===1) {
            count++;
        } else if (persons[1]===1) {
            count++;
        } else if (persons[2]===1) {
            count++;
        }

        if (count>=2) {
            problSolv++;
        }
    }

    return problSolv;
}

print (resolve(parseInt(problems)));

var n = parseInt(readline());
var arr = [];
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1 < w.length) {
               result++;
               result += result;
               arr.push(result);
            }else {
                result += result
                arr.push(result);
            }

         }
}
print (arr[0]);

        numOfLines = readline();
        num = parseInt(numOfLines);
        output = 0;
        outputInOneLine = 0;
        for (i = 0; i < num; i++) {
            line = readline();
            val = line.split(" ");
            val.map(el => {
                if (el == 1) {
                    outputInOneLine++;
                }
            })
            if (outputInOneLine > 1) {
                output++;
            }
            print(output);
            outputInOneLine = 0;
        }

var n = readline()
var zad = 0;

for (var i=0; i<n; i++){
	var sum=0;
	var str = readline().split(' ');
	sum = str.reduce((sum, current)=> +sum+ +current);

	if(sum=>2)
	++zad;
};
print(zad);
//console.log(zad);

var n = parseInt(readline());
var s = 0;
var i;
for (i=0;i<n;i++){
    x=readline().split(' ');
    if ((x[0]+x[1]+x[2]) >= 1){
        s++;
    }
}
print(s);

var problems = readline();

function resolve(prb) {
    for (var i=0; i<prb; i++) {
        var problSolv=0;
        var persons = readline().split(' ');
        var total = parseInt(persons[0])+parseInt(persons[1])+parseInt(persons[2]);
        if (total>=2) {
            problSolv++;
        }
    }
    return problSolv;
}
print (resolve(parseInt(problems)));

var n = parseInt(readline());
var arr = [];
while (n--) {
        var w = readline();
        var result = 0;
        for (var i = 0; i <= w.length; i++) {
           if(w[i] == 1 && w[i + 1] == 1 || w[i + 1] == 1 && w[i + 2] == 1 || w[i] == 1 && w[i + 2] == 1) {
               result++;
               result += result;
               arr.push(result);
            }else {
                result += result
                arr.push(result);
            }

         }
}
print (arr[0]);

var problems = readline();

function resolve(prb) {
    var problSolv=0;
    for (var i=0; i<prb; i++) {
        var count=0;
        var persons = readline().split(' ');

        if (persons[0]===1) {
            count++;
        } else if (persons[1]===1) {
            count++;
        } else if (persons[2]===1) {
            count++;
        }

        if (count>=2) {
            problSolv++;
        }
    }
    return problSolv;
}

print (resolve(problems));


Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi. Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

NoteIn the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.

'use strict'

const N = +readline()
const qs = readline().split(' ').map(v => parseInt(v))
const M = +readline()
//const ms = []

let lll
const bs = []

while (lll = readline()) {
  lll = lll.split(' ').map(v => parseInt(v))
  //ms.push(lll)
  const b = lll[0]
  const e = lll[1]
  const p = lll[2]

  if (!bs[e] || bs[e][1] > p) bs[e] = [b, p]
}

let en = 0
let p = 0
bs.forEach(v => {
  en++
  p += v[1]
})

print(en == N - 1 ? p : -1)


Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.

The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct. Note that s can equal t.

If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.

print(function(n, s, t) {

  var p = ('0 ' + readline()).split(' ').map(Number);

  if (s === t) return 0;

  for (var i = p[s], ans = 1; i !== t && i !== s; ans++, i = p[i]);

  return i === t ? ans : -1;

}.apply(0, readline().split(' ').map(Number)));

;(function () {

	var n = readline().split(' '),
		s = +n[1],
		k = s,
		t = +n[2];
	n = +n[0];

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

	print((function () {
		var i = 0;
		while (s !== t) {
			s = p[s - 1];
			if (s === k) return -1;
			else i++;
		}

		return i;
	})());

}).call(this);


Polygon is not only the best platform for developing problems but also a square matrix with side $$$n$$$, initially filled with the character 0.On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly $$$2n$$$ cannons were placed.    Initial polygon for $$$n=4$$$. Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.More formally:   if a cannon stands in the row $$$i$$$, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell ($$$i, 1$$$) and ends in some cell ($$$i, j$$$);  if a cannon stands in the column $$$j$$$, above the first row, and shoots with a 1, then the 1 starts its flight from the cell ($$$1, j$$$) and ends in some cell ($$$i, j$$$). For example, consider the following sequence of shots:   1. Shoot the cannon in the row $$$2$$$.                         2. Shoot the cannon in the row $$$2$$$.                         3. Shoot the cannon in column $$$3$$$. You have a report from the military training on your desk. This report is a square matrix with side length $$$n$$$ consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case starts with a line containing an integer $$$n$$$ ($$$1 \le n \le 50$$$) — the size of the polygon. This is followed by $$$n$$$ lines of length $$$n$$$, consisting of 0 and 1 — the polygon matrix after the training. The total area of the matrices in all test cases in one test does not exceed $$$10^5$$$.

For each test case print:   YES if there is a sequence of shots leading to a given matrix;  NO if such a sequence does not exist.  The letters in the words YES and NO can be printed in any case.

NoteThe first test case was explained in the statement.The answer to the second test case is NO, since a 1 in a cell ($$$1, 1$$$) flying out of any cannon would continue its flight further.

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    checkNext();
  }

}

function checkNext() {
  var n = +readline();
  var allowedCols = new Set();
  var lines = [];

  for (var j = 0; j < n; j++) {
    allowedCols.add(j);
    lines[j] = readline();
  }
  for (var j = n - 1; j >= 0; j--) {
    var nextLine = lines[j];
    var allowed = true;
    for (var k = n - 1; k >= 0; k--) {
      if (allowedCols.has(k)) {
        allowed = true;
      }
      if (!allowed && nextLine[k] === "1") {
        print("NO");
        return;
      }
      if (nextLine[k] === "1") {
        allowedCols.add(k);
      } else {
        allowed = false;
        allowedCols.delete(k);
      }
    }
  }
  print("YES");
}
main();

function solve() {
    var n = readInt();
    var i;
    var j;
    var x = createMatrix(n)
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if(x[i][j] == 1) {
                if( !(j+1 == n || i + 1 == n || x[i][j+1] === 1 || x[i+1][j] === 1)) {
                    print("NO")
                    return
                }
            }
        }
    }
    print("YES")
}

function createMatrix(n) {
    var arr = new Array(n)
    var i
    for(i=0; i<n; i++) {
        arr[i] = readIntArray()
    }
    return arr
}

var testCases = readInt();
var testCaseNum;
for(testCaseNum=0; testCaseNum<testCases; testCaseNum++) {
  solve()
}

function readIntArray() {
    return readline().split("").map(function(x) { return parseInt(x); });
}

function readInt() {
    return parseInt(readline())
}

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

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    checkNext();
  }
}

function checkNext() {
  var n = +readline();
  var allowedCols = new Set();
  var lines = [];

  for (var j = 0; j < n; j++) {
    lines[j] = readline();
  }
  for (var j = n - 1; j >= 0; j--) {
    var nextLine = lines[j];
    var last0 = nextLine.lastIndexOf("0");
    for (var k = 0; k < n; k++) {
      if (nextLine[k] === "1" && k < last0 && !allowedCols.has(k)) {
        print("NO");
        return;
      }
      if (nextLine[k] === "1") {
        allowedCols.add(k);
      } else {
        allowedCols.delete(k);
      }
    }
  }
  print("YES");
}
main();

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    checkNext();
  }
}

function checkNext() {
  var n = +readline();
  var allowedCols = new Set();
  var lines = [];

  for (var j = 0; j < n; j++) {
    allowedCols.add(j);
    lines[j] = readline();
  }
  for (var j = n - 1; j >= 0; j--) {
    var nextLine = lines[j];
    var last0 = nextLine.lastIndexOf("0");
    for (var k = 0; k < n; k++) {
      if (nextLine[k] === "1" && k < last0 && !allowedCols.has(k)) {
        print("NO");
        return;
      }
      if (nextLine[k] === "1") {
        allowedCols.add(k);
      } else {
        allowedCols.delete(k);
      }
    }
  }
  print("YES");
}
main();