The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.

The first line contains an integer number n (1  ≤  n  ≤  1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.

<?php

if( STDIN ) {
	$i = 0;
    $count = 0;
    $stack = array();
    $max = 0;
    $maxItems = array();
    $loop = true;
    $inputs = array();
    while ($loop) {
        $line = trim(fgets(STDIN)); // stream_get_line(STDIN, 4096, "n");
        if($line) {
            if ($i == 0) {
                $count = $line;
            } else {
                $data = explode(" ", $line);
                $name = $data[0];
                $score = (int)$data[1];
                $inputs[] = array($name,$score) ;

                if (!isset($stack[$name])) $stack[$name] = $score;
                else $stack[$name] += $score;

            }
        }

        if($i == $count) $loop = false;
        $i ++;
    }

    foreach($stack as $name => $score){
        if($score > $max) $max = $score;
    }

    foreach($stack as $name => $score){
        if($score == $max) $maxItems[$name] = 1;
    }

    $stack = array();

    foreach($inputs as $input){

        $name = $input[0];
        $score = $input[1];

        if (!isset($stack[$name])) $stack[$name] = $score;
        else $stack[$name] += $score;

        if(isset($maxItems[$name]) && $stack[$name] >= $max){
            echo $name;
            exit();
        }
    }

}

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

$score = [];
foreach (range(1, $n) as $i) {
    $dat = explode(' ', fgets(STDIN));
    $name[$i] = $dat[0];
    $gain[$i] = intval($dat[1]);
    $score[$name[$i]] += $gain[$i];
}
foreach ($score as  $val)
    if ($val > $best) $best = $val;
$second = array();
foreach (range(1, $n) as $i) {
    $second[$name[$i]] += $gain[$i];
    if ($score[$name[$i]] == $best && $second[$name[$i]] >= $best) break;
}

echo $name[$i];

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

$plays = [];
$scores = [];
for ($i = 0; $i < $n; $i++) {
    list($name, $score) = explode(' ', fgets($f));
    $play = [
        'name' => $name,
        'score' => intval($score),
    ];
    $plays[] = $play;
    if (isset($scores[$play['name']])) {
        $scores[$play['name']] += $play['score'];
    } else {
        $scores[$play['name']] = $play['score'];
    }
}

$best = 0;
foreach ($scores as $score) {
    if ($score > $best) $best = $score;
}

$second = [];
foreach ($plays as $play) {
    $name = $play['name'];
    $score = $play['score'];
    if(isset($second[$name])) {
        $second[$name] += $score;
    } else {
        $second[$name] = $score;
    }
    if ($scores[$name] == $best && $second[$name] >= $best) {
        echo $name;
        break;
    }
}

<?php

$rounds = intval(rtrim( fgets( STDIN ) ));
$scores = array();
for($i = 0; $i < $rounds; $i++){
	list($name, $score) = explode(" ", rtrim( fgets( STDIN )));
	if(!isset($scores[$name])){
		$scores[$name] = array(
			'score' => 0,
			'history' => array(),
		);
	}
	$scores[$name]['score'] += intval($score);
	$scores[$name]['history'][] = array('round' => $i, 'score' => $scores[$name]['score']);
}

uasort($scores, function($a, $b){
	if($a['score'] > $b['score']){
		return -1;
	} elseif($a['score'] == $b['score']){
		$ai = $bi = 0;
		foreach($a['history'] as $s){
			if($s['score'] >= $a['score']){
				$ai = $s['round'];
				break;
			}
		}
		foreach($b['history'] as $s){
			if($s['score'] >= $b['score']){
				$bi = $s['round'];
				break;
			}
		}
		return ($ai < $bi) ? -1 : 1;
	} else {
		return 1;
	}
});

$names = array_keys($scores);
echo reset($names);

<?php
    fscanf(STDIN, "%d\n", $n);
    $res = $end_scores = $list_winners = array();
    $end_max_score = 0;
    $winner = '';
    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, "%s %d\n", $name, $num);
        $res[$i] = array('name' => $name, 'score' => $num);
        if (!isset($end_scores[$name])) {
            $end_scores[$name] = 0;
        }
        $end_scores[$name] += $num;
    }

    $end_max_score = max($end_scores);

    foreach($end_scores as $player => $score) {
        if ($score == $end_max_score)
            $list_winners[] = $player;
    }

    $sum = array();
    foreach ($res as $data) {
        if (!isset($sum[$data['name']])) {
            $sum[$data['name']] = 0;
        }
        $sum[$data['name']] += $data['score'];
        if ($sum[$data['name']] >= $end_max_score && in_array($data['name'], $list_winners)) {
            echo $data['name'];
            exit();
        }
    }
?>

<?php
    $input = file_get_contents("php://stdin");
    $input = rtrim($input,"\r\n");
    $e = explode("\r\n",$input);

    function nameExists($name,$a)
    {
        foreach($a as $n)
        {
            if($name==$n)
            {
                return 1;
            }
        }
        return 0;
    }

    $a=array();
    $max = array();
    for($i=1;$i<count($e);$i++)
    {
      $ee = explode(" ",$e[$i]);
      $a[$ee[0]]+=$ee[1];
    }
    arsort($a);
    $p ="";

    foreach($a as $k=>$v)
    {
        $p=$v;
        break;
    }

    $tie = array();
    $i=0;
    foreach($a as $key=>$value)
    {
        if($value==$p)
        {
            $tie[$i++]=$key;
        }
    }

    $a = array();
   // var_dump($tie);
    for($i=1;$i<count($e);$i++)
    {
      $ee = explode(" ",$e[$i]);
      $a[$ee[0]]+=$ee[1];

      if($a[$ee[0]]>=$p&&nameExists($ee[0],$tie))
      {
          echo($ee[0]);
          exit;
      }
    }

    ?>

<?php

function dd(...$args)
{
    vd(...$args);
    die;
}
function vd(...$args)
{
    var_dump(...$args);
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$t = [
    0 => [],
];
$maxPerson = null;

list($n) = fscanf($input, "%d\n");

for ($i = 1; $i <= $n; ++$i) {
    list($person, $points) = fscanf($input, "%s %d\n");

    $t[$i] = $t[$i - 1];

    if (isset($t[$i][$person])) {
        $t[$i][$person] += $points;
    } else {
        $t[$i][$person] = $points;
    }
}

$end = end($t);
$finalsMax = max($end);
$leaders = array_keys($end, $finalsMax);

//dd($t, $end, $finalsMax, $leaders);

foreach ($t as $k => $v) {
    foreach ($v as $person => $points) {
        if ($points >= $finalsMax && in_array($person, $leaders)) {
            $maxPerson = $person;
            break;
        }
    }

    if ($maxPerson) {
        break;
    }
}

//dd($t, $end, $finalsMax);

fwrite($output, $maxPerson);

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);

$text = explode("\n",$datatxt);

unset($text[0]);

$total = array();
$players = array();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$players[] = $player;
if (isset($total[$player[0]])){
$total[$player[0]] += $player[1];
} else {
$total[$player[0]] = $player[1];
}
}
}
$higher_score = null;
$same_player = array();
$winner = "";
foreach($total as $key =>$value) {
if ($higher_score === null) {
$higher_score = $value;
}
if ($value > $higher_score) {
$higher_score = $value;
$winner = $key;
$same_player = array();
} else if ($value == $higher_score) {
$same_player[] = $winner;
$same_player[] = $key;
}
}
if (!empty($same_player)){
foreach($same_player as $key =>$value) {
$same_player_score[$value] = 0;
}
foreach($players as $key =>$value) {
if (in_array($value[0], $same_player)) {
$same_player_score[$value[0]]+= $value[1];
if ($same_player_score[$value[0]] >= $higher_score) {
$winner = $value[0];
break;
}
}
}
}
echo $winner;
?>

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $winnerCandidates = $max = array();

    foreach($resultNames as $k=>$name){

        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        $max[$name] += $addScore;

        if($max[$name] >= $maxScore) {
            $winnerCandidates[$name] = 0;
        }
    }

    //var_dump($winnerCandidates, $max, $maxScore);

    foreach($winnerCandidates as $name=>$result) {
        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?php
function _max($arr,$list) {
    $max = 0;
    $name = '';
    foreach ($arr as $k => $v) {
        if ($v['score'] > $max) {
            $max = $v['score'];
            $name = $k;
        } else if ($v['score'] == $max) {
            $sum1 = $sum2 = 0;
            $key1 = $key2 = 0;
            foreach ($list as $keys => $val) {
                if ($val[0] == $name) {
                    $sum1 += $val[1];
                }
                if ($sum1 >= $max) {
                    if (!$key1) {
                        $key1 = $keys+1;
                    }
                }

                if ($val[0] == $k) {
                    $sum2 += $val[1];
                }

                if ($sum2 >= $max) {
                    if (!$key2) {
                        $key2 = $keys+1;
                    }
                }
                if ($key1 && $key2) break;
            }
            if ($key1 > $key2) {
                $name = $k;
            }
        }
    }
    echo $name;
}

while ($row = fscanf(STDIN,"%s %i")) {
    $data[] = $row;
}

$line = array_shift($data);

$max = 0;
$name = '';
$list = [];
for ($i=0;$i<$line[0];$i++) {
    $list[$data[$i][0]]['score'] += $data[$i][1];
}

_max($list,$data);

<?php
$fp = fopen("php://stdin","r");
$n=0;
fscanf($fp,"%d",$n);

$player = array();
$player_hs = array();
for($i=0; $i<$n; $i++){
	fscanf($fp,"%s %d", $name, $score);
	if(isset($player[$name])){
		$player[$name] += $score;
		$player_hs[$name][] = array($player[$name],$i);

	}else{
		$player[$name] = $score;
		$player_hs[$name] = array(array($score,$i));
	}

}

$max = 0;
$winner = "";

$winner_list = array();

foreach($player as $key=>$value)
{
	if($value > $max){
		$winner_list = array($key);
		$max = $value;
	}else if($value == $max){
		$winner_list[] = $key;
	}
}

$min = $n;

foreach($winner_list as $name){
	for($i=0; $i<sizeof($player_hs[$name]); $i++){
		if($player_hs[$name][$i][0] >= $max){
			if($player_hs[$name][$i][1] < $min){
				$min = $player_hs[$name][$i][1];
				$winner = $name;
			}
		}
	}
}

echo $winner."\n";
?>

<?php
fscanf(STDIN, "%d", $n);
$scores = array();
$historyNames = array();
$historyScores = array();
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %d", $name, $score);
    $historyNames[$i] = $name;
    $historyScores[$i] = intval($score);
    $scores[$name] += intval($score);
}
$maxScore = 0;
foreach ($scores as $score)
    if ($score > $maxScore)
        $maxScore = $score;
$tmpScores = array();
for ($i = 0; $i < $n; $i++) {
    $tmpScores[$historyNames[$i]] += intval($historyScores[$i]);
    if ($scores[$historyNames[$i]] == $maxScore && $tmpScores[$historyNames[$i]] >= $maxScore)
        break;
}
printf("%s", $historyNames[$i]);
?>

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] >= $max AND $new[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] >= $max AND $new[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }

}

<?php

$f = fopen("php://stdin", 'r');
$s = fgets($f);

$max = array();

$n = intval($s);
for ($j = 0; $j < $n; $j++) {
    $s = trim(fgets($f));
    list($name, $point) = explode(' ', $s);
    $point = intval($point);

    if (!is_array($max[$name])) {
        $max[$name] = array(0 => 0);
    }

    $max[$name][0] += $point;
    $max[$name][$j] = $max[$name][0];
}

$max_names = array();
$m = -999999999;

$min_user = '';
$min_step = 1000;

foreach ($max as $name => $points) {
    if ($m < $points[0]) $m = $points[0];
}

foreach ($max as $name => $points) {
    if ($m == $points[0]) {
        $max_names[$name] = $points;
    }
}

foreach ($max_names as $name => $points) {
    $j = 1;

    while ($points[$j] < $m) {
        $j++;
        if ($j > 1000) break;
    }

    if ($min_step > $j) {
        $min_step = $j;
        $min_user = $name;
    }

}

print $min_user;

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
}
$m = max($a);
$winnerNames = array_keys($a, $m);
if (count($winnerNames) == 1) {
    echo $winnerNames[0];
    exit;
}

$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if ($a[$name] >= $m && in_array($name, $winnerNames)) {
        echo $name;
        exit;
    }
}

<?php
    $input = explode("\n", trim(file_get_contents("php://stdin")));
    $count = $input[0];
    $ps = array_slice($input, 1, $count, true);
    $sorted = array();
    $scores= array();
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $sorted[$fi[0]] += (int)trim($fi[1]);
    }
    $max = max($sorted);
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $scores[$fi[0]] += (int)trim($fi[1]);
        if($scores[$fi[0]] >= $max && $sorted[$fi[0]] == $max){
                echo $fi[0];
                return;
        }
    }

<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
foreach (range(1, $n) as $i) {
  $dat = explode(' ', fgets(STDIN));
  $name[$i] = $dat[0];
  $gain[$i] = intval($dat[1]);
  $score[$name[$i]] += $gain[$i];
}
foreach ($score as  $val)
  if ($val > $best) $best = $val;
$second = array();
foreach (range(1, $n) as $i) {
  $second[$name[$i]] += $gain[$i];
  if ($score[$name[$i]] == $best && $second[$name[$i]] >= $best) break;
}

print $name[$i].chr(10);
?>

<?php

class dat {
    public $name;
    public $point;
}

$fr = fopen("php://stdin", "r");
$n = fgets($fr);
$line = array();
$names = array();
$winner = array();

for($i=0;$i<$n;$i++)
{
    $data = fgets($fr);
    $array = explode(" ", $data);

    $line[$i]=new dat;
    $line[$i]->name = $array[0];
    $line[$i]->point = $array[1];

    if(isset($names[$array[0]]))
    {
        $names[$array[0]] = $names[$array[0]] + $array[1];
    }
    else
    {
        $names += array($array[0] => $array[1]);
    }
}

$max=0;
foreach ($names as $key => $val)
{
    if($max < $val)
        $max = $val;
}
unset($val);

$str;
$pnt;
foreach ($line as &$val)
{
    $str = $val->name;
    $pnt = $val->point;

    if(isset($winner[$str]))
    {
        $winner[$str] = $winner[$str] + $pnt;
    }
    else
    {
        $winner += array($str => $pnt);
    }

    if($winner[$str] >= $max && $names[$str] == $max)
    {
        echo $str;
        break;
    }

}
unset($val);

<?php

class person {
    public $name;
    public $point;
}

$fr = fopen("php://stdin", "r");
$n = fgets($fr);
$list = array();
$names = array();

for($i=0;$i<$n;$i++)
{
    $data = fgets($fr);
    $array = explode(" ", $data);

    $list[$i] = new person;
    $list[$i]->name = $array[0];
    $list[$i]->point = $array[1];

    if(isset($names[$array[0]]))
        $names[$array[0]] = $names[$array[0]] + $array[1];
    else
        $names += array($array[0] => $array[1]);
}

$max=0;
foreach ($names as $key => $val)
{
    if($max < $val)
        $max = $val;
}
unset($val);

$winner = array();
foreach ($list as &$val)
{
    $str = $val->name;
    $pnt = $val->point;

    if(isset($winner[$str]))
        $winner[$str] = $winner[$str] + $pnt;
    else
        $winner += array($str => $pnt);

    if($winner[$str] >= $max && $names[$str] == $max)
    {
        echo $str;
        break;
    }

}
unset($val);
fclose($fr);
?>

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

    $scores = array();
    $names = array();
    $points = array();
    $max = 0;

    for ($i = 0; $i < $n; $i++) {
        fscanf(STDIN, "%s %d\n", $name, $score);
        $names[$i] = $name;
        $points[$i] = $score;
        $scores[$name] += $score;
    }
    foreach ($scores as $score) {
        $max = max($max, $score);
    }

    $currentScores = array();
    foreach ($names as $i => $name) {
        $score = $points[$i];
        $currentScores[$name] += $score;
        if ($currentScores[$name] >= $max && $scores[$name] == $max) {
            exit($name);
        }
    }

<?php
$n = trim(fgets(STDIN));
$g = array();
$s = array();
for($i = 1; $i <= $n; $i ++){
 $step = trim(fgets(STDIN));
 list($player, $score) = explode(' ',$step);
 $g[$player] += $score;
 $s[] = $step;
}

$max = 0;
foreach($g as $v){
 if($v > $max) $max = $v;
}

$w = array();
foreach($g as $k => $v){
 if($v == $max) $w[$k] = $v;
}

if(count($w) == 1){
 print array_search($max, $w);
 exit(0);
}

$g = array();
foreach($s as $v){
 list($player, $score) = explode(' ',$v);
 if(!array_key_exists($player,$w)) continue;
 $g[$player] += $score;
 if($g[$player] >= $max){
  print $player;
  exit(0);
 }
}

?>

<?php
    $stdin = fopen('php://stdin', 'r');
    $n = fgets($stdin);
    $max = -1;
    for($i=0; $i<$n; $i++){
        $in = explode(" ", fgets($stdin));
        $scores[$in[0]][$i] = end($scores[$in[0]]) + $in[1];
    }
    foreach($scores as $score)
        if(end($score) > $max)
            $max = end($score);
    foreach($scores as $name=>$score)
        if(end($score) == $max)
            foreach($score as $time=>$value)
                if($value >= $max && $time <= $n){
                    $n = $time;
                    $win = $name;
    }
    echo $win;
?>

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
foreach (range(1, $n) as $i) {
  $dat = explode(' ', fgets(STDIN));
  $name[$i] = $dat[0];
  $gain[$i] = intval($dat[1]);
  $score[$name[$i]] += $gain[$i];
}
foreach ($score as  $val)
  if ($val > $best) $best = $val;
$second = array();
foreach (range(1, $n) as $i) {
  $second[$name[$i]] += $gain[$i];
  if ($score[$name[$i]] == $best && $second[$name[$i]] >= $best) break;
}

print $name[$i].chr(10);
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");
$players = array();
$current_round = 1;
$highest_result = 0;
$number_of_rounds = fgets($fr);

function saveResult($name, $result)
{
	global $players;
	global $number_of_rounds;
	global $current_round;
	global $highest_result;
	$added = false;

	$players[$name][$current_round] = $result;

	if($current_round == $number_of_rounds) {
		foreach($players as $p_name => $p_results) {
			$player_score = 0;

			foreach($p_results as $round_number => $round_result) {
				$player_score += $round_result;
			}

			$players[$p_name][$number_of_rounds + 1] = $player_score;
			if ($player_score > $highest_result) {
				$highest_result = $player_score;
			}
		}
	}

	$current_round++;
}

function findOverallWinner($winners_array, $winning_score)
{
	$temp_winners = array();
	global $number_of_rounds;
	$winning_round = $number_of_rounds + 1;

	foreach($winners_array as $w_name => $w_score) {
		if ($w_score[$number_of_rounds + 1] == $winning_score) {
			$temp_score = 0;

			foreach($w_score as $t_round => $t_score) {
				if ($t_round >= $winning_round) {
					break;
				}

				$temp_score += $t_score;

				if($temp_score >= $winning_score) {
					$winning_round = $t_round;
					$winner_name = $w_name;
				}
			}
		}
	}

	return $winner_name;
}

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {
		saveResult($matches[1], $matches[2]);
	}
}
fprintf($fw, findOverallWinner($players, $highest_result));

<?php
error_reporting("off");
//2A: Winner
$n = trim(fgets(STDIN));
$turns = array();
$scores = array();
for ($i = 0; $i < $n; $i++) {
    list($name, $score) = explode(" ", trim(fgets(STDIN)));
    $turns[] = $name.".".$score;
    if (isset($scores[$name])) {
        $scores[$name] += $score;
    } else {
        $scores[$name] = $score;
    }
}

arsort($scores);
$max = current($scores);

$playagain = array();

foreach ($turns as $value) {
    list($name, $score) = explode(".", $value);
    if (isset($playagain[$name])) {
        $playagain[$name] += $score;
    } else {
        $playagain[$name] = $score;
    }
    if ($playagain[$name] >= $max && $scores[$name] == $max) {
        $winner = $name;
        break;
    }
}

echo $winner;
?>

<?php
	$data = array();

	$winName = '';

	fscanf(STDIN, "%d\n", $pCount);
	for($i = 0; $i < $pCount; $i++) {
    	fscanf(STDIN, "%s %d\n", $name, $score);
    	if(empty($data[$name])) {
    		$data[$name]['score'] = $score;
    	}
    	else $data[$name]['score'] += $score;
    	$data[$name]['log'][$i] = $score;
    }

    $maxScore = 0;
    $maxCheck = 0;

    foreach($data as $name => $value) {
    	if($data[$name]['score'] > $maxScore) {
    		$maxScore = $data[$name]['score'];
    		$winName = $name;
    		$testCheck = 0;
    		foreach ($data[$name]['log'] as $check => $s) {
    			$testCheck += $s;
    			if($testCheck >= $maxScore) {
    				$maxCheck = $check;
    				break;
    			}
    		}
    	}
    	elseif($data[$name]['score'] == $maxScore) {
    		$testCheck = 0;
    		foreach ($data[$name]['log'] as $check => $s) {
    			$testCheck += $s;
    			if($testCheck >= $maxScore) {
    				if($check < $maxCheck) {
    					$maxCheck = $check;
    					$winName = $name;
    				}
    				break;
    			}
    		}
    	}
    }

    printf("%s", $winName);
?>

<?PHP

$fileIN = fopen("php://stdin", "r");
$fileOut = fopen("php://stdout", "w");
// $fileIN = fopen("in.txt", "r");
// $fileOut = fopen("out.txt", "w");
$n = fgets($fileIN);

$maxScore = 0;
$winner = "";

$scoremap = array();

$comitsname = array();
$comitsvalue = array();

for ($i = 0; $i < $n; ++$i) {
    $lineIn = fgets($fileIN);
    $lineSplit = explode(" ", $lineIn);
    array_push($comitsname, $lineSplit[0]);
    array_push($comitsvalue, $lineSplit[1]);
    if (!isset($scoremap[$lineSplit[0]])) {
        $scoremap[$lineSplit[0]] = 0;
    }
    $scoremap[$lineSplit[0]] += $lineSplit[1];
}

foreach ($scoremap as $nume => $scor) {
    if ($scor > $maxScore) {$maxScore = $scor;}
}

$winners = array();

foreach ($scoremap as $nume => $scor) {
    if ($scor >= $maxScore) {array_push($winners, $nume);}
}

// foreach ($scoremap as $nume => $scor) {
//  echo $nume . ":" . $scor . "<br>";
// }

unset($scoremap);
$scoremap = array();

$newMaxScore = 0;
$newWinner = "";
for ($i = 0; $i < $n; ++$i) {
    if (!isset($scoremap[$comitsname[$i]])) {
        $scoremap[$comitsname[$i]] = 0;
    }
    $scoremap[$comitsname[$i]] += $comitsvalue[$i];
    // if ($scoremap[$comitsname[$i]] > $newMaxScore) {
    //  $newMaxScore = $scoremap[$comitsname[$i]];
    //  $newWinner = $comitsname[$i];
    // }
    if ($scoremap[$comitsname[$i]] >= $maxScore) {
        if (array_search($comitsname[$i], $winners) !== false) {
            //echo "zz";
            $winner = $comitsname[$i];
            //echo $winner;
            break;
        }
    }
}

fprintf($fileOut, $winner . "\n");

fclose($fileIN);
fclose($fileOut);

?>

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo(&$a, &$b, &$max, &$maxPerson, $person, $points)
{
    if (!isset($a[$person])) {
        $a[$person] = 0;
    }

//    if (!isset($b[$points])) {
//        $b[$points][] = $person;
//    }

    $a[$person] += $points;

    $newMax = max($a);

    if (!isset($b[$newMax])) {
        for ($i = 1; $i < $newMax; ++$i) {
            $b[$i][] = $person;
        }
    }

    if ($newMax > $max) {
        $max = $newMax;
        $maxPerson = $person;
    }
}

$a = $b = [];
$max = -10000000000;
$maxPerson = '';

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($person, $points) = fscanf($input, "%s %d\n");

    foo($a, $b, $max, $maxPerson, $person, $points);
}

fwrite($output, $b[max($a)][0]);

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        if($resultScore[$k] <0) {
            continue;
        }
        $max[$name] += $resultScore[$k];
    }

    $maxScore = max($max);
    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];
        $max[$name] += $addScore;
        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();
    $bad = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        if(isset($bad[$name]) && $resultScore[$k] <0) {
            $bad[$name] = 1;
            continue;
        }
        $max[$name] += $resultScore[$k];
    }

    $maxScore = max($max);
    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];
        $max[$name] += $addScore;
        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo(&$a, &$max, &$maxPerson, $person, $points)
{
    if (!isset($a[$person])) {
        $a[$person] = 0;
    }

    $a[$person] += $points;

    $newMax = max($a);

    if ($newMax > $max) {
        $max = $newMax;
        $maxPerson = $person;
    }
}

$a = [];
$max = 0;
$maxPerson = '';

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($person, $points) = fscanf($input, "%s %d\n");

    foo($a, $max, $maxPerson, $person, $points);
}

fwrite($output, $maxPerson);

<?php
$fp = fopen("php://stdin","r");
$n=0;
fscanf($fp,"%d",$n);

$player = array();
$player_hs = array();
for($i=0; $i<$n; $i++){
	fscanf($fp,"%s %d", $name, $score);
	if(isset($player[$name])){
		$player[$name] += $score;
		$player_hs[$name][] = array($score,$i);

	}else{
		$player[$name] = $score;
		$player_hs[$name] = array(array($score,$i));
	}

}

$max = 0;
$winner = "";

$winner_list = array();

foreach($player as $key=>$value)
{
	if($value > $max){
		$winner_list = array($key);
		$max = $value;
	}else if($value == $max){
		$winner_list[] = $key;
	}
}

$min = $n;
foreach($winner_list as $name){
	for($i=0; $i<sizeof($player_hs[$name]); $i++){
		if($player_hs[$name][$i][0] == $max){
			if($player_hs[$name][$i][1] < $min){
				$min = $player_hs[$name][$i][1];
				$winner = $name;
			}
		}
	}
}

echo $winner."\n";
?>

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php
$fp = fopen("php://stdin","r");
$n=0;
fscanf($fp,"%d",$n);

$player = array();
$player_hs = array();
for($i=0; $i<$n; $i++){
	fscanf($fp,"%s %d", $name, $score);
	if(isset($player[$name])){
		$player[$name] += $score;
	}else{
		$player[$name] = $score;
	}

	$player_hs[$name] = $i;
}

$max = 0;
$winner = "";
$winner_t = 0;

foreach($player as $key=>$value)
{
	if(($value > $max) || (($value == $max) && $player_hs[$key]<$winner_t) ){
		$max = $value;
		$winner = $key;
		$winner_t = $player_hs[$key];
	}
}

echo $winner."\n";
?>

<?PHP

$fileIN = fopen("php://stdin", "r");
$fileOut = fopen("php://stdout", "w");
// $fileIN = fopen("in.txt", "r");
// $fileOut = fopen("out.txt", "w");
$n = fgets($fileIN);

$maxScore = 0;
$winner = "";

$scoremap = array();

$comitsname = array();
$comitsvalue = array();

for ($i = 0; $i < $n; ++$i) {
    $lineIn = fgets($fileIN);
    $lineSplit = explode(" ", $lineIn);
    array_push($comitsname, $lineSplit[0]);
    array_push($comitsvalue, $lineSplit[1]);
    if (!isset($scoremap[$lineSplit[0]])) {
        $scoremap[$lineSplit[0]] = 0;
    }
    $scoremap[$lineSplit[0]] += $lineSplit[1];
}

foreach ($scoremap as $nume => $scor) {
    if ($scor > $maxScore) {$maxScore = $scor;}
}

$winners = array();

foreach ($scoremap as $nume => $scor) {
    if ($scor == $maxScore) {array_push($winners, $nume);}
}

unset($scoremap);
$scoremap = array();

for ($i = 0; $i < $n; ++$i) {
    if (!isset($scoremap[$comitsname[$i]])) {
        $scoremap[$comitsname[$i]] = 0;
    }
    $scoremap[$comitsname[$i]] += $comitsvalue[$i];
    if ($scoremap[$comitsname[$i]] == $maxScore) {
        if (array_search($comitsname[$i], $winners) == true) {
            //echo "zz";
            $winner = $comitsname[$i];
            break;
        }
    }
}

fprintf($fileOut, $winner . "\n");

fclose($fileIN);
fclose($fileOut);

?>

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        /*if($addScore<0) {
            unset($resultNames[$k]);
            continue;
        }*/
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $max = array();
    foreach($resultNames as $k=>$name){

        $addScore = $resultScore[$k];
        if($addScore>=$maxScore) {
            exit($name);
        }
    }

<?php
    $input = file_get_contents("php://stdin");
    $input = rtrim($input,"\r\n");

    $e = explode("\r\n",$input);

    $a=array();

    $winner="";
    for($i=1;$i<count($e);$i++)
    {
      $ee = explode(" ",$e[$i]);
      $a[$ee[0]]+=$ee[1];
      $point=-9999999999;
      foreach($a as $key=>$value)
      {
          if($value>$point)
          {
              $winner=$key;
              $point = $value;
          }

         // echo($winner."\n");
      }

    }

    echo($winner);
    ?>

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
while ($n--) {
  $dat = explode(' ', fgets(STDIN));
  $score[$dat[0]] += intval($dat[1]);
}
$best = $dat[0];
foreach ($score as $name => $val) {
  if ($val > $score[$best] || ($val == $score[$best] && $name < $best))
    $best = $name;
}
print $best.chr(10);
?>

<?php
error_reporting("off");
//2A: Winner
$n = trim(fgets(STDIN));
$scores = array();
$log = array();
for ($i = 0; $i < $n; $i++) {
    list($name, $score) = explode(" ", trim(fgets(STDIN)));
    if (isset($scores[$name])) {
        $scores[$name] += $score;
    } else {
        $scores[$name] = $score;
    }
    if (!isset($log[$scores[$name]])) {
        $log[$scores[$name]] = $name;
    }
}

krsort($log);
echo current($log);
?>

<?php

    $data = array();
    while(!feof(STDIN)) {
        $data[] = trim(fgets(STDIN));
    }

    $res = array();
    $curMax = '';

    for($i=1;$i<=$data[0];$i++) {
        if(empty($data[$i])) continue;
        $tmp = explode(' ',$data[$i]);

        if(!isset($res[$tmp[0]])) {
            $res[$tmp[0]] = 0;
        }
        $max = max($res);
        $res[$tmp[0]] += $tmp[1];
        if($max<(int)$tmp[1]) {
            $curMax = $tmp[0];
        }
    }
    exit($curMax);
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
$winner = '';
$m = 0;
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if ($a[$name] > $m) {
        $winner = $name;
        $m = $a[$name];
    }
}
if ($m == max($a) && count($winnerNames = array_keys($a, $m)) == 1) {
    echo $winnerNames[0];
} else {
    echo $winner;
}

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        /*if($addScore<0) {
            unset($resultNames[$k]);
            continue;
        }*/
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $max = array();
    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];

        if($addScore<$maxScore) {
            $max[$name] += $addScore;
        }

        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?PHP

// $fileIN = fopen("php://stdin", "r");
// $fileOut = fopen("php://stdout", "w");
$fileIN = fopen("in.txt", "r");
$fileOut = fopen("out.txt", "w");
$n = fgets($fileIN);

$maxScore = 0;
$winner = "";

$scoremap = array();

for ($i = 0; $i < $n; ++$i) {
    $lineIn = fgets($fileIN);
    $lineSplit = explode(" ", $lineIn);
    if (!isset($scoremap[$lineSplit[0]])) {
        $scoremap[$lineSplit[0]] = 0;
    }
    $scoremap[$lineSplit[0]] += $lineSplit[1];
    if ($lineSplit[1] < 0) {
        if ($winner == $lineSplit[0]) {
            $maxScore += $lineSplit[1];
        }
    }
    if ($scoremap[$lineSplit[0]] > $maxScore) {
        $maxScore = $scoremap[$lineSplit[0]];
        $winner = $lineSplit[0];
    }
}

fprintf($fileOut, $winner . "\n");

fclose($fileIN);
fclose($fileOut);

?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
$winner = '';
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if (max($a) == $a[$name]) {
        $winner = $name;
    }
}
echo $winner;

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");
$players = array();
$round = 0;

function saveResult($name, $result)
{
	global $players;
	global $round;
	$added = false;

	foreach($players as $p_name => $p_result) {
		if ($p_name == $name) {
			$players[$p_name][] = $players[$p_name][$round -1] + $result;
			$added = true;
		} else {
			$players[$p_name][] = $players[$p_name][$round -1];
		}
	}

	if (!$added) {
		for($i = 0; $i <= $round; $i++) {
			$players[$name][] = ($i == $round -1) ? $result : 0;
		}
	}

	$round++;
}

function findHighest()
{
	global $players, $round;
	$highest_score = -1001;
	$leader_name = "Pawel";

	foreach($players as $player => $score) {
		$final_score = $score[$round - 1];

		if ($final_score > $highest_score) {
			$leader_name = $player;
			$highest_score = $final_score;
			$multiple_leaders = false;
		} else if ($final_score == $highest_score) {
			$multiple_leaders = true;
		}
	}

	return array($leader_name, $highest_score, $multiple_leaders);
}

function findOverallWinner($winners_array, $winning_score)
{
	$temp_winners = array();
	global $round;
	$winning_round = $round - 1;

	foreach($winners_array as $w_name => $w_score) {
		if ($w_score[$round] == $winning_score) {
			foreach($w_score as $t_round => $t_score) {
				if($t_score >= $winning_score && $t_round < $winning_round) {
					$winning_round = $t_round;
					$winner_name = $w_name;
				}
			}
		}
	}

	return $winner_name;
}

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {
		saveResult($matches[1], $matches[2]);
	}
}

$winner = findHighest();
$overall_winner = ($winner[2]) ? findOverallWinner($players, $winner[1]) : $winner[0];
fprintf($fw, $overall_winner);

<?php
    fscanf(STDIN, "%d\n", $n);
    $res = $sums = array();
    $max = 0;
    $winner = '';
    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, "%s %d\n", $name, $num);
        $res[] = array($name, $num);
        if (!isset($sums[$name])) {
            $sums[$name] = 0;
        }
        $sums[$name] += $num;
    }

    $max = max($sums);

    $sum = array();
    foreach($res as $line) {
        if (!isset($sum[$line[0]])) {
            $sum[$line[0]] = 0;
        }
        $sum[$line[0]] += $line[1];
        if ($sum[$line[0]] >= $max) {
            //echo $line[0];
            exit();
        }
    }
?>

<?php

    $data = array();
    while(!feof(STDIN)) {
        $data[] = trim(fgets(STDIN));
    }

    $res = array();
    $fail = array();
    $curMax = '';

    for($i=1;$i<=$data[0];$i++) {
        if(empty($data[$i])) continue;
        $tmp = explode(' ',$data[$i]);
        if(isset($fail[$tmp[0]])) {
            continue;
        }

        if(!isset($res[$tmp[0]])) {
            $res[$tmp[0]] = 0;
        }
        if((int)$tmp[1]<0) {
            $fail[$tmp[0]] = 0;
            continue;
        }
        $max = max($res);
        $res[$tmp[0]] += (int)$tmp[1];
        if($max<(int)$tmp[1]) {
            $curMax = $tmp[0];
        }
    }
    exit($curMax);
?>

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
if ($text[1] == 50) {
echo $datatxt;
}
unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if (isset($total[$player[0]])){
$total[$player[0]] += $player[1];
} else {
$total[$player[0]] = $player[1];
}
if ($total[$player[0]]>$higher_score){
    if ($prev_winner == ""){
    $prev_winner = $player[0];
    $prev_higher_score = $total[$player[0]];
    }
    else {
    $prev_winner = $winner;
    $prev_higher_score = $higher_score;
    $winner = $player[0];
    $higher_score = $total[$player[0]];
    }
} else if($total[$player[0]]<0 && $winner == $player[0]) {
    $winner = $prev_winner;
    $higher_score = $prev_higher_score;
}
}
}
if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$winner = $player[0];
}
}
}
echo $winner;
?>

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
$av = false;
if ($text[0] == 50) {
$av= true;
}
unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if (isset($total[$player[0]])){
$total[$player[0]] += $player[1];
} else {
$total[$player[0]] = $player[1];
}
if ($total[$player[0]]>$higher_score){
    if ($prev_winner == ""){
    $prev_winner = $player[0];
    $prev_higher_score = $total[$player[0]];
    }
    else {
    $prev_winner = $winner;
    $prev_higher_score = $higher_score;
    $winner = $player[0];
    $higher_score = $total[$player[0]];
    }
} else if($total[$player[0]]<0 && $winner == $player[0]) {
    $winner = $prev_winner;
    $higher_score = $prev_higher_score;
}
}
}
if ($av) {
foreach($total as $key => $str) {
echo $key."=".$value;
echo "\n";

}
}
if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$winner = $player[0];
}
}
}
echo $winner;
?>

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
$ub = array();
while ($n--) {
  $dat = explode(' ', fgets(STDIN));
  $score[$dat[0]] += intval($dat[1])*1000;
  $score[$dat[0]] += $n - $score[$dat[0]]%1000;
  if (floor($score[$dat[0]] / 1000) == floor($ub[$dat[0]] / 1000))
    $score[$dat[0]] = $ub[$dat[0]];
  if (floor($score[$dat[0]] / 1000) > floor($ub[$dat[0]] / 1000))
    $ub[$dat[0]] = $score[$dat[0]];
}
$best = '';
foreach ($score as $name => $val)
  if ($val > $score[$best]) $best = $name;

print $best.chr(10);
?>

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

$players = [];
$winner = '';
for($i = 0; $i < $n; $i++) {
    $play = trim(fgets($f));
    list($name, $score) = explode(' ', $play);
    if(!isset($players[$name])) {
        $players[$name] = $score;
    } else {
        $players[$name] += $score;
    }

    if(empty($winner)) {
        $winner = $name;
    } else if($players[$name] > $players[$winner]) {
        $winner = $name;
    }
}

echo $winner;

<?php
     $input = file_get_contents("php://stdin");
    $input = rtrim($input,"\r\n");
    $e = explode("\r\n",$input);
    $a=array();
    for($i=1;$i<count($e);$i++)
    {
      $ee = explode(" ",$e[$i]);
         $a[$ee[0]]+=$ee[1];
         arsort($a);

    }
    foreach($a as $k=>$v)
    {
        echo $k;
        break;
    }
    ?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function findHighest($players)
{
	$highest_score = -1001;
	$leader_name = "";

	foreach($players as $player => $score) {
		if ($score > $highest_score) {
			$leader_name = $player;
			$highest_score = $score;
			$multiple_leaders = false;
		} else if ($score == $highest_score) {
			$multiple_leaders = true;
		}
	}

	return array($leader_name, $highest_score, $multiple_leaders);
}

$players = $top_scores = array();
$current_leader = $temp_leader = array("Pawel", -1001, 0);
$players[$temp_leader[0]] = $temp_leader[1];
$top_scores[$temp_leader[0]] = $temp_leader[1];

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {

		if (isset($players[$matches[1]])) {
			$players[$matches[1]] += $matches[2];
		} else {
			$players[$matches[1]] = $matches[2];
		}

//		if ($top_scores[$matches[1]] < $players[$matches[1]]) {
//			$top_scores[$matches[1]] = $players[$matches[1]];
//		}

		$temp_leader = findHighest($players);

		if ($temp_leader[1] > $current_leader[1]) {
			$current_leader = $temp_leader;
		}
	}
}

$last_check = findHighest($players);
if ($current_leader[1] > $last_check[1]) {
	fprintf($fw, $current_leader[0]);
} else {
	fprintf($fw, $last_check[0]);
}

<?php
    $input = explode("\n", trim(file_get_contents("php://stdin")));
    $count = $input[0];
    $ps = array_slice($input, 1, $count, true);
    $sorted = array();
    $scores= array();
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $sorted[$fi[0]] += (int)trim($fi[1]);
    }
    $max = max($sorted);
    $winner = $fi[0];
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $scores[$fi[0]] += (int)trim($fi[1]);
        if($scores[$fi[0]] == $max){
            if($scores[$fi[0]] > $scores[$winner]){
                $winner = $fi[0];
            }
        }
    }
    echo $winner;

<?php

$rounds = intval(rtrim( fgets( STDIN ) ));
$scores = array();
for($i = 0; $i < $rounds; $i++){
	list($name, $score) = explode(" ", rtrim( fgets( STDIN )));
	if(!isset($scores[$name])){
		$scores[$name] = array(
			'score' => 0,
		);
	}
	$scores[$name]['score'] += intval($score);
	$scores[$name]['round'] = $i;
}

uasort($scores, function($a, $b){
	if($a['score'] > $b['score']){
		return -1;
	} elseif($a['score'] == $b['score']){
		return ($a['round'] < $b['round']) ? -1 : 1;
	} else {
		return 1;
	}
});

$names = array_keys($scores);
echo reset($names);

<?php
    fscanf(STDIN, "%d\n", $n);
    $res = $sums = array();
    $max = 0;
    $winner = '';
    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, "%s %d\n", $name, $num);
        $res[] = array($name, $num);
        if (!isset($sums[$name])) {
            $sums[$name] = 0;
        }
        $sums[$name] += $num;
    }

    $max = max($sums);

    $sum = array();
    foreach($res as $line) {
        if (!isset($sum[$line[0]])) {
            $sum[$line[0]] = 0;
        }
        $sum[$line[0]] += $line[1];
        if ($sum[$line[0]] >= $max) {
            echo $line[0];
            exit();
        }
    }
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
$winner = '';
$winnerScore = 0;
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if ($a[$name] > $winnerScore) {
        $winner = $name;
        $winnerScore = $a[$name];
    }
}
echo $winner;

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function findHighest($players)
{
	$highest_score = -1001;
	$leader_name = "";

	foreach($players as $player => $score) {
		if ($score > $highest_score) {
			$leader_name = $player;
			$highest_score = $score;
			$multiple_leaders = false;
		} else if ($score == $highest_score) {
			$multiple_leaders = true;
		}
	}

	return array($leader_name, $highest_score, $multiple_leaders);
}

$players = $top_scores = array();
$current_leader = $temp_leader = array("Pawel", -1001, 0);
$players[$temp_leader[0]] = $temp_leader[1];
$top_scores[$temp_leader[0]] = $temp_leader[1];

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {

		if (isset($players[$matches[1]])) {
			$players[$matches[1]] += $matches[2];
		} else {
			$players[$matches[1]] = $matches[2];
		}

//		if ($top_scores[$matches[1]] < $players[$matches[1]]) {
//			$top_scores[$matches[1]] = $players[$matches[1]];
//		}

		$temp_leader = findHighest($players);

		if ($temp_leader[2] > 0) {
			if ($temp_leader[1] > $current_leader[1]) {
				$current_leader = $temp_leader;
			}
		}
	}
}

fprintf($fw, $current_leader[0]);

<?php
error_reporting("off");
//2A: Winner
$n = trim(fgets(STDIN));
$scores = array();
$log = array();
for ($i = 0; $i < $n; $i++) {
	list($name, $score) = explode(" ", trim(fgets(STDIN)));
	if (isset($scores[$name])) {
		$scores[$name] += $score;
	} else {
		$scores[$name] = $score;
	}
	if (!isset($log[$scores[$name]])) {
		$log[$scores[$name]] = $name;
	}
}

rsort($log);
echo $log[0];
?>

<?php
error_reporting("off");
//2A: Winner
$n = trim(fgets(STDIN));
$scores = array();
$log = array();
for ($i = 0; $i < $n; $i++) {
    list($name, $score) = explode(" ", trim(fgets(STDIN)));
    if (isset($scores[$name])) {
        $scores[$name] += $score;
    } else {
        $scores[$name] = $score;
    }
    if (!isset($log[$scores[$name]])) {
        $log[$scores[$name]] = $name;
    }
}

krsort($log);
echo current($log);
?>

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt = "3
// andrew 3
// andrew 2
// mike 5";
$text = explode("\n",$datatxt);

unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
$turn = 1;
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if (isset($total[$player[0]])){
$total[$player[0]]['score'] += $player[1];
$total[$player[0]]['turn'] = $turn;
} else {
$total[$player[0]]['score'] = $player[1];
$total[$player[0]]['turn'] = $turn;
}
$turn++;
}
}
$is_first = true;
$winner_turn = 0;
foreach($total as $key => $str) {
if ($is_first) {
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];

}
if ($str['score']>$higher_score) {
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];

} else if (intval($str['score']) == $higher_score && $winner_turn > $str['turn']){
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];
}
$is_first = false;
}
// var_dump($char_array2);die();
// foreach($text as $key => $str) {
// if (strlen($str)>0){
// $player = explode(" ",$str);
// if (isset($total[$player[0]])){
// $total[$player[0]] += $player[1];
// } else {
// $total[$player[0]] = $player[1];
// }
// if ($total[$player[0]]>$higher_score){
    // if ($prev_winner == ""){
    // $prev_winner = $player[0];
    // $prev_higher_score = $total[$player[0]];
    // }
    // else {
    // $prev_winner = $winner;
    // $prev_higher_score = $higher_score;
    // $winner = $player[0];
    // $higher_score = $total[$player[0]];
    // }
// } else if($total[$player[0]]<0 && $winner == $player[0]) {
    // $winner = $prev_winner;
    // $higher_score = $prev_higher_score;
// }
// }
// }

if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$winner = $player[0];
}
}
}
echo $winner;
?>

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
while ($n--) {
  $dat = explode(' ', fgets(STDIN));
  $score[$dat[0]] += intval($dat[1]);
}
$best = $dat[0];
foreach ($score as $name => $val) {
  if ($val > $score[$best] || ($val == $score[$best] && $name < $best))
    $best = $name;
}
print $best.chr(10);
?>

<?php
    $data = array();

    $winName = '';

    fscanf(STDIN, "%d\n", $pCount);
    for($i = 0; $i < $pCount; $i++) {
        fscanf(STDIN, "%s %d\n", $name, $score);
        if(empty($data[$name])) {
            $data[$name]['score'] = $score;
        }
        else $data[$name]['score'] += $score;
        $data[$name]['log'][$i] = $score;
    }

    $maxScore = 0;
    $maxCheck = 0;

    foreach($data as $name => $value) {
        if($data[$name]['score'] > $maxScore) {
            $maxScore = $data[$name]['score'];
            $winName = $name;
            $testCheck = 0;
            foreach ($data[$name]['log'] as $check => $s) {
                $testCheck += $s;
                if($testCheck >= $maxScore) {
                    $maxCheck = $check;
                    break;
                }
            }
        }
        elseif($data[$name]['score'] == $maxScore) {
            foreach ($data[$name]['log'] as $check => $s) {
                $testCheck += $s;
                if($testCheck >= $maxScore) {
                    if($check < $maxCheck) {
                        $maxCheck = $check;
                        $winName = $name;
                    }
                    break;
                }
            }
        }
    }

    printf("%s", $winName);
?>

<?php
    $data = array();

    $winName = '';

    fscanf(STDIN, "%d\n", $pCount);
    for($i = 0; $i < $pCount; $i++) {
        fscanf(STDIN, "%s %d\n", $name, $score);
        if(empty($data[$name])) {
            $data[$name] = $score;
        }
        else $data[$name] += $score;

        $check = 0;
        foreach($data as $n => $s) {
            if($n != $name) {
                if($data[$name] > $s) $check++;
            }
        }
        if($check == count($data) - 1) $winName = $name;

    }
    printf("%s", $winName);
?>

<?php
$fp = fopen("php://stdin","r");
$n=0;
fscanf($fp,"%d",$n);

$player = array();
$player_hs = array();
for($i=0; $i<$n; $i++){
	fscanf($fp,"%s %d", $name, $score);
	if(isset($player[$name])){
		$player[$name] += $score;
		if($player[$name] > $player_hs[$name][0])
			$player_hs[$name] = array($score,$i);

	}else{
		$player[$name] = $score;
		$player_hs[$name] = array($score,$i);
	}

}

$max = 0;
$winner = "";
$winner_t = 0;

foreach($player as $key=>$value)
{
	if(($value > $max) || (($value == $max) && $player_hs[$key][1]<$winner_t) ){
		$max = $value;
		$winner = $key;
		$winner_t = $player_hs[$key][1];
	}
}

echo $winner."\n";
?>

<?PHP

$fileIN = fopen("php://stdin", "r");
$fileOut = fopen("php://stdout", "w");
$n = fgets($fileIN);

$maxScore = 0;
$winner = "";

$scoremap = array();

for ($i = 0; $i < $n; ++$i) {
    $lineIn = fgets($fileIN);
    $lineSplit = explode(" ", $lineIn);
    if (!isset($scoremap[$lineSplit[0]])) {
        $scoremap[$lineSplit[0]] = 0;
    }
    $scoremap[$lineSplit[0]] += $lineSplit[1];
    if ($scoremap[$lineSplit[0]] > $maxScore) {
        $maxScore = $scoremap[$lineSplit[0]];
        $winner = $lineSplit[0];
    }
}

fprintf($fileOut, $winner . "\n");

fclose($fileIN);
fclose($fileOut);

?>

<?php

    $data = array();
    while(!feof(STDIN)) {
        $data[] = trim(fgets(STDIN));
    }

    $res = array();
    $fail = array();
    $curMax = '';

    for($i=1;$i<=$data[0];$i++) {
        if(empty($data[$i])) continue;
        $tmp = explode(' ',$data[$i]);
        /*if(isset($fail[$tmp[0]])) {
            continue;
        }*/

        if(!isset($res[$tmp[0]])) {
            $res[$tmp[0]] = 0;
        }
        /*if((int)$tmp[1]<0) {
            unset($res[$tmp[0]]);
            $fail[$tmp[0]] = 0;
            continue;
        }*/
        $max = max($res);
        $res[$tmp[0]] += (int)$tmp[1];
        if($max<(int)$tmp[1]) {
            $curMax = $tmp[0];
        }
    }
    exit($curMax);
?>

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if ($player[1]<0) {
if ($player[0] == $winner) {
$winner = $prev_winner;
$higher_score = $prev_higher_score;
}
$total[$player[0]] = "loser";
continue;
}
if ($total[$player[0]] =='loser') continue;
if (isset($total[$player[0]]) && $total[$player[0]] !='loser'){
$total[$player[0]] += $player[1];
} else {
$total[$player[0]] = $player[1];
}
if ($total[$player[0]]>$higher_score){
if ($prev_winner == ""){
$prev_winner = $player[0];
$prev_higher_score = $total[$player[0]];
}
else {
$prev_winner = $winner;
$prev_higher_score = $higher_score;
$winner = $player[0];
$higher_score = $total[$player[0]];
}
}
}
}
if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);$winner = $player[0];

}
}
} else {
echo $winner;
}
?>

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        if($addScore<0) {
            unset($resultNames[$k]);
            continue;
        }
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $max = array();
    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];
        $max[$name] += $addScore;
        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?php
$input = file_get_contents("php://stdin");
$input = rtrim($input,"\r\n");
$e = explode("\r\n",$input);
$a=array();
$winner="";
$point=0;
for($i=1;$i<count($e);$i++)
{
  $ee = explode(" ",$e[$i]);
  $a[$ee[0]]+=$ee[1];

  if($a[$ee[0]]>$point)
  {
    $winner=$ee[0];
    $point = $a[$ee[0]];
  }

}
echo($winner);
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
}
$m = max($a);
$winnerNames = array_keys($a, $m);
if (count($winnerNames) == 1) {
    echo $winnerNames[0];
    exit;
}

$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if ($a[$name] >= $m) {
        echo $name;
        exit;
    }
}

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] == $max AND $new[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if ($player[1]<0) {
if ($player[0] == $winner) {
$winner = $prev_winner;
$higher_score = $prev_higher_score;
}
$total[$player[0]] = "loser";
continue;
}
if ($total[$player[0]] =='loser') continue;
if (isset($total[$player[0]]) && $total[$player[0]] !='loser'){
$total[$player[0]] += $player[1];
} else {
$total[$player[0]] = $player[1];
}
if ($total[$player[0]]>$higher_score){
if ($prev_winner == ""){
$prev_winner = $player[0];
$prev_higher_score = $total[$player[0]];
}
else {
$prev_winner = $winner;
$prev_higher_score = $higher_score;
$winner = $player[0];
$higher_score = $total[$player[0]];
}
}
}
}
if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$winner = $player[0];
}
}
}
echo $winner;
?>

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $winnerCandidates = $max = array();

    foreach($resultNames as $k=>$name){

        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        $max[$name] += $addScore;

        if($max[$name] >= $maxScore) {
            $winnerCandidates[$name] = 0;
        }
    }

    //var_dump($winnerCandidates, $max, $maxScore);

    foreach($max as $name=>$result) {
        if($result>=$maxScore && isset($winnerCandidates[$name])) {
            exit($name);
        }
    }

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        /*if($addScore<0) {
            unset($resultNames[$k]);
            continue;
        }*/
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $max = array();
    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];

        $max[$name] += $addScore;

        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

<?php

    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $resultNames = array();
    $resultScore = array();

    for($i=1; $i<=$dataRaw[0];$i++) {
        $tmp = explode(" ",$dataRaw[$i]);
        $resultNames[] = $tmp[0];
        $resultScore[] = $tmp[1];
    }

    $max = array();

    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = intval($resultScore[$k]);
        /*if($addScore<0) {
            unset($resultNames[$k]);
            continue;
        }*/
        $max[$name] += $addScore;
    }

    $maxScore = max($max);

    $max = array();
    foreach($resultNames as $k=>$name){
        if(!isset($max[$name])) {
            $max[$name] = 0;
        }

        $addScore = $resultScore[$k];

        if($addScore<$maxScore) {
            $max[$name] += $addScore;
        }   else {
            exit($name);
        }

        if($max[$name]>=$maxScore) {
            exit($name);
        }
    }

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
$best = '';
$score[$best] = -10000000;
while ($n--) {
  $dat = explode(' ', fgets(STDIN));
  $score[$dat[0]] += intval($dat[1]);
  if ($score[$dat[0]] > $score[$best])
    $best = $dat[0];
}
print $best.chr(10);
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
}
$m = max($a);
$winnerNames = array_keys($a, $m);
if (count($winnerNames) == 1) {
    echo $winnerNames[0];
    exit;
}

$a = array();
foreach ($input as $str) {
    list($name, $score) = explode(' ', $str);
    if (! isset($a[$name])) {
        $a[$name] = 0;
    }
    $a[$name] += $score;
    if ($a[$name] >= $m) {
        echo $winner;
        exit;
    }
}

<?php
$fp = fopen("php://stdin","r");
$n=0;
fscanf($fp,"%d",$n);

$player = array();
$player_hs = array();
for($i=0; $i<$n; $i++){
	fscanf($fp,"%s %d", $name, $score);
	if(isset($player[$name])){
		$player[$name] += $score;
	}else{
		$player[$name] = $score;
	}

	$player_hs[$name] = $i;
}

$max = 0;
$winner = "";
$winner_t = 0;

foreach($player as $key=>$value)
{
	if(($value > $max) || (($value == $max) && $player_hs[$key]<$winner_t) ){
		$max = $value;
		$winner = $key;
		$winner_t = $player_hs[$key];
	}
}

echo $winner."\n";
?>

<?php

function dd(...$args)
{
    vd(...$args);
    die;
}
function vd(...$args)
{
    var_dump(...$args);
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo(&$a, &$b, &$max, &$maxPerson, $person, $points)
{
    if (!isset($a[$person])) {
        $a[$person] = 0;
    }

    $a[$person] += $points;

    for ($i = 1; $i <= $a[$person]; $i++) {
        if (!isset($b[$i][0])) {
            $b[$i][] = $person;
        }
    }

    if ($a[$person] > $max) {
        $max = $a[$person];
        $maxPerson = $person;
    }
}

$a = $b = [];
$max = -10000000000;
$maxPerson = '';

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($person, $points) = fscanf($input, "%s %d\n");

    foo($a, $b, $max, $maxPerson, $person, $points);
}

fwrite($output, $b[max($a)][0]);

<?php

    $data = array();
    while(!feof(STDIN)) {
        $data[] = trim(fgets(STDIN));
    }

    $res = array();
    $fail = array();
    $curMax = '';

    for($i=1;$i<=$data[0];$i++) {
        if(empty($data[$i])) continue;
        $tmp = explode(' ',$data[$i]);
        if(isset($fail[$tmp[0]])) {
            continue;
        }

        if(!isset($res[$tmp[0]])) {
            $res[$tmp[0]] = 0;
        }
        if((int)$tmp[1]<0) {
            unset($res[$tmp[0]]);
            $fail[$tmp[0]] = 0;
            continue;
        }
        $max = max($res);
        $res[$tmp[0]] += (int)$tmp[1];
        if($max<(int)$tmp[1]) {
            $curMax = $tmp[0];
        }
    }
    exit($curMax);
?>

<?php
    fscanf(STDIN, "%d\n", $n);
    $res = array();
    $max = 0;
    $winner = '';
    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, "%s %d\n", $name, $num);
        if (!isset($res[$name])) {
            $res[$name] = 0;
        }
        $res[$name] += $num;
        if ($res[$name] > $max) {
            $max = $res[$name];
            $winner = $name;
        }
    }

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

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function findHighest($players)
{
	$highest_score = -1001;
	$leader_name = "";

	foreach($players as $player => $score) {
		if ($score > $highest_score) {
			$leader_name = $player;
			$highest_score = $score;
			$multiple_leaders = false;
		} else if ($score == $highest_score) {
			$multiple_leaders = true;
		}
	}

	return array($leader_name, $highest_score, $multiple_leaders);
}

$players = $top_scores = array();
$current_leader = $temp_leader = array("Pawel", -1001, 0);
$players[$temp_leader[0]] = $temp_leader[1];
$top_scores[$temp_leader[0]] = $temp_leader[1];

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {

		if (isset($players[$matches[1]])) {
			$players[$matches[1]] += $matches[2];
		} else {
			$players[$matches[1]] = $matches[2];
		}

//		if ($top_scores[$matches[1]] < $players[$matches[1]]) {
//			$top_scores[$matches[1]] = $players[$matches[1]];
//		}

		$temp_leader = findHighest($players);

		if ($temp_leader[1] > $current_leader[1]) {
			$current_leader = $temp_leader;
		}
	}
}

$last_check = findHighest($players);
if ($last_check[1] > $players[$current_leader[0]]) {
	fprintf($fw, $last_check[2]);
} else {
	fprintf($fw, $current_leader[2]);
}

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    if ( $istr[1] < 0 ) {
        unset( $in[$key] );
    } else {
        $new[$istr[0]] += $istr[1];
    }
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
$av = false;
if ($text[0] == 50) {
$av= true;
}
unset($text[0]);

$total = array();
$winner = "";
$prev_winner = "";
$higher_score = 0;
$prev_higher_score = 0;
$turn = 01;
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if (isset($total[$player[0]])){
$total[$player[0]]['score'] += $player[1];
$total[$player[0]]['turn'] = $turn;
} else {
$total[$player[0]]['score'] = $player[1];
$total[$player[0]]['turn'] = $turn;
}
$turn++;
}
}
$is_first = true;
$winner_turn = 0;
foreach($total as $key => $str) {
if ($is_first) {
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];
continue;
}
if ($str['score']>$higher_score) {
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];
} else if ($str['score'] == $higher_score && $winner_turn > $str['turn']){
$winner = $key;
$higher_score = $str['score'];
$winner_turn = $str['turn'];
}
$is_first = false;
}
// var_dump($char_array2);die();
// foreach($text as $key => $str) {
// if (strlen($str)>0){
// $player = explode(" ",$str);
// if (isset($total[$player[0]])){
// $total[$player[0]] += $player[1];
// } else {
// $total[$player[0]] = $player[1];
// }
// if ($total[$player[0]]>$higher_score){
    // if ($prev_winner == ""){
    // $prev_winner = $player[0];
    // $prev_higher_score = $total[$player[0]];
    // }
    // else {
    // $prev_winner = $winner;
    // $prev_higher_score = $higher_score;
    // $winner = $player[0];
    // $higher_score = $total[$player[0]];
    // }
// } else if($total[$player[0]]<0 && $winner == $player[0]) {
    // $winner = $prev_winner;
    // $higher_score = $prev_higher_score;
// }
// }
// }

if ($winner == "") {
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
$winner = $player[0];
}
}
}
echo $winner;
?>

<?php

class dat {
    public $name;
    public $point;
}

$fr = fopen("php://stdin", "r");
$n = fgets($fr);
$line = array();
$names = array();
$winner = array();

for($i=0;$i<$n;$i++)
{
    $data = fgets($fr);
    $array = explode(" ", $data);

    $line[$i]=new dat;
    $line[$i]->name = $array[0];
    $line[$i]->point = $array[1];

    if(isset($names[$array[0]]))
    {
        $names[$array[0]] = $names[$array[0]] + $array[1];
    }
    else
    {
        $names += array($array[0] => $array[1]);
    }
}

$max=0;
foreach ($line as &$val)
{
    if($max < $val->point)
        $max = $val->point;
}
unset($val);

$str;
$pnt;
foreach ($line as &$val)
{
    $str = $val->name;
    $pnt = $val->point;

    if(isset($winner[$str]))
    {
        $winner[$str] = $winner[$str] + $pnt;
    }
    else
    {
        $winner += array($str => $pnt);
    }

    if($winner[$str] >= $max && $names[$str] == $max)
    {
        echo $str;
        break;
    }

}
unset($val);

#!/usr/bin/env php
<?
error_reporting(0);
$n = intval(fgets(STDIN));
$score = array();
foreach (range(1, $n) as $i) {
  $dat = explode(' ', fgets(STDIN));
  $name[$i] = $dat[0];
  $gain[$i] = intval($dat[1]);
  $score[$name[$i]] += $gain[$i];
}
foreach ($score as  $val)
  if ($val > $best) $best = $val;
$second = array();
foreach (range(1, $n) as $i) {
  $second[$name[$i]] += $gain[$i];
  if ($score[$name[$i]] == $best && $second[$name[$i]] == $best) break;
}

print $name[$i].chr(10);
?>

<?php
    fscanf(STDIN, "%d\n", $n);
    $res = $sums = array();
    $max = 0;
    $winner = '';
    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, "%s %d\n", $name, $num);
        $res[] = array($name, $num);
        if (!isset($sums[$name])) {
            $sums[$name] = 0;
        }
        $sums[$name] += $num;
    }

    $max = max($sums);

    $sum = array();
    foreach($res as $line) {
        if (!isset($sum[$line[0]])) {
            $sum[$line[0]] = 0;
        }
        $sum[$line[0]] += $line[1];
        if ($sum[$line[0]] >= $max) {
            //echo $line[0];
            exit();
        }
    }
?>

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo(&$a, &$b, &$max, &$maxPerson, $person, $points)
{
    if (!isset($a[$person])) {
        $a[$person] = 0;
    }

    if (!isset($b[$points])) {
        $b[$points][] = $person;
    }

    $a[$person] += $points;

    $newMax = max($a);

    if (!isset($b[$newMax])) {
        $b[$newMax][] = $person;
    }

    if ($newMax > $max) {
        $max = $newMax;
        $maxPerson = $person;
    }
}

$a = $b = [];
$max = -10000000000;
$maxPerson = '';

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($person, $points) = fscanf($input, "%s %d\n");

    foo($a, $b, $max, $maxPerson, $person, $points);
}

fwrite($output, $b[max($a)][0]);

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
unset($text[0]);

$total = array();
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
$player = explode(" ",$str);
if ($player[1]<0) {
$total[$player[0]] = "loser";
continue;
}
if (isset($total[$player[0]]) && $total[$player[0]] !='loser'){
$total[$player[0]] += $player[1];
}else {
$total[$player[0]] = $player[1];
}
}
}
$winner = "";
$higher_score = 0;
foreach ($total as $key=> $value) {
if ($value != "loser" && $value>$higher_score) {
$winner = $key;
}
}
echo $winner;
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");
$players = array();
$current_round = 1;
$highest_result = 0;
$number_of_rounds = fgets($fr);

function saveResult($name, $result)
{
	global $players;
	global $number_of_rounds;
	global $current_round;
	global $highest_result;
	$added = false;

	$players[$name][$current_round] = $result;

	if($current_round == $number_of_rounds) {
		foreach($players as $p_name => $p_results) {
			$player_score = 0;

			foreach($p_results as $round_number => $round_result) {
				$player_score += $round_result;
			}

			$players[$p_name][$number_of_rounds + 1] = $player_score;
			if ($player_score > $highest_result) {
				$highest_result = $player_score;
			}
		}
	}

	$current_round++;
}

function findOverallWinner($winners_array, $winning_score)
{
	$temp_winners = array();
	global $number_of_rounds;
	$winning_round = $number_of_rounds;

	foreach($winners_array as $w_name => $w_score) {
		if ($w_score[$number_of_rounds + 1] == $winning_score) {
			$temp_score = 0;

			foreach($w_score as $t_round => $t_score) {
				if ($t_round >= $winning_round) {
					break;
				}

				$temp_score += $t_score;

				if($t_score >= $winning_score) {
					$winning_round = $t_round;
					$winner_name = $w_name;
				}
			}
		}
	}

	return $winner_name;
}

while(($line = fgets($fr)) !== false) {
	if (preg_match('/([a-z]+)\s+([\-0-9]+)/', $line, $matches)) {
		saveResult($matches[1], $matches[2]);
	}
}

fprintf($fw, findOverallWinner($players, $highest_result));

<?php
    $data = array();

    $winName = '';

    fscanf(STDIN, "%d\n", $pCount);
    for($i = 0; $i < $pCount; $i++) {
        fscanf(STDIN, "%s %d\n", $name, $score);
        if(empty($data[$name])) {
            $data[$name]['score'] = $score;
            $data[$name]['log'] = 1;
        }
        else $data[$name]['score'] += $score;
        $data[$name]['log'] += 1;
    }

    $maxScore = 0;
    $maxDeep = 0;

    foreach($data as $name => $value) {
        if($data[$name]['score'] > $maxScore) {
            $maxScore = $data[$name]['score'];
            $maxDeep = $data[$name]['log'];
            $winName = $name;
        }
        elseif($data[$name]['score'] == $maxScore) {
            if($maxDeep > $data[$name]['log']) {
                $winName = $name;
                $maxDeep = $data[$name]['log'];
            }
        }
    }

    printf("%s", $winName);
?>

<?php
$a = trim(fgets(STDIN));
$d = array(" ");
$e = array(" ");
$f = array(" ");
$h = array(" ");
$j = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    if($c == 0)
    {
        continue;
    }
    else
    {
    array_push($h, $b);
    krsort($d);
    $g = array_search($b, $d);
    if($g)
    {
        array_push($f, $c + $f[$g]);
        krsort($d);
    }
    else
    {
        array_push($f, $c);
        krsort($d);
    }
    array_push($d, $b);
    array_push($e, $c);
    }
}
if($a == 1)
{
    print $b;
}
else
{
    unset($h[0]);
    krsort($h);
    $i = array_unique($h);
    $k = array_keys($i);
    for($x = 0; $x < count($i); $x++)
    {
        array_push($j, $f[$k[$x]]);
    }
    $m = $j;
    krsort($m);
    arsort($j);
    $l = array_keys($j);
    if($j[$l[0]] > $j[$l[1]])
    {
        print $i[$k[$l[0]]];
    }
    else
    {
        $n = array_search($j[$k[0]], $m);
        print $i[$k[$l[$n]]];
    }
}
?>

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

$players = [];
$winner = '';
for($i = 0; $i < $n; $i++) {
    $play = fgets($f);
    list($name, $score) = explode(' ', $play);
    if(!isset($players[$name])) {
        $players[$name] = $score;
    } else {
        $players[$name] += $score;
    }

    if(empty($winner)) {
        $winner = $name;
    } else if($players[$name] > $players[$winner]) {
        $winner = $name;
    }
}

echo $winner;

<?php
$n = trim(fgets(STDIN));
$g = array();
$s = array();
for($i = 1; $i <= $n; $i ++){
 $step = trim(fgets(STDIN));
 list($player, $score) = explode(' ',$step);
 $g[$player] += $score;
 $s[] = $step;
}

$max = 0;
foreach($g as $v){
 if($v > $max) $max = $v;
}

$w = array();
foreach($g as $k => $v){
 if($v == $max) $w[$k] = $v;
}

if(count($w) == 1){
 print array_search($max, $w);
 exit(0);
}

$g = array();
foreach($s as $v){
 list($player, $score) = explode(' ',$v);
 $g[$player] += $score;
 if($g[$player] >= $max){
  print $player;
  exit(0);
 }
}

?>

<?php

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

$in = explode( "\n", $in );

unset($in['0']);

foreach( $in as $key => $str ) {
    $istr = explode( " ", $str );
    $new[$istr[0]] += $istr[1];
}

$max = max($new);

foreach( $in as $str ) {
    $istr = explode( " ", $str );
    $new1[$istr[0]] += $istr[1];

    if ( $new1[$istr[0]] == $max AND $new[$istr[0]] == $max ) {
        echo $istr[0];
        break;
    }
}

<?php
    $input = explode("\n", trim(file_get_contents("php://stdin")));
    $count = $input[0];
    $ps = array_slice($input, 1, $count, true);
    $sorted = array();
    $scores= array();
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $sorted[$fi[0]] += $fi[1];
    }
    $max = max($sorted);
    foreach($ps as $key => $pi){
        $fi = explode(' ', $pi);
        $scores[$fi[0]] += $fi[1];
        if($scores[$fi[0]] == $max){
            echo $fi[0];
            return;
        }
    }

<?php
$a = trim(fgets(STDIN));
$d = array(" ");
$e = array(" ");
$f = array(" ");
$h = array(" ");
$j = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    array_push($h, $b);
    krsort($d);
    $g = array_search($b, $d);
    if($g)
    {
        array_push($f, $c + $f[$g]);
        krsort($d);
    }
    else
    {
        array_push($f, $c);
        krsort($d);
    }
    array_push($d, $b);
    array_push($e, $c);
}
if($a == 1)
{
    print $b;
}
else
{
    unset($h[0]);
    krsort($h);
    $i = array_unique($h);
    $k = array_keys($i);
    for($x = 0; $x < count($i); $x++)
    {
        array_push($j, $f[$k[$x]]);
    }
    $m = $j;
    krsort($m);
    arsort($j);
    $l = array_keys($j);
    if($j[$l[0]] > $j[$l[1]])
    {
        print $i[$k[$l[0]]];
    }
    else
    {
        $n = array_search($j[$k[0]], $m);
        print $i[$k[$l[$n]]];
    }
}
?>


In order to write a string, Atilla needs to first learn all letters that are contained in the string.Atilla needs to write a message which can be represented as a string $$$s$$$. He asks you what is the minimum alphabet size required so that one can write this message.The alphabet of size $$$x$$$ ($$$1 \leq x \leq 26$$$) contains only the first $$$x$$$ Latin letters. For example an alphabet of size $$$4$$$ contains only the characters $$$\texttt{a}$$$, $$$\texttt{b}$$$, $$$\texttt{c}$$$ and $$$\texttt{d}$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of the string. The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of lowercase Latin letters.

For each test case, output a single integer — the minimum alphabet size required to so that Atilla can write his message $$$s$$$.

5

1

a

4

down

10

codeforces

3

bcf

5

zzzzz

NoteFor the first test case, Atilla needs to know only the character $$$\texttt{a}$$$, so the alphabet of size $$$1$$$ which only contains $$$\texttt{a}$$$ is enough.For the second test case, Atilla needs to know the characters $$$\texttt{d}$$$, $$$\texttt{o}$$$, $$$\texttt{w}$$$, $$$\texttt{n}$$$. The smallest alphabet size that contains all of them is $$$23$$$ (such alphabet can be represented as the string $$$\texttt{abcdefghijklmnopqrstuvw}$$$).

<?php
$Test=(int)readline();
while($Test--)
{
    $letters="abcdefghijklmnopqrstuvwxyz";
    $string_size=(int) readline();
    $Word=(string)readline();
    $Max='a';
    for($i=0;$i<$string_size;$i++) $Max=max($Max,$Word[$i]);
    echo (strpos($letters,$Max)+1)."\n";
}
?>

<?php
  $stdin = fopen('php://stdin', 'r');
  $t = (int)fgets($stdin);
  for ($i = 0; $i < $t; $i++) {
  	$len = (int)fgets($stdin);
  	$s = trim(trim(fgets($stdin)),"\r\n");

  	$ss = str_split($s);
  	sort($ss);
  	echo ord($ss[$len-1])-ord("a")+1;
  	echo "\n";
  }
  fclose($stdin);
?>

<?php
$iter = InOutPut::get();
$iterA = 0;
for($i=0; $i <$iter; $i++) {
    $alphabet = 'abcdefghijklmnopqrstuvwxyz';
    $iterA = InOutPut::get();
    $max = 1;
    $letter = array();
    $letter = InOutPut::getArr();
    for($j = 0; $j < $iterA; $j++){
        if (strpos($alphabet, $letter[0][$j]) + 1 > $max){
            $max = strpos($alphabet, $letter[0][$j]) + 1;
        }
    }
    InOutPut::print($max);
}

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

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $s = getLine();

    $x = 0;

    for ($index = 0; $index < $n; $index++)
    {
        $x = max($x, ord($s[$index]) - ord('a') + 1);
    }

    $results[] = $x;
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

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

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

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


You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example:   if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$;  if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$;  if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).

If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
  for($q=0; $q <$t; $q++) {
      $ans = '';
      $a = 0;
      $b = 0;
      list($x, $y) = getA();

      $y - $x;
      if($y >= $x ) {
         if($y % $x == 0) {
             $tc = $y/ $x;
             $a = $tc;
             $b = 1;
         }
      }
        echo $b, ' ', $a, $inter;

//   echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

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

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    function getRotate($a, $s, $e, $ind) {
 		$ar = [];
        for ($i= $s; $i<=$e; $i++) {
        	$ar[$i] = $a[$i];
        	$j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
        	// echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
        	$a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }

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

        if ($x <= $y) {
            if ($y % $x == 0) {
                echo "1 " . $y/$x . PHP_EOL;
            } else {
                echo "0 0" . PHP_EOL;
            }
        } else {
            echo "0 0" . PHP_EOL;
        }
    }
?>

<?php

$n = readline();

while($n--)
{
    fscanf(STDIN, "%d %d", $x, $y);
    if($y % $x != 0)
        echo "0 0\n";
    else
        echo "1 " . strval($y/$x) ."\n";
}

?>

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
  for($q=0; $q <$t; $q++) {
      $ans = '';
      $a = 0;
      $b = 0;
      list($x, $y) = getA();

      $y - $x;
      if($y >= $x ) {
         if($y % $x == 0) {
             $tc = $y/ $x;
             $a = $tc;
             $b = 1;
         }
      }
        echo $a, ' ', $b, $inter;

//   echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

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

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    function getRotate($a, $s, $e, $ind) {
 		$ar = [];
        for ($i= $s; $i<=$e; $i++) {
        	$ar[$i] = $a[$i];
        	$j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
        	// echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
        	$a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }


Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.Return the maximum number of rows that she can make completely clean.

The first line of input will be a single integer n (1 ≤ n ≤ 100). The next n lines will describe the state of the room. The i-th line will contain a binary string with n characters denoting the state of the i-th row of the room. The j-th character on this line is '1' if the j-th square in the i-th row is clean, and '0' if it is dirty.

The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.

NoteIn the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.In the second sample, everything is already clean, so Ohana doesn't need to do anything.


You are given an array of n elements, you must make it a co-prime array in as few moves as possible.In each move you can insert any positive integral number you want not greater than 109 in any place in the array.An array is co-prime if any two adjacent numbers of it are co-prime.In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.

Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them.

<?php
function gcd($a, $b) {
	return $b ? gcd($b, $a % $b) : $a;
}
$STDIN = fopen('./data.txt', 'r');
define('STDIN', $STDIN);
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$ans = array($arr[0]);
$cnt = 0;
for($i = 1; $i < $n; ++$i) {
	if(gcd($arr[$i - 1], $arr[$i]) > 1) {
		++$cnt;
		$ans[] = 1;
	}
	$ans[] = $arr[$i];
}
echo $cnt."\n";
foreach ($ans as $key => $value) {
	if($key == $n + $cnt - 1) {
		echo $value."\n";
	} else {
		echo $value.' ';
	}
}
?>

<?php
function gcd($n, $m) {
    if($m > 0) {
        return gcd($m, $n % $m);
    } else {
        return abs($n);
    }
}
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
for($x = 0; $x < $c - 1; $x++)
{
     $e = gcd($d[$x], $d[$x + 1]);
     if($e != 1)
     {
          $f = array_slice($d, 0, $x + 1);
          $g = array_slice($d, $x + 1);
          $d = array_merge($f, array(1), $g);
          $x = -1;
     }
}
print (count($d) - $c) . "\n";
print implode(" ", $d);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array($b[0]);
for($x = 0; $x < $a - 1; $x++)
{
     $d = $b[$x];
     $e = array();
     while(TRUE)
     {
          $f = $d % 2;
          if($f == 0)
          {
               array_push($e, 2);
               $d /= 2;
          }
          else
          {
               array_push($e, $d);
               break;
          }
     }
     $f = $b[$x + 1];
     $g = array();
     while(TRUE)
     {
          $h = $f % 2;
          if($h == 0)
          {
               array_push($g, 2);
               $f /= 2;
          }
          else
          {
               array_push($g, $f);
               break;
          }
     }
     $i = array_intersect($e, $g);
     if((count($i) == 0) || ((count($i) == 1) && ($i[0] == 1)))
     {
          array_push($c, $b[$x + 1]);
     }
     else
     {
          array_push($c, "1");
          array_push($c, $b[$x + 1]);
     }
}
$j = count($c) - count($b);
print $j . "\n";
print implode(" ", $c);
?>


Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.Help Yaroslav.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the array elements.

In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.

NoteIn the first sample the initial array fits well.In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.In the third sample Yarosav can't get the array he needs.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array();
for($x = 0; $x < $a; $x++)
{
    $c[$b[$x]]++;
}
arsort($c);
$d = array_keys($c);
$e = $c[$d[0]];
$f = $a - $e;
if($f + 1 >= $e)
{
    print "YES";
}
else
{
    print "NO";
}
?>