John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$) — the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$.

Print the rank of Thomas Smith. Thomas's id is $$$1$$$.

NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$.

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 0; $x < $a; $x++)
{
     $c = array_sum(explode(" ", trim(fgets(STDIN))));
     define(d, $c);
     $b[$x] = $c;
}
rsort($b);
for($x = 0; $x < $a; $x++)
{
     if($b[$x] == d)
     {
          print $x + 1;
          break;
     }
}
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
array_multisort(array_column($aPoints, 'sum'), SORT_DESC,
    array_column($aPoints, 'id'),      SORT_ASC,
    $aPoints);

for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            echo $i+1;
            break;
        }
    }
}

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? 1 : -1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
$x = 0;
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}
$x = $s[0];
rsort($s);
echo array_search($x, $s) + 1;
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        $a,
        $b,
        $c,
        $d,
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0 && !$sergey){
            $sergey = $i+1;
            echo $sergey;
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
usort($aPoints, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            $sergey = $i +1;
            break;
        }
    }
}
echo $sergey;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        $a,
        $b,
        $c,
        $d,
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0){
            $sergey = $i;
        }
    }
}
echo $sergey+1;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        intval($a),
        intval($b),
        intval($c),
        intval($d),
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0){
            $sergey = $i;
        }
    }
}
echo $sergey+1;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
usort($aPoints, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            echo $i+1;
            break;
        }
    }
}
?>

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($a);
}

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 1;
foreach($aCount AS $iK => $iC) {
    if($iK === 1) {
        break;
    }
    $iCount++;
}

echo $iCount;
?>

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? 1 : -1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $aData[$i] = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($aData[$i]);
}
$iMax = -1;
$iMaxIndex = -1;
foreach($aCount AS $indexC => $iC) {
    if($iMax <= $iC) {
        $iMax = $iC;
        $iMaxIndex = $indexC;
    }
}

echo $iMaxIndex;
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($a);
}

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
print_r($aCount);
$iCount = 1;
foreach($aCount AS $iK => $iC) {
    if($iK === 1) {
        break;
    }
    $iCount++;
}

echo $iCount;

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $aData[$i] = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($aData[$i]);
}
$iMax = -1;
$iMaxIndex = -1;
foreach($aCount AS $indexC => $iC) {
    if($iMax < $iC) {
        $iMax = $iC;
        $iMaxIndex = $indexC;
    }
}

echo $iMaxIndex;
?>

<?php
$n = fgets(STDIN);
$n = (int)$n;

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? -1 : 1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}

rsort($s);
echo array_search(array_sum($a), $s) + 1;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));

$s = array(
    array_sum($a),
    array_sum($b),
    array_sum($c),
    array_sum($d),
    array_sum($e)
);

rsort($s);
echo array_search(array_sum($a), $s) + 1;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
$x = 0;
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}
$x = $s[0];
rsort($s);
echo array_search(array_sum($a), $x) + 1;
?>


You have decided to watch the best moments of some movie. There are two buttons on your player:   Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.  Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x). Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button. The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space li, ri (1 ≤ li ≤ ri ≤ 105). It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

Output a single number — the answer to the problem.

NoteIn the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

<?php
list($n, $x) = explode(" ", trim(fgets(STDIN)));

	 $t = 1;
 $ans = 0;
	while($n>0) {
		list($l, $r) = explode(" ", trim(fgets(STDIN)));

		$t = $l - ($l - $t) % $x;
		$ans += $r - $t + 1;

		$t = $r + 1;
	$n--;}
	echo $ans;

?>

<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$x=1;
while($n>0){
    list($l,$r)=explode(" ",trim(fgets(STDIN)));
    $x=$l-($l-$x)%$m;
    $ans+=$r-$x+1;
    $x=$r+1;
    $n--;
}
echo $ans;
?>

<?php
    list($n,$x) = explode(" ", trim(fgets(STDIN)));
    $s = 1;
    $ans = 0;
    while($n > 0){
        list($l,$r) = explode(" ", trim(fgets(STDIN)));
        $s = $l - ($l -$s) % $x;
        $ans += $r - $s + 1;

        $s = $r + 1;
        $n --;
    }
    echo $ans;
?>

<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$x=0;
while($n>0){
    list($l,$r)=explode(" ",trim(fgets(STDIN)));
    $x=$l-($l-$x)%$m;
    $ans+=$r-$x;
    $x=$r;
    $n--;
}
echo $ans;
?>


You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times:  Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»);  Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.What is the minimum number of coins you need to spend to get a string consisting only of ones?

The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.

NoteIn the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».The total cost of operations is $$$1 + 10 = 11$$$.In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «11000» $$$\to$$$ «11111».The overall cost is $$$1 + 1 = 2$$$.In the third example, string already consists only of ones, so the answer is $$$0$$$.


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:   replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);  swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.

The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.

Print on the single line the single number — the minimum number of operations needed to convert string a into string b.

NoteIn the first sample it is enough simply to swap the first and the second digit.In the second sample we should replace the second digit with its opposite.In the third number we should replace all three digits with their opposites.


Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.Vasya also believes that if the phone number a is a suffix of the phone number b (that is, the number b ends up with a), and both numbers are written by Vasya as the phone numbers of the same person, then a is recorded without the city code and it should not be taken into account.The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers x and y, and x is a suffix of y (that is, y ends in x), then you shouldn't print number x. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.Read the examples to understand statement and format of the output better.

First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books.  The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.

Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend. Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.


The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).

The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are:    1 ≤ n ≤ 300  The input limitations for getting 50 points are:    1 ≤ n ≤ 2000  The input limitations for getting 100 points are:    1 ≤ n ≤ 105

Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$N = (int)$Input->in();
	for ($i = 1; $i <= $N; $i++) $A[$i] = (int)$Input->in();

	$sum = 0;
	for ($k = 1; $k <= $N - 1; $k++) {
		$pow = 2;
		//while ($A[$k] + $pow < $N) {
		while ($k + $pow <= $N) $pow *= 2;

		$A[$k + $pow / 2] += $A[$k];
		$sum += $A[$k];
		$A[$k] = 0;

		print($sum."\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Character;
import java.lang.Long;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Arrays;

public class TaskC {
	BufferedReader reader;
	StringTokenizer tokenizer = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		new TaskC().run();
	}

	private void run() throws IOException {
		tokenizer = null;
		reader = new BufferedReader(new InputStreamReader(System.in));
		solve();
	}

	public static int divide_by_two(int x, int y){

		if (y == 0) return 0;

		x = x - y;
		int r = 1;
		int c = 0;
		while(x != 0){
			r = x % 2;
			x = (int)(x / 2);
			if (r == 1) c++;
		}
		return c;
	}

	private void solve() throws IOException {
		int N = nextInt();
		int[] A = new int[Integer.MAX_VALUE];
		int[] dp = new int[N];
		int[] ans = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = 0;
		}
		for (int i = 0; i < dp.length; i++) {
			dp[i] = 0;
			ans[i] = 0;
		}
		for (int i = 1; i <= N; i++) A[i] = nextInt();

		for (int k = N - 1; k >= 1; k--) {
			int sum = 0;
			for (int index = 1; index <= k; index++) {
				int min = Integer.MAX_VALUE;
				int temp = 0;
				for (int n = N; n >= k + 1; n--) {
					if (dp[index] > n) {
						min = 1;
					sum += A[index];
					break;
				} else {
					temp = divide_by_two(n, index);
					min = Math.min(min, temp);
					if (min == 1) {
						sum += A[index];
						dp[index] = n;
						break;
					}
				}
			}
			if (min != 1) sum += A[index] * min;
		}
		ans[k] = sum;
	}

		for (int i = 1; i <= N - 1; i++) {
			System.out.print(ans[i]);
			if (i != N - 1) System.out.print("\n");
		}
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
}

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$N = (int)$Input->in();
	for ($i = 1; $i <= $N; $i++) $A[$i] = (int)$Input->in();

	$sum = 0;
	for ($k = 1; $k <= $N - 1; $k++) {

		$pow = 2;
		while ($A[$k] + $pow <= $N) {
			$pow *= 2;
		}

		$A[$k + $pow / 2] += $A[$k];
		$sum += $A[$k];
		$A[$k] = 0;

		print($sum);
		if ($i !== $N - 2) print("\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>


Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

Output one integer  — the maximum number of breaks.

NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.


Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.

The first line of the input data contains an integer n (1 ≤ n ≤ 105). The second line contains an array of original integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).

Print on the single line the answer to the problem: the amount of subarrays, which are magical. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).

NoteNotes to sample tests:Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].


There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.

The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 1 ≤ s ≤ n) — the number of workers and the id of the chief. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.

Print the minimum number of workers that could make a mistake.

NoteIn the first example it is possible that only the first worker made a mistake. Then:   the immediate superior of the first worker is the second worker,  the immediate superior of the third worker is the first worker,  the second worker is the chief.


Valera loves his garden, where n fruit trees grow.This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.  Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.

Print a single integer — the maximum number of fruit that Valera can collect.

NoteIn the first sample, in order to obtain the optimal answer, you should act as follows.   On the first day collect 3 fruits from the 1-st tree.  On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.  On the third day collect the remaining fruits from the 2-nd tree.  In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.

<?php
	$in = 'php://stdin';
	//$in = 'inputB.txt';

	$input = fopen($in, "r");

    list($n, $v) = explode(" ", trim(fgets($input)));

    $matrix = Array();
    $sum = 0;

    for ($i=0;$i<=3001;$i++) {
    	$matrix[$i] = 0;
    }

    for ($i=0;$i<$n;$i++) {
    	list($a, $b) = explode(" ", trim(fgets($input)));

    	$matrix[$a] += $b;
    }

    for($i=1;$i<=3001;$i++) {
    	$delta = min($v, $matrix[$i-1]);
    	$sum += $delta;
    	$matrix[$i-1] -= $delta;

    	$newv = $v - $delta;

    	$delta = min($newv, $matrix[$i]);
    	$sum += $delta;
    	$matrix[$i] -= $delta;
    }

    echo $sum;
?>

<?php
	$in = 'php://stdin';
	//$in = 'inputB.txt';

	$input = fopen($in, "r");

    list($n, $v) = explode(" ", trim(fgets($input)));

    $matrix = Array();

    for ($i=0;$i<$n;$i++) {
    	list($a, $b) = explode(" ", trim(fgets($input)));

		if (!array_key_exists($a, $matrix)) $matrix[$a]=0;

    	$matrix[$a] += $b;
    }
    $matrix[0] = 0;
    $matrix[3001] = 0;
    ksort($matrix);
    $days = array_keys($matrix);
    $sum = 0;

    for($i=1;$i<count($days);$i++) {
    	$delta = min($v, $matrix[$days[$i-1]]);
    	$sum += $delta;
    	$matrix[$days[$i-1]] -= $delta;

    	$newv = $v - $delta;

    	$delta = min($newv, $matrix[$days[$i]]);
    	$sum += $delta;
    	$matrix[$days[$i]] -= $delta;
    }

    echo $sum;
?>


Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.The prefix of string $$$s$$$ of length $$$l$$$ ($$$1 \le l \le n$$$) is a string $$$s[1..l]$$$.For example, for the string $$$s=$$$"abba" there are two prefixes of the even length. The first is $$$s[1\dots2]=$$$"ab" and the second $$$s[1\dots4]=$$$"abba". Both of them have the same number of 'a' and 'b'.Your task is to calculate the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.

The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.

In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.

NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.

<?php
$count = fgets(STDIN);
$str = fgets(STDIN);

$newstr = '';
$n = 0;
for($i=0; $i<$count; $i = $i + 2){
    $str1 = substr($str, $i, 2);
    if($str1 == 'aa') {
        $n++;
        $newstr .= 'ba';

    } else if($str1 == 'bb') {
        $n++;
        $newstr .= 'ab';

    } else {
        $newstr .= $str1;
    }

}

echo $n . PHP_EOL;
if($newstr == '') echo $str;
else echo $newstr;

<?php
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
//$n = $_SERVER['argv'][1];
//$s = $_SERVER['argv'][2];

$cnt = 0;
$resultString = '';
for($i = 0; $i < $n; $i+=2) {
	$substr = $s[$i].$s[$i+1];
	if($substr[0] == $substr[1]) {
		$substr[0] == 'a' ? $substr[0] = 'b' : $substr[0] = 'a';
		$cnt++;
	}
	$resultString .= $substr;
}

echo $cnt."\n";
echo $resultString;

<?php
fscanf(STDIN,"%d\n",$evenLength);
$str1=trim(fgets(STDIN));
$str2="";
$count=0;
for ($i=0; $i <$evenLength ; $i+=2)
{
   $str3=substr($str1,$i,2);
   if($str3=='aa')
   	{
      $str2.='ba';
      $count++;
   	}
   elseif ($str3=='bb')
    {
      $str2.='ab';
      $count++;
    }
   else
   	$str2.=$str3;

}
echo "$count\n$str2";

<?php
$count = fgets(STDIN);
$str = fgets(STDIN);

$newstr = '';
$n = 0;
for($i=0; $i<$count; $i = $i + 2){
    $str1 = substr($str, $i, 2);
    if($str1 == 'aa') {
        $n++;
        $newstr .= 'ba';
    }

    if($str1 == 'bb') {
        $n++;
        $newstr .= 'ab';
    }
}
echo $n . PHP_EOL;
if($newstr == '') echo $str;
else echo $newstr;

<?php
$n = explode('', fgets(STDIN));
$s = explode('', fgets(STDIN));
//$n = $_SERVER['argv'][1];
//$s = $_SERVER['argv'][2];

$cnt = 0;
$resultString = '';
for($i = 0; $i < $n; $i+=2) {
	$substr = $s[$i].$s[$i+1];
	if($substr[0] == $substr[1]) {
		$substr[0] == 'a' ? $substr[0] = 'b' : $substr[0] = 'a';
		$cnt++;
	}
	$resultString .= $substr;
}

echo $cnt."\n";
echo $resultString;


Sho has an array $$$a$$$ consisting of $$$n$$$ integers. An operation consists of choosing two distinct indices $$$i$$$ and $$$j$$$ and removing $$$a_i$$$ and $$$a_j$$$ from the array.For example, for the array $$$[2, 3, 4, 2, 5]$$$, Sho can choose to remove indices $$$1$$$ and $$$3$$$. After this operation, the array becomes $$$[3, 2, 5]$$$. Note that after any operation, the length of the array is reduced by two.After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible. More formally, the array after Sho has made his operations respects these criteria:   No pairs such that ($$$i < j$$$) and $$$a_i = a_j$$$ exist.  The length of $$$a$$$ is maximized. Output the length of the final array.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^4$$$) — the elements of the array.

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

NoteFor the first test case Sho can perform operations as follows:   Choose indices $$$1$$$ and $$$5$$$ to remove. The array becomes $$$[2, 2, 2, 3, 3, 3] \rightarrow [2, 2, 3, 3]$$$.  Choose indices $$$1$$$ and $$$4$$$ to remove. The array becomes $$$[2, 2, 3, 3] \rightarrow [2, 3]$$$.  The final array has a length of $$$2$$$, so the answer is $$$2$$$. It can be proven that Sho cannot obtain an array with a longer length.For the second test case Sho can perform operations as follows:   Choose indices $$$3$$$ and $$$4$$$ to remove. The array becomes $$$[9, 1, 9, 9, 1] \rightarrow [9, 1, 1]$$$.  Choose indices $$$1$$$ and $$$3$$$ to remove. The array becomes $$$[9, 1, 1] \rightarrow [1]$$$.  The final array has a length of $$$1$$$, so the answer is $$$1$$$. It can be proven that Sho cannot obtain an array with a longer length.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

function solve()
{
    $mod = 1000000007;
    $intMaxValue = 2147483646; //2147483647
    $alph = 'abcdefghijklmnopqrstuvwxyz';
    $n = IO::getInt();
    $a = IO::getArray();
    $ans =0;
    $temp = [];
    $tt = [];
//    $n = count($a);
    for($i=0; $i < $n; $i++) {
        if(isset($temp[$a[$i]])) {
            $temp[$a[$i]] += 1;
            $tt[]  = $a[$i];
        } else {
            $temp[$a[$i]] = 1;
        }
    }
    $delete = 0;
    $ss = 0;

    if((count($tt) % 2)== 0) {
        $delete += count($tt);
    } else {
        $delete += count($tt) + 1;
    }

    IO::pr($n - $delete );

}

class IO {
    public static function getInt()
    {
        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;
    }
}

class Algor {
    public static function efclidLcm($a, $b) {
        return ($a  / self::efclidGcd($a, $b)) * $b;
    }
    public static function efclidGcd($a, $b) {
        return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
    }
    public static function isPrime($n) {
        $d = 2;
        while ($n % $d != 0) {
            $d += 1;
        }

        return $d == $n;
    }

    public static function fabicon($n, $a) {
        if($n <= 1) {
            return $a[$n];
        }
        for($i=2; $i<=$n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

    function getRotate($a, $s, $e, $ind) {
        $ar = [];
        for ($i= $s; $i<=$e; $i++) {
            $ar[$i] = $a[$i];
            $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
            // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
            $a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }

}

class bigOperation {
    public static function efclidLcm($a, $b) {
        return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
    }
    public static function efclidGcd($a, $b) {
        return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
    }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $length = readline();

    $arr = explode(" ", readline());

    $size = count($arr);

    $u_values = array_unique($arr);

    if (($size - count($u_values)) % 2 == 0) {
        echo count($u_values)."\n";
    }else{
        echo count($u_values)-1 ."\n";
    }

}

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $m = count(array_unique($a = fgetcsv(STDIN, 0, ' ')));
    printf("%d\n", ($n - $m) % 2 ? ($m - 1) : $m);
}

<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    fscanf($inp, '%d', $n);
    $ar = fscanf($inp, str_repeat('%d ', $n));

    echo (($finC = count(array_flip($ar))) - ($n & 1 & $n !== $finC)).PHP_EOL;
}

<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    fscanf($inp, '%d', $n);
    $ar = fscanf($inp, str_repeat('%d ', $n));

    echo (count(array_flip($ar)) - ($n & 1)).PHP_EOL;
}

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

function solve()
{
    $mod = 1000000007;
    $intMaxValue = 2147483646; //2147483647
    $alph = 'abcdefghijklmnopqrstuvwxyz';
    $n = IO::getInt();
    $a = IO::getArray();
    $ans =0;
    $temp = [];
    $tt = [];
//    $n = count($a);
    for($i=0; $i < $n; $i++) {
        if(isset($temp[$a[$i]])) {
            $temp[$a[$i]] += 1;
            $tt[$a[$i]]  = $temp[$a[$i]];
        } else {
            $temp[$a[$i]] = 1;
        }
    }
    $delete = 0;
    foreach ($tt as $ti => $v) {
        if($v > 2) {
            $delete += $v-2;
        }
    }
    if((count($tt) % 2)== 0) {
        $delete += count($tt);
    } else {
        $delete += count($tt) + 1;
    }

    IO::pr($n - $delete );

}

class IO {
    public static function getInt()
    {
        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;
    }
}

class Algor {
    public static function efclidLcm($a, $b) {
        return ($a  / self::efclidGcd($a, $b)) * $b;
    }
    public static function efclidGcd($a, $b) {
        return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
    }
    public static function isPrime($n) {
        $d = 2;
        while ($n % $d != 0) {
            $d += 1;
        }

        return $d == $n;
    }

    public static function fabicon($n, $a) {
        if($n <= 1) {
            return $a[$n];
        }
        for($i=2; $i<=$n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

    function getRotate($a, $s, $e, $ind) {
        $ar = [];
        for ($i= $s; $i<=$e; $i++) {
            $ar[$i] = $a[$i];
            $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
            // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
            $a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }

}

class bigOperation {
    public static function efclidLcm($a, $b) {
        return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
    }
    public static function efclidGcd($a, $b) {
        return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
    }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$testcases = readline();
for ($i = $testcases; $i > 0; $i--) {
    $length = readline();
    $arr = explode(" ",readline());

    echo count(array_unique($arr))."\n" ;

}

?>


The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?

The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.

Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.  Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

NoteNote to the second sample. In the worst-case scenario you will need five clicks:   the first click selects the first variant to the first question, this answer turns out to be wrong.  the second click selects the second variant to the first question, it proves correct and we move on to the second question;  the third click selects the first variant to the second question, it is wrong and we go back to question 1;  the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;  the fifth click selects the second variant to the second question, it proves correct, the test is finished.

<?PHP
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 500000);
fclose($putdata);
$tr = fopen('php://output', 'w');
$t = explode("\n",$data);
$i = $t[0];
$asks = explode(' ',$t[1]);
$clicks=0;
for($ii=1;$ii<=$i;$ii++){
$clicks=bcadd($clicks,bcadd(bcmul($ii,$asks[$ii-1]-1),1));
}
fputs($tr,$clicks);

<?php
$numberQuestions= (int) fgets(STDIN);
$replays = explode(' ', fgets(STDIN));
$result = 0;
for ($i =0;$i<$numberQuestions;$i++) {
   $result += $replays[$i] + $i * ($replays[$i] - 1);
}
echo number_format($result,0,'','');
?>

<?php

$src = 'php://stdin';
//$src = 'input.txt';

$data = file($src);

$n = (int) array_shift($data);
$a = array_map('intval', explode(' ', array_shift($data)));

$s = (int) -($n * ($n - 1)) / 2;

$i = 0;
while ($v = array_shift($a)) {
	$i++;
	$s += $v * $i;
}

echo $s;

<?php

$src = 'php://stdin';
$src = 'input.txt';

$data = file($src);

$n = (int) array_shift($data);
$a = array_map('intval', explode(' ', array_shift($data)));

$s = (int) -($n * ($n - 1)) / 2;

$i = 0;
while ($v = array_shift($a)) {
	$i++;
	$s += $v * $i;
}

echo $s;


Given an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$). Find the maximum value of $$$i + j$$$ such that $$$a_i$$$ and $$$a_j$$$ are coprime,$$$^{\dagger}$$$ or $$$-1$$$ if no such $$$i$$$, $$$j$$$ exist.For example consider the array $$$[1, 3, 5, 2, 4, 7, 7]$$$. The maximum value of $$$i + j$$$ that can be obtained is $$$5 + 7$$$, since $$$a_5 = 4$$$ and $$$a_7 = 7$$$ are coprime.$$$^{\dagger}$$$ Two integers $$$p$$$ and $$$q$$$ are coprime if the only positive integer that is a divisor of both of them is $$$1$$$ (that is, their greatest common divisor is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$a_1$$$, $$$a_2$$$,..., $$$a_n$$$ ($$$1 \leq a_i \leq 1000$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output a single integer  — the maximum value of $$$i + j$$$ such that $$$i$$$ and $$$j$$$ satisfy the condition that $$$a_i$$$ and $$$a_j$$$ are coprime, or output $$$-1$$$ in case no $$$i$$$, $$$j$$$ satisfy the condition.

NoteFor the first test case, we can choose $$$i = j = 3$$$, with sum of indices equal to $$$6$$$, since $$$1$$$ and $$$1$$$ are coprime.For the second test case, we can choose $$$i = 7$$$ and $$$j = 5$$$, with sum of indices equal to $$$7 + 5 = 12$$$, since $$$7$$$ and $$$4$$$ are coprime.

<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b): int
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a + $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b): int
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a | $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b)
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a | $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b)
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a + $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */


$$$n$$$ students attended the first meeting of the Berland SU programming course ($$$n$$$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not. Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of each testcase contains one integer $$$n$$$ ($$$2 \le n \le 1\,000$$$) — the number of students. The $$$i$$$-th of the next $$$n$$$ lines contains $$$5$$$ integers, each of them is $$$0$$$ or $$$1$$$. If the $$$j$$$-th integer is $$$1$$$, then the $$$i$$$-th student can attend the lessons on the $$$j$$$-th day of the week. If the $$$j$$$-th integer is $$$0$$$, then the $$$i$$$-th student cannot attend the lessons on the $$$j$$$-th day of the week.  Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $$$10^5$$$.

For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

NoteIn the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.

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

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $d = [];

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

    for ($k = 0; $k < 5; $k++) {
      if ($a[$k] != 0) {
        $d[$k] .= $j;
      }
    }
  }
  $c = 0;

  if (count($d) < 2) {
    echo 'NO'.PHP_EOL;
  } else {
    for ($j = 0; $j < count($d); $j++) {
      if (strlen($d[$j]) >= $n / 2) {
        $c++;
      }
    }
    if ($c >= 2) { echo 'YES'.PHP_EOL; }
    else {
      echo 'NO'.PHP_EOL;
    }
  }

}

?>


You are given a number $$$k$$$ and a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:   The first character '*' in the original string should be replaced with 'x';  The last character '*' in the original string should be replaced with 'x';  The distance between two neighboring replaced characters 'x' must not exceed $$$k$$$ (more formally, if you replaced characters at positions $$$i$$$ and $$$j$$$ ($$$i < j$$$) and at positions $$$[i+1, j-1]$$$ there is no "x" symbol, then $$$j-i$$$ must be no more than $$$k$$$). For example, if $$$n=7$$$, $$$s=$$$.**.*** and $$$k=3$$$, then the following strings will satisfy the conditions above:   .xx.*xx;  .x*.x*x;  .xx.xxx.  But, for example, the following strings will not meet the conditions:   .**.*xx (the first character '*' should be replaced with 'x');  .x*.xx* (the last character '*' should be replaced with 'x');  .x*.*xx (the distance between characters at positions $$$2$$$ and $$$6$$$ is greater than $$$k=3$$$). Given $$$n$$$, $$$k$$$, and $$$s$$$, find the minimum number of '*' characters that must be replaced with 'x' in order to meet the above conditions.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$). The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. It is guaranteed that there is at least one '*' in the string $$$s$$$. It is guaranteed that the distance between any two neighboring '*' characters does not exceed $$$k$$$.

For each test case output the minimum number of '*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k) = IO::arr();
    $s = str_split(IO::str());
    $res = 0;
    $last = -1;
    $lastdigit = 0;
    $l = [];
    for($i = 0; $i < $n; $i++) {
        if($s[$i] == '*') {
            $lastdigit = $i;
        }
        if ($last == -1 && $s[$i] == '*') {
            $last = $i;
            $res++;
            $l[$lastdigit] = 1;
        } elseif ($i - $last == $k && $last != -1) {
            if($s[$i] == '*') {
                $last = $i;
                $res++;
                $l[$i] = 1;
            } elseif(!isset($l[$lastdigit])) {
                $last = $lastdigit;
                $res++;
                $l[$lastdigit] = 1;
            }
        }
    }
    if ($lastdigit != end(array_keys($l))) {
        $res++;
    }
    IO::line($res);

}

?>

<?php
$t = readline();

for ($i = 0; $i < $t; $i++) {
    $input = readline();
    list($len, $k) = explode(' ', $input);
    $input_str = readline();

    formatString($input_str, $k);
}

function formatString($str, $k)
{
    $first_pos = strpos($str, '*');
    $last_pos = strrpos($str, '*');

    if ($first_pos === $last_pos) {
        echo '1'.PHP_EOL;
    } else {
        $count = 2;
        $str[$first_pos] = 'x';
        $str[$last_pos] = 'x';
        $current_pos = $first_pos;

        while ($current_pos + $k < $last_pos) {
            /*for ($i = $current_pos + $k; $i > $current_pos; $i--) {
                if ($str[$i] == '*') {
                    $str[$i] = 'x';
                    $count++;
                    $current_pos = $i;
                    break;
                }
            }*/

            $temp = substr($str, $current_pos, $k + 1);
            $temp_last_pos = strrpos($temp, '*');
            $current_pos += $temp_last_pos;
            $count++;
        }

        echo $count.PHP_EOL;
        //echo "
 Счетчик: " . $count . "
";
    }
}


Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct. Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on. A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.

The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even. The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.

If there is no answer, print -1. Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to. If there are multiple answers, it is allowed to print any of them.


By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.In 2312 there was a startling discovery: a collider's activity is safe if and only if all numbers of activated colliders are pairwise relatively prime to each other (two numbers are relatively prime if their greatest common divisor equals 1)! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse.Upon learning this, physicists rushed to turn the colliders on and off and carry out all sorts of experiments. To make sure than the scientists' quickness doesn't end with big trouble, the Large Hadron Colliders' Large Remote Control was created. You are commissioned to write the software for the remote (well, you do not expect anybody to operate it manually, do you?).Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the i-th collider". The program should handle requests in the order of receiving them. The program should print the processed results in the format described below.To the request of "+ i" (that is, to activate the i-th collider), the program should print exactly one of the following responses:   "Success" if the activation was successful.  "Already on", if the i-th collider was already activated before the request.  "Conflict with j", if there is a conflict with the j-th collider (that is, the j-th collider is on, and numbers i and j are not relatively prime). In this case, the i-th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them. The request of "- i" (that is, to deactivate the i-th collider), should receive one of the following responses from the program:   "Success", if the deactivation was successful.  "Already off", if the i-th collider was already deactivated before the request. You don't need to print quotes in the output of the responses to the requests.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of colliders and the number of requests, correspondingly. Next m lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the i-th collider, or "- i" (without the quotes) — deactivate the i-th collider (1 ≤ i ≤ n).

Print m lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes.

Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 10
Already on

NoteNote that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3".

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

$p = array();
$p[0] = 2;
$pc = 1;
for ($i = 3; $i <= $n; $i += 2)
{
  for ($j = 0; ($t = $p[$j]) * $t <= $i; $j++) if ($i % $t == 0) break;
  if ($i % $t != 0) $p[$pc++] = $i;
}

$c = array();
for ($i = 1; $i <= $n; $i++) $c[$i] = array();
for ($i = 0; $i < $pc; $i++)
{
  for ($j = $p[$i]; $j <= $n; $j += $p[$i]) $c[$j][$p[$i]] = true;
}

$on = array();
$cc = array();
for ($i = 0; $i < $m; $i++)
{
  fscanf(STDIN, "%s %d", $s, $t);
  if ($s === '+')
  {
    if (isset($on[$t]))
    {
      fprintf(STDOUT, "Already on\n");
    }
    else
    {
      $ci = -1;
      foreach ($c[$t] as $ii => $v)
      {
        if (isset($cc[$ii]))
        {
          $ci = $cc[$ii];
          break;
        }
      }
      if ($ci == -1)
      {
        $on[$t] = true;
        foreach ($c[$t] as $ii => $v) $cc[$ii] = $t;
        fprintf(STDOUT, "Success\n");
      }
      else
      {
        fprintf(STDOUT, "Conflict with %d\n", $ci);
      }
    }
  }
  else
  {
    if (isset($on[$t]))
    {
      unset($on[$t]);
      foreach ($c[$t] as $ii => $v) unset($cc[$ii]);
      fprintf(STDOUT, "Success\n");
    }
    else
    {
      fprintf(STDOUT, "Already off\n");
    }
  }
}


There are $$$n$$$ programmers that you want to split into several non-empty teams. The skill of the $$$i$$$-th programmer is $$$a_i$$$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $$$x$$$.Each programmer should belong to at most one team. Some programmers may be left without a team.Calculate the maximum number of teams that you can assemble.

The first line contains the integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5; 1 \le x \le 10^9$$$) — the number of programmers and the restriction of team skill respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th programmer. The sum of $$$n$$$ over all inputs does not exceed $$$10^5$$$.

For each test case print one integer — the maximum number of teams that you can assemble.


Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length $$$k$$$ is vowelly if there are positive integers $$$n$$$ and $$$m$$$ such that $$$n\cdot m = k$$$ and when the word is written by using $$$n$$$ rows and $$$m$$$ columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.You are given an integer $$$k$$$ and you must either print a vowelly word of length $$$k$$$ or print $$$-1$$$ if no such word exists.In this problem the vowels of the English alphabet are 'a', 'e', 'i', 'o' ,'u'.

Input consists of a single line containing the integer $$$k$$$ ($$$1\leq k \leq 10^4$$$) — the required length.

The output must consist of a single line, consisting of a vowelly word of length $$$k$$$ consisting of lowercase English letters if it exists or $$$-1$$$ if it does not. If there are multiple possible words, you may output any of them.

NoteIn the second example, the word "agoeuioaeiruuimaeoieauoweouoiaouimae" can be arranged into the following $$$6 \times 6$$$ grid:  It is easy to verify that every row and every column contain all the vowels.


The flag of Berland is such rectangular field n × m that satisfies following conditions:  Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.  Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.  Each color should be used in exactly one stripe. You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB

NoteThe field in the third example doesn't have three parralel stripes.Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.


n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n = fgets($stdin);
    $numbers = explode(" ", fgets($stdin));

    $min_diff=1000000000;
    $pair = "";
    for($i=1;$i<$n;++$i){
        if(abs($numbers[$i]-$numbers[$i-1]) < $min_diff){
            $min_diff = abs($numbers[$i]-$numbers[$i-1]);
            $pair = ($i) . " " . ($i+1);
        }
    }

    if(abs($numbers[$n-1]-$numbers[0]) < $min_diff){
        $pair = intval($n) . " " . 1;
    }

    fputs($stdout, $pair);
?>

<?php

fscanf(STDIN,"%d\n",$number);
$line = trim(fgets(STDIN));

$heights = explode(' ', $line);

for ($i=0; $i < $number - 1; $i++) {
    $d[] = array($i, $i +1, abs($heights[$i] - $heights[$i + 1]));
}

$d[] = array(0, $number - 1, abs(end($heights) - $heights[0]));

$diff = array(0, 0, 1001);

Foreach ($d as $value) {
    If ($value[2] < $diff[2]) {
        $diff = $value;
    }
}

echo ($diff[0] + 1) . ' ' . ($diff[1] + 1);

?>

<?php

fscanf(STDIN,"%d\n",$number);
$line = trim(fgets(STDIN));

$heights = explode(' ', $line);

for ($i=0; $i < $number - 1; $i++) {
    $d[] = array($i, $i +1, abs($heights[$i] - $heights[$i + 1]));
}

$d[] = array(0, $number - 1, abs(end($heights) - $heights[0]));

$diff = array(0, 0, 1001);

Foreach ($d as $value) {
    If ($value[2] < $diff[2]) {
        $diff = $value;
    }
}

print_r($diff);

echo ($diff[0] + 1) . ' ' . ($diff[1] + 1);

?>

<?php
$stdout = fopen('php://stdout', 'w');
fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
$s = trim(fgets($h));
$len = strlen($s);
if (($n>=1 && $n<=100))
	{
	$f=true;
for ($i=1; $i<=$n-1; $i++)
{
	$r=stripos($s,' ');
	$mas[$i]=substr($s, 0, $r);
	if (($mas[$i]<1 && $mas[$i]>1000))
	{$f=false;}
	$s=substr($s, $r+1, $len-$r-1);
	}
	$mas[$n]=$s;
	if (($mas[$n]<1 && $mas[$n]>1000))
	{$f=false;}
	if($f)
	{
fputs(STDOUT, "Vihodnie dannie:  ");
	for ($i=1; $i<=$n-1; $i++)
	{
		$d=abs($mas[$i]-$mas[$i+1]);
		$mas1[$i]=$d;
		}
		$d=abs($mas[$n]-$mas[1]);
		$mas1[$n]=$d;
		$min=$mas1[1]; $t=1;
		for ($i=1; $i<=$n; $i++)
		{
			if($mas1[$i]<$min){$min=$mas1[$i]; $t=$i;}
			}
			if ($t==$n){$t1=1;}
				else {$t1=$t+1;}
fputs(STDOUT, "$t");
fputs(STDOUT, " ");
fputs(STDOUT, "$t1");
			}
			else
	{fputs(STDOUT, "Nevernii diapazon");}
}
else
	{fputs(STDOUT, "Nevernii diapazon");}
?>


You are given an array $$$a$$$ of length $$$n$$$.You are also given a set of distinct positions $$$p_1, p_2, \dots, p_m$$$, where $$$1 \le p_i < n$$$. The position $$$p_i$$$ means that you can swap elements $$$a[p_i]$$$ and $$$a[p_i + 1]$$$. You can apply this operation any number of times for each of the given positions.Your task is to determine if it is possible to sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps.For example, if $$$a = [3, 2, 1]$$$ and $$$p = [1, 2]$$$, then we can first swap elements $$$a[2]$$$ and $$$a[3]$$$ (because position $$$2$$$ is contained in the given set $$$p$$$). We get the array $$$a = [3, 1, 2]$$$. Then we swap $$$a[1]$$$ and $$$a[2]$$$ (position $$$1$$$ is also contained in $$$p$$$). We get the array $$$a = [1, 3, 2]$$$. Finally, we swap $$$a[2]$$$ and $$$a[3]$$$ again and get the array $$$a = [1, 2, 3]$$$, sorted in non-decreasing order.You can see that if $$$a = [4, 1, 2, 3]$$$ and $$$p = [3, 2]$$$ then you cannot sort the array.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m < n \le 100$$$) — the number of elements in $$$a$$$ and the number of elements in $$$p$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$). The third line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$, all $$$p_i$$$ are distinct) — the set of positions described in the problem statement.

For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps. Otherwise, print "NO".

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($k = 0; $k < $m; $k++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $j = 0;
    while (true) {
        $bFlag = true;
        $aLocalArray = $aArray;
        foreach ($aList as $sK => $sV) {
            if (isset($aArray[$sV - 1]) && isset($aArray[$sV])) {
                if ($aArray[$sV - 1] > $aArray[$sV]) {
                    $tmp = $aArray[$sV - 1];
                    $aArray[$sV - 1] = $aArray[$sV];
                    $aArray[$sV] = $tmp;
                    $bFlag = false;
                }
            }
        }
        if ($aArray == $aLocalArray) {
            break;
        }
    }

    $bFlag = true;
    for ($i = 0; $i < count($aArray) - 1; $i++) {
        if ($aArray[$i] > $aArray[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

//YES
//NO
//YES
//YES
//NO
//YES


There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:  The crow sets ai initially 0.  The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row. The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

NoteIn the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

<?
$n = trim(fgets(STDIN));
$numbers = explode(' ',trim(fgets(STDIN)));
$initial = array();
$initial[]=$numbers[count($numbers)-1];

for ($i=(count($numbers)-2);$i>=0;$i--){
    $cur = $numbers[$i]+$numbers[$i+1];
	$initial[]=$cur;
	$s.=(" ".$cur);
}

$s = implode(' ',array_reverse($initial));
echo $s;
?>