( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ HEX
HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux mail.thebrand.ai 6.8.0-107-generic #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 x86_64
User: www-data (33)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/tmpr/..//tmpr/../tmpr/../tmpr/..//tmpr/..//andela.php
 <?php 
 
 // Complete the factorial function below.
function factorial($n)
{
    if ($n === 0) {
        return 1;
    } else {
        return $n * factorial($n - 1);
    }
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

$result = factorial($n);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);





   // Solve me first

function solveMeFirst($a,$b){
	return $a + $b;
}

   // Simple Array Sum

function simpleArraySum($ar) {
    $sum = 0;
    foreach($ar as $value){
        $sum+=$value;
    }
    return $sum;
}

   // Compare the Triplets

function compareTriplets($a, $b) {
    $length = count($a);
    $aliceScore = 0;
    $bobScore = 0;
    for($i=0; $i<$length; $i++){
        if($a[$i] == $b[$i]){
            continue;
        }
        if($a[$i] > $b[$i]){
            $aliceScore++;
            continue;
        }
        $bobScore++;
    }
    return [$aliceScore, $bobScore];
}

   // A Very Big Sum

function aVeryBigSum($ar) {
    $sum = 0;
    foreach($ar as $value){
        $sum+=$value;
    }
    return $sum;
}

  //  Diagonal Difference

function diagonalDifference($arr) {
    $length = count($arr);
    $primaryDiagonal = 0;
    $secondaryDiagonal = 0;
    $lastIndex = $length - 1;
    for($i = 0; $i<$length; $i++){
        $primaryDiagonal+=$arr[$i][$i];
        $secondaryDiagonal+=$arr[$i][$lastIndex--];
    }
    return abs($primaryDiagonal - $secondaryDiagonal);
}

 //   Plus Minus

function plusMinus($arr) {
    $POSITIVES = 0;
    $NEGATIVES = 1;
    $ZEROES = 2;

    $length = count($arr);
    // declare the temp numbers to index positions
    $numbers = [0, 0, 0];

    // determine the plusMinus of the numbers
    foreach($arr as $val){
        if($val === 0){
            $numbers[$ZEROES] = $numbers[$ZEROES] + 1;
            continue;
        }
        if($val > 0){
            $numbers[$POSITIVES] = $numbers[$POSITIVES] + 1;
            continue;
        }
        $numbers[$NEGATIVES] = $numbers[$NEGATIVES] + 1;
    }

    $plusMinusArr = array_map(function ($number) use ($length) {
        return number_format($number/$length, 6);
    }, $numbers);

    foreach($plusMinusArr as $plusMinus){
        echo $plusMinus;
        echo "\n";
    }
}

   // Staircase

function staircase($n) {
    $totalSteps = $n;
    $staircase = [];
    // start from the right steps
    for($n; $n>0; $n--){
        $stairs = [];
        // proceed from left stair until the reach the final stair steps
        // then gradually increase the starting stair
        for($i=1; $i<=$n; $i++){
            // if it reached the final step print the stairs "#" else the its spaces
            if($i == $n){
                // calculate the total stairs to print
                $totalPrintOfStairs = ($totalSteps - $n) + 1;
                for($totalPrintOfStairs; $totalPrintOfStairs>0; $totalPrintOfStairs--){
                 array_push($stairs, "#");
                }
                array_push($staircase, $stairs);
                break;
            }
            array_push($stairs, " ");
        }
    }

    // print the staircases
    foreach($staircase as $stairs){
        foreach($stairs as $stair){
            echo $stair;
        }
        echo "\n";
    }
}

   // Mini-Max Sum

function miniMaxSum($arr) {
    $maxSumTempArr = $arr;
    $minSumTempArr = $arr;

    // sort into ascending order and get the first four values
    sort($minSumTempArr);
    $minSumArr = array_splice($minSumTempArr, 0 ,4);

    // sort into descending order and get the first four values
    rsort($maxSumTempArr);
    $maxSumArr = array_splice($maxSumTempArr, 0, 4);    

    echo array_sum($minSumArr) . ' ' . array_sum($maxSumArr);
}

    //Birthday Cake Candles

function birthdayCakeCandles($ar) {
   // count the recurring of the candle
   $candles = array_count_values($ar);
   // sort the recurring candle by descending & get the most recurring candle
   krsort($candles);
   $candlesBlowsValue = array_values($candles);
   return $candlesBlowsValue[0];
}

    //Time Conversion

function timeConversion($s) {
    $strToTime = strtotime($s);
    return date('H:i:s', $strToTime);
}

    //Grading Students

function gradingStudents($grades) {
     $MODULO = 5;
     $finalGrades = [];

     $finalGrades = array_map(function($grade) use ($MODULO){
         // get the next multiplier by 5
         $nextMultiplier = $grade + ($MODULO - $grade % $MODULO);
         $difference = $nextMultiplier - $grade;
         // do not round up if grade less than 40 
         // the difference is 3 and greater than 3
         if($nextMultiplier < 40 || $difference === 3 || $difference > 3){
             return $grade;
         }
         
         // round up if the difference is less than 3
         return $nextMultiplier;
     }, $grades);

     return $finalGrades;
}


//2d Arrays

$stdin = fopen("php://stdin", "r");

$arr = [];
for ($i = 0; $i < 6; $i++) {
    fscanf($stdin, "%[^\n]", $arr_temp);
    $items = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($items as $k => $item) {
        $arr[$i][$k] = $item;
    }
}

$sums = [];
for ($i = 0; $i < 4; $i++) {
    for ($x = 0; $x < 4; $x++) {
        $top = $arr[$i][$x] + $arr[$i][$x + 1] + $arr[$i][$x + 2];
        $middle = $arr[$i + 1][$x + 1];
        $bottom = $arr[$i + 2][$x] + $arr[$i + 2][$x + 1] + $arr[$i + 2][$x + 2];

        $sum = $top + $middle + $bottom;
        $sums[] = $sum;
    }
}

print(max($sums));

fclose($stdin);


//rotate left

// Complete the rotLeft function below.
function rotLeft($a, $d)
{
    $first = array_slice($a, 0, $d);
    $origin = array_slice($a, $d);

    return array_merge($origin, $first);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $nd_temp);
$nd = explode(' ', $nd_temp);

$n = intval($nd[0]);

$d = intval($nd[1]);

fscanf($stdin, "%[^\n]", $a_temp);

$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = rotLeft($a, $d);

fwrite($fptr, implode(" ", $result) . "\n");

fclose($stdin);
fclose($fptr);



///ransome note
// Complete the checkMagazine function below.
function checkMagazine($magazine, $note)
{
    foreach ($magazine as $i => $string) {
        if (in_array($string, $note, false)) {
            $k = array_search($string, $note, false);
            unset($note[$k]);
        }
    }

    echo empty($note) ? 'Yes' : 'No';
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $mn_temp);
$mn = explode(' ', $mn_temp);

$m = intval($mn[0]);

$n = intval($mn[1]);

fscanf($stdin, "%[^\n]", $magazine_temp);

$magazine = preg_split('/ /', $magazine_temp, -1, PREG_SPLIT_NO_EMPTY);

fscanf($stdin, "%[^\n]", $note_temp);

$note = preg_split('/ /', $note_temp, -1, PREG_SPLIT_NO_EMPTY);

checkMagazine($magazine, $note);

fclose($stdin);

// Complete the twoStrings function below.
function twoStrings($s1, $s2)
{
    $s1 = str_split($s1);
    $s2 = str_split($s2);


    return count(array_intersect($s1, $s2)) > 0 ? 'YES' : 'NO';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s1 = '';
    fscanf($stdin, "%[^\n]", $s1);

    $s2 = '';
    fscanf($stdin, "%[^\n]", $s2);

    $result = twoStrings($s1, $s2);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);


// Complete the flippingBits function below.
function flippingBits($n)
{
    return $n ^ 0xFFFFFFFF;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    fscanf($stdin, "%ld\n", $n);

    $result = flippingBits($n);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);


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



//flipping
function fibonacci($n)
{
    if (in_array($n, [0, 1], false)) {
        return $n;
    }

    return fibonacci($n - 1) + fibonacci($n - 2);
}

$n = fgets($handle);

printf("%d", fibonacci($n));

fclose($handle);
 
 
 
 
 
 
 // Complete the maximumToys function below.
function maximumToys($prices, $k)
{
    sort($prices);
    $quantity = 0;
    foreach ($prices as $price) {
        $k -= $price;
        if ($k <= 0) {
            break;
        }

        $quantity++;
    }

    return $quantity;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $nk_temp);
$nk = explode(' ', $nk_temp);

$n = intval($nk[0]);

$k = intval($nk[1]);

fscanf($stdin, "%[^\n]", $prices_temp);

$prices = array_map('intval', preg_split('/ /', $prices_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = maximumToys($prices, $k);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);
 
 
 
 // bubble sort Complete the countSwaps function below.
function countSwaps($a)
{
    $numberOfSwaps = 0;
    $n = count($a);
    for ($i = 0; $i < $n; $i++) {
        for ($j = 0; $j < $n - 1 - $i; $j++) {
            if ($a[$j + 1] < $a[$j]) {
                $a = swap($a, $j, $j + 1);
                $numberOfSwaps++;
            }
        }
    }

    print('Array is sorted in ' . $numberOfSwaps . ' swaps.') . PHP_EOL;
    print('First Element: ' . current($a)) . PHP_EOL;
    print('Last Element: ' . end($a)) . PHP_EOL;
}

function swap($a, $left, $right)
{
    $old = $a[$right];
    $a[$right] = $a[$left];
    $a[$left] = $old;
    return $a;
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $a_temp);

$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

countSwaps($a);

fclose($stdin);
 
 
 
 
 
 // Complete the alternatingCharacters function below.
function alternatingCharacters($s)
{
    $arrayOfLetters = str_split($s);
    $countOfRemoving = 0;

    for ($i = 1; $i < count($arrayOfLetters); $i++) {
        if ($arrayOfLetters[$i - 1] === $arrayOfLetters[$i]) {
            $countOfRemoving++;
        }
    }

    return $countOfRemoving;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s = '';
    fscanf($stdin, "%[^\n]", $s);

    $result = alternatingCharacters($s);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);


///seherlock

// Complete the isValid function below.
function isValid($s)
{
    $excess = 0;
    $letters = [];
    foreach (str_split($s) as $letter) {
        if (isset($letters[$letter])) {
            $letters[$letter]++;
        } else {
            $letters[$letter] = 1;
        }
    }

    $total = [];
    $letters = array_values($letters);
    foreach ($letters as $count) {
        if (isset($letters[$letter])) {
            $total[$count]++;
        } else {
            $total[$count] = 1;
        }
    }

    arsort($total);
    $maxCount = key($total);

    foreach ($letters as $count) {
        if ($count !== $maxCount) {
            $excess++;
        }
    }

    return $excess > 1 ? 'NO' : 'YES';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

$result = isValid($s);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



//anagrams
/**
 * @title Strings: Making Anagrams
 * @link https://www.hackerrank.com/challenges/ctci-making-anagrams
 * @status solved
 */

// Complete the makeAnagram function below.
function makeAnagram($a, $b) {
    $a = str_split($a);
    $b = str_split($b);

    $a = array_count_values($a);
    $b = array_count_values($b);

    $error = 0;
    foreach ($a as $letter => $count) {
        if (isset($b[$letter])) {
            $error += abs($count - $b[$letter]);
            unset($b[$letter]);
        } else {
            $error += $count;
        }
    }

    return $error + array_sum($b);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$a = '';
fscanf($stdin, "%[^\n]", $a);

$b = '';
fscanf($stdin, "%[^\n]", $b);

$res = makeAnagram($a, $b);

fwrite($fptr, $res . "\n");

fclose($stdin);
fclose($fptr);





// Complete the countingValleys function below.
function countingValleys($n, $s)
{
    $total = 0;
    $level = 0;
    $isValley = false;

    for ($i = 0; $i < $n; $i++) {
        if ($s[$i] === 'U') {
            $level++;
        } else {
            $level--;
        }

        if ($level < 0) {
            if (!$isValley) {
                $total++;
            }
            $isValley = true;
        } else {
            $isValley = false;
        }
    }

    return $total;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

$s = '';
fscanf($stdin, "%[^\n]", $s);

$result = countingValleys($n, $s);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




// Complete the jumpingOnClouds function below.
function jumpingOnClouds($c)
{
    $steps = 0;
    $current = 0;

    foreach ($c as $k => $cloud) {
        if ($k <= $current) {
            continue;
        }

        if ($c[$current + 2] === 1) {
            $current++;
        } else {
            $current += 2;
        }

        $steps++;
    }

    return $steps;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $c_temp);

$c = array_map('intval', preg_split('/ /', $c_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = jumpingOnClouds($c);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);


// Complete the repeatedString function below.
function repeatedString($s, $n)
{
    $strLength = strlen($s);

    $needLetter = 'a';
    $repeatingCount = floor($n / $strLength);

    $filteredArray = array_filter(str_split($s), function ($letter) use ($needLetter) {
        return $letter === $needLetter;
    });

    $lettersInOneString = count($filteredArray);

    $subStringCount = 0;
    if (($repeatingCount * $strLength) < $n) {
        $subString = $n - ($repeatingCount * $strLength);
        $subString = substr($s, 0, $subString);

        $substringArray = array_filter(str_split($subString), function ($letter) use ($needLetter) {
            return $letter === $needLetter;
        });

        $subStringCount = count($substringArray);
    }

    return ($lettersInOneString * $repeatingCount) + $subStringCount;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

fscanf($stdin, "%ld\n", $n);

$result = repeatedString($s, $n);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);


// Complete the sockMerchant function below.
function sockMerchant($n, $ar)
{
    $count = 0;
    $socks = [];
    foreach ($ar as $number) {
        $socks[$number]++;
    }

    foreach ($socks as $sock) {
        $count += floor($sock / 2);
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = sockMerchant($n, $ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title A Very Big Sum
 * @link https://www.hackerrank.com/challenges/a-very-big-sum
 * @status solved
 */

// Complete the aVeryBigSum function below.
function aVeryBigSum($ar) {
    return array_sum($ar);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $ar_count);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = aVeryBigSum($ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Alternating Characters
 * @link https://www.hackerrank.com/challenges/alternating-characters
 * @status solved
 */

// Complete the alternatingCharacters function below.
function alternatingCharacters($s) {
    $arrayOfLetters = str_split($s);
    $countOfRemoving = 0;

    for ($i = 1; $i < count($arrayOfLetters); $i++) {
        if ($arrayOfLetters[$i - 1] === $arrayOfLetters[$i]) {
            $countOfRemoving++;
        }
    }

    return $countOfRemoving;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s = '';
    fscanf($stdin, "%[^\n]", $s);

    $result = alternatingCharacters($s);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



///
/**
 * @title Angry Professor
 * @link https://www.hackerrank.com/challenges/angry-professor
 * @status solved
 */

// Complete the angryProfessor function below.
function angryProfessor($k, $a) {
    $needStudents = $k;
    $punctualStudents = 0;

    foreach ($a as $time) {
        if ($time <= 0) {
            $punctualStudents++;
        }
    }

    return $punctualStudents >= $needStudents ? 'NO' : 'YES';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $t);

for ($t_itr = 0; $t_itr < $t; $t_itr++) {
    fscanf($stdin, "%[^\n]", $nk_temp);
    $nk = explode(' ', $nk_temp);

    $n = intval($nk[0]);

    $k = intval($nk[1]);

    fscanf($stdin, "%[^\n]", $a_temp);

    $a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

    $result = angryProfessor($k, $a);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);






/**
 * @title Apple and Orange
 * @link https://www.hackerrank.com/challenges/apple-and-orange
 * @status solved
 */

// Complete the countApplesAndOranges function below.
function countApplesAndOranges($s, $t, $a, $b, $apples, $oranges) {
    $total = ['apples' => 0, 'oranges' => 0];

    foreach ($apples as $apple) {
        $distance = $a + $apple;
        if ($distance >= $s && $distance <= $t) {
            $total['apples']++;
        }
    }
    foreach ($oranges as $orange) {
        $distance = $b + $orange;
        if ($distance >= $s && $distance <= $t) {
            $total['oranges']++;
        }
    }

    echo implode(PHP_EOL, $total);
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $st_temp);
$st = explode(' ', $st_temp);

$s = intval($st[0]);

$t = intval($st[1]);

fscanf($stdin, "%[^\n]", $ab_temp);
$ab = explode(' ', $ab_temp);

$a = intval($ab[0]);

$b = intval($ab[1]);

fscanf($stdin, "%[^\n]", $mn_temp);
$mn = explode(' ', $mn_temp);

$m = intval($mn[0]);

$n = intval($mn[1]);

fscanf($stdin, "%[^\n]", $apples_temp);

$apples = array_map('intval', preg_split('/ /', $apples_temp, -1, PREG_SPLIT_NO_EMPTY));

fscanf($stdin, "%[^\n]", $oranges_temp);

$oranges = array_map('intval', preg_split('/ /', $oranges_temp, -1, PREG_SPLIT_NO_EMPTY));

countApplesAndOranges($s, $t, $a, $b, $apples, $oranges);

fclose($stdin);



/**
 * @title Beautiful Days at the Movies
 * @link https://www.hackerrank.com/challenges/beautiful-days-at-the-movies
 * @status solved
 */

// Complete the beautifulDays function below.
function beautifulDays($i, $j, $k) {
    $count = 0;
    for ($day = $i; $day <= $j; $day++) {
        $first = $day;
        $second = implode('', array_reverse(str_split($day)));

        if (is_integer(($first - $second) / $k)) {
            $count++;
        }
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $ijk_temp);
$ijk = explode(' ', $ijk_temp);

$i = intval($ijk[0]);

$j = intval($ijk[1]);

$k = intval($ijk[2]);

$result = beautifulDays($i, $j, $k);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Birthday Cake Candles
 * @link https://www.hackerrank.com/challenges/birthday-cake-candles
 * @status solved
 */

// Complete the birthdayCakeCandles function below.
function birthdayCakeCandles($ar) {
    $maxHeight = max($ar);

    $candles = array_filter($ar, function ($item) use ($maxHeight) {
        return $item === $maxHeight;
    });

    return count($candles);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $ar_count);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = birthdayCakeCandles($ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);





/**
 * @title Breaking the Records
 * @link https://www.hackerrank.com/challenges/breaking-best-and-worst-records
 * @status solved
 */

// Complete the breakingRecords function below.
function breakingRecords($scores) {
    $currentMaxScore = 0;
    $currentMinScore = 0;

    $totalMaxScores = 0;
    $totalMinScores = 0;

    foreach ($scores as $k => $score) {
        if ($k === 0) {
            $currentMaxScore = $score;
            $currentMinScore = $score;
        }

        if ($score > $currentMaxScore) {
            $currentMaxScore = $score;
            if ($k > 0) {
                $totalMaxScores++;
            }
        }

        if ($score < $currentMinScore) {
            $currentMinScore = $score;
            if ($k > 0) {
                $totalMinScores++;
            }
        }
    }

    return [$totalMaxScores, $totalMinScores];
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $scores_temp);

$scores = array_map('intval', preg_split('/ /', $scores_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = breakingRecords($scores);

fwrite($fptr, implode(" ", $result) . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title CamelCase
 * @link https://www.hackerrank.com/challenges/camelcase
 * @status solved
 */

// Complete the camelcase function below.
function camelcase($s) {
    $wordsCount = 0;
    $splitWord = str_split($s);

    foreach ($splitWord as $k => $letter) {
        if ($k === 0 || ctype_upper($letter)) {
            $wordsCount++;
        }
    }

    return $wordsCount;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

$result = camelcase($s);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);
 
 
 
 /**
 * @title Compare the Triplets
 * @link https://www.hackerrank.com/challenges/compare-the-triplets
 * @status solved
 */


// Complete the compareTriplets function below.
function compareTriplets($a, $b) {
    $aValue = 0;
    $bValue = 0;

    for ($i = 0; $i < 3; $i++) {
        if ($a[$i] > $b[$i]) {
            $aValue++;
        } elseif ($a[$i] < $b[$i]) {
            $bValue++;
        }
    }

    return [$aValue, $bValue];
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$a_temp = rtrim(fgets(STDIN));

$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

$b_temp = rtrim(fgets(STDIN));

$b = array_map('intval', preg_split('/ /', $b_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = compareTriplets($a, $b);

fwrite($fptr, implode(" ", $result) . "\n");

fclose($fptr);



/**
 * @title Day of the Programmer
 * @link https://www.hackerrank.com/challenges/day-of-the-programmer
 * @status solved
 */

// Complete the dayOfProgrammer function below.
function dayOfProgrammer($year) {
    $isJulian = $year >= 1700 && $year <= 1917;
    $isGregorian = $year >= 1919;

    if ($isJulian) {
        $isLeapYear = $year % 4 === 0;
    } else {
        $isLeapYear = $year % 400 === 0 || ($year % 4 === 0 && $year % 100 !== 0);
    }

    $date = $isLeapYear ? '12.09.' : '13.09.';

    if (!$isJulian && !$isGregorian) {
        $date = '26.09.';
    }

    return $date . $year;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$year = intval(trim(fgets(STDIN)));

$result = dayOfProgrammer($year);

fwrite($fptr, $result . "\n");

fclose($fptr);




/**
 * @title Diagonal Difference
 * @link https://www.hackerrank.com/challenges/diagonal-difference
 * @status solved
 */

// Complete the diagonalDifference function below.
function diagonalDifference($arr) {
    $first = 0;
    $second = 0;
    $count = count($arr);

    $firstIterator = 0;
    $secondIterator = $count - 1;
    for ($i = 0; $i < $count; $i++) {
        $first += $arr[$i][$firstIterator];
        $second += $arr[$i][$secondIterator];
        $firstIterator++;
        $secondIterator--;
    }

    return abs($first - $second);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

$arr = [];

for ($i = 0; $i < $n; $i++) {
    fscanf($stdin, "%[^\n]", $arr_temp);
    $arr[] = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));
}

$result = diagonalDifference($arr);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Divisible Sum Pairs
 * @link https://www.hackerrank.com/challenges/divisible-sum-pairs
 * @status solved
 */

// Complete the divisibleSumPairs function below.
function divisibleSumPairs($n, $k, $ar) {
    $total = 0;
    for ($i = 0; $i < $n; $i++) {
        for ($p = 0; $p < $n; $p++) {
            if ((($ar[$i] + $ar[$p]) % $k === 0) && $i !== $p) {
                $total++;
            }
        }
    }

    return $total / 2;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $nk_temp);
$nk = explode(' ', $nk_temp);

$n = intval($nk[0]);

$k = intval($nk[1]);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = divisibleSumPairs($n, $k, $ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Electronics Shop
 * @link https://www.hackerrank.com/challenges/electronics-shop
 * @status solved
 */

/*
 * Complete the getMoneySpent function below.
 */
function getMoneySpent($keyboards, $drives, $b) {
    rsort($keyboards);
    rsort($drives);

    $allows = [];
    foreach ($keyboards as $keyboard) {
        foreach ($drives as $drive) {
            if ($keyboard + $drive <= $b) {
                $allows[] = $keyboard + $drive;
            }
        }
    }

    return !empty($allows) ? max($allows) : -1;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $bnm_temp);
$bnm = explode(' ', $bnm_temp);

$b = intval($bnm[0]);

$n = intval($bnm[1]);

$m = intval($bnm[2]);

fscanf($stdin, "%[^\n]", $keyboards_temp);

$keyboards = array_map('intval', preg_split('/ /', $keyboards_temp, -1, PREG_SPLIT_NO_EMPTY));

fscanf($stdin, "%[^\n]", $drives_temp);

$drives = array_map('intval', preg_split('/ /', $drives_temp, -1, PREG_SPLIT_NO_EMPTY));

/*
 * The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
 */

$moneySpent = getMoneySpent($keyboards, $drives, $b);

fwrite($fptr, $moneySpent . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Encryption
 * @link https://www.hackerrank.com/challenges/encryption
 * @status solved
 */

// Complete the encryption function below.
function encryption($s) {
    $string = preg_replace('~\W~', '', $s);
    $length = strlen($string);
    $sqrt = ceil(sqrt($length));

    $arrayOfLetters = str_split($string);
    $countOfRows = floor($length / $sqrt);

    if ($sqrt * $countOfRows <= $length) {
        $countOfRows = $sqrt;
    }

    $chunk = array_chunk($arrayOfLetters, $countOfRows);

    $str = [];
    for ($i = 0; $i < $countOfRows; $i++) {
        foreach ($chunk as $letters) {
            if (isset($letters[$i])) {
                $str[$i] .= $letters[$i];
            }
        }
    }

    return implode(' ', $str);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

$result = encryption($s);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);


/**
 * @title Equalize the Array
 * @link https://www.hackerrank.com/challenges/equality-in-a-array
 * @status solved
 */

// Complete the equalizeArray function below.
function equalizeArray($arr) {
    $count = 0;
    $numbers = [];
    foreach ($arr as $number) {
        if (isset($numbers[$number])) {
            $numbers[$number]++;
        } else {
            $numbers[$number] = 1;
        }
    }

    $maxValue = array_search(max($numbers), $numbers, false);

    foreach ($arr as $number) {
        if ($number !== $maxValue) {
            $count++;
        }
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $arr_temp);

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = equalizeArray($arr);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Find Digits
 * @link https://www.hackerrank.com/challenges/find-digits
 * @status solved
 */

// Complete the findDigits function below.
function findDigits($n) {
    $count = 0;

    foreach (str_split($n) as $number) {
        if ($number > 0 && $n % $number === 0) {
            $count++;
        }
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $t);

for ($t_itr = 0; $t_itr < $t; $t_itr++) {
    fscanf($stdin, "%d\n", $n);

    $result = findDigits($n);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



/**
 * @title Find the Median
 * @link https://www.hackerrank.com/challenges/find-the-median
 * @status solved
 */

// Complete the findMedian function below.
function findMedian($arr) {
    sort($arr);
    $middle = floor(count($arr) / 2);

    return $arr[$middle];
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $arr_temp);

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = findMedian($arr);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Flipping bits
 * @link https://www.hackerrank.com/challenges/flipping-bits
 * @status solved
 */

// Complete the flippingBits function below.
function flippingBits($n) {
    return $n ^ 0xFFFFFFFF;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    fscanf($stdin, "%ld\n", $n);

    $result = flippingBits($n);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



/**
 * @title Funny String
 * @link https://www.hackerrank.com/challenges/funny-string
 * @status solved
 */

// Complete the funnyString function below.
function funnyString($s) {
    $first = [];
    $second = [];

    $array = str_split($s);
    foreach ($array as $k => $letter) {
        if ($letter && isset($array[$k + 1])) {
            $first[] = abs(ord($letter) - ord($array[$k + 1]));
        }
    }

    $array = array_reverse(str_split($s));
    foreach ($array as $k => $letter) {
        if ($letter && isset($array[$k + 1])) {
            $second[] = abs(ord($letter) - ord($array[$k + 1]));
        }
    }

    return count(array_diff_assoc($first, $second)) > 0 ? 'Not Funny' : 'Funny';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s = '';
    fscanf($stdin, "%[^\n]", $s);

    $result = funnyString($s);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



/**
 * @title Gemstones
 * @link https://www.hackerrank.com/challenges/gem-stones
 * @status solved
 */

// Complete the gemstones function below.
function gemstones($arr) {
    $countOfStones = count($arr);
    $elements = [];

    foreach ($arr as $k => $stone) {
        foreach (str_split($stone) as $element) {
            if (isset($elements[$k][$element])) {
                $elements[$k][$element]++;
            } else {
                $elements[$k][$element] = 1;
            }
        }
    }

    $total = [];
    foreach ($elements as $element) {
        foreach ($element as $component => $count) {
            if (isset($total[$component])) {
                $total[$component]++;
            } else {
                $total[$component] = 1;
            }
        }
    }

    return count(array_filter($total, function ($item) use ($countOfStones) {
        return $item === $countOfStones;
    }));
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

$arr = [];

for ($i = 0; $i < $n; $i++) {
    $arr_item = '';
    fscanf($stdin, "%[^\n]", $arr_item);
    $arr[] = $arr_item;
}

$result = gemstones($arr);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Grading Students
 * @link https://www.hackerrank.com/challenges/grading
 * @status solved
 */

/*
 * Complete the gradingStudents function below.
 */
function gradingStudents($grades) {
    $final = [];
    foreach ($grades as $grade) {
        if ($grade % 5 === 0) {
            $final[] = $grade;
        } else {
            $nextGrade = ceil($grade / 5) * 5;
            if (($nextGrade - $grade) >= 3 || $grade < 38) {
                $final[] = $grade;
            } else {
                $final[] = $nextGrade;
            }
        }
    }

    return $final;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$__fp = fopen("php://stdin", "r");

fscanf($__fp, "%d\n", $n);

$grades = [];

for ($grades_itr = 0; $grades_itr < $n; $grades_itr++) {
    fscanf($__fp, "%d\n", $grades_item);
    $grades[] = $grades_item;
}

$result = gradingStudents($grades);

fwrite($fptr, implode("\n", $result) . "\n");

fclose($__fp);
fclose($fptr);




/**
 * @title HackerRank in a String!
 * @link https://www.hackerrank.com/challenges/hackerrank-in-a-string
 * @status solved
 */

// Complete the hackerrankInString function below.
function hackerrankInString($s) {
    $word = 'hackerrank';
    foreach (str_split($s) as $letter) {
        if ($letter === $word[0]) {
            $word = substr($word, 1);
        }
    }

    return strlen($word) > 0 ? 'NO' : 'YES';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s = '';
    fscanf($stdin, "%[^\n]", $s);

    $result = hackerrankInString($s);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



/**
 * @title Halloween Sale
 * @link https://www.hackerrank.com/challenges/halloween-sale
 * @status solved
 */

// Complete the howManyGames function below.
function howManyGames($p, $d, $m, $s) {
    $games = 0;
    $money = $s;

    for ($i = $p; $i >= 0; $i -= $d) {
        if ($i >= $m && $money > 0) {
            $money -= $i;
            $games++;
        }
    }

    $games += floor($money / $m);

    return $games > 0 ? $games : 0;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $pdms_temp);
$pdms = explode(' ', $pdms_temp);

$p = intval($pdms[0]);

$d = intval($pdms[1]);

$m = intval($pdms[2]);

$s = intval($pdms[3]);

$answer = howManyGames($p, $d, $m, $s);

fwrite($fptr, $answer . "\n");

fclose($stdin);
fclose($fptr);

/**
 * @title Jumping on the Clouds
 * @link https://www.hackerrank.com/challenges/jumping-on-the-clouds
 * @status solved
 */

// Complete the jumpingOnClouds function below.
function jumpingOnClouds($c) {
    $steps = 0;
    $current = 0;

    foreach ($c as $k => $cloud) {
        if ($k <= $current) {
            continue;
        }

        if ($c[$current + 2] === 1) {
            $current++;
        } else {
            $current += 2;
        }

        $steps++;
    }

    return $steps;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $c_temp);

$c = array_map('intval', preg_split('/ /', $c_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = jumpingOnClouds($c);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Library Fine
 * @link https://www.hackerrank.com/challenges/library-fine
 * @status solved
 */

// Complete the libraryFine function below.
function libraryFine($d1, $m1, $y1, $d2, $m2, $y2) {
    if (mktime(0, 0, 0, $m1, $d1, $y1) < mktime(0, 0, 0, $m2, $d2, $y2)) {
        return 0;
    }

    $d = 15 * ($d1 - $d2) > 0 ? 15 * ($d1 - $d2) : 0;
    $m = 500 * ($m1 - $m2) > 0 ? 500 * ($m1 - $m2) : 0;
    $y = 10000 * ($y1 - $y2) > 0 ? 10000 * ($y1 - $y2) : 0;

    if ($y > 0) {
        return $y;
    } elseif ($m > 0) {
        return $m;
    } elseif ($d > 0) {
        return $d + $m + $y;
    } else {
        return 0;
    }
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $d1M1Y1_temp);
$d1M1Y1 = explode(' ', $d1M1Y1_temp);

$d1 = intval($d1M1Y1[0]);

$m1 = intval($d1M1Y1[1]);

$y1 = intval($d1M1Y1[2]);

fscanf($stdin, "%[^\n]", $d2M2Y2_temp);
$d2M2Y2 = explode(' ', $d2M2Y2_temp);

$d2 = intval($d2M2Y2[0]);

$m2 = intval($d2M2Y2[1]);

$y2 = intval($d2M2Y2[2]);

$result = libraryFine($d1, $m1, $y1, $d2, $m2, $y2);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Halloween Sale
 * @link https://www.hackerrank.com/challenges/halloween-sale
 * @status solved
 */

// Complete the howManyGames function below.
function howManyGames($p, $d, $m, $s) {
    $games = 0;
    $money = $s;

    for ($i = $p; $i >= 0; $i -= $d) {
        if ($i >= $m && $money > 0) {
            $money -= $i;
            $games++;
        }
    }

    $games += floor($money / $m);

    return $games > 0 ? $games : 0;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $pdms_temp);
$pdms = explode(' ', $pdms_temp);

$p = intval($pdms[0]);

$d = intval($pdms[1]);

$m = intval($pdms[2]);

$s = intval($pdms[3]);

$answer = howManyGames($p, $d, $m, $s);

fwrite($fptr, $answer . "\n");

fclose($stdin);
fclose($fptr);



// Complete the jumpingOnClouds function below.
function jumpingOnClouds($c) {
    $steps = 0;
    $current = 0;

    foreach ($c as $k => $cloud) {
        if ($k <= $current) {
            continue;
        }

        if ($c[$current + 2] === 1) {
            $current++;
        } else {
            $current += 2;
        }

        $steps++;
    }

    return $steps;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $c_temp);

$c = array_map('intval', preg_split('/ /', $c_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = jumpingOnClouds($c);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Library Fine
 * @link https://www.hackerrank.com/challenges/library-fine
 * @status solved
 */

// Complete the libraryFine function below.
function libraryFine($d1, $m1, $y1, $d2, $m2, $y2) {
    if (mktime(0, 0, 0, $m1, $d1, $y1) < mktime(0, 0, 0, $m2, $d2, $y2)) {
        return 0;
    }

    $d = 15 * ($d1 - $d2) > 0 ? 15 * ($d1 - $d2) : 0;
    $m = 500 * ($m1 - $m2) > 0 ? 500 * ($m1 - $m2) : 0;
    $y = 10000 * ($y1 - $y2) > 0 ? 10000 * ($y1 - $y2) : 0;

    if ($y > 0) {
        return $y;
    } elseif ($m > 0) {
        return $m;
    } elseif ($d > 0) {
        return $d + $m + $y;
    } else {
        return 0;
    }
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $d1M1Y1_temp);
$d1M1Y1 = explode(' ', $d1M1Y1_temp);

$d1 = intval($d1M1Y1[0]);

$m1 = intval($d1M1Y1[1]);

$y1 = intval($d1M1Y1[2]);

fscanf($stdin, "%[^\n]", $d2M2Y2_temp);
$d2M2Y2 = explode(' ', $d2M2Y2_temp);

$d2 = intval($d2M2Y2[0]);

$m2 = intval($d2M2Y2[1]);

$y2 = intval($d2M2Y2[2]);

$result = libraryFine($d1, $m1, $y1, $d2, $m2, $y2);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Library Fine
 * @link https://www.hackerrank.com/challenges/library-fine
 * @status solved
 */

// Complete the libraryFine function below.
function libraryFine($d1, $m1, $y1, $d2, $m2, $y2) {
    if (mktime(0, 0, 0, $m1, $d1, $y1) < mktime(0, 0, 0, $m2, $d2, $y2)) {
        return 0;
    }

    $d = 15 * ($d1 - $d2) > 0 ? 15 * ($d1 - $d2) : 0;
    $m = 500 * ($m1 - $m2) > 0 ? 500 * ($m1 - $m2) : 0;
    $y = 10000 * ($y1 - $y2) > 0 ? 10000 * ($y1 - $y2) : 0;

    if ($y > 0) {
        return $y;
    } elseif ($m > 0) {
        return $m;
    } elseif ($d > 0) {
        return $d + $m + $y;
    } else {
        return 0;
    }
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $d1M1Y1_temp);
$d1M1Y1 = explode(' ', $d1M1Y1_temp);

$d1 = intval($d1M1Y1[0]);

$m1 = intval($d1M1Y1[1]);

$y1 = intval($d1M1Y1[2]);

fscanf($stdin, "%[^\n]", $d2M2Y2_temp);
$d2M2Y2 = explode(' ', $d2M2Y2_temp);

$d2 = intval($d2M2Y2[0]);

$m2 = intval($d2M2Y2[1]);

$y2 = intval($d2M2Y2[2]);

$result = libraryFine($d1, $m1, $y1, $d2, $m2, $y2);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Lonely Integer
 * @link https://www.hackerrank.com/challenges/lonely-integer
 * @status solved
 */

// Complete the lonelyinteger function below.
function lonelyinteger($a) {
    $result = [];
    foreach ($a as $item) {
        if (isset($result[$item])) {
            $result[$item]++;
        } else {
            $result[$item] = 1;
        }
    }

    $result = array_filter($result, function ($item) {
        return $item % 2 !== 0;
    });

    return key($result);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $a_temp);

$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = lonelyinteger($a);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);


/**
 * @title Mark and Toys
 * @link https://www.hackerrank.com/challenges/mark-and-toys
 * @status solved
 */

// Complete the maximumToys function below.
function maximumToys($prices, $k) {
    sort($prices);
    $quantity = 0;
    foreach ($prices as $price) {
        $k -= $price;
        if ($k <= 0) {
            break;
        }

        $quantity++;
    }

    return $quantity;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $nk_temp);
$nk = explode(' ', $nk_temp);

$n = intval($nk[0]);

$k = intval($nk[1]);

fscanf($stdin, "%[^\n]", $prices_temp);

$prices = array_map('intval', preg_split('/ /', $prices_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = maximumToys($prices, $k);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Migratory Birds
 * @link https://www.hackerrank.com/challenges/migratory-birds
 * @status solved
 */

// Complete the migratoryBirds function below.
function migratoryBirds($arr) {
    $birds = [];
    foreach ($arr as $bird) {
        if (isset($birds[$bird])) {
            $birds[$bird]++;
        } else {
            $birds[$bird] = 1;
        }
    }

    ksort($birds);

    return array_search(max($birds), $birds, false);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$arr_count = intval(trim(fgets(STDIN)));

$arr_temp = rtrim(fgets(STDIN));

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = migratoryBirds($arr);

fwrite($fptr, $result . "\n");

fclose($fptr);




/**
 * @title Mini-Max Sum
 * @link https://www.hackerrank.com/challenges/mini-max-sum
 * @status solved
 */

// Complete the miniMaxSum function below.
function miniMaxSum($arr) {
    $allSums = [];
    for ($i = 0; $i < count($arr); $i++) {
        $tmpArray = $arr;
        unset($tmpArray[$i]);
        $allSums[] = array_sum($tmpArray);
    }

    print min($allSums) . ' ' . max($allSums);
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $arr_temp);

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

miniMaxSum($arr);

fclose($stdin);




/**
 * @title Minimum Distances
 * @link https://www.hackerrank.com/challenges/minimum-distances
 * @status solved
 */

// Complete the minimumDistances function below.
function minimumDistances($a) {
    $result = [];
    foreach ($a as $k => $number) {
        $result[$number][] = $k;
    }

    $min = -1;
    foreach ($result as $line) {
        if (count($line) !== 2) {
            continue;
        }
        $l = abs($line[0] - $line[1]);
        if ($min < 0 || $l < $min) {
            $min = $l;
        }
    }

    return $min;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $a_temp);

$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = minimumDistances($a);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Missing Numbers
 * @link https://www.hackerrank.com/challenges/missing-numbers
 * @status solved
 */

// Complete the missingNumbers function below.
function missingNumbers($arr, $brr) {
    $acount = [];
    foreach ($arr as $number) {
        if (isset($acount[$number])) {
            $acount[$number]++;
        } else {
            $acount[$number] = 1;
        }
    }

    $bcount = [];
    foreach ($brr as $number) {
        if (isset($bcount[$number])) {
            $bcount[$number]++;
        } else {
            $bcount[$number] = 1;
        }
    }

    $result = [];
    foreach ($acount as $number => $count) {
        if (!isset($bcount[$number]) || $bcount[$number] !== $count) {
            $result[$number] = $number;
        }
    }

    foreach ($bcount as $number => $count) {
        if (!isset($acount[$number]) || $acount[$number] !== $count) {
            $result[$number] = $number;
        }
    }

    sort($result);

    return $result;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $arr_temp);

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

fscanf($stdin, "%d\n", $m);

fscanf($stdin, "%[^\n]", $brr_temp);

$brr = array_map('intval', preg_split('/ /', $brr_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = missingNumbers($arr, $brr);

fwrite($fptr, implode(" ", $result) . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Pangrams
 * @link https://www.hackerrank.com/challenges/pangrams
 * @status solved
 */

// Complete the pangrams function below.
function pangrams($s) {
    $letters = range('a', 'z');
    $word = str_split(strtolower($s));

    foreach ($word as $letter) {
        $index = array_search($letter, $letters, false);
        if ($index !== false) {
            unset($letters[$index]);
        }
    }

    return !empty($letters) ? 'not pangram' : 'pangram';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

$result = pangrams($s);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Plus Minus
 * @link https://www.hackerrank.com/challenges/plus-minus
 * @status solved
 */

// Complete the plusMinus function below.
function plusMinus($arr) {
    $positives = 0;
    $negatives = 0;
    $zeros = 0;
    $count = count($arr);

    foreach ($arr as $number) {
        if ($number === 0) {
            $zeros++;
        } elseif ($number > 0) {
            $positives++;
        } else {
            $negatives++;
        }
    }

    $result = [];
    $result[] = round($positives / $count, 6);
    $result[] = round($negatives / $count, 6);
    $result[] = round($zeros / $count, 6);

    echo implode(PHP_EOL, $result);
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $arr_temp);

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

plusMinus($arr);

fclose($stdin);


/**
 * @title Repeated String
 * @link https://www.hackerrank.com/challenges/repeated-string
 * @status solved
 */

// Complete the repeatedString function below.
function repeatedString($s, $n) {
    $strLength = strlen($s);

    $needLetter = 'a';
    $repeatingCount = floor($n / $strLength);

    $filteredArray = array_filter(str_split($s), function ($letter) use ($needLetter) {
        return $letter === $needLetter;
    });

    $lettersInOneString = count($filteredArray);

    $subStringCount = 0;
    if (($repeatingCount * $strLength) < $n) {
        $subString = $n - ($repeatingCount * $strLength);
        $subString = substr($s, 0, $subString);

        $substringArray = array_filter(str_split($subString), function ($letter) use ($needLetter) {
            return $letter === $needLetter;
        });

        $subStringCount = count($substringArray);
    }

    return ($lettersInOneString * $repeatingCount) + $subStringCount;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

$s = '';
fscanf($stdin, "%[^\n]", $s);

fscanf($stdin, "%ld\n", $n);

$result = repeatedString($s, $n);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Save the Prisoner!
 * @link https://www.hackerrank.com/challenges/save-the-prisoner
 * @status solved
 */

// Complete the saveThePrisoner function below.
function saveThePrisoner($n, $m, $s) {
    return ((($s + $m - 2) % $n) + 1);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $t);

for ($t_itr = 0; $t_itr < $t; $t_itr++) {
    fscanf($stdin, "%[^\n]", $nms_temp);
    $nms = explode(' ', $nms_temp);

    $n = intval($nms[0]);

    $m = intval($nms[1]);

    $s = intval($nms[2]);

    $result = saveThePrisoner($n, $m, $s);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);


/**
 * @title Simple Array Sum
 * @link https://www.hackerrank.com/challenges/simple-array-sum
 * @status solved
 */

/*
 * Complete the simpleArraySum function below.
 */
function simpleArraySum($ar) {
    /*
     * Write your code here.
     */
    return array_sum($ar);
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $ar_count);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = simpleArraySum($ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Sock Merchant
 * @link https://www.hackerrank.com/challenges/sock-merchant
 * @status solved
 */

// Complete the sockMerchant function below.
function sockMerchant($n, $ar) {
    $count = 0;
    $socks = [];
    foreach ($ar as $number) {
        $socks[$number]++;
    }

    foreach ($socks as $sock) {
        $count += floor($sock / 2);
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = sockMerchant($n, $ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);



/**
 * @title Two Strings
 * @link https://www.hackerrank.com/challenges/two-strings
 * @status solved
 */

// Complete the twoStrings function below.
function twoStrings($s1, $s2) {
    $s1 = str_split($s1);
    $s2 = str_split($s2);


    return count(array_intersect($s1, $s2)) > 0 ? 'YES' : 'NO';
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $q);

for ($q_itr = 0; $q_itr < $q; $q_itr++) {
    $s1 = '';
    fscanf($stdin, "%[^\n]", $s1);

    $s2 = '';
    fscanf($stdin, "%[^\n]", $s2);

    $result = twoStrings($s1, $s2);

    fwrite($fptr, $result . "\n");
}

fclose($stdin);
fclose($fptr);



/**
 * @title Time Conversion
 * @link https://www.hackerrank.com/challenges/time-conversion
 * @status solved
 */

/*
 * Complete the timeConversion function below.
 */
function timeConversion($s) {
    preg_match('/([0-9]+):([0-9]+):([0-9]+)(AM|PM)/', $s, $times);
    $hours = $times[1];
    $minutes = $times[2];
    $seconds = $times[3];
    $isPM = $times[4] === 'PM';

    $hours = ((!$isPM && $hours >= 12) || ($isPM && $hours < 12)) ? $hours + 12 : $hours;
    if ($hours === 24) {
        $hours = '00';
    }

    return $hours . ':' . $minutes . ':' . $seconds;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$__fp = fopen("php://stdin", "r");

fscanf($__fp, "%[^\n]", $s);

$result = timeConversion($s);

fwrite($fptr, $result . "\n");

fclose($__fp);
fclose($fptr);


/**
 * @title The Time in Words
 * @link https://www.hackerrank.com/challenges/the-time-in-words
 * @status solved
 */

// Complete the timeInWords function below.
function timeInWords($h, $m) {
    $hours = [1 => 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'];
    $minutes = [
        'o\' clock',
        'one minute',
        'two minutes',
        'three minutes',
        'four minutes',
        'five minutes',
        'six minutes',
        'seven minutes',
        'eight minutes',
        'nine minutes',
        'ten minutes',
        'eleven minutes',
        'twelve minutes',
        'thirteen minutes',
        'fourteen minutes',
        'quarter',
        'sixteen minutes',
        'seventeen minutes',
        'eighteen minutes',
        'nineteen minutes',
        'twenty minutes',
        'twenty one minutes',
        'twenty two minutes',
        'twenty three minutes',
        'twenty four minutes',
        'twenty five minutes',
        'twenty six minutes',
        'twenty seven minutes',
        'twenty eight minutes',
        'twenty nine minutes',
        'half',
    ];

    if ($m === 0) {
        return $hours[$h] . ' ' . $minutes[$m];
    } elseif ($m > 30) {
        $m = 60 - $m;

        return $minutes[$m] . ' to ' . $hours[$h + 1];
    } else {
        return $minutes[$m] . ' past ' . $hours[$h];
    }
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $h);

fscanf($stdin, "%d\n", $m);

$result = timeInWords($h, $m);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title The Hurdle Race
 * @link https://www.hackerrank.com/challenges/the-hurdle-race
 * @status solved
 */

// Complete the hurdleRace function below.
function hurdleRace($k, $height) {
    $maxHeight = max($height);

    $doses = $maxHeight - $k;

    return $doses > 0 ? $doses : 0;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $nk_temp);
$nk = explode(' ', $nk_temp);

$n = intval($nk[0]);

$k = intval($nk[1]);

fscanf($stdin, "%[^\n]", $height_temp);

$height = array_map('intval', preg_split('/ /', $height_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = hurdleRace($k, $height);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




/**
 * @title Staircase
 * @link https://www.hackerrank.com/challenges/staircase
 * @status solved
 */

// Complete the staircase function below.
function staircase($n) {
    for ($i = 1; $i <= $n; $i++) {
        print str_pad(str_repeat('#', $i), $n, ' ', STR_PAD_LEFT) . PHP_EOL;
    }
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

staircase($n);

fclose($stdin);



 /**
 * @title Sock Merchant
 * @link https://www.hackerrank.com/challenges/sock-merchant
 * @status solved
 */

// Complete the sockMerchant function below.
function sockMerchant($n, $ar) {
    $count = 0;
    $socks = [];
    foreach ($ar as $number) {
        $socks[$number]++;
    }

    foreach ($socks as $sock) {
        $count += floor($sock / 2);
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = sockMerchant($n, $ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr); 



/**
 * @title Sock Merchant
 * @link https://www.hackerrank.com/challenges/sock-merchant
 * @status solved
 */

// Complete the sockMerchant function below.
function sockMerchant($n, $ar) {
    $count = 0;
    $socks = [];
    foreach ($ar as $number) {
        $socks[$number]++;
    }

    foreach ($socks as $sock) {
        $count += floor($sock / 2);
    }

    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH"), "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $n);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = sockMerchant($n, $ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);
 ?>