<?php
list($sx, $sy, $tx, $ty) = explode(' ', trim(fgets(STDIN)));
$x = abs($tx - $sx);
$y = abs($ty - $sy);

//root1
echo str_repeat('U', $y);
echo str_repeat('R', $x);
echo str_repeat('D', $y);
echo str_repeat('L', $x);

//root2
echo 'L';
echo str_repeat('U', $y + 1);
echo str_repeat('R', $x + 1);
echo 'D';
echo 'R';
echo str_repeat('D', $y + 1);
echo str_repeat('L', $x + 1);
echo 'U';
?>

Score : 300 points

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.

Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.

Here, both the x- and y-coordinates before and after each movement must be integers.

He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).

Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).

Under this condition, find a shortest path for him.

Constraints

-1000 ≤ sx < tx ≤ 1000

-1000 ≤ sy < ty ≤ 1000

sx,sy,tx and ty are integers.

Input

The input is given from Standard Input in the following format:

sx sy tx ty

Output

Print a string S that represents a shortest path for Dolphin.

The i-th character in S should correspond to his i-th movement.

The directions of the movements should be indicated by the following characters:

U: Up

D: Down

L: Left

R: Right

If there exist multiple shortest paths under the condition, print any of them.

Sample Input 1

0 0 1 2

Sample Output 1

UURDDLLUUURRDRDDDLLU

One possible shortest path is:

Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)

Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)

Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)

Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)

Sample Input 2

-2 -2 1 1

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL


<?php
list($sx, $sy, $gx, $gy) = explode(" ", trim(fgets(STDIN)));
$dx = $gx - $sx;
$dy = $gy - $sy;

echo str_repeat("U", $dy);
echo str_repeat("R", $dx);
echo str_repeat("D", $dy);
echo str_repeat("L", $dx);

echo str_repeat("L", 1);
echo str_repeat("U", $dy+1);
echo str_repeat("R", $dx+2);
echo str_repeat("D", $dy+2);
echo str_repeat("L", $dx+1);
echo str_repeat("U", 1);

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

Submitted source-code file size, in bytes.

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

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


<?php
/*
    Problem URL : http://abc051.contest.atcoder.jp/tasks/abc051_d

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

$m = array();
$ans = 0;

fscanf(STDIN, "%d %d", $N, $M);
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    $m[$a][$b] = $c;
    $m[$b][$a] = $c;
}

if (DEBUG) var_dump($m);

for ($k = 1; $k <= $M; $k++) {
    if (DEBUG) echo "\nk:{$k} ";
    for ($i = 1; $i <= $M; $i++) {
        // if ($i == $k) {
        //     if (DEBUG) echo PHP_EOL;
        //     continue;
        // }
        if (DEBUG) echo "i:{$i} ";
        for ($j = 1; $j <= $M; $j++) {
            if ($j == $i || $j == $k) {
                if (DEBUG) echo PHP_EOL;
                continue;
            }
            if (DEBUG) echo "j:{$j} ";
            if (!isset($m[$i][$j])) continue;
            if (!isset($m[$i][$k])) continue;
            if (!isset($m[$j][$k])) continue;
            // if (DEBUG) echo "root {$i} {$k} {$j}\n";
            if ($m[$i][$k] > $m[$i][$j] + $m[$j][$k]) {
                if (DEBUG) echo "X {$i} {$k} - {$i} {$j} + {$j} {$k}\n";
                $ans++;
            }
        }
    }
}

echo ($ans / 2) . PHP_EOL;

Score : 400 points

Problem Statement

You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.

The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.

Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).

A connected graph is a graph where there is a path between every pair of different vertices.

Find the number of the edges that are not contained in any shortest path between any pair of different vertices.

Constraints

2≤N≤100

N-1≤M≤min(N(N-1)/2,1000)

1≤a_i,b_i≤N

1≤c_i≤1000

c_i is an integer.

The given graph contains neither self-loops nor double edges.

The given graph is connected.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.

Sample Input 1

3 3
1 2 1
1 3 1
2 3 3

Sample Output 1

1

In the given graph, the shortest paths between all pairs of different vertices are as follows:

The shortest path from vertex 1 to vertex 2 is: vertex 1 → vertex 2, with the length of 1.

The shortest path from vertex 1 to vertex 3 is: vertex 1 → vertex 3, with the length of 1.

The shortest path from vertex 2 to vertex 1 is: vertex 2 → vertex 1, with the length of 1.

The shortest path from vertex 2 to vertex 3 is: vertex 2 → vertex 1 → vertex 3, with the length of 2.

The shortest path from vertex 3 to vertex 1 is: vertex 3 → vertex 1, with the length of 1.

The shortest path from vertex 3 to vertex 2 is: vertex 3 → vertex 1 → vertex 2, with the length of 2.

Thus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1.

Sample Input 2

3 2
1 2 1
2 3 1

Sample Output 2

0

Every edge is contained in some shortest path between some pair of different vertices.


<?php
    /*
        Problem URL : http://agc008.contest.atcoder.jp/tasks/agc008_a
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    // define('DEBUG', true);
    define('DEBUG', false);

    $arr = array();

    fscanf(STDIN, "%d %d", $x, $y);

    if ($x >= 0 && $y >= 0) {
        if ($x < $y) {
            echo ($y - $x) . PHP_EOL;
            exit;
        } elseif ($y == 0) {
            echo (($x - $y) + 1 ) . PHP_EOL;
            exit;
        } else {
            echo (($x - $y) + 2 ) . PHP_EOL;
            exit;
        }
    } elseif ($x >= 0 && $y < 0) {
        if ($x >= -$y) {
            echo ($x + $y + 1) . PHP_EOL;
            exit;
        } else {
            echo (-$y - $x + 1) . PHP_EOL;
            exit;
        }
    } elseif ($x < 0 && $y >= 0) {
        if ($x == -$y) {
            echo "1\n";
            exit;
        } elseif (-$x >= $y) {
            echo (-$x - $y + 1) . PHP_EOL;
            exit;
        } else {
            $w1 = $y - $x;
            $w2 = $y + $x + 1;
            echo min($w1, $w2) . PHP_EOL;
            exit;
        }
    } elseif ($x < 0 && $y < 0) {
        if ($x > $y) {
            echo ($x - $y + 2) . PHP_EOL;
            exit;
        } else {
            echo ($y - $x) . PHP_EOL;
            exit;
        }
    }

Score : 300 points

Problem Statement

Snuke has a calculator. It has a display and two buttons.

Initially, the display shows an integer x.
Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:

Button A: When pressed, the value on the display is incremented by 1.

Button B: When pressed, the sign of the value on the display is reversed.

Find the minimum number of times Snuke needs to press the buttons to achieve his objective.
It can be shown that the objective is always achievable regardless of the values of the integers x and y.

Constraints

x and y are integers.

|x|, |y| ≤ 10^9

x and y are different.

Input

The input is given from Standard Input in the following format:

x y

Output

Print the minimum number of times Snuke needs to press the buttons to achieve his objective.

Sample Input 1

10 20

Sample Output 1

10

Press button A ten times.

Sample Input 2

10 -10

Sample Output 2

1

Press button B once.

Sample Input 3

-10 -20

Sample Output 3

12

Press the buttons as follows:

Press button B once.

Press button A ten times.

Press button B once.


<?php
fscanf(STDIN, "%d %s %d", $a, $op, $b);
if($op == '+'){
    print $a + $b;
}else{
    print $a - $b;
}

Score : 100 points

Problem Statement

Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.

Constraints

1≦A,B≦10^9

op is either + or -.

Input

The input is given from Standard Input in the following format:

A op B

Output

Evaluate the formula and print the result.

Sample Input 1

1 + 2

Sample Output 1

3

Since 1 + 2 = 3, the output should be 3.

Sample Input 2

5 - 7

Sample Output 2

-2


<?php
fscanf(STDIN, "%d %d", $n, $w);
for($i = 1; $i <= $n; $i++){
    fscanf(STDIN, "%s", $c);
    print "$c\n$c\n";
}


<?php
fscanf(STDIN, "%s %s %s", $a, $s, $c);
$split = substr($s, 0, 1);
echo 'A'.$split.'B';

?>

Score : 100 points

Problem Statement

Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

Snuke has decided to abbreviate the name of the contest as "AxC".
Here, x is the uppercase English letter at the beginning of s.

Given the name of the contest, print the abbreviation of the name.

Constraints

The length of s is between 1 and 100, inclusive.

The first character in s is an uppercase English letter.

The second and subsequent characters in s are lowercase English letters.

Input

The input is given from Standard Input in the following format:

AtCoder s Contest

Output

Print the abbreviation of the name of the contest.

Sample Input 1

AtCoder Beginner Contest

Sample Output 1

ABC

The contest in which you are participating now.

Sample Input 2

AtCoder Snuke Contest

Sample Output 2

ASC

This contest does not actually exist.

Sample Input 3

AtCoder X Contest

Sample Output 3

AXC


<?php
fscanf(STDIN, "%s %s %s", $a, $b, $c);
echo 'A' . substr($b, 0, 1) . 'C';


Score : 200 points

Problem Statement

You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?

Constraints

0 ≤ a ≤ b ≤ 10^{18}

1 ≤ x ≤ 10^{18}

Input

The input is given from Standard Input in the following format:

a b x

Output

Print the number of the integers between a and b, inclusive, that are divisible by x.

Sample Input 1

4 8 2

Sample Output 1

3

There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.

Sample Input 2

0 5 1

Sample Output 2

6

There are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.

Sample Input 3

9 9 2

Sample Output 3

0

There are no integer between 9 and 9, inclusive, that is divisible by 2.

Sample Input 4

1 1000000000000000000 3

Sample Output 4

333333333333333333

Watch out for integer overflows.


<?php
list($a, $b, $c) = array_map("intval", explode(" ", fgets(STDIN)));
echo intdiv($b+$c,$c)-intdiv($a-1+$c,$c);


<?php
/*
    Problem URL : http://abc048.contest.atcoder.jp/tasks/abc048_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%s %s %s", $a, $b, $x);
if (DEBUG) echo implode(" ", array($a, $b, $x)) . PHP_EOL;

$mmin = bigDiv($a, $x, true);
$mmax = bigDiv($b, $x);
$ans = bigSub($mmax, $mmin);
if ($ans === false) {
    if (DEBUG) echo "false found.\n";
    echo "0\n";
    exit;
}
$ans = bigAdd($ans, "1");
if (DEBUG) echo $mmin , " " , $mmax , PHP_EOL;
echo $ans . PHP_EOL;
exit;

$x = bigAdd("999999999999999", "2");
$x = bigSub("10000000000000000000", "2");
// $x = bigDiv("10000000000000000000", "3", true);
$x = bigDiv("99999999999999999999", "10000000000000000000");
$x = bigDiv("9", "4");
// $x = bigDiv("10000000000000000000", "7");
// $x = bigDiv("100", "49", true);
// var_dump($x);
echo $x . PHP_EOL;

function bigDiv($a, $b, $ceilFlag = false) {
    if (gettype($a) != "string") {
        exit("arg1 not string\n");
    }
    if (gettype($b) != "string") {
        exit("arg2 not string\n");
    }
    $ans = array();
    $a = bigGetArray($a);
    // $b = bigGetArray($b);
    $aa = array();
    while (true) {
        if (count($a) > 1 && array_sum($aa) == 0 && array_sum($a) == 0 && $ans) {
            if (DEBUG) echo "hell\n";
            while($a) {
                array_unshift($ans, array_pop($a));
            }
            break;
        }
        $ret = bigSub(bigKeta($aa), $b);
        // print_r($ret);
        // echo PHP_EOL;
        if ($ret === false) {
            if (!$a) break;
            array_unshift($aa, array_pop($a));
            if ($ans) {
                array_unshift($ans, 0);
            }
        } else {
            if (!$ans) {
                array_unshift($ans, 0);
            }
            $ans[0]++;
            $aa = bigGetArray($ret);
        }
    }
    // var_dump($ans);
    $ret = implode("", array_reverse($ans));
    // echo "amari: " . implode("", array_reverse($aa)) . PHP_EOL;
    $amari = implode("", array_reverse($aa));
    if ($amari != 0 && $ceilFlag === true) {
        $ret = bigAdd($ret, "1");
    }
    if ($ret == null) {
        $ret = "0";
    }
    if (DEBUG) echo "bigDiv: {$a} {$b} {$ret}\n";
    return $ret;
}

function bigAdd($a, $b) {
    if (gettype($a) != "string") {
        exit("arg1 not string\n");
    }
    if (gettype($b) != "string") {
        exit("arg2 not string\n");
    }
    $a = bigGetArray($a);
    $b = bigGetArray($b);
    $keta = max(count($a), count($b));
    for ($i = 0; $i < $keta; $i++) {
        $a_ex = isset($a[$i]) ? $a[$i] : 0;
        $b_ex = isset($b[$i]) ? $b[$i] : 0;
        $a[$i] = $a_ex + $b_ex;
    }
    $a = bigKeta($a);

    return $a;
}

/*
    param : string
    return: string
*/
function bigSub($a, $b) {
    // echo "sub1: {$a} {$b}\n";
    if (gettype($a) != "string") {
        exit("arg1 not string\n");
    }
    if (gettype($b) != "string") {
        exit("arg2 not string\n");
    }
    if (strlen($b) > strlen($a)) {
        // exit("arg2 is larger than ard1\n");
        return false;
    }
    if ((strlen($b) == strlen($a)) && $b > $a) {
        // exit("arg2 is larger than ard1\n");
        return false;
    }

    $a = bigGetArray($a);
    $b = bigGetArray($b);
    $keta = max(count($a), count($b));
    for ($i = 0; $i < $keta; $i++) {
        $a_ex = isset($a[$i]) ? $a[$i] : 0;
        $b_ex = isset($b[$i]) ? $b[$i] : 0;
        $a[$i] = $a_ex - $b_ex;
    }
    $a = bigKeta($a);

    // echo "sub2: {$a}\n";
    return $a;
}

/*
    param : string
    return: array
*/
function bigGetArray($a) {
    if (gettype($a) != "string") {
        exit("arg1 not string\n");
    }
    return array_reverse(str_split($a));
}

function bigGetString($a) {
    if (gettype($a) != "array") {
        exit("arg1 not array\n");
    }
    return implode("", array_reverse($a));
}

/*
    param : array
    return: string
*/
function bigKeta($a) {
    if (gettype($a) != "array") {
        exit("arg1 not array\n");
    }
    $cnt = count($a);

    $flag = true;

    while($flag) {
        $flag = false;
        foreach ($a as $key => $val) {
            if ($val < 0) {
                $a[$key+1]--;
                $a[$key] += 10;
                $flag = true;
            }
            if ($val > 9) {
                $a[$key+1]++;
                $a[$key] -= 10;
                $flag = true;
            }
        }
    }

    if ($a[$cnt-1] == "0") {
        unset($a[$cnt-1]);
    }
    return implode("", array_reverse($a));
}


<?php
/*
    http://cf16-final-open.contest.atcoder.jp/tasks/cf16-final-open_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $N);
$score = 0;
$ans = array();
for ($i = 1; $i < 100000; $i++) {
	$score += $i;
	$ans[] = $i;
	if ($score === $N) {
		echo implode(" ", $ans);
		echo PHP_EOL;
		exit;
	}
	if ($score > $N) {
		$diff = abs($score - $N);
		unset($ans[$diff-1]);
		echo implode(" ", $ans);
		echo PHP_EOL;
		exit;
	}
}

Score : 300 points

Problem Statement

The problem set at CODE FESTIVAL 20XX Finals consists of N problems.

The score allocated to the i-th (1≦i≦N) problem is i points.

Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.

As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.

Determine the set of problems that should be solved.

Constraints

1≦N≦10^7

Partial Score

200 points will be awarded for passing the test set satisfying 1≦N≦1000.

Additional 100 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

N

Output

Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.

If there exists more than one such set, any of them will be accepted.

Sample Input 1

4

Sample Output 1

1
3

Solving only the 4-th problem will also result in the total score of 4 points, but solving the 1-st and 3-rd problems will lower the highest score of a solved problem.

Sample Input 2

7

Sample Output 2

1
2
4

The set \{3,4\} will also be accepted.

Sample Input 3

1

Sample Output 3

1


<?php
define('ROAD', '#');
define('WALL', '.');
list($h, $w) = ints();
for ($i = 0; $i < $h; ++$i) list($a[]) = strs();
$c = 0;
for ($i = 0; $i < $h; ++$i) {
    for ($j = 0; $j < $w; ++$j) {
        if ($a[$i][$j] === WALL) continue;
        if ($i < $h - 1 && $a[$i + 1][$j] === ROAD) ++$c;
        if ($j < $w - 1 && $a[$i][$j + 1] === ROAD) ++$c;
    }
}
echo $c === $h - 1 + $w - 1 ? 'Possible' : 'Impossible';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 200 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).

You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is # if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is .. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Constraints

2 \leq H, W \leq 8

a_{i,j} is either # or ..

There exists a valid sequence of moves for Shik to generate the map a.

Input

The input is given from Standard Input in the following format:

H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}

Output

If it is possible that Shik only uses right and down moves, print Possible. Otherwise, print Impossible.

Sample Input 1

4 5
##...
.##..
..##.
...##

Sample Output 1

Possible

The matrix can be generated by a 7-move sequence: right, down, right, down, right, down, and right.

Sample Input 2

5 3
###
..#
###
#..
###

Sample Output 2

Impossible

Sample Input 3

4 5
##...
.###.
.###.
...##

Sample Output 3

Impossible


<?php
list($h,$w)=fscanf(STDIN,"%d %d");
$pastRange=array(-1,-1);
$ansflg=false;
for($i=0;$i<$h;++$i){
    $input=trim(fgets(STDIN));
    $start=strpos($input,"#");
    $end=strrpos($input,"#");
    if(($start>$pastRange[0]&&$end>$pastRange[1])||($start===$pastRange[1]&&$start<=$end)){
        $ansflg=true;
        $pastRange=array($start,$end);
    }else{
        $ansflg=false;
        break;
    }
}
if($ansflg){
    echo "Possible";
}else{
    echo "Impossible";
}
?>


Score : 400 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions:

1 \leq a_i, b_i \leq 10^9 for all i

a_1 < a_2 < ... < a_N

b_1 > b_2 > ... > b_N

a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}

Constraints

2 \leq N \leq 20,000

p is a permutation of the set {1, 2, ..., N}

Input

The input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space.

It can be shown that there always exists a solution for any input satisfying the constraints.

Sample Input 1

2
1 2

Sample Output 1

1 4
5 4

a_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.

Sample Input 2

3
3 2 1

Sample Output 2

1 2 3
5 3 1

Sample Input 3

3
2 3 1

Sample Output 3

5 10 100
100 10 1


<?php
$arrayCandy=explode(" ",trim(fgets(STDIN)));
rsort($arrayCandy);
if(intval($arrayCandy[0])===intval($arrayCandy[1]+$arrayCandy[2])){
    echo "Yes";
}else{
    echo "No";
}

Score : 100 points

Problem Statement

Two students of AtCoder Kindergarten are fighting over candy packs.

There are three candy packs, each of which contains a, b, and c candies, respectively.

Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.

Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Constraints

1 ≦ a, b, c ≦ 100

Input

The input is given from Standard Input in the following format:

a b c

Output

If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

Sample Input 1

10 30 20

Sample Output 1

Yes

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.

Sample Input 2

30 30 100

Sample Output 2

No

In this case, the student who gets the pack with 100 candies always has more candies than the other.

Note that every pack must be given to one of them.

Sample Input 3

56 25 31

Sample Output 3

Yes


<?php
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));
$ans = "";
if($s===$t){
    $ans=$t;
}else{
    for($i=$n-1;$i>=0;--$i){
        $offsets=substr($s,$i);
        $offsett=substr($t,0,$n-$i);
        if($offsett===$offsets){
            $ans=$s.substr($t,$n-$i);
            break;
        }
    }

}
if($ans===""){
    $ans=$s.$t;
}
echo strlen($ans);
?>

Score : 200 points

Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.

The first N characters equal to the string s.

The last N characters equal to the string t.

Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100

The lengths of s and t are both N.

s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5

The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2

The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4

The shortest string is expr.


<?php
/*
    http://agc006.contest.atcoder.jp/tasks/agc006_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

for ($i = $N; $i >= 0; $i--) {
	$ss = substr($s, strlen($s) - $i);
	$tt = substr($t, 0, $i);
	// echo "{$ss} {$tt}\n";
	if ($ss == $tt) {
		echo ($N * 2 - $i) . PHP_EOL;
		exit;
	}
}


<?php
list($N) = ints();
$A = ints();
$B = ints();
$p = 1;
for($i = 0; $i < $N; $i++){
    if($A[$i] > ($A[$i-1]??0)){
        $Amin = $A[$i];
        $Amax = $A[$i];
    }else{
        $Amin = 1;
        $Amax = $A[$i];
    }
    if($B[$i] > ($B[$i+1]??0)){
        $Bmin = $B[$i];
        $Bmax = $B[$i];
    }else{
        $Bmin = 1;
        $Bmax = $B[$i];
    }
    $min = max($Amin, $Bmin);
    $max = min($Amax, $Bmax);
    if($min > $max){
        $p = 0;
    }
    $p*=$max-$min+1;
    $p%=10**9+7;
}
echo $p,"\n";

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

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

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

Score : 400 points

Problem Statement

Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.
The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.
Mr. Takahashi traversed the range from the west and Mr. Aoki from the east.

The height of Mt. i is h_i, but they have forgotten the value of each h_i.
Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).
Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i.

We know that the height of each mountain h_i is a positive integer.
Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.

Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.
In such a case, output 0.

Constraints

1 ≤ N ≤ 10^5

1 ≤ T_i ≤ 10^9

1 ≤ A_i ≤ 10^9

T_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)

A_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)

Input

The input is given from Standard Input in the following format:

N
T_1 T_2 ... T_N
A_1 A_2 ... A_N

Output

Print the number of possible sequences of the mountains' heights, modulo 10^9 + 7.

Sample Input 1

5
1 3 3 3 3
3 3 2 2 2

Sample Output 1

4

The possible sequences of the mountains' heights are:

1, 3, 2, 2, 2

1, 3, 2, 1, 2

1, 3, 1, 2, 2

1, 3, 1, 1, 2

for a total of four sequences.

Sample Input 2

5
1 1 1 2 2
3 2 1 1 1

Sample Output 2

0

The records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.

Sample Input 3

10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Sample Output 3

884111967

Don't forget to compute the number modulo 10^9 + 7.

Sample Input 4

1
17
17

Sample Output 4

1

Some mountain ranges consist of only one mountain.


<?php
$stdins = array();
    while(true)
    {
        $stdin = trim(fgets(STDIN));

        if ($stdin === '')
        {
         var_dump(count(array_unique($stdins))) ;
        return;
        }
        $stdins[] = $stdin;
    }

Score : 100 points

Problem Statement

AtCoDeer the deer recently bought three paint cans.
The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.
Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.

Since he is forgetful, he might have bought more than one paint can in the same color.
Count the number of different kinds of colors of these paint cans and tell him.

Constraints

1≦a,b,c≦100

Input

The input is given from Standard Input in the following format:

a b c

Output

Print the number of different kinds of colors of the paint cans.

Sample Input 1

3 1 4

Sample Output 1

3

Three different colors: 1, 3, and 4.

Sample Input 2

3 3 33

Sample Output 2

2

Two different colors: 3 and 33.


<?php
fscanf(STDIN,"%d %d",$n,$k);
$pattern = $k;
if($pattern>1){
    for($i=2;$i<=$n;++$i){
        $pattern*=($k-1);
    }
}
echo $pattern;
?>


Score : 200 points

Problem Statement

There are N balls placed in a row.
AtCoDeer the deer is painting each of these in one of the K colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.

Find the number of the possible ways to paint the balls.

Constraints

1≦N≦1000

2≦K≦1000

The correct answer is at most 2^{31}-1.

Input

The input is given from Standard Input in the following format:

N K

Output

Print the number of the possible ways to paint the balls.

Sample Input 1

2 2

Sample Output 1

2

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

Sample Input 2

1 10

Sample Output 2

10

Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.


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

$arr = str_split($s);
$qualifier = 0;
$abroad_qualifier = 0;
$qualifier_limit = $a + $b;

for ($i = 0; $i < $N; $i++) {
    switch ($arr[$i]) {
        case "a":
            if ($qualifier < $qualifier_limit) {
                $qualifier++;
                echo "Yes" . "\n";
            } else {
                echo "No" . "\n";
            }
            break;
        case "b":
            if ($qualifier < $qualifier_limit && $abroad_qualifier < $b) {
                $qualifier++;
                $abroad_qualifier++;
                echo "Yes" . "\n";
            } else {
                echo "No" . "\n";
            }
            break;
        case "c":
            echo "No" . "\n";
            break;
    }
}

Score : 200 points

Problem Statement

There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.

Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.

A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.

An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.

A string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.

Write a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.

Constraints

1≦N,A,B≦100000

A+B≦N

S is N characters long.

S consists only of the letters a, b and c.

Input

Inputs are provided from Standard Input in the following form.

N A B
S

Output

Output N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.

Sample Input 1

10 2 3
abccabaabb

Sample Output 1

Yes
Yes
No
No
Yes
Yes
Yes
No
No
No

The first, second, fifth, sixth, and seventh participants pass the Qualification contests.

Sample Input 2

12 5 2
cabbabaacaba

Sample Output 2

No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No

The sixth participant is third among overseas students and thus does not pass the Qualification contests.

Sample Input 3

5 2 2
ccccc

Sample Output 3

No
No
No
No
No


<?php

$string = trim(fgets(STDIN));

$parts = explode(" ", $string);

$count = $parts[0];
$size = $parts[1];

$buckets = array();

for ($i = 0; $i < $count; $i++)
{
    $name  = trim(fgets(STDIN));
    $first_letter= substr($name,0,1);

    $buckets[$first_letter]++;

}

if (count($buckets) < $size)
{
    echo "0\n";
    die();
}

$sum =0;

foreach ($buckets as $i => $bucket)
{
     $sum +=  $buckets[$i];
}

$sum2=0;

foreach ($buckets as $i => $bucket)
{
    if ($bucket > ((int)($sum /$size)))
    {
        $buckets[$i] = (int)($sum /$size);
    }
   $sum2 +=  $buckets[$i];
}

$result = (int)($sum2 / $size);

echo $result . "\n";

Score : 100 points

Problem Statement

Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students.
This contest is abbreviated as Kyoto University Programming Contest and called KUPC.

source: Kyoto University Programming Contest Information

The problem-preparing committee met to hold this year's KUPC and N problems were proposed there.
The problems are numbered from 1 to N and the name of i-th problem is P_i.
However, since they proposed too many problems, they decided to divide them into some sets for several contests.

They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions.

One KUPC provides K problems.

Each problem appears at most once among all the KUPCs.

All the first letters of the problem names in one KUPC must be different.

You, one of the committee members, want to hold as many KUPCs as possible.
Write a program to find the maximum number of KUPCs that can be held this year.

Constraints

1 \leq N \leq 10^4

1 \leq K \leq 26

1 \leq |P_i| \leq 10

All characters in P_i are capital letters.

Note that, for each i and j (1 \leq i < j \leq N),
P_i \neq P_j are not necessarily satisfied.

Input

The input is given from Standard Input in the following format:

N K
P_1
:
P_N

Output

Print the maximum number of KUPCs that can be held on one line.

Sample Input 1

9 3
APPLE
ANT
ATCODER
BLOCK
BULL
BOSS
CAT
DOG
EGG

For example, three KUPCs can be held by dividing the problems as follows.

First: APPLE, BLOCK, CAT

Second: ANT, BULL, DOG

Third: ATCODER, BOSS, EGG

Sample Output 1

3

Sample Input 2

3 2
KU
KYOUDAI
KYOTOUNIV

Sample Output 2

0

No KUPC can be held.


<?php
$N = trim(fgets(STDIN));
$S = trim(fgets(STDIN));
$data = explode(' ',$S);
$count = 0;
foreach($data as $k => $d) if($data[(int)$d] == (int) $k)$count++;
echo $count;die;

Score : 100 points

Problem Statement

This contest is CODE FESTIVAL.
However, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.

So he has decided to make a program that puts the single space he omitted.

You are given a string s with 12 letters.
Output the string putting a single space between the first 4 letters and last 8 letters in the string s.

Constraints

s contains exactly 12 letters.

All letters in s are uppercase English letters.

Input

The input is given from Standard Input in the following format:

s

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s.
Put a line break at the end.

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE FESTIVAL

Putting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.

Sample Input 2

POSTGRADUATE

Sample Output 2

POST GRADUATE

Sample Input 3

ABCDEFGHIJKL

Sample Output 3

ABCD EFGHIJKL


<?php
// https://atcoder.jp/contests/abc045/tasks/abc045_a
// 台形の面積を求める

// fgets(STDIN)で標準入力,trimで改行を削除
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$h = trim(fgets(STDIN));

echo ($a + $b)/2 * $h."\n";

Score : 100 points

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints

1≦a≦100

1≦b≦100

1≦h≦100

All input values are integers.

h is even.

Input

The input is given from Standard Input in the following format:

a
b
h

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

Sample Input 1

3
4
2

Sample Output 1

7

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

Sample Input 2

4
4
4

Sample Output 2

16

In this case, a parallelogram is given, which is also a trapezoid.


<?php
$A = mb_strtoupper(trim(fgets(STDIN)));
$B = mb_strtoupper(trim(fgets(STDIN)));
$C = mb_strtoupper(trim(fgets(STDIN)));

$data = [
    'A' => str_split($A),
    'B' => str_split($B),
    'C' => str_split($C),
];

$turn = 'A';

while(true) {
    if (empty($data[$turn])) {
        break;
    }
    $turn = array_shift($data[$turn]);
}

echo "$turn\n";

Score : 200 points

Problem Statement

Alice, Bob and Charlie are playing Card Game for Three, as below:

At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.

The players take turns. Alice goes first.

If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)

If the current player's deck is empty, the game ends and the current player wins the game.

You are given the initial decks of the players.
More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

1≦|S_A|≦100

1≦|S_B|≦100

1≦|S_C|≦100

Each letter in S_A, S_B, S_C is a, b or c.

Input

The input is given from Standard Input in the following format:

S_A
S_B
S_C

Output

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

Sample Input 1

aca
accc
ca

Sample Output 1

A

The game will progress as below:

Alice discards the top card in her deck, a. Alice takes the next turn.

Alice discards the top card in her deck, c. Charlie takes the next turn.

Charlie discards the top card in his deck, c. Charlie takes the next turn.

Charlie discards the top card in his deck, a. Alice takes the next turn.

Alice discards the top card in her deck, a. Alice takes the next turn.

Alice's deck is empty. The game ends and Alice wins the game.

Sample Input 2

abcb
aacb
bccc

Sample Output 2

C


Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

3 \leq H \leq 10^9

3 \leq W \leq 10^9

0 \leq N \leq min(10^5,H×W)

1 \leq a_i \leq H (1 \leq i \leq N)

1 \leq b_i \leq W (1 \leq i \leq N)

(a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

The input is given from Standard Input in the following format:

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0


<?php
/*
    Problem URL : http://arc061.contest.atcoder.jp/tasks/arc061_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// fscanf(STDIN, "%d", $S);
$S = trim(fgets(STDIN));
$len = strlen($S);
$str = str_split($S);
$b = pow(2, $len-1);
for ($i = 0; $i < $b; $i++) {
	$strX = str_pad(decbin($i), $len, "0", STR_PAD_LEFT);
	// echo $strX . PHP_EOL;
	$x = str_split($strX);

	$arr = array();
	$cur = 0;
	for ($y = 0; $y < $len; $y++) {
		$arr[$cur] .= $str[$y];
		if ($x[$y+1] == '1') {
			$cur++;
		}
	}
	// var_dump($arr);
	// echo implode(" ", $arr) . PHP_EOL;
	$ans += array_sum($arr);
}

echo $ans . PHP_EOL;

Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

1 \leq |S| \leq 10

All letters in S are digits between 1 and 9, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the sum of the evaluated value over all possible formulas.

Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125

1+25=26

12+5=17

1+2+5=8

Thus, the sum is 125+26+17+8=176.

Sample Input 2

9999999999

Sample Output 2

12656242944


<?php
$n = intval(trim(fgets(STDIN)));
$k = intval(trim(fgets(STDIN)));
$x = intval(trim(fgets(STDIN)));
$y = intval(trim(fgets(STDIN)));
if ($n <= $k){
    $ans = $n*$x;
} else {
    $ans = $k*$x+($n-$k)*$y;
}
print("$ans\n");
?>

Score : 100 points

Problem Statement

There is a hotel with the following accommodation fee:

X yen (the currency of Japan) per night, for the first K nights

Y yen per night, for the (K+1)-th and subsequent nights

Tak is staying at this hotel for N consecutive nights.
Find his total accommodation fee.

Constraints

1 \leq N, K \leq 10000

1 \leq Y < X \leq 10000

N,\,K,\,X,\,Y are integers.

Input

The input is given from Standard Input in the following format:

N
K
X
Y

Output

Print Tak's total accommodation fee.

Sample Input 1

5
3
10000
9000

Sample Output 1

48000

The accommodation fee is as follows:

10000 yen for the 1-st night

10000 yen for the 2-nd night

10000 yen for the 3-rd night

9000 yen for the 4-th night

9000 yen for the 5-th night

Thus, the total is 48000 yen.

Sample Input 2

2
3
10000
9000

Sample Output 2

20000


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

if ($n < $k) {
$result = $n * $x;
} else {
$result = ($k * $x) + ($n - $k) * $y;
}
echo $result;
?>


fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
fscanf(STDIN, "%d", $y);
$result = ($k * $x) + ($n - $k) * $y;
echo $result;


<?php
/*
  http://abc044.contest.atcoder.jp/tasks/abc044_b
*/

function is_even($value) {
  return $value % 2 === 0 ? true : false;
}

$stdin = trim(fgets(STDIN));
$str_hash = [];

foreach (str_split($stdin) as $key => $value) {
  if (isset($str_hash[$value])) {
    $str_hash[$value] += 1;
  } else {
    $str_hash[$value] = 1;
  }
}

$is_beautiful = true;
foreach ($str_hash as $key => $value) {
  if (!is_even($value)) {
    $is_beautiful = false;
    break;
  }
}

echo $is_beautiful ? "Yes" : "No";

?>


<?php
fscanf(STDIN, "%s", $w);
$text = array();
$total_string = strlen($w);
for ($i = 0; $i < $total_string; $i++) {
    if (isset($text[$w[$i]])) {
        $text[$w[$i]]++;
    } else {
        $text[$w[$i]] = 1;
    }
}
foreach ($text as $obj) {
    if ($obj % 2  == 1) {
        echo 'No';
       exit;
    }
}
echo 'Yes';
exit;
?>

Score : 200 points

Problem Statement

Let w be a string consisting of lowercase letters.
We will call w beautiful if the following condition is satisfied:

Each lowercase letter of the English alphabet occurs even number of times in w.

You are given the string w. Determine if w is beautiful.

Constraints

1 \leq |w| \leq 100

w consists of lowercase letters (a-z).

Input

The input is given from Standard Input in the following format:

w

Output

Print Yes if w is beautiful. Print No otherwise.

Sample Input 1

abaccaba

Sample Output 1

Yes

a occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.

Sample Input 2

hthth

Sample Output 2

No


<?php

$N = intval(fgets(STDIN));

$sum = 0;

for ($i = 1; $i <= $N ; $i++ ) {
  $sum += $i;
}

echo $sum;

?>

Score : 100 points

Problem Statement

There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

Constraints

1≦N≦100

Input

The input is given from Standard Input in the following format:

N

Output

Print the necessary number of candies in total.

Sample Input 1

3

Sample Output 1

6

The answer is 1+2+3=6.

Sample Input 2

10

Sample Output 2

55

The sum of the integers from 1 to 10 is 55.

Sample Input 3

1

Sample Output 3

1

Only one child. The answer is 1 in this case.


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

    $result = 0;

    for($i = 1; $i <= $n; $i++) {
        $result += $i;
    }

    echo $result;

?>


<?php
list($s) = strs();
$a = '';
for ($i = 0; $i < strlen($s); ++$i) {
    if ($s[$i] === 'B') $a = substr($a, 0, -1);
    else $a .= $s[$i];
}
echo $a;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}

Score : 200 points

Problem Statement

Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.

To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:

The 0 key: a letter 0 will be inserted to the right of the string.

The 1 key: a letter 1 will be inserted to the right of the string.

The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.

Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?

Constraints

1 ≦ |s| ≦ 10 (|s| denotes the length of s)

s consists of the letters 0, 1 and B.

The correct answer is not an empty string.

Input

The input is given from Standard Input in the following format:

s

Output

Print the string displayed in the editor in the end.

Sample Input 1

01B0

Sample Output 1

00

Each time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.

Sample Input 2

0BB1

Sample Output 2

1

Each time the key is pressed, the string in the editor will change as follows: 0, (empty), (empty), 1.


<?php
fscanf(STDIN, "%d", $n);
$array = array();
$array = explode(' ', trim(fgets(STDIN)));  # explodeで行全部を配列に取り込む。

$Sk = array();
for($k = -100; $k <= 100; $k++){
    $total = 0;
    for($i = 0; $i < $n; $i++){
        $total += ($k - $array[$i]) ** 2;
    }
    $Sk[$k] = $total;
}
print min($Sk);

Score : 200 points

Problem Statement

Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.

He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).

Find the minimum total cost to achieve his objective.

Constraints

1≦N≦100

-100≦a_i≦100

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum total cost to achieve Evi's objective.

Sample Input 1

2
4 8

Sample Output 1

8

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

Sample Input 2

3
1 1 3

Sample Output 2

3

Transforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.

Sample Input 3

3
4 2 5

Sample Output 3

5

Leaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.

Sample Input 4

4
-100 -100 -100 -100

Sample Output 4

0

Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.


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

$v = round(array_sum($a) / $n);
$x = 0;
foreach ($a as $b) {
	$x += ($b - $v) ** 2;
}
echo $x, "\n";


Score : 400 points

Problem Statement

Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

Constraints

2 ≦ |s| ≦ 10^5

s consists of lowercase letters.

Partial Score

200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.

Input

The input is given from Standard Input in the following format:

s

Output

If there exists no unbalanced substring of s, print -1 -1.

If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.

Sample Input 1

needed

Sample Output 1

2 5

The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

Sample Input 2

atcoder

Sample Output 2

-1 -1

The string atcoder contains no unbalanced substring.


<?php
function getArrayChar($string)
{
	$array_char = array();
	$length = strlen($string);
	for ($i = 0; $i < $length; $i++) {
	    $array_char[] = $string[$i];
	}
	return $array_char;
}
function checkIsUnbalance($string, $string_check)
{
	$result['value'] = false;
	$num_length = strlen($string_check);
	$array_char = getArrayChar($string_check);
	$array_char = array_unique($array_char);
	if (count($array_char) <= 1) {
		return $result;
	}

	for ($i = 0; $i < $num_length; $i++) {
		$char = $string_check[$i];
		if (substr_count($string_check, $char) > ($num_length/2)) {
			$result['value']    = true;
			$result['position_start'] = strpos($string, $char) + 1;
			$result['position_end'] = (strpos($string, $string_check) + 1) + ($num_length - 1);
			return $result;
		}
	}
	return $result;
}
function createAllSubStr($string, $array_char)
{
	$array_sub_string = array();
	$count_letter     = count($array_char);
	unset($array_char[0]);
	for ($i = 2; $i < $count_letter; $i++) {
		for ($j = 1; $j < $count_letter; $j++) {
			$str_string = substr($string, $j, $i);
			if (strlen($str_string) > 1) {
				$array_sub_string[] = $str_string;
			}
		}
	}

	for ($i = 0; $i < $count_letter; $i++) {
		unset($array_char[$i]);
		if (count($array_char) >= 2) {
			$array_sub_string[] = implode("", $array_char);
		}
	}

	return $array_sub_string;
}

fscanf(STDIN, "%s", $string);
$array_char       = getArrayChar($string);
$array_sub_string = createAllSubStr($string, $array_char);
$count_sub_string = count($array_sub_string);
$has_unbalance = false;
for ($i = 0; $i < $count_sub_string; $i++) {
	$result = checkIsUnbalance($string, $array_sub_string[$i]);
	if ($result['value']) {
		$has_unbalance = true;
		echo $result['position_start'] . " " . $result['position_end'];
		return;
	}
}

if (!$has_unbalance) {
	echo "-1 -1 ";
}

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
if($a > 0 && $b > 0){
    echo "Positive\n";
}elseif($a * $b <= 0){
    echo "Zero\n";
}else{
    echo (($b - $a) % 2) == 0 ? "Negative\n" : "Positive\n";
}

Problem Statement

You are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.

Constraints

a and b are integers.

-10^9≤a≤b≤10^9

Partial Score

In test cases worth 100 points, -10≤a≤b≤10.

Input

The input is given from Standard Input in the following format:

a b

Output

If the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.

Sample Input 1

1 3

Sample Output 1

Positive

1×2×3=6 is positive.

Sample Input 2

-3 -1

Sample Output 2

Negative

(-3)×(-2)×(-1)=-6 is negative.

Sample Input 3

-1 1

Sample Output 3

Zero

(-1)×0×1=0.


<?php
    /*
        Problem URL : http://arc058.contest.atcoder.jp/tasks/arc058_a

        Score  :
        Result :
        Time   : ms
        Memory : KB
     */

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    // define('DEBUG', true);
    define('DEBUG', false);

    // N“ú‚ÅKŸ
    fscanf(STDIN, "%d %d", $N, $K);
    $D = explode(" ", trim(fgets(STDIN)));

    for ($i = $N; $i < 100000; $i++) {
        $str = str_split($i);
        // var_dump($str);
        $len = count($str);
        $bool = true;
        for ($j = 0; $j < $len; $j++) {
            if (in_array($str[$j], $D) === true) {
                $bool = false;
            }
        }
        if ($bool === true) {
            echo $i . PHP_EOL;
            exit;
        }
    }

Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

1 ≦ N < 10000

1 ≦ K < 10

0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999


<?php

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

$counted = array_count_values($input);

print ($counted[5] == 2) && ($counted[7] ==1) ? 'YES' : 'NO';

Score : 100 points

Problem Statement

Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Constraints

1≦A,B,C≦10

Input

The input is given from Standard Input in the following format:

A B C

Output

If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.

Sample Input 1

5 5 7

Sample Output 1

YES

Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.

Sample Input 2

7 7 5

Sample Output 2

NO


<?php

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

$d = explode(' ', rtrim(fgets(STDIN),PHP_EOL));

//var_dump($d);exit;
//$flg = false;
for ($i=$n;$i<=100000;$i++) {

    $str = str_split($i);
//    $cnt = 0;

    foreach ($str as $word) {
        if (in_array($word, $d)){
            continue 2;
        }

//        $cnt += 1;
//
//        if($cnt == count($str)){
//            print($i);
//            exit;
//        }
    }

    echo $i.PHP_EOL;
    exit;

}


<?php

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

$expend = (int)$input[0];
$count = (int)$input[1];

while(true){
	$input = explode(' ', trim(fgets(STDIN)));
	foreach ($input as $value) {
		if ($value !== '') {
			$args[] = $value;
		}
		if (count($args) >= $count) {
			break;
		}
	}
	if (count($args) >= $count) {
		break;
	}
}

$e_str = (string)$expend;
$len = strlen($e_str);//桁数

while (true) {
	if (validate($expend, $args)) {
		echo $expend;
		exit(0);
	}
	$expend = $expend + 1;
}

function validate($int, $not_usable){
	$str = (string)$int;
	$c = count($str);
	for ($i=0; $i < $c; $i++) {
		if (in_array($str[$i], $not_usable)) {
			return false;
		}
	}
	return true;
}


Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135