Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All n people who came to the barbecue sat in a circle (thus each person received a unique index bi from 0 to n - 1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the j-th turn was made by the person with index bi, then this person acted like that:  he pointed at the person with index (bi + 1) mod n either with an elbow or with a nod (x mod y is the remainder after dividing x by y);  if j ≥ 4 and the players who had turns number j - 1, j - 2, j - 3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;  the turn went to person number (bi + 1) mod n. The person who was pointed on the last turn did not make any actions.The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.You can assume that in any scenario, there is enough juice for everybody.

The first line contains a single integer n (4 ≤ n ≤ 2000) — the number of participants in the game. The second line describes the actual game: the i-th character of this line equals 'a', if the participant who moved i-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns.

Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.

NoteIn both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 193 Div 2 (Unofficial Participant) Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
$str = g(1);

$ct = 0;
for ($i = $n; $i < strlen($str); $i += $n) {
	if ((substr($str, $i-3, 1) == substr($str, $i-2, 1)) && (substr($str, $i-3, 1) == substr($str, $i-1, 1))) {$ct++;}
}
echo $ct;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    // $max_beer = (2000/$mod)-1;

    // if($beer_count > $max_beer)
    //     $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
        echo $participant_size%$mod;
    }

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    // if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
    // }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    if($beer_count>499)
        $beer_count=499;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($split_text[1], $participant_size-9,20));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($participant_size%$mod == 0 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $max_beer -= 1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3] && $beer_count!=0)
        $beer_count -= 1;

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(range($participant_size-9, $participant_size-1));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = $participant_size/$mod;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $max_beer -= 1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count > $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    // if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
    // }
    echo $participant_size%$mod;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $beer_count -= 1;

    echo $beer_count;

<?php
	$input = "4
abbba";
    // $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0')-1;
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i%$mod];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else
    		$valid_flag=0;

    	if($i%$mod == ($mod-1) && $valid_flag==1)
    		$beer_count++;
    	$prev_sign=$string[$i%$mod];
    }
    echo $beer_count;

<?php
// 	$input = "4
// abbaabbba";
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');
    // var_dump($mod);
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else{
    		if($i%$mod != 1){
    			$valid_flag=0;
    			while(($i%$mod) != $mod-1)
    				$i++;
    		}
    	}

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}

    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count > $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
        echo $participant_size%$mod;
    }

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;
    if($beer_count==398){
        var_dump($participant_size);
        var_dump(range($participant_size-9, $participant_size-1));
    }
    // echo $beer_count;

<?php
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0')-1;
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i%$mod];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else
    		$valid_flag=0;

    	if($i%$mod == ($mod-1) && $valid_flag==1)
    		$beer_count++;
    	$prev_sign=$string[$i%$mod];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    // if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
    //     $max_beer -= 1;

    if($beer_count == 398){
        var_dump($participant_size);
        var_dump($string);
    }

    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    if($participant_size>2000)
        $participant_size=2000;
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    if($participant_size/$mod>500)
        $participant_size=500*$mod;
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = ($participant_size/$mod)-1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($split_text[1], $participant_size-9,20));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($string, $participant_size-9,20));
    }
    echo $beer_count;


There is a binary string $$$a$$$ of length $$$n$$$. In one operation, you can select any prefix of $$$a$$$ with an equal number of $$$0$$$ and $$$1$$$ symbols. Then all symbols in the prefix are inverted: each $$$0$$$ becomes $$$1$$$ and each $$$1$$$ becomes $$$0$$$.For example, suppose $$$a=0111010000$$$.   In the first operation, we can select the prefix of length $$$8$$$ since it has four $$$0$$$'s and four $$$1$$$'s: $$$[01110100]00\to [10001011]00$$$.  In the second operation, we can select the prefix of length $$$2$$$ since it has one $$$0$$$ and one $$$1$$$: $$$[10]00101100\to [01]00101100$$$.  It is illegal to select the prefix of length $$$4$$$ for the third operation, because it has three $$$0$$$'s and one $$$1$$$. Can you transform the string $$$a$$$ into the string $$$b$$$ using some finite number of operations (possibly, none)?

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 3\cdot 10^5$$$) — the length of the strings $$$a$$$ and $$$b$$$. The following two lines contain strings $$$a$$$ and $$$b$$$ of length $$$n$$$, consisting of symbols $$$0$$$ and $$$1$$$. The sum of $$$n$$$ across all test cases does not exceed $$$3\cdot 10^5$$$.

For each test case, output "YES" if it is possible to transform $$$a$$$ into $$$b$$$, or "NO" if it is impossible. You can print each letter in any case (upper or lower).

NoteThe first test case is shown in the statement.In the second test case, we transform $$$a$$$ into $$$b$$$ by using zero operations.In the third test case, there is no legal operation, so it is impossible to transform $$$a$$$ into $$$b$$$.In the fourth test case, here is one such transformation:   Select the length $$$2$$$ prefix to get $$$100101010101$$$.  Select the length $$$12$$$ prefix to get $$$011010101010$$$.  Select the length $$$8$$$ prefix to get $$$100101011010$$$.  Select the length $$$4$$$ prefix to get $$$011001011010$$$.  Select the length $$$6$$$ prefix to get $$$100110011010$$$. In the fifth test case, the only legal operation is to transform $$$a$$$ into $$$111000$$$. From there, the only legal operation is to return to the string we started with, so we cannot transform $$$a$$$ into $$$b$$$.


Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).Inserting an element in the same position he was erased from is also considered moving.Can Vasya divide the array after choosing the right element to move and its new position?

The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.

Print YES if Vasya can divide the array after moving one element. Otherwise print NO.

NoteIn the first example Vasya can move the second element to the end of the array.In the second example no move can make the division possible.In the third example Vasya can move the fourth element by one position to the left.


You are playing a variation of game 2048. Initially you have a multiset $$$s$$$ of $$$n$$$ integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this multiset.During each operation you choose two equal integers from $$$s$$$, remove them from $$$s$$$ and insert the number equal to their sum into $$$s$$$.For example, if $$$s = \{1, 2, 1, 1, 4, 2, 2\}$$$ and you choose integers $$$2$$$ and $$$2$$$, then the multiset becomes $$$\{1, 1, 1, 4, 4, 2\}$$$.You win if the number $$$2048$$$ belongs to your multiset. For example, if $$$s = \{1024, 512, 512, 4\}$$$ you can win as follows: choose $$$512$$$ and $$$512$$$, your multiset turns into $$$\{1024, 1024, 4\}$$$. Then choose $$$1024$$$ and $$$1024$$$, your multiset turns into $$$\{2048, 4\}$$$ and you win.You have to determine if you can win this game.You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) – the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in multiset. The second line of each query contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$1 \le s_i \le 2^{29}$$$) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.

For each query print YES if it is possible to obtain the number $$$2048$$$ in your multiset, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

NoteIn the first query you can win as follows: choose $$$512$$$ and $$$512$$$, and $$$s$$$ turns into $$$\{1024, 64, 1024\}$$$. Then choose $$$1024$$$ and $$$1024$$$, and $$$s$$$ turns into $$$\{2048, 64\}$$$ and you win.In the second query $$$s$$$ contains $$$2048$$$ initially.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     for($y = 0; $y < $b; $y++)
     {
          if($c[$y] > 2048)
          {
               unset($c[$y]);
          }
     }
     $d = array_sum($c);
     if($d < 2048)
     {
          print "NO\n";
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
        ksort($arr_);
    }
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php

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

function solve() {
    global $__fp;
    $n = fgets($__fp);
    $s = array_map('intval', explode(' ', fgets($__fp)));
    $sum = 0;
    foreach ($s as $p) {
        if ($p == 2048) {
            echo 'YES'. PHP_EOL;
            return;
        } else if ($p < 2048) {
            $sum += $p;
        }
    }
    if ($sum >= 2048) {
        echo 'YES' . PHP_EOL;
    } else {
        echo 'NO' . PHP_EOL;
    }
    return;
}

$q = fgets($__fp);
for ($i = 0; $i < $q; $i++) {
    solve();
}

<?php
$q = (int)fgets(STDIN);
while ($q--) {
    $n = (int)fgets(STDIN);
    $a = array_map(function ($x) { return (int)$x; }, explode(' ', trim(fgets(STDIN))));
    $cnt = array();
    foreach ($a as $i)
        $cnt[$i] ++;

    for ($i = 1; $i < 2048; $i *= 2) {
        if (!array_key_exists($i, $cnt)) continue;
        $cnt[$i * 2] += (int)($cnt[$i] / 2);
    }
    if (array_key_exists(2048, $cnt) && $cnt[2048] > 0) printf("YES\n");
    else printf("NO\n");
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
    }
//    var_dump($arr_);
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
    }
    unset($arr_, $v, $c);
//    var_dump($arr_);
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
    }
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}


A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).Let $$$p$$$ be any permutation of length $$$n$$$. We define the fingerprint $$$F(p)$$$ of $$$p$$$ as the sorted array of sums of adjacent elements in $$$p$$$. More formally,$$$$$$F(p)=\mathrm{sort}([p_1+p_2,p_2+p_3,\ldots,p_{n-1}+p_n]).$$$$$$For example, if $$$n=4$$$ and $$$p=[1,4,2,3],$$$ then the fingerprint is given by $$$F(p)=\mathrm{sort}([1+4,4+2,2+3])=\mathrm{sort}([5,6,5])=[5,5,6]$$$.You are given a permutation $$$p$$$ of length $$$n$$$. Your task is to find a different permutation $$$p'$$$ with the same fingerprint. Two permutations $$$p$$$ and $$$p'$$$ are considered different if there is some index $$$i$$$ such that $$$p_i \ne p'_i$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 668$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 100$$$)  — the length of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1,\ldots,p_n$$$ ($$$1\le p_i\le n$$$). It is guaranteed that $$$p$$$ is a permutation.

For each test case, output $$$n$$$ integers $$$p'_1,\ldots, p'_n$$$ — a permutation such that $$$p'\ne p$$$ and $$$F(p')=F(p)$$$. We can prove that for every permutation satisfying the input constraints, a solution exists. If there are multiple solutions, you may output any.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / 2);
     $e = array_reverse(array_slice($c, 0, $d));
     $f = array_reverse(array_slice($c, $d));
     $g = array_merge($f, $e);
     print implode(" ", $g) . "\n";
}
?>


You are given an integer $$$n$$$.You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:   Replace $$$n$$$ with $$$\frac{n}{2}$$$ if $$$n$$$ is divisible by $$$2$$$;  Replace $$$n$$$ with $$$\frac{2n}{3}$$$ if $$$n$$$ is divisible by $$$3$$$;  Replace $$$n$$$ with $$$\frac{4n}{5}$$$ if $$$n$$$ is divisible by $$$5$$$. For example, you can replace $$$30$$$ with $$$15$$$ using the first operation, with $$$20$$$ using the second operation or with $$$24$$$ using the third operation.Your task is to find the minimum number of moves required to obtain $$$1$$$ from $$$n$$$ or say that it is impossible to do it.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of queries. The next $$$q$$$ lines contain the queries. For each query you are given the integer number $$$n$$$ ($$$1 \le n \le 10^{18}$$$).

Print the answer for each query on a new line. If it is impossible to obtain $$$1$$$ from $$$n$$$, print -1. Otherwise, print the minimum number of moves required to do it.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = 0;
     while(TRUE)
     {
          if($b == 1)
          {
               print $c . "\n";
               break;
          }
          else
          {
               if(bcmod($b, 2) == 0)
               {
                    $b = bcdiv($b, 2);
                    $c++;
               }
               elseif(bcmod(bcmul($b, 2), 3) == 0)
               {
                    $b = bcdiv(bcmul($b, 2), 3);
                    $c++;
               }
               elseif(bcmod(bcmul($b, 4), 5) == 0)
               {
                    $b = bcdiv(bcmul($b, 4), 5);
                    $c++;
               }
               else
               {
                    print "-1\n";
                    break;
               }
          }
     }
}
?>


Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.Упрощенно процесс фотографирования можно описать следующим образом. На фотографии каждый из друзей занимает прямоугольник из пикселей: в стоячем положении i-й из них занимает прямоугольник ширины wi пикселей и высоты hi пикселей. Но также, при фотографировании каждый человек может лечь, и тогда он будет занимать прямоугольник ширины hi пикселей и высоты wi пикселей.Общая фотография будет иметь размеры W × H, где W — суммарная ширина всех прямоугольников-людей, а H — максимальная из высот. Друзья хотят определить, какую минимальную площадь может иметь общая фотография. Помогите им в этом.

В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей. В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей.

Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей.


There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values:   how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?  how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$).

For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them.

NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop.

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $a = intval($in_str[0]) ;
        $b = intval($in_str[1]) ;
        $c = intval($in_str[2]) ;

        $ans = array(-1, -1) ;
        if($a < $c) $ans[0] = 1 ;
        if($a > $c / $b) $ans[1] = $b ;

        echo $ans[0] . " " . $ans[1] . "\n" ;
    }
?>


Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.

Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.

NoteIn the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.


A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $$$n$$$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again.Each round has the same scenario. It is described by a sequence of $$$n$$$ numbers: $$$d_1, d_2, \dots, d_n$$$ ($$$-10^6 \le d_i \le 10^6$$$). The $$$i$$$-th element means that monster's hp (hit points) changes by the value $$$d_i$$$ during the $$$i$$$-th minute of each round. Formally, if before the $$$i$$$-th minute of a round the monster's hp is $$$h$$$, then after the $$$i$$$-th minute it changes to $$$h := h + d_i$$$.The monster's initial hp is $$$H$$$. It means that before the battle the monster has $$$H$$$ hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to $$$0$$$. Print -1 if the battle continues infinitely.

The first line contains two integers $$$H$$$ and $$$n$$$ ($$$1 \le H \le 10^{12}$$$, $$$1 \le n \le 2\cdot10^5$$$). The second line contains the sequence of integers $$$d_1, d_2, \dots, d_n$$$ ($$$-10^6 \le d_i \le 10^6$$$), where $$$d_i$$$ is the value to change monster's hp in the $$$i$$$-th minute of a round.

Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer $$$k$$$ such that $$$k$$$ is the first minute after which the monster is dead.


Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set of n numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.

The first line contains a single integer n — the number of items (1 ≤ n ≤ 105). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.

Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.

NoteIn the first test the numeration is already a permutation, so there is no need to change anything.In the second test there are two pairs of equal numbers, in each pair you need to replace one number.In the third test you need to replace 2 by 1, as the numbering should start from one.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}
$c = 0;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = $unusedNumbers[$c];
        $c++;
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = $unusedNumbers[$c];
        $c++;
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}

for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = array_pop($unusedNumbers);
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = array_pop($unusedNumbers);
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();

for ($i=0; $i<$itemsNumber; $i++) {

    if ($eArray[$i]>$itemsNumber || isset($usedNumbers[$eArray[$i]])) {
        $eArray[$i] = 0;

    }else{
        $usedNumbers[$eArray[$i]] = 1;
    }
}
$c = 1;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i] == 0) {
        while (isset($usedNumbers[$c])) {
            $c++;
        }
        $usedNumbers[$c] = 1;
        $eArray[$i] = $c;
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}
$c = 0;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = array_pop($unusedNumbers);
        $c++;
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = array_pop($unusedNumbers);
        $c++;
    }
}
echo implode(" ", $eArray);


Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move. Help Anton and write the program that for the given position determines whether the white king is in check.Remainder, on how do chess pieces move:   Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.  Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.  Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces. The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king. Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.

NotePicture for the first sample:    White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES".Picture for the second sample:    Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".


Alice lives on a flat planet that can be modeled as a square grid of size $$$n \times n$$$, with rows and columns enumerated from $$$1$$$ to $$$n$$$. We represent the cell at the intersection of row $$$r$$$ and column $$$c$$$ with ordered pair $$$(r, c)$$$. Each cell in the grid is either land or water.  An example planet with $$$n = 5$$$. It also appears in the first sample test. Alice resides in land cell $$$(r_1, c_1)$$$. She wishes to travel to land cell $$$(r_2, c_2)$$$. At any moment, she may move to one of the cells adjacent to where she is—in one of the four directions (i.e., up, down, left, or right).Unfortunately, Alice cannot swim, and there is no viable transportation means other than by foot (i.e., she can walk only on land). As a result, Alice's trip may be impossible.To help Alice, you plan to create at most one tunnel between some two land cells. The tunnel will allow Alice to freely travel between the two endpoints. Indeed, creating a tunnel is a lot of effort: the cost of creating a tunnel between cells $$$(r_s, c_s)$$$ and $$$(r_t, c_t)$$$ is $$$(r_s-r_t)^2 + (c_s-c_t)^2$$$.For now, your task is to find the minimum possible cost of creating at most one tunnel so that Alice could travel from $$$(r_1, c_1)$$$ to $$$(r_2, c_2)$$$. If no tunnel needs to be created, the cost is $$$0$$$.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the width of the square grid. The second line contains two space-separated integers $$$r_1$$$ and $$$c_1$$$ ($$$1 \leq r_1, c_1 \leq n$$$) — denoting the cell where Alice resides. The third line contains two space-separated integers $$$r_2$$$ and $$$c_2$$$ ($$$1 \leq r_2, c_2 \leq n$$$) — denoting the cell to which Alice wishes to travel. Each of the following $$$n$$$ lines contains a string of $$$n$$$ characters. The $$$j$$$-th character of the $$$i$$$-th such line ($$$1 \leq i, j \leq n$$$) is 0 if $$$(i, j)$$$ is land or 1 if $$$(i, j)$$$ is water. It is guaranteed that $$$(r_1, c_1)$$$ and $$$(r_2, c_2)$$$ are land.

Print an integer that is the minimum possible cost of creating at most one tunnel so that Alice could travel from $$$(r_1, c_1)$$$ to $$$(r_2, c_2)$$$.

NoteIn the first sample, a tunnel between cells $$$(1, 4)$$$ and $$$(4, 5)$$$ should be created. The cost of doing so is $$$(1-4)^2 + (4-5)^2 = 10$$$, which is optimal. This way, Alice could walk from $$$(1, 1)$$$ to $$$(1, 4)$$$, use the tunnel from $$$(1, 4)$$$ to $$$(4, 5)$$$, and lastly walk from $$$(4, 5)$$$ to $$$(5, 5)$$$.In the second sample, clearly a tunnel between cells $$$(1, 3)$$$ and $$$(3, 1)$$$ needs to be created. The cost of doing so is $$$(1-3)^2 + (3-1)^2 = 8$$$.


Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:   +  ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.   -  ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.  ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.

The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform. Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.

For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.

NoteConsider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.   1 and 241.  361.  101 and 361.  361.  4000.


New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.Vasya's verse contains $$$n$$$ parts. It takes $$$a_i$$$ seconds to recite the $$$i$$$-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes $$$a_1$$$ seconds, secondly — the part which takes $$$a_2$$$ seconds, and so on. After reciting the verse, Vasya will get the number of presents equal to the number of parts he fully recited.Vasya can skip at most one part of the verse while reciting it (if he skips more than one part, then Santa will definitely notice it).Santa will listen to Vasya's verse for no more than $$$s$$$ seconds. For example, if $$$s = 10$$$, $$$a = [100, 9, 1, 1]$$$, and Vasya skips the first part of verse, then he gets two presents.Note that it is possible to recite the whole verse (if there is enough time). Determine which part Vasya needs to skip to obtain the maximum possible number of gifts. If Vasya shouldn't skip anything, print 0. If there are multiple answers, print any of them.You have to process $$$t$$$ test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 10^5, 1 \le s \le 10^9$$$) — the number of parts in the verse and the maximum number of seconds Santa will listen to Vasya, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the time it takes to recite each part of the verse. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the number of the part that Vasya needs to skip to obtain the maximum number of gifts. If Vasya shouldn't skip any parts, print 0.

NoteIn the first test case if Vasya skips the second part then he gets three gifts.In the second test case no matter what part of the verse Vasya skips.In the third test case Vasya can recite the whole verse.

<?php
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new Scanner();
$t = $sc->nextInt();
for($j = 0; $j < $t; $j++)
{
    $n = $sc->nextInt();
    $s = $sc->nextInt();
    $a = array();
    $sum = 0;
    $index = 0;
    $max = 0;
    $b = false;
    for($i = 0; $i < $n; $i++)
    {
        $a[$i] = $sc->nextInt();
        if($b) continue;
        $sum += $a[$i];
        //out::println($sum);
        if($max < $a[$i])
        {
            $max = $a[$i];
            $index = $i;
        }
        if($s < $sum)
        {
            $b = true;
           // break;
        }
    }
    if($b)
    {
        out::println($index + 1);
    }
    else
    {
        out::println("0");
    }
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for($j=0;$j<$t;$j++)
{
    $n=trim(fgets($handle));
    $n=explode(' ',$n);
    $arr=trim(fgets($handle));
    $arr=explode(' ',$arr);
    $id=0;$ans=$n[1];
        for($i=0;$i<$n[0];$i++) {
            if($arr[$i]>$arr[$id])
            {
                $id=$i;
            }
            $ans-=$arr[$i];

            if($ans<0)break;
        }
    if($ans>=0)
    {
        $id=-1;
    }
    echo ($id+1)."\n";
}

?>


Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you still program the robot army to do this reliably?The new questions are of the following form: a grayscale photograph has been divided into several horizontal pieces, which have been arbitrarily rearranged. The task is to assemble the original image back from these pieces (somewhat like in a jigsaw puzzle). To further delay the zombies, significant Gaussian-distributed noise has been added to the image.

The input format is the same as in the previous version, except that the first line of every question now contains three space-separated numbers h, w and k (1 ≤ h, w ≤ 600, 2 ≤ k ≤ 16) – the height (number of rows) and width (number of columns) of the photograph and the number of pieces, respectively. The number of pieces evenly divides the height, and each piece is of the same height h / k. Again, there is only one input file to be processed, and the same resources are provided to you as in the previous version (except that now you are given all input images in .bmp format, rather than the first 50).

Your program should print q lines. The i-th line should contain your answer for the i-th question: a space-separated sequence of k numbers π1, π2, ..., πk such that:    π is a permutation of {1, 2, ..., k}, that is, each number from 1 to k appears exactly once in π,  for each j = 1, ..., k, πj is the position (index), in the original image, of the piece which is at position j in the input image. (See the illustration below for clarity.)   The second image from the test set. If the three pieces in the original image are numbered 1, 2, 3 from top to bottom, then the numbering in the image on the right should be 2, 3, 1. The correct answer for this image is thus 2 3 1.  Again, your answers will be accepted if they conform to this format and if at least 75% of them are correct. Again, you may process the input locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).

NoteThe link to download all the necessary materials is http://assets.codeforces.com/files/690/medium_contestant_package.zip


It is the easy version of the problem. The only difference is that in this version $$$k = 3$$$.You are given a positive integer $$$n$$$. Find $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, such that:  $$$a_1 + a_2 + \ldots + a_k = n$$$  $$$LCM(a_1, a_2, \ldots, a_k) \le \frac{n}{2}$$$ Here $$$LCM$$$ is the least common multiple of numbers $$$a_1, a_2, \ldots, a_k$$$.We can show that for given constraints the answer always exists.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$  — the number of test cases. The only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 10^9$$$, $$$k = 3$$$).

For each test case print $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, for which all conditions are satisfied.

<?php
function gcd($a, $b) {
	return $b ? gcd($b, $a % $b) : $a;
}

function lcm($a, $b) {
	return $a*$b/gcd($a, $b);
}

function mlcm($a, $b, $c) {
	return lcm(lcm($a, $b), $c);
}

$t = trim(fgets(STDIN));

for ($o = 0; $o < $t; $o++) {
	list($n, $k) = explode(" ", trim(fgets(STDIN)));
	if ($n % 2 == 1) {
		$a = 1;
		$n--;
		$b = $c = floor(($n)/2);
	} else {
		if (floor($n/2) % 2 == 0) {
			$a = floor($n/2);
			$b = $c = floor($n/4);
		} else {
			$a = floor($n/2) - 1;
			$b = floor($n/2) - 1;
			$c = 2;
		}
	}
	print $a.' '.$b.' '.$c."\n";
}

?>

<?php
function gcd($a, $b) {
	return $b ? gcd($b, $a % $b) : $a;
}

function lcm($a, $b) {
	return $a*$b/gcd($a, $b);
}

function mlcm($a, $b, $c) {
	return lcm(lcm($a, $b), $c);
}

$t = trim(fgets(STDIN));

for ($o = 0; $o < $t; $o++) {
	list($n, $k) = explode(" ", trim(fgets(STDIN)));
	if ($n % 2 == 1) {
		$a = 1;
		$n--;
		$b = $c = floor(($n)/2);
	} else {
		if (floor($n/2) == 0) {
			$a = floor($n/2);
			$b = $c = floor($n/4);
		} else {
			$a = floor($n/2) - 1;
			$b = floor($n/2) - 1;
			$c = 2;
		}
	}
	print $a.' '.$b.' '.$c."\n";
}

?>

<?php
function gcd($a, $b) {
	return $b ? gcd($b, $a % $b) : $a;
}

function lcm($a, $b) {
	return $a*$b/gcd($a, $b);
}

function mlcm($a, $b, $c) {
	return lcm(lcm($a, $b), $c);
}

$t = trim(fgets(STDIN));

for ($o = 0; $o < $t; $o++) {
	list($n, $k) = explode(" ", trim(fgets(STDIN)));
	$a = 1;
	$n--;
	$b = floor(($n)/2);
	print $a.' '.$b.' '.$b."\n";
}

?>

<?php
function gcd($a, $b) {
	return $b ? gcd($b, $a % $b) : $a;
}

function lcm($a, $b) {
	return $a*$b/gcd($a, $b);
}

function mlcm($a, $b, $c) {
	return lcm(lcm($a, $b), $c);
}

$t = trim(fgets(STDIN));

for ($o = 0; $o < $t; $o++) {
	list($n, $k) = explode(" ", trim(fgets(STDIN)));
	$b = floor(($n-1)/2);
	$a = $n - 2*$b;
	print $a.' '.$b.' '.$b."\n";
}

?>


A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture.  For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.

We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).

Print n numbers. The i-th of them should be equal to ai.

<?php
class INPUT_HELP{
    public function read_array(){
        $a[0] = '';
        $j = 0;
        $input = fgets(STDIN);
        for ($i = 0; $i < strlen($input); $i++){
            if (preg_replace("/[0-9A-zА-я._-]/",null,$input[$i]) == false) {
                $a[$j] = $a[$j].$input[$i];
            } else {
                if ($a[$j] != '') {
                    ++$j;
                    $a[$j] = '';
                }
            }
        }
        return $a;
    }
    public function read_one(){
        $array = $this->read_array();
        return $array[0];
    }
}
?>
<?php
    $input_connect = new INPUT_HELP();
    $a = $input_connect->read_array();
    $n = $a[0];
    $k = $a[1];
    $t = $a[2];
    $sum = floor(($n * $k * $t) / 100);
    for ($i = 0; $i < $n; $i++){
        if ($sum == 0) echo '0 ';
        if ($sum < $k && $sum > 0) {
            echo $sum.' ';
            $sum = 0;
        };
        if ($sum >= $k) {
            echo $k.' ';
            $sum -= $k;
        }
    }
?>

<?php
fscanf(STDIN,'%d %d %d', $n, $k, $t);
$all=$n*$k;
$completed=floor($all*$t/100);
for($i=0;$i<$n;$i++){
    if($completed>0){
        $j=min($k,$completed);
        $completed-=$j;
        echo $j." ";
    } else echo "0 ";
}
?>


A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0, 0, 0, 1, 1, 1, 0, 0, 0] can be a photo of zebra, while the photo [0, 0, 0, 1, 1, 1, 1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the width of the photo. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 1) — the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white.

If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.

<?php
$fl =STDIN;
fscanf($fl, "%d\n", $n);
$numbers = explode(" ", trim(fgets($fl)));
$length=0;
$currentLength = 0;
$current = -1;
$zebra = true;
for($i=0;$i<$n;++$i)
{
    $a = $numbers[$i];

    if ($current === -1) {
        $current = $a;
    }

    if ($a === $current) {
        $currentLength += 1;
    } else {
        $current = $a;

        if ($length === 0) {
            $length = $currentLength;

        } else if ($length !== $currentLength) {
            $zebra = false;
            break;
        }

        $currentLength = 1;
    }
}

if ($length !== $currentLength && $length !== 0) {
    $zebra = false;
}

if ($zebra === true) {
    printf("YES");
} else {
    printf("NO");
}

?>

<?php

$fl =STDIN;

$prev = 2;
$line = -1;
$cur = 0;
$ans = 0;
list($n) = explode(" ", trim(fgets(STDIN)));
$arr = explode(" ", trim(fgets(STDIN)));
for($i=1;$i<=$n;++$i)
{
	$a = $arr[$i-1];
    #printf("%d\n", $a);
	if ($i == 1) {
	    $cur = 1;
	} else {
	    if ($a == $prev) {
	        $cur = $cur + 1;
	    } else {
	        if ($line == -1) {
	            $line = $cur;
	            $cur = 1;

	        } else {
	            if ($line == $cur) {
	                $cur = 1;
	            } else {
	                $ans = 1;
	            }
	        }
	    }
	}
    $prev = $a;
	#printf("%d %d\n", $ans, $cur);
}
if ($line == -1) {
	            $line = $cur;
	            $cur = 1;

	        } else {
	            if ($line == $cur) {
	                $cur = 1;
	            } else {
	                $ans = 1;
	            }
	        }
#printf("%d %d\n", $ans, $cur);
if ($ans == 0)
		printf("%s\n",'YES');
	else
		printf("%s\n",'NO');
?>

<?php
    fscanf(STDIN, "%d\n", $n); // читает число из STDIN
    $line = trim(fgets(STDIN)); // читает одну строку из STDIN
    $x = 1;
    $tmp1 = $line[0];
    $color = $tmp1;
    $cnt = 1;
    $cnt_prev = -1;
    while ($x != $n)
    {
        $tmp = $line[2 * $x];
        if ($tmp == $color)
        {
            $cnt++;
        }
        else
        {
            if ($cnt_prev != -1)
            {
                if ($cnt != $cnt_prev)
                {
                    echo "NO";
                    return;
                }
                else
                {
                    $cnt_prev = $cnt;
                    $cnt = 1;
                    $color = $tmp;
                }
            }
            else
            {
              $cnt_prev = $cnt;
              $cnt = 1;
              $color = $tmp;
            }
        }
        $x++;
    }
    if ($cnt_prev == $cnt or $cnt_prev == -1)
    {
        echo "YES";
    }
    else {
        echo "NO";
    }
?>

<?php

$fl =STDIN;
fscanf($fl, "%d\n", $n);
$last = -1;
$last_color = -1;
$size = 0;
$last_size = 0;
$ok = 0;
$input = explode(' ', trim(fgets($fl)));
for($i=0;$i<$n;++$i){
	if($last == -1){
	    $last = $input[$i];
	    $size = 1;
	} else {
	    if($last == $input[$i]) $size = $size + 1;
	    else{
	        if($last_color == -1){

	        } else {
	            if($size == $last_size);
	            else{
	                ++$ok;
	            }
	        }
	        $last_color = $last;
	        $last_size = $size;
	        $last = $input[$i];
	        $size = 1;
	    }
	}
}
    if($last_color == -1){

	        } else {
	            if($size == $last_size);
	            else{
	                ++$ok;
	            }
	        }
	 if($ok == 0) printf("YES\n");
	 else printf("NO\n");
?>

<?php
function in(){
	return trim(fgets(STDIN));
}
function inarr(){
	return explode(' ', in());
}

$n = in();
$a = inarr();
$cur = $a[0];
$count = 0;
$period = -1;
$flag = 0;

for($i=0; $i<$n; $i++){
    //print $a[$i];
	if($a[$i]!=$cur){
		if($period!=-1 && $count!=$period){
			$flag=1; break;
		}

		$period = $count;
		$cur = $a[$i];
		$count = 1;
	}
	else{
		$count++;
	}
}
if($period!=-1 && $count!=$period){
	$flag=1;
}

if($flag==0){
	print "YES";
}
else{
	print "NO";
}

<?php
$fl =STDIN;//fopen("input.txt","r");
$flag = TRUE;
$prev = -1;
$count = -1;
$prevcount = -1;

$segments = explode(" ", trim(fgets(STDIN)) );
$n = trim($segments[0]);
//$segments = explode(" ", fgets(STDIN) );

$arr = explode(" ", trim(fgets(STDIN)) );
for($i=0;$i<$n;++$i)
{
	$a = $arr[$i];
    //echo $a;
	if ($a == $prev) {
	    $count++;
	} else {
	    if ($prevcount != -1) {
	        //echo $prevcount;

	        if ($count != $prevcount) {
	            $flag = FALSE;

	        }
	    }

	    $prevcount = $count;
	    $count = 1;
	}
	$prev = $a;
}

if ($prevcount != -1) {
     if ($count != $prevcount) $flag = FALSE;
}

if ($flag == TRUE) {
echo "YES";
} else {
echo "NO";

}

<?php

    // go to this idea
    // go to php
    // go to me
    // go to you
    // go to mellicard
    // go to johnny

    $n = fgets(STDIN);
    $cnt = 1; $mn = $n; $mx = 0;
    $s; $tmp; $last;
    $s = fgets(STDIN);
    $last = $s[0];

    for($i = 2 ; $i < strlen($s) ; $i = $i + 2){

        if($i < 2*$n){
            $tmp = $s[$i];

            if($tmp == $last)
                $cnt++;
            else{
                if($cnt > $mx)
                    $mx = $cnt;
                if($cnt < $mn)
                    $mn = $cnt;

                $cnt = 1;
                $last = $tmp;
            }
        }
    }

    if($cnt > $mx)
        $mx = $cnt;
    if($cnt < $mn)
        $mn = $cnt;

    if($mn == $mx)
        echo "YES";
    else
        echo "NO";

?>

<?php
	$n = (int)fgets(STDIN);
    $arr = explode(" ", trim(fgets(STDIN)));
	$siz = -1;
	$currsiz = 1;
	$good = 1;
	$i = 1;
	$prev = $arr[0];
	while ($i < $n) {
		$curr = $arr[$i];
		if($curr == $prev) {
		    $currsiz++;
		} else {
		    if($siz == -1) {
		        $siz = $currsiz;
		    } else {
		        if($siz != $currsiz) {
		            $good = 0;
		        }
		    }
		    $currsiz = 1;
		    $prev = $curr;
		}
		$i++;
	}
    if($siz == -1) {
        $siz = $currsiz;
    } else {
        if($siz != $currsiz) {
            $good = 0;
        }
    }
	if($good == 1) {
	    echo("YES");
	} else {
	    echo("NO");
	}
?>

<?php

$n=(int)fgets(STDIN);
$a=fgets(STDIN);

$fa=-1;
$nowa=0;
for($i=0;$i<$n;++$i)
{
	if($a[$i] == $olda){
		++$nowa;
	}else{
		$olda=$a[$i];
		if($fa == -1){
			$fa=$nowa;
		}elseif($fa == -2){

		}else{
			if($fa==$nowa)
				$nowa=1;
			else $fa=-2;

		}

	}
}
if($fa==-2){
	printf("NO");
}else{
	printf("YES");
}

?>

<?php
	$n = (int)fgets(STDIN)-1;
	$prev = (int)fgets(STDIN);
	$siz = -1;
	$currsiz = 1;
	$good = 1;
	while ($n >= 0) {
		$curr = (int)fgets(STDIN);
		if($curr == $prev) {
		    $currsiz++;
		} else {
		    if($siz == -1) {
		        $siz = $currsiz;
		    } else {
		        if($siz != $currsiz) {
		            $good = 0;
		        }
		    }
		    $siz = 1;
		    $prev = $curr;
		}
		$n--;
	}
    if($siz == -1) {
        $siz = $currsiz;
    } else {
        if($siz != $currsiz) {
            $good = 0;
        }
    }
	if($good == 1) {
	    echo("YES");
	} else {
	    echo("NO");
	}
?>


There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.In one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books (i.e. for each $$$i$$$ from $$$l$$$ to $$$r$$$ the condition $$$a_i = 1$$$ holds) and:  Shift it to the right by $$$1$$$: move the book at index $$$i$$$ to $$$i + 1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$r+1 \le n$$$ and there is no book at the position $$$r+1$$$.  Shift it to the left by $$$1$$$: move the book at index $$$i$$$ to $$$i-1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$l-1 \ge 1$$$ and there is no book at the position $$$l-1$$$. Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps).For example, for $$$a = [0, 0, 1, 0, 1]$$$ there is a gap between books ($$$a_4 = 0$$$ when $$$a_3 = 1$$$ and $$$a_5 = 1$$$), for $$$a = [1, 1, 0]$$$ there are no gaps between books and for $$$a = [0, 0,0]$$$ there are also no gaps between books.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of places on a bookshelf. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is $$$1$$$ if there is a book at this position and $$$0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.

For each test case, print one integer: the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps).

NoteIn the first test case of the example, you can shift the segment $$$[3; 3]$$$ to the right and the segment $$$[4; 5]$$$ to the right. After all moves, the books form the contiguous segment $$$[5; 7]$$$. So the answer is $$$2$$$.In the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already.In the third test case of the example, you can shift the segment $$$[5; 5]$$$ to the left and then the segment $$$[4; 4]$$$ to the left again. After all moves, the books form the contiguous segment $$$[1; 3]$$$. So the answer is $$$2$$$.In the fourth test case of the example, you can shift the segment $$$[1; 1]$$$ to the right, the segment $$$[2; 2]$$$ to the right, the segment $$$[6; 6]$$$ to the left and then the segment $$$[5; 5]$$$ to the left. After all moves, the books form the contiguous segment $$$[3; 4]$$$. So the answer is $$$4$$$.In the fifth test case of the example, you can shift the segment $$$[1; 2]$$$ to the right. After all moves, the books form the contiguous segment $$$[2; 5]$$$. So the answer is $$$1$$$.

<?php
fscanf(STDIN,"%d",$t);
while($t--)
{
        fscanf(STDIN,"%d",$n);
        $arr=explode(' ',trim(fgets(STDIN)));
		//$cnt=0;
		//$newArr=array();
		$pos=array();
		for ($i=0,$j=0; $i <$n; $i++)
		{
			if($arr[$i]==1)
				{
					$pos[$j]=$i;
					//$newArr[$j]=$arr[$i];
					$j++;
				}

		}
		//print_r($pos);
		if(count($pos)==1)
			echo "0\n";
		else
		    {   $cnt=0;
		    	$firstPos=$pos[0];
		    	$lstindx=count($pos)-1;
		    	$lstPos=$pos[$lstindx];
		    	for ($i=$firstPos;$i <=$lstPos ; $i++)
		    	{
		    		if($arr[$i]==0)
		    			$cnt++;
		    	}
		    	echo "$cnt\n";

		    }

}

<?php
    $jt = trim(fgets(STDIN));
    for($sr = 0; $sr < $jt; $sr++){
        $i = trim(fgets(STDIN));
        $a = explode(" ", trim(fgets(STDIN)));
        $ic = 0;
        $ie = 0;
        $b = false;
        foreach($a as $c){
            if($c == 1){
                $b = true;
                $ie = 0;
            }
            if($b && $c == 0){
                $ic++;
                $ie++;
            }
        }
        echo $ic - $ie. "\n";

    }

?>