A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.

The first line consists of two integers n and m . Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n. It is guaranteed that every pair of cities will appear at most once in the input.

You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may print any of them.

NoteThis is one possible solution of the example:   These are examples of wrong solutions:   The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair.   The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads.   Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.

<?php
/*  $input = "4 1
1 3";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
    $number_of_not_match = $n_m[1]-'0';
    array_splice($split_text, 0, 1);
    $list_of_unmatch=array();
    $array_length = sizeof($split_text);
    for($c=0; $c<$array_length; $c++){
        $unmatch = explode(" ",$split_text[$c]);
        array_push($list_of_unmatch, trim($unmatch[0]), trim($unmatch[1]));
    }

    $list_of_unmatch = array_unique($list_of_unmatch);
    $list_of_unmatch = array_values($list_of_unmatch);
    $initial=1;
    $unmatch_length = sizeof($list_of_unmatch);
    $n = $n_m[0]-'0';

    for($a=0; $a<$n;$a++){
        if(in_array("$initial", $list_of_unmatch))
            $initial++;
    }

    $path = "";

    $fix=$initial;
    for($i=1; $i<=$n; $i++){
        $initial=$fix;
        while($initial==$i)
            $initial++;
        $temp=$i.' '.$initial;
        if(in_array($temp,$path)){
 			continue;
        }

        $temp=$initial.' '.$i;
        $path[]=$temp;
    }
    echo $n-1;
    for($j=0; $j<$n-1; $j++){
        // echo "<br>".$path[$j];
        echo PHP_EOL.$path[$j];
    }

<?php
/*	$input = "4 1
1 3";*/
	$input = trim(file_get_contents("php://stdin"));
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$array_length = $split_text.length;

	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$split_text)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	// $input = trim(file_get_contents("php://stdin"));
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$array_length = sizeof($split_text);
	for($c=0; $c<$array_length; $c++){
		$list_of_unmatch[] = explode(" ",$split_text[$c]);
	}

	$initial=1;
	$unmatch_length = sizeof($list_of_unmatch);

	$n = $n_m[0]-'0';
	for($a=0; $a<$n;$a++){
		if(in_array("$initial", $list_of_unmatch))
			$initial++;
	}
	$path = "";
	for($i=1; $i<$n; $i++){
		$temp=(string)($initial.' '.($i+1));
		while($initial==$i)
			$initial++;
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
	$input = "4 1
1 3";
	// $input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$split_text)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		echo "<br>".$path[$j];
		// echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
	}
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		$temp1=($i+1).' '.$initial;
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo $path[$j].PHP_EOL;
	}

<?php
/*  $input = "4 1
1 3";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
    $number_of_not_match = $n_m[1]-'0';
    array_splice($split_text, 0, 1);
    $list_of_unmatch=array();
    $array_length = sizeof($split_text);
    for($c=0; $c<$array_length; $c++){
        $unmatch = explode(" ",$split_text[$c]);
        array_push($list_of_unmatch, trim($unmatch[0]), trim($unmatch[1]));
    }

    var_dump($list_of_unmatch);

    $list_of_unmatch = array_unique($list_of_unmatch);
    $list_of_unmatch = array_values($list_of_unmatch);
    $initial=1;
    $unmatch_length = sizeof($list_of_unmatch);
    $n = $n_m[0]-'0';

    for($a=0; $a<$n;$a++){
        if(in_array("$initial", $list_of_unmatch))
            $initial++;
    }

    $path = "";

    $fix=$initial;
    for($i=1; $i<=$n; $i++){
        $initial=$fix;
        while($initial==$i)
            $initial++;
        $temp=$i.' '.$initial;
        if(in_array($temp,$path)){
 			continue;
        }

        $temp=$initial.' '.$i;
        $path[]=$temp;
    }
    echo $n-1;
    for($j=0; $j<$n-1; $j++){
        // echo "<br>".$path[$j];
        echo PHP_EOL.$path[$j];
    }

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	$split_text = implode("\n",$split_text);
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text);
	}
	$forever_nt_couple = array_map('strval',$forever_nt_couple);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(var_dump(in_array($temp,$forever_nt_couple))){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = trim(file_get_contents("php://stdin"));
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$array_length = sizeof($split_text);
	for($c=0; $c<$array_length; $c++){
		$list_of_unmatch[] = explode(" ",$split_text[$c]);
	}

	$initial=1;
	$unmatch_length = sizeof($list_of_unmatch);

	$n = $n_m[0]-'0';
	for($a=0; $a<$n;$a++){
		if(in_array("$initial", $list_of_unmatch))
			$initial++;
	}
	$path = "";
	$fix=$initial;
	for($i=1; $i<$n; $i++){
		$initial=$fix;
		$temp=(string)($initial.' '.($i+1));
		while($initial==$i)
			$initial++;
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*  $input = "4 1
1 3";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
    $number_of_not_match = $n_m[1]-'0';
    array_splice($split_text, 0, 1);

    $array_length = sizeof($split_text);
    for($c=0; $c<$array_length; $c++){
    	$split_text[$c] = trim($split_text[$c]);
        $list_of_unmatch = explode(" ",$split_text[$c]);
    }

    $initial=1;
    $unmatch_length = sizeof($list_of_unmatch);
    $n = $n_m[0]-'0';

    for($a=0; $a<$n;$a++){
        if(in_array("$initial", $list_of_unmatch))
            $initial++;
    }

    $path = "";

    $fix=$initial;
    for($i=1; $i<=$n; $i++){
        $initial=$fix;
        while($initial==$i)
            $initial++;
        $temp=$i.' '.$initial;
        $temp1=$initial.' '.$i;
        if(in_array($temp,$path)){
 			continue;
        }

        if(in_array($temp,$split_text) || in_array($temp1,$split_text)){
        	$initial++;
        	while($initial==$i)
            	$initial++;
        }

        $temp=$initial.' '.$i;
        $path[]=$temp;
    }
    echo $n-1;
    for($j=0; $j<$n-1; $j++){
        // echo "<br>".$path[$j];
        echo PHP_EOL.$path[$j];
    }

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	$split_text = implode("\n",$split_text);
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text);
	}
	$forever_nt_couple = array_map('strval',$forever_nt_couple);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array(var_dump($temp),var_dump($forever_nt_couple))){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*  $input = "4 1
1 3";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
    $number_of_not_match = $n_m[1]-'0';
    array_splice($split_text, 0, 1);

    $array_length = sizeof($split_text);
    for($c=0; $c<$array_length; $c++){
    	$split_text[$c] = trim($split_text[$c]);
        $list_of_unmatch = explode(" ",$split_text[$c]);
    }

    $initial=1;
    $unmatch_length = sizeof($list_of_unmatch);
    $n = $n_m[0]-'0';

    for($a=0; $a<$n;$a++){
        if(in_array("$initial", $list_of_unmatch))
            $initial++;
    }

    $path = "";

    $fix=$initial;
    for($i=1; $i<=$n; $i++){
        $initial=$fix;
        while($initial==$i)
            $initial++;
        $temp=$i.' '.$initial;
        $temp=$initial.' '.$i;
        if(in_array($temp,$path) || in_array($temp,$split_text) || in_array($temp1,$split_text)){
        	$initial++;
        	while($initial==$i)
            	$initial++;
        }

        $temp=$initial.' '.$i;
        $path[]=$temp;
    }
    echo $n-1;
    for($j=0; $j<$n-1; $j++){
        // echo "<br>".$path[$j];
        echo PHP_EOL.$path[$j];
    }

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
	}
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		if(in_array($temp,"$forever_nt_couple")){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
	}
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		$temp1=($i+1).' '.$initial;
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	$split_text = implode("\n",$split_text);
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text);
	}
	$forever_nt_couple = array_map('strval',$forever_nt_couple);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
	}
	$forever_nt_couple = array_map('strval',$forever_nt_couple);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = trim(file_get_contents("php://stdin"));
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$array_length = sizeof($split_text);
	for($c=0; $c<$array_length; $c++){
		$list_of_unmatch[] = explode(" ",$split_text[$c]);
	}

	$initial=1;
	$unmatch_length = sizeof($list_of_unmatch);

	$n = $n_m[0]-'0';
	for($a=0; $a<$n;$a++){
		if(in_array("$initial", $list_of_unmatch))
			$initial++;
	}
	$path = "";
	for($i=1; $i<$n; $i++){
		$temp=(string)($initial.' '.($i+1));
		while($initial==$i)
			$initial++;
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");
	var_dump($input);
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	var_dump($split_text);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$split_text)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(array_search($temp,$split_text)!==false){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text);
	}
	$forever_nt_couple = array_map('strval',$forever_nt_couple);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
		echo $forever_nt_couple;
	}
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		$temp1=($i+1).' '.$initial;
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*  $input = "4 1
1 3";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
    $number_of_not_match = $n_m[1]-'0';
    array_splice($split_text, 0, 1);

    $array_length = sizeof($split_text);
    for($c=0; $c<$array_length; $c++){
    	$split_text[$c] = trim($split_text[$c]);
        $list_of_unmatch = explode(" ",$split_text[$c]);
    }

    $initial=1;
    $unmatch_length = sizeof($list_of_unmatch);
    $n = $n_m[0]-'0';

    for($a=0; $a<$n;$a++){
        if(in_array("$initial", $list_of_unmatch))
            $initial++;
    }

    $path = "";

    $fix=$initial;
    for($i=1; $i<=$n; $i++){
        $initial=$fix;
        while($initial==$i)
            $initial++;
        $temp=trim($i.' '.$initial);
        if(in_array($temp,$path)){
        	continue;
        }
        $temp=$initial.' '.$i;
        $path[]=$temp;
    }
    echo $n-1;
    for($j=0; $j<$n-1; $j++){
        // echo "<br>".$path[$j];
        echo PHP_EOL.$path[$j];
    }

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$split_text)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	for($c=0; $c<$number_of_not_match; $c++){
		$forever_nt_couple = explode("\n",$split_text[$c+1]);
		echo $forever_nt_couple[0];
	}
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=$initial.' '.($i+1);
		$temp1=($i+1).' '.$initial;
		if(in_array($temp,$forever_nt_couple)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");
	var_dump($input);
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);
	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array(var_dump($temp),var_dump($split_text))){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?php
/*	$input = "4 1
1 3";*/
	$input = file_get_contents("php://stdin");
	var_dump($input);
	$split_text = explode("\n",$input);
	$n_m = explode(" ",$split_text[0]); //index 0 store n, index 1 store m
	$number_of_not_match = $n_m[1]-'0';
	array_splice($split_text, 0, 1);

	$array_length = $split_text.length;
	for($a=0; $a<$array_length;$a++)
		$split_text[$a]=trim($split_text[$a]);

	$n = $n_m[0]-'0';
	$path = "";
	for($i=1; $i<$n; $i++){
		$initial=1;
		$temp=(string)($initial.' '.($i+1));
		if(in_array($temp,$split_text)){
			$initial++;
			while($initial==$i)
				$initial++;
			$temp=$initial.' '.$i;
		}
		$path[]=$temp;
	}
	echo $n-1;
	for($j=0; $j<$n-1; $j++){
		// echo "<br>".$path[$j];
		echo PHP_EOL.$path[$j];
	}

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);

$nm = explode(' ',$f[0]);

for ($i=1;$i<=$nm[0];$i++) {
	$all[$i] = 1;
}

$left = $right = array();

if ($f[1]) {
	for ($i=1;$i<=$nm[1];$i++) {
		$deny = explode(' ',$f[$i]);

		if (!$left || $left[$deny[0]] || $left[$deny[1]]) {
			$left[$deny[0]] = 1;
			$left[$deny[1]] = 1;
		} else {
			$right[$deny[0]] = 1;
			$right[$deny[1]] = 1;
		}

		unset($all[$deny[0]],$all[$deny[1]]);
	}

	$qa = sizeof($all);

	if (!$right) {
		$move = key($all);
		$right[$move] = 1;
		unset($all[$move]);
		$left += $all;
	} elseif (sizeof($left) > sizeof($right)) {
		$left += $all;
	} else {
		$right += $all;
	}

} else {
	$left = array(1=>1);
	unset($all[1]);
	$right = $all;
}

$ql = sizeof($left);
$qr = sizeof($right);

if ($a = $ql * $qr) {
	echo $a;
	foreach ($left as $l=>$null) {
		foreach ($right as $r=>$null) {
			echo PHP_EOL.$l.' '.$r;
		}
	}
} else {
	echo 0;
}

<?
$f = file('php://stdin'); $f2 = fopen('php://stdout','w+');

$nm = explode(' ',$f[0]);

for ($i=1;$i<=$nm[0];$i++) {
	$all[$i] = 1;
}

$left = $right = array();

if ($f[1]) {
	for ($i=1;$i<=$nm[1];$i++) {
		$deny = explode(' ',$f[$i]);

		if (!$left || $left[$deny[0]] || $left[$deny[1]]) {
			$left[$deny[0]] = 1;
			$left[$deny[1]] = 1;
		} else {
			$right[$deny[0]] = 1;
			$right[$deny[1]] = 1;
		}

		unset($all[$deny[0]],$all[$deny[1]]);
	}

	$qa = sizeof($all);

	if ($right && sizeof($left) > sizeof($right)) {
		$left += $all;
		$ql += $qa;
	} else {
		$right += $all;
		$qr += $qa;
	}

} else {
	$left = array(1=>1);
	unset($all[1]);
	$right = $all;
}

$ql = sizeof($left);
$qr = sizeof($right);

if ($a = $ql * $qr) {
	fwrite($f2, $a);
	foreach ($left as $l=>$null) {
		foreach ($right as $r=>$null) {
			fwrite($f2, $l.' '.$r);
		}
	}
} else {
	fwrite($f2, 0);
}

fclose($f2);

<?
$f = file('php://stdin');

$nm = explode(' ',$f[0]);

for ($i=1;$i<=$nm[0];$i++) {
	$all[$i] = 1;
}

$left = $right = array();

if ($f[1]) {
	for ($i=1;$i<=$nm[1];$i++) {
		$deny = explode(' ',$f[$i]);

		if (!$left || $left[$deny[0]] || $left[$deny[1]]) {
			$left[$deny[0]] = 1;
			$left[$deny[1]] = 1;
		} else {
			$right[$deny[0]] = 1;
			$right[$deny[1]] = 1;
		}

		unset($all[$deny[0]],$all[$deny[1]]);
	}

	$qa = sizeof($all);

	if (!$right) {
		$move = key($all);
		$right[$move] = 1;
		unset($all[$move]);
		$left += $all;
	} elseif (sizeof($left) > sizeof($right)) {
		$left += $all;
	} else {
		$right += $all;
	}

} else {
	$left = array(1=>1);
	unset($all[1]);
	$right = $all;
}

$ql = sizeof($left);
$qr = sizeof($right);

if ($a = $ql * $qr) {
	echo $a;
	foreach ($left as $l=>$null) {
		foreach ($right as $r=>$null) {
			echo PHP_EOL.$l.' '.$r;
		}
	}
} else {
	echo 0;
}

<?
$f = file('php://stdin'); $f2 = fopen('php://stdout','w+');

$nm = explode(' ',$f[0]);

for ($i=1;$i<=$nm[0];$i++) {
	$all[$i] = 1;
}

$left = $right = array();

if ($f[1]) {
	for ($i=1;$i<=$nm[1];$i++) {
		$deny = explode(' ',$f[$i]);

		if (!$left || $left[$deny[0]] || $left[$deny[1]]) {
			$left[$deny[0]] = 1;
			$left[$deny[1]] = 1;
		} else {
			$right[$deny[0]] = 1;
			$right[$deny[1]] = 1;
		}

		unset($all[$deny[0]],$all[$deny[1]]);
	}

	$qa = sizeof($all);

	if (!$right) {
		$move = key($all);
		$right[$move] = 1;
		unset($all[$move]);
		$left += $all;
	} elseif (sizeof($left) > sizeof($right)) {
		$left += $all;
	} else {
		$right += $all;
	}

} else {
	$left = array(1=>1);
	unset($all[1]);
	$right = $all;
}

$ql = sizeof($left);
$qr = sizeof($right);

if ($a = $ql * $qr) {
	fwrite($f2, $a.PHP_EOL);
	foreach ($left as $l=>$null) {
		foreach ($right as $r=>$null) {
			fwrite($f2, $l.' '.$r.PHP_EOL);
		}
	}
} else {
	fwrite($f2, 0);
}

fclose($f2);


You are given a positive integer $$$n$$$, it is guaranteed that $$$n$$$ is even (i.e. divisible by $$$2$$$).You want to construct the array $$$a$$$ of length $$$n$$$ such that:   The first $$$\frac{n}{2}$$$ elements of $$$a$$$ are even (divisible by $$$2$$$);  the second $$$\frac{n}{2}$$$ elements of $$$a$$$ are odd (not divisible by $$$2$$$);  all elements of $$$a$$$ are distinct and positive;  the sum of the first half equals to the sum of the second half ($$$\sum\limits_{i=1}^{\frac{n}{2}} a_i = \sum\limits_{i=\frac{n}{2} + 1}^{n} a_i$$$). If there are multiple answers, you can print any. It is not guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the array. It is guaranteed that that $$$n$$$ is even (i.e. divisible by $$$2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) satisfying conditions from the problem statement on the second line.

<?php
//$stdin = fopen('input.txt', 'r');

$solve = function($n){

	if($n % 4 !== 0){
		return false;
	}
	$a = array_fill(0, $n, 0);
	$n2 = $n / 2;
	for($i = 0; $i < $n2; $i++){
		$i2 = 2*$i + 1;
		$a[$i + $n2] = $i2;
		$a[$i] = $i2 + 1;
	}
	$a[$n-1] += $n2;
	return $a;
};

$t = intval(fgets(STDIN));
for(; $t > 0; $t--){

	$n = intval(fgets(STDIN));

	if(($a = $solve($n)) === false){
		echo "NO";
	} else {
		echo "YES\n";
		echo implode(' ', $a);
	}
	echo "\n";
}

<?php
error_reporting(0);

main();

function main() {
	list($cases) = explode(" ", trim(fgets(STDIN)));

	for ($i = 0; $i < $cases; $i++) {
		$n = trim(fgets(STDIN));
		$res = run($n);
		if ($res[0] == "NO") {
			print "NO\n";
		} else {
			print "YES\n";
			print join(" ", $res[1]) . "\n";
		}
	}
}

function run($n) {
	if ( ($n / 2) % 2 == 1) {
		return ["NO", []];
	}

	$start = 4;

	$res = [];

	$total1 = 0;

	for ($i = 0; $i < $n/2; $i++) {
		array_push($res, $start);
		$total1 += $start;
		$start += 2;
	}

	$start = 3;

	$total2 = 0;

	for ($i = 0; $i < $n/2; $i++) {
		array_push($res, $start);
		$total2 += $start;
		$start += 2;
	}

	#print $total1 . ":" . $total2 . "\n";

	$res[count($res)-1] += ($total1 - $total2);

	return ["YES", $res];
}

?>

<?php

for($t = intval(trim(fgets(STDIN))); $t > 0; $t --){
    //print pow(2, intval(fgets(STDIN)) - 1)."\n";
    $n = intval(trim(fgets(STDIN)));
    if(($n / 2) % 2 == 1) {
        print "NO\n";
        continue;
    }
    print "YES\n";

    for($i = 0; $i < $n / 2; $i++){
        print (($i + 1) * 2)." ";
    }

    for($i = 1; $i < $n - 1; $i += 2){
        print ($i)." ";
    }

    print $n + $n / 2 - 1;
    print "\n";

}

<?php

$t = (int)fgets(STDIN);
for ($i = 0; $i < $t; $i++) {
    $n = (int)fgets(STDIN);
    if ($n === 2) {
        echo "NO\n";
        continue;
    }

    if (($n % 4) !== 0) {
        echo "NO\n";
        continue;
    }

    $sum = 0;
    $diff = 0;
    echo "YES\n";
    $k = $n / 2;
    for ($j = 0; $j < $k; $j++) {
        $diff += 2;
        echo $diff.' ';
        $sum += $diff;
    }
    $k = $n / 2;
    $diff = 1;
    while ($k > 1) {
        echo $diff." ";
        $sum -= $diff;
        $diff += 2;
        $k--;
    }
    echo $sum."\n";
}

<?php
    //phpinfo();
    // 输入
    function solve($n)
    {
        for($i = 1; $i <= $n; $i ++) echo $i * 2 . " " ;
        for($i = 1; $i < $n; $i ++) echo $i * 2 - 1 . " " ;
        echo $n * 3 - 1 . "\n" ;
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $n = intval(fgets(STDIN));

        $half = $n / 2 ;
        if($half & 1)
        {
            echo "NO" . "\n" ;
            continue ;
        }
        else
        {
            echo "YES" . "\n" ;
            solve($half) ;
        }
    }
?>

<?php
    //phpinfo();
    // 输入
    function solve($n)
    {
        for($i = 1; $i <= $n; $i ++) echo $i * 2 . " " ;
        for($i = 1; $i < $n; $i ++) echo $i * 2 - 1 . " " ;
        echo $n * 3 - 1 . "\n" ;
    }

    $a = trim(fgets(STDIN));
    while($a --)
    {
        $n = trim(fgets(STDIN));

        $half = $n / 2 ;
        if($half & 1)
        {
            echo "NO" . "\n" ;
            continue ;
        }
        else
        {
            echo "YES" . "\n" ;
            solve($half) ;
        }
    }
?>

<?php
    //phpinfo();
    // 输入
    function solve($n)
    {
        $Balanced = array() ;

        for($i = 1; $i <= $n; $i ++) $Balanced[] = 2 * $i ;
        for($i = 1; $i < $n; $i ++) $Balanced[] = $i * 2 - 1 ;
        $Balanced[] = $i * 3 - 1 ;

        echo implode(" ", $Balanced) . "\n" ;
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $n = intval(fgets(STDIN));

        $half = $n / 2 ;
        if($half & 1)
        {
            echo "NO" . "\n" ;
            continue ;
        }
        else
        {
            echo "YES" . "\n" ;
            solve($half) ;
        }
    }
?>

<?php
error_reporting(0);

main();

function main() {
	list($cases) = explode(" ", trim(fgets(STDIN)));

	for ($i = 0; $i < $cases; $i++) {
		$n = trim(fgets(STDIN));
		$res = run($n);
		if ($res[0] == "NO") {
			print "NO\n";
		} else {
			print "YES\n";
			print join(" ", $res[1]) . "\n";
		}
	}
}

function run($n) {
	if ( ($n / 2) % 2 == 1) {
		return ["NO", []];
	}

	$start = 4;

	$res = [];

	$total1 = 0;

	for ($i = 0; $i < $n/2; $i++) {
		array_push($res, $start);
		$total1 += $start;
		$start += 2;
	}

	$start = 3;

	$total2 = 0;

	for ($i = 0; $i < $n/2; $i++) {
		array_push($res, $start);
		$total2 += $start;
		$start += 2;
	}

	print $total1 . ":" . $total2 . "\n";

	$res[count($res)-1] += ($total1 - $total2);

	return ["YES", $res];
}

?>


Polycarp has $$$n$$$ friends, the $$$i$$$-th of his friends has $$$a_i$$$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $$$a_i$$$ to be the same. To solve this, Polycarp performs the following set of actions exactly once:   Polycarp chooses $$$k$$$ ($$$0 \le k \le n$$$) arbitrary friends (let's say he chooses friends with indices $$$i_1, i_2, \ldots, i_k$$$);  Polycarp distributes their $$$a_{i_1} + a_{i_2} + \ldots + a_{i_k}$$$ candies among all $$$n$$$ friends. During distribution for each of $$$a_{i_1} + a_{i_2} + \ldots + a_{i_k}$$$ candies he chooses new owner. That can be any of $$$n$$$ friends. Note, that any candy can be given to the person, who has owned that candy before the distribution process. Note that the number $$$k$$$ is not fixed in advance and can be arbitrary. Your task is to find the minimum value of $$$k$$$.For example, if $$$n=4$$$ and $$$a=[4, 5, 2, 5]$$$, then Polycarp could make the following distribution of the candies:   Polycarp chooses $$$k=2$$$ friends with indices $$$i=[2, 4]$$$ and distributes $$$a_2 + a_4 = 10$$$ candies to make $$$a=[4, 4, 4, 4]$$$ (two candies go to person $$$3$$$). Note that in this example Polycarp cannot choose $$$k=1$$$ friend so that he can redistribute candies so that in the end all $$$a_i$$$ are equal.For the data $$$n$$$ and $$$a$$$, determine the minimum value $$$k$$$. With this value $$$k$$$, Polycarp should be able to select $$$k$$$ friends and redistribute their candies so that everyone will end up with the same number of candies.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^4$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output:    the minimum value of $$$k$$$, such that Polycarp can choose exactly $$$k$$$ friends so that he can redistribute the candies in the desired way;  "-1" if no such value $$$k$$$ exists.

<?php

$data1 = (int) trim(fgets(STDIN));
// $data2 = str_split(trim(fgets(STDIN)), 1);
// $data3 = str_split(trim(fgets(STDIN)), 1);
for($i=0;$i<$data1;$i++)
{
    $data2 = (int) trim(fgets(STDIN));
    $data3 = preg_split("/ /", trim(fgets(STDIN)));

    $main = new MainClass;

    echo $main->solution($data1, $data2 , $data3) . "\r\n";
}

class MainClass {

	public function solution($n , $m , $data)
	{
	    if($m == 1)
    	    return 0;

    	$sum = array_sum($data);
    	if($sum % $m != 0)
    	    return -1;

    	$avg=$sum/count($data);
    	$max= 0;
    	$min= 0;
    	foreach($data as $value)
    	{
    	    if($value > $avg)
    	    {
    	        $max++;
    	    }
    	    elseif($value <= $avg)
    	    {
    	        $min++;
    	    }
    	}

	    return $max;
	}
}

<?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)));
  $ans = 0;

  $sum = array_sum($a);
  if ($sum % $n != 0) { echo '-1'.PHP_EOL; }
  else {
    $d = $sum / $n;
    for ($j = 0; $j < $n; $j++) {
      if ($a[$j] > $d) { $ans++; }
    }
    echo $ans.PHP_EOL;
  }
}

?>

<?php

$data1 = (int) trim(fgets(STDIN));
// $data2 = str_split(trim(fgets(STDIN)), 1);
// $data3 = str_split(trim(fgets(STDIN)), 1);
for($i=0;$i<$data1;$i++)
{
    $data2 = (int) trim(fgets(STDIN));
    $data3 = preg_split("/ /", trim(fgets(STDIN)));

    $main = new MainClass;

    echo $main->solution($data1, $data2 , $data3) . "\r\n";
}

class MainClass {

	public function solution($n , $m , $array)
	{
	    if($m == 1)
    	    return 0;

	    $sum = $max_c = $max = 0;
	    foreach($array as $index)
	    {
	        $sum += $index;
	        if($max < $index)
	        {
	            $max = $index;
	        }
	    }

	    if($sum % $m != 0)
            return -1;

	    foreach($array as $index)
	    {
	        if($max == $index)
            {
                $max_c++;
            }
	    }

	    return $m - $max_c;
	}
}

<?php

$data1 = (int) trim(fgets(STDIN));
// $data2 = str_split(trim(fgets(STDIN)), 1);
// $data3 = str_split(trim(fgets(STDIN)), 1);
for($i=0;$i<$data1;$i++)
{
    $data2 = (int) trim(fgets(STDIN));
    $data3 = preg_split("/ /", trim(fgets(STDIN)));

    $main = new MainClass;

    echo $main->solution($data1, $data2 , $data3) . "\r\n";
}

// End of interface

class MainClass {
	// 978В.File name
	//public $problemLink = 'https://codeforces.com/problemset/problem/978/B';
	//public $submissionLink = '';

	public function solution($n , $m , $array)
	{
	    if($m == 1)
    	    return 0;

	    $sum = $max_c = $max = 0;
	    foreach($array as $index)
	    {
	        $sum += $index;
	        if($max < $index)
	        {
	            $max = $index;
	        }
	    }

	    if($sum % $m != 0)
            return -1;

	    foreach($array as $index)
	    {
	        if($max == $index)
            {
                $max_c++;
            }
	    }

	    return $max - $max_c;
	}
}


Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive).To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than $$$k$$$, and each color should belong to exactly one group.Finally, the students will replace the color of each pixel in the array with that color’s assigned group key.To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing $$$k$$$ to the right.   To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array.

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is the color of the $$$i$$$-th pixel.

Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.

NoteOne possible way to group colors and assign keys for the first sample:Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$.Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$.Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$.Other groups won't affect the result so they are not listed here.

<?php
/**
 * Created by PhpStorm.
 * User: jianzjzhang
 * Date: 2018/5/10
 * Time: 10:36
 */

function mapping($arr, $k)
{
    $map = array();
    $map = array_pad($map, 256, -1);
    $dp = array();
    $dp = array_pad($dp, 256, -1);
    $result = array();

    foreach ($arr as $x){
        if($map[$x] != -1){
            $result[] = $map[$x];
        }
        else{
            $start = $x - $k + 1;
            if($start < 0){
                $start = 0;
            }
            if($map[$start] != -1 && $start != 0 && $map[$start-1] == $map[$start]){
                $start = $dp[$start] + 1;
            }
            $result[] = $start;
            for($i=$start; $i<=$x; $i++){
                $map[$i] = $start;
                $dp[$i] = $x;
            }
        }
    }
    return $result;
}

function main()
{
    list($n, $k) = explode(" ", fgets(STDIN));
    $arr = array();
    for($i=0; $i<$n-1; $i++){
        $arr[] = intval(stream_get_line(STDIN, 4, " "));
    }
    $arr[] = intval(stream_get_line(STDIN, 4, "\n"));

    echo implode(" ", mapping($arr, intval($k)));
}

main();

<?php
/**
 * Created by PhpStorm.
 * User: jianzjzhang
 * Date: 2018/5/10
 * Time: 10:36
 */

function mapping($arr, $k)
{
    $map = array();
    $map = array_pad($map, 256, -1);
    $result = array();

    foreach ($arr as $x){
        if($map[$x] != -1){
            $result[] = $map[$x];
        }
        else{
            $start = $x;
            for(; $start+$k>$x && $start>=0 && $map[$start]==-1; $start--);
            $result[] = ++$start;
            for($i=0; $i<$k; $i++){
                $map[$start+$i] = $start;
            }
        }
    }
    return $result;
}

function main()
{
    list($n, $k) = explode(" ", fgets(STDIN));
    $arr = array();
    for($i=0; $i<$n; $i++){
        $arr[] = intval(stream_get_line(STDIN, 4, " "));
    }

    echo implode(" ", mapping($arr, intval($k)));
}

main();


In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.Help platform select such an hour, that the number of people who will participate in the contest is maximum.

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).

Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.

NoteIn the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.In second example only people from the third and the fourth timezones will participate.


Allen wants to enter a fan zone that occupies a round square and has $$$n$$$ entrances.There already is a queue of $$$a_i$$$ people in front of the $$$i$$$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.Allen uses the following strategy to enter the fan zone:   Initially he stands in the end of the queue in front of the first entrance.  Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance). Determine the entrance through which Allen will finally enter the fan zone.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of entrances. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of people in queues. These numbers do not include Allen.

Print a single integer — the number of entrance that Allen will use.

NoteIn the first example the number of people (not including Allen) changes as follows: $$$[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$$$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.In the second example the number of people (not including Allen) changes as follows: $$$[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$$$.In the third example the number of people (not including Allen) changes as follows: $$$[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$$$.

<?php
    $dir                        = fopen("php://stdin", 'r');
    $contents                   = stream_get_contents($dir);
    $inputs                     = explode("\n",$contents);
    $entrancesCount             = (int) $inputs[0];
    $fansCountPerEntrance       = array_map('intval', explode(' ', $inputs[1]));
    $possibilitiesForEntrance   = [];
    $fanEntrance                = getEntrance($entrancesCount, $fansCountPerEntrance);
    echo $fanEntrance;

    function getEntrance($entrancesCount, $fansCountPerEntrance)
    {
        for($entranceCounter = 0; $entranceCounter < $entrancesCount; $entranceCounter ++)
        {
           /* if($fansCountPerEntrance[0] == 1)
            {
                return $entranceCounter + 1;
            } */
            $possibilitiesForEntrance[$entranceCounter] = max(0, ceil(($fansCountPerEntrance[$entranceCounter] - $entranceCounter) / $entrancesCount));
        }
        $entranceNumber = array_keys($possibilitiesForEntrance, min($possibilitiesForEntrance))[0]+1;
        return $entranceNumber;
    }
?>

<?php
    $dir                        = fopen("php://stdin", 'r');
    $contents                   = stream_get_contents($dir);
    $inputs                     = explode("\n",$contents);
    $entrancesCount             = (int) $inputs[0];
    $fansCountPerEntrance       = array_map('intval', explode(' ', $inputs[1]));
    $possibilitiesForEntrance   = [];
    $fanEntrance                = getEntrance($entrancesCount, $fansCountPerEntrance);
    echo $fanEntrance;

    function getEntrance($entrancesCount, $fansCountPerEntrance)
    {
        for($entranceCounter = 0; $entranceCounter < $entrancesCount; $entranceCounter ++)
        {
            if($fansCountPerEntrance[0] == 1)
            {
                return $entranceCounter + 1;
            }
            $possibilitiesForEntrance[$entranceCounter] = max(0, ceil(($fansCountPerEntrance[$entranceCounter] - $entranceCounter) / $entrancesCount));
        }
        $entranceNumber = array_keys($possibilitiesForEntrance, min($possibilitiesForEntrance))[0]+1;
        return $entranceNumber;
    }
?>


You are given a range of positive integers from $$$l$$$ to $$$r$$$.Find such a pair of integers $$$(x, y)$$$ that $$$l \le x, y \le r$$$, $$$x \ne y$$$ and $$$x$$$ divides $$$y$$$.If there are multiple answers, print any of them.You are also asked to answer $$$T$$$ independent queries.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of queries. Each of the next $$$T$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 998244353$$$) — inclusive borders of the range. It is guaranteed that testset only includes queries, which have at least one suitable pair.

Print $$$T$$$ lines, each line should contain the answer — two integers $$$x$$$ and $$$y$$$ such that $$$l \le x, y \le r$$$, $$$x \ne y$$$ and $$$x$$$ divides $$$y$$$. The answer in the $$$i$$$-th line should correspond to the $$$i$$$-th query from the input. If there are multiple answers, print any of them.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = $b * 2;
     print $b . " " . $d . "\n";
}
?>

<?php
$numberOfRooms = (int)trim(fgets(STDIN));

$count = 0;
for ($i = 0; $i < $numberOfRooms; $i++) {
    $numbers = explode(' ', trim(fgets(STDIN)));
    $first = (int) $numbers[0];
    $last = (int) $numbers[1];
    echo $first. " ". ($first*2) . "\n";
}

<?php
$number = trim(fgets(STDIN));
for ($i=$number; $i > 0 ; $i--) {
    list($x, $y) = explode(' ', trim(fgets(STDIN)));
    echo $x ." ".($x*2)."\n";
    $number--;
}

<?php
function returnDivisible($start, $end)
{
    for ($i = $start; $i <= floor($end/2)  ; $i++) {
        if ($i * 2 <= $end) {
            return [$i, $i * 2];
        }
    }

    return [null, null];
}

$p = fopen('php://stdin', 'r');
$t = intval(fgets($p));
$lines = [];
for ($i = 0; $i < $t; $i++) {
    $lines[] = explode(' ', fgets($p));
}

foreach ($lines as $line) {
    echo returnDivisible($line[0], $line[1])[0] . ' ' . returnDivisible($line[0], $line[1])[1] . PHP_EOL;
}

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	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 readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public 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. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */
$t = $ir->readInt();

for($i=1; $i<=$t; $i++) {
	list($l, $r) = $ir->readArrayOfInt(2);
	echo $l.' '.(2*$l)."\n";
	flush();
}

<?php
$number = trim(fgets(STDIN));
$res[] = 0;
for ($i=$number; $i > 0 ; $i--) {
    list($x, $y) = explode(' ', trim(fgets(STDIN)));
    for ($j=$x; $j < $y ; $j++) {
        if ($y%$j == 0) {
            echo $j ." ".$y."\n";
            break;
        }
    }
    $number--;
}

<?php
$number = trim(fgets(STDIN));
$res[] = 0;
for ($i=$number; $i > 0 ; $i--) {
    list($x, $y) = explode(' ', trim(fgets(STDIN)));
    for ($j=$x; $j <= $y ; $j++) {
        if ($y%$j == 0 && $j != $y) {
            echo $j ." ".$y."\n";
            break;
        }
    }
    $number--;
}


One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n. If a tournir that meets the conditions of the problem does not exist, then print -1.


You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 < b_2 < \ldots < b_n$$$.

Print the minimum total length of the pieces.

NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.


This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.Ujan has two distinct strings $$$s$$$ and $$$t$$$ of length $$$n$$$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions $$$i$$$ and $$$j$$$ ($$$1 \le i,j \le n$$$, the values $$$i$$$ and $$$j$$$ can be equal or different), and swaps the characters $$$s_i$$$ and $$$t_j$$$. Can he succeed?Note that he has to perform this operation exactly once. He has to perform this operation.

The first line contains a single integer $$$k$$$ ($$$1 \leq k \leq 10$$$), the number of test cases. For each of the test cases, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^4$$$), the length of the strings $$$s$$$ and $$$t$$$.  Each of the next two lines contains the strings $$$s$$$ and $$$t$$$, each having length exactly $$$n$$$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.

For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise. You can print each letter in any case (upper or lower).

4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca

NoteIn the first test case, Ujan can swap characters $$$s_1$$$ and $$$t_4$$$, obtaining the word "house".In the second test case, it is not possible to make the strings equal using exactly one swap of $$$s_i$$$ and $$$t_j$$$.

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++) {
    list($k) = explode(' ', trim(fgets(STDIN)));
    list($s1) = explode(' ', trim(fgets(STDIN)));
    list($s2) = explode(' ', trim(fgets(STDIN)));
    $iCountTrue = 0;
    $iCountFalse = 0;
    $aTest1 = [];
    $aTest2 = [];
    $bFlag = true;
    for ($j = 0; $j < $k; $j++){
        if($s1[$j] != $s2[$j] && $iCountFalse <= 2){
            $aTest1[] = [
                'key' => $j,
                'word' => $s1[$j]
            ];
            $aTest2[] = [
                'key' => $j,
                'word' => $s2[$j]
            ];
            $iCountFalse++;
        }
    }
    if($iCountFalse == 2 && ($aTest1[0]['word'] == $aTest1[1]['word'] && $aTest2[0]['word'] == $aTest2[1]['word'])){
        echo "YES"."\n";
    } else {
        echo "NO"."\n";
    }
}

<?php

$q = + trim(fgets(STDIN));

for ($i = 0; $i < $q; $i++){
	$n = + trim(fgets(STDIN));
	$str1 = trim(fgets(STDIN));
	$str2 = trim(fgets(STDIN));

	echo calc($n, $str1, $str2) ? 'YES':'NO';
	echo "\n";

}

function calc($n, $str1, $str2){

	$arr1 = [];$arr2 = [];
	for ($i = 0; $i < $n; $i++){
		if($str1[$i] != $str2[$i]){
			$arr1[] = $str1[$i];
			$arr2[] = $str2[$i];
		}
	}
	$str1 = implode('', $arr1);
	$str2 = implode('', $arr2);

	if(strlen($str1) == 2 && $str1[0] == $str1[1] && $str2[0] == $str2[1]){
		return true;
	}
	return false;

}

<?php
$k = intval(fgets(STDIN));
for($i = 0; $i < $k; $i++)
{
    $n = intval(fgets(STDIN));
    $repeats = array();
    $s1 = fgets(STDIN);
    $s2 = fgets(STDIN);
    $arS1 = str_split($s1);
    $arS2 = str_split($s2);
    $diff1 = array_diff_assoc($arS1, $arS2);
    $diff2 = array_diff_assoc($arS2, $arS1);
    $succ = false;
    if(count($diff1) == 2) {
        $first = reset($diff1);
        $second = array_pop($diff1);
        $third = reset($diff2);
        $fourth = array_pop($diff2);
        if($first == $second && $third == $fourth)
            $succ = true;
    }

    $res = ($succ) ? "YES\n" : "NO\n";
    echo $res;

}?>

<?php
fscanf(STDIN,"%d\n",$tc);
while ($tc--)
{
	fscanf(STDIN,"%d\n",$lengthOfStr);
	$str1=trim(fgets(STDIN));
	$str2=trim(fgets(STDIN));
    $cnt=0;
    $j=0;
    $a=array();
    $b=array();
	for ($i=0; $i <$lengthOfStr ; $i++)
	{
		if($str1[$i]!=$str2[$i])
		{
			$cnt++;
			$a[$j]=$str1[$i];
			$b[$j]=$str2[$i];
			$j++;
			if($cnt>2)
			break;
		}

	}
	if($cnt==2&&$a[0]==$a[1]&&$b[0]==$b[1])
		echo "Yes\n";
	else
		echo "No\n";
}

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

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray)-2; $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
            array_push($response, "YES");
        } else {
            array_push($response, "NO");
        }
    }

    echo implode(PHP_EOL, $response);

    function countDifferencesAndValidate($length, $word_1, $word_2)
    {
        $charactersOfWord_1 = str_split($word_1);
        $charactersOfWord_2 = str_split($word_2);

        $counter = 0;
        $differencesArray = array();
        for ($i = 0; $i < $length; $i++) {
            if ($charactersOfWord_1[$i] != $charactersOfWord_2[$i]) {
                $counter++;
                $differencesArray[$i] = array('word_1' => $charactersOfWord_1[$i], 'word_2' => $charactersOfWord_2[$i]);
            }

            if ($counter > 2) {
                return false;
            }
        }

        if ($counter == 2) {
            $status = validateDifferences($differencesArray);

            return $status;
        } else {
            return false;
        }
    }

    function validateDifferences($inputArray)
    {
        $keys = array_keys($inputArray);
        if ($inputArray[$keys[0]]['word_1'] == $inputArray[$keys[1]]['word_1'] &&
            $inputArray[$keys[0]]['word_2'] == $inputArray[$keys[1]]['word_2']) {
            return true;
        }

        return false;
    }

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

//bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray)-2; $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
            array_push($response, "YES");
        } else {
            array_push($response, "NO");
        }
    }

    echo implode(PHP_EOL, $response);

    function countDifferencesAndValidate($length, $word_1, $word_2)
    {
        $charactersOfWord_1 = str_split($word_1);
        $charactersOfWord_2 = str_split($word_2);

        $counter = 0;
        $differencesArray = array();
        for ($i = 0; $i < $length; $i++) {
            if ($charactersOfWord_1[$i] != $charactersOfWord_2[$i]) {
                $counter++;
                $differencesArray[$i] = array('word_1' => $charactersOfWord_1[$i], 'word_2' => $charactersOfWord_2[$i]);
            }

            if ($counter > 2) {
                return false;
            }
        }

        if ($counter == 2) {
            $status = validateDifferences($differencesArray);

            return $status;
        } else {
            return false;
        }
    }

    function validateDifferences($inputArray)
    {
        $keys = array_keys($inputArray);
        if ($inputArray[$keys[0]]['word_1'] == $inputArray[$keys[1]]['word_1'] &&
            $inputArray[$keys[0]]['word_2'] == $inputArray[$keys[1]]['word_2']) {
            return true;
        }

        return false;
    }

<?php
    $dir = fopen("php://stdin", 'r');
    $input = stream_get_contents($dir);
//    $input = '4
//5
//souse
//houhe
//3
//cat
//dog
//2
//aa
//az
//3
//abc
//bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray)-2; $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
            array_push($response, "YES");
        } else {
            array_push($response, "NO");
        }
    }

    echo implode(PHP_EOL, $response);

    function countDifferencesAndValidate($length, $word_1, $word_2)
    {
        $charactersOfWord_1 = str_split($word_1);
        $charactersOfWord_2 = str_split($word_2);

        $counter = 0;
        $differencesArray = array();
        for ($i = 0; $i < $length; $i++) {
            if ($charactersOfWord_1[$i] != $charactersOfWord_2[$i]) {
                $counter++;
                $differencesArray[$i] = array('word_1' => $charactersOfWord_1[$i], 'word_2' => $charactersOfWord_2[$i]);
            }

            if ($counter > 2) {
                return false;
            }
        }

        if ($counter == 2) {
            $status = validateDifferences($differencesArray);

            return $status;
        } else {
            return false;
        }
    }

    function validateDifferences($inputArray)
    {
        $keys = array_keys($inputArray);
        if ($inputArray[$keys[0]]['word_1'] == $inputArray[$keys[1]]['word_1'] &&
            $inputArray[$keys[0]]['word_2'] == $inputArray[$keys[1]]['word_2']) {
            return true;
        }

        return false;
    }

<?php

$n = trim(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    $x = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $b = str_split(trim(fgets(STDIN)));
    $aR = $bR = array();
    $bool = "Yes";
    for($j = 0; $j < $x; $j++){
        if($a[$j] != $b[$j]){
            $aR[] = $a[$j];
            $bR[] = $b[$j];
        }
        if(count($aR) > 2 || count($bR) > 2){
            $bool = "No";
            break;
        }
    }

    if(count($aR) == 1){
            $bool = "No";
        }

    if($bool == "Yes"){
        $r1 = array_unique($aR);
        $r2 = array_unique($bR);
        if(count($r1) > 1 || count($r2) > 1){
            $bool = "No";
        }
    }
    echo $bool."\n";

}

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $t = trim(fgets($handle));
    for($i=0;$i<$t;$i++)
    {
        $arr=array();
        $d = trim(fgets($handle));

        $str1 = trim(fgets($handle));
        $str2 = trim(fgets($handle));

        $arr=array();
        $ans=1;
        for ($h=0;$h<$d;$h++) {
            if($str1[$h]!=$str2[$h])
            {
                $arr[]=$str1[$h].$str2[$h];
            }
        }

            if(sizeof($arr)==2 && $arr[0]==$arr[1])
             printf("%s\n","Yes");
         else
             printf("%s\n","No");

    }

}

solve();
?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++) {
    list($k) = explode(' ', trim(fgets(STDIN)));
    list($s1) = explode(' ', trim(fgets(STDIN)));
    list($s2) = explode(' ', trim(fgets(STDIN)));
    $iCountTrue = 0;
    $iCountFalse = 0;
    $bFlag = true;
    for ($j = 0; $j < $k; $j++){
        if($s1[$j] != $s2[$j]){
            $iCountFalse++;
        } else {
            $iCountTrue++;
        }
    }
    if($iCountFalse == 2 && $k != $iCountFalse){
        echo "YES"."\n";
    } else {
        echo "NO"."\n";
    }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++) {
    list($k) = explode(' ', trim(fgets(STDIN)));
    list($s1) = explode(' ', trim(fgets(STDIN)));
    list($s2) = explode(' ', trim(fgets(STDIN)));
    $iCountTrue = 0;
    $iCountFalse = 0;
    $aTest1 = [];
    $aTest2 = [];
    $bFlag = true;
    for ($j = 0; $j < $k; $j++){
        if($s1[$j] != $s2[$j]){
            $aTest1[] = $s1[$j];
            $aTest2[] = $s2[$j];
            $iCountFalse++;
        } else {
            $iCountTrue++;
        }
    }
    if($iCountFalse == 2 && $k != $iCountFalse && ($aTest1[0] == $aTest1[1] && $aTest2[1] == $aTest2[0])){
        echo "YES"."\n";
    } else {
        echo "NO"."\n";
    }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++) {
    list($k) = explode(' ', trim(fgets(STDIN)));
    list($s1) = explode(' ', trim(fgets(STDIN)));
    list($s2) = explode(' ', trim(fgets(STDIN)));
    $iCountTrue = 0;
    $iCountFalse = 0;
    $aTest1 = [];
    $aTest2 = [];
    $bFlag = true;
    for ($j = 0; $j < $k; $j++){
        if($s1[$j] != $s2[$j] && $iCountFalse <= 2){
            $aTest1[] = [
                'key' => $j,
                'word' => $s1[$j]
            ];
            $aTest2[] = [
                'key' => $j,
                'word' => $s2[$j]
            ];
            $iCountFalse++;
        }
    }
    if($iCountFalse == 2 && $k != $iCountFalse && ($aTest1[0]['word'] == $aTest1[1]['word'] && $aTest2[1]['word'] == $aTest2[0]['word'])){
        $s1[$aTest1[0]['key']] = $aTest2[0]['word'];
        $s2[$aTest2[1]['key']] = $aTest1[1]['word'];
        if($s1 == $s2){
            echo "YES"."\n";
        } else {
            echo "NO"."\n";
        }
    } else {
        echo "NO"."\n";
    }
}

<?php
$k = intval(fgets(STDIN));
for($i = 0; $i < $k; $i++)
{
    $n = intval(fgets(STDIN));
    $repeats = array();
    $s1 = fgets(STDIN);
    $s2 = fgets(STDIN);
    $arS1 = str_split($s1);
    $arS2 = str_split($s2);
    $diff1 = array_diff_assoc($arS1, $arS2);
    $diff2 = array_diff_assoc($arS2, $arS1);
    print_r($diff1);
    $succ = false;
    if(count($diff1) == 2) {
        $first = reset($diff1);
        $second = array_pop($diff1);
        $third = reset($diff2);
        $fourth = array_pop($diff2);
        if($first == $second && $third == $fourth)
            $succ = true;
    }

    $res = ($succ) ? "YES\n" : "NO\n";
    echo $res;

}?>

<?php
fscanf(STDIN,"%d\n",$tc);
while ($tc--)
{
	fscanf(STDIN,"%d\n",$lengthOfStr);
	$str1=trim(fgets(STDIN));
	$str2=trim(fgets(STDIN));
    $cnt=0;
    $j=0;
    $a=array();
    $b=array();
	for ($i=0; $i <$lengthOfStr ; $i++)
	{
		if($str1[$i]!=$str2[$i])
		{
			$cnt++;
			$a[$j]=$str1[$i];
			$b[$j]=$str2[$i];
			$j++;
		}
		if($cnt==2)
			break;
	}
	if($cnt==2&&$a[0]==$a[1]&&$b[0]==$b[1])
		echo "Yes\n";
	else
		echo "No\n";
}

<?php
    $dir = fopen("php://stdin", 'r');
    $input = stream_get_contents($dir);
    //    $input = '4
    //5
    //souse
    //houhe
    //3
    //cat
    //dog
    //2
    //aa
    //az
    //3
    //abc
    //bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray); $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
            array_push($response, "YES");
        } else {
            array_push($response, "NO");
        }
    }

    echo implode(PHP_EOL, $response);

    function countDifferencesAndValidate($length, $word_1, $word_2)
    {
        $charactersOfWord_1 = str_split($word_1);
        $charactersOfWord_2 = str_split($word_2);

        $counter = 0;
        $differencesArray = array();
        for ($i = 0; $i < $length; $i++) {
            if ($charactersOfWord_1[$i] != $charactersOfWord_2[$i]) {
                $counter++;
                $differencesArray[$i] = array('word_1' => $charactersOfWord_1[$i], 'word_2' => $charactersOfWord_2[$i]);
            }

            if ($counter > 2) {
                return false;
            }
        }

        if ($counter == 2) {
            $status = validateDifferences($differencesArray);

            return $status;
        } else {
            return false;
        }
    }

    function validateDifferences($inputArray)
    {
        $keys = array_keys($inputArray);
        if ($inputArray[$keys[0]]['word_1'] == $inputArray[$keys[1]]['word_1'] &&
            $inputArray[$keys[0]]['word_2'] == $inputArray[$keys[1]]['word_2']) {
            return true;
        }

        return false;
    }

<?php
        $dir = fopen("php://stdin", 'r');
        $input = stream_get_contents($dir);
//    $input = '4
//5
//souse
//houhe
//3
//cat
//dog
//2
//aa
//az
//3
//abc
//bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray); $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
//        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
//            $response[] = "YES";
//        } else {
//            $response[] = "NO";
//        }
    }

    echo 1; exit();

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

<?php
    $dir = fopen("php://stdin", 'r');
    $input = stream_get_contents($dir);
    //    $input = '4
    //5
    //souse
    //houhe
    //3
    //cat
    //dog
    //2
    //aa
    //az
    //3
    //abc
    //bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray); $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    $response = array();
    foreach ($casesArray as $case) {
        if (countDifferencesAndValidate($case['length'], $case['word_1'], $case['word_2'])) {
            array_push($response, "YES");
        } else {
            array_push($response, "NO");
        }
    }

    echo implode(' ', $response);

    function countDifferencesAndValidate($length, $word_1, $word_2)
    {
        $charactersOfWord_1 = str_split($word_1);
        $charactersOfWord_2 = str_split($word_2);

        $counter = 0;
        $differencesArray = array();
        for ($i = 0; $i < $length; $i++) {
            if ($charactersOfWord_1[$i] != $charactersOfWord_2[$i]) {
                $counter++;
                $differencesArray[$i] = array('word_1' => $charactersOfWord_1[$i], 'word_2' => $charactersOfWord_2[$i]);
            }

            if ($counter > 2) {
                return false;
            }
        }

        if ($counter == 2) {
            $status = validateDifferences($differencesArray);

            return $status;
        } else {
            return false;
        }
    }

    function validateDifferences($inputArray)
    {
        $keys = array_keys($inputArray);
        if ($inputArray[$keys[0]]['word_1'] == $inputArray[$keys[1]]['word_1'] &&
            $inputArray[$keys[0]]['word_2'] == $inputArray[$keys[1]]['word_2']) {
            return true;
        }

        return false;
    }

<?php
        $dir = fopen("php://stdin", 'r');
        $input = stream_get_contents($dir);
//    $input = '4
//5
//souse
//houhe
//3
//cat
//dog
//2
//aa
//az
//3
//abc
//bca';

    $inputArray = explode(PHP_EOL, $input);

    $casesArray = array();
    $nrCases = (int)array_shift($inputArray);
    for ($i = 0, $count = 1; $i < count($inputArray); $i += 3) {
        $casesArray[$count++] = array(
            'length' => (int)$inputArray[$i],
            'word_1' => $inputArray[$i + 1],
            'word_2' => $inputArray[$i + 2]
        );
    }

    var_dump($casesArray);exit();

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $t = trim(fgets($handle));
    for($i=0;$i<$t;$i++)
    {
        $arr=array();
        $d = trim(fgets($handle));

        $str1 = trim(fgets($handle));
        $str2 = trim(fgets($handle));
        $str1map=array();
        $str2map=array();
        for ($h=0;$h<$d;$h++)
        {
            if(isset($str1map[$str1[$h]])) {
                $str1map[$str1[$h]] = $str1map[$str1[$h]] + 1;
            }else
            {
                $str1map[$str1[$h]]=0;
            }
            if(isset($str2map[$str2[$h]])) {
                $str2map[$str2[$h]] = $str2map[$str2[$h]] + 1;
            }else
            {
                $str2map[$str2[$h]]=0;
            }

        }
        $arr=array();
        $ans=0;
        for ($h=0;$h<$d;$h++) {

            if ($str1[$h] != $str2[$h] && $str1map[$str1[$h]] == $str2map[$str2[$h]] && $str1map[$str1[$h]] == 1)
                $ans = 1;
        }
            if($ans==1)
             printf("%s\n","Yes");
         else
             printf("%s\n","No");

    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $t = trim(fgets($handle));
    for($i=0;$i<$t;$i++)
    {
        $arr=array();
        $d = trim(fgets($handle));

        $str1 = trim(fgets($handle));
        $str2 = trim(fgets($handle));
        $str1map=array();
        $str2map=array();
        for ($h=0;$h<$d;$h++)
        {
            if(isset($str1map[$str1[$h]])) {
                $str1map[$str1[$h]] = $str1map[$str1[$h]] + 1;
            }else
            {
                $str1map[$str1[$h]]=0;
            }
            if(isset($str2map[$str2[$h]])) {
                $str2map[$str2[$h]] = $str2map[$str2[$h]] + 1;
            }else
            {
                $str2map[$str2[$h]]=0;
            }

        }
        $arr=array();
        $ans=1;
        for ($h=0;$h<$d;$h++) {
            if ($str1[$h] != $str2[$h] && $str1map[$str1[$h]] == $str2map[$str2[$h]] && $str1map[$str1[$h]] >0)
                $ans = 1;
            else if($str1[$h]==$str2[$h]){
                $ans=1;
            }else
            {
                $ans=0;
            }
        }
            if($ans==1)
             printf("%s\n","Yes");
         else
             printf("%s\n","No");

    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($local, "r");
    $s="";$d=0;$t=0;
    $t = trim(fgets($handle));
    for($i=0;$i<$t;$i++)
    {
        $arr=array();
        $d = trim(fgets($handle));

        $str1 = trim(fgets($handle));
        $str2 = trim(fgets($handle));

        $arr=array();
        $ans=1;
        for ($h=0;$h<$d;$h++) {
            if($str1[$h]!=$str2[$h])
            {
                $arr[]=$str1[$h].$str2[$h];
            }
        }

            if(sizeof($arr)==2 && $arr[0]==$arr[1])
             printf("%s\n","Yes");
         else
             printf("%s\n","No");

    }

}

solve();
?>


You are given an array $$$a$$$ with $$$n$$$ integers. You can perform the following operation at most $$$k$$$ times:  Choose two indices $$$i$$$ and $$$j$$$, in which $$$i \,\bmod\, k = j \,\bmod\, k$$$ ($$$1 \le i < j \le n$$$).  Swap $$$a_i$$$ and $$$a_j$$$. After performing all operations, you have to select $$$k$$$ consecutive elements, and the sum of the $$$k$$$ elements becomes your score. Find the maximum score you can get.Here $$$x \bmod y$$$ denotes the remainder from dividing $$$x$$$ by $$$y$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$) — the number of test cases. Each test case consists of two lines.  The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the length of the array and the number in the statement above. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$)  — the array itself.

For each test case, print the maximum score you can get, one per line.

NoteIn the first test case, we can get a score of $$$11$$$ if we select $$$a_1, a_2$$$ without performing any operations.In the third test case, we can get a score of $$$15$$$ if we first swap $$$a_1$$$ with $$$a_4$$$ and then select $$$a_3, a_4, a_5$$$.

<?php

$t=trim(fgets(STDIN));
while($t--)
{
     list($n,$k)=explode(' ',trim(fgets(STDIN)));
     $a=explode(' ',trim(fgets(STDIN)));
     $ans=0;
     for($i=0;$i<$k;$i++)
     {
          $s=0;
          for($j=$i;$j<$n;$j+=$k)
               $s=max($s,$a[$j]);
          $ans+=$s;
     }
     echo $ans."\n";
}
?>

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

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

   list($n, $k) = IO::getArray();
   $a = IO::getArray();
     if($n > $k) {
        for ($i=0; $i<$k; $i++) {
           for ($j=$k+$i; $j<$n; $j +=$k) {
               if($a[$i] < $a[$j]) {
                    $a[$i] = $a[$j];
               }
           }
        }
     }

     $ans = 0;
     for ($i=0; $i<$k; $i++) {
        $ans = bcadd($ans, $a[$i]);
     }
     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;
    }
}


General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.

The first line contains two integers n, k (1 ≤ n ≤ 50; 1 ≤ k ≤  ) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the beauties of the battalion soldiers. It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.

Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 ≤ ci ≤ n) — the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i — the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order. Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.


Polycarp likes arithmetic progressions. A sequence $$$[a_1, a_2, \dots, a_n]$$$ is called an arithmetic progression if for each $$$i$$$ ($$$1 \le i < n$$$) the value $$$a_{i+1} - a_i$$$ is the same. For example, the sequences $$$[42]$$$, $$$[5, 5, 5]$$$, $$$[2, 11, 20, 29]$$$ and $$$[3, 2, 1, 0]$$$ are arithmetic progressions, but $$$[1, 0, 1]$$$, $$$[1, 3, 9]$$$ and $$$[2, 3, 1]$$$ are not.It follows from the definition that any sequence of length one or two is an arithmetic progression.Polycarp found some sequence of positive integers $$$[b_1, b_2, \dots, b_n]$$$. He agrees to change each element by at most one. In the other words, for each element there are exactly three options: an element can be decreased by $$$1$$$, an element can be increased by $$$1$$$, an element can be left unchanged.Determine a minimum possible number of elements in $$$b$$$ which can be changed (by exactly one), so that the sequence $$$b$$$ becomes an arithmetic progression, or report that it is impossible.It is possible that the resulting sequence contains element equals $$$0$$$.

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100\,000)$$$ — the number of elements in $$$b$$$. The second line contains a sequence $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le 10^{9})$$$.

If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't use operation twice to the same position).

NoteIn the first example Polycarp should increase the first number on $$$1$$$, decrease the second number on $$$1$$$, increase the third number on $$$1$$$, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to $$$[25, 20, 15, 10]$$$, which is an arithmetic progression.In the second example Polycarp should not change anything, because his sequence is an arithmetic progression.In the third example it is impossible to make an arithmetic progression.In the fourth example Polycarp should change only the first element, he should decrease it on one. After that his sequence will looks like $$$[0, 3, 6, 9, 12]$$$, which is an arithmetic progression.

<?php
/**
 * Created by PhpStorm.
 * User: jianzjzhang
 * Date: 2018/5/13
 * Time: 18:32
 */

function minChange($arr)
{
    if(count($arr) < 3){
        return 0;
    }

    $min_count = count($arr) + 1;

    foreach ([-1, 0, 1] as $i){
        foreach ([-1, 0, 1] as $j){
            $first = $arr[0] + $i;
            $second = $arr[1] + $j;

            $counter = 0;

            if($i != 0) $counter++;
            if($j != 0) $counter++;

            $diff = $second - $first;

            $cur = $second;
            $flag = true;
            for($k=1; $k<count($arr)-1; $k++){
                if(($cur + $diff == $arr[$k+1])
                    || ($cur + $diff == $arr[$k+1] - 1)
                    || ($cur + $diff == $arr[$k+1] + 1)){

                    if(!($cur + $diff == $arr[$k+1])){
                        $counter++;
                    }
                    $cur += $diff;
                }
                else{
                    $flag = false;
                    break;
                }
            }

            if($flag){
                $min_count = min($min_count, $counter);
            }
        }
    }

    if($min_count == count($arr) + 1) return -1;
    return $min_count;
}

function main()
{
    $n = intval(fgets(STDIN));
    $arr = array();
    for($i=0; $i<$n-1; $i++){
        $arr[] = intval(stream_get_line(STDIN, 4096, " "));
    }
    $arr[] = intval(stream_get_line(STDIN, 4096, "\n"));

    echo minChange($arr)."\n";
}

main();

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}

				if($count <= 0 || ($count > $tryCount && $tryCount != -1))
				{
					$count = $tryCount;
				}

				if($tryCount == 0)
				{
					break;
				}
			}

			if($count == 0)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1($sequence);

//echo sequence1(explode(' ', '1 3 6 9 12'));

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$tryCount = 0;
			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}

				if($count == 0 || $count > $tryCount)
				{
					$count = $tryCount;
				}

				if($tryCount != -1)
				{
					break;
				}
			}

			if($tryCount == 0)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1($sequence);

//echo sequence1(explode(' ', '24 21 14 10'));

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$tryCount = 0;
			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}
			}

			$count = $tryCount;

			if($tryCount != -1)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1(sequence);

<?php

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

function check($numbers)
{
    $needChange = 0;

    if (count($numbers) > 2) {

        $diff = $numbers[1] - $numbers[0];

        for ($i = 2; $i < count($numbers); $i++) {

            $prevDiff = $diff;
            $diff = $numbers[$i] - $numbers[$i - 1];

            $c = abs($prevDiff - $diff);

            if ($c <= 4) {
                $needChange += floor($c / 2);
            } else {
                $needChange = -1;
                break;
            }
        }
    }

    echo $needChange, PHP_EOL;
}

fscanf($handle, "%i", $n);

$numbers = explode(' ', fgets($handle));

check($numbers);

<?php

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

function sequence($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

        $a1 = $sequence[0];
        $a2 = $sequence[1];

        $found = false;

        $d1 = 0;
        $d2 = 0;
        $minDiff = null;

        // define first elements
        for ($i = -1; $i < 2; $i++) {

            $a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;
                $r = abs($sequence[2] - ($a1 + 2 * ($a2 - $a1)));

                if ($r <= 1 && ($minDiff === null || $r < $minDiff)) {

                    $found = true;

                    $minDiff = $r;
                    $d1 = $i;
                    $d2 = $j;
                }
            }
        }

        if ($found) {

            $a1 = $sequence[0] + $d1;
            $a2 = $sequence[1] + $d2;

            $count = abs($d1) + abs($d2);

            for ($i = 2; $i < count($sequence); $i++) {

                $diff = abs($sequence[$i] - ($a1 + $i * ($a2 - $a1)));

                if ($diff > 1) {
                    $count = -1;
                    break;
                } else {
                    $count += $diff;
                }
            }

        } else {
            $count = -1;
        }

    }

    return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));

echo sequence($sequence);

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$tryCount = 0;
			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}

				if($count <= 0 || ($count > $tryCount && $tryCount != -1))
				{
					$count = $tryCount;
				}
			}

			if($tryCount == 0)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1($sequence);

//echo sequence1(explode(' ', '24 21 14 10'));

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$tryCount = 0;
			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}

				if($count <= 0 || $count > $tryCount)
				{
					$count = $tryCount;
				}

				if($tryCount != -1)
				{
					break;
				}
			}

			if($tryCount == 0)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1($sequence);

//echo sequence1(explode(' ', '24 21 14 10'));

<?php

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

function sequence1($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

		// define first elements
        for ($i = -1; $i < 2; $i++) {

			$tryCount = 0;
			$a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;

				$tryCount = abs($i) + abs($j);

				for ($k = 2; $k < count($sequence); $k++) {

					$diff = abs($sequence[$k] - ($a1 + $k * ($a2 - $a1)));

					if ($diff > 1) {
						$tryCount = -1;
						break;
					} else {
						$tryCount += $diff;
					}
				}

				$count = $tryCount;

				if($tryCount != -1)
				{
					break;
				}
			}

			if($tryCount != -1)
			{
				break;
			}
		}

	}

	return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));
echo sequence1($sequence);

//echo sequence1(explode(' ', '24 21 14 10'));

<?php

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

function sequence($sequence)
{
    $count = 0;

    if (count($sequence) > 2) {

        $a1 = $sequence[0];
        $a2 = $sequence[1];

        $found = false;

        // define first elements
        for ($i = -1; $i < 2 && !$found; $i++) {

            $a1 = $sequence[0] + $i;

            for ($j = -1; $j < 2; $j++) {

                $a2 = $sequence[1] + $j;
                $r = abs($sequence[2] - ($a1 + 2 * ($a2 - $a1)));

                if ($r <= 1) {

                    $found = true;
                    $count += abs($i) + abs($j) + $r;
                    break;
                }
            }
        }

        if ($found) {

            for ($i = 3; $i < count($sequence); $i++) {

                $diff = abs($sequence[$i] - ($a1 + $i * ($a2 - $a1)));

                if ($diff > 1) {
                    $count = -1;
                    break;
                } else {
                    $count += $diff;
                }
            }

        } else {
            $count = -1;
        }

    }

    return $count;
}

fscanf($handle, "%i", $n);

$sequence = array_map('intval', explode(' ', trim(fgets($handle))));

echo sequence($sequence);