<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 200003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = fscanf(STDIN, str_repeat('%d ', $n));// array_filter();

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 200003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 100003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $sources = $ar;
    foreach($ar as &$el) {
        $el %= 100003;
    }
    unset($el);
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        //100003
        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];
    $maxIt = $sources[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
//
//    if ($n === 12500 && $t === 12) {
//        var_dump($totalRead, $totalPrepare, $totalLoop);
//        die;
//    }
}
//        var_dump($totalRead, $totalPrepare, $totalLoop);

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 10007;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = [];

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        if (!isset($latestPosition[$it])) {
            $latestPosition[$it] = $currentPos;
            continue;
        }

        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);

    if ($n === 12500 && $t === 12) {
        var_dump($totalRead, $totalPrepare, $totalLoop);
        die;
    }
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);

    if ($n === 12500 && $t === 12) {
        var_dump($totalRead, $totalPrepare, $totalLoop);
        die;
    }
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

$totalRead = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;
    if ($n === 12500 && $t === 11) {
        var_dump($afterRead - $beforeRead, $totalRead, $afterRead - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

$totalRead = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    if ($n === 12500 && $t === 10) {
        var_dump($afterRead - $beforeRead, $totalRead, $afterRead - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

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

$start = microtime(true);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $now = microtime(true);

    if ($n === 12500 && $t === 10) {
        var_dump($now - $beforeRead, $now - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

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

$ns = [];

while ($t--) {
    fscanf(STDIN, '%d', $n);
    $ns[] = $n;
    if ($n === 12500 && $t === 15) {
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n === 12500 && $t === 10) {
        $end = microtime(true);
        var_dump($end - $start, $ns);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

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

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500 && $t === 15){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500&& $t === 10) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

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

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500 && $t === 15){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500&& $t === 12) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

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

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%u', $t);
$startTime = microtime(true);

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

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;

        if ((microtime(true) - $startTime) > 0.2) {
            die(500);
            break;
        }
    }

    sleep(1);

    fprintf(STDOUT, '%d', (microtime(true) - $startTime) * 100);

    die;
    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%u', $t);
$startTime = microtime(true);

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

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;

        if ((microtime(true) - $startTime) > 0.2) {
            die(500);
            break;
        }
    }

    fprintf(STDOUT, '%d', microtime(true) * 1000);

    die;
    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

phpinfo();
die;

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

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

    /** @var array<int, array<int, int>> $pos */
    $pos = array_fill_keys($ar, []);

    foreach ($ar as $key => $it) {
        $pos[$it][] = $key;
    }

    $maxP = 1;
    $maxL = 0;
    $maxR = 0;
    $maxIt = $ar[0];

    foreach ($pos as $it => $occ) {
        $mI = count($occ);

        if ($maxP >= $mI) {
            continue;
        }

        // matrix, holding optimal powers if start from the index
        $dm = array_fill(0, $mI, 1);// array_fill_keys ($occ, 1);
        $dmStarts = array_keys($dm);

        $prevPos = $occ[0];
        foreach ($occ as $i => $currentPos) {
            $gap = $currentPos - $prevPos - 1;

            if (~$gap) {
                $powerWithGap = 1 + $dm[$i - 1] - $gap;

                if ($powerWithGap > 1) {
                    $dm[$i] = $powerWithGap;
                    $dmStarts[$i] = $start = $dmStarts[$i - 1];

                    if ($maxP < $powerWithGap) {
                        $maxP = $powerWithGap;
                        $maxL = $occ[$start];
                        $maxR = $currentPos;
                        $maxIt = $it;
                    }
                }
            }

            $prevPos = $currentPos;
        }
    }

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1

1
5
1 2 2 3 4

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3

 */


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

for($j = 0; $j < $i; $j++){
    $k = trim(fgets(STDIN));
    $a = array();
    for($m = 0; $m < $k; $m++){
        $d = explode(" ", trim(fgets(STDIN)));
        $a[$d[0]][] = $d[1];
    }
    ksort($a);
    $x = 0;
    $y = 0;
    $res = '';
    foreach($a as $key => $val){
        sort($val);
        if($key >= $x){
            for($t = 0; $t < $key - $x; $t++){
                    $res .= 'R';
                }
            $x = $key;
        } else {
            echo "NO\n";
            continue 2;
        }
        foreach($val as $v){
            if($v >= $y){
                for($t = 0; $t < $v - $y; $t++){
                    $res .= 'U';
                }
                $y = $v;
            } else {
                echo "NO\n";
                continue 3;
            }
        }

    }
    echo "YES\n";
    echo $res."\n";

}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
function cmp($a, $b)
{
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}
for($j=0;$j<$t;$j++)
{
    $n = trim(fgets($handle));
    $arr=[];
    for($i=0;$i<$n;$i++)
    {
        $a=trim(fgets($handle));
        $a=explode(" ",$a);

        $arr[]=[$a[0],$a[1]];
    }
    usort($arr,'cmp');
    $str='';$check=true;
    $lastx=0;$lasty=0;
    foreach ($arr as $k=>$v)
    {
        if($v[0]<$lastx || $v[1]<$lasty)
        {$check=false;break;}
        for($l=$lastx;$l<$v[0];$l++)
        {
            $str=$str."R";
        }
        for($l=$lasty;$l<$v[1];$l++)
        {
            $str=$str."U";
        }
        $lastx=$v[0];
        $lasty=$v[1];
    }
    if($check)
    {
        echo "YES"."\n";
        echo $str."\n";

    }else {
       echo "NO"."\n";
    }

}

?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     $d = array_intersect($b, $c);
     if(count($d) == 0)
     {
          print "NO\n";
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
$str1=trim(fgets(STDIN));
$str2=trim(fgets(STDIN));
$flag=0;
for ($i=0; $i <strlen($str1) ; $i++)
{
	for ($j=0; $j <strlen($str1) ; $j++)
	{
       if($str1[$i]==$str2[$j])
       	   {
       	   	$flag=1;
       	   	echo "YES\n";
       	   	break;
       	   }
	}
	if($flag==1)
		break;
}
if($flag==0)
echo "NO\n";
}


<?php

$n = (int)trim(fgets(STDIN));
$div_n = $n % 4;

$sum1 = 0;
$sum2 = 0;
$res_list = [];

foreach (range($n, 1) as $value)
{
	if ($sum1 <= $sum2)
	{
		$sum1 += $value;
		$res_list[] = $value;
	}
	else
	{
		$sum2 += $value;
	}
}

echo abs($sum1 - $sum2).PHP_EOL;
echo count($res_list).' '.implode(' ', array_reverse($res_list));


<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $a = maxPro($a, $b);
    print maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = bcmul(max($a), max($b));
        $aMax[] = bcmul(max($a), min($b));
        $aMax[] = bcmul(min($a), max($b));
        $aMax[] = bcmul(min($a), min($b));
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
$i = abs($h);
if($f >= $i)
{
     printf("%.0f", $f);
}
else
{
     printf("%.0f", $h);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
$i = max($f, $h);
printf("%.0f", $i);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
print max($f, $h);
?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    echo count($a);
    $max = max($a);
    $maxb = max($b);
    if ($max < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $max = max($a);
    $maxb = max($b);
    if ($max < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $maxb = max($b);
    if ($max < 0 && $maxb < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    foreach($a AS $k=> $v) {
        if ($max == $v) {
            unset($a[$k]);
        }
    }
    echo max($a) * max($b);
?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $maxa = max($a);
    $maxb = max($b);
    $mina = min($a);
    $minb = min($b);

    if ($maxa*$maxb > $mina*$minb ) {
        foreach($a AS $k=> $v) {
            if ($maxa == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($mina == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return (int)max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $a = maxPro($a, $b);
    print maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return ceil(max($aMax));
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));

    $maxa = max($a);
    $maxb = max($b);
    $mina = min($a);
    $minb = min($b);

    if ($maxa*$maxb > $mina*$minb ) {
        foreach($a AS $k=> $v) {
            if ($maxa == $v) {
                unset($a[$k]);
                break;
            }
        }
        $i = max($a) * max($b);
        echo (string)$i;
    } else {
        foreach($a AS $k=> $v) {
            if ($mina == $v) {
                unset($a[$k]);
                break;
            }
        }
        $i = min($a) * min($b);
        echo (string)$i;
    }

?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($ordersT, $s) = explode(" ", trim(fgets($file)));
$bArray = array();
$sArray = array();
for ($i = 1 ; $i<=$ordersT; $i++) {
    list($t, $p, $q) = explode(" ", trim(fgets($file)));
    switch ($t) {
        case 'B':
            if (isset($bArray[$p])) {
                $bArray[$p] += $q;
            }else{
                $bArray[$p] = $q;
            }
            break;
        case 'S':
            if (isset($sArray[$p])) {
                $sArray[$p] += $q;
            }else{
                $sArray[$p] = $q;
            }
            break;
    }
}

krsort($bArray);
ksort($sArray);

$printed = 0;
$sP = array();
foreach ($sArray as $p => $q) {
    if ($printed < $s) {
        $sP[] = "S $p $q";
        $printed++;
    }
}
$sP = array_reverse($sP);
echo implode(PHP_EOL, $sP).PHP_EOL;

$printed = 0;
foreach ($bArray as $p => $q) {
    if ($printed < $s) {
        echo "B $p $q".PHP_EOL;
        $printed++;
    }
}


<?php
    $q = (int)fgets(STDIN);
    $i=0;
    $all = [];
    $res=[];

    $ind = 200000;
    $left = 200000;
    $right = 200000;

    while($i<$q) {
        $str = fgets(STDIN);

        $str = explode(' ', $str);
        $ch = (string)$str[0];
        $id = (int)$str[1];

        if ($i==0) {
            $all[$id]=$ind;
        } else {
            switch ($ch) {
                case 'L':
                    $left--;
                    $all[$id] = $left;
                    break;
                case 'R':
                    $right++;
                    $all[$id] = $right;
                    break;
                case '?':
                    //если всего одна книга на полке
                    if ($i == 1) {
                        $res[] = 0;
                        break;
                    }

                    $key = $all[$id];
                    $l = $key - $left;
                    $r = $right - $key;
                    $res[] = $l < $r ? $l : $r;

                    break;
            }
        }
        $i++;
    }

    foreach ($res as $r) {
        echo $r.'
';
    }
?>


<?php
$lines  = @file("php://stdin");
$boxes_num = array_shift($lines);
$left_boxes_opened = 0;
$right_boxes_opened = 0;
$actions_num = 0;
foreach($lines  as $line ){
$box_state = explode(' ', $line);
$left_boxes_opened +=$box_state[0];
$right_boxes_opened +=$box_state[1];
}
if($right_boxes_opened > $boxes_num/2)
    $actions_num = $boxes_num - $right_boxes_opened;
else
    $actions_num = $right_boxes_opened;

if($left_boxes_opened > $boxes_num/2)
    $actions_num += $boxes_num - $left_boxes_opened;
else
    $actions_num += $left_boxes_opened;

echo $actions_num;

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

$count = fgets($f);

$leftOpen = 0;
$rightOpen = 0;

for ($i = 0; $i < $count; $i++) {
    $line = explode(" ", fgets($f));
    if ($line[0] > 0) $leftOpen += 1;
    if ($line[1] > 0) $rightOpen += 1;
}

$ans = 0;
if (($count/2) > $leftOpen) $ans += $leftOpen;
else $ans += $count-$leftOpen;
if (($count/2) > $rightOpen ) $ans += $rightOpen;
else $ans += $count-$rightOpen;

echo $ans;

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$x = array_sum($ar);
if($x == $a and $x == 0)
    $tmp1 = 0;
else
    if($x < $a/2)
        $tmp1 = $x;
    else
        $tmp1 = $a - $x;
$y = array_sum($br);
if($y == $a and $y == 0)
    $tmp2 = 0;
else
    if($y < $a/2)
        $tmp2 = $y;
    else
        $tmp2 = $a - $y;
echo $tmp1+$tmp2;

<?php
$lines  = @file("php://stdin");
$boxes_num = array_shift($lines);
$left_boxes_opened = 0;
$right_boxes_opened = 0;
$actions_num = 0;
foreach($lines  as $line ){
$box_state = explode(' ', $line);
$left_boxes_opened +=$box_state[0];
$right_boxes_opened +=$box_state[1];
}

if($right_boxes_opened > $left_boxes_opened){
    $actions_num = $boxes_num - $right_boxes_opened;
    $actions_num += $left_boxes_opened;
}
else{
    $actions_num = $boxes_num - $left_boxes_opened;
    $actions_num += $right_boxes_opened;
}

echo $actions_num;

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$tmp = array_sum(array_merge($ar, $br));
if($tmp <= $a){
    echo $tmp;
}else{
    echo $a*2-$tmp;
}

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$x1 = array_sum($ar);
$y1 = $a - array_sum($br);
$x2 = $a - array_sum($ar);
$y2 = array_sum($br);
echo min($x1+$y1,$y2+$x2);


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

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

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

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

$ir = new InputReader();

/* TASK */

$t = $ir->readInt();
for ($tt=0; $tt<$t; $tt++) {
	$n = $ir->readInt();
	$a = [];
	for ($nn=0; $nn<$n; $nn++) {
		$a[] = $ir->readArrayOfInt(2);
	}

	$b = array_fill(0, $n, 2);

	uasort($a, function($x, $y) { return $x[0]<=>$y[0];});

	reset($a);
	$x = current($a);
	//var_dump($a);
	$R = $x[1];
	reset($a);
	foreach ($a as $k=>$v){
		//echo "R = $R; checking {$v[0]} : {$v[1]}\n";
		if ($v[0]<=$R) {
			$R = max([$v[1], $R]);
			$b[$k] = 1;
		}
		else {
			echo implode(' ', $b)."\n";
			flush();
			continue 2;
		}
	}

	echo "-1\n";
	flush();
}


<?php

$ar = [];

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

for($q = 0; $q < $t; $q++)
{
  list($n, $m, $r, $c) = explode(' ', trim(fgets(STDIN)));

  for($i = 0; $i < $n; $i++)
  {
    $ar[$i] = str_split(trim(fgets(STDIN)));
  }

  // -1
  $hasBlack = false;

  for($row = 0; $row < $n; $row++)
  {
    if(in_array("B", $ar[$row]))
    {
      $hasBlack = true;
      break;
    }
  }

  if(!$hasBlack)
  {
    echo "-1\n";
    continue;
  }

  //0
  if($ar[$r - 1][$c - 1] === "B")
  {
    echo "0\n";
    continue;
  }

  if(in_array("B", $ar[$r - 1]))
  {
    echo "1\n";
    continue;
  }

  $in_column = false;
  for($row = 0; $row < $n; $row++)
  {
    if($ar[$row][$c - 1] === "B")
    {
      $in_column = true;
      break;
    }
  }

  if($in_column)
  {
    echo "1\n";
    continue;
  }

  echo "2\n";
}

?>


<?php
    $num =(int)fgets(STDIN);
    $res=[];
    while ($num-->0){
        $str=fgets(STDIN);
        $str = explode(' ',$str);
        $ll=(int)$str[0];
        $v=(int)$str[1];
        $l=(int)$str[2];
        $r=(int)$str[3];

        //первый столб после поезда
        if ($v>$r) {
            $count = floor($ll/$v);
            $res[]=$count;
            continue;
        }

        //первый столб до поезда
        if ($v<=$l) {
            $a = floor($l/$v);
            if (!($l%$v)) {
                $a--;
            }
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-($b-$a);
            $res[]=$count;
            continue;
        }

        //первый фонарь между поездом
        if ($l<$v && $v<=$r) {
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-$b;
            $res[]=$count;
            continue;
        }

        //ll - пункт назначения
        //v - позиция фонаря
        //l - начало длины поезда
        //r - конец длины поезда

        //686817107 73138233 67053564 180837627
        //7

        //868494849 135243336 281738625 468972539
        //5

        //100 51 51 51
        //0

        //10 2 3 7
        //3

        //1234 1 100 199
        //1134

        //99 200
    }
    /*
echo '______
';
    */
    foreach ($res as $r) {
        echo $r.'
';
    }

?>

<?php
    $num =(int)fgets(STDIN);
    $res=[];
    while ($num-->0){
        $str=fgets(STDIN);
        $str = explode(' ',$str);
        $ll=(int)$str[0];
        $v=(int)$str[1];
        $l=(int)$str[2];
        $r=(int)$str[3];

        if ($v>$r) {
            $count = floor($ll/$v);
            $res[]=$count;
            continue;
        }

        if ($v<$l && $r<$ll) {
            $a = floor($l/$v);
            if (!($l%$v)) {
                $a--;
            }
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-($b-$a);
            $res[]=$count;
            continue;
        }

        //первый фонарь между поездом
        if ($l<$v && $v<$r) {
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-$b;
            $res[]=$count;
            continue;
        }

        if ($v > $r) {
            $c = floor($ll/$v);
            $count = $c;
            $res[]=$count;
            continue;
        }

        $i = $v;
        $count = 0;

        if ($i<$l) {
            $c = floor($l / $v);
            if (!($l%$v)) {
                $c--;
            }
/*
            echo $c.' (1)
';
*/
            $count+=$c;
        }

        $k2 = 0;
        if ($r>$v){
            $k2 = floor($r / $v);
        }

        $k3 = ($k2+1) *$v;
        if ($ll>$k3 && !(($ll-$k3)%$v)) {
            $count+=1;
/*
            echo '1 (2)
';
*/
        }

        if ($r<$ll) {
            $k = $ll - $k3;
            $c = floor($k / $v);
            if ($c<0){
                $c=0;
            }
            $count += $c;
/*
            echo $c . ' (3)
';
*/

        }

/*

        while ($i<=$ll) {
            if ($i<$l || $i>$r) {
                $count++;
                echo $i.'
';
            }
            $i+=$v;

        }
*/
        //echo $count;
        $res[]=$count;

        //ll - пункт назначения
        //v - позиция фонаря
        //l - начало длины поезда
        //r - конец длины поезда

        //686817107 73138233 67053564 180837627
        //7

        //868494849 135243336 281738625 468972539
        //5

        //100 51 51 51
        //0

        //10 2 3 7
        //3

        //1234 1 100 199
        //1134

        //99 200
    }
    /*
echo '______
';
    */
    foreach ($res as $r) {
        echo $r.'
';
    }

?>


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

    for($i=0; $i<$t; $i++) {
        list($n, $d) = explode(' ', trim(fgets(STDIN)));

       if($d > $n) {
           $bR = 0;
            for($j=1; $j<$n; $j++) {
                if($j + ceil($d/($j+1)) <= $n) {
                    $bR++;
                    break;
                }
            }
            if($bR > 0) {
                echo "YES\n";
            }else{
                echo "NO\n";
            }

        } else {
            echo "YES\n";
        }

    }

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b < $c)
     {
          $d = 0;
          for($y = 0; $y <= floor(sqrt($c)); $y++)
          {
               $e = ceil($c / ($y + 1));
               if($b >= $y + $e)
               {
                    $d = 1;
                    break;
               }
          }
          if($d == 0)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $m; $j++) {
    list($n,$d) = explode(' ', trim(fgets(STDIN)));
    if ($d <= $n) {
        echo 'YES'. "\n";
    } else {
        $bFlag = false;
        $c = $d;
        $k = 1;
        for ($i = 1; $i < $n; $i++) {
            $c = $k + ceil($d/($k + 1));
            if ($c <= $n) {
                //echo 'Дней на оптимизацию = ' . $k . "  Итог =   " .  $c  . "   День до дедлайна = " . $n . "  \n";
                $bFlag = true;
                break;
            }
            $k++;
        }
        if ($bFlag) {
            echo 'YES'. "\n";
        } else {
            echo 'NO'. "\n";
        }
    }
}

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

$ex = explode("\n", $f);
$r = [];
foreach (array_slice($ex, 1) as $task) {
    if (!$task) {
        continue;
    }
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b < $c)
     {
          $d = 0;
          for($y = 0; $y <= floor(sqrt($b)); $y++)
          {
               $e = ceil($c / ($y + 1));
               if($b >= $y + $e)
               {
                    $d = 1;
                    break;
               }
          }
          if($d == 0)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     else
     {
          print "YES\n";
     }
}
?>

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

$ex = explode("\n", $f);
array_shift($ex);
print_r($ex);
foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

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

$ex = explode("\n", $f);
array_shift($ex);

foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

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

$ex = explode("\n", $f);
array_shift($ex);
$r = [];
foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);

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

$ex = explode("\n", $f);
$r = [];
foreach (array_slice($ex, 1) as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);


<?php

// your code goes here

$initial = fgets(STDIN);
$initial = trim($initial);

// echo the initial
echo $initial . PHP_EOL;

$names = explode(" ", $initial);

$n = fgets(STDIN);
$n = trim($n);
$n += 0;

for($i = 0; $i < $n; $i++)
{
	$c = fgets(STDIN);
	$c = explode(" ", trim($c));
	if($names[0] == $c[0])
		$names[0] = $c[1];
	else
		$names[1] = $c[1];

	echo $names[0] . " " . $names[1] . PHP_EOL;
}

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

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

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $i." ".$kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	//$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   else
   {
    	$newRep=$replace[$i];
    	//$newKill=$newKill;
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

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

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "output:\n$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $i." ".$kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	//$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   else
   {
    	$newRep=$replace[$i];
    	//$newKill=$newKill;
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

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

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "output:\n$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   if($kill[$i]==$newRep)
    {
    	$newRep=$replace[$i];
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php

// your code goes here

$initial = fgets(STDIN);
$initial = trim($initial);

// echo the initial
echo $initial . PHP_EOL;

$n = fgets(STDIN);
$n = trim($n);
$n += 0;

for($i = 0; $i < $n; $i++)
{
	$c = fgets(STDIN);
	$c = explode(" ", trim($c));
	$initial = str_replace($c[0], $c[1], $initial);
	echo $initial . PHP_EOL;
}

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

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

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   if($kill[$i]==$newRep)
    {
    	$newRep=$replace[$i];
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/


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

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

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

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

$ir = new InputReader();

/* TASK */

list($n, $x, $y) = $ir->readArrayOfInt(3);
$b = $ir->readArrayOfInt($n);

if ($x>$y) {
	$cnt = $n;
} else {
	$c = 0;
	for ($i=0; $i<$n; $i++) {
		if ($b[$i]<=$x) {
			$c++;
		}
	}

	$cnt = ceil($c/2);
}

echo $cnt;

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($d);
if($b <= $c)
{
     $e = 0;
     for($x = 0; $x < $a; $x++)
     {
          if($d[$x] <= $b)
          {
               $e++;
          }
          else
          {
               break;
          }
     }
     $f = ceil($e / 2);
     print $f;
}
elseif($b > $c)
{
     print $a;
}
?>

<?php

$dat = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$n = $dat[0];
$x = $dat[1];
$y = $dat[2];

$c = 0;

if($x > $y){
    fwrite(STDOUT, $n);
}else{
    for($i = 0; $i<$n; $i++){
        if($a[$i] <= $x) $c++;
    }
    fwrite(STDOUT, round($c/2));
}

?>

<?php

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

$line = explode(" ", rtrim(fgets($in)));

$n = $line[0];
$x = $line[1];
$y = $line[2];

$line = explode(" ", rtrim(fgets($in)));

for($i = 0; $i<$n; ++$i){
    $a[$i] = $line[$i];
    $a[$i] *= 1;
}

if ($x > $y){
    echo $n;
    return false;
}

sort($a);

for($i = 0; $i<$n; ++$i){
        if ($a[$i] > $x) {
            echo  floor(($i + 1) / 2);
            return false;
        }
}

echo floor(($n + 1) / 2);

function what($x){fprintf(STDERR, $x . "\n");}
?>


<?
$arr=explode('.',trim(fgets(STDIN)));
$num=strlen($arr[0]);
$cel=$arr[0];
$dr=$arr[1];
if($cel[$num-1]!=9){
    if($dr[0]>=5) {$cel[$num-1]=$cel[$num-1]+1; echo $cel;}
    else echo $cel;
} else{
    echo "GOTO Vasilisa.";
}
?>

<?php
error_reporting("off");
//99A: Help Far Away Kingdom
$n = str_split(trim(fgets(STDIN))); //$n = str_split("123456789123456789.999");
$dot = array_search(".", $n);
$lastint = $n[$dot - 1];
$firstdec = $n[$dot + 1];
$beforedot = array();
for ($i = 0; $i < $dot; $i++) {
    $beforedot[] = $n[$i];
}
$int = implode($beforedot);
if ($lastint == 9) {
    echo "GOTO Vasilisa.";
} else {
    if ($firstdec >= 5) {
        $int = substr($int, 0, -1);
        $int .= $lastint + 1;
    }
    echo $int;
}
?>

<?php

    $a = trim(fgets(STDIN));
    $t=explode('.', $a);
    $cel=$t[0];$dr=$t[1];
    $cel_l=strlen($cel);
    if($cel[$cel_l-1]!=9){
if($dr[0]<5){printf("%s\n", $cel);}else{$cel[$cel_l-1]=$cel[$cel_l-1]+1;printf("%s\n", $cel);

}

    }else{printf("%s\n", "GOTO Vasilisa.");}

?>

<?php

while (FALSE !== ($line = fgets(STDIN))) {

    list($intPart, $fracPart) =  explode('.', $line,2);

    $index = strlen($intPart);
    $index--;

    if($intPart[$index] == 9){
        echo 'GOTO Vasilisa.' . PHP_EOL;
        continue;
    }

    if($fracPart[0] >= 5){
        $intPart[$index] = $intPart[$index] + 1;
    }
    echo $intPart . PHP_EOL;
}

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
if ($parts[0][strlen($parts[0])-1]=="9")
    echo "GOTO Vasilisa.";
else
    echo (bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = array_search(".", $b);
$d = implode(array_slice($b, $c + 1));
if(($b[$c - 1] != 9) && (0 . "." . $d < 0.5))
{
    print implode(array_slice($b, 0, $c));
}
elseif(($b[$c - 1] != 9) && (0 . "." . $d >= 0.5))
{
    print implode(array_slice($b, 0, $c)) + 1;
}
elseif($b[$c - 1] == 9)
{
    print "GOTO Vasilisa.";
}
?>

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
echo "=".$parts[0][strlen($parts[0])-1]."=";
if ($parts[0][strlen($parts[0])-1]=="9")
	echo "GOTO Vasilisa.";
else
	echo (bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?php
fscanf(STDIN, "%s", $s);
echo (strpos($s,"9.")!==false)?"GOTO Vasilisa.":number_format(round($s),0,".","");
?>

<?php
fscanf(STDIN, "%s", $s);
echo (strpos($s,"9.")!==false)?"GOTO vasilisa":number_format(round($s),0,".","");
?>

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
echo (strpos("".$s,"9.")!==false)?"GOTO Vasilisa.":(bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?
$arr=explode('.',trim(fgets(STDIN)));
$num=strlen($arr[0]);
$cel=$arr[0];
$dr=$arr[1];
if($cel[$num-1]!=9){
    if($dr[0]<5) echo $arr[0];
    elseif($dr[0]>=5) echo $arr[0]+1;
} else{
    echo "GOTO Vasilisa.";
}
?>


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

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

for ($i = 0; $i < $n; $i++) {
  $s = trim(fgets($file));

  $ans = ceil(sqrt($s));

  echo $ans.PHP_EOL;
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $j = IO::str();
    $sum = 0;
    $count = 0;
    $n = 1;
    while ($sum < $j) {
        $count++;
        $sum = $sum + $n;
        $n += 2;
    }
    IO::line($count);
}

?>


<?php
$f = fopen ("php://stdin", 'r' ) ;
$lines = file("php://stdin");
function parseint($n){
    return(intval($n));
}
$epson_num = $lines[0];
$epson_watched = array_map("parseint", explode(" ",(strval($lines[1]))));
$epson_lost = (($epson_num * ($epson_num + 1))/2) - array_sum ($epson_watched);

print $epson_lost ;
?>

<?php
$handle = fopen ("php://stdin","r");
$n = fgets($handle);
$result=0;
$tmp=0;
$tmp=fgets($handle);
$tmp=explode(" ",$tmp);
for($i=1;$i<$n+1;$i++)
{
$result+=$tmp[$i-1];
}

echo ($n*($n + 1) / 2) - $result;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = range(1, $a);
$d = array_diff($c, $b);
print implode("", $d);
?>

<?php
$fh = fopen('php://stdin', 'r');
$input = '';
while ($line = fgets($fh)){
  $input .= $line;
}

list($series_count, $view_series) = explode(PHP_EOL, $input);
$view_series_array = explode(' ', $view_series);

$summ = $series_count * ($series_count + 1) / 2;

foreach ($view_series_array as $num) {
    $summ -= $num;
}

echo $summ;

<?php
$f = fopen ("php://stdin.txt", 'r' ) ;
$lines = file("php://stdin.txt");
function parseint($n){
    return(intval($n));
}
$epson_num = $lines[0];
$epson_watched = array_map("parseint", explode(" ",(strval($lines[1]))));
$epson_lost = (($epson_num * ($epson_num + 1))/2) - array_sum ($epson_watched);

print $epson_lost ;

?>


<?
$name=trim(fgets(STDIN));
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$privs=array('posted on','commented on','likes');
foreach($arr as $val){
    preg_match('/(.*?) (posted on|commented on|likes) (.*?)(\'s)/',$val,$m);
//  print_r ($m);
    if($m[2]=='posted on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=15; $newarr[$m[1]]+=15;}
    if($m[2]=='commented on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=10; $newarr[$m[1]]+=10;}
    if($m[2]=='likes' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=5; $newarr[$m[1]]+=5;}
    if($m[1]!=$name && $m[3]!=$name) {$newarr[$m[1]]+=0; $newarr[$m[3]]+=0;}
}
unset($newarr[$name]);
ksort($newarr);
foreach($newarr as $key=>$val){
     $new2[]=array($key,$val);
}
function cmp($a,$b) {
    if ($a[1]==$b[1])
return $a[0]>$b[0];
    else return $a[1]<$b[1];
}
usort($new2,'cmp');
//print_r($newarr);
foreach($new2 as $val){
    echo $val[0]."\n";
}
//print_r($new2);

?>

<?php
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $name = trim(fgets($in));
    $n = trim(fgets($in));
    for($i = 0; $i < $n; $i++)
    {
        $tokens = split(" ", fgets($in));
        $point = 0;
        $a = "";
        if($tokens[1] == "posted")
        {
            $point = 15;
            list($a, $tmp) = split("'", $tokens[3]);
        }
        else if ($tokens[1] == "commented")
        {
            $point = 10;
            list($a, $tmp) = split("'", $tokens[3]);
        }
        else
        {
            $point = 5;
            list($a, $tmp) = split("'", $tokens[2]);
        }
        if(!($tokens[0] == $name || $a == $name)) $point = 0;
        $map[$tokens[0]] += $point;
        $map[$a] += $point;
    }
    unset($map[$name]);
    foreach($map as $key => $value) $arr[] = array($key, $value);
    function my_cmp($a, $b)
    {
        if($a[1]!= $b[1]) return $a[1] > $b[1] ? -1 : 1;
        return $a[0] < $b[0] ? -1 : 1;
    }
    usort($arr, "my_cmp");

    foreach($arr as $val) echo $val[0] . "\n";
    fclose($in);
?>

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

	preg_match("!(\w{1,10}) posted on (\w{1,10})'s wall!", $str, $matches);
	if(!empty($matches))
	{
		if($matches[1]==$iam)
		{
			if(!isset($friends[$matches[2]]))
				$friends[$matches[2]] = 15;
			else
				$friends[$matches[2]] += 15;
		}
		elseif($matches[2]==$iam)
		{
			if(!isset($friends[$matches[1]]))
				$friends[$matches[1]] = 15;
			else
				$friends[$matches[1]] += 15;
		}
		else
		{
			if(!isset($friends[$matches[1]]))
				$friends[$matches[1]] = 0;
			if(!isset($friends[$matches[2]]))
				$friends[$matches[2]] = 0;
		}
	}
	else
	{
		preg_match("!(\w{1,10}) commented on (\w{1,10})'s post!", $str, $matches);
		if(!empty($matches))
		{
			if($matches[1]==$iam)
			{
				if(!isset($friends[$matches[2]]))
					$friends[$matches[2]] = 10;
				else
					$friends[$matches[2]] += 10;
			}
			elseif($matches[2]==$iam)
			{
				if(!isset($friends[$matches[1]]))
					$friends[$matches[1]] = 10;
				else
					$friends[$matches[1]] += 10;
			}
			else
			{
				if(!isset($friends[$matches[1]]))
					$friends[$matches[1]] = 0;
				if(!isset($friends[$matches[2]]))
					$friends[$matches[2]] = 0;
			}
		}
		else
		{
			preg_match("!(\w{1,10}) likes (\w{1,10})'s post!", $str, $matches);
			if(!empty($matches))
			{
				if($matches[1]==$iam)
				{
					if(!isset($friends[$matches[2]]))
						$friends[$matches[2]] = 5;
					else
						$friends[$matches[2]] += 5;
				}
				elseif($matches[2]==$iam)
				{
					if(!isset($friends[$matches[1]]))
						$friends[$matches[1]] = 5;
					else
						$friends[$matches[1]] += 5;
				}
				else
				{
					if(!isset($friends[$matches[1]]))
						$friends[$matches[1]] = 0;
					if(!isset($friends[$matches[2]]))
						$friends[$matches[2]] = 0;
				}
			}
		}
	}
}

arsort($friends);

function prr($arr)
{
	sort($arr);
	foreach($arr as $value)
		print $value."\n";
}

for($i=15000;$i>=0; $i-=5)
{
	$temp = array();
	foreach($friends as $key=>$value)
	{
		if($value == $i)
			$temp[] = $key;
	}
	prr($temp);
}

?>

<?php
// $input = fopen('input','r');
$name = trim(fgets(STDIN));
$nr = trim(fgets(STDIN));
$assoc = [];

for ($i = 0; $i < $nr; $i++) {
    $action[] = trim(fgets(STDIN));
    $action[$i] = explode(' ', $action[$i]);

    if ($action[$i][1] == 'posted') {
        $name = substr($action[$i][3],0,-2);
        @$assoc[$name] += 15;
    } elseif ($action[$i][1] == 'commented') {
        $name = $action[$i][0];
        @$assoc[$name] += 10;
    } elseif ($action[$i][1] == 'likes') {
        $name = $action[$i][0];
        @$assoc[$name] += 5;
    }
}

ksort($assoc);
foreach($assoc as $x => $x_value) {
    echo  $x . "</br>";
  }

<?php
//$input = fopen('input','r');
$name = trim(fgets(STDIN));
$nr = trim(fgets(STDIN));
$assoc = [];

for ($i = 0; $i < $nr; $i++) {
    $action[] = trim(fgets(STDIN));
    $action[$i] = explode(' ', $action[$i]);

    if ($action[$i][1] == 'posted') {
        $name = substr($action[$i][3],0,-2);
        @$assoc[$name] += 15;
    } elseif ($action[$i][1] == 'commented') {
        $name = $action[$i][0];
        @$assoc[$name] += 10;
    } elseif ($action[$i][1] == 'likes') {
        $name = $action[$i][0];
        @$assoc[$name] += 5;
    }
}

ksort($assoc);
foreach($assoc as $x => $x_value) {
    echo  $x . "</br>";
  }

<?php
$input = fopen('input','r');
$name = trim(fgets($input));
$nr = trim(fgets($input));
$assoc = [];

for ($i = 0; $i < $nr; $i++) {
    $action[] = trim(fgets($input));
    $action[$i] = explode(' ', $action[$i]);

    if ($action[$i][1] == 'posted') {
        $name = substr($action[$i][3],0,-2);
        @$assoc[$name] += 15;
    } elseif ($action[$i][1] == 'commented') {
        $name = $action[$i][0];
        @$assoc[$name] += 10;
    } elseif ($action[$i][1] == 'likes') {
        $name = $action[$i][0];
        @$assoc[$name] += 5;
    }
}

ksort($assoc);
foreach($assoc as $x => $x_value) {
    echo  $x . "</br>";
  }

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

	preg_match("!(\w{1,10}) posted on (\w{1,10})'s wall!", $str, $matches);
	if(!empty($matches))
	{
		if($matches[1]==$iam)
		{
			if(!isset($friends[$matches[2]]))
				$friends[$matches[2]] = 15;
			else
				$friends[$matches[2]] += 15;
		}
		elseif($matches[2]==$iam)
		{
			if(!isset($friends[$matches[1]]))
				$friends[$matches[1]] = 15;
			else
				$friends[$matches[1]] += 15;
		}
		else
		{
			if(!isset($friends[$matches[1]]))
				$friends[$matches[1]] = 0;
			if(!isset($friends[$matches[2]]))
				$friends[$matches[2]] = 0;
		}
	}
	else
	{
		preg_match("!(\w{1,10}) commented on (\w{1,10})'s post!", $str, $matches);
		if(!empty($matches))
		{
			if($matches[1]==$iam)
			{
				if(!isset($friends[$matches[2]]))
					$friends[$matches[2]] = 10;
				else
					$friends[$matches[2]] += 10;
			}
			elseif($matches[2]==$iam)
			{
				if(!isset($friends[$matches[1]]))
					$friends[$matches[1]] = 10;
				else
					$friends[$matches[1]] += 10;
			}
			else
			{
				if(!isset($friends[$matches[1]]))
					$friends[$matches[1]] = 0;
				if(!isset($friends[$matches[2]]))
					$friends[$matches[2]] = 0;
			}
		}
		else
		{
			preg_match("!(\w{1,10}) likes (\w{1,10})'s post!", $str, $matches);
			if(!empty($matches))
			{
				if($matches[1]==$iam)
				{
					if(!isset($friends[$matches[2]]))
						$friends[$matches[2]] = 5;
					else
						$friends[$matches[2]] += 5;
				}
				elseif($matches[2]==$iam)
				{
					if(!isset($friends[$matches[1]]))
						$friends[$matches[1]] = 5;
					else
						$friends[$matches[1]] += 5;
				}
				else
				{
					if(!isset($friends[$matches[1]]))
						$friends[$matches[1]] = 0;
					if(!isset($friends[$matches[2]]))
						$friends[$matches[2]] = 0;
				}
			}
		}
	}
}

arsort($friends);

function prr($arr)
{
	sort($arr);
	foreach($arr as $value)
		print $value."\n";
}

for($i=0;$i<=15000; $i+=5)
{
	$temp = array();
	foreach($friends as $key=>$value)
	{
		if($value == $i)
			$temp[] = $key;
	}
	prr($temp);
}

?>

<?
$fopen=fopen('input.txt','r');
define(STDIN,$fopen);
/*
http://codeforces.ru/problemset/problem/59/B
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
*/
?>
<?
$name=trim(fgets(STDIN));
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$privs=array('posted on','commented on','likes');
foreach($arr as $val){
    preg_match('/(.*?) (posted on|commented on|likes) (.*?)(\'s)/',$val,$m);
//  print_r ($m);
    if($m[2]=='posted on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=15; $newarr[$m[1]]+=0;}
    if($m[2]=='commented on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=10; $newarr[$m[1]]+=0;}
    if($m[2]=='likes' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=5; $newarr[$m[1]]+=0;}
    if($m[1]!=$name && $m[3]!=$name) {$newarr[$m[1]]+=0; $newarr[$m[3]]+=0;}
}
unset($newarr[$name]);
ksort($newarr);
foreach($newarr as $key=>$val){
     $new2[]=array($key,$val);
}
function cmp($a,$b) {
    if ($a[1]==$b[1])
    return $a[0]<$b[0];
    else return $a[1]>$b[1];
}
usort($new2,'cmp');
//print_r($newarr);
foreach($new2 as $val){
    echo $val[0]."\n";
}
//print_r($new2);

?>

<?
$name=trim(fgets(STDIN));
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$privs=array('posted on','commented on','likes');
foreach($arr as $val){
    preg_match('/(.*?) (posted on|commented on|likes) (.*?)(\'s)/',$val,$m);
//  print_r ($m);
    if($m[2]=='posted on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=15; $newarr[$m[1]]+=0;}
    if($m[2]=='commented on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=10; $newarr[$m[1]]+=0;}
    if($m[2]=='likes' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=5; $newarr[$m[1]]+=0;}
    if($m[1]!=$name && $m[3]!=$name) {$newarr[$m[1]]+=0; $newarr[$m[3]]+=0;}
}
unset($newarr[$name]);
ksort($newarr);
foreach($newarr as $key=>$val){
     $new2[]=array($key,$val);
}
function cmp($a,$b) {
    if ($a[0]==$b[0])
    return $a[1]<$b[1];
    else return $a[0]>$b[0];
}
usort($new2,'cmp');
//print_r($newarr);
foreach($new2 as $val){
    echo $val[0]."\n";
}
//print_r($new2);

?>

<?
$name=trim(fgets(STDIN));
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$privs=array('posted on','commented on','likes');
foreach($arr as $val){
    preg_match('/(.*?) (posted on|commented on|likes) (.*?)(\'s)/',$val,$m);
    if($m[2]=='posted on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=15; $newarr[$m[1]]+=0;}
    if($m[2]=='commented on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=10; $newarr[$m[1]]+=0;}
    if($m[2]=='likes' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=5; $newarr[$m[1]]+=0;}
    if($m[1]!=$name && $m[3]!=$name) {$newarr[$m[1]]+=0; $newarr[$m[3]]+=0;}
}
unset($newarr[$name]);
ksort($newarr);
foreach($newarr as $key=>$val){
     $new2[]=array($key,$val);
}
function cmp($a,$b) {
    if ($a[1]==$b[1])
return $a[0]>$b[0];
    else return $a[1]<$b[1];
}
usort($new2,'cmp');
foreach($new2 as $val){
    echo $val[0]."\n";
}
?>

<?
$name=trim(fgets(STDIN));
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$privs=array('posted on','commented on','likes');
foreach($arr as $val){
    preg_match('/(.*?) (posted on|commented on|likes) (.*?)(\'s)/',$val,$m);
//  print_r ($m);
    if($m[2]=='posted on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=15; $newarr[$m[1]]+=0;}
    if($m[2]=='commented on' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=10; $newarr[$m[1]]+=0;}
    if($m[2]=='likes' && ($m[1]==$name || $m[3]==$name)) {$newarr[$m[3]]+=5; $newarr[$m[1]]+=0;}
    if($m[1]!=$name && $m[3]!=$name) {$newarr[$m[1]]+=0; $newarr[$m[3]]+=0;}
}
unset($newarr[$name]);
ksort($newarr);
foreach($newarr as $key=>$val){
     $new2[]=array($key,$val);
}
function cmp($a,$b) {
    if ($a[1]==$b[1])
return $a[0]>$b[0];
    else return $a[1]<$b[1];
}
usort($new2,'cmp');
//print_r($newarr);
foreach($new2 as $val){
    echo $val[0]."\n";
}
//print_r($new2);

?>


<?php

$inputs[0] = 5;
$inputs[1] ='01111001';
$inputs[2] ='0000';
$inputs[3] ='111111';
$inputs[4] ='101010101';
$inputs[5] ='011011110111';

$debug = false;

$answers = [];
$tests = readline();
for ($t = 1; $t <= $tests; $t++){

	$score = 0;
	#$str = $inputs[$t];
	$str = readline();
	$len = strlen($str);

	$round = 0;
	while (true){

		$round++;

		$max_start = -1;
		$start = -1;
		$max = -1;
		$counter = 0;

		for ($i = 0; $i < $len; $i++){
			if($str[$i] == '1' && $counter == 0){
				$start = $i;
				$counter++;
			}elseif ($str[$i] == '1' && $counter != 0){
				$counter++;
			}else{
				if($counter > $max){
					$max = $counter;
					$max_start = $start;
				}
				$counter = 0;
			}
		}
		if($counter > $max){
			$max = $counter;
			$max_start = $start;
		}else{
			if($debug) echo "Counter ($counter) no es mayor a max ($max)". PHP_EOL;
		}

		if($debug) echo "Replacing from $max_start to $max" . PHP_EOL;
		$str = substr_replace($str,'', $max_start, $max);
		$len = strlen($str);
		if($round % 2){
			$score += $max;
			if($debug) echo "Round $t-$round: $str - Alice +$max". PHP_EOL;
		}else{
			//$score += $max;
			if($debug) echo "Round $t-$round: $str - Bob +$max". PHP_EOL;
		}

		if($max == 0) break;

	}
	$answers[]= $score;

}
foreach ($answers as $a) echo $a.PHP_EOL;

<?php

$inputs[0] = 5;
$inputs[1] ='01111001';
$inputs[2] ='0000';
$inputs[3] ='111111';
$inputs[4] ='101010101';
$inputs[5] ='011011110111';

$debug = false;

$tests = $debug ? $inputs[0] : readline();
$answers = [];
for ($t = 1; $t <= $tests; $t++){

	$score = 0;
	$str = $debug ? $inputs[$t] : readline();
	$len = strlen($str);

		$counter = 0;
		$consecutives = [];
		for ($i = 0; $i < $len; $i++){
			if($str[$i] == '1'){
				$counter++;
				if($i == $len-1 && $counter > 0) $consecutives[]= $counter;
			}else {
				if($counter > 0) $consecutives[]= $counter;
				$counter = 0;
			}
		}

		rsort($consecutives);

		$alice = 0;
		$bob = 0;
		foreach ($consecutives as $round => $score){
			if($round == 0){
				$alice += $score;
			}else{
				if($round % 2) $bob += $score; else $alice+= $score;
			}
		}

	$answers[]= $alice;

}
foreach ($answers as $a) echo $a . PHP_EOL;

<?php
$inputCount = trim(fgets(STDIN));
for ($i = 0; $i < $inputCount; $i++) runProgram();

function runProgram()
{
  $line = trim(fgets(STDIN));
  $points = 0;

  for ($j = 1;; $j++) {
    $max = 0;
    $counter = 0;

    // Get maximum from 1..1 from current line
    for ($i = 0; $i < strlen($line); $i++) {
      if ($line[$i] == '1') {
        $counter += 1;
      } else {
        $counter = 0;
      }

      if ($counter > $max) $max = $counter;
    }

    if ($j % 2 != 0) $points += $max;

    if ($max == 0) break;
    else {
      $search = str_repeat('1', $max);
      $line = preg_replace("/$search/", '', $line, 1);
    }
  }

  echo "$points\n";
}


<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$queue = 0;
$maxSize = 0;
$time = 0;
$prevTime = 0;
for ($i = 0; $i < $n; ++$i) {
    $str = fgets($fIn);
    $str = preg_split('[ ]', $str);
    $queue += $str[1];
    if ($i != 0) {
        $queue -= $str[0] - $prevTime;
        $queue = max($str[1], $queue);
    }
    if ($queue > $maxSize) {
        $maxSize = $queue;
    }
    $prevTime = $str[0];
    #echo $prevTime, ' ', $queue, PHP_EOL;
    $time += $str[0];
}
fclose($fIn);
echo ($prevTime + $queue), ' ', $maxSize;
?>

<?
$num = trim(fgets(STDIN));
for($i = 0; $i < $num; $i++){
    $arr[] = explode(' ', trim(fgets(STDIN)));
}
$sms_now = 0;
$time_last = 0;
$max = 0;
$now = 0;
foreach($arr as $a){
    if($sms_now != 0){
        if($sms_now - ($a[0] - $time_last) >= 0)
            $tmp = $sms_now - ($a[0] - $time_last);
        else
            $tmp = 0;
        $sms_now =  $tmp + $a[1];
    }
    else
        $sms_now = $a[1];
    if($max < $sms_now)
        $max = $sms_now;
    $time_last = $a[0];
}
echo ($time_last+$sms_now) . ' ' . $max . '
';
?>

<?php
$file = "php://stdin";
$lines = explode("\n", str_replace("\r", "", file_get_contents($file)));
$n = array_shift($lines);
$queue = 0;
$p = 0;
$max = 0;

for ($i = 0; $i < $n; $i++) {
    list($time, $count) = explode(" ", $lines[$i]);
    $queue = max(0, $queue - $time + $p) + $count;
    $max = max($queue, $max);
    $p = $time;
}
$time = $p + $queue;
echo $time, " ", $max;

<?

$n = (int)fgets(STDIN);

$msg = array();
while($n--) {
    list($time, $msg_cnt) = explode(" ", fgets(STDIN));
    $msg[$time] = $msg_cnt;
}

$queue_cnt = 0;
$queue_max = 0;
$last_time = 0;
$total_time = 0;
foreach($msg as $time => $cnt) {
    $time_diff = $time - $last_time;
    $last_time = $time;
    $queue_cnt = max(0, $queue_cnt - $time_diff);

    $queue_cnt += $cnt;
    $queue_max = max($queue_cnt, $queue_max);

    $total_time += $time_diff;
}

$total_time += $queue_cnt;

echo $total_time, " ", $queue_max;

<?php
$a = trim(fgets(STDIN));
list($b, $c) = explode(" ", trim(fgets(STDIN)));
$f = $b;
$g = array($c);
if($a == 1)
{
    print $b + $c . " " . $c;
}
else
{
    for($x = 1; $x < $a; $x++)
    {
        list($d, $e) = explode(" ", trim(fgets(STDIN)));
        if($d >= $b + $c)
        {
            $b = $d;
            $c = $e;
            $f = $b;
        }
        else
        {
            $c += $e;
            $h = $c - $x;
            array_push($g, $h);
        }
    }
    rsort($g);
    print $c + $f . " " . $g[0];
}
?>

<?
$num = trim(fgets(STDIN));
for($i = 0; $i < $num; $i++){
    $arr[] = explode(' ', trim(fgets(STDIN)));
}
$sms_now = 0;
$time_last = 0;
$max = 0;
$now = 0;
foreach($arr as $a){
if(trim($a[0]) - $time_last >= 0)
$tmp = trim($a[0]) - $time_last;
else $tmp = 0;
    if($sms_now != 0)
        $sms_now = ($sms_now - $tmp) + trim($a[1]);
    else
        $sms_now = trim($a[1]);
    if($max < $sms_now)
        $max = $sms_now;
    $time_last = trim($a[0]);
}
echo ($time_last+$sms_now) . ' ' . $max . '
';
?>

<?

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

$sms_now = 0;
$time_last = 0;
$max = 0;
$now = 0;
foreach($arr as $a){

    if($sms_now != 0)
        $sms_now = ($sms_now - ($a[0] - $time_last)) + $a[1];
    else
        $sms_now = $a[1];
    if($max < $sms_now)
        $max = $sms_now;
    $time_last = $a[0];
}
echo ($time_last+$sms_now) . ' ' . $max . '
';
?>

<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$queue = 0;
$maxSize = 0;
$time = 0;
$prevTime = 0;
for ($i = 0; $i < $n; ++$i) {
    $str = fgets($fIn);
    $str = preg_split('[ ]', $str);
    $queue += $str[1];
    if ($i != 0) {
        $queue -= max(0, $str[0] - $prevTime);
        $queue = max(0, $queue);
    }
    if ($queue > $maxSize) {
        $maxSize = $queue;
    }
    $prevTime = $str[0];
    #echo $prevTime, ' ', $queue, PHP_EOL;
    $time += $str[0];
}
fclose($fIn);
if ($queue == 0)
    $queue = $str[1];
echo ($prevTime + $queue), ' ', $maxSize;
?>

<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$queue = 0;
$maxSize = 0;
$time = 0;
$prevTime = 0;
for ($i = 0; $i < $n; ++$i) {
    $str = fgets($fIn);
    $str = preg_split('[ ]', $str);
    $queue += $str[1];
    if ($i != 0) {
        $queue -= max(0, $str[0] - $prevTime);
        $queue = max(0, $queue);
    }
    if ($queue > $maxSize) {
        $maxSize = $queue;
    }
    $prevTime = $str[0];
    #echo $prevTime, ' ', $queue, PHP_EOL;
    $time += $str[0];
}
fclose($fIn);

echo ($prevTime + $queue), ' ', $maxSize;
?>

<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$queue = 0;
$maxSize = 0;
$time = 0;
$prevTime = 0;
for ($i = 0; $i < $n; ++$i) {
    $str = fgets($fIn);
    $str = preg_split('[ ]', $str);
    $queue += $str[1];
    if ($i != 0)
        $queue -= max(0, $str[0] - $prevTime);
    if ($queue > $maxSize) {
        $maxSize = $queue;
    }
    $prevTime = $str[0];
    $time += $str[0];
}
fclose($fIn);

echo ($prevTime + $queue), ' ', $maxSize;
?>


<?php
// 454A     Маленькая пони и пещера кристаллов
$in = fopen("php://stdin", 'r');

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

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

$out = array();

$m = ($n + 1) /2;

for ($i=0; $i < $m ; $i++) {
    $out[$i]  = str_repeat('*', $m-$i-1);
    $out[$i] .= str_repeat('D', ($i+1)*2-1);
    $out[$i] .= str_repeat('*', $m-$i-1);
    $out[$i] .= "\n";
    if ($i !== $n) {
        $out[$n-$i-1] = $out[$i];
    }
}

for ($i=0; $i < $n ; $i++) {
    echo $out[$i];
}

?>

<?php
error_reporting("off");
//454A: Little Pony and Crystal Mine
$n = trim(fgets(STDIN)); //$n = 227;
$dsize = 1;
for ($i = $n; $i > ceil($n / 2); $i--) {
  $a = ($n - $dsize) / 2;
  echo str_repeat("*", $a);
  echo str_repeat("D", $dsize);
  echo str_repeat("*", $a)."\n";
  $dsize = $dsize + 2;
}
echo str_repeat("D", $dsize)."\n";
$dsize = $dsize - 2;
$top = ceil($n / 2) + 1;
for ($i = $top; $i <= $n; $i++) {
  $a = ($n - $dsize) / 2;
  echo str_repeat("*", $a);
  echo str_repeat("D", $dsize);
  echo str_repeat("*", $a)."\n";
  $dsize = $dsize - 2;
}
?>

<?php
/**
 * Cik d burtus vajadzees i-tajaa rindaa
 * 1  2  3  4  5  6   7
 * 2  4  6  8  10 12  14
 * 1  3  5  7  9  11  13
 */
function D($i)
{
	return $i * 2 - 1;
}

fscanf(STDIN, "%d\n", $n);
$output = "";
for ($row = 1; $row <= $n; $row++)
{
	$D_count = D(min($n + 1 - $row, $row));
	$S_count = ($n - $D_count) / 2;

	$output .= str_repeat("*", $S_count);
	$output .= str_repeat("D", $D_count);
	$output .= str_repeat("*", $S_count);
	$output .= "\n";
}

fprintf(STDOUT, "%s", $output);
?>

<?php
/**
 * Cik d burtus vajadzees i-tajaa rindaa
 * 1  2  3  4  5  6   7
 * 2  4  6  8  10 12  14
 * 1  3  5  7  9  11  13
 */
function D($i)
{
	return $i * 2 - 1;
}

fscanf(STDIN, "%d\n", $n);
$output = "";
for ($row = 1; $row <= $n; $row++)
{
	$D_count = D(min($n + 1 - $row, $row));
	$S_count = ($n - $D_count) / 2;

	$output .= str_repeat("*", $S_count);
	$output .= str_repeat("D", $D_count);
	$output .= str_repeat("*", $S_count);
	$output .= "\n";
}

fprintf(STDOUT, "%d", $output);
?>


<?php

function process($str)
{
    $ex = [];

    $a = null;
    $b = null;
    $c = null;

    $str = str_split($str);

    for ($i = 0; $i < count($str); $i++) {

        $num = ord($str[$i]);

        if ($num <= ord('9')) {
            $a = $i;
        } elseif ($num <= ord('Z')) {
            $b = $i;
        } else {
            $c = $i;
        }
    }

    if($a !== null)
    {
        $ex['1'] = $a;
    }
    if($b !== null)
    {
        $ex['A'] = $b;
    }
    if($c !== null)
    {
        $ex['a'] = $c;
    }

    $insert = array_values(array_diff(['1', 'A', 'a'], array_keys($ex)));

    if (count($ex) == 1) {

        $pos = reset($ex);
        $i = $pos != 0 ? 0 : $pos + 1;
        $j = $i + 1 != $pos ? $i + 1 : $pos + 1;

        $str[$i] = $insert[0];
        $str[$j] = $insert[1];

    } elseif (count($ex) == 2) {

        list($a, $b) = array_values($ex);

        $t = $a;
        $a = $a > $b ? $b : $a;
        $b = $a == $b ? $t : $b;

        $insert = $insert[0];
        $str[0 < $a ? 0 : ($a + 1 == $b ? $b + 1 : $a + 1)] = $insert;
    }

    return implode($str);
}

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

$list = [];

for ($i = 0; $i < $n; $i++) {
    $str = trim(fgets($handle));
    $list[] = process($str);
}

foreach ($list as $str) {
    echo $str, PHP_EOL;
}


<?php
$n = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$total = 0;
$symbols = 0;
$numb=0;
$second_round=false;
	for($i=0; $i<strlen($str); $i++)
	{
		$symbols++;
		if($str[$i]=='.' || $str[$i]=='?' || $str[$i]=='!')
		{
			if($second_round)
			{
				if($symbols-1>$n)
				{
					print "Impossible";
					return;
				}
			}
			else
			{
				if($symbols>$n)
				{
					print "Impossible";
					return;
				}
			}

			if($total+$symbols<=$n)
			{
				$total+=$symbols;
				$second_round=true;
			}
			else
			{
				$total=$symbols-1;
				$numb++;
				$second_round=true;
			}
			$symbols=0;
		}
	}
print $numb+1;

?>

<?php
$n = (int)fgets(STDIN,1111);
$text=trim(fgets(STDIN,11111));

function a($str){
    return strlen(trim($str))+1;
}
$otr = array_map('a', preg_split('~[.?!]~',$text));
$cnt=0;
$last=$n;
foreach($otr as $cur){
    if($cur<2)
        continue;
    if($cur>$n){
        exit('Impossible');
    }
    if($cur+1+$last<=$n)
        $last+=$cur+1;
    else{
        ++$cnt;
        $last=$cur;
    }
}
print $cnt;

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

function a($str){
    return strlen(trim($str))+1;
}
$otr = array_map('a', preg_split('~[.?!]~',$text));
$cnt=0;
$last=$n;
foreach($otr as $cur){
    if($cur<2)
        continue;
    if($cur>$n){
        exit('Impossible');
    }
    if($cur+1+$last<=$n)
        $last+=$cur+1;
    else{
        ++$cnt;
        $last=$cur;
    }
}
print $cnt;

<?php
$n = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$total = 0;
$symbols = 0;
$numb=0;
	for($i=0; $i<strlen($str); $i++)
	{
		$symbols++;
		if($str[$i]=='.' || $str[$i]=='?' || $str[$i]=='!')
		{
			if($symbols>$n)
			{
				print "Impossible";
				return;
			}

			if($total+$symbols<=$n)
			{
				$total+=$symbols;
			}
			else
			{
				$total=$symbols-1;
				$numb++;
			}
			$symbols=0;
		}
	}
print $numb+1;

?>

<?php
$n = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$total = 0;
$symbols = 0;
$numb=0;
	for($i=0; $i<strlen($str); $i++)
	{
		$symbols++;
		if($str[$i]=='.' || $str[$i]=='?' || $str[$i]=='!')
		{
			if($symbols>$n)
			{
				print "Imbossible";
				return;
			}

			if($total+$symbols<=$n)
			{
				$total+=$symbols;
			}
			else
			{
				$total=$symbols-1;
				$numb++;
			}
			$symbols=0;
		}
	}
print $numb+1;

?>

<?php
$n = (int)fgets(STDIN,1111);
$text=trim(fgets(STDIN,1111));

function a($str){
    return strlen($str)+1;
}
$otr = array_map('a', preg_split('~[.?!] ~',$text));
$cnt=0;
$last=$n;
foreach($otr as $cur){
    if($cur>$n){
        exit('Impossible');
    }
    if($cur+1+$last<=$n)
        $last+=$cur+1;
    else{
        ++$cnt;
        $last=$cur;
    }
}
print $cnt;

<?php
$n = (int)fgets(STDIN,1111);
$text=trim(fgets(STDIN,1111));

function a($str){
    return strlen(trim($str))+1;
}
$otr = array_map('a', preg_split('~[.?!]~',$text));
$cnt=0;
$last=$n;
//var_dump($otr);
foreach($otr as $cur){
    if($cur<2)
        continue;
    if($cur>$n){
        exit('Impossible');
    }
    if($cur+1+$last<=$n)
        $last+=$cur+1;
    else{
        ++$cnt;
        $last=$cur;
    }
}
print $cnt;


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));
$f = $a - $b + 1;
for($x = 0; $x < $f; $x++)
{
     for($y = 0; $y < $b; $y++)
     {
          $d[$x + $y] = ($d[$x + $y] + $e[$y]) % $c;
     }
}
print implode(" ", $d);
?>

<?
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function debug($var){echo '<pre>'; print_r($var); echo '</pre>';}
    function read_str(){return trim(fgets($GLOBALS['file']));}
    function read_array(){return explode(' ', read_str());}
    /***************************************************************/
    $arr = read_array();
    $n = $arr[0];
    $m = $arr[1];
    $c = $arr[2];
    $GLOBALS['c'] = $c;

    $a = read_array();
    $b = read_array();

    $k = $n - $m + 1;

    function add($a, $b)
    {
        return ($a+$b)%$GLOBALS['c'];
    }

    for($i=0; $i<$k; $i++)
    {
        for($j=0; $j<$m; $j++)
        {
            $a[$j+$i] = add($a[$j+$i], $b[$j]);
        }
    }

    foreach($a as $n) echo $n, ' ';
?>


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = bcdiv($a, $c, 0);
$e = bcdiv($b, $c, 0);
$f = bcadd($d, $e);
$g = bcadd($a, $b);
$h = bcdiv($g, $c, 0);
if($h > $f)
{
     $i = bcmod($a, $c);
     $j = bcmod($b, $c);
     print $h . " " . min(bcsub($c, $i), bcsub($c, $j));
}
else
{
     print $f . " 0";
}
?>

<?php
#1181A
[$s, $m, $c] = explode(' ', trim(fgets(STDIN)));
$nuts = bcadd(explode('.', bcdiv($s, $c))[0], explode('.', bcdiv($m, $c))[0]);
$sFree = bcmod($s, $c);
$mFree = bcmod($m, $c);
$refund = '0';
if ($sFree !== '0' && $mFree !== '0' && bcadd($sFree, $mFree) >= $c) {
    $refund = bcadd($c, bcmul(max($sFree, $mFree), '-1'));
    $nuts = bcadd($nuts, '1');
}
echo $nuts . ' ' . $refund;

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = bcdiv($a, $c, 0);
$e = bcdiv($b, $c, 0);
$f = bcadd($d, $e);
$g = bcadd($a, $b);
$h = bcdiv($g, $c, 0);
if($h > $f)
{
     $i = bcmod($a, $c);
     $j = bcmod($b, $c);
     print $h . " " . min($c - $i, $c - $j);
}
else
{
     print $f . " 0";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = bcdiv($a, $c, 0);
$e = bcdiv($b, $c, 0);
$f = bcadd($d, $e);
$g = bcadd($a, $b);
$h = bcdiv($g, $c, 0);
if($h > $f)
{
     $i = bcmod($a, $c);
     $j = bcmod($b, $c);
     print $h . " " . min($i, $j);
}
else
{
     print $f . " 0";
}
?>

<?php
#1181A
[$s, $m, $c] = explode(' ', trim(fgets(STDIN)));
$nuts = floor($s / $c) + floor($m / $c);
$sFree = $s % $c;
$mFree = $m % $c;
$refund = 0;
if ($sFree !== 0 && $mFree !== 0 && ($sFree + $mFree) >= $c) {
    $refund = $c - max($sFree, $mFree);
    $nuts++;
}
echo $nuts . ' ' . $refund;

<?php
#1181A
[$s, $m, $c] = explode(' ', trim(fgets(STDIN)));

$nuts = floor((float)$s / (float)$c) + floor((float)$m / (float)$c);
$sFree = bcmod($s, $c);
$mFree = bcmod($m, $c);
$refund = 0;
if ($sFree !== 0 && $mFree !== 0 && bcadd($sFree, $mFree) >= $c) {
    $refund = $c - max($sFree, $mFree);
    $nuts++;
}
echo $nuts . ' ' . $refund;


<?php
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$arr_temp = fgets($handle);
$arr = explode(" ",$arr_temp);
array_walk($arr,'intval');
$b=array();
$cont=0;
for ($i=0; $i < $n * 2; $i++) {
	if(count($b)>$cont)$cont=count($b);
	if(!isset($b[$arr[$i]])){
		$b[$arr[$i]]=1;
	}else{
		unset($b[$arr[$i]]);
	}
}
print $cont;

<?php
define('SUBMIT', true);
if(SUBMIT){
    $stdin = STDIN;
}else {
    $file = 'sample';
    $stdin = fopen($file, 'r');
}

$n = trim(fgets($stdin));
$ni = array_filter(explode(' ', trim(fgets($stdin))));
$max = 0;
$current = 0;

$table = [];
for($i = 0; $i < $n*2; $i++){
    if(!isset($table[$ni[$i]])){
        $current++;
        $table[$ni[$i]] = 1;
        if($current > $max){
            $max = $current;
        }
    }else{
        $current--;
    }

}
echo $max;

/**
 * I/O samples
 *
 * trim(fgets($stdin));
 * fscanf($stdin, "%d %d %d", $n, $m, $k);
 * array_filter(explode(' ', trim(fgets($stdin))));
 *
 * print();
 *
 */