There are $$$n$$$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.We want to plan a trip for every evening of $$$m$$$ days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:   Either this person does not go on the trip,  Or at least $$$k$$$ of his friends also go on the trip. Note that the friendship is not transitive. That is, if $$$a$$$ and $$$b$$$ are friends and $$$b$$$ and $$$c$$$ are friends, it does not necessarily imply that $$$a$$$ and $$$c$$$ are friends.For each day, find the maximum number of people that can go on the trip on that day.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5$$$, $$$1 \le k < n$$$) — the number of people, the number of days and the number of friends each person on the trip should have in the group. The $$$i$$$-th ($$$1 \leq i \leq m$$$) of the next $$$m$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1\leq x, y\leq n$$$, $$$x\ne y$$$), meaning that persons $$$x$$$ and $$$y$$$ become friends on the morning of day $$$i$$$. It is guaranteed that $$$x$$$ and $$$y$$$ were not friends before.

Print exactly $$$m$$$ lines, where the $$$i$$$-th of them ($$$1\leq i\leq m$$$) contains the maximum number of people that can go on the trip on the evening of the day $$$i$$$.

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }
        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);//存储无向边
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;//统计节点的度
    $friends_num[$id_y]++;
    $count_num[$id_x]++;//和上面一样，这个作用是方便知道当前点连的边的，不用再每次去count
    $count_num[$id_y]++;
}
//$suitable_id = array();
$flag        = array();//标记点是否在符合要求
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}//将不符合要求的点加入队列，并标记
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}//有不符合要求的点去更新其它点
$answer         = array();//结果数组
$n_cnt          = count($flag);//统计不符合要求的点
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]||isset($flag[$person_y])) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }//将度小的交换到前面
    //echo $person_x . "    ".$person_y ."\n";
    //当前边去掉，两个点减度（假设当前两点都符合要求）
    if (isset($flag[$person_x])) {//度数小的点在连这边之后也不会符合要求，那么这条边不会影响第二个点，所以加上度数，而第一个点已经不合要求，所以度数减去无影响
    } else {//第一个点在去除当前边前符合要求，减去后不符合
        if ($friends_num[$person_x] <= $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
          //在后面的队列中会减，所以这里加上，否则会多减
        } else {//两点在去除当前边后都符合要求，将当前边从存储的边中移除，因为是从后往前，所以是顺序的减边这块复杂度O(m)
            $friends_num[$person_x]--;
            $friends_num[$person_y]--;
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }
        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);//存储无向边
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;//统计节点的度
    $friends_num[$id_y]++;
    $count_num[$id_x]++;//和上面一样，这个作用是方便知道当前点连的边的，不用再每次去count
    $count_num[$id_y]++;
}
//$suitable_id = array();
$flag        = array();//标记点是否在符合要求
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}//将不符合要求的点加入队列，并标记
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}//有不符合要求的点去更新其它点
$answer         = array();//结果数组
$n_cnt          = count($flag);//统计不符合要求的点
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]||isset($flag[$person_y])) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }//将度小的交换到前面
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;//当前边去掉，两个点减度（假设当前两点都符合要求）
    if (isset($flag[$person_x])) {//度数小的点在连这边之后也不会符合要求，那么这条边不会影响第二个点，所以加上度数，而第一个点已经不合要求，所以度数减去无影响
        $friends_num[$person_y]++;
        $friends_num[$person_x]++;
    } else {//第一个点在去除当前边前符合要求，减去后不符合
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_x]++;
            $friends_num[$person_y]++;//在后面的队列中会减，所以这里加上，否则会多减
        } else {//两点在去除当前边后都符合要求，将当前边从存储的边中移除，因为是从后往前，所以是顺序的减边这块复杂度O(m)
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num = 0;
        $this->head = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }

        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num = array();
$person_node = array();
$edge_x = array();
$edge_y = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i] = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;
    $friends_num[$id_y]++;
    $count_num[$id_x]++;
    $count_num[$id_y]++;
}
$suitable_id = array();
$flag = array();
$que = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        if (!isset($flag[$s_id])) {
            $friends_num[$s_id]--;
        }
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}
$answer = array();
$n_cnt = count($flag);
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;
    if (isset($flag[$person_x])) {
        $friends_num[$person_y]++;
        $friends_num[$person_x]++;
    } else {
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_y]++;
        } else {
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x] - 1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
                //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y] - 1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                } else {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                    break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            if (!isset($flag[$s_id])) {
                $friends_num[$s_id]--;
            }
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    //echo $i . "    ".$friends_num[4] . "\n";
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }
        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);//存储无向边
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;//统计节点的度
    $friends_num[$id_y]++;
    $count_num[$id_x]++;//和上面一样，这个作用是方便知道当前点连的边的，不用再每次去count
    $count_num[$id_y]++;
}
//$suitable_id = array();
$flag        = array();//标记点是否在符合要求
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}//将不符合要求的点加入队列，并标记
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}//有不符合要求的点去更新其它点
$answer         = array();//结果数组
$n_cnt          = count($flag);//统计不符合要求的点
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }//将度小的交换到前面
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;//当前边去掉，两个点减度（假设当前两点都符合要求）
    if (isset($flag[$person_x])) {//度数小的点不在连这边之后也不会符合要求，那么这条边不会影响第二个点，所以加上度数，而第一个点已经不合要求，所以度数减去无影响
        $friends_num[$person_y]++;
    } else {//第一个点在去除当前边前符合要求，减去后不符合
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_y]++;//在后面的队列中会减，所以这里加上，否则会多减
        } else {//两点在去除当前边后都符合要求，将当前边从存储的边中移除，因为是从后往前，所以是顺序的减边这块复杂度O(m)
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }

        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;
    $friends_num[$id_y]++;
    $count_num[$id_x]++;
    $count_num[$id_y]++;
}
$suitable_id = array();
$flag        = array();
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}
$answer         = array();
$n_cnt          = count($flag);
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;
    if (isset($flag[$person_x])) {
        $friends_num[$person_y]++;
    } else {
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_y]++;
        } else {
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    //echo $i . "    ".$friends_num[4] . "\n";
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}

class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }

        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;
    $friends_num[$id_y]++;
    $count_num[$id_x]++;
    $count_num[$id_y]++;
}
$suitable_id = array();
$flag        = array();
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    $num = count($person_node[$id]);
    for ($i = 0; $i < $num; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !issest($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}
$answer         = array();
$n_cnt          = count($flag);
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;
    if (isset($flag[$person_x])) {
        $friends_num[$person_y]++;
    } else {
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_y]++;
        } else {
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        $num = count($person_node[$id]);
        for ($j = 0; $j < $num; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    //echo $i . "    ".$friends_num[4] . "\n";
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}
/*4 4 2
2 3
1 2
1 3
1 4*/

<?php
class QueStruct
{
    public $data;
    public $next;
    public function __construct($data)
    {
        $this->data = $data;
        $this->next = null;
    }
}
class Queue
{
    protected $head;
    protected $trail;
    protected $num;
    public function __construct()
    {
        $this->num   = 0;
        $this->head  = null;
        $this->trail = null;
    }
    public function push($data)
    {
        $this->num++;
        if ($this->head == null) {
            $this->head = $this->trail = new QueStruct($data);
        } else {
            $this->trail->next = new QueStruct($data);
            $this->trail       = $this->trail->next;
        }
    }
    public function front()
    {
        return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p          = &$this->head;
        $this->head = $this->head->next;
        if ($this->num == 0) {
            $this->trail = $this->head = null;
        }

        unset($p);
    }
    public function size()
    {
        return $this->num;
    }
    public function isEmpty()
    {
        if ($this->num == 0) {
            return true;
        }
        return false;
    }
}
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$friends_num = array();
$count_num   = array();
$person_node = array();
$edge_x      = array();
$edge_y      = array();
for ($i = 0; $i <= $n; $i++) {
    $friends_num[$i] = 0;
    $count_num[$i]   = 0;
}
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $id_x, $id_y);
    $edge_x[$i] = $id_x;
    $edge_y[$i] = $id_y;
    if (!isset($person_node[$id_x])) {
        $person_node[$id_x] = array();
    }
    if (!isset($person_node[$id_y])) {
        $person_node[$id_y] = array();
    }
    array_push($person_node[$id_x], $id_y);//存储无向边
    array_push($person_node[$id_y], $id_x);
    $friends_num[$id_x]++;//统计节点的度
    $friends_num[$id_y]++;
    $count_num[$id_x]++;//和上面一样，这个作用是方便知道当前点连的边的，不用再每次去count
    $count_num[$id_y]++;
}
//$suitable_id = array();
$flag        = array();//标记点是否在符合要求
$que         = new queue();
for ($i = 1; $i <= $n; $i++) {
    if ($friends_num[$i] < $k) {
        $que->push($i);
        $flag[$i] = true;
    }
}//将不符合要求的点加入队列，并标记
while (!$que->isEmpty()) {
    $id = $que->front();
    $que->pop();
    for ($i = 0; $i < $count_num[$id]; $i++) {
        $s_id = $person_node[$id][$i];
        $friends_num[$s_id]--;
        if ($friends_num[$s_id] < $k && !isset($flag[$s_id])) {
            $flag[$s_id] = true;
            $que->push($s_id);
        }
    }
}//有不符合要求的点去更新其它点
$answer         = array();//结果数组
$n_cnt          = count($flag);//统计不符合要求的点
$answer[$m - 1] = $n - $n_cnt;
for ($i = $m - 1; $i >= 1; $i--) {
    $person_x = $edge_x[$i];
    $person_y = $edge_y[$i];
    //echo $person_x . "    ".$person_y."\n";
    if ($friends_num[$person_y] < $friends_num[$person_x]) {
        $person_x ^= $person_y;
        $person_y ^= $person_x;
        $person_x ^= $person_y;
    }//将度小的交换到前面
    //echo $person_x . "    ".$person_y ."\n";
    $friends_num[$person_x]--;
    $friends_num[$person_y]--;//当前边去掉，两个点减度（假设当前两点都符合要求）
    if (isset($flag[$person_x])) {//度数小的点在连这边之后也不会符合要求，那么这条边不会影响第二个点，所以加上度数，而第一个点已经不合要求，所以度数减去无影响
        $friends_num[$person_y]++;
        $friends_num[$person_x]++;
    } else {//第一个点在去除当前边前符合要求，减去后不符合
        if ($friends_num[$person_x] < $k) {
            $flag[$person_x] = true;
            $que->push($person_x);
            $n_cnt++;
            $friends_num[$person_x]++;
            $friends_num[$person_y]++;//在后面的队列中会减，所以这里加上，否则会多减
        } else {//两点在去除当前边后都符合要求，将当前边从存储的边中移除，因为是从后往前，所以是顺序的减边这块复杂度O(m)
            while ($count_num[$person_x]) {
                if ($person_node[$person_x][$count_num[$person_x]-1] != $person_y) {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                } else {
                    array_pop($person_node[$person_x]);
                    $count_num[$person_x]--;
                    break;
                }
            }
            while ($count_num[$person_y]) {
              //var_dump($count_num[$person_y]);
                if ($person_node[$person_y][$count_num[$person_y]-1] != $person_x) {
                    array_pop($person_node[$person_y]);
                    $count_num[$person_y]--;
                }else {
                  array_pop($person_node[$person_y]);
                  $count_num[$person_y]--;
                  break;
                }
            }
        }
    }
    while (!$que->isEmpty()) {
        $id = $que->front();
        // var_dump($id);
        $que->pop();
        for ($j = 0; $j < $count_num[$id]; $j++) {
            $s_id = $person_node[$id][$j];
            $friends_num[$s_id]--;
            if (!isset($flag[$s_id]) && $friends_num[$s_id] < $k) {
                $que->push($s_id);
                $flag[$s_id] = true;
                $n_cnt++;
            }
        }
    }
    $answer[$i - 1] = $n - $n_cnt;
}
for ($i = 0; $i < $m; $i++) {
    echo $answer[$i] . "\n";
}


We start with a permutation $$$a_1, a_2, \ldots, a_n$$$ and with an empty array $$$b$$$. We apply the following operation $$$k$$$ times.On the $$$i$$$-th iteration, we select an index $$$t_i$$$ ($$$1 \le t_i \le n-i+1$$$), remove $$$a_{t_i}$$$ from the array, and append one of the numbers $$$a_{t_i-1}$$$ or $$$a_{t_i+1}$$$ (if $$$t_i-1$$$ or $$$t_i+1$$$ are within the array bounds) to the right end of the array $$$b$$$. Then we move elements $$$a_{t_i+1}, \ldots, a_n$$$ to the left in order to fill in the empty space.You are given the initial permutation $$$a_1, a_2, \ldots, a_n$$$ and the resulting array $$$b_1, b_2, \ldots, b_k$$$. All elements of an array $$$b$$$ are distinct. Calculate the number of possible sequences of indices $$$t_1, t_2, \ldots, t_k$$$ modulo $$$998\,244\,353$$$.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100\,000$$$), denoting the number of test cases, followed by a description of the test cases. The first line of each test case contains two integers $$$n, k$$$ ($$$1 \le k < n \le 200\,000$$$): sizes of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$): elements of $$$a$$$. All elements of $$$a$$$ are distinct. The third line of each test case contains $$$k$$$ integers $$$b_1, b_2, \ldots, b_k$$$ ($$$1 \le b_i \le n$$$): elements of $$$b$$$. All elements of $$$b$$$ are distinct. The sum of all $$$n$$$ among all test cases is guaranteed to not exceed $$$200\,000$$$.

For each test case print one integer: the number of possible sequences modulo $$$998\,244\,353$$$.

Note$$$\require{cancel}$$$Let's denote as $$$a_1 a_2 \ldots \cancel{a_i} \underline{a_{i+1}} \ldots a_n \rightarrow a_1 a_2 \ldots a_{i-1} a_{i+1} \ldots a_{n-1}$$$ an operation over an element with index $$$i$$$: removal of element $$$a_i$$$ from array $$$a$$$ and appending element $$$a_{i+1}$$$ to array $$$b$$$.In the first example test, the following two options can be used to produce the given array $$$b$$$:  $$$1 2 \underline{3} \cancel{4} 5 \rightarrow 1 \underline{2} \cancel{3} 5 \rightarrow 1 \cancel{2} \underline{5} \rightarrow 1 2$$$; $$$(t_1, t_2, t_3) = (4, 3, 2)$$$;  $$$1 2 \underline{3} \cancel{4} 5 \rightarrow \cancel{1} \underline{2} 3 5 \rightarrow 2 \cancel{3} \underline{5} \rightarrow 1 5$$$; $$$(t_1, t_2, t_3) = (4, 1, 2)$$$. In the second example test, it is impossible to achieve the given array no matter the operations used. That's because, on the first application, we removed the element next to $$$4$$$, namely number $$$3$$$, which means that it couldn't be added to array $$$b$$$ on the second step.In the third example test, there are four options to achieve the given array $$$b$$$:  $$$1 4 \cancel{7} \underline{3} 6 2 5 \rightarrow 1 4 3 \cancel{6} \underline{2} 5 \rightarrow \cancel{1} \underline{4} 3 2 5 \rightarrow 4 3 \cancel{2} \underline{5} \rightarrow 4 3 5$$$; $$$1 4 \cancel{7} \underline{3} 6 2 5 \rightarrow 1 4 3 \cancel{6} \underline{2} 5 \rightarrow 1 \underline{4} \cancel{3} 2 5 \rightarrow 1 4 \cancel{2} \underline{5} \rightarrow 1 4 5$$$; $$$1 4 7 \underline{3} \cancel{6} 2 5 \rightarrow 1 4 7 \cancel{3} \underline{2} 5 \rightarrow \cancel{1} \underline{4} 7 2 5 \rightarrow 4 7 \cancel{2} \underline{5} \rightarrow 4 7 5$$$; $$$1 4 7 \underline{3} \cancel{6} 2 5 \rightarrow 1 4 7 \cancel{3} \underline{2} 5 \rightarrow 1 \underline{4} \cancel{7} 2 5 \rightarrow 1 4 \cancel{2} \underline{5} \rightarrow 1 4 5$$$;

<?php
$T = fgets(STDIN);
$mod = 998244353;
for($t = 0; $t < $T; $t++) {
    $len = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));

    $ans = 1;
    $posInB = [];
    $posInA = [];

    foreach($a as $i => $x) {
        $posInA[$x] = $i;
    }
    foreach($b as $i => $x) {
        $posInB[$x] = $i;
    }

    for($i = 0; $i < $len[1]; $i++) {
        $pos = $posInA[$b[$i]];
        $mult = 0;
        if($pos != 0 && (!$posInB[$a[$pos-1]] || $posInB[$a[$pos-1]] < $i)) {
            $mult++;
        }
        if($pos != $len[0]-1 && (!$posInB[$a[$pos+1]] || $posInB[$a[$pos+1]] < $i)) {
            $mult++;
        }
        $ans = ($ans * $mult) % $mod;
    }
    echo $ans."\n";
}

?>


Recall that string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly zero or all) characters. For example, for the string $$$a$$$="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow", "", and others, but the following are not subsequences: "owoo", "owwwo", "ooo".The wow factor of a string is the number of its subsequences equal to the word "wow". Bob wants to write a string that has a large wow factor. However, the "w" key on his keyboard is broken, so he types two "v"s instead. Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string "ww". Bob would type it as "vvvv", but this string actually contains three occurrences of "w":   "vvvv"  "vvvv"  "vvvv" For example, the wow factor of the word "vvvovvv" equals to four because there are four wows:  "vvvovvv"  "vvvovvv"  "vvvovvv"  "vvvovvv" Note that the subsequence "vvvovvv" does not count towards the wow factor, as the "v"s have to be consecutive.For a given string $$$s$$$, compute and output its wow factor. Note that it is not guaranteed that it is possible to get $$$s$$$ from another string replacing "w" with "vv". For example, $$$s$$$ can be equal to "vov".

The input contains a single non-empty string $$$s$$$, consisting only of characters "v" and "o". The length of $$$s$$$ is at most $$$10^6$$$.

Output a single integer, the wow factor of $$$s$$$.

NoteThe first example is explained in the legend.


On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xj·k for 1 ≤ j ≤ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?

The first line contains two integers n and S (1 ≤ n ≤ 105 and 1 ≤ S ≤ 109) — the number of souvenirs in the market and Sagheer's budget. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the base costs of the souvenirs.

On a single line, print two integers k, T — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.

NoteIn the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.In the second example, he can buy all items as they will cost him [5, 10, 17, 22].In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it.


There is a special offer in Vasya's favourite supermarket: if the customer buys $$$a$$$ chocolate bars, he or she may take $$$b$$$ additional bars for free. This special offer can be used any number of times.Vasya currently has $$$s$$$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $$$c$$$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains four integers $$$s, a, b, c~(1 \le s, a, b, c \le 10^9)$$$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

Print $$$t$$$ lines. $$$i$$$-th line should contain the maximum possible number of chocolate bars Vasya can get in $$$i$$$-th test.

NoteIn the first test of the example Vasya can buy $$$9$$$ bars, get $$$3$$$ for free, buy another bar, and so he will get $$$13$$$ bars.In the second test Vasya buys $$$1000000000$$$ bars and gets $$$1000000000000000000$$$ for free. So he has $$$1000000001000000000$$$ bars.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d, $e) = explode(" ", trim(fgets(STDIN)));
     $f = floor($b / $e);
     if($f < $c)
     {
          print $f . "\n";
     }
     else
     {
          $g = floor($f / $c);
          $h = $f % $c;
          $i = bcadd($h, bcadd(bcmul($g, $c), bcmul($g, $d)));
          print $i . "\n";
     }
}
?>

<?php

$cnt = -1;
while($f = fgets(STDIN)){
    if ($cnt == -1) {
        $cnt = intval($f);
    } else if ($cnt > 0) {
        $arr = explode(" ", trim($f));
        $s = $arr[0];
        $a = $arr[1];
        $b = $arr[2];
        $c = $arr[3];

        $ret = cal($s, $a, $b, $c);
        echo $ret . "\n";

        $cnt--;
        if ($cnt == 0) {
            break;
        }
    } else {
        break;
    }
}

function cal($s, $a, $b, $c) {
    $d = bcmul($a, $c);
    $num = 0;

    $m = bcdiv($s, $d);
    $num = bcadd($num, $m);
    $num = bcadd($num, bcmul($m, $b));
    $left = $s - bcmul($m, $c);
    $num = bcadd($num, bcdiv($left,  $c));

    return $num;
}

//1000000000 1
//1000000000 1

<?php

$cnt = -1;
while($f = fgets(STDIN)){
    if ($cnt == -1) {
        $cnt = intval($f);
    } else if ($cnt > 0) {
        $arr = explode(" ", trim($f));
        $s = $arr[0];
        $a = $arr[1];
        $b = $arr[2];
        $c = $arr[3];

        $ret = cal($s, $a, $b, $c);
        echo $ret . "\n";

        $cnt--;
        if ($cnt == 0) {
            break;
        }
    } else {
        break;
    }
}

function cal($s, $a, $b, $c) {
    $d = bcmul($a, $c);
    $num = 0;

    $m = bcdiv($s, $d);
    $num = bcadd($num, $m);
    echo $num . "\n";
    $num = bcadd($num, bcmul($m, $b));
    echo $num . "\n";
    $left = $s - bcmul($m, $c);
    $num = bcadd($num, bcdiv($left,  $c));
    echo $num . "\n";

    return (string)$num;
}

//1000000000 1
//1000000000 1


Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.Print the minimum cost Vladik has to pay to get to the olympiad.

The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.  The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

NoteIn the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

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

<?php

fscanf(STDIN, '%d %d %d', $n, $a, $b);
$way = trim(fgets(STDIN));

if($way[$b-1] == $way[$a-1])  {print "0\n";}
else  {print "1";}

?>

<?php

function findMinCost($nab,$company)
{
    $nab = explode(" ",$nab);
    $n   = $nab[0];
    $a   = $nab[1];
    $b   = $nab[2];

    $company = str_split($company);

    $minCost = 0;

    if($company[$a-1]==$company[$b-1]){
        $minCost = 0;
    }else{
        if($a>$b){
            for($i=$a-1;$i>$b-1;$i--){

                if($company[$i]==$company[$i-1]){
                    $minCost += 0;
                }else{
                    $minCost +=abs($company[$i]-$company[$i-1]);
                }

                if($company[$i-1]==$company[$b-1]){
                    $minCost +=0;
                    break;
                } //echo $i."::".$minCost.'\n';
            }
        }else{
            for($i=$a-1;$i<$b-1;$i++){
                if($company[$i]==$company[$i+1]){
                    $minCost += 0;
                }else{
                    $minCost +=abs($company[$i]-$company[$i+1]);
                }

                if($company[$i+1]==$company[$b-1]){
                    $minCost +=0;
                    break;
                }
            }
        }
    }

    return $minCost;
}

$nab = trim(fgets(STDIN));
$company = trim(fgets(STDIN));

print_r(findMinCost($nab,$company));

<?php
list($n, $a, $b) = fscanf(STDIN, '%d %d %d');
$as = rtrim(fgets(STDIN));

if ($as[$a-1] == $as[$b-1]) {
    echo 0;
} else {
    echo 1;
}

<?php

fscanf(STDIN, '%d %d %d', $n, $a, $b);
$way = explode(trim(fgets(STDIN)));

if($way[$b-1] == $way[$a-1])  {print "0\n";}
else  {print "1";}

?>

<?php

function findMinCost($nab,$company)
{
    $nab = explode(" ",$nab);
    $n   = $nab[0];
    $a   = $nab[1];
    $b   = $nab[2];

    $company = str_split($company);

    $minCost = 0;

    if($company[$a-1]==$company[$b-1]){
        $minCost = 0;
    }else{
        for($i=0;$i<$n-1;$i++){
            if($company[$i]==$company[$i+1]){
                $minCost += 0;
            }else{
                $minCost +=abs($company[$i]-$company[$i+1]);
            }

            if($company[$i+1]==$company[$b-1]){
                $minCost +=0;
                break;
            }
        }
    }

    return $minCost;
}

$nab = trim(fgets(STDIN));
$company = trim(fgets(STDIN));

print_r(findMinCost($nab,$company));

<?php

function findMinCost($nab,$company)
{
    $nab = explode(" ",$nab);
    $n   = $nab[0];
    $a   = $nab[1];
    $b   = $nab[2];

    $company = str_split($company);

    $minCost = 0;

    if($company[$a-1]==$company[$b-1]){
        $minCost = 0;
    }else{
        if($a>$b){
            for($i=$a-1;$i>$b-1;$i--){
                if($company[$i]==$company[$i+1]){
                    $minCost += 0;
                }else{
                    $minCost +=abs($company[$i]-$company[$i+1]);
                }

                if($company[$i+1]==$company[$b-1]){
                    $minCost +=0;
                    break;
                }
            }
        }else{
            for($i=$a-1;$i<$b-1;$i++){
                if($company[$i]==$company[$i+1]){
                    $minCost += 0;
                }else{
                    $minCost +=abs($company[$i]-$company[$i+1]);
                }

                if($company[$i+1]==$company[$b-1]){
                    $minCost +=0;
                    break;
                }
            }
        }
    }

    return $minCost;
}

$nab = trim(fgets(STDIN));
$company = trim(fgets(STDIN));

print_r(findMinCost($nab,$company));

<?php

function findMinCost($nab,$company)
{
    $nab = explode(" ",$nab);
    $n   = $nab[0];
    $a   = $nab[1];
    $b   = $nab[2];

    $company = str_split($company);

    $minCost = 0;

    if($company[$a-1]==$company[$b-1]){
        $minCost = 0;
    }else{
        for($i=0;$i<$n-1;$i++){
            if($company[$i]==$company[$i+1]){
                $minCost += 0;
            }else{
                $minCost +=abs($company[$i]-$company[$i+1]);
            }

            if($company[$i+1]==$company[$b-1]){
                $minCost +=0;
                break;
            }
        }
    }

    return $minCost;
}

$nab = trim(fgets(STDIN));
$company = trim(fgets(STDIN));

findMinCost($nab,$company);


Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime:  Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.  Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows:  If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string.  If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.

The first line contains a non-empty string s.  It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.

In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.

NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this:  string "yxyxy" transforms into string "xyyxy";  string "xyyxy" transforms into string "xyxyy";  string "xyxyy" transforms into string "xxyyy";  string "xxyyy" transforms into string "xyy";  string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".


For the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \times h$$$, which can be cut into pieces.Polycarp can cut any sheet of paper $$$w \times h$$$ that he has in only two cases:   If $$$w$$$ is even, then he can cut the sheet in half and get two sheets of size $$$\frac{w}{2} \times h$$$;  If $$$h$$$ is even, then he can cut the sheet in half and get two sheets of size $$$w \times \frac{h}{2}$$$; If $$$w$$$ and $$$h$$$ are even at the same time, then Polycarp can cut the sheet according to any of the rules above.After cutting a sheet of paper, the total number of sheets of paper is increased by $$$1$$$.Help Polycarp to find out if he can cut his sheet of size $$$w \times h$$$ at into $$$n$$$ or more pieces, using only the rules described above.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three integers $$$w$$$, $$$h$$$, $$$n$$$ ($$$1 \le w, h \le 10^4, 1 \le n \le 10^9$$$) — the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.

For each test case, output on a separate line:    "YES", if it is possible to cut a sheet of size $$$w \times h$$$ into at least $$$n$$$ pieces;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteIn the first test case, you can first cut the $$$2 \times 2$$$ sheet into two $$$2 \times 1$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$. We can choose any three of them and send them to our friends.In the second test case, a $$$3 \times 3$$$ sheet cannot be cut, so it is impossible to get two sheets.In the third test case, you can cut a $$$5 \times 10$$$ sheet into two $$$5 \times 5$$$ sheets.In the fourth test case, there is no need to cut the sheet, since we only need one sheet.In the fifth test case, you can first cut the $$$1 \times 4$$$ sheet into two $$$1 \times 2$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = 1;
     $f = 1;
     while(TRUE)
     {
          if($b % 2 == 0)
          {
               $e *= 2;
               $b /= 2;
          }
          else
          {
               break;
          }
     }
     while(TRUE)
     {
          if($c % 2 == 0)
          {
               $f *= 2;
               $c /= 2;
          }
          else
          {
               break;
          }
     }
     if($e * $f >= $d)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

<?php
function isEven($a)
{
	return ($a % 2 == 0) ? 1 : 0;
}

$arr = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$str = readline();
	$param = explode(" ", $str);	// 0 - w; 1 - h; 2 - n;
	$w = $param[0];
	$h = $param[1];
	$ans = 1;
	while(true)
	{
		if($ans >= $param[2])
			break;
		if(isEven($w))
		{
			$w = $w / 2;
			$ans = $ans * 2;
		}
		elseif(isEven($h))
		{
			$h = $h / 2;
			$ans = $ans * 2;
		}
		else
			break;
	}
	if($ans >= $param[2])
		array_push($arr, "YES\r\n");
	else
		array_push($arr, "NO\r\n");
}
foreach($arr as $key => $value)
	print($value);

$end = readline();
?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $count_str = readline();
	//$count_str =  count($conten);

	for($j = 0; $j < $count_str; $j++)
	{
		$str = readline();
		$n = explode(' ', $str);

		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result.'</br>';
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $count_str = readline();
	//$count_str =  count($conten);

	for($j = 0; $j < $count_str; $j++)
	{
		$str = readline();
		$n = explode(' ', $str);

		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result;
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $count_str = readline();
	//$count_str =  count($conten);

	for($j = 0; $j < $count_str; $j++)
	{
		$str = readline();
		print_r($str);
		die();
		$n = explode(' ', $conten[$j]);

		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result;
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $conten = readline();
	//$count_str =  count($conten);
	print_r($conten);
		die();
	for($j = 1; $j < $count_str; $j++)
	{
		$n = explode(' ', $conten[$j]);

		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result;
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $conten = fgets(STDIN);
	$count_str =  count($conten);
	print_r($conten);
		die();
	for($j = 1; $j < $count_str; $j++)
	{
		$n = explode(' ', $conten[$j]);

		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result;
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $conten = fgets(STDIN);
	$count_str =  count($conten);

	for($j = 1; $j < $count_str; $j++)
	{
		$n = explode(' ', $conten[$j]);
		print_r($conten);
		die();
		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result.'</br>';
	}

?>

<?php
	//$str = '1 4 4';
	//$n = explode(' ', $str);

    $conten = fgets(STDIN);
	$count_str =  count($conten);

	for($j = 1; $j < $count_str; $j++)
	{
		$n = explode(' ', $conten[$j]);
		print_r($n);
		die();
		$arr = [];
		$flag = true;

		$arr[0] = 	[	'w'	=>	$n[0],
						'h'	=>	$n[1]
					];

		if(count($arr) != $n[2])
		{
			if($arr[0]['w'] % 2 == 0 || $arr[0]['h'] % 2 == 0)
			{
				while($flag)
				{
					$stop = 0;

					for($i = 0; $i < $count = count($arr); $i++)
					{
						if($arr[$i]['w'] % 2 == 0)
						{
							$arr[$i]['w'] = $arr[$i]['w']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2])
							break;

						if($arr[$i]['h'] % 2 == 0)
						{
							$arr[$i]['h'] = $arr[$i]['h']/2;
							$arr[count($arr)] = $arr[$i];
						}
						else
							$stop += 0.5;

						if(count($arr) == $n[2] || count($arr) == $stop)
							break;

					}
					if(count($arr) == $n[2] || count($arr) == $stop)
						break;
				}

				if(count($arr) == $n[2])
					$result = 'YES';
				else
					$result = 'NO';
			}
			else
				$result = 'NO';
		}
		else
			$result = 'YES';

		echo $result.'</br>';
	}

?>


Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

The first line contains the integer n (1 ≤ n ≤ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them.

NoteIn the first example we can connect the pairs of stones:  2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.  2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5  4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone:  1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5  2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5  4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5  5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.


The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?

The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.

Print a single number — the answer to the problem.

NoteIn the first sample only one team could be made: the first, the fourth and the fifth participants.In the second sample no teams could be created.In the third sample two teams could be created. Any partition into two teams fits.

<?php
$n=readline();
$kol_vo = readline();
//$n = '6 4';
$uchastniki = $n[0];
$sostav = $n[-1];
//$kol_vo = '0 0 0 0 0 0';
$kol_vo = explode(' ', $kol_vo);
$yes = 0;
foreach ($kol_vo as $v) {
 if ($v <= 5-$sostav) {
     $yes++;
}
}
if ($yes > 3);
echo floor($yes/3);

<?php

function ChooseTeam($n,$k,$y){

    $y     = explode(" ", $y);
    $team  = 0;
    $count = 0;

    for($i=0;$i<$n;$i++){
        if(($y[$i]+$k)<=5){
            $count++;
            if($count==3){
                $team++;
                $count=0;
            }
        }
    }

    echo $team;
}

$nk = trim(fgets(STDIN));
$nk = explode(" ", $nk);
$n  = $nk[0];
$k  = $nk[1];
$y = trim(fgets(STDIN));

ChooseTeam($n,$k,$y);

<?php
// 432A     Выбор команд
$in = fopen("php://stdin", 'r');

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

$input_line = fgets($in);
list($n, $k) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$max = 5 - (int) $k;
$col = 0;

foreach ($arr as $key => $value) {
    if ((int) $value <= $max) {
        $col ++;
    }
}

echo intval($col / 3);

?>

<?php
error_reporting("off");
//432A: Choosing Teams
list($n, $k) = explode(" ", trim(fgets(STDIN)));
$y = explode(" ", trim(fgets(STDIN)));
$valids = array();
foreach ($y as $value) {
  if ($value <= 5 - $k) {
    $valids[] = $value;
  }
}
$count = count($valids);
echo floor($count / 3);
?>


Monocarp has just learned a new card trick, and can't wait to present it to you. He shows you the entire deck of $$$n$$$ cards. You see that the values of cards from the topmost to the bottommost are integers $$$a_1, a_2, \dots, a_n$$$, and all values are different.Then he asks you to shuffle the deck $$$m$$$ times. With the $$$j$$$-th shuffle, you should take $$$b_j$$$ topmost cards and move them under the remaining $$$(n - b_j)$$$ cards without changing the order.And then, using some magic, Monocarp tells you the topmost card of the deck. However, you are not really buying that magic. You tell him that you know the topmost card yourself. Can you surprise Monocarp and tell him the topmost card before he shows it?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of cards in the deck. The second line contains $$$n$$$ pairwise distinct integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the values of the cards. The third line contains a single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of shuffles. The fourth line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_j \le n - 1$$$) — the amount of cards that are moved on the $$$j$$$-th shuffle. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$. The sum of $$$m$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the value of the card on the top of the deck after the deck is shuffled $$$m$$$ times.

NoteIn the first testcase, each shuffle effectively swaps two cards. After three swaps, the deck will be $$$[2, 1]$$$.In the second testcase, the second shuffle cancels what the first shuffle did. First, three topmost cards went underneath the last card, then that card went back below the remaining three cards. So the deck remained unchanged from the initial one — the topmost card has value $$$3$$$.

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));

        $m = trim(fgets(STDIN));
        $b = explode(' ', trim(fgets(STDIN)));

        $sSum = 0;
        for ($i=0; $i<$m; $i++) {
            $sSum = bcadd($sSum, $b[$i]);
        }

        $iIndex = bcmod($sSum, $n);
        echo $a[$iIndex] . PHP_EOL;
    }
?>

<?php

function run(){
    $n = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    $m = trim(fgets(STDIN));
    $brr = explode(' ', trim(fgets(STDIN)));
    $sum = 0;
    foreach($brr as $e){
             $sum += $e;
             $sum %= $n;
    }
    $sum %= $n;
    echo "$arr[$sum]\n";
}

$test_cases = trim(fgets(STDIN));
while($test_cases--){
    run();
}
?>

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

   $t = IO::getInt();
//   $point = ord('a') + ord('b') ;

   for($q=0; $q <$t; $q++) {
       $ans = 0;
       $n = IO::getInt();
       $a = IO::getArray();
       $m = IO::getInt();
       $b = IO::getArray();

     //   $bSum = array_sum($b);
     $index = 1;
       for($i = 0; $i <$m; $i++) {
          $index = $index + $b[$i] > $n ? $index + $b[$i] - $n :  $index + $b[$i];
       }

        IO::pr($a[$index-1]);
   }

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

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
         if(is_array($s)) {
             echo implode( ' ', $s), PHP_EOL;
         } else {
             echo $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 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  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
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));
        $b = explode(' ', trim(fgets(STDIN)));

        $iLeft = 0;
        $iRight = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iRight++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    $aCheck[] = "$i1 $i2";

                    if ($b[$i] > $b[$j]) {
                        $iLeft++;
                    }
                }

            }
        }

        //echo $iRight . PHP_EOL;
        //echo $iLeft;
        //exit;

        if ($iRight > 0 &&  $iLeft == 0) {
            echo $iRight . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        } else if ($iRight == 0 && $iLeft == 0){
            echo 0 . PHP_EOL;
        } else {
            echo -1 . PHP_EOL;
        }
    }
?>

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));

        $m = trim(fgets(STDIN));
        $b = explode(' ', trim(fgets(STDIN)));

        $iIndex = array_sum($b) % $n;
        echo $a[$iIndex] . PHP_EOL;
    }
?>

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $sA = $sA = str_replace(' ', '', trim(fgets(STDIN)));

        $m = trim(fgets(STDIN));
        $b = explode(' ', trim(fgets(STDIN)));

        for ($j=0; $j<$m; $j++) {
            $sNew = '';
            $countM = $b[$j];

            $sNew1 = substr($sA, $countM);
            $sNew2 = substr($sA, 0, $countM);
            $sNew = $sNew1 . $sNew2;

            $sA = $sNew;
        }
        echo $sNew[0] . PHP_EOL;

    }
?>

<?php

function run(){
    $n = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    $m = trim(fgets(STDIN));
    $brr = explode(' ', trim(fgets(STDIN)));
    $sum = 0;
    foreach($brr as $e){
             $sum += $e;
    }
    $sum %= $n;
    echo "$arr[$sum]\n";
}

$test_cases = trim(fgets(STDIN));
while($test_cases--){
    run();
}
?>

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

   $t = IO::getInt();
//   $point = ord('a') + ord('b') ;

   for($q=0; $q <$t; $q++) {
       $ans = 0;
       $n = IO::getInt();
       $a = IO::getArray();
       $m = IO::getInt();
       $b = IO::getArray();

       $bSum = array_sum($b);
     //   $s = floor($bSum/$n);
       $index = $bSum%$n;
     //   IO::pr($index);

        IO::pr($a[$index]);
   }

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

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
         if(is_array($s)) {
             echo implode( ' ', $s), PHP_EOL;
         } else {
             echo $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 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  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
{

}


There is a badminton championship in which $$$n$$$ players take part. The players are numbered from $$$1$$$ to $$$n$$$. The championship proceeds as follows: player $$$1$$$ and player $$$2$$$ play a game, then the winner and player $$$3$$$ play a game, and then the winner and player $$$4$$$ play a game, and so on. So, $$$n-1$$$ games are played, and the winner of the last game becomes the champion. There are no draws in the games.You want to find out the result of championship. Currently, you only know the following information:  Each player has either won $$$x$$$ games or $$$y$$$ games in the championship. Given $$$n$$$, $$$x$$$, and $$$y$$$, find out if there is a result that matches this information.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The only line of each test case contains three integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le x, y < n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Print the answer for each test case, one per line. If there is no result that matches the given information about $$$n$$$, $$$x$$$, $$$y$$$, print $$$-1$$$. Otherwise, print $$$n-1$$$ space separated integers, where the $$$i$$$-th integer is the player number of the winner of the $$$i$$$-th game.  If there are multiple valid results, print any.

NoteIn the first test case, player $$$1$$$ and player $$$4$$$ won $$$x$$$ times, player $$$2$$$ and player $$$3$$$ won $$$y$$$ times.In the second, third, and fifth test cases, no valid result exists.

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

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

   list($n, $x, $y) = IO::getArray();
   $ans = '';
   if(($x==0 && $y==0) || $x!=0 && $y != 0) {
        $ans = '-1';
   } else {
        $x = $x > 0 ? $x : $y;
        if(($n - 1) % $x == 0) {
             $c = $x;
             $w = 1;
			for($i=2; $i<=$n; $i++)
			{
				$ans .= $w . ' ';
				$c--;
				if(!$c) {
				    $w=$i+1;
					$c=$x;
				}
			}
        } else {
             $ans = '-1';
        }
   }
   IO::pr($ans);
}

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

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

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

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

   list($n, $x, $y) = IO::getArray();
   if($x * $x + $y != $n-1) {
         IO::pr('-1');
   } else {
        $it = 0;
        $j = 1;
        $ans = '';
       for($i=1; $i < $n - $y; $i++) {
          $it++;
          $ans .= $j . ' ';
          if($it == $x) {
               // IO::pr($i);
              $it = 0;
              $j = $i+2;

          }
       }
       $t = $n-$y;
       for($i=$n - $y; $i < $n; $i++) {
         $ans .= $t . ' ';
       }

     IO::pr($ans);
   }

}

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

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

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

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

   list($n, $x, $y) = IO::getArray();
   if($x * $x + $y != $n-1) {
         IO::pr('-1');
   } else {
        $it = 0;
        $j = 1;
        $ans = '';
       for($i=1; $i < $n - $y; $i++) {
          $it++;
          $ans .= $j . ' ';
          if($it == $x) {
               // IO::pr($i);
              $it = 0;
              $j = $i+2;

          }
       }
       $t = 0;
       for($i=$n - $y; $i < $n; $i++) {
         $ans .= $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;
    }
}

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

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

   list($n, $x, $y) = IO::getArray();
   if($x * $x + $y != $n-1) {
         IO::pr('-1');
   } else {
        $it = 0;
        $j = 1;
        $ans = '';
       for($i=1; $i < $n; $i++) {
          $it++;
          $ans .= $j . ' ';
          if($it == $x) {
               // IO::pr($i);
              $it = 0;
              $j = $i+2;

          }
       }
     IO::pr($ans);
   }

}

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

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

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

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

   list($n, $x, $y) = IO::getArray();
   if($y > 0 || $x * $x + $y != $n-1) {
         IO::pr('-1');
   } else {
        $it = 0;
        $j = 1;
        $ans = '';
       for($i=1; $i < $n; $i++) {
          $it++;
          $ans .= $j . ' ';
          if($it == $x) {
               // IO::pr($i);
              $it = 0;
              $j = $i+2;

          }
       }
     IO::pr($ans);
   }

}

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

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

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

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

   list($n, $x, $y) = IO::getArray();
   if($y > 0 || $x * $x + $y != $n-1) {
         IO::pr('-1');
   } else {
        $it = 0;
        $j = 1;
        $ans = '';
       for($i=1; $i < $n; $i++) {
          $it++;
          $ans .= $j . ' ';
          if($it == $x) {
               // IO::pr($i);
              $it = 0;
              $j = $i+1;

          }
       }
     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;
    }
}


Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the n - 2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109) — the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.

Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".

NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.  If k = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals.  If k = 1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds).  If k = 2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.

<?php
$a = trim(fgets(STDIN));
$d = array();
$e = 0;
$g = array();
$h = 1;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    $d[$e] = $b . $h;
    $g[$e] = "1";
    $e++;
    $h++;
    $d[$e] = $c . $h;
    $g[$e] = "2";
    $e++;
    $h++;
}
asort($d);
$i = array_keys($d);
sort($d);
$j = array_combine($i, $g);
ksort($j);
$l = array_slice($j, 0, $a);
sort($l);
$m = array_unique($l);
$n = array_keys($m);
$o = $n[1];
$p = count($l) - $n[1];
$r = max(floor($a / 2), $o);
$s = max(floor($a / 2), $p);
print implode("", array_fill(0, $r, "1"));
print implode("", array_fill(0, $a - $r, "0")) . "\n";
print implode("", array_fill(0, $s, "1"));
print implode("", array_fill(0, $a - $s, "0"));
?>