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.

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.

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.

<?
$n=trim(fgets(STDIN));
$z=0;
for($i=0;$i<$n;$i++)
    {
        $p=explode(" ",trim(fgets(STDIN)));
        foreach($p as $v)$s[$v]++;
        if($s[1]>=2)++$z;
        unset($s);
    }
   echo $z;
?>

<?php
$a = trim(fgets(STDIN));
for($c=0; $c<$a; ++$c)
{
    $b[$c] = trim(fgets(STDIN));
    $e = explode(" ", $b[$c]);
    if(array_sum($e)>=2)
    {$d += 1;}else{$d += 0;}
}
echo $d;
?>

<?php

function read() {

    fscanf(STDIN, "%d", $n);

    $arr = array();

    for ($i = 0; $i < $n; $i++) {
        $numbers = explode(" ", fgets(STDIN));
        $arr[] = $numbers;
    }
    return $arr;
}

function isValid($numbers) {

    $result = array_sum($numbers);
    return $result >= 2;
}

$arr = read();
$filtered = array_filter($arr, "isValid");

echo count($filtered);

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = explode(" ", trim(fgets(STDIN)));
}
$result = 0;
foreach ($a as $task) {
	if (($task[0] && $task[1]) || ($task[1] && $task[2]) || ($task[0] && $task[2]))
		$result++;
}

fprintf(STDOUT, $result);

<?php
while (fscanf(STDIN, "%d", $n)){
    $ac = 0;
    while ($n--){
        $line = stream_get_line(STDIN, 65535, "\n");
        $question = explode(" ", $line);
        if (array_sum($question) > 1){
            ++$ac;
        }
    }
    echo $ac . "\n";
}

<?php

fscanf(STDIN, "%d\n", $number);
$i = 0;
$counter = 0;

while($i<$number && $line = trim(fgets(STDIN))){

	if($line == '1 1 1' || $line == '1 1 0' || $line == '1 0 1' || $line == '0 1 1') $counter++ ;
}

fwrite(STDOUT, $counter."\n");

<?php
while($item = trim(fgets(STDIN))){
    $data[] = (int)str_replace(' ', '', $item);
}

$result = 0;
$count = array_shift($data);

foreach($data as $res) {
    if($res >= 101 || $res === 11) {
        $result++;
    }
}

echo $result;

<?php

$is_first = true;
$tasks_count = 0;
while ($row = fgets(STDIN)) {
    if ($is_first === true) {
        $is_first = false;
        continue;
    }
    if (substr_count($row, '1') >= 2) {
        $tasks_count++;
    }
}
echo $tasks_count;

<?php
	fscanf(STDIN, '%d', $num);
	$solve = 0;
	$arr = [];
	while (fscanf(STDIN, '%d %d %d', $arr[0], $arr[1], $arr[2])){
		$yes = 0;
		foreach ($arr as $key => $value) {
			if($value == 1) $yes++;
		}
		if($yes >= 2) $solve++;
		$arr = [];
	}
	echo $solve;
?>

<?php
$n = (int)readline();
$output = 0;
for($i = 0; $i < $n; $i++) {
    $input = str_replace(' ', '',readline());
    $input == 11 || $input > 100 ? $output += 1 : 1;
}
echo $output;

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$c=trim($input[0]);
$w= 0;
for ($i=1 ;$i <= $c ;$i++ ){
    $arr= explode(' ', trim($input[$i]));
    $arr=array_count_values($arr);
    if ($arr[1] >= 2){
        $w ++;
    }
}
echo $w;

<?php
    $n = trim(fgets(STDIN));
    $result = 0;
    for($i = 0; $i < $n; $i++){
        $args[$i] = explode(" ", trim(fgets(STDIN)));
        if($args[$i][0]+$args[$i][1]+$args[$i][2] >= 2) $result++;
    }
    fwrite(STDOUT, $result++);

<?php

//=====================================
// link: https://codeforces.com/contest/231/problem/A
//=====================================

// get inputs
$number_of_problems = trim(fgets(STDIN));

$implemention = 0;

for ($i=0; $i < $number_of_problems; $i++) {
    $approvals = array_sum(explode(' ', trim(fgets(STDIN))));

    if($approvals >= 2) {
        $implemention++;
    }
}

echo $implemention . "\n";

<?php
	$n = trim(fgets(STDIN));
	$i = 0;
	$num = 0;
	while($i<$n)
	{
		$str = trim(fgets(STDIN));
		$nilai = explode(" ",$str);
		if(array_sum($nilai)>1)
			$num = $num + 1;
		$i++;
	}
	echo $num;
?>

<?php
$problems_num = fgets(STDIN);
$vote_result=0;
for ($i=0; $i < $problems_num; $i++) {
	$vote = explode(' ', fgets(STDIN));
	if ($vote[0]+$vote[1]+$vote[2]>=2)
		$vote_result+=1;
}
echo $vote_result;
?>

<?php
$n = trim(fgets(STDIN));
$ret = 0;
for($i=0;$i<$n;$i++){
  list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
  if ($a + $b + $c >=2) $ret++;
}

echo $ret . PHP_EOL;

<?php
fscanf(STDIN,"%d",$n);
$a=array();
$ans=0;
foreach (range(1,$n) as $i)
{
    fscanf(STDIN,"%d%d%d",$x,$y,$z);
    if ($x+$y+$z>=2) $ans++;
}
fprintf(STDOUT,"%d\n",$ans);
?>

<?php
$n = trim(fgets(STDIN));
$sum = 0;

for($i = 0;$i < $n;$i++){
    $arr = explode(" ", trim(fgets(STDIN)));
    if(array_sum($arr) > 1){
        $sum++;
    }
}

print $sum

?>

<?php
$counter=0;
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%d %d %d",$v,$p,$t);
	if (($v+$p+$t)>1)
		$counter++;
}
echo $counter;
?>

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
 $input = STDIN;

//$output = TXTOUT;
 $output = STDOUT;

function foo($p, $v, $t)
{
    return ($p + $v + $t) >= 2;
}

$c = 0;

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($p, $v, $t) = fscanf($input, "%d %d %d\n");

    $c += foo($p, $v, $t) ? 1 : 0;
}

fwrite($output, $c);

<?php

    $dir = fopen("php://stdin", 'r');
    $input = stream_get_contents($dir);

// $input = '3
// 1 0 1
// 0 1 1
// 0 0 0';

$arr = explode(PHP_EOL, $input);
$k = 0;
for($i=0;$i<$arr[0];$i++){
    if(array_sum(array_map('intval', explode(' ', $arr[$i+1]))) >= 2)
        $k++;
}

echo $k;

<?php
// http://codeforces.com/problemset/problem/231/A

// initialize answer
$number_of_problems_to_implement = 0;

// INPUT
// The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest.
fscanf(STDIN, "%d", $n);

// Then n lines contain three integers each.
for ($i=0; $i < $n; $i++)
{
	// The numbers on the lines are separated by spaces. Each integer is either 0 or 1
	fscanf(STDIN, "%d %d %d", $integers_matrix[$i][0], $integers_matrix[$i][1], $integers_matrix[$i][2] );

	// 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.

	// 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:
	if
	(	( 1 == $integers_matrix[$i][0] && 1 == $integers_matrix[$i][1] )
	||	( 1 == $integers_matrix[$i][0] && 1 == $integers_matrix[$i][2] )
	||	( 1 == $integers_matrix[$i][1] && 1 == $integers_matrix[$i][2] )
	)
	{
		$number_of_problems_to_implement++;
	}

}

//Output: Print a single integer — the number of problems the friends will implement on the contest.
echo $number_of_problems_to_implement;

?>

<?php
$lines = (int)fgets(STDIN);
if($lines >= 1 && $lines <= 1000)
{
    $problems = [];
    for($i = 0;$i < $lines; $i++)
        $problems[$i] = fgets(STDIN);
    $submissions = 0;

    foreach($problems as $problem)
    {
        $checker1 = $problem[0] == 1 || $problem[0] == 0;
        $checker2 = $problem[2] == 1 || $problem[2] == 0;
        $checker3 = $problem[4] == 1 || $problem[4] == 0;
        if($checker1 && $checker2 && $checker3)
        {
            $petya = (int)$problem[0];
            $vasya = (int)$problem[2];
            $tonya = (int)$problem[4];
            if(($petya + $vasya + $tonya) >= 2)
            {
                $submissions++;
            }
        }
        else
        {
            echo "Not valid input\n";
            break;
        }

    }
    echo $submissions;

}
else
{
    echo "Not valid input\n";
}

?>

<?php
    $n = fgets(STDIN);
    $sum = 0;
    for($i = 0; $i < $n; ++$i)
    {
        $mass = explode(" ", fgets(STDIN));
        $ones = 0;
        for($key = 0; $key < 3; ++$key)
        {
            if($mass[$key] == 1){$ones++;}
        }
        if($ones >= 2){$sum ++;}
    }
    echo $sum;
?>

<?php
$n = trim(fgets(STDIN));
$tasks = array();

for( $i=0; $i<$n; $i++ )
{
    $tasks[$i] = explode(' ',trim(fgets(STDIN)));
}

//print_r($tasks);

$task_with_solution = 0;

for( $i=0; $i<$n; $i++ )
{
    $task_count = 0;
    foreach( $tasks[$i] as $task)
    {
        $task_count = $task + $task_count;
    }

    if( $task_count >= 2 ){
        $task_with_solution++;
    }
}
echo $task_with_solution;

<?
$a = trim(fgets(STDIN));
$res = 0;
for($i = 0; $i < $a; $i++){
    $tmp = explode(' ', trim(fgets(STDIN)));
    if(array_sum($tmp) > 1)
        $res++;
}
echo $res;

<?php
$lines = trim(fgets(STDIN));

$problemsOk = 0;

for ($i = 1; $i <= $lines; $i++) {
    $problem = trim(fgets(STDIN));
    $cP = 0;
    if($problem[0] == 1) $cP++;
    if($problem[2] == 1) $cP++;
    if($problem[4] == 1) $cP++;

    if($cP >= 2) $problemsOk++;
}
echo $problemsOk."\n";

<?php
$n = trim(fgets(STDIN));
$counter = 0;
for ($i = 1; $i <= $n; $i++)
{
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    if (($a+$b+$c) > 1) $counter++;
}

echo $counter;

<?php

$num = readline();

$des = 0;
for($i = 0; $i < $num; $i++) {
    $str = readline();

    $arr = explode(' ', $str);

    $f = array_filter($arr);

    if(count($f) >= 2) {
        $des++;
    }
}

echo $des;

<?php
$n = (fgets(STDIN));
$summSolution=0;
for ($i=0;$i<$n;$i++)
{
    $peopleVote = explode(" ",fgets(STDIN));
    if (($peopleVote[0]+$peopleVote[1]+$peopleVote[2])>=2)
    {
        $summSolution++;
    }
}
echo $summSolution;
?>

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    // 3 people
    // 2 have to be sure
    // n problems
    [$n] = getStdIn(true);
    $solved = 0;
    for ($i = 0; $i < $n; $i++) {
        if (array_sum(getStdIn(true)) >= 2) {
            ++$solved;
        }
    }
    stdOut($solved);
}

solve();

<?php

/**
 * @return int
 */
function getInt() {
    return (int) trim(fgets(STDIN));
}

/**
 * @return string
 */
function getStr() {
    return (string) trim(fgets(STDIN));
}

/**
 * @return array
 */
function getRow($len) {
    return array_slice(explode(' ', trim(fgets(STDIN))), 0, $len);
}

const N = "\n";

/*** SOLVING */

$n = getInt();
$count = 0;

for ($i = 0; $i < $n; $i++) {
    $point = array_reduce(getRow(3), function($sum, $v) {
        return $sum += $v;
    });
    if ($point >= 2) {
        $count++;
    }
}

echo $count;

<?php
$countTask = 0;
$count = trim(fgets(STDIN));
$data = array();
for ($i=0;$i<$count;$i++){
    $data[$i] = explode(" ", trim(fgets(STDIN)));
    $col[$i] = 0;
    foreach ($data[$i] as $o[$i]) {
        if ($o[$i]) {
            $col[$i]++;
        }
    }
    if ($col[$i]>=2) {
        $countTask++;
    }
}
echo $countTask;

<?php
	$n=fgets(STDIN);
	$cnt=0;
	for($i=1;$i<=$n;$i++)
	{
		list($a,$b,$c)=explode(' ',fgets(STDIN));
		if($a+$b+$c>=2)
			$cnt++;
	}
	echo $cnt;
?>

<?php
  //$file = fopen("/home/py/PHPtraing/input.txt", "r");
  $file = STDIN;
  $n = (int) fgets($file);
  $ans = 0;
  for ($i=0; $i < $n; $i++) {
  	$a = explode(" ", fgets($file));
  	$num = array_sum($a);
  	if ($num>1)
  		$ans++;
  }

  print $ans;

 fclose($file);

?>

<?php

$f = fopen("php://stdin", 'r');
$n = intval(trim(fgets($f)));

$result = 0;

for ($j = 0; $j < $n; $j++) {
    $arr = fscanf($f, "%d %d %d");
    if ($arr[0] + $arr[1] + $arr[2] > 1) $result++;
}

fclose($f);

print $result;

<?php
$n = trim(fgets(STDIN));
$pro = [];
for ($i = 0; $i<$n ; $i++){
	$input = fgets(STDIN);
	array_push($pro, $input);
}
$res = 0;
for ($i = 0; $i<$n ; $i++){
	$inputs = explode(' ',$pro[$i]);
	$sum = $inputs[0] + $inputs[1] + $inputs[2];
	if($sum > 1){
		$res++;
	}

}
echo $res;

?>

<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
fscanf($_fp,"%d",$problem);

$solved = 0;
$i = 0;

while (!feof($_fp) AND $i < $problem) {
    $solution[$i] = fgets($_fp);
    $i += 1;
}

for ($i=0; $i < $problem; $i++)
{
    $arr_solution = str_split($solution[$i]);
    $count_solution = 0;

    for ($j=0; $j < 5; $j += 2)
    {
        if($arr_solution[$j] > 0)
        {
            $count_solution += 1;
        }
    }
    if($count_solution > 1)
    {
        $solved += 1;
    }
}
echo $solved;

?>

<?php

function gaber( $n1 , $n2 , $n3 )
{
     if( $n1 == 1 && $n2 == 1)
     {
          return 1 ;
     }
     if( $n1 == 1 && $n3==1)
     {
          return 1 ;
     }
     if( $n2 == 1 && $n3==1)
     {
          return 1 ;
     }
     return 0 ;
}

$stdout = fopen( getenv( "OUTPUT_PATH" ) , "w" ) ;
$stdin = fopen( "php://stdin" , "r" ) ;

fscanf( $stdin , "%d" , $n) ;

$result = 0 ;

for( $i=0 ; $i<$n ; $i++ )
{
     fscanf( $stdin , "%d %d %d" , $n1 , $n2 , $n3 ) ;
     $result += intval( gaber( $n1 , $n2 , $n3 ) ) ;
}

echo $result ;

//$arr = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY) );
fwrite ( $stdout , $result . "\n" ) ;

fclose( $stdin ) ;
fclose( $stdout ) ;

?>

<?php

fscanf(STDIN, "%d\n", $n);

$problems = 0;

$i = 0;
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d %d\n", $petya, $vasya, $tonya);

    if (($petya + $vasya + $tonya) >= 2) {
        $problems++;
    }
}

echo $problems;

?>

<?php

fscanf(STDIN, "%d\n", $number);

if ($number <= 0){
    exit;
}
$sRes = array();
for ($i = 0; $i <= 8; $i++){
    $sRes[decbin($i)] = 0;
}

while($number > 0){
    $number--;
    $line = trim(fgets(STDIN));
    $line = str_replace(' ', '', $line);

    $line = (int)$line;

    $sRes[$line]++;
}

print($sRes[11] + $sRes[110] + $sRes[101] + $sRes[111]);

<?php
// https://codeforces.com/problemset/problem/231/A
$n = fgets(STDIN);
$out = 0;
for($i = 0; $i < $n; ++$i) {
	fscanf(STDIN, "%d%d%d", $p, $v, $t);
	if($p+$v+$t > 1) ++$out;
}
echo $out;

<?php

$input = trim(fgets(STDIN));
$numberOfInputs = (int)$input;
$result = 0;

for ($count = 0; $count < $numberOfInputs; $count++) {
    $string = trim(fgets(STDIN));
    list($a, $b, $c) = explode(" ", $string);
    if (((int)$a + (int)$b + (int)$c) > 1)
        $result++;
}
printf("%s\n", $result);

<?php
$total = 0;
$hitung = 0;
$n = trim(fgets(STDIN));
while($n--)
{
    $s = fgets(STDIN);
    $s = explode(' ', $s);
    if (array_sum($s) > 1)
        $total++;
}
print $total;

?>

<?php
    $f = fopen('php://stdin', 'r');
    $cnt = (int)fgets($f);
    $ount = 0;
    for ($i = 0; $i < $cnt; $i++) {
        $out+= array_sum(explode(" ", str_replace(["\r", "\n"], "", fgets($f)))) > 1 ? 1 : 0;
    }
    echo $out;
?>

<?php
/**
 * Created by IntelliJ IDEA.
 * User: 低调的程序员
 * Date: 2015/4/25
 * Time: 1:17
 */

while(fscanf(STDIN,"%d",$n)){
    $ans=0;
    while($n-->0){
        fscanf(STDIN,"%d%d%d",$p,$v,$t);
        if(($p+$v+$t)>1)$ans++;
    }
    fprintf(STDOUT,"%d\n",$ans);
}

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The First Line Of Code.
$n = explode("\n",$input)[0];

$sum = array();

$count = 0;

//Get The Rest Of The Inputs.
//Calculate Each Line Sum.
for($i = 0;$i < $n;$i++) {

    array_push($sum,0);

    for($ii = 0;$ii < 3;$ii++) {

        $inner_input = explode("\n",$input)[$i + 1];

        $sum[$i] += explode(" ",$inner_input)[$ii];

    }

    //Check If More Than Two Are Sure About The Answer.
    if($sum[$i] > 1) {

        $count++;

    }

}

//Return The Output.
echo $count;

?>

<?php
$n=trim(fgets(STDIN));
$hasil=0;
$i=0;
while ($i<$n) {
	$a=explode(" ",fgets(STDIN));
	if(array_sum($a)>=2)
		$hasil=$hasil+1;
	$i++;
}
echo $hasil;
?>

<?php
$n=trim(fgets(STDIN));
$hasil=0;
$i=0;
while ($i<$n) {
	$a=explode(" ",fgets(STDIN));
	/*if(array_sum($a)>=2)*/
	if($a[0]+$a[1]+$a[2] >= 2)
		$hasil=$hasil+1;
	$i++;
}
echo $hasil;
?>

<?php
// 231A Команда

$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$out = 0;

for ($i=1; $i <= $n; $i++) {

    $input_line = fgets($in);

    list($p, $v, $t) = split(" ", $input_line);
    //    $t = substr($t, 0, 1);
    $p = (int) $p;
    $v = (int) $v;
    $t = (int) $t;

    if (($p + $v + $t) > 1) $out++;
}

echo $out;

?>

<?php
    $in = 'php://stdin';
    //$in = 'input.txt';
    $input = fopen($in, "r");
    $n = trim(fgets($input));

    $c = 0;
    for ($j=0;$j<$n;$j++) {
        $task = array_count_values(explode(' ',trim(fgets($input))));
        if ($task[1]>1) $c++;
    }
    echo $c;
?>

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d', $n);

        $count = 0;
        while ($n--) {
            fscanf(STDIN, '%d %d %d', $a, $b, $c);
            $count+=$a + $b + $c >= 2;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?php
while($str = fgets(STDIN)){
	$array[] = explode(' ', trim($str));
}
if(!isset($array)) {
	$array[] = explode(' ', '2 4');
}
$out = 0;
for($i=1; $i<sizeof($array); $i++) {
	$sum = $array[$i][0] + $array[$i][1] + $array[$i][2];
	if($sum>1) {
		$out++;
	}
}
echo $out;
?>

<?php
$n = trim(fgets(STDIN));
$total= 0 ;
for ($i=0; $i<$n; $i++) {

$ar = explode (" ",trim (fgets (STDIN)));

if (array_sum ( $ar )>1 ) { $total++;}
}
echo $total;

?>

<?php

/**
 * @author Pablo Digiani <p.digiani@gmail.com>
 * @link https://codeforces.com/problemset/problem/231/A
 * @version 1.0
 *
 *
 *
 */

$problems = readline();

$implementations = 0;
for ($n = 1; $n <= $problems; $n++){
	if(array_sum(explode(' ', readline())) >= 2) $implementations++;
}
echo $implementations;

<?php

$fp=fopen('php://stdin','r');

$cpt=0;
$cptFound=0;
while(($line = fgets($fp)) !== false) {
    if($cpt>0){
        $line=explode(' ',$line);
        $cpt1=0;
        foreach($line as $l){
            if($l==1) $cpt1++;
        }
        if($cpt1>=2) $cptFound++;
    }
    $cpt++;
}
echo $cptFound;

<?php

$fp=fopen('php://stdin','r');

$first=true;
$cptFound=0;
while(($line = fgets($fp)) !== false) {
    if(!$first){
        $line=explode(' ',$line);
        $cpt1=0;
        foreach($line as $l){
            if($l==1) $cpt1++;
        }
        if($cpt1>=2) $cptFound++;
    }
    $first=false;
}
echo $cptFound;

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('5.txt', 'r');
$a = explode(" ",trim(fgets($f)));
$a = (int)$a[0];
$ans = 0;
while($a--){
    $och = trim(fgets($f));
    $int = explode(" ", $och);
    $total = 0;
    foreach ($int as $item){
        $total += (int)$item;
    }
    if($total >= 2){
        $ans++;
    }
}

echo $ans;

<?php
fscanf(STDIN,'%d', $n);
$count = 1;
$out = 0;
while($count++ <= $n){
    $counter = 0;
    list($f, $s, $th) = explode(' ', fgets(STDIN));
    if($f == 1){
        $counter++;
    }
    if($s == 1){
         $counter++;
    }
    if($th == 1){
         $counter++;
    }
    if($counter >= 2){
        $out++;
    }
}
echo $out;

<?php

$inputString = fgets(STDIN);

$n = (int) $inputString;

$answer = 0;
for ($i = 1; $i <= $n; $i++) {
    $inputString = fgets(STDIN);
    $opinions    = explode(' ', $inputString);

    $knowAnswer = 0;
    foreach ($opinions as $opinion) {
        if (rtrim($opinion) == '1') {
            $knowAnswer++;
        }
    }

    if ($knowAnswer > 1) {
        $answer++;
    }
}

echo $answer . PHP_EOL;

<?php
fscanf(STDIN, '%d\n', $n);	// получаем цифру - количество будущих строк
$line = array();
$strings = array();			// массив всех строчек
$result = array();

$m = array();  		// массив цифер в каждой строчке - вложенный массив

for($i = 0; $i < $n; $i++) {	// считываем n строк
	$strings[$i] = fgets(STDIN);	// теперь $strings - двумерный массив строк
	}

	for($i = 0; $i < count($strings); $i++) {
		$strings[$i] = explode(' ', $strings[$i]);		// расфигачиваем каждую строку на отдельнцые кусочки-цифры
		if(array_sum($strings[$i]) > 1){		// если сумма строки >= 2  -
			array_push($result, $strings[$i]);		// добавляем ее в массив результата
		}
	}

printf(count($result));

<?php
fscanf(STDIN, '%d', $n);

$solutionCount = 0;
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d %d', $a, $b, $c);
    if ($a + $b + $c >= 2) $solutionCount++;
}

echo $solutionCount;

<?php
function team($n){

echo $n;
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
$r=0;
for($i=0;$i<$n;$i++){
fscanf($stdin,"%d %d %d",$a,$b,$c);
if ($a + $b + $c >= 2)
        $r++;
}
team($r);
?>

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $tasks = array();
    $cnt = 0;
    while(!feof($fp))
        $tasks[] = explode(' ', rtrim(fgets($fp)));
    for($i = 0; $i < $n; $i++)
        if(array_sum($tasks[$i]) >= 2)
            $cnt++;
    echo $cnt;
?>

<?php
    function readFiles ($dir) {
        return file($dir, FILE_IGNORE_NEW_LINES);
    }
    $dir = 'php://stdin';
    $data = readFiles($dir);
    $n = $data[0];
    for ($i = 1; $i < count($data); $i++) {
        $data[$i] = explode(' ', $data[$i]);
    }
    $counter = 0;
    for ($i = 1; $i < count($data); $i++) {
        if (2 <= (int)array_count_values($data[$i])['1']) {
            $counter++;
        }
    }
    echo $counter;

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$val = substr_count(fgets(STDIN),'1');
		if ($val > 1) $total++;
	}
	echo $total;
?>

<?php
while($str = fgets(STDIN)) $arr[] = explode(' ', trim($str));
if(!isset($arr)) {
    $arr[] = explode(' ', '2 4');
}
$out = 0;
for($i=1; $i<sizeof($arr); $i++) {
    $sum = $arr[$i][0] + $arr[$i][1] + $arr[$i][2];
    if($sum>=2) $out++;
}
echo $out;
?>

<?php

fscanf(STDIN, "%d", $n);
$ans = 0;
for($i=0; $i<$n; $i++){
    $in = explode(' ', trim(fgets(STDIN)));
    $ans += (array_sum($in) >=2) ? 1 : 0;
}
printf("%d",$ans);
?>

<?php
$input = STDIN;
$output = STDOUT;

fscanf($input,"%d",$n);
$solvedProblems = 0;
for($i=0; $i<$n; ++$i) {
    fscanf($input,"%d%d%d",$Petya,$Vasya,$Tonya);
    $count = $Petya + $Vasya + $Tonya;
    if($count >= 2) {
        ++$solvedProblems;
    }
}
fprintf($output,"%d",$solvedProblems);

?>

<?php
fscanf(STDIN,"%d",$n);
$a=array();
$ans=0;
foreach (range(1,$n) as $i)
{
    fscanf(STDIN,"%d%d%d",$x,$y,$z);
    if ($x+$y+$z>=2) $ans++;
}
fprintf(STDOUT,"%d\n",$ans);
?>

<?php

# https://codeforces.com/contest/231/problem/A
# A. Team
# sample input =>
//3
//1 1 0
//1 1 1
//1 0 0
# sample output => 2
# scihesham

    $tests_num = trim(fgets(STDIN));
    $sum = 0;

    for($i=0; $i<$tests_num; $i++){
       list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
       $a + $b + $c > 1 ? $sum+=1 : '';
    }
    echo $sum;

?>

<?php

$result = 0;
$n = readline();

for ( $i = 0; $i < $n; $i++ ) {
	list($p, $v, $t) = explode(' ', readline());
	if ( $p + $v + $t >= 2 ) {
		$result++;
	}
}
echo $result;

<?php

$n = readline();
$p = 0;
while ($n > 0) {
    $inputs = (explode(" ",readline()));
    if(array_sum($inputs) >= 2){
        $p += 1;
    }
    $n--;
}

echo $p;

?>

<?

$num = (int)trim(fgets(STDIN));

$result = 0;
for($i = 0; $i < $num; $i ++) {
    if(array_sum(explode(' ', trim(fgets(STDIN)))) >= 2){
        $result++;
    }
}

echo $result;

<?php
$a = trim(fgets(STDIN));
for($c=0; $c<$a; ++$c)
{
    $b[$c] = trim(fgets(STDIN));
    $e = explode(" ", $b[$c]);
    if(array_sum($e)>=2)
    {$d += 1;}
}
echo $d;
?>

<?php

function read() {
    fscanf(STDIN, "%d", $n);
    $arr = array();
    for ($i = 0; $i < $n; $i++) {
        $numbers = explode(" ", fgets(STDIN));
        $arr[] = $numbers;
    }
}

function isValid($numbers) {

    $result = array_sum($numbers);
    return $result >= 2;
}

$arr = read();
$filtered = array_filter($arr, "isValid");

echo count($filtered);

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = explode(" ", trim(fgets(STDIN)));
}
$result = 0;
foreach ($a as $task) {
	if (($task[0] && $task[1]) || ($task[1] && $task[2]) || ($task[0] && $task[1]))
		$result++;
}

fprintf(STDOUT, $result);

<?php
while($item = trim(fgets(STDIN))){
    $data[] = (int)str_replace(' ', '', $item);
}

$result = 0;
$count = array_shift($data);

foreach($data as $res) {
    if($res === 101 || $res === 11 || $res === 110) {
        $result++;
    }
}

echo $result;

<?php
while($item = trim(fgets(STDIN))){
    $data[] = (int)str_replace(' ', '', $item);
}

$result = 0;
$count = array_shift($data);

foreach($data as $res) {
    if($res > 101 || $res === 11) {
        $result++;
    }
}

echo $result;

<?php
$n = (fgets(STDIN));
$summSolution=0;
for ($i=0;$i<$n;$i++)
{
    $peopleVote = explode(" ",fgets($resource));
    if (($peopleVote[0]+$peopleVote[1]+$peopleVote[2])>=2)
    {
        $summSolution++;
    }
}
echo $summSolution;
?>

<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
fscanf($_fp,"%d",$problem);

$solved = 0;

for ($i=0; $i < $problem; $i++)
{
    fscanf($_fp,"%s",$solution[$i]);

    $arr_solution = str_split($solution[$i]);

    $count_solution = 0;

    for ($j=0; $j < 5; $j += 2)
    {
        if($solution[$i][$j] > 0)
        {
            $count_solution += 1;
        }
    }
    if($count_solution > 1)
    {
        $solved += 1;
    }
    echo "\n";
}

echo $solved;
?>

<?php

$input = trim(fgets(STDIN));
$numberOfInputs = (int)$input;
$result = 0;

for ($count = 0; $count < $numberOfInputs; $count++) {
    $string = trim(fgets(STDIN));
    list($a, $b, $c) = explode(" ", $string);
    if (((int)$a + (int)$b + (int)$c) > 1)
        $result++;
}
foreach ($resultArray as $result) {
    printf("%s\n", $result);
}

<?php
$total = 0;
$hitung = 0;
fscanf(STDIN, "%d", $n);
while($n--)
{
    fscanf(STDIN, "%s", $s);
    $s = explode(' ', $s);
    foreach ($s as $arr){
        if ($arr == '1')
            $hitung++;
    }
    if ($hitung > 1)
        $total++;
    $hitung = 0;
}
print $total;

?>

<?php
$total = 0;
$hitung = 0;
fscanf(STDIN, "%d", $n);
while($n--)
{
    fscanf(STDIN, "%s", $s);
    print $s;
    $s = explode(' ', $s);
    foreach ($s as $arr){
        if ($arr == 1)
            $hitung++;
    }
    if ($hitung > 1)
        $total++;
    $hitung = 0;
}
print $total;

?>

<?php
$total = 0;
$hitung = 0;
fscanf(STDIN, "%d", $n);
while($n--)
{
    fscanf(STDIN, "%s", $s);
    $s = explode(' ', $s);
    foreach ($s as $arr){
        if ($arr == 1)
            $hitung++;
    }
    if ($hitung > 1)
        $total++;
    $hitung = 0;
}
print $total;

?>

<?php
fscanf(STDIN, "%d", $n);
while($n--)
{
    $total = 0;
    $hitung = 0;
    fscanf(STDIN, "%s", $s);
    $s = explode(' ', $s);
    foreach ($s as $arr){
        if ($arr == 1)
            $hitung++;
    }
    if ($hitung > 1)
        $total++;
    $hitung = 0;
}
print $total;

?>

<?php
$n=trim(fgets(STDIN));
$hasil=0;
$i=0;
while ($i<$n) {
	$a=explode(" ",fgets(STDIN));
	if(array_sum($a))
		$hasil=$hasil+1;
	$i++;
}
echo $hasil;
?>

<?php
$n=trim(fgets(STDIN));
$hasil=0;
$i=0;
while ($i<$n) {
	$a=explode(" ",fgets(STDIN));
	/*if(array_sum($a)>=2)*/
	if($a[0]+$a[1]+a[2] >= 2)
		$hasil=$hasil+1;
	$i++;
}
echo $hasil;
?>

<?php
while($str = fgets(STDIN)){
	$array[] = explode(' ', trim($str));
}
if(!isset($array)) {
	$array[] = explode(' ', '2 4');
}
$out = 0;
for($i=1; $i<sizeof($array); $i++) {
	$sum = $array[$i][0] + $array[i][1] + $array[$i][2];
	if($sum>1) {
		$out++;
	}
}
echo $out;
?>

<?php
$n = trim(fgets(STDIN));
for ($i=0; $i<$n; $i++) {

$ar = explode (" ",trim (fgets (STDIN)));

if (array_sum ( $ar )>1 ) { $total++;}
}
echo $total;

?>

<?php

$fp=fopen('php://stdin','r');

$first=true;
$cptFound=0;
while(($line = fgets($fp)) !== false) {
    if(!$first){
        $first=false;
        $line=explode(' ',$line);
        $cpt1=0;
        foreach($line as $l){
            if($l==1) $cpt1++;
        }
        if($cpt1>=2) $cptFound++;
    }
}
echo $cptFound;

<?php

//$f = fopen('php://stdin', 'r');
$f = fopen('5.txt', 'r');
$a = explode(" ",trim(fgets($f)));
$a = (int)$a[0];
$ans = 0;
while($a--){
    $och = trim(fgets($f));
    $int = explode(" ", $och);
    $total = 0;
    foreach ($int as $item){
        $total += (int)$item;
    }
    if($total >= 2){
        $ans++;
    }
}

echo $ans;

<?php

$inputString = fgets(STDIN);

$n = (int) $inputString[0];

$answer = 0;
for ($i = 1; $i <= $n; $i++) {
    $inputString = fgets(STDIN);
    $opinions    = explode(' ', $inputString);

    $knowAnswer = 0;
    foreach ($opinions as $opinion) {
        if (rtrim($opinion) == 1) {
            $knowAnswer++;
        }
    }

    if ($knowAnswer > 1) {
        $answer++;
    }
}

echo $answer . PHP_EOL;

<?php
function team($n,$in){
for($i=0;$i<$n;$i++){
    for($j=0;$j<3;$j++){
        echo $in[$j]." ";
    }
    echo PHP_EOL;
}
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
$in=array();
for($j=0;$j<3;$j++){
    fscanf($stdin,"%b",$in);
}
team($n,$in);
?>

<?php
function team($n){
$in=array();
$stdin = fopen("php://stdin","r");
for($i=0;$i<$n;$i++){
for($j=0;$j<3;$j++){
    fscanf($stdin,"%d",$in[$j]);
}
}
for($i=0;$i<$n;$i++){
    for($j=0;$j<3;$j++){
        echo $in[$j]." ";
    }
    echo PHP_EOL;
}
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);

team($n);
?>

<?php
function team($n){
    $r=0;
for($i=0;$i<$n;$i++){
    fscanf($stdin,"%d %d %d",$a, $b, $c);
    if ($a + $b + $c >= 2)
         $r++;
    }
echo $r;
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
team($n);
?>

<?php
function team($n,$in){
for($i=0;$i<$n;$i++){
    for($j=0;$j<3;$j++){
        echo $in[$j]." ";
    }
    echo PHP_EOL;
}
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
$in=array();
for($j=0;$j<3;$j++){
    fscanf($stdin,"%d",$in);
}
team($n,$in);
?>

<?php
function team($n){
    $r=0;
for($i=0;$i<$n;$i++){
    fscanf($stdin,"%d%d%d",$a,$b,$c);
    if ($a + $b + $c >= 2)
         $r++;
        break;
    }
echo $r;
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
team($n);
?>

<?php
    function readFiles ($dir) {
        return file($dir, FILE_IGNORE_NEW_LINES);
    }
    $dir = 'php://stdin';
    $data = readFiles($dir);
    $n = $data[0];
    for ($i = 1; $i < count($data); $i++) {
        $data[$i] = explode(' ', $data[$i]);
    }
    $counter = 0;
    for ($i = 1; $i < count($data); $i++) {
        if (2 >= array_count_values($data[$i])[1]) {
            $counter++;
        }
    }
    echo $counter;


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.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
array_unshift($d, " ");
unset($d[0]);
$e = 0;
if($b == $c)
{
    print "0";
}
else
{
    for($x = 1; $x <= $a; $x++)
    {
        $b = $d[$b];
        if($b == $c)
        {
            $e = 1;
            break;
        }
    }
    if($e == 0)
    {
        print "-1";
    }
    else
    {
        print $x;
    }
}
?>


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.


Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

The first line of the output contains a single integer k — maximum possible number of primes in representation. The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.

<?php
$a = trim(fgets(STDIN));
$b = $a % 2;
if($b == 0)
{
     $c = $a / 2;
     $d = array_fill(0, $c, 2);
     print count($d) . "\n";
     print implode(" ", $d);
}
else
{
     $a -= 3;
     $c = $a / 2;
     $d = array_fill(0, $c, 2);
     array_unshift($d, 3);
     print count($d) . "\n";
     print implode(" ", $d);
}
?>

<?php
$num = (int) trim(fgets(STDIN));
$add = 0;
if ($num%2 == 0) {
    $count = $num/2;
} else {
    $count = ($num-3)/2;
    $add = 1;
}
echo $count + $add . "\n";
for ($i = 0; $i < $count; $i++) {
    echo '2 ';
}
if ($add) {
    echo '3';
}

<?php

fscanf(STDIN, '%s', $n);

fprintf(STDOUT, "%d\n", intval($n / 2));

for ($i = 0; $i + $i < $n - 3; $i++) {
    if ($i) {
        fprintf(STDOUT, ' ');
    }

    fprintf(STDOUT, '2');
}

if ($n > 3) {
    fprintf(STDOUT, ' ');
}

fprintf(STDOUT, "%d\n", 2 + $n % 2);

<?php

fscanf(STDIN, '%d', $n);

echo intval($n / 2) . PHP_EOL;

for ($k = 0; $k < $n; $k += 2) {
    if ($k) {
        echo ' ';
    }

    if ($n - $k == 3) {
        echo 3;
        break;
    }

    echo 2;
}

echo PHP_EOL;

<?php

fscanf(STDIN, '%s', $n);

for ($i = 0; $i + $i < $n - 3; $i++) {
    if ($i) {
        fprintf(STDOUT, ' ');
    }

    fprintf(STDOUT, '2');
}

if ($n > 3) {
    fprintf(STDOUT, ' ');
}

fprintf(STDOUT, "%d\n", 2 + $n % 2);

<?php

fscanf(STDIN, '%d', $n);

for ($k = 0; $k < $n; $k += 2) {
    if ($k) {
        echo ' ';
    }

    if ($n - $k == 3) {
        echo 3;
        break;
    }

    echo 2;
}

echo PHP_EOL;


Santa has to send presents to the kids. He has a large stack of $$$n$$$ presents, numbered from $$$1$$$ to $$$n$$$; the topmost present has number $$$a_1$$$, the next present is $$$a_2$$$, and so on; the bottom present has number $$$a_n$$$. All numbers are distinct.Santa has a list of $$$m$$$ distinct presents he has to send: $$$b_1$$$, $$$b_2$$$, ..., $$$b_m$$$. He will send them in the order they appear in the list.To send a present, Santa has to find it in the stack by removing all presents above it, taking this present and returning all removed presents on top of the stack. So, if there are $$$k$$$ presents above the present Santa wants to send, it takes him $$$2k + 1$$$ seconds to do it. Fortunately, Santa can speed the whole process up — when he returns the presents to the stack, he may reorder them as he wishes (only those which were above the present he wanted to take; the presents below cannot be affected in any way).What is the minimum time required to send all of the presents, provided that Santa knows the whole list of presents he has to send and reorders the presents optimally? Santa cannot change the order of presents or interact with the stack of presents in any other way.Your program has to answer $$$t$$$ different test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow, each represented by three lines. The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 10^5$$$) — the number of presents in the stack and the number of presents Santa wants to send, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le n$$$, all $$$a_i$$$ are unique) — the order of presents in the stack. The third line contains $$$m$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_m$$$ ($$$1 \le b_i \le n$$$, all $$$b_i$$$ are unique) — the ordered list of presents Santa has to send. The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the minimum number of seconds which Santa has to spend sending presents, if he reorders the presents optimally each time he returns them into the stack.


Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:  She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .  Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.  The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

NotePlease note that the answers to the questions may overflow 32-bit integer type.


Given an array $$$a$$$ of length $$$n$$$, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.A sequence $$$b$$$ is a subsequence of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deleting some (possibly zero) elements.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

If there's a subsequence of $$$a$$$ whose product isn't a perfect square, print "YES". Otherwise, print "NO".

NoteIn the first example, the product of the whole array ($$$20$$$) isn't a perfect square.In the second example, all subsequences have a perfect square product.

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
        $x = sqrt($a[$i]);
        if (strpos((string)$x, '.') !== false) {
            $bool = true;
            break;
        }
    }
    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));
for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $a = explode(" ", trim(fgets($file)));

  $r = 0;
  for ($j = 0; $j < $n; $j++) {
    $ans1 = sqrt($a[$j]);
    $v1 = round($ans1);
    if ($ans1 != $v1) { $r = 1; break; }
  }

  if ($r == 1) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }
}
?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

$t = IO::str();

while ($t--) {
    $n = IO::str();
    $arr = IO::arr();
    $a = true;
    foreach ($arr as $ar) {
        $num = sqrt($ar);
//        echo $num; exit;
        if (strpos($num, '.')) {
            $res[] = 'YES';
            $a = false;
            break;
        }
    }
    if ($a) {
        $res[] = 'NO';
    }
}

foreach ($res as $r) {
    echo $r . "\n";
}

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
        $x = sqrt($a[$i]);
        if (strpos((string)$x, '.') !== false) {
            $bool = true;
            break;
        }
        $x = -1;
        for ($j = $i + 1; $j < $n; $j++) {
            if ($i == $j) {
                continue;
            }
            $z = $a[$i] * $a[$j];
            if ($x == -1) {
                $x = $a[$i] * $a[$j];
            } else {
                $x = $x * $a[$j];
            }
            $y = sqrt($x);
            $zy = sqrt($z);
            if (strpos((string)$y, '.') !== false || strpos((string)$zy, '.') !== false) {
                $bool = true;
                break;
            }
        }
        if ($bool) {
            break;
        }
    }

    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
        $x = sqrt($a[$i]);
        if ((int)$x != $x) {
            $bool = true;
            break;
        }
        $x = -1;
        for ($j = 0; $j < $n; $j++) {
            if ($i == $j) {
                continue;
            }
            $z = $a[$i] * $a[$j];
            if ($x == -1) {
                $x = $a[$i] * $a[$j];
            } else {
                $x = $x * $a[$j];
            }
            $y = sqrt($x);
            $zy = sqrt($z);
            if ((int)$y != $y || (int)$zy != $zy) {
                $bool = true;
                break;
            }
        }
        if ($bool) {
            break;
        }
    }

    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
//        $x = sqrt($a[$i]);
//        if ((int)$x != $x) {
//            $bool = true;
//            break;
//        }
        $x = -1;
        for ($j = 0; $j < $n; $j++) {
            if ($i == $j) {
                continue;
            }
            $z = $a[$i] * $a[$j];
            if ($x == -1) {
                $x = $a[$i] * $a[$j];
            } else {
                $x = $x * $a[$j];
            }
            $y = sqrt($x);
            $zy = sqrt($z);
            if ((int)$y != $y || (int)$zy != $zy) {
                $bool = true;
                break;
            }
        }
        if ($bool) {
            break;
        }
    }

    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
        $x = sqrt($a[$i]);
        if ((int)$x != $x) {
            $bool = true;
            break;
        }
        $x = -1;
        for ($j = 0; $j < $n; $j++) {
            if ($i == $j) {
                continue;
            }
            if ($x == -1) {
                $x = $a[$i] * $a[$j];
            } else {
                $x = $x * $a[$j];
            }
            $y = sqrt($x);
            if ((int)$y != $y) {
                $bool = true;
                break;
            }
        }
        if ($bool) {
            break;
        }
    }

    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;

$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $bool = false;
    for ($i = 0; $i < $n; $i++) {
        $x = sqrt($a[$i]);
        if ((int)$x != $x) {
            $bool = true;
            break;
        }
        $x = -1;
        for ($j = 0; $j < $n; $j++) {
            if ($i == $j) {
                continue;
            }
            if ($x == -1) {
                $x = $a[$i] * $a[$j];
            } else {
                $x = $x * $a[$j];
            }
            if ((int)$x != $x) {
                $bool = true;
                break;
            }
        }
        if ($bool) {
            break;
        }
    }

    if ($bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>


Let's call a positive integer composite if it has at least one divisor other than $$$1$$$ and itself. For example:  the following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$;  the following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$. You are given a positive integer $$$n$$$. Find two composite integers $$$a,b$$$ such that $$$a-b=n$$$.It can be proven that solution always exists.

The input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^7$$$): the given integer.

Print two composite integers $$$a,b$$$ ($$$2 \leq a, b \leq 10^9, a-b=n$$$). It can be proven, that solution always exists. If there are several possible solutions, you can print any.


Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $$$a=[1, 3, 3, 7]$$$ is good because there is the element $$$a_4=7$$$ which equals to the sum $$$1 + 3 + 3$$$.You are given an array $$$a$$$ consisting of $$$n$$$ integers. Your task is to print all indices $$$j$$$ of this array such that after removing the $$$j$$$-th element from the array it will be good (let's call such indices nice).For example, if $$$a=[8, 3, 5, 2]$$$, the nice indices are $$$1$$$ and $$$4$$$:   if you remove $$$a_1$$$, the array will look like $$$[3, 5, 2]$$$ and it is good;  if you remove $$$a_4$$$, the array will look like $$$[8, 3, 5]$$$ and it is good. You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the array $$$a$$$.

In the first line print one integer $$$k$$$ — the number of indices $$$j$$$ of the array $$$a$$$ such that after removing the $$$j$$$-th element from the array it will be good (i.e. print the number of the nice indices). In the second line print $$$k$$$ distinct integers $$$j_1, j_2, \dots, j_k$$$ in any order — nice indices of the array $$$a$$$. If there are no such indices in the array $$$a$$$, just print $$$0$$$ in the first line and leave the second line empty or do not print it at all.

NoteIn the first example you can remove any element with the value $$$2$$$ so the array will look like $$$[5, 1, 2, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 1 + 2 + 2$$$).In the second example you can remove $$$8$$$ so the array will look like $$$[3, 5, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 3 + 2$$$). You can also remove $$$2$$$ so the array will look like $$$[8, 3, 5]$$$. The sum of this array is $$$16$$$ and there is an element equals to the sum of remaining elements ($$$8 = 3 + 5$$$).In the third example you cannot make the given array good by removing exactly one element.

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfFloat($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (float)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n, 1);

$s = 0.0;
$m = 0;
for ($i=1; $i<=$n; $i++) {
	$ai = $a[$i];
	if (!isset($b[$ai])) {
		$b[$ai] = [];
	}

	$b[$ai][] = $i;

	if ($m < $ai) {
		$m = $ai;
	}
	$s += $ai;
}

$items = [];

// delete max element
for ($i=1; $i<=$n; $i++) {
	$ind = ($s - $a[$i])/2;
	if (intval($ind) == $ind) {
		if (isset($b[$ind]) && !($ind==$a[$i] && count($b[$ind])==1)) {
			$items[] = $i;
		}
	}
}

echo count($items) . "\n";
echo implode(' ', $items);


There is a toy building consisting of $$$n$$$ towers. Each tower consists of several cubes standing on each other. The $$$i$$$-th tower consists of $$$h_i$$$ cubes, so it has height $$$h_i$$$.Let's define operation slice on some height $$$H$$$ as following: for each tower $$$i$$$, if its height is greater than $$$H$$$, then remove some top cubes to make tower's height equal to $$$H$$$. Cost of one "slice" equals to the total number of removed cubes from all towers.Let's name slice as good one if its cost is lower or equal to $$$k$$$ ($$$k \ge n$$$).  Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$n \le k \le 10^9$$$) — the number of towers and the restriction on slices, respectively. The second line contains $$$n$$$ space separated integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 2 \cdot 10^5$$$) — the initial heights of towers.

Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth.

NoteIn the first example it's optimal to make $$$2$$$ slices. The first slice is on height $$$2$$$ (its cost is $$$3$$$), and the second one is on height $$$1$$$ (its cost is $$$4$$$).

<?php
fscanf(STDIN,"%d %d",$n,$k);
$height = fgets(STDIN);
$height = explode(' ',$height);
$height_count = array();
$minn = 2e5 + 100;
$maxx = 0;
for($i = 0;$i < $n;$i++)
{
    $height[$i] = intval($height[$i]);
    $minn = min($minn,$height[$i]);
    $maxx = max($maxx,$height[$i]);
}
$maxx -= $minn;
for($i = 0;$i < $n;$i++)
{
    $height[$i] -= $minn;
    if(!isset($height_count[$height[$i]])) {
        $height_count[$height[$i]] = 1;
    } else $height_count[$height[$i]]++;
}
for($i = $maxx-1;$i >= 1;$i--)
{
    if(!isset($height_count[$i])) {
        $height_count[$i] = $height_count[$i+1];
    } else {
        $height_count[$i] += $height_count[$i+1];
    }
}
for($i = $maxx-1;$i >= 1;$i--)
{
    $height_count[$i] += $height_count[$i+1];
}
$cnt = 0;
$height_count[$maxx + 1] = 0;
$up = $maxx + 1;
$low = $maxx;
while($up > 1)
{
    while($low >= 1&&$height_count[$low] - $height_count[$up] <= $k)
    {
        $low--;
    }
    $cnt++;
    $up = $low + 1;
}
echo $cnt."\n";


A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practice.Applying the simplest variant of median smoothing to the sequence of numbers a1, a2, ..., an will result a new sequence b1, b2, ..., bn obtained by the following algorithm:  b1 = a1, bn = an, that is, the first and the last number of the new sequence match the corresponding numbers of the original sequence.  For i = 2, ..., n - 1 value bi is equal to the median of three values ai - 1, ai and ai + 1. The median of a set of three numbers is the number that goes on the second place, when these three numbers are written in the non-decreasing order. For example, the median of the set 5, 1, 2 is number 2, and the median of set 1, 0, 1 is equal to 1.In order to make the task easier, Vasya decided to apply the method to sequences consisting of zeros and ones only.Having made the procedure once, Vasya looked at the resulting sequence and thought: what if I apply the algorithm to it once again, and then apply it to the next result, and so on? Vasya tried a couple of examples and found out that after some number of median smoothing algorithm applications the sequence can stop changing. We say that the sequence is stable, if it does not change when the median smoothing is applied to it.Now Vasya wonders, whether the sequence always eventually becomes stable. He asks you to write a program that, given a sequence of zeros and ones, will determine whether it ever becomes stable. Moreover, if it ever becomes stable, then you should determine what will it look like and how many times one needs to apply the median smoothing algorithm to initial sequence in order to obtain a stable one.

The first input line of the input contains a single integer n (3 ≤ n ≤ 500 000) — the length of the initial sequence. The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 1), giving the initial sequence itself.

If the sequence will never become stable, print a single number  - 1. Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print n numbers separated by a space  — the resulting sequence itself.

NoteIn the second sample the stabilization occurs in two steps: , and the sequence 00000 is obviously stable.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
$aArray[-1] = $aArray[0];
$aArray[$n] = $aArray[$n - 1];
$rArray = array();
$temp = 0;
$max = 0;
for ($i = 0; $i < $n; $i++) {
    if ($aArray[$i] == $aArray[$i - 1] || $aArray[$i] == $aArray[$i + 1]) {
        $rArray[$i] = $aArray[$i];
        if ($temp % 2) {
            for ($j = $i - 1; $j >= $i - $temp; $j--) {
                $rArray[$j] = $rArray[$i];
            }
            $max = max($max, ($temp + 1) / 2);
        } else {
            for ($j = $i - 1; $j >= $i - $temp / 2; $j--) {
                $rArray[$j] = $aArray[$i];
            }
            for ($j = $i - $temp; $j < $i - $temp / 2; $j++) {
                $rArray[$j] = $aArray[$i - $temp - 1];
            }
            $max = max($max, $temp / 2);
        }
        $temp = 0;
    } else {
        $temp++;
    }
}

echo $max . PHP_EOL;
echo $aArray[0].' ';
for ($i = 1; $i < $n - 1; $i++) {
    echo $rArray[$i] . ' ';
}
echo $aArray[$n-1];


Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).Implement this feature to help Polycarp test his editor.

The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.

Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.

<?php
function init(&$h,&$w){
    $pic = array();
    for ($i=0; $i<$h; $i++){
        $line = trim(fgets(STDIN));
        $pic[$i] = array();
        for ($j=0; $j<$w; $j++){
            $pic[$i][$j] = $line[$j];
        }
    }
    return $pic;
}
function pic_gen($h,$w){
    $pic = array();
    for ($i=0; $i<$h; $i++)
        $pic[$i] = array();
    return $pic;
}

function draw(&$input_pic,&$h,&$w){
    for ($i=0; $i<$h; $i++){
        for ($j=0; $j<$w; $j++){
            printf("%s",$input_pic[$i][$j]);
        }
        printf("\n");
    }
}

function rotate(&$input_pic,&$h,&$w){
    $pic_rotate = pic_gen($w,$h);
    for ($i=0; $i<$w; $i++)
        for ($j=$h-1; $j>=0; $j--)
            $pic_rotate[$i][($h-1)-$j]=$input_pic[$j][$i];
    list($h,$w) = array($w,$h);
    $input_pic = $pic_rotate;
}

function div($int,$divider){
    return (($int-($int%$divider))/$divider);
}

function reflect(&$input_pic,&$h,&$w){
    $pic_reflect = pic_gen($h,$w);
    for ($i=0; $i<$h; $i++)
        for ($j=0; $j<$w; $j++)
            $pic_reflect[$i][$j]=$input_pic[$i][($w-1)-$j];
    $input_pic = $pic_reflect;
}
function zoom(&$input_pic,&$h,&$w){
    list($h,$w) = array(2*$h,2*$w);
    $pic_zoom = pic_gen($h,$w);
    for ($i=0; $i<$h; $i++)
        for ($j=0; $j<$w; $j++)
            $pic_zoom[$i][$j]=$input_pic[div($i,2)][div($j,2)];
    $input_pic = $pic_zoom;
}

list($w,$h) = explode(" ",trim(fgets(STDIN)));
$pic = init($h,$w);
rotate($pic,$h,$w);
reflect($pic,$h,$w);
zoom($pic,$h,$w);
draw($pic,$h,$w);

<?php

    $FINP = STDIN;

    $tmp = explode( ' ', fgets($FINP));

    $w = (int)$tmp[0]; $h = (int)$tmp[1];

    $newImg = array_fill( 0, 2*$w, array_fill( 0, 2*$h, '.' ) );

    for($i=0;$i<$h;$i++){
        $str = fgets($FINP);
        for($j=0;$j<$w;$j++){
            if( $str[$j] == '.' ) continue;
            $newY = 2*$i;
            $newX = 2*$j;
            $newImg[$newX][$newY] = $newImg[$newX][$newY+1] = $newImg[$newX+1][$newY] = $newImg[$newX+1][$newY+1] = '*';
        }
    }

    for( $i=0;$i<2*$w;$i++ ){
        print implode('',$newImg[$i]) . "\n";
    }

<?php
list($width, $height) = explode(' ', fgets(STDIN));
for ($row = 0; $row < $height; $row++) {
	$line[$row] = fgets(STDIN);
}
for ($col = 0; $col < $width; $col++) {
	$flag = 0;
	while ($flag < 2) {
		for ($row = 0; $row < $height; $row++) {
			echo $line[$row][$col], $line[$row][$col];
		}
		echo "\n";
		$flag++;
	};
}
?>

<?php

$exp = explode(' ', fgets(STDIN));

$w = $exp[0];
$h = $exp[1];

unset($exp);

$lines = array();

for($i = 0; $i < $h; $i++){
    $exp = str_split(fgets(STDIN));

    $z = 0;
    for($j = 0; $j < $w; $j++){
        if(!isset($lines[$z])){
            $lines[$z] = array();
            $lines[$z+1] = array();
        }
        array_unshift($lines[$z], $exp[$j], $exp[$j]);
        array_unshift($lines[$z+1], $exp[$j], $exp[$j]);
        $z += 2;
    }
}

$last = $w*2;
for($i = 0; $i < $last; $i++){
    echo implode('', array_reverse($lines[$i]));
    if($i != $last) echo "\n";
}

<?php
function init(&$h,&$w){
	$pic = array();
	for ($i=0; $i<$h; $i++){
		$line = trim(fgets(STDIN));
		$pic[$i] = array();
		for ($j=0; $j<$w; $j++){
			$pic[$i][$j] = $line[$j];
		}
	}
	return $pic;
}

function draw(&$input_pic,&$h,&$w){
	for ($i=0; $i<$h; $i++){
		for ($j=0; $j<$w; $j++){
			printf("%s",$input_pic[$i][$j]);
		}
		printf("\n");
	}
}

function rotate(&$input_pic,&$h,&$w){
	$pic_rotate = array();
	for ($i=0; $i<$w; $i++)
		$pic_rotate[$i] = array();

	for ($i=0; $i<$w; $i++)
		for ($j=$h-1; $j>=0; $j--)
			$pic_rotate[$i][($h-1)-$j]=$input_pic[$j][$i];
	list($h,$w) = array($w,$h);
	$input_pic = $pic_rotate;
}

function div($int,$divider){
	return (($int-($int%$divider))/$divider);
}

function reflect(&$input_pic,&$h,&$w){
	$pic_reflect = array();
	for ($i=0; $i<$h; $i++)
		$pic_reflect[$i] = array();
	for ($i=0; $i<$h; $i++)
		for ($j=0; $j<$w; $j++)
			$pic_reflect[$i][$j]=$input_pic[$i][($w-1)-$j];
	$input_pic = $pic_reflect;
}
function zoom(&$input_pic,&$h,&$w){
	list($h,$w) = array(2*$h,2*$w);
	$pic_zoom = array();
	for ($i=0; $i<$h; $i++)
		$pic_zoom[$i] = array();
	for ($i=0; $i<$h; $i++)
		for ($j=0; $j<$w; $j++)
			$pic_zoom[$i][$j]=$input_pic[div($i,2)][div($j,2)];
	$input_pic = $pic_zoom;
}

list($w,$h) = explode(" ",trim(fgets(STDIN)));
$pic = init($h,$w);
rotate($pic,$h,$w);
reflect($pic,$h,$w);
zoom($pic,$h,$w);
//printf("%dx%d\n",$h,$w);
draw($pic,$h,$w);

<?php
list($w,$h) = explode(' ',rtrim(fgets(STDIN)));
$matrixStart = array();
for($i = 0; $i < $h; $i++){
    $string = rtrim(fgets(STDIN));
    for($j = 0; $j < $w; $j++){
        $matrixStart[$i][$j] = $string[$j];
    }
}
for ($i = 0; $i < $w; $i++)
{
    $str= '';
    for($j = 0; $j < $h; $j++){
        $str .= $matrixStart[$j][$i].$matrixStart[$j][$i];
    }
    echo $str."\n".$str."\n";
}
?>


Let's denote a function You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.

Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.

NoteIn the first example:  d(a1, a2) = 0;  d(a1, a3) = 2;  d(a1, a4) = 0;  d(a1, a5) = 2;  d(a2, a3) = 0;  d(a2, a4) = 0;  d(a2, a5) = 0;  d(a3, a4) =  - 2;  d(a3, a5) = 0;  d(a4, a5) = 2.

<?php
error_reporting(E_ERROR | E_PARSE);
$maxx = array();
$cntmap = array();
$cnt = 0;
$ansmap = array();
$ans = 0;

$n = fgets(STDIN);
$a = explode(' ', trim(fgets(STDIN)));

for($i=0; $i < $n; $i++){
	$cntmap[$a[$i]] = 0;
	$cntmap[$a[$i]+1] = 0;
	$cntmap[$a[$i]-1] = 0;
	$maxx[$a[$i]]++;
	if(!isset($maxx[$a[$i]-1]))$maxx[$a[$i]-1] = 0;
	if(!isset($maxx[$a[$i]+1]))$maxx[$a[$i]+1] = 0;
}

$total = 0;
$poslijeMene = 0;
for($i=0; $i < $n; $i++){
	$total = ($cnt - $cntmap[$a[$i]] - $cntmap[$a[$i]-1] - $cntmap[$a[$i]+1]);
	$poslijeMene = $n - 1 - $cnt;
	$total = $total - ($poslijeMene - ($maxx[$a[$i]] - 1 - $cntmap[$a[$i]]) - ($maxx[$a[$i]-1] - $cntmap[$a[$i]-1]) - ($maxx[$a[$i]+1] - $cntmap[$a[$i]+1]) );
	$ansmap[$a[$i]] += $total;
	$cnt++;
	$cntmap[$a[$i]]++;
}

$ans = "0";
foreach ($ansmap as $key => $value) {
	$ans = bcadd($ans, bcmul($key, $value));
}

echo $ans;
?>

<?php
error_reporting(E_ERROR | E_PARSE);
$maxx = array();
$cntmap = array();
$cnt = 0;
$ansmap = array();
$ans = 0;

$n = fgets(STDIN);
$a = explode(' ', trim(fgets(STDIN)));

for($i=0; $i < $n; $i++){
	$cntmap[$a[$i]] = 0;
	$cntmap[$a[$i]+1] = 0;
	$cntmap[$a[$i]-1] = 0;
	$maxx[$a[$i]]++;
	if(!isset($maxx[$a[$i]-1]))$maxx[$a[$i]-1] = 0;
	if(!isset($maxx[$a[$i]+1]))$maxx[$a[$i]+1] = 0;
}

$total = 0;
$poslijeMene = 0;
for($i=0; $i < $n; $i++){
	$total = ($cnt - $cntmap[$a[$i]] - $cntmap[$a[$i]-1] - $cntmap[$a[$i]+1]);
	$poslijeMene = $n - 1 - $cnt;
	$total = $total - ($poslijeMene - ($maxx[$a[$i]] - 1 - $cntmap[$a[$i]]) - ($maxx[$a[$i]-1] - $cntmap[$a[$i]-1]) - ($maxx[$a[$i]+1] - $cntmap[$a[$i]+1]) );
	$ansmap[$a[$i]] += $total;
	$cnt++;
	$cntmap[$a[$i]]++;
}

$ans = "0";
foreach ($ansmap as $key => $value) {
	$ans = bcadd($ans, $key * $value);
}

echo $ans;
?>


There is a string $$$s$$$ of length $$$3$$$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of testcases. The description of each test consists of one line containing one string $$$s$$$ consisting of three characters. Each character of $$$s$$$ is either an uppercase or lowercase English letter.

For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

10

YES

yES

yes

Yes

YeS

Noo

orZ

yEz

Yas

XES

NoteThe first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of these are equal to "YES", where each character is either uppercase or lowercase.

<?php

fscanf(STDIN, "%d", $t);
for($i=1; $i<=$t; $i++)
{
	fscanf(STDIN, "%s", $inputString);
	$inputString = strtoupper($inputString);
	if($inputString == 'YES'){
		printf("YES \n");
	}else{
		print("NO \n");
	}
}

?>

<?php

    $rowLength = (int) fgets(STDIN);
    for ($i = 0; $i < $rowLength; $i++) {
        $yes = trim(fgets(STDIN));
        if (strcasecmp('yes', $yes) === 0) {
            echo('YES'.PHP_EOL);
        } else {
            echo('NO'.PHP_EOL);
        }
    }

<?php

$cnt = readline();
$res = array();
while ($cnt--) {
    $s = readline();

    if (strtolower($s) == 'yes') {
        $res[] = 'YES';
    } else {
        $res[] = 'NO';
    }
}

foreach ($res as $ss) {
    echo $ss . "\n";
}

<?php $t = (int)readline();
for ($i = 0; $i < $t; $i++) {
    $s = strtoupper(readline());
    if ($s == "YES") {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
} ?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = strtolower(trim(fgets(STDIN)));
     if($b == "yes")
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

<?php

$n = readline();
while($n--)
{
	$s = readline();
	$s = strtolower($s);
	if($s == 'yes')
		echo "YES\n";
	else
		echo "NO\n";
}

<?php
$n = ReadLine();
for ($i = 0; $i < $n; $i++) {
    $s = (string) ReadLine();
    $s = strtoupper($s);
    if ($s == "YES") {
        echo "YES\n";
    }else {
        echo "NO\n";
    }
}

<?php

$t = readline();
$t = intval($t);

$i = 0;
$inputs = [];

while($i++ < $t) {
    array_push($inputs, readline());
}

foreach($inputs as $in) {
    if(strtoupper(trim($in)) === "YES") {
        echo "YES" . PHP_EOL;
    } else {
        echo "NO" . PHP_EOL;
    }
}

<?php
$test_case  = readline('test case: ');
for($i=0;$i<$test_case;$i++){
	$str  = readline('string: ');
	if($str) {
		$str = strtoupper($str);
	}
	if($str == 'YES') {
		echo "YES\n";
	} else {
		echo "NO\n";
	}
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%s", $s);
    printf("%s\n", ['no', 'yes']['yes' == strtolower($s)]);
}

<?php

function read() {
	return trim(fgets(STDIN)) ;
}

function readInt() {
	return (int) read() ;
}

function readStrs() {
	return explode(" ",read()) ;
}

function readIntArray() {
	return array_map('intval', readStrs());
}

function readAsArray() {
	return str_split(read()) ;
}

function printLine($arg) {
	// if($arg) print_r("true");
	// elseif(!$arg) print_r("false");
	// else {
		print_r($arg) ;
	// }
	print_r("\n") ;
}

$t = readInt() ;

while($t--) {
	$inp = read() ;
	if(strtolower($inp) === "yes") {
		// printLine(strtolower($inp));
		printLine("YES") ;
	}
	else {
		printLine("NO") ;
	}
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
    $s = IO::get();
    $sNew = strtoupper($s);
    $ans = $sNew == 'YES' ? 'YES' : 'NO';
    IO::pr($ans);

}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php

fscanf(STDIN, "%d", $t);
for($i=1; $i<=$t; $i++)
{
	fscanf(STDIN, "%s", $inputString);
	$inputString = strtoupper($inputString);
	if($inputString == 'YES'){
		printf("YES");
	}else{
		print("NO");
	}
}

?>

<?php

fscanf(STDIN, "%d", $t);
for($i=1; $i<=$t; $i++)
{
	fscanf(STDIN, "%s", $inputString);
	$inputString = strtoupper($inputString);
	if($inputString == 'YES'){
		printf("Yes");
	}else{
		print("No");
	}
}

?>

		<form name="form1" id="form1" method = "POST">
			Test Cases : <input type = "text" name = "testCase" id="testCase" value="" />

			Input String : <input type = "text" name = "inputString" id = "inputString" />

			<input type = "button" name = "save" value = "save" onclick = "validation()" />
			<input type = "button" name = "reset" value = "reset" onclick = "resetForm()" />
			<?php
			echo "

 Your result will be Displyed here";
			?>

		</form>

<?php

    $rowLength = (int) fgets(STDIN);
    for ($i = 0; $i < $rowLength; $i++) {
        $yes = fgets(STDIN);
        if (strcasecmp('yes', $yes)) {
            echo('YES'.PHP_EOL);
        } else {
            echo('NO'.PHP_EOL);
        }
    }

<?php

$cnt = readline();

while ($cnt--) {
    $s = readline();

    if (strtolower($s) == 'yes') {
        echo 'YES';
    } else {
        echo 'NO';
    }
}


An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.


Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Print a single integer — the number of k-good numbers in a.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = range(0, $b);
$g = 0;
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = str_split($c);
    $f = array_intersect($e, $d);
    if(count($f) >= count($e))
    {
        $g++;
    }
}
print $g;
?>

<?php
function has ($a, $k) {
    // printf ("%d %d %d\n", $a, $k, $a % 10);
    if ($a < 10) return (int) $a == (int) $k;
    return ((int) $a % 10 == (int) $k) || has ($a / 10, $k);
}

function is_good ($a, $k) {
    for ($i = 0; $i <= $k; $i++) {
        if (!has ($a, $i)) return false;
    }
    return true;
}

fscanf(STDIN, "%d %d", $n, $k);
$tot = 0;
for ($i = 0; $i < $n; $i++) {
    fscanf (STDIN, "%d", $a);
    if (is_good($a, $k)) $tot++;
}
printf ("%d\n", $tot);
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$n=$input[0][0];
$k=$input[0][1];
unset($input[0]);
for ($i=0; $i<=$k;$i++) {
    $arrk[]=$i;
}
$res=0;
for ($i=1;$i<=$n;$i++) {
    $input[$i]=array_unique(str_split($input[$i]));
    sort($input[$i]);
    if (array_intersect($input[$i],$arrk)== $arrk) $res++;
}
echo $res;
?>

<?php
error_reporting("off");
//365A: Good Number
//Lesson of the day: If you're nesting a for loop inside a for loop, you cannot use the same loop counter variable name. The compiler will be extremely unhappy.
//$array = array("1", "10");
list($n, $k) = explode(" ", trim(fgets(STDIN))); //$n = 2; $k = 1;
$kgood = 0;
for ($i = 0; $i < $n; $i++) {
    $hasdigits = TRUE;
    $line = trim(fgets(STDIN)); //$line = $array[$i];
    $explode = str_split($line);
    for ($j = 0; $j <= $k; $j++) {
        if (!in_array($j, $explode)) {
            $hasdigits = FALSE;
            break;
        }
    }
    if ($hasdigits == TRUE) {
        $kgood++;
    }
}

echo $kgood;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = range(0, $b);
$g = 0;
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = str_split($c);
    $f = array_intersect($d, $e);
    if(count($f) >= count($e))
    {
        $g++;
    }
}
print $g;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = range(0, $b);
$g = 0;
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = str_split($c);
    $f = array_intersect($d, $e);
    if(count($f) <= count($e))
    {
        $g++;
    }
}
print $g;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = range(0, $b);
$g = 0;
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = str_split($c);
    $f = array_intersect($d, $e);
    if(count($f) == count($e))
    {
        $g++;
    }
}
print $g;
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$n=$input[0][0];
$k=$input[0][1];
unset($input[0]);
for ($i=0; $i<=$k;$i++) {
    $arrk[]=$i;
}
$res=0;
for ($i=1;$i<=$n;$i++) {
    $input[$i]=array_unique(str_split($input[$i]));
    sort($input[$i]);
    if ($input[$i] == $arrk) $res++;
}
echo $res;
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$n=$input[0][0];
$k=$input[0][1];
unset($input[0]);
for ($i=0; $i<=$k;$i++) {
	$arrk[]=$i;
}
foreach ($input as $item) {
	str_split($item);
	if (!array_diff($item,$arrk)) $res++;
}
echo $res;
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$k=$input[0][1];
unset($input[0]);
$res=0;
for ($i=0; $i<=$k;$i++) {
    $arrk[]=$i;
}
foreach ($input as $item) {
    $item=str_split($item);
    if ($item==$arrk) $res++;
}
echo $res;
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$n=$input[0][0];
$k=$input[0][1];
unset($input[0]);
for ($i=0; $i<=$k;$i++) {
	$arrk[]=$i;
}
foreach ($input as $item) {
	str_split($item);
	if (!array_diff($item,$arrk)) $i++;
}
echo $i;
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$input[0]=explode(" ", $input[0]);
$n=$input[0][0];
$k=$input[0][1];
unset($input[0]);
for ($i=0; $i<=$k;$i++) {
    $arrk[]=$i;
}
foreach ($input as $item) {
    str_split($item);
    if (!array_diff($item,$arrk)) $res++;
}
echo $res-1;
?>


You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'  'y'  'x'  'b'  'a'  'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.

<?php

###### IO ######
error_reporting(E_ALL);
#error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$str = readString($f);
	$len = strlen($str);
	$min = false;
	for ($i = 0; $i < $len; $i++) {
		if ($str[$i] == 'a') {
			continue;
		}
		$replaceTo = false;
		for ($j = $i; $j < $len; $j++) {
			if ($str[$j] == 'a') {
				$replaceTo = $j;
				break;
			}
		}
		if ($replaceTo == false) {
			$replaceTo = $len;
		}
		$replace = substr($str, $i, $replaceTo - $i);
		$_len = strlen($replace);
		$_str = '';
		for ($k = 0; $k < $_len; $k++) {
			$c = ord($replace[$k]) - 1;
			if ($replace[$k] == 'a') {
				$c = ord('z');
			}
			$_str .= chr($c);
		}

		$min = substr($str, 0, $i) . $_str . substr($str, $replaceTo);
		break;
	}
	if ($min === false) {
		$min = $str;
		$min[strlen($min) - 1] = 'z';
	}
	echo $min;
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php

class Solution
{
    protected function solve($s)
    {
        $check = false;
        for ($i = 0; $i < strlen($s); $i++) {
            if ($s[$i] == 'a') {
                if ($check) {
                    return $s;
                }

                continue;
            }

            $s[$i] = chr(ord($s[$i])-1);
            $check = true;
        }

        if (!$check) {
            $s[strlen($s) - 1] = 'z';
        }

        return $s;
    }

    public function run()
    {
        $s = trim(fgets(STDIN));
        echo $this->solve($s) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

<?php

class Solution
{
    protected function solve($s)
    {
        $len = strlen($s);
        $was = false;
        for ($i = 0; $i < $len; $i++) {
            if ($s[$i] == 'a') {
                if ($was) {
                    return $s;
                }

                continue;
            }

            $was = true;
            $s[$i] = chr(ord($s[$i]) - 1);
        }

        if (!$was) {
            $s[$len-1] = 'z';
        }

        return $s;
    }

    public function run()
    {
        $s = trim(fgets(STDIN));

        echo $this->solve($s) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

<?php

class Solution
{
    protected function solve($s)
    {
        $len = strlen($s);
        $was = false;
        for ($i = 0; $i < $len; $i++) {
            if ($s[$i] == 'a') {
                if ($was) {
                    return $s;
                }

                continue;
            }

            $was = true;
            $s[$i] = chr(ord($s[$i]) - 1);
        }

        return $s;
    }

    public function run()
    {
        fscanf(STDIN, '%s', $s);

        echo $this->solve($s) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

<?php

class Solution
{
    protected function solve($s)
    {
        $len = strlen($s);
        $was = false;
        for ($i = 0; $i < $len; $i++) {
            if ($s[$i] == 'a') {
                if ($was) {
                    return $s;
                }

                continue;
            }

            $was = true;
            $s[$i] = chr(ord($s[$i]) - 1);
        }

        return $s;
    }

    public function run()
    {
        $s = fgets(STDIN);

        echo $this->solve($s) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();