<?php
fscanf(STDIN, '%d', $N);

$nums = array();
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    $nums[] = $n;
}

list($m, $G, $cnt, $nums) = shellSort($nums, $N);

echo "$m\n";
echo join(' ', $G)."\n";
echo "$cnt\n";
foreach ($nums as $num) {
    echo "$num\n";
}

function insertionSort($A, $n, $g, &$cnt)
{
    for ($i = $g; $i < $n; $i++) {
        $val = $A[$i];
        $j = $i - $g;

        while ($j >= 0 && $A[$j] > $val) {
            $A[$j+$g] = $A[$j];
            $j -= $g;
            $cnt++;
        }
        $A[$j+$g] = $val;
    }

    return $A;
}

function shellSort($A, $n)
{
    $G = array();
    for ($i = 1; $i <= floor(sqrt($n)); $i++) {
        $G[] = $i*$i;
    }
    $G = array_reverse($G);

    $cnt = 0;
    foreach ($G as $g) {
        $A = insertionSort($A, $n, $g, $cnt);
    }

    return array(count($G), $G, $cnt, $A);
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Shell Sort

Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.

1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A[j+g] = A[j]
7 j = j - g
8 cnt++
9 A[j+g] = v
10
11 shellSort(A, n)
12 cnt = 0
13 m = ?
14 G[] = {?, ?,..., ?}
15 for i = 0 to m-1
16 insertionSort(A, n, G[i])

A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$.

Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements:

$1 \leq m \leq 100$

$0 \leq G_i \leq n$

cnt does not exceed $\lceil n^{1.5}\rceil$

Input

In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line.

Output

In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line.

In the third line, print cnt in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively.

This problem has multiple solutions and the judge will be performed by a special validator.

Constraints

$1 \leq n \leq 1,000,000$

$0 \leq A_i \leq 10^9$

Sample Input 1

5
5
1
4
3
2

Sample Output 1

2
4 1
3
1
2
3
4
5

Sample Input 2

3
3
2
1

Sample Output 2

1
1
3
1
2
3

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


<?php
fscanf(STDIN, '%d', $N);

$nums = array();
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    $nums[] = $n;
}

list($m, $G, $cnt, $nums) = shellSort($nums, $N);

echo "$m\n";
echo join(' ', $G)."\n";
echo "$cnt\n";
foreach ($nums as $num) {
    echo "$num\n";
}

function insertionSort($A, $n, $g, &$cnt)
{
    for ($i = $g; $i < $n; $i++) {
        $val = $A[$i];
        $j = $i - $g;

        while ($j >= 0 && $A[$j] > $val) {
            $A[$j+$g] = $A[$j];
            $j -= $g;
            $cnt++;
        }
        $A[$j+$g] = $val;
    }

    return $A;
}

function shellSort($A, $n)
{
    // h_{i+1} = 3 h_{i} + 1 ( 1 <= $h < $n )
    $G = array();
    for ($h = 1; $h < $n; $h = 3*$h+1) {
        $G[] = $h;
    }
    $G = array_reverse($G);

    $cnt = 0;
    foreach ($G as $g) {
        $A = insertionSort($A, $n, $g, $cnt);
    }

    return array(count($G), $G, $cnt, $A);
}


<?php
fscanf(STDIN, '%d', $N);

$nums = array();
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    $nums[] = $n;
}

list($m, $G, $cnt, $nums) = shellSort($nums, $N);

echo "$m\n";
echo join(' ', $G)."\n";
echo "$cnt\n";
foreach ($nums as $num) {
    echo "$num\n";
}

function insertionSort($A, $n, $g, &$cnt)
{
    for ($i = $g; $i < $n; $i++) {
        $val = $A[$i];
        $j = $i - $g;

        while ($j >= 0 && $A[$j] > $val) {
            $A[$j+$g] = $A[$j];
            $j -= $g;
            $cnt++;
        }
        $A[$j+$g] = $val;
    }

    return $A;
}

function shellSort($A, $n)
{
    // h_{i+1} = 3 h_{i} + 1 ( 1 <= $h <= $n )
    $G = array();
    for ($h = 1; $h <= $n; $h = 3*$h+1) {
        $G[] = $h;
    }
    $G = array_reverse($G);

    $cnt = 0;
    foreach ($G as $g) {
        $A = insertionSort($A, $n, $g, $cnt);
    }

    return array(count($G), $G, $cnt, $A);
}


<?php
$n=(int)fgets(STDIN);
$A=[];
for($i=0;$i<$n;$i++) $A[]=(int)fgets(STDIN);
$cnt=0;
shSort($A,$n);

function shSort($A,$n){
  global $cnt;
  $G=[];
  for($i=1;$i<=$n;$i=$i*3+1){$G[]=$i;}
  $G=array_reverse($G);
  foreach($G as $g) $A=inSort($A,$n,$g);

  echo count($G),PHP_EOL,implode(' ',$G),PHP_EOL,$cnt,PHP_EOL;
  foreach($A as $a) echo $a,PHP_EOL;
}

function inSort($A,$n,$g){
  global $cnt;
  for($i=$g;$i<$n;$i++){
    $v=$A[$i];
    $j=$i-$g;
    while($j>=0 && $A[$j]>$v){
      $A[$j+$g]=$A[$j];
      $j-=$g;
      ++$cnt;
    }
    $A[$j+$g]=$v;
  }
  return $A;
}
?>


<?php
$n=(int)fgets(STDIN);
$A=[];
for($i=0;$i<$n;$i++) $A[]=(int)fgets(STDIN);
shSort($A,$n);

function inSort(&$A,$n,$g){
  global $cnt;
  for($i=$g;$i<$n;$i++){
    $v=$A[$i];
    $j=$i-$g;
    while($j>=0 && $A[$j]>$v){
      $A[$j+$g]=$A[$j];
      $j-=$g;
      ++$cnt;
    }
    $A[$j+$g]=$v;
  }
}

function shSort(&$A,$n){
  global $cnt;
  $cnt=0;
  $G=[];
  for($i=1;$i<=$n;$i=$i*3+1) $G[]=$i;
  $G=array_reverse($G);
  foreach($G as $g) inSort($A,$n,$g);

  echo count($G),PHP_EOL,implode(' ',$G),PHP_EOL,$cnt,PHP_EOL;
  foreach($A as $a){
    echo $a,PHP_EOL;
    unset($a);
  }
}


<?php
ini_set("memory_limit", "-1");

// input
$input = STDIN;
$n = (int)fgets($input);
for ($i = 0; $i < $n; $i++) {
    $A[] = (int)fgets($input);
}

// Calculation of the shell sort interval G
for ($i = 17; $i > 0; $i--) {
    $g = (int)((2.25 ** $i - 1) / 1.25);
    if ($g <= $n) {
        $G[] = $g;
    }
}

// Shell Sort
$cnt = 0;
foreach ($G as $g) {
    // Insertion Sort
    for ($i = $g; $i < $n; $i++) {
        $v = $A[$i];
        $j = $i - $g;
        while ($j >= 0 && $A[$j] > $v) {
            $A[$j+$g] = $A[$j];
            $j -= $g;
            $cnt++;
        }
        $A[$j+$g] = $v;
    }
}

// output
print count($G) . "\n";
print implode(" ", $G) . "\n";
print $cnt . "\n";
print implode("\n", $A) . "\n";


<?php

class Answer
{
    private $num;
    private $sequence;
    private $m;
    private $count = 0;
    private $interval;
    public function __construct()
    {
        ini_set('memory_limit', '-1');
        $this->num = fgets(STDIN);
        for ($i = 0; $i < $this->num; $i++) {
            $this->sequence[] = trim(fgets(STDIN));
        }
    }

    public function getAnswer(){
        $ans = $this->shellSort($this->sequence, $this->num);
        echo $this->m . PHP_EOL;
        echo join(' ', $this->interval) . PHP_EOL;
        echo $this->count . PHP_EOL;
        for ($i = 0; $i < count($ans); $i++) {
            echo $ans[$i] . PHP_EOL;
        }
    }

    public function insertSort($seq, $interval, $num)
    {
        for ($i = $interval; $i < $num; $i++) {
            $tmp = $seq[$i];
            $j = $i - $interval;
            while ($j >= 0 && $seq[$j] > $tmp) {
                $seq[$j + $interval] = $seq[$j];
                $j = $j - $interval;
                $this->count++;
            }
            $seq[$j + $interval] = $tmp;
        }
        return $seq;
    }

    public function shellSort($seq, $num)
    {
        for ($i = 1; $i <= $num; $i = 3 * $i + 1) {
            $this->interval[] = $i;
        }
        $this->m = count($this->interval);
        $this->interval = array_reverse($this->interval);
        for ($i = 0; $i < $this->m; $i++) {
            $seq = $this->insertSort($seq, $this->interval[$i], $num);
        }
        return $seq;
    }
}
$answer = new Answer;
$answer->getAnswer();


<?php
fscanf(STDIN, '%d', $length);
$dictionary = array();

for($i=0; $i<$length; ++$i){
    fscanf(STDIN, '%s %s', $action, $str);
    switch ($action) {
    case 'insert':
        $dictionary=array_merge($dictionary,array($str=>true));
        break;
    case 'find':
        if(isset($dictionary[$str])){
            echo 'yes'.PHP_EOL;
        } else {
            echo 'no'.PHP_EOL;
        }
        break;
    }
}

Search III

Your task is to write a program of a simple dictionary which implements the following instructions:

insert str: insert a string str in to the dictionary

find str: if the distionary contains str, then print 'yes', otherwise print 'no'

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Constraints

A string consists of 'A', 'C', 'G', or 'T'

1 ≤ length of a string ≤ 12

n ≤ 1000000

Sample Input 1

5
insert A
insert T
insert C
find G
find A

Sample Output 1

no
yes

Sample Input 2

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Sample Output 2

yes
no
no
yes
yes
yes

Notes

Template in C


<?php
// Your code here!
$number = intval(fgets(STDIN));
$num_array = explode(" ",fgets(STDIN));

$sum = 0;
for($i=0;$i<$number-1;$i++){
    for($j=$i+1;$j<$number;$j++){
        $sum += ($num_array[$i]*$num_array[$j])% (pow(10, 9) + 7);
        $sum = $sum % (pow(10, 9) + 7);
    }
}

echo $sum;

?>

Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).

Constraints

2 \leq N \leq 2\times 10^5

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829


<?php

$n = fgets(STDIN);
$list = explode(" ",fgets(STDIN));
$mod = 10**9+7;
$total = array_sum($list);
$result;

for($i=0;$i<$n-1;$i++){
    $total-=$list[$i];
    $result+=$total*$list[$i]%$mod;
    $result%=$mod;
}

echo $result%$mod."\n";


<?php
define("MOD", 10**9+7);

$N = (int)trim(fgets(STDIN));
//$T = trim(fgets(STDIN));
//list($D,$T,$S) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$rsum=0;
for($i=0;$i<$N;$i++) {
  $rsum=addm($rsum,$A[$i]);
}
$sum=0;
for($i=0;$i<$N;$i++) {
  $rsum -= $A[$i];
  if ($rsum < 0) $rsum+=MOD;
  $r = $A[$i]*$rsum;
  $sum = addm($sum,$r);
}
printf("%d\n",$sum);

//https://atcoder.jp/contests/abc145/submissions/8474723

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}

//解説のcombinationを移植
Class combinationsnk {
  private $fact;
  private $ifact;
  public function __construct(int $n) {
    $this->fact[0]=1;
    for($i=1;$i<=$n;$i++) $this->fact[$i]=mulm($this->fact[$i-1],$i);
    $this->ifact[$n]=powerm($this->fact[$n],MOD-2);
    for ($i = $n; $i >= 1; --$i) $this->ifact[$i-1] = mulm($this->ifact[$i],$i);
  }
  public function calc(int $n,int $k)
  {
    if ($k < 0 || $k > $n) return 0;
    return mulm(mulm($this->fact[$n],$this->ifact[$k]),$this->ifact[$n-$k]);
  }
}


<?php
//Sの部分文字列になりうる全パターンに対して一致率を算出して一致率が高いパターンに関して
//Tが部分文字列となるのに必要な文字の変更数を算出する
fscanf(STDIN,"%d",$n);
$sum = 0;
$a_li = explode(" ",trim(fgets(STDIN)));
$sum_ini = array_sum($a_li);
for($i=0;$i<$n-1;$i++){
 $sum_ini -= $a_li[$i];
 $sum += $a_li[$i]*($sum_ini);
}

echo ($sum%(10**9+7));


<?php
$N = (int) trim(fgets(STDIN));
$A = trim(fgets(STDIN));
$A_arr = explode(" ", $A);

$result = 0;
for ($i=1; $i <= $N - 1; $i++) {
  for ($j=$i+1; $j <= $N; $j++) {
    $result += $A_arr[$i - 1] * $A_arr[$j - 1];
  }
  $result = $result % 1000000007;
}
echo $result;


<?php
fscanf(STDIN, "%d", $n);
$input = explode(' ',trim(fgets(STDIN)));

$mod = 10**9 + 7;
$ans = 0;
foreach ($input as $key => $value) {
    for ($i=1; $i <= $n ; $i++) {
        $num = $key+$i;
        if ($num < $n) {
            $result = $value * $input[$num] % $mod;
            $ans += $result;
        }
    }
}
echo $ans % $mod;


<?php
list($n) = ints();
$a = ints();
$max = max($a);
if ($max === 1) exit('pairwise coprime');
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) ++$cnt[$a[$i]];
    else $cnt[$a[$i]] = 1;
}
$p = new Prime($max);
$primes = $p->primes();
$maxc = 0;
foreach ($primes as $prime) {
    $c = 0;
    for ($j = $prime; $j <= $max; $j += $prime) {
        if (isset($cnt[$j])) $c += $cnt[$j];
    }
    $maxc = max($maxc, $c);
}
if ($maxc === $n) exit('not coprime');
if ($maxc === 1) exit('pairwise coprime');
echo 'setwise coprime';

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 素数関係
class Prime
{
    private $n;
    private $table; // 素数の添字にtrueが格納された配列

    function __construct($n)
    {
        $this->n = $n;
        $this->makeTable();
    }

    function makeTable()
    {
        $n = $this->n;
        $table = array_fill(2, $n - 1, true);
        $rn = (int) floor(sqrt($n));
        for ($i = 2; $i <= $rn; $i++) {
            if (!isset($table[$i])) continue;
            for ($j = 2 * $i; $j <= $n; $j += $i) {
                unset($table[$j]);
            }
        }
        $this->table = $table;
    }

    // 素数
    function primes()
    {
        return array_keys($this->table);
    }

    function table()
    {
        return $this->table;
    }

    // 素数判定
    function isPrime($x)
    {
        return isset($this->table[$x]);
    }

    // 素因数分解
    function factor($x)
    {
        $res = [];
        if ($x === 1) return $res;
        $primes = $this->primes();
        foreach ($primes as $prime) {
            while ($x % $prime === 0) {
                if (isset($res[$prime])) $res[$prime]++;
                else $res[$prime] = 1;
                $x /= $prime;
            }
        }
        if ($x > 1) {
            if (isset($res[$x])) $res[$x]++;
            else $res[$x] = 1;
        }
        return $res;
    }
}

Score : 500 points

Problem Statement

We have N integers. The i-th number is A_i.

\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.

\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.

Determine if \{A_i\} is pairwise coprime, setwise coprime, or neither.

Here, GCD(\ldots) denotes greatest common divisor.

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

If \{A_i\} is pairwise coprime, print pairwise coprime; if \{A_i\} is setwise coprime, print setwise coprime; if neither, print not coprime.

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.


<?php
list($n) = ints();
$a = ints();
$max = max($a);
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) ++$cnt[$a[$i]];
    else $cnt[$a[$i]] = 1;
}
$p = new Prime($max);
$primes = $p->primes();
$maxc = 0;
foreach ($primes as $prime) {
    $c = 0;
    for ($j = $prime; $j <= $max; $j += $prime) {
        if (isset($cnt[$j])) $c += $cnt[$j];
    }
    $maxc = max($maxc, $c);
}
if ($maxc === $n) exit('not coprime');
if ($maxc === 1) exit('pairwise coprime');
echo 'setwise coprime';

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 素数関係
class Prime
{
    private $n;
    private $table; // 素数の添字にtrueが格納された配列

    function __construct($n)
    {
        $this->n = $n;
        $this->makeTable();
    }

    function makeTable()
    {
        $n = $this->n;
        $table = array_fill(2, $n - 1, true);
        $rn = (int) floor(sqrt($n));
        for ($i = 2; $i <= $rn; $i++) {
            if (!isset($table[$i])) continue;
            for ($j = 2 * $i; $j <= $n; $j += $i) {
                unset($table[$j]);
            }
        }
        $this->table = $table;
    }

    // 素数
    function primes()
    {
        return array_keys($this->table);
    }

    function table()
    {
        return $this->table;
    }

    // 素数判定
    function isPrime($x)
    {
        return isset($this->table[$x]);
    }

    // 素因数分解
    function factor($x)
    {
        $res = [];
        if ($x === 1) return $res;
        $primes = $this->primes();
        foreach ($primes as $prime) {
            while ($x % $prime === 0) {
                if (isset($res[$prime])) $res[$prime]++;
                else $res[$prime] = 1;
                $x /= $prime;
            }
        }
        if ($x > 1) {
            if (isset($res[$x])) $res[$x]++;
            else $res[$x] = 1;
        }
        return $res;
    }
}


Score : 100 points

Problem Statement

We will buy a product for N yen (the currency of Japan) at a shop.

If we use only 1000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

1 \leq N \leq 10000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the amount of change as an integer.

Sample Input 1

1900

Sample Output 1

100

We will use two 1000-yen bills to pay the price and receive 100 yen in change.

Sample Input 2

3000

Sample Output 2

0

We can pay the exact price.


<?php
$N = trim(fgets(STDIN));
$money = 0;

if($money<$N){
  $money + 1000;
}
echo($money - $N);
?>


<?php
$N = trim(fgets(STDIN));
$money = 1000;

if($money<$N){
  $money + 1000;
}
echo($money - $N);
?>


$m = 0;

while(true){
    if(1000 * $m > $N){
        $ans = 1000 * $m - $N;
        var_dump($ans);
        return $ans;
        break;
    } else {
        $m++;
    }
}


<?php
// Your code here!
 $n = trim(fgets(STDIN));
 echo 1000 - ($n % 1000);
?>


<?php
// Your code here!
    $N = fgets(STDIN);
    $change = $N % 1000;
    if($change == 0){
        echo 0;
    }else {
        echo 1000 - $change;
    }
?>


<?php
fscanf(STDIN, "%d", $n);
$number = 1000 - ($n % 1000);
if ($number === 1000) {
    echo 0;
} else echo $number;


<?php
list($n) = ints();
echo 1000 * (intdiv($n, 1000) + min(1, $n % 1000)) - $n;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php
$start = microtime(true);
list($n) = ints();
$k = 26;
$c = ints();
$last = array_fill(0, $k, 0);
for ($i = 1; $i <= $n; ++$i) {
    $s[$i] = ints();
    $max = PHP_INT_MIN;
    for ($p = 0; $p < $k; ++$p) {
        $ts = ($score[$i - 1] ?? 0) + $s[$i][$p];
        for ($q = 0; $q < $k; ++$q) {
            if ($p === $q) continue;
            $ts -= $c[$q] * ($i - $last[$q]);
        }
        if ($ts > $max) {
            $max = $ts;
            $maxp = $p;
        }
    }
    $score[$i] = $max;
    $ans[$i] = $maxp + 1;
    $last[$maxp] = $i;
}
while (true) {
    for ($i = 1; $i < 365; ++$i) {
        for ($p = 1; $p <= $k - 1; ++$p) {
            $anst = $ans;
            $anst[$i] = ($ans[$i] - 1 + $p) % 26;
            $scoret = calcScore($anst);
            $diff = $scoret - $score[365];
            if ($diff > 0) {
                $ans = $anst;
                $score[365] = $scoret;
                break;
            }
        }
        $now = microtime(true);
        if ($now - $start > 1.9) break 2;
    }
}
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function calcScore($ans)
{
    global $c, $s;
    $last = array_fill(0, 26, 0);
    $score[0] = 0;
    for ($i = 1; $i <= 365; ++$i) {
        $score[$i] = ($score[$i - 1] ?? 0) + $s[$i][$ans[$i]];
        $last[$ans[$i]] = $i;
        for ($q = 0; $q < 26; ++$q) {
            $score[$i] -= $c[$q] * ($i - $last[$q]);
        }
    }
    return $score[365];
}

Problem Statement

AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.

The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.

Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.

If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).

Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0).
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.

Constraints

D = 365

Each c_i is an integer satisfying 0\leq c_i \leq 100.

Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.

Input

Input is given from Standard Input in the following format:

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}

Output

Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d.
Print D integers t_d to Standard Output in the following format:

t_1
t_2
\vdots
t_D

Any output that does not follow the above format may result in 0 pointsWA for that test case.

Input Generation

Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192

Sample Output 1

1
17
13
14
13

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.

Input generator, score calculator, and visualizer

Beginner's Guide

If you don't know what to do, proceed to problem B or C.


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

$cc = fgets(STDIN);
$c = explode(' ', $cc);

$cckey1 =  array_keys($c, max($c));
$ckey1 = $cckey1[0];
$c[$ckey1] = 0;
$cckey2 =  array_keys($c, max($c));
$ckey2 = $cckey2[0];
$c[$ckey2] = 0;
$cckey3 =  array_keys($c, max($c));
$ckey3 = $cckey3[0];

foreach ($c as &$value) {
    $value = (int) $value;
}
unset($value);

  for($i = 0; $i < $d; $i++) {
$aa = fgets(STDIN);
$a = explode(' ', $aa);

foreach ($a as &$value) {
    $value = (int) $value;
}
unset($value);

    if(($i % 4) === 0) {
      echo $ckey1.PHP_EOL;
      continue;
    }
    if(($i % 4) === 1) {
      echo $ckey2.PHP_EOL;
      continue;
    }
    if(($i % 4) === 2) {
      echo $ckey3.PHP_EOL;
      continue;
    }
    $key =  array_keys($a, max($a));
    echo (1 + (int) $key[0]).PHP_EOL;
    unset($a);
    unset($aa);
  }


<?php
// Your code here!
$day = trim(fgets(STDIN));
$c = explode(' ',trim(fgets(STDIN)));

for ($i = 0; $i < $day; $i++) {
     $scores = explode(' ',trim(fgets(STDIN)));
     foreach($c as $ck => $cv){
         $scores[$ck] -= $cv * (365 - $i -1);
     }
     arsort($scores);
     echo array_key_first($scores) +1;
     if($i != 364){
        echo "\n";
     }
}

?>


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

$cc = fgets(STDIN);
$c = explode(' ', $aa);

$cckey1 =  array_keys($c, max($c));
$ckey1 = $cckey1[0];
$c[$ckey1] = 0;
$cckey2 =  array_keys($c, max($c));
$ckey2 = $cckey2[0]
$c[$ckey2] = 0;
$cckey3 =  array_keys($c, max($c));
$ckey3 = $cckey3[0]

foreach ($c as &$value) {
    $value = (int) $value;
}
unset($value);

  for($i = 0; $i < $d; $i++) {
$aa = fgets(STDIN);
$a = explode(' ', $aa);

foreach ($a as &$value) {
    $value = (int) $value;
}
unset($value);

    if(($i % 4) === 0) {
      echo $ckey1;
      continue;
    }
    if(($i % 4) === 1) {
      echo $ckey2;
      continue;
    }
    if(($i % 4) === 2) {
      echo $ckey3;
      continue;
    }
    $key =  array_keys($a, max($a));
    echo (1 + (int) $key[0]).PHP_EOL;
    unset($a);
    unset($aa);
  }


<?php
$d=trim(fgets(STDIN));//365
$c=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$d){
  $s[$i]=explode(" ",trim(fgets(STDIN)));
  $t=$i%26;
  echo $t+1 . "\n";
  ++$i;
}


<?php
list($n) = ints();
$m = 26;
$c = ints();
for ($i = 0; $i < $n; ++$i) {
    $s = ints();
    for ($j = 0; $j < $m; ++$j) $s[$j] += $c[$j] * 365;
    $max = PHP_INT_MIN;
    for ($j = 0; $j < $m; ++$j) {
        if ($max < $s[$j]) {
            $max = $s[$j];
            $maxi = $j;
        }
    }
    $ans[] = $maxi + 1;
}
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php

// 入力
fscanf(STDIN, "%d %d %d", $n, $m, $k);
$arr_a = explode(" ",trim(fgets(STDIN)));
$arr_b = explode(" ",trim(fgets(STDIN)));

$read_book_num = 0;

// 机A　机Bから少ない方を読む
do{

  if(!empty($arr_a) && !empty($arr_b)){
    if($arr_a[0] > $arr_b[0]){
      $k =  $k - $arr_b[0];
      array_shift($arr_b);
    }else
    if($arr_a[0] <= $arr_b[0]){
      $k = $k - $arr_a[0];
      array_shift($arr_a);
    }
  }elseif (empty($arr_a) && !empty($arr_b)) {
    $k = $k - $arr_b[0];
    array_shift($arr_b);
  }elseif (!empty($arr_a) && empty($arr_b)) {
    $k = $k - $arr_a[0];
    array_shift($arr_a);
  }else{
    break;
  }
  if($k < 0){
    break;
  }

  $read_book_num++;

}while($k > 0);

echo $read_book_num;

Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.


<?php

list($a, $b, $limit) = explode(" ", trim(fgets(STDIN)));

$first_line_input = trim(fgets(STDIN));
$first_line_input = str_replace(array("\r\n","\r","\n"), '', $first_line_input);
$booklist1 = explode(" ", $first_line_input);

$first_line_input = trim(fgets(STDIN));
$first_line_input = str_replace(array("\r\n","\r","\n"), '', $first_line_input);
$booklist2 = explode(" ", $first_line_input);

$sum = 0;
$cnt = 0;
$max = 0;

    for($j=0;$j<$b;$j++){
        $sum += $booklist2[$j];
        $tmp = $limit - $sum;
        if($tmp >= 0){
            $cnt = $j+1;
            if($max < $cnt){
                $max = $cnt;
            }
        }else{
            break;
        }
    }

    $sum = 0;

    for($i=0;$i<$a;$i++){
        $sum = 0;
        for($k=0;$k<=$i;$k++){
            $sum += $booklist1[$k];
        }
        var_dump($sum);
        $tmp = $limit - $sum;
            if($tmp < 0){
                break;
            }
        for($j=0;$j<$b;$j++){
            $sum += $booklist2[$j];
            $tmp = $limit - $sum;
            if($tmp >= 0){
                $cnt = ($i+1)+($j+1);
                if($max < $cnt){
                $max = $cnt;
            }
            }else{
                break;
            }
        }
    }

echo $max;

?>


<?php

$a=fgets(STDIN);
$b=fgets(STDIN);
$c=fgets(STDIN);
$result=0;
$bint=0;
$cint=0;
$count=0;

$a_array=$array1 = preg_split("/\s/",$a);
$b_array=$array1 = preg_split("/\s/",$b);
$c_array=$array1 = preg_split("/\s/",$c);
$limit=$a_array[2];

while ($result<=$limit) {
    if (intval($b_array[$bint])<intval($c_array[$cint])) {
        if ($result<=$limit) {
            $result+=intval($b_array[$bint]);
        }
        $bint++;

    } else {
        if ($result<=$limit) {
            $result+=intval($c_array[$cint]);
        }
        $cint++;

    }
    $count++;
}

echo $count-1;


<?php
[$N, $M, $K] = ints();
$A = ints();
$B = ints();
$A = array_reverse($A);
$C = array_merge($A,$B);
$sum = 0;
$j = 0;
$max = -1;
foreach($C as $i => $c){
  $sum += $c;
  while($sum > $K){
    $sum -= $C[$j] ?? 0;
    $j++;
  }
  if($i >= count($A)-1 && $j <= count($A)){
    chmax($max, $i-$j);
  }
}
echo $max+1;
function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array\n";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}


<?php
[$N, $M, $K] = ints();
$A = ints();
$B = ints();
$A = array_reverse($A);
$C = array_merge($A,$B);
$sum = 0;
$j = 0;
$max = 0;
foreach($C as $i => $c){
  $sum += $c;
  while($sum > $K){
    $sum -= $C[$j] ?? 0;
    $j++;
  }
  if($i >= count($A) && $j <= count($A)){
    chmax($max, $i-$j);
  }
}
echo $max;
function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array\n";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}


<?php
list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$a_array = [0];
$b_array = [0];
foreach ($a as $key => $value) {
	if($key==0){
		$a_array[] = $value;
	}else{
		$a_array[] = $a_array[$key] + $value;
	}
}
foreach ($b as $key => $value) {
	if($key==0){
		$b_array[] = $value;
	}else{
		$b_array[] = $b_array[$key] + $value;
	}
}

$ans = [];
for($i=0; $i<=$n; $i++){
	if($a_array[$i] > $k){break;}
	for($j=$m; $j>=0; $j--){
		if($a_array[$i] + $b_array[$j] <= $k){
			$ans[] = $i+$j;
			$m=$j;
			break;
		}
	}
}

echo max($ans) . "\n";


<?php
fscanf(STDIN, "%d %d %d", $n,$m,$k);
$arr = array_map('intval', explode(' ', trim(fgets(STDIN))));
$arr2 = array_map('intval', explode(' ', trim(fgets(STDIN))));
//print_r($arr);
//print_r($arr2);

$ans = 0;
$cal = 0;
$n = $n+$m;
array_sum($arr);
array_sum($arr2);
if(array_sum($arr)+array_sum($arr2)<=$k){
echo $n;
}else{
for($i=0;$i<$n;++$i){
while ($cal <= $k) {
  if($arr[0]<=$arr2[0]){
    $ans=++$ans;
    $cal = bcadd($cal, $arr[0]);
    array_splice($arr, 0, 1);
    //print_r($arr);
}else{
    $ans=++$ans;
    $cal = bcadd($cal, $arr2[0]);
    array_splice($arr2, 0, 1);
    //print_r($arr2);
  }
}
}
    echo $ans-1;
}
?>


<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$as = explode(' ', trim(fgets(STDIN)));
$bs = explode(' ', trim(fgets(STDIN)));

$a = 0;
$b = 0;
$cnt = 0;
$time = 0;
while (true) {

  $current_a = isset($as[$a]) ? $as[$a] : null;
  $current_b = isset($bs[$b]) ? $bs[$b] : null;

  if (is_null($current_a) && is_null($current_b)) {
    break;

  } elseif (!is_null($current_a) && (is_null($current_b) || $current_a <= $current_b)) {
    if (($time + $current_a > $k)) {
      break;
    }

    $time += $current_a;
    $a++;
    $cnt++;

  } elseif (!is_null($current_b) && (is_null($current_a) || $current_b <= $current_a)) {
    if (($time + $current_b > $k)) {
      break;
    }

    $time += $current_b;
    $b++;
    $cnt++;

  } else {
    break;
  }

}

echo $cnt;


<?php
list($a_count,$b_count,$tatal_time) = explode(" ",trim(fgets(STDIN)));
$a_books = explode(" ",trim(fgets(STDIN)));
$b_books = explode(" ",trim(fgets(STDIN)));

for($i=0; $i< 10; $i++){
    if($a_books[0] > $b_books[0] || count($a_books) == 0){
        $tatal_time -= $b_books[0];
        unset($b_books[0]);
        $b_books = array_values($b_books);
        $hh[] =  $tatal_time;
    }else{
        $tatal_time -= $a_books[0];
        unset($a_books[0]);
        $a_books = array_values($a_books);
        $hh[] = $tatal_time;
    }
    if(count($a_books) == 0 && count($b_books) == 0){
        break;
    }
    if($tatal_time < 0){
        break;
    }
}

if($tatal_time < 0){
    echo count($hh)-1;
}else{
    echo count($hh);
}


<?php

fscanf(STDIN,"%d %d %d",$n,$m,$k);
$A = explode(" ", trim(fgets(STDIN)));
$B = explode(" ", trim(fgets(STDIN)));

if(array_sum($A) + array_sum($B) <= $k){
    echo count($A) + count($B);
    exit;
}

$ans = 0;
while($k > 0){
    if(current($A) > $k && current($B) > $k){
        break;
    }

    if(!empty($A) && !empty($B)){
        if(current($A) < current($B)){
            $ans++;
            $k -= current($A);
            unset($A[0]);
            continue;
        }elseif(current($A) > current($B)){
            $ans++;
            $k -= current($B);
            unset($B[0]);
            continue;
        }
    }elseif(empty($A)){
        $ans++;
        $k -= current($B);
        unset($B[0]);
        continue;
    }elseif(empty($B)){
        $ans++;
        $k -= current($A);
        unset($A[0]);
        continue;
    }

}
echo $ans;


<?php
//$a_countが机Aにある本の数
//$b_countが机Bにある本の数
//$tatal_timeが合計時間でこの時間を超えないように読める最大値を求める
list($a_count,$b_count,$tatal_time) = explode(" ",trim(fgets(STDIN)));
$a_books = explode(" ",trim(fgets(STDIN)));
$b_books = explode(" ",trim(fgets(STDIN)));

//aとbを比べて数値が小さい方をtotalから引いてカウントをプラス
//引いた方の配列の0番を消して配列を詰める
if($a_books > $b_books){
    $count = count($a_books);
}else{
    $count = count($b_books);
}

for($i=0; $i< 10; $i++){
    // var_dump($a_books,$b_books);
    if($a_books[0] > $b_books[0] || count($a_books) == 0){
        $tatal_time -= $b_books[0];
        unset($b_books[0]);
        $b_books = array_values($b_books);
        $hh[] =  $tatal_time;
    }else{
        $tatal_time -= $a_books[0];
        unset($a_books[0]);
        $a_books = array_values($a_books);
        $hh[] = $tatal_time;
    }
    if(count($a_books) == 0 && count($b_books) == 0){
        break;
    }
    if($tatal_time < 0){
        break;
    }
}

if($tatal_time < 0){
    echo count($hh)-1;
}else{
    echo count($hh);
}


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

$aa = fgets(STDIN);
$a = explode(' ', $aa);

foreach ($a as &$value) {
    $value = (int) $value;
}
unset($value);

$bb = fgets(STDIN);
$b = explode(' ', $bb);

foreach ($b as &$value) {
    $value = (int) $value;
}
unset($value);

$readtime = "0";
$readbooks = "0";

for($i = 0; $i < ($n + $m); $i++) {
if(!isset($a[0]) && !isset($b[0])) {
    echo $readbooks;
    exit;
} elseif(!isset($a[0])) {
    $book = array_shift($b);
} elseif(!isset($b[0])) {
    $book = array_shift($a);
} else {
    if($a[0] < $b[0]) {
        $book = array_shift($a);
    } else {
        $book = array_shift($b);
    }
}
$readtime = bcadd($readtime, (string) $book);
if(bccomp($k, $readtime) === -1) {
    echo $readbooks;
    exit;
}
$readbooks++;

//echo "$book $readbooks $readtime $k".PHP_EOL;
}

echo $readbooks;
exit;


<?php

$inp = explode( ' ', trim( fgets( STDIN ) )  );
foreach ( $inp as $key => $value ) {
  $inp[$key] = intval( $value );
}

$inp2 = explode( ' ', trim( fgets( STDIN ) )  );
foreach ( $inp2 as $key => $value ) {
  $inp2[$key] = intval( $value );
}

$inp3 = explode( ' ', trim( fgets( STDIN ) )  );
foreach ( $inp3 as $key => $value ) {
  $inp3[$key] = intval( $value );
}

if ($inp2[0] >= $inp[2] || $inp3[0] >= $inp[2]) {
  echo 0;
  exit;
}

$roop = $inp[0] + $inp[1];
$time = 0;
$count = 0;

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

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

  if (count($inp3) === 0) {
    $time += $inp2[0];
    unset($inp2[0]);
  } elseif (count($inp2) === 0) {
    $time += $inp3[0];
    unset($inp3[0]);
  } elseif ($inp2[0] > $inp3[0]) {
    $time += $inp3[0];
    unset($inp3[0]);
  } else {
    $time += $inp2[0];
    unset($inp2[0]);
  }
  $inp2 = array_values($inp2);
  $inp3 = array_values($inp3);

  if ($time > $inp[2]) {
  break;
}

  ++$count;
}

echo $count;
?>


<?php
  fscanf(STDIN, "%d%d%d", $n,$m,$k);
  $a = explode(" ", trim(fgets(STDIN)));
  $b = explode(" ", trim(fgets(STDIN)));
//   print_r($a);
  $a[] = PHP_INT_MAX;
  $b[] = PHP_INT_MAX;
  $ai = 0;
  $bi = 0;
  $cnt = 0;
  $read = 0;
  for($i=0; $i<($n+$m); $i++){
      if($a[$ai] >= $b[$bi]){
          $cnt += $b[$bi];
          $bi++;
      }else if($a[$ai]<$b[$bi]){
          $cnt += $a[$ai];
          $ai++;
      }
      if($cnt > $k){
          break;
      }
      $read++;
  }
  echo $read;


<?php
  fscanf(STDIN, "%d%d%d", $n,$m,$k);
  $a = explode(" ", trim(fgets(STDIN)));
  $b = explode(" ", trim(fgets(STDIN)));
//   print_r($a);
  $a[] = PHP_INT_MAX;
  $b[] = PHP_INT_MAX;
  $ai = 0;
  $bi = 0;
  $cnt = 0;
  $read = 0;
  for($i=0; $i<($n+$m); $i++){
      if($a[$ai] > $b[$bi]){
          $cnt += $b[$bi];
          $bi++;
      }else if($a[$ai]<$b[$bi]){
          $cnt += $a[$ai];
          $ai++;
      }
      if($cnt > $k){
          break;
      }
      $read++;
  }
  echo $read;


<?php

fscanf(STDIN, "%d %d %d", $N, $M, $K);
$p_array = trim(fgets(STDIN));
$A_array = explode(" ", $p_array);

$p_array = trim(fgets(STDIN));
$B_array = explode(" ", $p_array);

$r = 0;
$read = 0;
for ($i = 0;$i < $N + $M;$i++) {
   $A = array_shift($A_array);
   $B = array_shift($B_array);
   if ($A >= $B) {
     $read += $B;
     array_unshift($A_array, $A);
   } else {
     $read += $A;
     array_unshift($B_array, $B);
   }
  if ($K < $read) {
    echo $r;
    exit;
  } else {
    $r++;
  }
}

echo $r;


<?php

fscanf(STDIN, "%d %d %d", $n, $m, $k);

$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$B = array_map('intval', explode(' ', trim(fgets(STDIN))));
$n++;
$m++;
$sumA = array_merge([0], $A);
/* $sumA = $A; */
for ($i = 1; $i < $n; ++$i) {
    $sumA[$i] += $sumA[$i - 1];
}

$sumB = array_merge([0], $B);
for ($i = 1; $i < $m; ++$i) {
    $sumB[$i] += $sumB[$i - 1];
}

print_r($sumA);
print_r($sumB);

$max = 0;
// Aの撮り方を全探索する
for ($i = 0; $i < $n; ++$i) {
    // 残り分数
    $x = $k - $sumA[$i];
    if ($x < 0) {
        break;
    }

    // sumBを2分探索する
    $l = 0;
    $r = $m;
    while ($r - $l >= 1) {
        $mid = intdiv($r + $l, 2);
        if ($sumB[$mid] > $x) {
            $r = $mid;
        } else {
            $l = $mid + 1;
        }
    }
    $y = $r - 1;
    $max = max($max, $i + $y);
    echo "i: $i, x: $x, y: $y", PHP_EOL;
}

echo (int) $max, PHP_EOL;


<?php
$n = intval(trim(fgets(STDIN)));
$sum = 0;
for($i = 1; $i <= $n; ++$i){
  $N = intdiv($n,$i);
  $sum += $N*($N+1)/2*$i;
}
echo $sum;

Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.


<?php
$n = intval(trim(fgets(STDIN)));
$sum = 0;
for($i = 1; $i <= $n; $i++){
  $N = intdiv($n,$i);
  $sum += $N*($N+1)/2*$i;
}
echo $sum;


<?php
$n = intval(trim(fgets(STDIN)));
$counts = array_fill(1, $n, 1);
for($i = 2; $i <= $n; $i++){
  for($j = $i; $j <= $n; $j+=$i){
    $counts[$j]++;
  }
}
$sum = 0;
foreach($counts as $i => $c){
  $sum += $i*$c;
}
echo $sum;


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

  $data = explode(" ", trim(fgets(STDIN)));
  sort($data);

  $max = $data[$n-1];
  $flags = [];
  for($i=0; $i<$n; $i++){
    if($i>0 && $data[$i-1]==$data[$i]){
      //同じ数字2回目なので、自身もフラグオン
      $flags[$data[$i]] = true;
    }else{
      $j = 2;  //自身を含まないように2倍からスタート
      while($data[$i]*$j<$max){
        $idx = $data[$i]*$j;

        $flags[$idx] = true;
        //echo $idx." is true\n";
        /*
        if(isset($flags[$idx])){
          //チェック済みなのでブレーク
          break;
        }else{
          $flags[$idx] = true;
          echo $idx." is true\n";
        }
        */

        $j++;
      }
    }
  }

  $count = 0;
  for($i=0; $i<$n; $i++){
    if(!isset($flags[$data[$i]])){
      $count++;
    }
  }
  echo $count."\n";

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5


<?php
  $n = trim(fgets(STDIN));
  $arr = explode(" ", trim(fgets(STDIN)));
  sort($arr);
  $maxnum = $arr[count($arr) - 1];
  for($i = 0; $i < count($arr); $i++){
    $key = $arr[$i];
    $num = count($arr);
    $flg = true;
    for($j = $i+1; $j < $num; $j++){
      if($key == $arr[$j]){
        unset($arr[$i], $arr[$j]);
        $flg = false;
      } else if($arr[$j] % $key == 0){
        unset($arr[$j]);
      }
    }
    if($key > ceil($maxnum / 2)){
      break;
    }
    if(!$flg){
      $i--;
    }
    $arr = array_values($arr);
  }
  echo count($arr);
?>


<?php
  fscanf(STDIN, "%d", $n);
  $nums = explode(' ', trim(fgets(STDIN)));
  $count = 0;

  for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $n; $j++) {
      if ($nums[$i] == $nums[$j]) {
        break;
      }
      if ($i != $j && $nums[$i] % $nums[$j] == 0) {
        break;
      }
    }
    if ($j == $n) {
      $count++;
    }
  }

  echo $count;


<?php
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) $cnt[$a[$i]]++;
    else $cnt[$a[$i]] = 1;
}
if (isset($cnt[1])) {
    if ($cnt[1] > 1) exit('0');
    else exit('1');
}
ksort($cnt);
$max = max($a);
$isPrime = isPrimeArr($max);
$ans = 0;
foreach ($cnt as $i => $v) if ($v === 1 && $isPrime[$i]) $ans++;
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function isPrimeArr($max)
{
    global $cnt;
    $arr = array_fill(0, $max + 1, true);
    $arr[0] = false;
    foreach ($cnt as $i => $v)
        for ($j = 2 * $i; $j <= $max; $j += $i) $arr[$j] = false;
    return $arr;
}


<?php
fscanf(STDIN, "%d", $n);
$lineInput = trim(fgets(STDIN));
$A= explode(" ", $lineInput);
if(in_array(1,$A)){
    echo 0;
}else{
    if(count($a) == 1){
        echo 1;
    }else{

        $arr = array_unique($A);
        $dubs = array_count_values($A);
        $dubs = array_diff($dubs,array(1));
        rsort($arr);
        $ans = count($arr);
        if($ans > 1){
            for($i=0; $i<count($arr); $i++){
                if(array_key_exists($arr[$i], $dubs)){
                    $ans--;
                    break;
                }
                for($j = count($arr) - 1; $j > $i ; $j--){
                    if($arr[$i] % $arr[$j] == 0){
                        $ans--;
                        break;
                    }
                }

            }
        }else{
            if(array_key_exists($arr[0], $dubs)){
                $ans--;
            }
        }
    }
    echo $ans;
}

?>


<?php

fscanf(STDIN, "%d", $n);
$a_list = explode(' ', trim(fgets(STDIN)));
sort($a_list);

$answer = 0;
for ($i = 0; $i < $n; ++$i) {
    for ($j = 0; $j < $i; ++$j) {
        if ($i === $j) {
            continue;
        }
        if ($a_list[$i] % $a_list[$j] === 0) {
            continue 2;
        }
    }

    ++$answer;
}

echo $answer;


<?php
$N = (int)trim(fgets(STDIN));
//list($X,$N) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$S = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$pri=array();
$odd=array();
$even=array();
foreach($A as $v) {
  if (is_prime($v)) {
    $pri[]=$v;
    continue;
  }
  if ($v % 2 == 0) {
    $odd[]=$v;
  }
  else {
    $even[]=$v;
  }
}
$tot=0;
$pc = array_count_values($pri);
//1つだけある素数
foreach($pc as $v) {
  if ($v == 1) $tot++;
}
//最小の偶数と、奇数...じゃ間違ってそう。
//割り切れないかどうか確認がいりそうな希ガス
sort($odd);
sort($even);
$pc = array_count_values($odd);
foreach($pc as $v) {
  if ($v==1) {
    $tot++;
    break;
  }
}
$pc = array_count_values($even);
foreach($pc as $v) {
  if ($v==1) {
    $tot++;
    break;
  }
}
printf("%d\n",$tot);
function gcd($a,$b) {
  if ($b == 0) return $a;
  return gcd($b,$a%$b);
}
function lcm($a,$b) {
  $l = gcd($a,$b);
  return $a / $l * $b;
}

function prime_factors(int $n) {
    $i = 2;
    $factors = [];
    while ($i * $i <= $n) {
        if ($n % $i) $i += 1;
        else {
            $n /= $i;
            $factors[] = $i;
        }
    }
    if ($n > 1) $factors[] = $n;
    return $factors;
}
function is_prime(int $n) : bool {
    $r = true;
    if ($n < 2) $r = false;
    elseif ($n == 2 || $n == 3 || $n == 5) $r = true;
    elseif ($n & 1 == 0) $r = false;
    elseif ($n % 2 == 0 || $n % 3 == 0 || $n % 5 == 0) $r = false;
    else {
        $f = true;
        $v = 7;
        $m = intval($n ** 0.5) + 1;
        while ($v < $m) {
            if ($n % $v == 0) {
                $r = false;
                break;
            }
            $v += $f ? 4 : 2;
            $f = !$f;
        }
    }
    return $r;
}


<?php
$n = trim(fgets(STDIN));
$nums =  explode(" ", trim(fgets(STDIN)));
sort($nums);
$ans =  0;
foreach ($nums as $key => $value) {
	$flg =false;
	for($i=0; $i<$key; $i++){
		if($num[$i] > $value/2){
			break;
		}
		if($value % $nums[$i] == 0){
			$flg = true;
			break;
		}
	}
	if($flg===false && $nums[$key]!=$nums[$key+1]){ $ans +=1;}
}

echo $ans."\n";


<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  $b = array_fill(0,$n,$a[0]);
  if($a == $b){
      echo "0";
      exit;
  }
  $count=0;
  for($i=0; $i<$n; $i++){
      $flag = true;
      for($j=$i+1; $j<$n; $j++){
          if($a[$i]%$a[$j] == 0 || $a[$j]%$a[$i] == 0){
              $flag = false;
          }
      }
      if($flag){
          $count++;
      }
  }
  echo $count;


<?php
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) $cnt[$a[$i]]++;
    else $cnt[$a[$i]] = 1;
}
ksort($cnt);
if (isset($cnt[1])) {
    if ($cnt[1] > 1) exit('0');
    else exit('1');
}
$max = max($a);
$isPrime = isPrimeArr($max);
$ans = 0;
foreach ($cnt as $i => $v) {
    if ($v === 1 && $isPrime[$i]) $ans++;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function isPrimeArr($max)
{
    global $cnt;
    $arr = array_fill(0, $max + 1, true);
    $arr[0] = false;
    foreach ($cnt as $i => $v) {
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            $arr[$j] = false;
        }
    }
    return $arr;
}


<?php
fscanf(STDIN, "%d", $N);
$list = fscanf(STDIN, str_repeat("%d", $N));
sort($list);
$bai_list  = [];
$same_list = [];
$ans = 0;
if($list[0] === 1){
    echo 0;
    exit;
}
foreach($list as $value){
    if(isset($same_list[$value])){
        if($same_list[$value] == 1){
            $ans--;
            $same_list[$value] = 2;
        }
    }elseif(!isset($bai_list[$value])){
        $no = $value;
        while($no < 1000000){
            $bai_list[$no] = 1;
            $no += $value;
        }
        $bai_list[$no] = 1;
        $same_list[$value] = 1;
        $ans++;
    }else{
        $same_list[$value] = 2;
    }
}

echo $ans;


<?php
$input = fgets(STDIN);
$multi = array_map('intval', explode(' ',fgets(STDIN)));
$sum = true;
for ($i = 0; $i < $input; $i++) {
    (int)$sum *= $multi[$i];
}
$limit = pow(10,18);
if($sum>$limit) {
    echo -1;
} else {
    echo (int)$sum;
}

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0


<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (float)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b

list($N) = sscanf(trim(fgets(STDIN)), "%d");
$sc = new Scanner();
$calc = 1;
for ($i = 0; $i < $N; $i++) {
    $calc *= $sc->nextInt();
    if($calc > 10**18){
        print(-1);
        exit();
    }
}
print($calc);


<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (float)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b

list($N) = sscanf(trim(fgets(STDIN)), "%d");
$sc = new Scanner();
$calc = 1;
for ($i = 0; $i < $N; $i++) {
    $calc *= $sc->nextInt();
}
print($calc > 10**18 ? -1 : $calc);


<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = true;
for ($i=0; $i < $cnt; $i++) {
    (int)$ans *= $nums[$i];
}
$limit = pow(10, 18);
if ($ans > $limit) {
    $ans = -1;
}
echo $ans;


<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 1;
for ($i=0; $i < $cnt; $i++) {
    (int)$ans *= $nums[$i];
}
$limit = pow(10, 18);
if ($ans > $limit) {
    $ans = -1;
}
echo $ans;


<?php

fscanf(STDIN,"%d",$n);
$a=array_map('intval',explode(" ",fgets(STDIN)));
$product=1;
$flag=0;
for($i=0;$i<$n;$i++){
    if($a[$i]<=1000000000000000000/$product){
        $product*=$a[$i];
    }else{
        $flag=1;
        break;
    }
}
if($flag==1){
    echo -1;
}else{
    echo array_product($a);
}


<?php

$max = trim(fgets(STDIN));
$numbers = explode(' ', trim(fgets(STDIN)));

$result = 1;

foreach($numbers as $number)
{
  if(pow(10, 18) / $result < $number)
  {
    echo '-1' . PHP_EOL;
    return;
  }
  $result *= $number;
}

echo $result . PHP_EOL;


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

$ans = 1;
foreach($a as $value){
    $ans *= $value;
}

if($ans>pow(10,18)){
    echo -1;
    exit;
}

echo $ans;


<?php
fscanf(STDIN,"%d",$n);
$a=explode(' ',trim(fgets(STDIN)));
$sum = array_product($a);

if($sum>pow(10,18)){
    echo -1;
}else{
    echo $sum;
}
?>


<?php
  fscanf(STDIN, "%d", $n);
  $nums = explode(' ', trim(fgets(STDIN)));
  $ans = 1;

  for ($i = 0; $i < $n; $i++) {
    $ans *= $nums[$i];
  }

  if ($ans > pow(10, 18)) {
    $ans = -1;
  }

  echo $ans;


<?php
	fscanf(STDIN, "%d", $n);
	$array = explode(" ", trim(fgets(STDIN)));
	$num = count($array);
	for($i = 1; $i < $num; $i++){
      if($i === 1){
     	$ans = $array[0] * $array[$i];
      }
      $ans *= $array[$i];
    }

	if($ans > pow(10, 18)){
      echo -1;
    }else{
      echo $ans;
    }


<?php
$loop = trim(fgets(STDIN));
$nums_input = trim(fgets(STDIN));

$nums = explode(" ", $nums_input);
$result = 1;
$max_num = 1000000000000000000;

for ($i = 0;$i < $loop;$i++) {
    if ($nums[$i] == 0) {
        $result = 0;
        break;
    }
}

if ($result !== 0) {
    for ($i = 0;$i < $loop;$i++) {
        $result = $result * $nums[$i];
        if ($result > $max_num) {
            $result = -1;
            break;
        }
    }
}

print $result;


<?php
$a = fgets(STDIN);
$ts = explode(" ",trim(fgets(STDIN)));
$sum = 1;
$max = 10**18;
$flg = false;
for ($i=0;$i<intval($a);$i++){
  if($ts[$i] == 0){
    echo '0';
    return;
  }
  $sum *= $ts[$i];
}
if($sum > $max){
  $flg = true;
  $sum = 1;
}else{
  $flg = false;
}

if($flg){
  echo '-1';
  exit;
}

echo $sum;


<?php
$a = fgets(STDIN);
$ts = explode(" ",trim(fgets(STDIN)));
$sum = 1;
$max = 10**18;
for ($i=0;$i<intval($a);$i++){
  $sum *= $ts[$i];
}
if($sum == 0){
  echo $sum;
  return;
}elseif($sum > $max){
  $flg = false;
  $sum = 1;
}else{
  $flg = true;
}

if(!$flg){
  echo '-1';
  exit;
}

echo $sum;


<?php
$a = fgets(STDIN);
$ts = explode(" ",trim(fgets(STDIN)));
$sum = 1;
for ($i=0;$i<intval($a);$i++){
  $sum *= $ts[$i];
}
if($sum == 0){
  echo $sum;
  exit;
}elseif(strlen($sum) > 18){
  $sum = '-1';
}
echo $sum;


<?php
$a = fgets(STDIN);
$ts = explode(" ",trim(fgets(STDIN)));
if (0 < strlen(array_product($ts)) <= 18) {
  echo array_product($ts);
}elseif (strlen(array_product($ts)) > 18) {
  echo "-1";
}else{
  echo "0";
}


<?php

	$count = trim(fgets(STDIN));

	$num = explode(" ",trim(fgets(STDIN)));

	for($i=0; $i<$count; $i++){
      if($i==0){
      	$result = $num[$i];
      }else{
        $result = $result * $num[$i];
      }
    }
	if($result > 10**18){
      echo -1;
    }else{
      echo $result;
    }

  ?>


<?php
$loop = trim(fgets(STDIN));
$nums_input = trim(fgets(STDIN));

$nums = explode(" ", $nums_input);
$result = 1;
$max_num = 1000000000000000000;

for($i = 0;$i < $loop;$i++) {
  $result = $result * $nums[$i];
  if ($result > $max_num) {
    $result = -1;
    break;
  }
}

print $result;


n = gets
ary = gets.split.map(&:to_i)
b = 1
if ary.count(0)
  puts 0
  exit
end
ary.each do |a|
  b *= a
  if b > 10**18
    puts -1
    exit
  end
end
puts b


<?PHP
fscanf(STDIN, "%d", $n);
$array = array_map('intval', explode(' ', trim(fgets(STDIN))));
if (in_array('0', $array)){
  echo 0;
  return;
}
$sum = $array[0];
for($i = 1; $i < $n; $i++){
  $sum = $sum * $array[$i];
  if($sum > 1000000000000000000){
   echo -1;
   return;
  }
}

 echo $sum;


<?PHP
$max = 10**18;
$n = fgets(STDIN);
$array = array_map('intval', explode(' ', trim(fgets(STDIN))));
if (in_array('0', $array){
  echo 0;
  return;
}
$sum = $array[0];
for($i = 1; $i < $n; $i++){
  $sum = $sum * $array[$i];
  if($sum > $max){
   echo -1;
   return;
  }
}

 echo $sum;


<?PHP
$max = 10**18;
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
if (in_array(0, $array){
  echo 0;
  return;
}
$sum = 1;
for($i = 0; $i < $n; $i++){
  $sum = $sum * $array[$i];
  if($sum > $max){
  echo -1;
  return;
	}
}

 echo $sum;


<?php
    fscanf(STDIN, "%d", $n);
    while ($line = fgets(STDIN)) {
        $tmp = explode(" ",trim($line));
    }

    $ans = 0;
    foreach($tmp as $value){
        $value = $value * $value;
    }
    $ans = $value;

    if ($ans > 1000000000000000000) {
        echo "-1";
    } else {
        echo $ans;
    }


<?php
while($line = fgets(STDIN)) {
   $stdinDatas[] = trim($line);
}

$n = $stdinDatas[0];
$nums = explode(' ', $stdinDatas[1]);

$result = 1; // 結果格納変数、１で初期化
$count = count($nums);

// $numsに0が一つでも含まれていたら、計算せずに0を出力する
if (array_search(0, $nums) !== false) {
	echo 0;
}
// forループの中で↑に対して配列の中身を一つずつかけていく
for ($i = 0; $i < $count; $i++) {
  $result *= $nums[i];
}

if ($result >= (10 ** 18)) {
  echo -1;
} else {
  echo $result;
}


<?php
fscanf(STDIN, "%d", $n);
$list = explode(" ", fgets(STDIN));
$result = array_product($list);
echo ($result > pow(10, 18)) ? '-1' : $result;


<?php
 fscanf(STDIN, "%d", $n);
   $ans=1;
$arr = array_map('intval', explode(' ', trim(fgets(STDIN))));
   for($i=0;$i<$n;++$i){
    $ans=bcmul($ans,$arr[$i]);
   }
 if($ans>1000000000000000000){
      echo "-1";
    }else{
    echo $ans;
   }
?>


<?php

$N = trim(fgets(STDIN));
$N_array = trim(fgets(STDIN));

$pieces = explode(" ", $N_array);

$result = $pieces[0];

foreach($pieces as $k => $p) {
  if ($p == 0) {
   	echo 0;
    exit;
  }
}

foreach($pieces as $k => $p) {
  if($k == 0) {
    $result = $p;
  } else {
    if ((strlen($result)+ strlen($p)) > 20) {
     	echo "-1";
        exit;
    }
    $result = $result * $p;
  }
}

if ($result > 1000000000000000000) {
  echo "-1";
}

echo $result;


<?php
// Your code here!
$n = trim(fgets(STDIN));
$line = explode(" ",(trim(fgets(STDIN))));

$sum = 1;
for($i=0; $i<count($line); $i++){
    $sum = $sum * (int)$line[$i];
}

if($sum > 10**18){
    echo '-1',PHP_EOL;
    return 0;
}else{
    echo $sum,PHP_EOL;
}


<?php
$N = fgets(STDIN);
$input=explode(' ',(fgets(STDIN)));

$ans = 1;
for ($i = 0; $i < $N; $i++) {
    $ans = $ans * $input[$i];
}

if ($ans > 10**18) {
  $ans = '-1';
}
print ($ans);
?>


<?PHP
$max = 10**18;
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
$sum = $array[0];
for($i = 1; $i < $n; $i++){
  $sum = $sum * $array[$i];
}
if($sum > $max){
  echo -1;
  return;
}else{
 echo $sum;
}


<?php
$kaisuu = fgets(STDIN);
$args = explode(' ', fgets(STDIN));
$mysum = 1;
for ($i = 0; $i < $kaisuu; $i++) {
	$mysum = $args[$i] * $mysum;
}
if ($kaisuu == 0) {
  echo 0;
} else {
  if ($mysum > 1000000000000000000) {
    echo -1;
  } else {
    echo $mysum;
  }
}
?>


<?PHP
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
$sum = $array[0];
for($i = 1; $i < $n; $i++){
	$sum *= $array[$i];
}
if($sum > 10**18){
  echo -1;
  return;
}else{
	echo $sum;
}


<?php
fscanf(STDIN,"%d",$N);
$arr = explode(" ",rtrim(fgets(STDIN)));
$res = 0;
// ０が配列の中に入っていなかったら計算する
if(!array_search(0, $arr)){
    $res = 1;
    for($i=0; $i<$N; $i++){
        $res = $res * $arr[$i];
    }
    if($res > pow(10,18)){
        $res = -1;
    }
};
echo $res;
?>


<?php
    $cnt = fgets(STDIN);

    $i = explode(" ",trim(fgets(STDIN)));
    $i = (int)(array_product($i));
    // echo $i;
    $g = (int)(pow(10,18));
    // echo $g;

    if($i > $g){
        echo '-1';
    }else{
        echo (int)($i);
    }


<?php
    $num_a = intval(trim(fgets(STDIN)));
    $num = array_map('intval',explode(" ",trim(fgets(STDIN))));
    sort($num);
    $answer =1;
    for($i=0;$i<$num_a;$i++){

        $answer = $answer * $num[$i];
        if($answer>pow(10,18)){
            echo "-1";
            exit;
        }
    }
    echo $answer;
?>


<?php
  fscanf(STDIN, "%d", $n);
  $aa = fgets(STDIN);
  $a = explode(' ', $aa);

  foreach($a as $num) {
    if(0 === (int) $num) {
      echo 0;
      exit;
    }
  }

  $ans = 1;
  foreach($a as $num) {
    $ans = $ans * (int) $num;
    if($ans > pow(10, 18)) {
      echo -1;
      exit;
    }
  }
  echo $ans;


<?php
// Your code here!
$times = fgets(STDIN);
$nums = explode(" ",fgets(STDIN));

$ans = 1;
foreach ($nums as $num) {
    $ans *= $num;
}
if($ans >= 10 ** 18){
    $ans = -1;
}
echo $ans;
?>


<?php
// B
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 1;
sort($a);
for ($i = 0; $i < $n; $i++) {
    if ($a[$i] === 0) exit('0');
    $ans *= $a[$i];
    if ($ans > 10 ** 18) exit('-1');
}
echo $ans;


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

$array = explode(' ', trim(fgets(STDIN)));

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

if ($ans > pow(10, 18)) {
  echo -1;
} else {
  echo $ans;
}


<?php
$N = (int)fgets(STDIN);
$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

if (array_search(0, $A)) {
    echo 0;
    return;
}

$ans = 1;
foreach ($A as $a) {
    $ans *= $a;
    if ($ans > 1000000000000000000) {
        echo '-1';
        return;
    }
}

echo $ans;


<?php

$n = (int)fgets(STDIN);
$a = array_map('intval', explode(' ',trim(fgets(STDIN)));
$mul = 1;
for ($i=0; $i<$n; $i++) {
  $mul *= $a[$i];
  if ($mul > 1000000000000000000) {
    echo -1;
    exit;
  }
}
echo $mul;


<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($A);

$flg = true;
$prod = 1;
for ($i = 0; $i < $n; ++$i) {
    $prod *= $A[$i];

    if ($prod > 1000000000000000000) {
        $flg = false;
        break;
    }
}

echo $flg ? $prod : -1;


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

if($a * $b > 10**18){
    echo "-1";
}else{
    echo $a * $b;
}


<?php
fscanf(STDIN, '%f %f', $a, $b);
echo (int)floor((int)$a * (int)($b*100)/100);

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


<?php
  $tmp = explode(" ",trim(fgets(STDIN)));

  $val1 = $tmp[0];
  $val2 = intval(str_replace(".", "", $tmp[1]));

  $tmp2 = $val1*$val2;
  if(strlen($tmp2)>2){
    echo substr($tmp2, 0, -2)."\n";
  }else{
    echo ($tmp2 / 100)."\n";
  }


<?php
  fscanf(STDIN, "%d %f", $a, $b);
  echo bcmul($a, $b);


<?php
fscanf(STDIN, "%d %s", $a, $b);
echo intdiv($a * $b, 100);

?>


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

$m = $m * 100 +0.5;
echo intdiv($n*$m, 100);
?>


<?php
fscanf(STDIN, "%d %f", $a, $b);
$sum = $a * $b * 100 / 100;
echo intval($sum);


<?php
fscanf(STDIN, "%d %f", $a, $b);
$b = $b * 100;
$sum = $a * $b /100;
echo floor($sum);


<?php
fscanf(STDIN, "%d %f", $a, $b);
$sum = $a * $b;
if(preg_match('/[.]/',$sum)){
  $sum = floor($sum);
}
echo $sum;


<?php

list($num1,$num2) = explode(' ',trim(fgets(STDIN)));

echo ($num1 * (int)($num2 * 100)) / 100;
?>


<?php
fscanf(STDIN,"%d%f",$a,$b);
printf("%d\n",bcmul($a,$b,0));
?>


<?php
  	$input = explode(" ", trim(fgets(STDIN)));
	$ans = $input[0] * $input[1];
	echo $ans;
	$ans = floor($ans);
	echo $ans;
?>


<?PHP

$array = explode(" ", trim(fgets(STDIN)));
$a = $array[0];
$b = $array[1] * 100;

$kotae = (int)($a * $b / 100);
echo $kotae;


<?php
list($A, $B) = explode(' ', fgets(STDIN));
$B = str_replace('.', '', $B);
$ans = (string)(int)$A * (int)$B;
if ($ans < 100) {
    echo 0;
    return;
}
echo substr($ans, 0, -2);


<?php

fscanf(STDIN, "%d %f", $in_a, $in_b);
$a = $in_a * $in_b;
$ans = (int)$a;

echo "$ans\n";


<?php

$input=explode(' ',trim(fgets(STDIN)));

$a = intval($input[0]);
$b = intval(str_replace(".", "", $input[1]));

$res = $a * $b;

echo gmp_div_qr($res, 100)[0];


<?php
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$x=(int)$a;
$y=str_replace(".","",$b);
$ans=(int)($x*$y);
$n=strlen($ans);
if($n<3){
  echo 0;
  exit;
}
echo substr($ans,0,$n-2);


<?php

$input=explode(' ',trim(fgets(STDIN)));

$a = floatval($input[0]);
$b = intval(floatval($input[1]) * 1000);

$res = $a * $b;

echo sprintf("%.0f", floor($res / 1000));


<?php

$input=explode(' ',trim(fgets(STDIN)));

$a = floatval($input[0]);
$b = intval(floatval($input[1]) * 100 + 0.5);

$res = $a * $b;

echo sprintf("%.0f", floor($res / 100));


<?php
fscanf(STDIN, "%d %f", $A, $B);
$ans = $A*$B;
$ans = (int)(floor($ans));
echo ($ans);
?>


<?php

fscanf(STDIN, "%d %f", $a, $b);

echo (int) bcmul($a, $b);


<?php
// C2
fscanf(STDIN, '%s %s', $a, $b);
$b = str_replace('.', '', $b);
echo intdiv($a * $b, 100);


<?php
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$x=(int)$a;
$y=(int)($b*1000);
$ans=(int)($x*$y);
$n=strlen($ans);
if($n<4){
  echo 0;
  exit;
}
echo substr($ans,0,$n-3);


<?php
  fscanf(STDIN, "%d%s", $a,$b);
  $b *= 100;
  $ans = $a*$b;
  if(strlen($ans) <= 3){
      echo $ans;
  }else{
      echo substr($ans,0,-2);
  }


<?PHP

$array = explode(" ", trim(fgets(STDIN)));
$a = $array[0];
$b = $array[1];

$kotae = (int)($a * $b);
echo $kotae;


<?php
    $num = explode(" ",trim(fgets(STDIN)));

    $num[0]= intval($num[0]);
    $num[1]= str_replace(".","",$num[1]);

    $answer =  intval($num[1])*($num[0]);

    if($answer<1000){
        echo floor($answer/100);
        exit;
    }

    $answer = strval($answer);

    $answer = str_split($answer);

    array_pop($answer);
    array_pop($answer);

    foreach ($answer as $value) {
        echo $value;
    }

?>


<?php
// C
fscanf(STDIN, '%s %s', $a, $b);
$b1 = (int) ($b * 100);
$ans = (int) substr(omulti($a, $b1), 0, -2);
echo $ans;

function omulti($a, $b)
{
    $aa = str_split(strval($a));
    $bb = str_split(strval($b));
    foreach ($aa as $ka => $va) {
        foreach ($bb as $kb => $vb) {
            $res[$ka + $kb + 1] += intval($va) * intval($vb);
        }
    }
    for ($i = max(array_keys($res)); $i > 0; $i--) {
        if ($res[$i] > 9) {
            $res[$i - 1] += floor($res[$i] / 10);
            $res[$i] %= 10;
        }
    }
    ksort($res);
    return implode("", $res);
}


<?php
    $num = explode(" ",trim(fgets(STDIN)));

    $num[0]= intval($num[0]);
    $num[1]= str_replace(".","",$num[1]);

    $answer =  intval($num[1])*($num[0]);

    $answer = strval($answer);

    $answer = str_split($answer);

    array_pop($answer);
    array_pop($answer);

    // print_r($answer);

    foreach ($answer as $value) {
        echo $value;
    }

?>


<?php
    $num = explode(" ",trim(fgets(STDIN)));

    $num[0]= intval($num[0]);
    $num[1]= str_replace(".","",$num[1]);

    $answer =  $num[1].$num[0];

    echo floor($answer/100);
?>


<?php
// Your code here!
list($num1,$num2) = explode(" ",trim(fgets(STDIN)));

$ans = (int)floor($num1 * $num2);
echo $ans;
?>


<?php
fscanf(STDIN, "%d%f", $a, $b);
$mul = $a * (int)($b * 100);
echo intdiv($mul, 100);


<?php
    $c = explode(" ",trim(fgets(STDIN)));
    $c = array_product($c);
    $c = floor($c);
    $c = (int)($c);
    // var_dump($c);
    echo $c;


<?php
  $a = explode(' ', trim(fgets(STDIN)));
  $num = 1;
  foreach ($a as $value) {
    // code...
    $num *= $value;
  }
  $newN = floor($num);
  echo intval($num);


<?php

$n = explode(' ', fgets(STDIN));
$a = (int)$n[0];

if ($a == 0) {
    echo 0;
    return;
}

$b = round((float)$n[1] * 100);
$b = $b / 100;

if ($b == 0) {
    echo 0;
    return;
}

$hoge = floor($a * $b);
echo (int)$hoge;


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

//  $m = $m*100;

  $ans = (int)($n*$m);

  echo $ans;

 // echo intdiv($n*$m, 100);


<?php

$n = explode(' ', fgets(STDIN));
$a = (int)$n[0];

if ($a == 0) {
    echo 0;
    return;
}

if ($b == 0) {
    echo 0;
    return;
}

$b = (float)$n[1];
$hoge = floor($a * $b);
echo (int)$hoge;


<?php
fscanf(STDIN,"%d%f",$a,$b);

echo (int)($a*$b)."\n";


<?php
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$b*=100;
$ans=(int)($a*$b);
$n=strlen($ans);
if($n<3){
  echo 0;
  exit;
}
echo substr($ans,0,$n-2);


<?php

$a = explode(' ', fgets(STDIN));

echo floor($a[0] * $a[1]);


<?php
fscanf(STDIN, "%d %f", $A, $B);
$ans = $A*$B;
print_r ($ans);
?>


<?php
list($A, $B) = explode(' ', fgets(STDIN));

echo (int)((int)$A * (float)$B);


<?php

[$N,$T] = fscanf(STDIN, "%d%d");
$town = fscanf(STDIN, str_repeat("%d", $N));
$tele = array_fill(1,$N,0);
$tele[1] = 1;
$i = 0;
$now = 1;
while($T--){
    $now = $town[$now-1];

    if($tele[$now] === 1){
        $start = $now;
        $now = $town[$now-1];
        $count = 1;
        while($now != $start){
            $now = $town[$now-1];
            $count++;
        }
        $T %= $count;
        while($T--){
            $now = $town[$now-1];

        }
        break;
    }else{
        $tele[$now] = 1;
    }

}

echo $now;

Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


<?php
fscanf(STDIN, "%d %d", $N, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cursor = 1;
$line = ['1'];
$visited = ['1' => 1];
$next = null;
$ans = null;
while(true) {
    $next = $A[$cursor - 1];
    if (isset($visited[$next])) {
        $pos = array_search($next, $line);
        $K -= $pos;
        $loop = count($line) - $pos;
        $ans = $line[$pos + $K % $loop];
        break;
    } else {
        $line[] = $next;
		$visited[$next] = 1;
    }
    if (count($line) === $K + 1) {
        $ans = $next;
        break;
    }
    $cursor = $next;
}
printf("%d", $ans);


<?php
  fscanf(STDIN,"%d%d", $n,$k);
  $a = explode(" ", trim(fgets(STDIN)));
  $tosi[0] = 0;
  $tele[0] = 1;
  $i = 1;
  while(1){
    if(isset($tosi[$a[$tele[$i-1]-1]])){
      $s = $tosi[$a[$tele[$i-1]-1]];
      break;
    }
    $tele[$i] = $a[$tele[$i-1]-1];
    $tosi[$a[$tele[$i-1]-1]] = $i;
    $i++;
  }
 // print_r($tele);
  //print_r($tosi);

  $syu = count($tosi)-$s;
  if($k<count($tele)){
    echo $tele[$k-1];
  }else{
    $l = count($tele)-1-$s;
    $t = ($k-$l)%$syu;
    //echo $t;
  echo $tele[$t+$l];
  }


<?php
  fscanf(STDIN,"%d%d", $n,$k);
  $a = explode(" ", trim(fgets(STDIN)));
  $tosi[0] = 0;
  $tele[0] = 1;
  $i = 1;
  while(1){
    if(isset($tosi[$a[$tele[$i-1]-1]])){
      $s = $tosi[$a[$tele[$i-1]-1]];
      break;
    }
    $tele[$i] = $a[$tele[$i-1]-1];
    $tosi[$a[$tele[$i-1]-1]] = $i;
    $i++;
  }
 // print_r($tele);
  //print_r($tosi);

  $syu = count($tosi)-$s;
  //echo $syu;
  if($k<=count($tele)){
    echo $tele[$k];
  }else{
    $l = count($tele)-1-$s;
    $t = ($k-$l)%$syu;
    //echo $t;
    echo $tele[$t+$l];
  }


<?php
  fscanf(STDIN,"%d%d", $n,$k);
  $a = explode(" ", trim(fgets(STDIN)));
  $tosi[0] = 0;
  $tele[0] = 1;
  $i = 1;
  while(1){
    if(isset($tosi[$a[$tele[$i-1]-1]])){
      $s = $tosi[$a[$tele[$i-1]-1]];
      break;
    }
    $tele[$i] = $a[$tele[$i-1]-1];
    $tosi[$a[$tele[$i-1]-1]] = $i;
    $i++;
  }
 // print_r($tele);
  //print_r($tosi);

  $syu = count($tosi)-$s;
  //echo $syu;
  if($k<=count($tele)){
    echo $tele[$k];
  }else{
    $l = count($tele)-1-$s;
    $t = $k%$syu-$l;
    //echo $t;
    echo $tele[$t+$l];
  }


<?php
[$N, $K] = ints();
$dp[0] = array_merge([0],ints());
for($i = 1; $i < 64; $i++){
  $dpi = &$dp[$i];
  $dpim = $dp[$i-1];
  for($j = 1; $j <= $N; $j++){
    $dpi[$j] = $dpim[$dpim[$j]];
  }
}
$c = 1;
$i = 0;
while($K >> $i){
  if($K >> $i & 1)$c=$dp[$i][$c];
  $i++;
}
echo $c;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


<?php
  list($townNum, $move) = explode(' ', input());
  $to = explode(' ', input());
  $current = 1;
  $visited = $moved = [];

  for($i = 1; $i <= $move; $i++) {
    if (isset($visited[$current])) {
      break;
    }
    $visited[$current] = $i;
    $moved[$i] = $current;

    $_tmp = $to[$current - 1];
    $current = $_tmp;
  }

$base = $visited[$current];
$loop = $i - $base;
$_moved = ($move + 1 - $base) % $loop;

echo $moved[$base + $_moved];

function input()
{
  return trim(fgets(STDIN));
}


<?php

fscanf(STDIN, "%d%d", $N, $K);

$list = explode(" ", trim(fgets(STDIN)));
$chkarray = array_fill(1, $N, 0);
$count = 0;
$now = 1;
while(true){
    $count++;
    if($chkarray[$now] != 0){
        $before = $chkarray[$now] - 1;
        $loop = $count - $before -1;
        $loop_target = $now;
        break;
    }else{
        $chkarray[$now] = $count;
        $now = $list[$now-1];
        $memo[$count] = $now;
    }
}
$value = $K - $before;
$value = $value - $loop * intdiv($value-1, $loop);
//
//while($value--){
//    $loop_target = $list[$loop_target-1];
//}
echo $memo[$value + $before];


<?php

fscanf(STDIN, '%d %d %d %d', $A, $B, $C, $D);

$takahashi = false;
while ($A > 0 && $C > 0) {
    $takahashi = !$takahashi;
    if ($takahashi) {
        $C -= $B;
    } else {
        $A -= $D;
    }
}

if ($takahashi) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;

Score : 200 points

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...
Here, an attack decreases the opponent's health by the value equal to the attacker's strength.
The monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

If Takahashi will win, print Yes; if he will lose, print No.

Constraints

1 \leq A,B,C,D \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi will win, print Yes; if he will lose, print No.

Sample Input 1

10 9 10 10

Sample Output 1

No

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

Sample Input 2

46 4 40 5

Sample Output 2

Yes


<?php
fscanf(STDIN, "%d %d %d %d", $A, $B, $C, $D);
$result = 'Yes';
$count = 0;

while ($A > 0 && $C > 0){
  if ($count % 2 === 0) {
    $C -= $B;
  } else {
    $A -= $D;
  }
  $count++;
}

if ($A <= 0) {
  $result = 'No';
}

echo $result;


<?php
list($takahashi_hp, $takahashi_att, $aoki_hp, $aoki_att) = explode(' ', trim(fgets(STDIN)));

for ($i = 0; $i <= 100; $i++) {
    (int)$aoki_hp -= (int)$takahashi_att;

    if ($aoki_hp <= 0) {
        echo 'Yes';
        break;
    }

    (int)$takahashi_hp -= (int)$aoki_att;

    if ($takahashi_hp <= 0) {
        echo 'No';
        break;
    }
}


<%php
fscanf(STDIN,"%d %d %d %d",$taka_a,$taka_b,$ao_c,$ao_d);
while(true){
  $ao_c = $ao_c - $taka_b;
  if($ao_c <= 0) {
    echo "Yes";
    break;
  }
  $taka_a = $taka_a - $ao_d;
  if($taka_a <= 0) {
    echo "No";
    break;
  }
}
%>


<%php
fscanf(STDIN,"%d %d %d %d",$taka_a,$taka_b,$ao_c,$ao_d);
while(true){
  $ao_c = $ao_c - $taka_b;
  if($ao_c <= 0) {
    echo "Yes";
    break;
  }
  $taka_a = $taka_a - $ao_d;
  if($taka_a <= 0 {
    echo "No";
    break;
  }
}
%>


<?php

$input = fgets(STDIN);

$T_LP = (int)explode(' ', $input)[0];
$T_AT = (int)explode(' ', $input)[1];
$A_LP = (int)explode(' ', $input)[2];
$A_AT = (int)explode(' ', $input)[3];

while($T_LP > 0 && $A_LP > 0){
  $A_LP -= $T_AT;
  if($A_LP <= 0){
    echo 'Yes';
    break;
  }

  $T_LP -= $A_AT;
  if($T_LP <= 0){
    echo 'No';
    break;
  }
}


<?php

$input = fgets(STDIN);

$T_LP = (int)explode(' ', $input)[0];
$T_AT = (int)explode(' ', $input)[1];
$A_LP = (int)explode(' ', $input)[2];
$A_AT = (int)explode(' ', $input)[3];

while($T_LP > 0 && $A_LP){
  $A_LP -= $T_AT;
  if($A_LP <= 0){
    echo 'Yes';
  }

  $T_LP -= $A_AT;
  if($T_LP <= 0){
    echo 'No';
  }
}


<?php
fscanf(STDIN, "%d %d %d %d", $tAt, $tHp, $aAt, $aHp);

// 両者のHPが残存している場合にバトル成立
while($tHp > 0 && $aHp > 0){

  // 高橋の攻撃 両者のHPが残存している場合に、攻撃が成立
  if($tHp > 0 && $aHp > 0){
	$aHp = $aHp - $tAt;
}
   // 青木の攻撃 両者のHPが残存している場合に、攻撃が成立
  if($aHp > 0 && $tHp > 0){
	$tHp = $tHp - $aAt;
}
}

if($tHp <= 0){
	echo 'No';
}elseif($aHp <= 0){
	echo 'Yes';
}


<?php
fscanf(STDIN, "%d %d %d %d", $tAt, $tHp, $aAt, $aHp);

while($tHp > 0 && $aHp > 0){

  if($aHp > 0){
	$aHp = $aHp - $tAt;
}
  if($aHp > 0 && $tHp > 0){
	$tHp = $tHp - $aAt;
}
}

if($tHp <= 0){
	echo 'No';
}else{
	echo 'Yes';
}


<?php
fscanf(STDIN, "%d %d %d %d", $tAt, $tHp, $aAt, $aHp);

while($tHp > 0 && $aHp > 0){

  if($aHp > 0){
	$aHp = $aHp - $tAt;
}
  if($tHp > 0){
	$tHp = $tHp - $aAt;
}
}

if($tHp > 0){
	echo 'Yes';
}else{
	echo 'No';
}


<?php
fscanf(STDIN, "%d %d %d %d", $tAt, $tHp, $aAt, $aHp);

while($tHp > 0 && $aHp > 0){

  if($aHp > 0){
	$aHp = $aHp - $tAt;
}
  if($tHp > 0){
	$tHp = $tHp - $aAt;
}
}

if($tHp <= 0){
	echo 'No';
}else{
	echo 'Yes';
}


<?php
  fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);
  $who = 0;
  $switch = true;
  while ($switch == true ) {
    // code...
    $c -= $b;
    if ($c <= 0) {
      // code...
      $who = 1;
      $switch = false;
      break;
    }
    $a -= $d;
    if ($a <= 0) {
      // code...
      $who = 2;
      $switch = false;
    }
  }
  if ($who == 1) {
    // code...
    echo "Yes";
  }else {
    // code...
    echo "No";
  }


<?php
    fscanf(STDIN, '%d %d %d %d',$a,$b,$c,$d);
    while(true){
        if(($c -= $b) <= 0){
            $ans = 'Yes';
            break;
        }
        if (($a -= $d) <= 0) {
            $ans = 'No';
            break;
        }
    }
    echo $ans.PHP_EOL;
?>


<?php
fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$d);
while (true) {
    if (($c -= $b) < 1) {
        echo 'Yes'.PHP_EOL;
        break;
    }

    if (($a -= $d) < 1) {
        echo 'No'.PHP_EOL;
        break;
    }
}


<?php
fscanf(STDIN, "%d %d %d %d", $a,$b,$c,$d);

if($c % $b < $a % $d){
   echo "Yes";
}else{
   echo "No";
}

?>


<?php

    // AtCoder Beginner Contest 164
    // B - Battle

    list($hp1, $atk1, $hp2, $atk2) = in_ints();
    while ($hp1 != 0 && $hp2 != 0) {
        $hp2 -= $atk1;
        if ($hp2 <= 0) {
            break;
        }
        $hp1 -= $atk2;
    }
    if ($hp1 <= 0) {
        no();
    } else {
        yes();
    }

    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.


<?php

  list($s) = explode(" ", trim(fgets(STDIN)));

  $s = strrev($s);

  $len = strlen($s);

  $ten = 1;
  $amari_count = array_fill(0, 2019, 0);
  $amari = 0;
  $amari_count[0]++;
  $ans = 0;
  for($i=0; $i<$len; $i++){
    $amari = ($s[$i] * $ten + $amari) % 2019;
    $ans += $amari_count[$amari];
    $amari_count[$amari]++;
    $ten = $ten * 10 % 2019;
  }

  echo $ans;


<?php

  list($s) = explode(" ", trim(fgets(STDIN)));

  $s = strrev($s);

  $len = strlen($s);

  $ten = 1;
  $amari_count = array_fill(0, 2019, 0);
  $amari = 0;
  $amari_count[0]++;
  $ans = 0;
  for($i=0; $i<$len; $i++){
    $amari = ($s[$i] * $ten + $amari) % 2019;
    $ans += $amari_count[$amari];
    $amari_count[$amari]++;
    $ten *= 10 % 2019;
  }

  echo $ans;


<?php

$input = trim(fgets(STDIN));

$ret = 0;
for($i = 0; $i < strlen($input); ++$i){
  for($j = $i + 3; $j < strlen($input); ++$j){
    if($i > $j){
      continue;
    }

    $num = substr($input, $i, ($j - $i) + 1);
    if($num % 2019 == 0){
      ++$ret;
    }

    unset($num);
  }
}

echo $ret;


<?php

$input = trim(fgets(STDIN));

$ret = 0;
for($i = 0; $i < strlen($input); ++$i){
  for($j = $i + 3; $j < strlen($input); ++$j){
    if($i > $j){
      continue;
    }

    $num = substr($input, $i, ($j - $i) + 1);
    if($num % 2019 == 0){
      $ret += 1;
    }

    unset $num;
  }
}

echo $ret;


<?php

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

$ret = 0;
for($j = 4; $j <= strlen($input); $j++){
  for($i = 0; $i < $j - 4; $i++ ){
     $mod = substr($input, $i, $j - $i) % 2019;
     if($mod === 0){
       $ret   += 1;
     }
 }
}

echo $ret;


<?php
$S = trim(fgets(STDIN));
$len = strlen($S) - 1;

$ti = [];
$ti[$len] = (int)$S[$len] % 2019;
$mod_table = [];
$mod_table[$ti[$len]] = 1;
$mod_pow_ten_table = [];
$mod_pow_ten_table[0] = 1;

$ans = 0;
for ($i = $len; $i > 0; $i--) {
    $mod_pow_ten_table[$len - $i + 1] = $mod_pow_ten_table[$len - $i] * 10 % 2019;
    $ti[$i - 1] = ((int)$S[$i - 1] * $mod_pow_ten_table[$len - $i + 1] + $ti[$i]) % 2019;
    $mod_table[$ti[$i - 1]] += 1;
}

foreach ($mod_table as $index => $num) {
    if ($index === 0) {
        $num += 1;
    }
    $ans += $num * ($num - 1) / 2;
}

echo $ans;


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

  $str4 = [];
  $str5 = [];
  $str6 = [];
  $str7 = [];
  $str8 = [];
  for($i=1; $i<10000; $i++){
    $b2019 = 2019*$i;
    if (preg_match("/0/", $b2019)){
      continue;
    }
    $len = strlen($b2019);
    if($len==4){
      $str4[$b2019] = true;
    }else if($len==5){
      $str5[$b2019] = true;
    }else if($len==6){
      $str6[$b2019] = true;
    }else if($len==7){
      $str7[$b2019] = true;
    }else if($len==8){
      $str8[$b2019] = true;
    }
  }

  $len = strlen($s);
  $ans = 0;
  for($i=0;$i<$len; $i++){
    $substr = substr($s, $i, 4);
    if(isset($str4[$substr])){
      $ans++;
    }
    $substr = substr($s, $i, 5);
    if(isset($str5[$substr])){
      $ans++;
    }
    $substr = substr($s, $i, 6);
    if(isset($str6[$substr])){
      $ans++;
    }
    $substr = substr($s, $i, 7);
    if(isset($str7[$substr])){
      $ans++;
    }
    $substr = substr($s, $i, 8);
    if(isset($str8[$substr])){
      $ans++;
    }
  }
echo $ans;


<?php
// 標準入力を代入します
$number = fgets(STDIN);

$count = 0;

for($i = 0 ; $i < strlen($number); $i++){
    for($j = 1; $j <= strlen($number) - $i; $j++){
        $target_num = substr($number,$i,$j);
        if($target_num % 2019 == 0){
            $count++;
            //print("(i,j) = ( $i , $j )"."\n");
        }
    }
}

print ($count);


<?php
while ($line = fgets(STDIN)) {
    $inputs[] = trim($line);
};
$s = (int)array_shift($inputs);
$s_arr = str_split($s);

$ans = 0;
for ($i = 0; $i < count($s_arr); $i++) {
    for ($j = $i; $j < count($s_arr); $j++){
        $check_num = "";
        for ($k = $i; $k <= $j; $k++) {
            if ($s_arr[$k] == 0) {
                break;
            }
            $check_num .= $s_arr[$k];
        }
        $check_num = (int) $check_num;
        if ($check_num > 200000 | $check_num < 1) {
            continue;
        }

        if (($check_num % 2019) === 0) {
            #echo "check_num: $check_num\n";
            #echo "i, j: $i, $j\n";
            $ans++;
        }
    }

}
echo $ans . "\n";


<?php
    fscanf(STDIN,'%s',$s);
    $len = strlen($s);
    if($len > 3){
        $ans = 0;
        for($start = 0;$start < $len-4;++$start){
            for ($end = $start + 4; $end <= $len; ++$end) {
                if((int)substr($s,$start,$end) % 2019 === 0){
                    ++$ans;
                }
            }
        }
    }else{
        $ans = 0;
    }
    echo $ans.PHP_EOL;
?>


<?php

list($s) = explode(' ', trim(fgets(STDIN)));

$length = strlen($s);
$target_length = 4;

$count = 0;
for ($i = 0; $i < $length - $target_length; ++$i) {
    for ($j = $target_length; $j <= $length - $i; ++$j) {
        $sub = substr($s, $i, $j);
        if ($sub % 2019 === 0) {
            ++$count;
        }
    }
}

echo $count;


Score : 100 points

Problem Statement

Print the circumference of a circle of radius R.

Constraints

1 \leq R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R

Output

Print the circumference of the circle.
Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

Sample Input 1

1

Sample Output 1

6.28318530717958623200

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

Sample Input 2

73

Sample Output 2

458.67252742410977361942


<?php
$stdin = fgets(STDIN);
echo (int)$stdin * 2 * pi();


<?php
$s = intval(trim(fgets(STDION)));
print($s * 2 * 3.14)
?>


<?php

fscanf(STDIN, "%d", $a);
echo $a * 2 * pi();


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

echo 2*pi()*$input;


<?php
    fscanf(STDIN, '%d', $d);

    $diameter = $d * 2;
    $circumference = $diameter * 3.14;

    echo $circumference;


<?php

$stdin = trim(fgets(STDIN));
echo $stdin * 4.14;


<?php

$line = fgets(STDIN);
$r = (int)$line;
$ans = 2 * $r * 3.1415926535;
echo $ans;


<?php
  fscanf(STDIN, "%d", $d);
	echo (floor)$d*2*3.14 . "\n";


<?php

    // AtCoder Beginner Contest 163
    // A - Circle Pond

    $r = in_int();
    out($r * 2 * pi());

    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
$R = trim(fgets(STDIN));
//list($a,$b,$c) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

printf("%f\n",($R*2)*M_PI);


<?php

fscanf(STDIN, "%d", $N);
strpos($N,'7') !== false ? print "Yes" : print "No";

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes


<?php
  $a=str_split(trim(fgets(SDTIN)));
if(in_array(7,$a)){
  echo "Yes";
}else{
  echo "No";
}


<?php

$line = fgets(STDIN);

if(preg_match("/7/", $line)) {
    echo "Yes";
} else {
    echo "No";
}

?>


<?php
$jud = 0;
$N = trim(fgets(STDIN));  // 入力
$Nlen = strlen($N);
for ($i = 0; $i <= ($Nlen - 1); $i++) {
    if ($N[$i] == 7) {
        echo 'Yes';
        $jud = 1;
        break;
    }
}
if ($jud == 0) {
    echo 'No';
}