<?php
$N = fgets(STDIN);

for ($i = 0; $i < 3; $i++) {
    var_dump((int)$N[$i]);
    if ((int)$N[$i] === 7) {
        echo 'Yes';
        return;
    }
}

echo 'No';


<?php
// Your code here!
    $stdin = trim(fgets(STDIN));
    $pos = strpos($stdin, "7");

    if ($pos === false) {
        echo "No";
    } else {
        echo "Yes";
    }
?>

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

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

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

$N = str_split($N);

foreach ($N as $N_1) {
 	 if ($N_1 === 7){
       echo 'Yes';
       exit;
     }
}
echo 'No';


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

  if(strpos($val, "7")!==false){
    echo "Yes";
  }else{
    echo "No";
  }


$n = fgets(STDIN);
$arr = str_split($n);
$arr0 = $arr[0];
$arr1 = $arr[1];
$arr2 = $arr[2];

if($arr0 == 7){
  echo 'Yes';
  }
  elseif($arr1 == 7){
  echo 'Yes';
  }
  elseif($arr2 == 7){
  echo 'Yes';
  }
  else{
  echo 'No';
  }


<?php

  $a = fgets(STDIN);

  $b= str_split($a);

  if( in_array('7',$b)){
      echo "Yes";
  }else{
      echo "No";
  }

?>


$n = fgets(STDIN);
$arr = str_split($n);
$arr0 = $arr[0];
$arr1 = $arr[1];
$arr2 = $arr[2];

if($arr0 == 7 ||$arr1 == 7 ||$arr2 == 7){
  echo 'Yes';
  }else{
  echo 'No';
  }


<?php
// Your code here!
$stdin = trim(fgets(STDIN));
if (preg_match("[7]", $stdin) != 0){
    echo "Yes";
}else{
    echo "No";
};


<?php
$num = str_split(trim(fgets(STDIN)));
foreach($num as $value) {
  if($value == '7') {
    echo 'Yes';
    return;
  }
}
echo 'No';


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

$ans = 'No';
for ($i = 0; $i < 3; $i++) {
  if ($n[$i] == 7) {
    $ans = 'Yes';
  }
}
echo $ans;


<?php
$n=trim(fgets(STDIN));
$i=0;
while($i<3){
  if($n[$i]==7){
    echo "Yes";
    exit;
  }
  ++$i;
}
echo "No";


Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


<?php
// C
fscanf(STDIN, '%d', $K);
$ans = 0;
for ($i = 1; $i <= $K; $i++) {
    for ($j = 1; $j <= $K; $j++) {
        for ($k = 1; $k <= $K; $k++) {
            $ans += gcd(gcd($i, $j), $k);
        }
    }
}
echo $ans;

// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}


<?php
    //ユークリッドの互除法
    function gcd($a,$b){
        if($b === 0){
            return $a;
        }
        return gcd($b,$a%$b);
    }

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

    //参考　⇒　https://note.com/tanon_cp/n/n2eb2bb1d69f9
    //keyがaとbの最大公約数でvalueがその個数になる
    $gcdAAndB = array_fill(1,$n,0);
    for ($a = 1; $a <= $n; ++$a) {
        for ($b = 1; $b <= $n; ++$b) {
            ++$gcdAAndB[gcd($a,$b)];
        }
    }
    //$gcdAAndBとkeyの最大公約数がvalue個ある
    $ans = 0;
    $count = count($gcdAAndB);
    for ($c = 1; $c <= $n; ++$c) {
        for ($index = 1; $index <= $count; ++$index) {
            $ans += gcd($c,$index) * $gcdAAndB[$index];
        }
    }
    echo $ans.PHP_EOL;

?>


<?php
list($K) = ints();
$sum6 = 0;
for($i = 1; $i <= $K; ++$i)
for($j = 1; $j <= $K; ++$j)
$memo[$i][$j] = $memo[$j][$i] = (int)gmp_gcd($i, $j);

for($i = 1; $i <= $K; ++$i)
for($j = $i+1; $j <= $K; ++$j){
    $mij = $memo[$memo[$i][$j]];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$mij[$k];
}

for($i = 1; $i <= $K; ++$i){
  $mi = $memo[$i];
  for($j = $i+1; $j <= $K; ++$j)
    $sum6+=$mi[$j];
}

echo $sum6*6+$K*($K+1)/2;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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($K) = ints();
$sum6 = 0;
for($i = 1; $i <= $K; ++$i)
for($j = 1; $j <= $K; ++$j)
$memo[$i][$j] = $memo[$j][$i] = (int)gcd($i, $j);

for($i = 1; $i <= $K; ++$i)
for($j = $i+1; $j <= $K; ++$j){
    $mij = $memo[$i][$j];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$mij[$k];
}
for($i = 1; $i <= $K; ++$i){
  $mi = $memo[$i];
  for($j = $i+1; $j <= $K; ++$j)
    $sum6+=$mi[$j];
}

echo $sum6*6+$K*($K+1)/2;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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($K) = ints();
$sum6 = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = (int)gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++){
    $mij = $memo[$memo[$i][$j]];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$mij[$k];
}

for($i = 1; $i <= $K; $i++){
  $mi = $memo[$i];
  for($j = $i+1; $j <= $K; ++$j)
    $sum6+=$mi[$j];
}

echo $sum6*6+$K*($K+1)/2;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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($K) = ints();
$sum6 = 0;
$sum1 = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = (int)gmp_gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++){
    $ij = $memo[$i][$j];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$memo[$ij][$k];
}
for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
    $sum6+=$memo[$i][$j];

for($i = 1; $i <= $K; $i++)
    $sum1+=$i;

echo $sum6*6+$sum1;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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($K) = ints();
$sum6 = 0;
$sum1 = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = (int)gmp_gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
for($k = $j+1; $k <= $K; ++$k)
    $sum6+=$memo[$memo[$i][$j]][$k];

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
    $sum6+=$memo[$i][$j];

for($i = 1; $i <= $K; $i++)
    $sum1+=$i;

echo $sum6*6+$sum1;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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($K) = ints();
$sum = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = gmp_gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
for($k = 1; $k <= $K; $k++)
    $sum+=$memo[$memo[$i][$j]][$k];

echo $sum;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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
$input_line = trim(fgets(STDIN));
$sum = 0;
for ($i = 0; $i < $input_line; $i++) {
  for ($j = 0; $j < $input_line; $j++) {
    for ($k = 0; $k < $input_line; $k++) {
 	   $sum += (int)gmp_gcd($i, $j);
       $sum += (int)gmp_gcd($j, $k);
   	   $sum += (int)gmp_gcd($k, $i);
    }
  }
}
$sum /= 2;
echo $sum; // 21
?>


<?php
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//$S = 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))));

$c = array();
for($i=1;$i<=$N;$i++) {
  for($j=1;$j<=$N;$j++) {
    for($k=1;$k<=$N;$k++) {
      if (!isset($c[$i][$j])) {
        $c[$i][$j]=gcd($i,$j);
      }
      if (!isset($c[$c[$i][$j]][$k])) {
        $c[$c[$i][$j]][$k]=gcd($c[$i][$j],$k);
      }
      //printf("%d %d %d  %d\n",$i,$j,$k,$s);
      $sum+=$c[$c[$i][$j]][$k];
    }
  }
}
printf("%d\n",$sum);

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

$k = trim(fgets(STDIN));

$divisors = [];
for ($i=1;$i<=$k;++$i) {
    for ($j=1;$j<=$i;++$j) {
        if ($i%$j === 0) $divisors[$i][] = $j;
    }
}

$count = 0;
for($i=1;$i<=$k;++$i) {
    for($j=$i;$j<=$k;++$j) {
        for($l=$j;$l<=$k;++$l) {
            $common_divisors = array_intersect(
                $divisors[$i],
                $divisors[$j],
                $divisors[$l]
            );

            if ($i === $j || $j === $l || $i === $l) {
                if ($i === $j && $j === $l) {
                    $count += end($common_divisors);
                } else {
                    $count += end($common_divisors) * 3;
                }
            } else {
                $count += end($common_divisors) * 6;
            }
        }
    }
}

echo $count . PHP_EOL;


<?php

    // AtCoder Beginner Contest 162
    // C - Sum of gcd of Tuples (Easy)

    $max = in_int();

    $sum = 0;
    for ($i = 1; $i <= $max; $i++) {
        for ($j = 1; $j <= $max; $j++) {
            for ($k = 1; $k <= $max; $k++) {
                $sum += gcd($i, gcd($j, $k));
            }
        }
    }

    out($sum);

    function gcd($m, $n) {
        if ($n > $m) {
            $tmp = $n;
            $n = $m;
            $n = $tmp;
        }
        while($n !== 0){
            $tmp = $n;
            $n = $m % $n;
            $m = $tmp;
        }
        return $m;
    }

    // -----------------------------------------------------
    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
$k = (int)trim(fgets(STDIN));

$list = [];
$sum = 0;
for ($i=1; $i <= $k; $i++) {
	for ($j=1; $j <= $k; $j++) {
		for ($m=1; $m <= $k; $m++) {
			$ary = [$i, $j, $m];
			$sum += gcd($i, gcd($j, $m));
		}
	}
}
echo $sum;

// 最大公約数（ユークリッドの互除法）
function gcd($n1, $n2){
	$large = max($n1, $n2);
	$small = min($n1, $n2);
	if ($small === 1) {
		return 1;
	}
	while($small !== 0){
		$tmp_n = $small;
		$small = $large % $small;
		$large = $tmp_n;
	}
	return $large;
}


Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


<?php
$num = trim(fgets(STDIN));
$array = str_split(trim(fgets(STDIN)));
$count = 0;
$array_r = [];
$array_g = [];
$array_b = [];
foreach($array as $id => $value) {
  if($value == 'R') {
    $array_r[$id+1] = $value;
  } else if ($value == 'G') {
    $array_g[$id+1] = $value;
  } else {
    $array_b[$id+1] = $value;
  }
}

$count_r = count($array_r);
$count_g = count($array_g);
$count_b = count($array_b);

if($count_r > $count_g) {
  $tmp = $array_r;
  $array_r = $array_g;
  $array_g = $tmp;
}
if($count_r > $count_b) {
  $tmp = $array_r;
  $array_r = $array_b;
  $array_b = $tmp;
}
if($count_g > $count_b) {
  $tmp = $array_g;
  $array_g = $array_b;
  $array_b = $tmp;
}

foreach($array_r as $id_r => $value_r) {
  foreach($array_g as $id_g => $value_g) {
    foreach($array_b as $id_b => $value_b) {
      if($id_r > $id_g) {
        $tmp = $id_r;
        $id_r = $id_g;
        $id_g = $tmp;
      }
      if($id_r > $id_b) {
        $tmp = $id_r;
        $id_r = $id_b;
        $id_b = $tmp;
      }
      if($id_g > $id_b) {
        $tmp = $id_g;
        $id_g = $id_b;
        $id_b = $tmp;
      }
      if($id_r+$id_b == $id_b*2) {continue;}
      $count++;
    }
  }
}
echo $count;


<?php

$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$s = str_split($s);

$r = [];
$g = [];
$b = [];

for ($i=1;$i<=$n;++$i) {
    $offset = $i-1;
    if ($s[$offset] === 'R') {
        $r[] = $i;
    } else if ($s[$offset] === 'G') {
        $g[] = $i;
    } else if ($s[$offset] === 'B') {
        $b[] = $i;
    }
}

$count = 0;
foreach ($r as $rv) {
    foreach ($g as $gv) {
        foreach ($b as $bv) {
            $array = [$rv, $gv , $bv];
            sort($array);
            if (($array[2] - $array[1]) !== ($array[1] - $array[0])) {
                ++$count;

            }
        }
    }
}
echo $count . PHP_EOL;


<?php
list($N) = ints();
$str = str();
$R[-1] = $G[-1] = $B[-1] = 0;
for($i = 0; $i < $N; $i++){
    $R[$i] = $R[$i-1];
    $G[$i] = $G[$i-1];
    $B[$i] = $B[$i-1];
    $c = $str[$i];
    $$c[$i]++;
}
$Rc = $R[$N-1];
$Gc = $G[$N-1];
$Bc = $B[$N-1];
$sum = 0;
for($i = 1; $i < $N-1; $i++){
    $c = $str[$i];
    if($c=="R"){$sum+=$G[$i-1]*($Bc-$B[$i])+$B[$i-1]*($Gc-$G[$i]);}
    if($c=="G"){$sum+=$R[$i-1]*($Bc-$B[$i])+$B[$i-1]*($Rc-$R[$i]);}
    if($c=="B"){$sum+=$G[$i-1]*($Rc-$R[$i])+$R[$i-1]*($Gc-$G[$i]);}
    for($j = 0; $j <= min($i, $N-$i-1); $j++){
        if($str[$i] != $str[$i-$j] && $str[$i] != $str[$i+$j] && $str[$i-$j]!=$str[$i+$j])$sum--;
    }
}
echo $sum;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
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)$N = $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;
}


Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


<?php
  list($x, $y, $z) = explode(' ', trim(fgets(STDIN)));
  echo $z . ' ' . $x . ' ' . $y;
?>


<?php
  list($x, $y, $z) = explode(' ', trim(fgets(STDIN)));
  echo $z . " " . $x . "" . $y;
?>


<?php
// Your code here!
    fscanf(STDIN,"%d %d %d",$a,$b,$c);
    // var_dump($a);
    $trima = $a;
    $a = $b;
    $b = $trima;
    // echo $a,$b,$c;
    $ti2 = $a;
    $a = $c;
    $c = $ti2;
    echo $a,' ',$b,' ',$c;
?>


<?php
$f = fopen( 'php://stdin', 'r' );
$line = fgets( $f );
$items = array_map('intval', explode(" ",$line));
$votes = array_map('intval', explode(" ",fgets($f)));
sort($votes);
if($votes[$items[0]-$items[1]]>=(1/(4*$items[1]))*array_sum($votes)){
	echo "Yes";
} else {
	echo "No";
}
?>


<?php
$f = fopen( 'php://stdin', 'r' );
$line = fgets( $f );
$items = array_map('intval', explode(" ",$line));
$votes = array_map('intval', explode(" ",fgets($f)));
$min = floor(1/(4*$items[0]))*array_sum($votes);
$count =0;
foreach($votes as $vote) {
	if($vote>$min){
      $count++;
    }
}
if($count>=$items[1]) {
	echo "Yes";
} else {
	echo "No";
}
?>


$f = fopen( 'php://stdin', 'r' );
$line = fgets( $f )
$numbers = array_map('intval', explode(" ",$line));
$result[0] = $numbers[2];
$result[1] = $numbers[0];
$result[3] = $numbers[1];
echo implode(" ",$result)


<?php
  $inputs = [];
  list($inputs[0], $inputs[1], $inputs[2]) = sscanf(fgets(STDIN), "%d %d %d");

  print("$inputs[2] $inputs[0] $inputs[1]");

?>


<?php

$box = explode(" ",fgets(STDIN));

$change = $box[0];
$box[0] = $box[1];
$box[1] = $change;

$change = $box[0];
$box[0] = $box[2];
$box[2] = $change;

echo "{$box[0]} {$box[1]} {$box[2]}";
 ?>


<?php
fscanf(STDIN, "%d %d %d", $X, $Y, $Z);
echo($Z);
echo(" ");
echo($X);
echo(" ");
echo($Y);

?>


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


<?php
$stdin = trim(fgets(STDIN));
$array = explode(' ', $stdin);

echo $array[2] . ' ' . $array[0] . ' ' . $array[1];


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


<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($X,$Y,$Z) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

list($X,$Y) =array($Y,$X);
list($X,$Z) = array($Z,$X);
printf("%d %d %d\n",$X,$Y,$Z);


<?php

  list($x, $y, $z) = explode(" ", trim(fgets(STDIN)));

  echo $z." ".$x." ".$y;


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

    $array_A = array_map('intval',explode(" ",trim(fgets(STDIN))));

    $sum = array_sum($array_A);

    $sum_quart = $sum/4;

    rsort($array_A);
    array_unshift($array_A,0);

    // var_dump($array_A);

    if($array_A[$M] < $sum_quart){
        echo "No";
    }else{
        echo "Yes";
    }

?>

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


<?php
list($item_count, $popular_item_count) = explode(' ', trim(fgets(STDIN)));
$array = explode(' ', trim(fgets(STDIN)));
// 得票数を降順に並べ替える
rsort($array);
// 全得票数を計算
$amount = 0;
foreach ($array as $num) {
  	var_dump($num);
    $amount += (int)$num;
}

$check = floor($amount / (4 * (int)$popular_item_count));
var_dump($amount);
$i = 0;
while ($i < (int)$popular_item_count) {
    if ((int)$array[$i] > (int)$check) {
        $output_array[] = $array[$i];
    }
    $i++;
}

if ((int)$popular_item_count === count($output_array)) {
    echo 'Yes';
} else {
    echo 'No';
}


<?php
$n = 0;
$m = 0;
fscanf(STDIN, '%u %u', $n, $m);
$input = fgets(STDIN);

$votes = explode(' ', trim($input));
$total_votes = array_sum($votes);
$min_votes = (float)$total_votes / (float)(4 * $m);
$popular = 0;
foreach ($votes as $vote) {
	if ($vote >= $min_votes) {
		$popular++;
	}
	if ($popular >= $m) {
		echo "Yes";
		exit;
	}
}
echo 'No';


<?php

list($n, $m) = explode(' ', fgets(STDIN));
$a = explode(' ', fgets(STDIN));
rsort($a);
$count = 0;
$sum = 0;
//総得票
  foreach ($a as $value) {
    // code...
    $sum += $value;
  }

for ($i=0; $i<$m ; $i++) {
  // code...
  if ($a[$i] >= $sum*1/(4*$m)) {
    // code...
    $count ++;

  }
}
if($count >= $m){
  echo 'Yes';
}else{
  echo 'No';
}


<?php
  list($n, $m) = sscanf(fgets(STDIN), "%d %d");
  $a = explode(" ", fgets(STDIN));
  rsort($a);
  $s = array_sum($a);
  if($a[$m-1] >= $s / (4*$m))
    print("Yes");
  else
    print("No");
?>


<?php
  fscanf(STDIN,"%d %d", $n, $m);
  $a = explode(" ",fgets(STDIN));
  $t = array_sum($a)/(4*$m);
  $count = 0;
  for ($i=0; $i<$n; $i++){
    if((int)$t <= $a[$i]){
      $count++;
    }
  }
  if ($count >= $m){
    echo "Yes\n";
  } else {
    echo "No\n";
  }

?>


<?php
  $items = 0;
  $pickups = 0;
  $total = 0;
  $border = 0;
  $input = "";
  $i = 0;

  list($items, $pickups) = sscanf(fgets(STDIN), "%d %d");
  $input = fgets(STDIN);
  $items = explode(" ", $input);
  $total = array_sum($items);
  $border = $total / (4*$pickups);

  rsort($items);

  for($i=0; $i<$pickups; $i++){
    if($items[$i] < $border){
      print("No");
      return ;
    }
  }
  print("Yes");

?>


<?php

list($n, $m) = explode(' ', fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$count = 0;
$sum = 0;
//総得票
  foreach ($a as $value) {
    // code...
    $sum += $value;
  }

for ($i=0; $i<$m ; $i++) {
  // code...
  if ($a[$i] >= floor($sum/ (4*$m))) {
    // code...
    $count ++;

  }
}
if($count >= $m){
  echo 'Yes';
}else{
  echo 'No';
}


<?php
  fscanf(STDIN,"%d %d",$n,$m);
  $a = explode(" ",fgets(STDIN));
  asort($a);
  $t = array_sum($a)/($m*4);
  if ($a[$m-1] > $t) {
    echo "Yes\n";
  } else {
    echo "No\n";
  }
?>


<?php
  $items = 0;
  $pickups = 0;
  $total = 0;
  $input = "";

  list($items, $pickups) = sscanf(fgets(STDIN), "%d %d");
  $input = fgets(STDIN);
  $items = explode(" ", $input);
  $total = array_sum($items);

  rsort($items);

  if($items[$pickups-1]>= $total / (4*$pickups))
    print("Yes");
  else
    print("No");

?>


<?php
// Your code here!
$insert1 = explode(" ",trim(fgets(STDIN)));
$N = $insert1[0];
$M = $insert1[1];
$insert2 = explode(" ",trim(fgets(STDIN)));

$sum = array_sum($insert2);
for($i=0; $i <= count($insert2)-1; $i++){
    if($insert2[$i] >= $sum / (4*$M)){
        $results[] = $insert2[$i];
    }
}

if(count($results) >= $M){
    echo "Yes".PHP_EOL;
}else{
    echo "No".PHP_EOL;
}


<?php
  fscanf(STDIN,"%d %d", $n, $m);
  $a = explode(" ",fgets(STDIN));
  $k = 4*$m;
  $t = array_sum($a)/$k;
  $count = 0;
  for ($i=0; $i<$n; $i++){
    if($t < $a[$i]){
      $count++;
    }
  }
  if ($count >= $m){
    echo "Yes\n";
  } else {
    echo "No\n";
  }

?>


<?php
  fscanf(STDIN,"%d %d", $n, $m);
  $a = explode(" ",fgets(STDIN));
  $t = array_sum($a)*$m/4;
  $count = 0;
  for ($i=0; $i<$n; $i++){
    if($t < $a[$i]){
      $count++;
    }
  }
  if ($count >= $m){
    echo "Yes\n";
  } else {
    echo "No\n";
  }

?>


<?php

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

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

 $match = 0;

 $need =  (4 * $M);
 $votes = 0;

 foreach($A as $num => $score){
 	$votes += $score;
 }

 $score = 0;
 $num = 0;

 foreach($A as $num => $score){
 	if($score < $score / $need){
 		continue;
 	}
 	$match++;
 }
 if($match >= $M){
 	printf("Yes");
 }else{
 	printf("No");
 }
 ?>


<?php
  fscanf(STDIN,"%d %d", $n, $m);
  $a = explode(" ",fgets(STDIN));
  $t = array_sum($a)/(4*$m);
  $count = 0;
  for ($i=0; $i<$n; $i++){
    if($t < $a[$i]){
      $count++;
    }
  }
  if ($count >= $m){
    echo "Yes\n";
  } else {
    echo "No\n";
  }

?>


<?php
$input = file_get_contents('php://stdin');
$inarr = explode("\n", $input);

$nmlist = explode(" ", $inarr[0]);
$aList = array_map("intval", explode(" ", $inarr[1]));

$n = (int)$nmlist[0];
$m = (int)$nmlist[1];

$sum = array_sum($aList);
$div = $sum/(4 * $m);

for($i=0;$i<$m;$i++){
    $select = max($aList);
    if($select<$div){
        echo "No"."\n";
        exit();
    }
    $aList = array_diff($aList, [$select]);
}
echo "Yes"."\n";

?>


$input_1 = trim(fgets(STDIN));
$m = explode(' ', $input_1)[1];

$input_2 = trim(fgets(STDIN));
$items = explode(' ', $input_2);

$total = array_sum($items);
$border = $total / (4 * $m);

rsort($items);

for ($i = 0; $i < $m; $i++) {
    if ($items[$i] < $border) {
        echo "No";
        exit();
    }
}

echo 'Yes';


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

$A_i = trim(fgets(STDIN));

$A_list = explode(" ",$A_i);

$count = 0;

$sum_A = 0;

for($i = 0; $i<$n; $i++){
    $sum_A +=  (int)$A_list[$i];
}

for($i = 0; $i<$n; $i++){
    if($A_list[$i] >= (1/(4*$m))*$sum_A ){
        $count ++;
    }
}

if($count >= $m){
    echo "Yes\n";
}else{
    echo "No\n";
}


<?php

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

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

 $match = 0;

 foreach($A as $votes){
 	if($votes >= $M / (4 * $M)){
 		$match++;
 	}
 }
 if($match >= $M){
 	printf("Yes");
 }else{
 	printf("No");
 }
 ?>


<?php

class scan {
    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 (double)$this->next();
    }
}

$sc = new scan();
$n = $sc->nextInt();
$m = $sc->nextInt();
$sum = 0;
for ($i=0;$i<$n;$i++) {
    $a[] = $sc->nextInt();
    $sum += $a[$i];
}

rsort($a);
if ($a[$m - 1] < (1/(4*$m)*$sum)) {
    echo "No";
} else {
    echo "Yes";
}


<?php
$stdin1 = trim(fgets(STDIN));
$array1 = explode(' ', $stdin1);
$select = $array1[1];
$stdin2 = trim(fgets(STDIN));
$array2 = explode(' ', $stdin2);
$sum = array_sum($array2);
$count = 0;

foreach ($array2 as $num) {
  if ($sum * (1/$select*4) < $num) {
    continue;
  }
  $count++;
}

if ($count >= $select) {
  echo 'Yes';
} else {
  echo 'No';
}


<?php
$stdin1 = trim(fgets(STDIN));
$array1 = explode(' ', $stdin1);
$select = $array1[1];
$stdin2 = trim(fgets(STDIN));
$array2 = explode(' ', $stdin2);
$sum = array_sum($array2);
$count = 0;

foreach ($array2 as $num) {
  if ($sum * (1/$select*4) > $num) {
    continue;
  }
  $count++;
}

if ($count > $select) {
  echo 'Yes';
} else {
  echo 'No';
}


?php

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

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

 $match = 0;

 foreach($A as $votes){
 	if($votes >= floor ($votes / (4 * $M)){
 		$match++;
 	}
 }
 if($match >= $M){
 	printf("Yes");
 }else{
 	printf("No");
 }
 ?>


<?php

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

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

  $sum = array_sum($a);

  $x=0;
  for($i=0;$i<$n;$i++){
    if(1/(4*$m) <= $a[$i]/$sum){
       $x++;
    }
  }

  if($m <= $x){
    echo "Yes";
  }else{
    echo "No";
  }


<?php
list($X, $Y, $A, $B ,$C) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$red = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($red);
$red = array_slice($red, 0, $X);

$green = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($green);
$green = array_slice($green, 0, $Y);

$white = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));
rsort($white);

$apples = array_merge($red, $green, $white);
rsort($apples);

echo array_sum(array_slice($apples, 0, $X + $Y));

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


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

  $p = explode(" ", trim(fgets(STDIN)));
  $q = explode(" ", trim(fgets(STDIN)));
  $r = explode(" ", trim(fgets(STDIN)));

  rsort($p);
  rsort($q);
  rsort($r);

  $f = array_slice($p,0,$x);
  for($i=0;$i<$y;$i++){
    $f[] = $q[$i];
  }

  sort($f);

  for($i=0;$i<$c;$i++){
    if($r[$i]>$f[$i]){
      $f[$i]=$r[$i];
    }
  }
  echo array_sum($f);


<?php

    // AtCoder Beginner Contest 160
    // E - Red and Green Apples

    list(
        $count_eat_red,
        $count_eat_green,
        $count_red,
        $count_green,
        $count_colorless
    ) = in_ints();
    $red = in_ints();
    $green = in_ints();
    $colorless = in_ints();

    rsort($red);
    rsort($green);
    rsort($colorless);

    $umai = 0;
    $r = 0;
    $g = 0;
    $c = 0;
    while ($count_eat_red > 0 || $count_eat_green > 0) {
        if ($count_eat_red > 0 && $count_eat_green > 0) { // 赤緑どちらでも食べられる場合
            if ($red[$r] >= $green[$g] && $red[$r] >= @$colorless[$c]) {
                $umai += $red[$r];
                $r++;
                $count_eat_red--;
                continue;
            }
            if ($green[$g] >= $red[$r] && $green[$g] >= @$colorless[$c]) {
                $umai += $green[$g];
                $g++;
                $count_eat_green--;
                continue;
            }
            $umai += $colorless[$c];
            $c++;
            if ($red[$r] <= $green[$g]) {
                $count_eat_red--;
            } else {
                $count_eat_green--;
            }
        } else if ($count_eat_red > 0) { // 赤しか食べられない場合
            if ($red[$r] >= @$colorless[$c]) {
                $umai += $red[$r];
                $r++;
            } else {
                $umai += $colorless[$c];
                $c++;
            }
            $count_eat_red--;
        } else { // 緑しか食べられない場合
            if ($green[$g] >= @$colorless[$c]) {
                $umai += $green[$g];
                $g++;
            } else {
                $umai += $colorless[$c];
                $c++;
            }
            $count_eat_green--;
        }
    }

    out($umai);

    /**
    * お手伝い関数さんたち
    */
    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
list($a, $b, $c) = ints();
$a = (float) $a;
$b = (float) $b;
$c = (float) $c;
echo 4 * $a * $b < ($c - $a - $b) ** 2 ? 'Yes' : 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


<?php

    $shiki = fgets(STDIN);

    $shiki_list = explode(" ",$shiki);

    $a = $shiki_list[0];
    $b = $shiki_list[1];
    $c = $shiki_list[2];

    if(4<(($c-$a-$b)**2)/($a*$b)){
        echo "Yes\n";
    }else{
        echo "No\n";
    }


<?php
  fscanf(STDIN,"%d %d %d", $a, $b, $c);
  $a = sqrt($a);
  $b = sqrt($b);
  $c = sqrt($c);
  if ($a*$a + 2*$a*$b + $b*$b < $c*$c){
    echo "Yes\n";
  } else {
    echo "No\n";
  }


<?php
  fscanf(STDIN,"%d %d %d", $a, $b, $c);
  if ($a*$a + 2*$a*$b + $b*$b < $c*$c){
    echo "Yes\n";
  } else {
    echo "No\n";
  }


<?php
  $a = intval($argv[1]); $b = intval($argv[2]); $c = intval($argv[3]);

  if(c-a-b < 0)
    print("No");
  else{
    if((c-a-b)*(c-a-b) > 4ab)
      print("Yes");
    else
      print("No");
  }
?>


<?php
  list($a, $b, $c) = sscanf(fgets(STDIN), "%d %d %d");

  if(sqrt($a) + sqrt($b) < sqrt($c) )
    print("Yes");
  else
    print("No");

  return ;
?>


<?php
list($A,$B,$C)=sscanf(trim(fgets(STDIN)),"%d %d %d");

if(((real)sqrt($A) + (real)sqrt($B))< (real)sqrt($C)){
    printf("Yes");
}else{
    printf("No");
}


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

  $n = $c-($a+$b);

  if($n<0){
    echo "No";
  }

  if(4*$a*$b < $n*$n){
    echo "Yes";
  }else{
    echo "No";
  }


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

  if(4*$a*$b < pow(($c-($a+$b)), 2)){
    echo "Yes";
  }else{
    echo "No";
  }


<?php

    list($a, $b, $c) = in_ints();

    $a = sqrt($a);
    $b = sqrt($b);
    $c = sqrt($c);

    while( is_not_int($a) || is_not_int($b) || is_not_int($c)) {
        $a *= 10;
        $b *= 10;
        $c *= 10;
    }
    $a = (int)$a;
    $b = (int)$b;
    $c = (int)$c;
    if ($a + $b < $c) {
        yes();
    } else {
        no();
    }

    function is_not_int($f) {
        $wk = explode('.', strval($f));
        return @$wk[1] != 0;
    }

    /**
    * お手伝い関数さんたち
    */
    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

    list($a, $b, $c) = in_ints();

    $a = sqrt($a);
    $b = sqrt($b);
    $c = sqrt($c);

    while( ! is_int($a) || ! is_int($b) || ! is_int($c)) {
        $a *= 10;
        $b *= 10;
        $c *= 10;
    }
    $a = (int)$a;
    $b = (int)$b;
    $c = (int)$c;
    if ($a + $b < $c) {
        yes();
    } else {
        no();
    }

    function is_int($f) {
        $wk = explode('.', strval($f));
        return @$wk[1] == 0;
    }

    /**
    * お手伝い関数さんたち
    */
    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
  list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));

  if($a*$b*4 < ($c-$a-$b)*($c-$a-$b)){
    echo "Yes";
  }else{
    echo "No";
  }


<?php

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

$temp = intdiv(pow(($c - $a - $b) ,2)+3 ,4);
if($a * $b < $temp){
    echo "Yes";
}else{
    echo "No";
}


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

$sc = sqrt($c);
$sb = sqrt($b);
$sa = sqrt($a);

  if($sa + $sb < $sc){
    if($sc - $sb - $sa < 0.0000001){
      echo "No";
    }else{
      echo "Yes";
    }
  }else{
    echo "No";
  }


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

if((sqrt($a) + sqrt($b)) < sqrt($c)){
	echo "Yes";
}else{
	echo "No";
}
?>


<?php

    list($a, $b, $c) = in_ints();

    if (add_float(sqrt($a), sqrt($b)) < sqrt($c)) {
        yes();
    } else {
        no();
    }

    function add_float($a, $b) {
        $a = strval($a);
        $b = strval($b);

        $a = explode('.', $a);
        $b = explode('.', $b);

        $left = (int)$a[0] + (int)$b[0];

        $idx = 0;
        $a_right = str_split($a[1]);
        $b_right = str_split($b[1]);
        if (count($a_right) > count($b_right)) {
            $idx = count($a_right) - 1;
        } else {
            $idx = count($b_right) - 1;
        }

        $right = [];
        $carry = false;
        while ($idx >= 0) {
            $sum = (int)@$a_right[$idx] + (int)@$b_right[$idx];
            if ($carry) {
                $sum++;
            }
            $carry = false;
            if ($sum >= 10) {
                $sum -= 10;
                $carry = true;
            }
            $right[$idx] = strval($sum);
            $idx--;
        }
        if ($carry) {
            $left++;
        }

        return (float)($left . '.' . implode('', $right));
    }

    /**
    * お手伝い関数さんたち
    */
    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
list($A,$B,$C)=sscanf(trim(fgets(STDIN)),"%d %d %d");

if((sqrt($A) +sqrt($B) )< sqrt($C)){
    printf("Yes");
}else{
    printf("No");
}


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

if (sqrt($a) + sqrt($b) < sqrt($c)) {
  echo 'Yes';
} else {
  echo 'No';
}


<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d %d", $a, $b, $c);
if (bcsqrt(a, 100) + bcsqrt(b, 100) < bcsqrt(c, 100)) {
  echo "Yes\n";
} else {
  echo "No\n";
}
?>


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

$a = (int)$input[0];
$b = (int)$input[1];
$c = (int)$input[2];

if ($c - $a - $b > 2 * sqrt($a) * sqrt($b)) {
	echo 'Yes';
} else {
	echo 'No';
}


<?php
list($a, $b, $c) = ints();
echo ($c-$a-$b)*($c-$a-$b)-4*$a*$b>0 ? "Yes": "No";

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
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 o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo 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++){
        $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++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


<?php
list($a, $b, $c) = ints();
echo ($c-$a-$b)**2-4*$a*$b>0 ? "Yes": "No";

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
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 o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo 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++){
        $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++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


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

$a = (int)$input[0];
$b = (int)$input[1];
$c = (int)$input[2];

if (sqrt($a) + sqrt($b) < sqrt($c)) {
	echo 'Yes';
} else {
	echo 'No';
}


<?php

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

    for($i=0;$i<$M;$i++){
        $array[$i] = array_map('intval',explode(" ",trim(fgets(STDIN))));
    }
    //2桁以上の数字の場合の最上位の桁が0である場合を排除する。
    if($N>=2){
        for($i=0;$i<$M;$i++){
            if(($array[$i][0] == 1) && ($array[$i][1]==0)){
                echo "-1";
                exit;
            }
        }
    }

    //同じ行を指定して異なる値を指定している場合は無効
    for($i=0;$i<$M-1;$i++){
        for($j=$i+1;$j<$M;$j++){
            //情報の1番目が同じで2番目の値が異なる場合あり得ない
            if(($array[$i][0] == $array[$j][0]) && ($array[$i][1] != $array[$j][1])){
                echo "-1";
                exit;
            }
        }
    }

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

    // var_dump($ans);

    for($x=1;$x<=3;$x++){
        if(empty($ans[$x])){
            echo "0";
        }else{
            echo $ans[$x];
        }
    }

?>

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


<?php
  fscanf(STDIN,"%d%d",$n, $m);
  $ans = [];
  if($n == 1){
      if($m){
          fscanf(STDIN,"%d%d",$s, $c);
          echo $c;
      }else{
          echo "-1";
      }
  }else {
      $flag =false;
      if($m > 0){
          for($i=0; $i<$m; $i++){
              fscanf(STDIN,"%d%d",$s, $c);
              if($s == $n){
                  $flag = true;
              }
              $ans[$s-1][] = $c;
          }
          if($flag){
              for($i=0; $i<$n; $i++){
                  if(!isset($ans[$i])) echo "0";
                  else echo min($ans[$i]);
              }
          }else{
              echo "-1";
          }
      }else{
          echo "-1";
      }
  }


<?php
    $arr = explode(' ', trim(fgets(STDIN)));
    $n =$arr[0];
    $m =$arr[1];

    $out =[];
    for ($i=0; $i < $m ; $i++) {
        $arr = explode(' ', trim(fgets(STDIN)));
        $s = $arr[0] - 1;
        $c = $arr[1];
        // すでに設定されている桁で
        // かつ違う数字の場合はNG
        if (isset($out[$s]) && $out[$s] != $c) {
            echo '-1';
            return;
        }

        $out[$s] = $c;
    }

    // 頭が0はだめ
    $set_flg_1 = false;
    $set_flg_2 = false;
    if (isset($out[0])){
        if($out[0] == 0) {
            echo '-1';
            return;
        }
        $set_flg_1 = true;
    }
    if (isset($out[1])){
        if (!$set_flg_1 && $out[1] == 0) {
            echo '-1';
            return;
        }
        $set_flg_2 = true;
    } else {
        if ($set_flg_1) {
            $out[1] = 0;
            $set_flg_2 = true;
        }
    }
    if (isset($out[2])){
        if (!$set_flg_2 && $out[2] == 0) {
            echo '-1';
            return;
        }
    } else {
        if ($set_flg_2) {
            $out[2] = 0;
        }
    }

    $ret = 0;
    if ($set_flg_1) {
        $ret = $ret + ($out[0] * 100);
    }
    if ($set_flg_2) {
        $ret = $ret + ($out[1] * 10);
    }
    $ret = $ret + $out[2];

    echo $ret;
    return;
?>


<?php
fscanf(STDIN, "%d %d", $N, $M);
$arr = array();
for ($m=0; $m<$M; $m++){
    fscanf(STDIN, "%d %d", $s, $c);
    $arr[] = array($s, $c);
}

$isIncluded = FALSE;
for ($n=0;$n<1000;$n++){
    if (strlen(strval($n)) == $N){
        foreach ($arr as $item){
            if (strval($n)[$item[0]-1] == $item[1]){
                $isIncluded = TRUE;
                /*echo strval($n) . "\t" . $item[0] . "\t" . $item[1];
                echo "\n";*/
            } else {
                $isIncluded = FALSE;
                break;
            }
        }
        if ($isIncluded){
            //echo "Yes\n";
            echo $n;
            die();
        }
    }
}
echo -1;


<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, '-');

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        if ($ans[$index] != '-' && $ans[$index] != $num) {
            echo -1;
            exit;
        }
        $ans[$index] = $num;
    }
}
#var_dump($ans);
if ($n > 1 && $ans[0] == 0) {
    echo -1;
    exit;
}

if ($n > 1 && $ans[0] == '-') $ans[0] = 1;
$ans = str_replace('-', '0',$ans);

$x = intval(join('', $ans));
#var_dump($x);
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}


<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, '-');

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        if ($ans[$index] != '-' && $ans[$index] != $num) {
            echo -1;
            exit;
        }
        $ans[$index] = $num;
    }
}
#var_dump($ans);

if ($n > 1 && $ans[0] == '-') $ans[0] = 1;
$ans = str_replace('-', '0',$ans);

$x = intval(join('', $ans));
#var_dump($x);
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}


<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, '*');

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        if ($ans[$index] != '*' && $ans[$index] != $num) {
            echo -1;
            exit;
        }
        $ans[$index] = $num;
    }
}
#var_dump($ans);

if ($n > 1 && $ans[0] == '*') $ans[0] = 1;

$x = intval(str_replace('*', '0', join('', $ans)));
#var_dump($x);
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}


<?php
  $NM = explode(' ', trim(fgets(STDIN)));
  $N = $NM[0];
  $M = $NM[1];

  $out = [];
  for ($i = 0; $i < $N; $i++) {
    array_push($out, null);
  }

  // 入力チェック・保持: 同じ桁に対する指定、先頭1桁が0でないか
  for ($i = 0; $i < $M; $i++) {
    $tmp = trim(fgets(STDIN));
    $sc = explode(' ', $tmp);
    $s = $sc[0] - 1;
    $c = $sc[1];

    if (!(is_null($out[$s]) || $out[$s] === $c)) {
      echo '-1';
      return;
    }
    if (($N > 1 && $tmp === '1 0')) {
      echo '-1';
      return;
    }
    $out[$s] = $c;
  }
  // 整形: 不定桁の切り捨て、0埋め、先頭0の場合は1追加
  $isNullTo0 = false;
  for ($i = 0; $i < $N; $i++) {
    if (!$isNullTo0) {
      $isNullTo0 = !is_null($out[$i]);
//      if ($i > 1 && $out[$i] === '0') {
//        $out[$i-1] = '1';
//      }
      continue;
    }

    $out[$i] = is_null($out[$i]) ? 0 : $out[$i];
  }

  echo implode('', $out) . PHP_EOL;


<?php

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

while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}
foreach ($tmp as $key => $value) {
  $array[] = explode(" ", $value);
}

for($i=1;$i<=$m;$i++){
	$items[$i] = '';
}
$items = array();
$flg = false;
for($i=0;$i<$m;$i++){
  	if($items[$array[$i][0]]){
      if($items[$array[$i][0]] == $array[$i][1]){
      }else{
        $flg=true;
      	break;
      }
    }
	$items[$array[$i][0]] = $array[$i][1];
}
if($flg){
  echo -1;
}else{
	for($i=1;$i<=$n;$i++){
    	if($items[$i]){
          	echo $items[$i];
        }else{
        	echo 0;
        }
    }
}


<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, 0);

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        if ($ans[$index] != 0 && $ans[$index] != $num) {
            echo -1;
            exit;
        }
        $ans[$index] = $num;
    }
}
#var_dump($ans);
$x = intval(join('', $ans));
#echo $x;
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}


<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, 0);

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        $ans[$index] = $num;
    }
}
#var_dump($ans);
$x = intval(join('', $ans));
#echo $x;
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}


<?php

$nm = explode(" ", fgets(STDIN));

$arr = array_pad([], $nm[0], 0);

for ($i = 0; $i < $nm[1]; $i++) {
    $kv = explode(" ", fgets(STDIN));
    $idx = intval($kv[0]) - 1;
    if ($arr[$idx] != 0 && $kv[1] != $arr[$idx]) {
        echo "-1";
        return;
    }
    if ($idx == 0 && intval($kv[1]) == 0) {
        echo "-1";
        return;
    }
    $arr[$idx] = intval($kv[1]);
}

if ($arr[0] == 0) $arr[0] = 1;

echo join("", $arr);


<?php
list($N, $K) = ints();
$A = ints();
$mi = $pl = [];
$zero = 0;
foreach($A as $a){
  if($a < 0){
    $mi[] = $a;
  }elseif($a > 0){
    $pl[] = $a;
  }else{
    $zero++;
  }
}
$minusCount = count($mi)*count($pl);
$zeroCount = $zero*(count($pl)+count($mi)) + intdiv($zero*($zero-1), 2);
rsort($mi);
sort($pl);
$micount = count($mi);
$plcount = count($pl);

$min = (int)-10**18;
$max = (int)10**18;
while($max>$min){
  $mid = $min + intdiv($max-$min+1,2);
  if(countLT($mid)>=$K){
    $max = $mid-1;
  }else{
    $min = $mid;
  }
}
echo $min;

function countLT($t){
  global $mi, $pl, $zero, $minusCount, $zeroCount, $micount,$plcount;
  if($t==0){
    return $minusCount;
  }elseif($t > 0){
    $count = $minusCount + $zeroCount;
    //pl*pl
    $i = $plcount-1;
    foreach($pl as $j => $p){
      while(($pl[$i]??0) * $p >= $t)--$i;
      if($i > $j)$count+=$i-$j;
    }
    //mi*mi
    $i = $micount-1;
    foreach($mi as $j => $m){
      while(($mi[$i]??0) * $m >= $t)--$i;
      if($i > $j)$count+=$i-$j;
    }
  }else{
    $count = ($micount-1) * $plcount;
    $i = $micount-1;
    foreach($pl as $p){
      while(($mi[$i]??0) * $p < $t)$i--;
      $count-=$i;
    }
  }
  return $count;
}

function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}

Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

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

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064


<?php
fscanf(STDIN, "%d %d", $n, $k);
$a_number = explode(' ', trim(fgets(STDIN)));
$a_multi = array();
for($i = 0; $i < $n - 1; ++$i){
	$a_multi[$i] = array();
	for($h = $i + 1; $h < $n; ++$h){
		$a_multi[$i][] = $a_number[$i] * $a_number[$h];
	}
}

$ans = $a_multi[0][0];
array_shift($a_multi[0]);
--$k;
while($k-- > 0){
	if(count($a_multi) > 1){
		if($a_multi[0][0] <= $a_multi[1][0]){
			$ans = $a_multi[0][0];
			array_shift($a_multi[0]);
			continue;
		}else{
			$ans = $a_multi[1][0];
			array_shift($a_multi[1]);
			continue;
		}
	}else{
		if(count($a_multi[0]) > 1){
			$ans = $a_multi[0][0];
			array_shift($a_multi[0]);
			continue;
		}else{
			$ans =  $a_multi[0][0];
			break;
		}
	}
}

echo $ans;
?>


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

$n = (int)$input[0];
$k = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));
$plus  = [];
$minus = [];
$zero  = [];
foreach ($input as $v) {
	$v = (int)$v;
	if ($v == 0) {
		$zero[] = $v;
	} elseif ($v > 0) {
		$plus[] = $v;
	} else {
		$minus[] = $v;
	}
}

// マイナスの数
$total_minus = count($minus) * count($plus);
// ゼロの数
$total_zero  = count($zero) * (count($plus) + count($minus)) + (int)floor(count($zero) * (count($zero) - 1) / 2);
// プラスの数
$total_plus  = (int)floor(count($plus) * (count($plus) - 1) / 2) + (int)floor(count($minus) * (count($minus) - 1) / 2);

if ($total_minus >= $k) {
	$all = [];
	sort($minus);
	rsort($plus);
	foreach ($minus as $m) {
		foreach ($plus as $p) {
			$all[] = $m * $p;
		}
	}
	sort($all);
	echo $all[$k-1];
} elseif ($total_minus + $total_zero >= $k) {
	echo '0';
} else {
	$all = [];
	for ($i=0; $i < count($minus); $i++) {
		for ($j=$i+1; $j < count($minus); $j++) {
			$all[] = $minus[$i] * $minus[$j];
		}
	}
	for ($i=0; $i < count($plus); $i++) {
		for ($j=$i+1; $j < count($plus); $j++) {
			$all[] = $plus[$i] * $plus[$j];
		}
	}
	sort($all);
	echo $all[$k - $total_minus - $total_zero - 1];
}


<?php
fscanf(STDIN, '%d %d', $n, $k);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));

function pair_multipl($array, $results = []) {
  if (count($array) == 1) {
    return $results;
  }
  for ($i=1; $i<count($array); $i++) {
    $temp[] = $array[0] * $array[$i];
    $next_array[] = $array[$i];
  }
  return pair_multipl($next_array, array_merge($results, $temp));
}

$result_array = pair_multipl($exploded_numbers);
sort($result_array);
echo $result_array[$k-1];


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

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

Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

1 \leq A \leq 20

1 \leq B \leq 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.

Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.

Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

Sample Input 3

9 9

Sample Output 3

81


<?php

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

$a = (int)$array[0];
$b = (int)$array[1];

if ($a > 9 || $b > 9) {
    echo -1;
} else {
    echo $a * $b;
}


<?php
$input = fgets(STDIN);
$input = explode(' ', $input);
$A = $input[0];
$B = $input[1];

if (($A<10)and($B<10)){
    print $A*$B;
}else {
    print -1;
}
?>


<?php

//整数の入力
fscanf(STDIN,"%d　%d",$a,$b);

//1以上9以下の整数の積を計算
if ($a <= 9 && $b <= 9){
    echo $a*$b;
}else{
    echo '-1';
}


<?php
$stdin = (int)trim(fgets(STDIN));
for($i=1;$i<9;$i++){
	for($j=1;$j<9;$j++){
		if($i*$j == $stdin){
			print 'Yes';
			exit;
		}
	}
}
print 'No';


<?php
$stdin = trim(fgets(STDIN));
$moji = explode(' ', $stdin);
if((int)$moji[0] >= 1 && (int)$moji[0] <= 9 && (int)$moji[1] >= 1 && (int)$moji[1] <= 9){
	print (int)$moji[0] * (int)$moji[1];
} else {
	print -1;
}


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

if($contents[0] < 10 && $contents[1] ) {
echo   $result = $contents[0] * $contents[1];
}


<?php
list($s) = strs();
$n = strlen($s);
list($k) = ints();
$a = substr_info($s);
$cnt = 0;
foreach ($a as $i => list($v, $c)) {
    if ($i === count($a) - 1 && $s[0] === $s[$n - 1])
        $cnt += intdiv($c + 1, 2) * ($k - 1) + intdiv($c, 2);
    else $cnt += intdiv($c, 2) * $k;
}
echo $cnt;
// 文字列の要素と連続数を格納した配列を返す
function substr_info(string $s): array
{
    $n = strlen($s);
    $cnt = 0;
    for ($i = 0; $i < $n; $i++) {
        $cnt++;
        if ($i === $n - 1 || $s[$i] !== $s[$i + 1]) {
            $_s[] = [$s[$i], $cnt];
            $cnt = 0;
        }
    }
    return $_s;
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}

Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997


<?php
$str = str();
$n = int();
$p = $str[0];
$count = 1;
for($i = 1; $i < strlen($str); $i++){
  if($str[$i] != $str[$i-1]){
    $numArray[] = $count;
    $count = 0;
  }
  $count++;
}
if($count != 0){
  $numArray[] = $count;
}
if(count($numArray) == 1){
  echo floor(strlen($str) * $n / 2);
}elseif($str[0] == $str[-1]){
  $sum = 0;
  foreach($numArray as $num){
    $sum+=floor($num/2);
  }
  $l = $numArray[0];
  $r = $numArray[count($numArray)-1];
  $diff = floor(($r+$l)/2) - floor($l/2) - floor($r/2);
  echo $sum * $n + $diff * ($n-1);
}else{
  $sum = 0;
  foreach($numArray as $num){
    $sum+=floor($num/2);
  }
  echo $sum * $n;
}

function str(){
  return trim(fgets(STDIN));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}


<?php

$string = trim(fgets(STDIN));
$repeat_count = trim(fgets(STDIN));

$arr = [];
$count = 0;
for ($i = 0; $i < mb_strlen($string) - 1; $i++) {
    $current_char = $string[$i];
    $next_char = $string[$i + 1];

    if ($current_char === $next_char) {
        $arr[$current_char] += 1;
    } else {
        $count += floor(($arr[$current_char] + 1) / 2);
        $arr[$current_char] = 0;
    }
}

$first_char = $string[0];
$last_char = $string[mb_strlen($string) - 1];

if (count($arr) === 1) {
    $count += floor(($arr[$first_char] + 1) / 2);
} else if ($first_char === $last_char) {
    $count += 1;
}

echo $count * $repeat_count;


<?php

$string = trim(fgets(STDIN));
$repeat_count = trim(fgets(STDIN));

$arr = [];
$count = 0;
for ($i = 0; $i < mb_strlen($string) - 1; $i++) {
    $current_char = $string[$i];
    $next_char = $string[$i + 1];

    if ($current_char === $next_char) {
        $arr[$current_char] += 1;
    } else {
        $count += floor(($arr[$current_char] + 1) / 2);
        $arr[$current_char] = 0;
    }
}

$first_char = $string[0];
$last_char = $string[mb_strlen($string) - 1];

echo $last_char . PHP_EOL;

// 全部同じ文字
if (count($arr) === 1) {
    $count += floor(($arr[$first_char] + 1) / 2);
} else if ($first_char === $last_char) {
    $count += 1;
}

echo $count * $repeat_count;


<?php

$string = fgets(STDIN);
$repeat_count = fgets(STDIN);

$arr = [];
$count = 0;
for ($i = 0; $i < mb_strlen($string) - 1; $i++) {
    $current_char = $string[$i];
    $next_char = $string[$i + 1];

    if ($current_char === $next_char) {
        $arr[$current_char] += 1;
    } else {
        $count += floor(($arr[$current_char] + 1) / 2);
        $arr[$current_char] = 0;
    }
}

$first_char = $string[0];
$last_char = $string[mb_strlen($string) - 1];

echo $last_char . PHP_EOL;

// 全部同じ文字
if (count($arr) === 1) {
    $count += floor(($arr[$first_char] + 1) / 2);
} else if ($first_char === $last_char) {
    $count += 1;
}

echo $count * $repeat_count;


<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
$K = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));
$len=strlen($S);
if ($len == 1) {
printf("%d\n",intval($K/2));
exit;
}
$rep=0;
for($i=1;$i<$len;$i++) {
  if ($S[$i-1]==$S[$i]) {
    $S[$i]='*';
    $rep++;
  }
}
if ($S[0]==$S[$len-1]) {
  printf("%d\n",$rep+($rep+1)*($K-1));
}
else {
  printf("%d\n",$rep*$K);
}


<?php

function fget_array($dlmt = null) {
    $input = trim(fgets(STDIN));
    return $dlmt ? explode($dlmt, $input) : str_split($input);
}

$s = fget_array();
$k = fget_array(' ')[0];

$limit = count($s) - 1;
$cnt = 0;
$all = true;
for ($i = 0, $c = $s[0]; $i < $limit; $i++) {
    $next = $s[$i + 1];
    if ($s[$i] !== $next) $all = false;
    if ($next === $c) {
        $cnt++;
        $c = '';
    } else {
        $c = $next;
    }
}

$offset = 0;
if ($limit > 1 && $s[0] === $s[$limit]) {
    if (empty(in_array($s[0], [$s[1], $s[$limit - 1]]))) $offset = $k - 1;
    if ($all) $offset++;
}

echo $cnt * $k + $offset;
?>


<?php

function fget_array($dlmt = null) {
    $input = trim(fgets(STDIN));
    return $dlmt ? explode($dlmt, $input) : str_split($input);
}

$s = fget_array();
$s = array_merge($s, $s);
$k = fget_array(' ')[0];

$limit = count($s) - 1;
$cnt = 0;
for ($i = 0, $c = $s[0]; $i < $limit; $i++) {
    $next = $s[$i + 1];
    if ($next === $c) {
        $cnt++;
        $c = '';
    } else {
        $c = $next;
    }
}

echo ceil($cnt * $k / 2);
?>


<?PHP
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $K);

$str = str_split($S);
$key="";
$cnt=0;
foreach($str as $v){
  if($key==$v){
    $cnt++;
    $key="";
  }else{
    $key=$v;
  }
}
$cnt *= $K;

if($K>1){
  if(count($str)==1){
    $cnt=floor($K/2);
  }elseif($key==$str[0]){
    $cnt += $K-1;
  }
}
echo $cnt;


<?php

  $test = fgets(STDIN);
  $test =str_replace(PHP_EOL, '', $test);
  $num = (int)fgets(STDIN);
  $count = 0;
  $arr = str_split($test);
  $arr_size =  count($arr);
  for($i =0; $i < $arr_size; $i++){
     if ($i !== 0){
        if($arr[$i] == $arr[$i -1] ){
			$arr[$i] = "0";
       		$count++;
       }
     }
   }
    echo $count * $num;

  ?>


<?php
# get a integer
fscanf(STDIN, "%s", $s);
# get two integers separated with half-width break
fscanf(STDIN, "%d", $k);

$parts = [];
$n = strlen($s);

$part = '';
$new = true;
for ($i=0; $i < $n ; $i++) {
	if($i==0){
		$part = $s[$i];
	}else{
		if($s[$i]==$s[$i-1]){
			$part .= $s[$i];
		}else{
			$parts[] = $part;
			$part = $s[$i];
		}
	}
}
if($part !='')
	$parts[] = $part;

$ans = 0;

$p = count($parts);

if($p>1)
{
	if($s[0]!=$s[$n-1]){
		foreach ($parts as $i => $part) {
			$ans += $k*onePiece($part);
		}

	}else{
		foreach ($parts as $i => $part) {
			if($i!=0 && $i!=$p-1){
				$ans += $k*onePiece($part);
			}
		}
		$ss = $parts[$p-1].$parts[0];
		$ans += onePiece($ss,$k-1);

		$ans+=onePiece($parts[0]);
		$ans+=onePiece($parts[$p-1]);

	}
}else{
	$ans = onePiece($parts[0],$k);
	//$ans += strlen($parts[0])==1?($k-1):($k*(intval((strlen($parts[0])+1)/2)));
}

function onePiece($s,$k=1){
	$n = strlen($s)*$k;

	$ans =0 ;
	switch ($n) {
		case 0:
		case 1:
			$ans = 0;
		break;
		default:
			$ans = intval($n/2);
	}
	return  $ans;
}

# output
echo $ans;


<?PHP
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $K);

$str = str_split($S);
$key="";
$cnt=0;
foreach($str as $v){
  if($key==$v){
    $cnt++;
    $key="";
  }else{
    $key=$v;
  }
}
$cnt *= $K;
if(count($str)>2){
  if(($str[count($str)-2]<>$str[count($str)-1]) and ($str[count($str)-1]==$str[0])){
    $cnt++;
  }
}else{
  $cnt=floor($K/2);
}
echo $cnt;


<?php

function fget_array($dlmt = null) {
    $input = trim(fgets(STDIN));
    return $dlmt ? explode($dlmt, $input) : str_split($input);
}

$s = fget_array();
$k = fget_array(' ')[0];

$prev = '';
$cnt = 0;
foreach ($s as $c) {
    if ($prev === $c) {
        $cnt++;
        $prev = '';
    } else {
        $prev = $c;
    }
}
echo $cnt * $k;
?>


<?php
  $s = trim(fgets(STDIN));
  $k = trim(fgets(STDIN));

  $str_array = str_split($s);
  $cnt = count($str_array);
  $num = 0;
  $is_change = false;
  for($i = 1; $i < $cnt; $i++) {
    if ($str_array[$i] === $str_array[$i - 1] && !$is_change) {
      $num += 1;
      $is_change = true;
    } else {
      $is_change = false;
    }
  }
  echo $num * $k . PHP_EOL;


<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
$K = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

$rep=0;
for($i=1;$i<strlen($S);$i++) {
  if ($S[$i-1]==$S[$i]) {
    $S[$i]='*';
    $rep++;
  }
}
printf("%d\n",$rep*$K);


<?php
fscanf(STDIN, "%d %d", $n, $m);
$a = explode(" ",fgets(STDIN));
$queue = new SplPriorityQueue();
for($i=0; $i<$n; $i++) {
    $queue->insert($a[$i], $a[$i]);
}
while($m) {
    $max = $queue->extract();
    $max = $max/2;
    $queue->insert($max, $max);
    $m--;
}
$count = $queue->count();
$ans = 0;
for($i=0; $i<$count; $i++) {
    $ans += (int)floor($queue->extract());
}
echo $ans;

Score : 400 points

Problem Statement

Takahashi is going to buy N items one by one.

The price of the i-th item he buys is A_i yen (the currency of Japan).

He has M discount tickets, and he can use any number of them when buying an item.

If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen.

What is the minimum amount of money required to buy all the items?

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the minimum amount of money required to buy all the items.

Sample Input 1

3 3
2 13 8

Sample Output 1

9

We can buy all the items for 9 yen, as follows:

Buy the 1-st item for 2 yen without tickets.

Buy the 2-nd item for 3 yen with 2 tickets.

Buy the 3-rd item for 4 yen with 1 ticket.

Sample Input 2

4 4
1 9 3 5

Sample Output 2

6

Sample Input 3

1 100000
1000000000

Sample Output 3

0

We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

Sample Input 4

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

9500000000


<?php

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

$n = $a[0];
$m = $a[1];

$heap = new SplPriorityQueue();

foreach ($numbers as $n) {
    $heap->insert((int)$n);
}

for ($i = 0; $i < $m; $i++) {
    $max = floor($heap->extract() / 2);
    $heap->insert($max);
}

$ans = [];
while ($heap->valid()) {
    $ans[] = $heap->extract();
}

echo array_sum($ans);


<?php
fscanf(STDIN, '%d, %d', $N, $M);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
rsort($A);

while ($M > 0) {
    $base = $A[0] / 2;
    foreach ($A as $k => $v) {
        if ($base <= $v) {
            if ($M > 0) {
                $A[$k] /= 2;
                $M--;
            } else {
                break;
            }
        }
    }
    rsort($A);
}

$ans = 0;
foreach ($A as $v) {
    $ans += $v;
}
echo $ans;


<?php
fscanf(STDIN, "%d %d", $N, $M);
$A = array_map('intval' , explode(" ", trim(fgets(STDIN))));
rsort($A);

while($M > 0) {
    $base = $A[0] / 2;
    foreach ($A as $k => $v) {
        if ($base <= $v) {
            if ($M > 0) {
                $A[$k] /= 2;
                $M--;
            } else {
                break;
            }
        }
    }
    rsort($A);
}

$ans = 0;
foreach ($A as $v) {
    $ans += intval($v);
}
echo $ans;


<?php
fscanf(STDIN, "%d %d", $n, $m);
$a = explode(" ",fgets(STDIN));
for($i=0; $i<$m; $i++) {
    $expensive = array_search(max($a), $a);
    $a[$expensive] = floor($a[$expensive]/2);
}
echo array_sum($a);


<?php
$conditions = trim(fgets(STDIN));
$array = explode(' ', $conditions);
$N = $array[0];
$M = $array[1];

$str = trim(fgets(STDIN));
$prices = explode(' ', $str);

for ($i = 0; $i < $M; $i++) {
    $max = array_search(max($prices), $prices);
     $prices[$max] = floor($prices[$max] / 2);
     if ($prices[0] === 0) {
         break;
     }
}
echo(array_sum($prices));


<?php
$conditions = trim(fgets(STDIN));
$array = explode(' ', $conditions);
$N = $array[0];
$M = $array[1];

$str = trim(fgets(STDIN));
$prices = explode(' ', $str);
rsort($prices);

for ($i = 0; $i < $M; $i++) {
     $prices[0] = floor($prices[0] / 2);
     rsort($prices);
     if ($prices[0] === 0) {
         break;
     }
}
echo(array_sum($prices));


<?php
list($n) = ints();
list($s) = strs();
$max = 0;
for ($i = 0; $i < $n; ++$i) {
    $t = substr($s, $i);
    $lcp = zAlgo($t);
    for ($j = 0; $j < $n - $i; ++$j)
        $max = max($max, min($j, $lcp[$j]));
}
echo $max;
// sとs[i:]が、先頭から最大で何文字まで一致しているか格納した配列を返す
// O(N)
function zAlgo(string $s): array
{
    $n = strlen($s);
    $res = array_fill(0, $n, 0);
    $res[0] = $n;
    $i = 1;
    $len = 0;
    while ($i < $n) {
        while ($i + $len < $n && $s[$len] === $s[$i + $len]) ++$len;
        $res[$i] = $len;
        if ($len === 0) {
            ++$i;
            continue;
        }
        $k = 1;
        while ($i + $k < $n && $k + $res[$k] < $len) {
            $res[$i + $k] = $res[$k];
            ++$k;
        }
        $i += $k;
        $len -= $k;
    }
    return $res;
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 500 points

Problem Statement

Given is a string S of length N.

Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.

More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:

l_1 + len \leq l_2

S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)

If there is no such integer len, print 0.

Constraints

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

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. If there is no such non-empty string, print 0 instead.

Sample Input 1

5
ababa

Sample Output 1

2

The strings satisfying the conditions are: a, b, ab, and ba. The maximum length among them is 2, which is the answer.
Note that aba occurs twice in S as contiguous substrings, but there is no pair of integers l_1 and l_2 mentioned in the statement such that l_1 + len \leq l_2.

Sample Input 2

2
xy

Sample Output 2

0

No non-empty string satisfies the conditions.

Sample Input 3

13
strangeorange

Sample Output 3

5


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

$max = 0;
for($i = 0; $i < $n; $i++){
    for($j = $i+$max+1; $j < $n; $j++){
        $ss = substr($s, $i, $j-$i);
        if(strpos($s, $ss, $j) === false){
            break;
        }else{
            $max=max($max,$j-$i);
        }
    }
}
echo $max;


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

$max = 0;
for($i = 0; $i < $n; $i++){
    for($j = $i+1; $j < $n; $j++){
        $ss = substr($s, $i, $j-$i);
        if(strpos($s, $ss, $j) !== false)$max=max($max,$j-$i);
    }
}
echo $max;


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

if ($a < 3200) {
    echo 'red';
} else {
    echo $s;
}

echo PHP_EOL;

Score : 100 points

Problem Statement

You will be given an integer a and a string s consisting of lowercase English letters as input.

Write a program that prints s if a is not less than 3200 and prints red if a is less than 3200.

Constraints

2800 \leq a < 5000

s is a string of length between 1 and 10 (inclusive).

Each character of s is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

a
s

Output

If a is not less than 3200, print s; if a is less than 3200, print red.

Sample Input 1

3200
pink

Sample Output 1

pink

a = 3200 is not less than 3200, so we print s = pink.

Sample Input 2

3199
pink

Sample Output 2

red

a = 3199 is less than 3200, so we print red.

Sample Input 3

4049
red

Sample Output 3

red

a = 4049 is not less than 3200, so we print s = red.


<?php
    $R = fgets(STDIN);
    $S = fgets(STDIN);
	$ans = "";
	if($R >= 3200){
    	$ans = $S;
    }else{
    	$ans = "red";
    }
	echo $ans;
?>


<?php

$a = trim(fgets(STDIN));
if ($a >= 3200){
  echo trim(fgets(STDIN));
} else {
  echo "red";
}

?>


<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%s", $s);
if($a >= 3200){
  echo $s;
}else {
  echo "red";
}
?>


<?php

//文字列の入力
fscanf(STDIN,"%s",$a);
fscanf(STDIN,"%s",$s);

if($a >= 3200){
    echo $s;
}elseif ($a < 3200){
    echo "red";
}


<?php
$a = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
if($a >= 3200){
    echo $s;
}else{
    echo "red";
}


<?php
# 数値の入力
fscanf(STDIN, "%d", $data1);
# 文字列の入力
fscanf(STDIN, "%s", $data2);

if($data1 < 3200){
    echo "red"."\n";
}else{
    echo $data2."\n";
}

?>


<?php

fscanf(STDIN, "%s", $number);
fscanf(STDIN, "%s", $string);

if($number >= 3200)
{
	print($string);
}
else
{
	print("red");
}


<?php
# 整数の入力
fscanf(STDIN, "%d", $a);
# 文字列の入力
fscanf(STDIN, "%s", $s);

if ($a < 3200) {
  print("red");
} else {
  print $s;
}
?>


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

echo ($a >= 3200 ? $s : 'red') . "\n";


<?php

function fget_array()
{
    return explode(' ', trim(fgets(STDIN)));
}

$num = fget_array()[0];
$str = fget_array()[0];
$result = $num < 3200 ? 'red' : $str;
echo $result.PHP_EOL;


<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%s", $s);
echo $a >= 3200 ? $s : 'red';


<?php
$a = intval(fgets(STDIN));
$s = fgets(STDIN);

if($a>=3200){
    echo $s;
} else {
    echo "red";
}


<?php
fscanf(STDIN, '%d', $a);
fscanf(STDIN, '%s', $s);
if ($a >= 3200) $ans = $s;
else $ans = 'red';
echo $ans . PHP_EOL;


Score : 400 points

Problem Statement

Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.

Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.

Now, the following Q operations will be performed:

Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.

Find the value of the counter on each vertex after all operations.

Constraints

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

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

1 \leq a_i < b_i \leq N

1 \leq p_j \leq N

1 \leq x_j \leq 10^4

The given graph is a tree.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
a_1 b_1
:
a_{N-1} b_{N-1}
p_1 x_1
:
p_Q x_Q

Output

Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between.

Sample Input 1

4 3
1 2
2 3
2 4
2 10
1 100
3 1

Sample Output 1

100 110 111 110

The tree in this input is as follows:

Each operation changes the values of the counters on the vertices as follows:

Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.

Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.

Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.

Sample Input 2

6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10

Sample Output 2

20 20 20 20 20 20


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

$nodelist = [
  1 => ['children'=>[], 'value'=>0]
];

for($i=0; $i<$n-1; $i++){
  fscanf(STDIN, "%d %d", $a, $b);

  if(empty($nodelist[$b])) {
    $nodelist[$b] = [
      'children' => [],
      'value' => 0
    ];
  }

  if(empty($nodelist[$a])) {
    $nodelist[$a] = [
      'children' => [],
      'value' => 0
    ];
  }

  $nodelist[$a]['children'][] = $b;
}

for($i=0; $i<$q; $i++){
  fscanf(STDIN, "%d %d", $p, $x);

  $nodelist[$p]['value'] += $x;
}

function add(&$node, $key, $value = 0) {
  $node[$key]['value'] += $value;

  foreach($node[$key]['children'] as $child) {
    add($node, $child, $node[$key]['value']);
  }
}

add($nodelist, 1);
ksort($nodelist);

echo implode(' ', array_column($nodelist, 'value'));


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

$nodelist = [
  'i1' => ['p'=>0, 'c'=>0]
];

for($i=0; $i<$n-1; $i++){
  fscanf(STDIN, "%d %d", $a, $b);
  $nodelist["i$b"] = [
    'p' => $a,
    'c' => 0
  ];
}

$keys = array_column($nodelist, 'c');
array_multisort($keys, SORT_ASC, $nodelist);

for($i=0; $i<$q; $i++){
  fscanf(STDIN, "%d %d", $p, $x);

  $nodelist["i$p"]['c'] += $x;
}

foreach($nodelist as $i => $node){
  if($nodelist[$i]['p'] === 0) continue;
  $nodelist[$i]['c'] += $nodelist["i".$nodelist[$i]['p']]['c'];
}

ksort($nodelist);

echo implode(' ', array_column($nodelist, 'c'));