id
stringlengths 6
6
| slug_name
stringlengths 1
105
| pretty_content
stringlengths 1
27.2k
| test_cases
sequencelengths 1
1
|
---|---|---|---|
p03556 | AtCoder Beginner Contest 077 - Around Square | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the largest square number not exceeding <var>N</var>. Here, a <em>square number</em> is an integer that can be represented as the square of an integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^9</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest square number not exceeding <var>N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>10</var> is not square, but <var>9 = 3 Γ 3</var> is. Thus, we print <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>81
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>81
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>271828182
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>271821169
</pre></section>
</div>
</span> | [
[
"10\n",
"10\n"
]
] |
p03557 | AtCoder Beginner Contest 077 - Snuke Festival | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.</p>
<p>He has <var>N</var> parts for each of the three categories. The size of the <var>i</var>-th upper part is <var>A_i</var>, the size of the <var>i</var>-th middle part is <var>B_i</var>, and the size of the <var>i</var>-th lower part is <var>C_i</var>.</p>
<p>To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.</p>
<p>How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq C_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>...</var> <var>A_N</var>
<var>B_1</var> <var>...</var> <var>B_N</var>
<var>C_1</var> <var>...</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different altars that Ringo can build.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 5
2 4
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The following three altars can be built:</p>
<ul>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>1</var>-st part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>2</var>-nd part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>2</var>-nd part, Lower: <var>2</var>-nd part</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1
2 2 2
3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>27
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>87
</pre></section>
</div>
</span> | [
[
"2\n1 5\n2 4\n3 6\n",
"2\n1 5\n2 4\n3 6\n"
]
] |
p03558 | AtCoder Beginner Contest 077 - Small Multiple | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq 10^5</var></li>
<li><var>K</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>12=6Γ2</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>41
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p><var>11111=41Γ271</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>79992
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36
</pre></section>
</div>
</span> | [
[
"6\n",
"6\n"
]
] |
p03559 | AtCoder Regular Contest 084 - Snuke Festival | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.</p>
<p>He has <var>N</var> parts for each of the three categories. The size of the <var>i</var>-th upper part is <var>A_i</var>, the size of the <var>i</var>-th middle part is <var>B_i</var>, and the size of the <var>i</var>-th lower part is <var>C_i</var>.</p>
<p>To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.</p>
<p>How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq C_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>...</var> <var>A_N</var>
<var>B_1</var> <var>...</var> <var>B_N</var>
<var>C_1</var> <var>...</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different altars that Ringo can build.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 5
2 4
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The following three altars can be built:</p>
<ul>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>1</var>-st part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>2</var>-nd part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>2</var>-nd part, Lower: <var>2</var>-nd part</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1
2 2 2
3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>27
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>87
</pre></section>
</div>
</span> | [
[
"2\n1 5\n2 4\n3 6\n",
"2\n1 5\n2 4\n3 6\n"
]
] |
p03560 | AtCoder Regular Contest 084 - Small Multiple | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq 10^5</var></li>
<li><var>K</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>12=6Γ2</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>41
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p><var>11111=41Γ271</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>79992
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36
</pre></section>
</div>
</span> | [
[
"6\n",
"6\n"
]
] |
p03561 | AtCoder Regular Contest 084 - Finite Encyclopedia of Integer Sequences | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between <var>1</var> and <var>N</var> (inclusive) consisting of integers between <var>1</var> and <var>K</var> (inclusive) are listed.</p>
<p>Let the total number of sequences listed in FEIS be <var>X</var>. Among those sequences, find the <var>(X/2)</var>-th (rounded up to the nearest integer) lexicographically smallest one.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,K \leq 3 Γ 10^5</var></li>
<li><var>N</var> and <var>K</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var> <var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the <var>(X/2)</var>-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where <var>X</var> is the total number of sequences listed in FEIS.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 1
</pre>
<p>There are <var>12</var> sequences listed in FEIS: <var>(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3)</var>.
The <var>(12/2 = 6)</var>-th lexicographically smallest one among them is <var>(2,1)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 2 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3 3 3 3 3 3 3 3 3 3 3 3 2 2
</pre></section>
</div>
</span> | [
[
"3 2\n",
"3 2\n"
]
] |
p03562 | AtCoder Regular Contest 084 - XorShift | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> non-negative integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p>
<p>Takahashi can perform the following two kinds of operations any number of times in any order:</p>
<ul>
<li>Select one integer written on the board (let this integer be <var>X</var>). Write <var>2X</var> on the board, without erasing the selected integer.</li>
<li>Select two integers, possibly the same, written on the board (let these integers be <var>X</var> and <var>Y</var>). Write <var>X</var> XOR <var>Y</var> (XOR stands for bitwise xor) on the blackboard, without erasing the selected integers.</li>
</ul>
<p>How many different integers not exceeding <var>X</var> can be written on the blackboard? We will also count the integers that are initially written on the board.
Since the answer can be extremely large, find the count modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 6</var></li>
<li><var>1 \leq X < 2^{4000}</var></li>
<li><var>1 \leq A_i < 2^{4000}(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
<li><var>X</var> and <var>A_i(1\leq i\leq N)</var> are given in binary notation, with the most significant digit in each of them being <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
<var>A_1</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different integers not exceeding <var>X</var> that can be written on the blackboard.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 111
1111
10111
10010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Initially, <var>15</var>, <var>23</var> and <var>18</var> are written on the blackboard. Among the integers not exceeding <var>7</var>, four integers, <var>0</var>, <var>3</var>, <var>5</var> and <var>6</var>, can be written.
For example, <var>6</var> can be written as follows:</p>
<ul>
<li>Double <var>15</var> to write <var>30</var>.</li>
<li>Take XOR of <var>30</var> and <var>18</var> to write <var>12</var>.</li>
<li>Double <var>12</var> to write <var>24</var>.</li>
<li>Take XOR of <var>30</var> and <var>24</var> to write <var>6</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 100100
1011
1110
110101
1010110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>37
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 111001100101001
10111110
1001000110
100000101
11110000011
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1843
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 111111111111111111111111111111111111111111111111111111111111111
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>466025955
</pre>
<p>Be sure to find the count modulo <var>998244353</var>.</p></section>
</div>
</span> | [
[
"3 111\n1111\n10111\n10010\n",
"3 111\n1111\n10111\n10010\n"
]
] |
p03563 | AtCoder Beginner Contest 076 - Rating Goal | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is a user of a site that hosts programming contests.<br/>
When a user competes in a contest, the <em>rating</em> of the user (not necessarily an integer) changes according to the <em>performance</em> of the user, as follows: </p>
<ul>
<li>Let the current rating of the user be <var>a</var>.</li>
<li>Suppose that the performance of the user in the contest is <var>b</var>.</li>
<li>Then, the new rating of the user will be the avarage of <var>a</var> and <var>b</var>.</li>
</ul>
<p>For example, if a user with rating <var>1</var> competes in a contest and gives performance <var>1000</var>, his/her new rating will be <var>500.5</var>, the average of <var>1</var> and <var>1000</var>.</p>
<p>Takahashi's current rating is <var>R</var>, and he wants his rating to be exactly <var>G</var> after the next contest.<br/>
Find the performance required to achieve it. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq R, G \leq 4500</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>R</var>
<var>G</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the performance required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2002
2017
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2032
</pre>
<p>Takahashi's current rating is <var>2002</var>.<br/>
If his performance in the contest is <var>2032</var>, his rating will be the average of <var>2002</var> and <var>2032</var>, which is equal to the desired rating, <var>2017</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4500
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-4500
</pre>
<p>Although the current and desired ratings are between <var>0</var> and <var>4500</var>, the performance of a user can be below <var>0</var>.</p></section>
</div>
</span> | [
[
"2002\n2017\n",
"2002\n2017\n"
]
] |
p03564 | AtCoder Beginner Contest 076 - Addition and Multiplication | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Square1001 has seen an electric bulletin board displaying the integer <var>1</var>.
He can perform the following operations A and B to change this value:</p>
<ul>
<li>Operation A: The displayed value is doubled.</li>
<li>Operation B: The displayed value increases by <var>K</var>.</li>
</ul>
<p>Square1001 needs to perform these operations <var>N</var> times in total.
Find the minimum possible value displayed in the board after <var>N</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, K \leq 10</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value displayed in the board after <var>N</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The value will be minimized when the operations are performed in the following order: A, A, B, B.<br/>
In this case, the value will change as follows: <var>1</var> β <var>2</var> β <var>4</var> β <var>7</var> β <var>10</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>76
</pre>
<p>The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.<br/>
In this case, the value will change as follows: <var>1</var> β <var>2</var> β <var>4</var> β <var>8</var> β <var>16</var> β <var>26</var> β <var>36</var> β <var>46</var> β <var>56</var> β <var>66</var> β <var>76</var>. </p>
<p>By the way, this contest is AtCoder Beginner Contest 076.</p></section>
</div>
</span> | [
[
"4\n3\n",
"4\n3\n"
]
] |
p03565 | AtCoder Beginner Contest 076 - Dubious Document 2 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>E869120 found a chest which is likely to contain treasure.<br/>
However, the chest is locked. In order to open it, he needs to enter a string <var>S</var> consisting of lowercase English letters.<br/>
He also found a string <var>S'</var>, which turns out to be the string <var>S</var> with some of its letters (possibly all or none) replaced with <code>?</code>. </p>
<p>One more thing he found is a sheet of paper with the following facts written on it: </p>
<ul>
<li>Condition 1: The string <var>S</var> contains a string <var>T</var> as a contiguous substring.</li>
<li>Condition 2: <var>S</var> is the lexicographically smallest string among the ones that satisfy Condition 1.</li>
</ul>
<p>Print the string <var>S</var>.<br/>
If such a string does not exist, print <code>UNRESTORABLE</code>. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S'|, |T| \leq 50</var></li>
<li><var>S'</var> consists of lowercase English letters and <code>?</code>.</li>
<li><var>T</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>T'</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string <var>S</var>.<br/>
If such a string does not exist, print <code>UNRESTORABLE</code> instead. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>?tc????
coder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>atcoder
</pre>
<p>There are <var>26</var> strings that satisfy Condition 1: <code>atcoder</code>, <code>btcoder</code>, <code>ctcoder</code>,..., <code>ztcoder</code>.
Among them, the lexicographically smallest is <code>atcoder</code>, so we can say <var>S = </var><code>atcoder</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>??p??d??
abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>UNRESTORABLE
</pre>
<p>There is no string that satisfies Condition 1, so the string <var>S</var> does not exist.</p></section>
</div>
</span> | [
[
"?tc????\ncoder\n",
"?tc????\ncoder\n"
]
] |
p03566 | AtCoder Beginner Contest 076 - AtCoder Express | <span class="lang-en">
<p>ο»ΏScore : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called <em>AtCoder Express</em>.</p>
<p>In the plan developed by the president Takahashi, the trains will run as follows:</p>
<ul>
<li>A train will run for <var>(t_1 + t_2 + t_3 + ... + t_N)</var> seconds.</li>
<li>In the first <var>t_1</var> seconds, a train must run at a speed of at most <var>v_1</var> m/s (meters per second). Similarly, in the subsequent <var>t_2</var> seconds, a train must run at a speed of at most <var>v_2</var> m/s, and so on.</li>
</ul>
<p>According to the specifications of the trains, the acceleration of a train must be always within <var>Β±1m/s^2</var>. Additionally, a train must stop at the beginning and the end of the run.</p>
<p>Find the maximum possible distance that a train can cover in the run.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq t_i \leq 200</var></li>
<li><var>1 \leq v_i \leq 100</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>t_1</var> <var>t_2</var> <var>t_3</var> β¦ <var>t_N</var>
<var>v_1</var> <var>v_2</var> <var>v_3</var> β¦ <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible that a train can cover in the run.<br/>
Output is considered correct if its absolute difference from the judge's output is at most <var>10^{-3}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
100
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2100.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/69c1f4241b608bc36f1f08dd4184d3f0.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>30</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>450</var> meters.</li>
<li>In the subsequent <var>40</var> seconds, it maintains the velocity of <var>30m/s</var>, covering <var>1200</var> meters.</li>
<li>In the last <var>30</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>450</var> meters.</li>
</ul>
<p>The total distance covered is <var>450</var> + <var>1200</var> + <var>450</var> = <var>2100</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
60 50
34 38
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2632.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/a3e07ea723f50df04461165bc2cc8890.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>34</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>578</var> meters.</li>
<li>In the subsequent <var>26</var> seconds, it maintains the velocity of <var>34m/s</var>, covering <var>884</var> meters.</li>
<li>In the subsequent <var>4</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>144</var> meters.</li>
<li>In the subsequent <var>8</var> seconds, it maintains the velocity of <var>38m/s</var>, covering <var>304</var> meters.</li>
<li>In the last <var>38</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>722</var> meters.</li>
</ul>
<p>The total distance covered is <var>578</var> + <var>884</var> + <var>144</var> + <var>304</var> + <var>722</var> = <var>2632</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
12 14 2
6 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>76.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/77f821f590cb19d8e449303a102422dc.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>6</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>18</var> meters.</li>
<li>In the subsequent <var>2</var> seconds, it maintains the velocity of <var>6m/s</var>, covering <var>12</var> meters.</li>
<li>In the subsequent <var>4</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>16</var> meters.</li>
<li>In the subsequent <var>14</var> seconds, it maintains the velocity of <var>2m/s</var>, covering <var>28</var> meters.</li>
<li>In the last <var>2</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>2</var> meters.</li>
</ul>
<p>The total distance covered is <var>18</var> + <var>12</var> + <var>16</var> + <var>28</var> + <var>2</var> = <var>76</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
9
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>20.250000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/ebde8cbeb649ae7fd338180c0562ae0b.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>4.5</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>10.125</var> meters.</li>
<li>In the last <var>4.5</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>10.125</var> meters.</li>
</ul>
<p>The total distance covered is <var>10.125</var> + <var>10.125</var> = <var>20.25</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>20291.000000000000
</pre></section>
</div>
</span> | [
[
"1\n100\n30\n",
"1\n100\n30\n"
]
] |
p03567 | CODE FESTIVAL 2017 qual C - Can you get AC? | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke built an online judge to hold a programming contest.</p>
<p>When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string <var>S</var> as a contiguous substring.
(The judge can return any two-character substring of <var>S</var>.)</p>
<p>Determine whether the judge can return the string <code>AC</code> as the verdict to a program.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq |S| \leq 5</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the judge can return the string <code>AC</code> as a verdict to a program, print <code>Yes</code>; if it cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BACD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The string <code>AC</code> appears in <code>BACD</code> as a contiguous substring (the second and third characters).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ABCD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Although the string <code>ABCD</code> contains both <code>A</code> and <code>C</code> (the first and third characters), the string <code>AC</code> does not appear in <code>ABCD</code> as a contiguous substring.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>CABD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>ACACA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>XX
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>No
</pre></section>
</div>
</span> | [
[
"BACD\n",
"BACD\n"
]
] |
p03568 | CODE FESTIVAL 2017 qual C - Similar Arrays | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will say that two integer sequences of length <var>N</var>, <var>x_1, x_2, ..., x_N</var> and <var>y_1, y_2, ..., y_N</var>, are <em>similar</em> when <var>|x_i - y_i| \leq 1</var> holds for all <var>i</var> (<var>1 \leq i \leq N</var>).</p>
<p>In particular, any integer sequence is similar to itself.</p>
<p>You are given an integer <var>N</var> and an integer sequence of length <var>N</var>, <var>A_1, A_2, ..., A_N</var>.</p>
<p>How many integer sequences <var>b_1, b_2, ..., b_N</var> are there such that <var>b_1, b_2, ..., b_N</var> is similar to <var>A</var> and the product of all elements, <var>b_1 b_2 ... b_N</var>, is even?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10</var></li>
<li><var>1 \leq A_i \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of integer sequences that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>There are seven integer sequences that satisfy the condition:</p>
<ul>
<li><var>1, 2</var></li>
<li><var>1, 4</var></li>
<li><var>2, 2</var></li>
<li><var>2, 3</var></li>
<li><var>2, 4</var></li>
<li><var>3, 2</var></li>
<li><var>3, 4</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>26
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
90 52 56 71 44 8 13 30 57 84
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>58921
</pre></section>
</div>
</span> | [
[
"2\n2 3\n",
"2\n2 3\n"
]
] |
p03569 | CODE FESTIVAL 2017 qual C - Inserting 'x' | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters.
Snuke can perform the following operation repeatedly:</p>
<ul>
<li>Insert a letter <code>x</code> to any position in <var>s</var> of his choice, including the beginning and end of <var>s</var>.</li>
</ul>
<p>Snuke's objective is to turn <var>s</var> into a palindrome.
Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward.
For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 10^5</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is achievable, print the number of operations required.
If it is not, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>xabxa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One solution is as follows (newly inserted <code>x</code> are shown in bold):</p>
<p>xabxa β xa<strong>x</strong>bxa β xaxbxa<strong>x</strong></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>No sequence of operations can turn <var>s</var> into a palindrome.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>a
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p><var>s</var> is a palindrome already at the beginning.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>oxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
<p>One solution is as follows:</p>
<p>oxxx β <strong>x</strong>oxxx β <strong>x</strong>xoxxx β <strong>x</strong>xxoxxx</p></section>
</div>
</span> | [
[
"xabxa\n",
"xabxa\n"
]
] |
p03570 | CODE FESTIVAL 2017 qual C - Yet Another Palindrome Partitioning | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters.
Snuke is partitioning <var>s</var> into some number of non-empty substrings.
Let the subtrings obtained be <var>s_1</var>, <var>s_2</var>, <var>...</var>, <var>s_N</var> from left to right. (Here, <var>s = s_1 + s_2 + ... + s_N</var> holds.)
Snuke wants to satisfy the following condition:</p>
<ul>
<li>For each <var>i</var> (<var>1 \leq i \leq N</var>), it is possible to permute the characters in <var>s_i</var> and obtain a palindrome.</li>
</ul>
<p>Find the minimum possible value of <var>N</var> when the partition satisfies the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 2 \times 10^5</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of <var>N</var> when the partition satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aabxyyzz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The solution is to partition <var>s</var> as <code>aabxyyzz</code> = <code>aab</code> + <code>xyyzz</code>.
Here, <code>aab</code> can be permuted to form a palindrome <code>aba</code>, and <code>xyyzz</code> can be permuted to form a palindrome <code>zyxyz</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>byebye
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p><code>byebye</code> can be permuted to form a palindrome <code>byeeyb</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcdefghijklmnopqrstuvwxyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>26
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>abcabcxabcx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
<p>The solution is to partition <var>s</var> as <code>abcabcxabcx</code> = <code>a</code> + <code>b</code> + <code>cabcxabcx</code>.</p></section>
</div>
</span> | [
[
"aabxyyzz\n",
"aabxyyzz\n"
]
] |
p03571 | CODE FESTIVAL 2017 qual C - Cubes | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We constructed a rectangular parallelepiped of dimensions <var>A \times B \times C</var> built of <var>ABC</var> cubic blocks of side <var>1</var>.
Then, we placed the parallelepiped in <var>xyz</var>-space as follows:</p>
<ul>
<li>For every triple <var>i, j, k</var> (<var>0 \leq i < A, 0 \leq j < B, 0 \leq k < C</var>), there exists a block that has a diagonal connecting the points <var>(i, j, k)</var> and <var>(i + 1, j + 1, k + 1)</var>. All sides of the block are parallel to a coordinate axis.</li>
</ul>
<p>For each triple <var>i, j, k</var>, we will call the above block as block <var>(i, j, k)</var>.</p>
<p>For two blocks <var>(i_1, j_1, k_1)</var> and <var>(i_2, j_2, k_2)</var>, we will define the distance between them as max<var>(|i_1 - i_2|, |j_1 - j_2|, |k_1 - k_2|)</var>.</p>
<p>We have passed a wire with a negligible thickness through a segment connecting the points <var>(0, 0, 0)</var> and <var>(A, B, C)</var>.
How many blocks <var>(x,y,z)</var> satisfy the following condition? Find the count modulo <var>10^9 + 7</var>.</p>
<ul>
<li>There exists a block <var>(x', y', z')</var> such that the wire passes inside the block <var>(x', y', z')</var> (not just boundary) and the distance between the blocks <var>(x, y, z)</var> and <var>(x', y', z')</var> is at most <var>D</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B < C \leq 10^{9}</var></li>
<li>Any two of the three integers <var>A, B</var> and <var>C</var> are coprime.</li>
<li><var>0 \leq D \leq 50,000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the blocks that satisfy the condition, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>54
</pre>
<p>The figure below shows the parallelepiped, sliced into five layers by planes parallel to <var>xy</var>-plane.
Here, the layer in the region <var>i - 1 \leq z \leq i</var> is called layer <var>i</var>.</p>
<p>The blocks painted black are penetrated by the wire, and satisfy the condition.
The other blocks that satisfy the condition are painted yellow.</p>
<div style="text-align: center;">
<img alt="b09f2a541e463456c01d148eabdf36c3.png" src="https://img.atcoder.jp/code-festival-2017-qualc/b09f2a541e463456c01d148eabdf36c3.png">
</img></div>
<p>There are <var>54</var> blocks that are painted black or yellow.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 3 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>There are four blocks that are penetrated by the wire, and only these blocks satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 5 7 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>105
</pre>
<p>All blocks satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 123456781 1000000000 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>444124403
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1234 12345 1234567 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>150673016
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>999999997 999999999 1000000000 50000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>8402143
</pre></section>
</div>
</span> | [
[
"3 4 5 1\n",
"3 4 5 1\n"
]
] |
p03572 | CODE FESTIVAL 2017 qual C - Three Gluttons | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Three men, A, B and C, are eating sushi together.
Initially, there are <var>N</var> pieces of sushi, numbered <var>1</var> through <var>N</var>.
Here, <var>N</var> is a multiple of <var>3</var>.</p>
<p>Each of the three has likes and dislikes in sushi.
A's preference is represented by <var>(a_1,\ ...,\ a_N)</var>, a permutation of integers from <var>1</var> to <var>N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), A's <var>i</var>-th favorite sushi is Sushi <var>a_i</var>.
Similarly, B's and C's preferences are represented by <var>(b_1,\ ...,\ b_N)</var> and <var>(c_1,\ ...,\ c_N)</var>, permutations of integers from <var>1</var> to <var>N</var>.</p>
<p>The three repeats the following action until all pieces of sushi are consumed or a fight brakes out (described later):</p>
<ul>
<li>Each of the three A, B and C finds his most favorite piece of sushi among the remaining pieces. Let these pieces be Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. If <var>x</var>, <var>y</var> and <var>z</var> are all different, A, B and C eats Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. Otherwise, a fight brakes out.</li>
</ul>
<p>You are given A's and B's preferences, <var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var>.
How many preferences of C, <var>(c_1,\ ...,\ c_N)</var>, leads to all the pieces of sushi being consumed without a fight?
Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 399</var></li>
<li><var>N</var> is a multiple of <var>3</var>.</li>
<li><var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var> are permutations of integers from <var>1</var> to <var>N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>...</var> <var>a_N</var>
<var>b_1</var> <var>...</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the preferences of C that leads to all the pieces of sushi being consumed without a fight, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The answer is two, <var>(c_1,\ c_2,\ c_3) = (3,\ 1,\ 2),\ (3,\ 2,\ 1)</var>.
In both cases, A, B and C will eat Sushi <var>1</var>, <var>2</var> and <var>3</var>, respectively, and there will be no more sushi.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Regardless of what permutation <var>(c_1,\ c_2,\ c_3)</var> is, A and B will try to eat Sushi <var>1</var>, resulting in a fight.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2 3 4 5 6
2 1 4 3 6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>80
</pre>
<p>For example, if <var>(c_1,\ c_2,\ c_3,\ c_4,\ c_5,\ c_6) = (5,\ 1,\ 2,\ 6,\ 3,\ 4)</var>, A, B and C will first eat Sushi <var>1</var>, <var>2</var> and <var>5</var>, respectively, then they will eat Sushi <var>3</var>, <var>4</var> and <var>6</var>, respectively, and there will be no more sushi.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
1 2 3 4 5 6
6 5 4 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>160
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>33600
</pre></section>
</div>
</span> | [
[
"3\n1 2 3\n2 3 1\n",
"3\n1 2 3\n2 3 1\n"
]
] |
p03573 | AtCoder Beginner Contest 075 - One out of Three | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three integers, <var>A</var>, <var>B</var> and <var>C</var>.<br/>
Among them, two are the same, but the remaining one is different from the rest.<br/>
For example, when <var>A=5,B=7,C=5</var>, <var>A</var> and <var>C</var> are the same, but <var>B</var> is different.<br/>
Find the one that is different from the rest among the given three integers. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-100 \leq A,B,C \leq 100</var> </li>
<li><var>A</var>, <var>B</var> and <var>C</var> are integers.</li>
<li>The input satisfies the condition in the statement.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Among <var>A</var>, <var>B</var> and <var>C</var>, print the integer that is different from the rest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>This is the same case as the one in the statement.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
<p>In this case, <var>C</var> is the one we seek.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>-100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-100
</pre></section>
</div>
</span> | [
[
"5 7 5\n",
"5 7 5\n"
]
] |
p03574 | AtCoder Beginner Contest 075 - Minesweeper | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an <var>H Γ W</var> grid.<br/>
The squares in the grid are described by <var>H</var> strings, <var>S_1,...,S_H</var>.<br/>
The <var>j</var>-th character in the string <var>S_i</var> corresponds to the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left <var>(1 \leq i \leq H,1 \leq j \leq W)</var>.<br/>
<code>.</code> stands for an empty square, and <code>#</code> stands for a square containing a bomb. </p>
<p>Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.<br/>
(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)<br/>
He decides to replace each <code>.</code> in our <var>H</var> strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. </p>
<p>Print the strings after the process. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 50</var></li>
<li><var>S_i</var> is a string of length <var>W</var> consisting of <code>#</code> and <code>.</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>H</var> <var>W</var>
<var>S_1</var>
<var>:</var>
<var>S_H</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the <var>H</var> strings after the process.<br/>
The <var>i</var>-th line should contain a string <var>T_i</var> of length <var>W</var>, where the <var>j</var>-th character in <var>T_i</var> corresponds to the square at the <var>i</var>-th row from the top and <var>j</var>-th row from the left in the grid <var>(1 \leq i \leq H, 1 \leq j \leq W)</var>. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
.....
.#.#.
.....
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11211
1#2#1
11211
</pre>
<p>For example, let us observe the empty square at the first row from the top and first column from the left.<br/>
There is one bomb square adjacent to this empty square: the square at the second row and second column.<br/>
Thus, the <code>.</code> corresponding to this empty square is replaced with <code>1</code>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
#####
#####
#####
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>#####
#####
#####
</pre>
<p>It is possible that there is no empty square. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>#####3
#8#7##
####5#
4#65#2
#5##21
#4#310
</pre></section>
</div>
</span> | [
[
"3 5\n.....\n.#.#.\n.....\n",
"3 5\n.....\n.#.#.\n.....\n"
]
] |
p03575 | AtCoder Beginner Contest 075 - Bridge | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected connected graph with <var>N</var> vertices and <var>M</var> edges that does not contain self-loops and double edges.<br/>
The <var>i</var>-th edge <var>(1 \leq i \leq M)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. </p>
<p>An edge whose removal disconnects the graph is called a <em>bridge</em>.<br/>
Find the number of the edges that are bridges among the <var>M</var> edges. </p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><ul>
<li>A <em>self-loop</em> is an edge <var>i</var> such that <var>a_i=b_i</var> <var>(1 \leq i \leq M)</var>.</li>
<li><em>Double edges</em> are a pair of edges <var>i,j</var> such that <var>a_i=a_j</var> and <var>b_i=b_j</var> <var>(1 \leq i<j \leq M)</var>.</li>
<li>An undirected graph is said to be <em>connected</em> when there exists a path between every pair of vertices.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>N-1 \leq M \leq min(N(Nβ1)β2,50)</var></li>
<li><var>1 \leq a_i<b_i \leq N</var></li>
<li>The given graph does not contain self-loops and double edges.</li>
<li>The given graph is connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the edges that are bridges among the <var>M</var> edges.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The figure below shows the given graph:</p>
<div style="text-align: center;">
<img alt="570677a9809fd7a5b63bff11e5d9bf79.png" src="https://img.atcoder.jp/abc075/570677a9809fd7a5b63bff11e5d9bf79.png">
</img></div>
<p>The edges shown in red are bridges. There are four of them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It is possible that there is no bridge.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 5
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
<p>It is possible that every edge is a bridge.</p></section>
</div>
</span> | [
[
"7 7\n1 3\n2 7\n3 4\n4 5\n4 6\n5 6\n6 7\n",
"7 7\n1 3\n2 7\n3 4\n4 5\n4 6\n5 6\n6 7\n"
]
] |
p03576 | AtCoder Beginner Contest 075 - Axis-Parallel Rectangle | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> points in a two-dimensional plane.<br/>
The coordinates of the <var>i</var>-th point <var>(1 \leq i \leq N)</var> are <var>(x_i,y_i)</var>.<br/>
Let us consider a rectangle whose sides are parallel to the coordinate axes that contains <var>K</var> or more of the <var>N</var> points in its interior.<br/>
Here, points on the sides of the rectangle are considered to be in the interior.<br/>
Find the minimum possible area of such a rectangle. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq N \leq 50</var> </li>
<li><var>-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)</var> </li>
<li><var>x_iβ x_j (1 \leq i<j \leq N)</var> </li>
<li><var>y_iβ y_j (1 \leq i<j \leq N)</var> </li>
<li>All input values are integers. (Added at 21:50 JST) </li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var> <var>K</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_{N}</var> <var>y_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible area of a rectangle that satisfies the condition. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 4
3 3
6 2
8 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>One rectangle that satisfies the condition with the minimum possible area has the following vertices: <var>(1,1)</var>, <var>(8,1)</var>, <var>(1,4)</var> and <var>(8,4)</var>.<br/>
Its area is <var>(8-1) Γ (4-1) = 21</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2
0 0
1 1
2 2
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3999999996000000001
</pre>
<p>Watch out for integer overflows. </p></section>
</div>
</span> | [
[
"4 4\n1 4\n3 3\n6 2\n8 1\n",
"4 4\n1 4\n3 3\n6 2\n8 1\n"
]
] |
p03577 | CODE FESTIVAL 2017 qual B - XXFESTIVAL | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Rng is going to a festival.</p>
<p>The name of the festival is given to you as a string <var>S</var>, which ends with <code>FESTIVAL</code>, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.</p>
<p>Here, assume that the name of "a festival of <var>s</var>" is a string obtained by appending <code>FESTIVAL</code> to the end of <var>s</var>.
For example, <code>CODEFESTIVAL</code> is a festival of <code>CODE</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>9 \leq |S| \leq 50</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
<li><var>S</var> ends with <code>FESTIVAL</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer to the question: "Rng is going to a festival of what?"</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>CODEFESTIVAL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>CODE
</pre>
<p>This is the same as the example in the statement.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>CODEFESTIVALFESTIVAL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>CODEFESTIVAL
</pre>
<p>This string is obtained by appending <code>FESTIVAL</code> to the end of <code>CODEFESTIVAL</code>, so it is a festival of <code>CODEFESTIVAL</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>YAKINIKUFESTIVAL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YAKINIKU
</pre></section>
</div>
</span> | [
[
"CODEFESTIVAL\n",
"CODEFESTIVAL\n"
]
] |
p03578 | CODE FESTIVAL 2017 qual B - Problem Set | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Rng is preparing a problem set for a qualification round of CODEFESTIVAL.</p>
<p>He has <var>N</var> candidates of problems. The difficulty of the <var>i</var>-th candidate is <var>D_i</var>.</p>
<p>There must be <var>M</var> problems in the problem set, and the difficulty of the <var>i</var>-th problem must be <var>T_i</var>. Here, one candidate of a problem cannot be used as multiple problems.</p>
<p>Determine whether Rng can complete the problem set without creating new candidates of problems.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200,000</var></li>
<li><var>1 \leq D_i \leq 10^9</var></li>
<li><var>1 \leq M \leq 200,000</var></li>
<li><var>1 \leq T_i \leq 10^9</var></li>
<li>All numbers in the input are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>100</var> points will be awarded for passing the test set satisfying <var>N \leq 100</var> and <var>M \leq 100</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var>
<var>M</var>
<var>T_1</var> <var>T_2</var> <var>...</var> <var>T_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if Rng can complete the problem set without creating new candidates of problems; print <code>NO</code> if he cannot.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 1 4 1 5
3
5 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
100 200 500 700 1200 1600 2000
6
100 200 500 700 1600 1600
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>Not enough <var>1600</var>s.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
800
5
100 100 100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>15
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
9
5 4 3 2 1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>YES
</pre></section>
</div>
</span> | [
[
"5\n3 1 4 1 5\n3\n5 4 3\n",
"5\n3 1 4 1 5\n3\n5 4 3\n"
]
] |
p03579 | CODE FESTIVAL 2017 qual B - 3 Steps | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Rng has a connected undirected graph with <var>N</var> vertices.
Currently, there are <var>M</var> edges in the graph, and the <var>i</var>-th edge connects Vertices <var>A_i</var> and <var>B_i</var>.</p>
<p>Rng will add new edges to the graph by repeating the following operation:</p>
<ul>
<li>Operation: Choose <var>u</var> and <var>v</var> <var>(u \neq v)</var> such that Vertex <var>v</var> can be reached by traversing exactly three edges from Vertex <var>u</var>, and add an edge connecting Vertices <var>u</var> and <var>v</var>. It is not allowed to add an edge if there is already an edge connecting Vertices <var>u</var> and <var>v</var>.</li>
</ul>
<p>Find the maximum possible number of edges that can be added.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 10^5</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li>The graph has no self-loops or multiple edges.</li>
<li>The graph is connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_M</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the maximum possible number of edges that can be added.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 5
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>If we add edges as shown below, four edges can be added, and no more.</p>
<p><img alt="" src="https://img.atcoder.jp/code-festival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
1 2
2 3
3 1
5 4
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>Five edges can be added, for example, as follows:</p>
<ul>
<li>Add an edge connecting Vertex <var>5</var> and Vertex <var>3</var>.</li>
<li>Add an edge connecting Vertex <var>5</var> and Vertex <var>2</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>1</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>2</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>3</var>.</li>
</ul></section>
</div>
</span> | [
[
"6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6 5\n1 2\n2 3\n3 4\n4 5\n5 6\n"
]
] |
p03580 | CODE FESTIVAL 2017 qual B - 101 to 010 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> cells are arranged in a row.
Some of them may contain tokens.
You are given a string <var>s</var> that consists of <code>0</code>s and <code>1</code>s.
If the <var>i</var>-th character of <var>s</var> is <code>1</code>, the <var>i</var>-th cell (from left) contains a token.
Otherwise, it doesn't contain a token.</p>
<p>Snuke wants to perform the following operation as many times as possible.
In each operation, he chooses three consecutive cells.
Let's call the cells <var>X, Y, Z</var> from left to right.
In order for the operation to be valid, both <var>X</var> and <var>Z</var> must contain tokens and <var>Y</var> must not contain a token.
Then, he removes these two tokens and puts a new token on <var>Y</var>.</p>
<p>How many operations can he perform if he performs operations in the optimal way?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 500,000</var></li>
<li><var>|s| = N</var></li>
<li>Each character in <var>s</var> is either <code>0</code> or <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
1010101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, he can perform two operations in the following way:</p>
<ul>
<li>Perform an operation on the last three cells. Now the string that represents tokens becomes <code>1010010</code>.</li>
<li>Perform an operation on the first three cells. Now the string that represents tokens becomes <code>0100010</code>.</li>
</ul>
<p>Note that the choice of operations matters.
For example, if he chooses three cells in the middle first, he can perform no more operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>50
10101000010011011110001001111110000101010111100110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre></section>
</div>
</span> | [
[
"7\n1010101\n",
"7\n1010101\n"
]
] |
p03581 | CODE FESTIVAL 2017 qual B - Popping Balls | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>A + B</var> balls are arranged in a row.
The leftmost <var>A</var> balls are colored red, and the rightmost <var>B</var> balls are colored blue.</p>
<p>You perform the following operation:</p>
<ul>
<li>First, you choose two integers <var>s, t</var> such that <var>1 \leq s, t \leq A + B</var>.</li>
<li>Then, you repeat the following step <var>A + B</var> times:
In each step, you remove the first ball or the <var>s</var>-th ball (if it exists) or the <var>t</var>-th ball (if it exists, all indices are 1-based) from left in the row, and give it to Snuke.</li>
</ul>
<p>In how many ways can you give the balls to Snuke?
Compute the answer modulo <var>10^9 + 7</var>.</p>
<p>Here, we consider two ways to be different if for some <var>k</var>, the <var>k</var>-th ball given to Snuke has different colors.
In particular, the choice of <var>s, t</var> doesn't matter.
Also, we don't distinguish two balls of the same color.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A, B \leq 2000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>20
</pre>
<p>There are <var>20</var> ways to give <var>3</var> red balls and <var>3</var> blue balls.
It turns out that all of them are possible.</p>
<p>Here is an example of the operation (<code>r</code> stands for red, <code>b</code> stands for blue):</p>
<ul>
<li>You choose <var>s = 3, t = 4</var>.</li>
<li>Initially, the row looks like <code>rrrbbb</code>.</li>
<li>You remove <var>3</var>rd ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rrbbb</code>.</li>
<li>You remove <var>4</var>th ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rrbb</code>.</li>
<li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rbb</code>.</li>
<li>You remove <var>3</var>rd ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rb</code>.</li>
<li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>b</code>.</li>
<li>You remove <var>1</var>st ball (<code>b</code>) and give it to Snuke. Now the row is empty.</li>
</ul>
<p>This way, Snuke receives balls in the order <code>rbrbrb</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>67
</pre>
<p>There are <var>70</var> ways to give <var>4</var> red balls and <var>4</var> blue balls.
Among them, only <code>bbrrbrbr</code>, <code>brbrbrbr</code>, and <code>brrbbrbr</code> are impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7772
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1987 1789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>456315553
</pre></section>
</div>
</span> | [
[
"3 3\n",
"3 3\n"
]
] |
p03582 | CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a string <var>S</var>, let <var>f(S)</var> be the lexicographically smallest cyclic shift of <var>S</var>.
For example, if <var>S = </var><code>babca</code>, <var>f(S) = </var><code>ababc</code> because this is the smallest among all cyclic shifts (<code>babca</code>, <code>abcab</code>, <code>bcaba</code>, <code>cabab</code>, <code>ababc</code>).</p>
<p>You are given three integers <var>X, Y</var>, and <var>Z</var>.
You want to construct a string <var>T</var> that consists of exactly <var>X</var> <code>a</code>s, exactly <var>Y</var> <code>b</code>s, and exactly <var>Z</var> <code>c</code>s.
If there are multiple such strings, you want to choose one that maximizes <var>f(T)</var> lexicographically.</p>
<p>Compute the lexicographically largest possible value of <var>f(T)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X + Y + Z \leq 50</var></li>
<li><var>X, Y, Z</var> are non-negative integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>abab
</pre>
<p><var>T</var> must consist of two <code>a</code>s and two <code>b</code>s.</p>
<ul>
<li>If <var>T = </var><code>aabb</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>abab</code>, <var>f(T) = </var><code>abab</code>.</li>
<li>If <var>T = </var><code>abba</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>baab</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>baba</code>, <var>f(T) = </var><code>abab</code>.</li>
<li>If <var>T = </var><code>bbaa</code>, <var>f(T) = </var><code>aabb</code>.</li>
</ul>
<p>Thus, the largest possible <var>f(T)</var> is <code>abab</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>acb
</pre></section>
</div>
</span> | [
[
"2 2 0\n",
"2 2 0\n"
]
] |
p03583 | Tenka1 Programmer Contest - 4/N | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p>
<p>Find a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> such that <var>4/N = 1/h + 1/n + 1/w</var>.</p>
<p>If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>It is guaranteed that, for the given integer <var>N</var>, there exists a solution such that <var>h,n,w \leq 3500</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> that satisfies the condition, in the following format:</p>
<pre><var>h</var> <var>n</var> <var>w</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2
</pre>
<p><var>4/2 = 1/1 + 1/2 + 1/2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3485
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>872 1012974 1539173474040
</pre>
<p>It is allowed to use an integer exceeding <var>3500</var> in a solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4664
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3498 3498 3498
</pre></section>
</div>
</span> | [
[
"2\n",
"2\n"
]
] |
p03584 | Tenka1 Programmer Contest - IntegerotS | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Seisu-ya</em>, a store specializing in non-negative integers, sells <var>N</var> non-negative integers. The <var>i</var>-th integer is <var>A_i</var> and has a <em>utility</em> of <var>B_i</var>.
There may be multiple equal integers with different utilities.</p>
<p>Takahashi will buy some integers in this store. He can buy a combination of integers whose <em>bitwise OR</em> is less than or equal to <var>K</var>. He wants the sum of utilities of purchased integers to be as large as possible.</p>
<p>Find the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq K < 2^{30}</var></li>
<li><var>0 \leq A_i < 2^{30}(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Buy <var>2</var> and <var>3</var> to achieve the maximum possible total utility, <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 6
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>Buy <var>2</var> and <var>4</var> to achieve the maximum possible total utility, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32
</pre></section>
</div>
</span> | [
[
"3 5\n3 3\n4 4\n2 5\n",
"3 5\n3 3\n4 4\n2 5\n"
]
] |
p03585 | Tenka1 Programmer Contest - CARtesian Coodinate | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> lines in the <var>xy</var>-plane. The <var>i</var>-th line is represented by <var>A_ix+B_iy=C_i</var>.
Any two lines among the <var>N+2</var> lines, the above <var>N</var> lines plus the <var>x</var>-axis and <var>y</var>-axis, cross each other at exactly one point.</p>
<p>For each pair <var>1 \leq i < j \leq N</var>, there is a car at the cross point of the <var>i</var>-th and <var>j</var>-th lines.
Even where three or more lines intersect at a point, a car is individually placed for each pair of lines.
That is, there will be <var>k(k-1)/2</var> cars placed at the intersection of <var>k</var> lines.</p>
<p>Those cars are already very old, and can only be moved parallel to the <var>x</var>-axis or <var>y</var>-axis.</p>
<p>Takahashi will hold an exhibition of antique cars at a place on the <var>xy</var>-plane.
In order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place.
If such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum <var>x</var>-coordinate will be selected.
If the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum <var>y</var>-coordinate will be selected.</p>
<p>Find the place of the exhibition that will be selected.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 4 Γ 10^4</var></li>
<li><var>1 \leq |A_i|,|B_i| \leq 10^4(1 \leq i \leq N)</var></li>
<li><var>0 \leq |C_i| \leq 10^4(1 \leq i \leq N)</var></li>
<li>No two given lines are parallel.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
:
<var>A_N</var> <var>B_N</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the <var>x</var>-coordinate and <var>y</var>-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1 1
2 -1 2
-1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1.000000000000000 1.000000000000000
</pre>
<p><img alt="" src="https://img.atcoder.jp/tenka1-2017/650fff486341589a0388efff446acf0a.png"/></p>
<p>There is a car at each place shown by a blue circle in the figure. The place to be selected is shown by a purple circle.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1 2
1 -1 0
3 -1 -2
1 -3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1.000000000000000 -1.000000000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 7 8
-2 4 9
3 -8 -5
9 2 -14
6 7 5
-8 -9 3
3 8 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1.722222222222222 1.325000000000000
</pre></section>
</div>
</span> | [
[
"3\n1 1 1\n2 -1 2\n-1 2 2\n",
"3\n1 1 1\n2 -1 2\n-1 2 2\n"
]
] |
p03586 | Tenka1 Programmer Contest - ModularPowerEquation!! | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Process the <var>Q</var> queries below.</p>
<ul>
<li>You are given two integers <var>A_i</var> and <var>M_i</var>. Determine whether there exists a positive integer <var>K_i</var> not exceeding <var>2 Γ 10^{18}</var> such that <var>A_i^{K_i} β‘ K_i</var> <var>(mod</var> <var>M_i)</var>, and find one if it exists.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq Q \leq 100</var></li>
<li><var>0 \leq A_i \leq 10^9(1 \leq i \leq Q)</var></li>
<li><var>1 \leq M_i \leq 10^9(1 \leq i \leq Q)</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var>
<var>A_1</var> <var>M_1</var>
:
<var>A_Q</var> <var>M_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>In the <var>i</var>-th line, print <var>-1</var> if there is no integer <var>K_i</var> that satisfies the condition.
Otherwise, print an integer <var>K_i</var> not exceeding <var>2 Γ 10^{18}</var> such that <var>A_i^{K_i} β‘ K_i</var> <var>(mod</var> <var>M_i)</var>. If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 4
3 8
9 6
10 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
11
9
2
</pre>
<p>It can be seen that the condition is satisfied: <var>2^4 = 16 β‘ 4</var> <var>(mod</var> <var>4)</var>, <var>3^{11} = 177147 β‘ 11</var> <var>(mod</var> <var>8)</var>, <var>9^9 = 387420489 β‘ 9</var> <var>(mod</var> <var>6)</var> and <var>10^2 = 100 β‘ 2</var> <var>(mod</var> <var>7)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
177 168
2028 88772
123456789 987654321
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7953
234831584
471523108231963269
</pre></section>
</div>
</span> | [
[
"4\n2 4\n3 8\n9 6\n10 7\n",
"4\n2 4\n3 8\n9 6\n10 7\n"
]
] |
p03587 | Tenka1 Programmer Beginner Contest - Accepted...? | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke prepared <var>6</var> problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.</p>
<p>You are given a string <var>S</var> of length <var>6</var>.
If the <var>i</var>-th character of <var>s</var> is <code>1</code>, it means that the <var>i</var>-th problem prepared by Snuke is accepted to be used; <code>0</code> means that the problem is not accepted.</p>
<p>How many problems prepared by Snuke are accepted to be used in the contest?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>6</var>.</li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of problems prepared by Snuke that are accepted to be used in the contest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>111100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The first, second, third and fourth problems are accepted, for a total of four.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>001001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> | [
[
"111100\n",
"111100\n"
]
] |
p03588 | Tenka1 Programmer Beginner Contest - Different Distribution | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A group of people played a game. All players had distinct scores, which are positive integers.</p>
<p>Takahashi knows <var>N</var> facts on the players' scores. The <var>i</var>-th fact is as follows: the <var>A_i</var>-th highest score among the players is <var>B_i</var>.</p>
<p>Find the maximum possible number of players in the game.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>0 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>If <var>i β j</var>, <var>A_i β A_j</var>.</li>
<li>There exists a possible outcome of the game that are consistent with the facts.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible number of players in the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4 7
2 9
6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>The maximum possible number of players is achieved when, for example, the players have the following scores: <var>12,9,8,7,5,2,1,0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 10
3 6
5 2
4 4
2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 1000000000
1000000000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000001
</pre></section>
</div>
</span> | [
[
"3\n4 7\n2 9\n6 2\n",
"3\n4 7\n2 9\n6 2\n"
]
] |
p03589 | Tenka1 Programmer Beginner Contest - 4/N | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p>
<p>Find a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> such that <var>4/N = 1/h + 1/n + 1/w</var>.</p>
<p>If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>It is guaranteed that, for the given integer <var>N</var>, there exists a solution such that <var>h,n,w \leq 3500</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> that satisfies the condition, in the following format:</p>
<pre><var>h</var> <var>n</var> <var>w</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2
</pre>
<p><var>4/2 = 1/1 + 1/2 + 1/2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3485
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>872 1012974 1539173474040
</pre>
<p>It is allowed to use an integer exceeding <var>3500</var> in a solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4664
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3498 3498 3498
</pre></section>
</div>
</span> | [
[
"2\n",
"2\n"
]
] |
p03590 | Tenka1 Programmer Beginner Contest - IntegerotS | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Seisu-ya</em>, a store specializing in non-negative integers, sells <var>N</var> non-negative integers. The <var>i</var>-th integer is <var>A_i</var> and has a <em>utility</em> of <var>B_i</var>.
There may be multiple equal integers with different utilities.</p>
<p>Takahashi will buy some integers in this store. He can buy a combination of integers whose <em>bitwise OR</em> is less than or equal to <var>K</var>. He wants the sum of utilities of purchased integers to be as large as possible.</p>
<p>Find the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq K < 2^{30}</var></li>
<li><var>0 \leq A_i < 2^{30}(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Buy <var>2</var> and <var>3</var> to achieve the maximum possible total utility, <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 6
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>Buy <var>2</var> and <var>4</var> to achieve the maximum possible total utility, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32
</pre></section>
</div>
</span> | [
[
"3 5\n3 3\n4 4\n2 5\n",
"3 5\n3 3\n4 4\n2 5\n"
]
] |
p03591 | CODE FESTIVAL 2017 qual A - Snuke's favorite YAKINIKU | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo is giving a present to Snuke.</p>
<p>Ringo has found out that Snuke loves <em>yakiniku</em> (a Japanese term meaning grilled meat. <em>yaki</em>: grilled, <em>niku</em>: meat). He supposes that Snuke likes grilled things starting with <code>YAKI</code> in Japanese, and does not like other things.</p>
<p>You are given a string <var>S</var> representing the Japanese name of Ringo's present to Snuke. Determine whether <var>S</var> starts with <code>YAKI</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> starts with <code>YAKI</code>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>YAKINIKU
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>YAKINIKU</code> starts with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>TAKOYAKI
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><code>TAKOYAKI</code> (a Japanese snack. <em>tako</em>: octopus) does not start with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>YAK
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> | [
[
"YAKINIKU\n",
"YAKINIKU\n"
]
] |
p03592 | CODE FESTIVAL 2017 qual A - fLIP | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>M</var> columns of squares. Initially, all the squares are white.</p>
<p>There is a button attached to each row and each column.
When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.
When a button attached to a column is pressed, the colors of all the squares in that column are inverted.</p>
<p>Takahashi can freely press the buttons any number of times. Determine whether he can have exactly <var>K</var> black squares in the grid.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 1000</var></li>
<li><var>0 \leq K \leq NM</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi can have exactly <var>K</var> black squares in the grid, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Press the buttons in the order of the first row, the first column.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>Press the buttons in the order of the first column, third column, second row, fifth column.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7 9 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> | [
[
"2 2 2\n",
"2 2 2\n"
]
] |
p03593 | CODE FESTIVAL 2017 qual A - Palindromic Matrix | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>H</var>-by-<var>W</var> matrix.
Let <var>a_{ij}</var> be the element at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.
In this matrix, each <var>a_{ij}</var> is a lowercase English letter.</p>
<p>Snuke is creating another <var>H</var>-by-<var>W</var> matrix, <var>A'</var>, by freely rearranging the elements in <var>A</var>.
Here, he wants to satisfy the following condition:</p>
<ul>
<li>Every row and column in <var>A'</var> can be read as a palindrome.</li>
</ul>
<p>Determine whether he can create a matrix satisfying the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Note</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward.
For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are all palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ H, W β€ 100</var></li>
<li><var>a_{ij}</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}</var><var>a_{12}</var><var>...</var><var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var><var>a_{H2}</var><var>...</var><var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Snuke can create a matrix satisfying the condition, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
aabb
aabb
aacc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>For example, the following matrix satisfies the condition.</p>
<pre>abba
acca
abba
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
aa
bb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in <var>A</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1
t
w
e
e
t
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>For example, the following matrix satisfies the condition.</p>
<pre>t
e
w
e
t
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 5
abxba
abyba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1 1
z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> | [
[
"3 4\naabb\naabb\naacc\n",
"3 4\naabb\naabb\naacc\n"
]
] |
p03594 | CODE FESTIVAL 2017 qual A - Four Coloring | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares.
We will represent the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left as <var>(i,\ j)</var>.
Also, we will define the distance between the squares <var>(i_1,\ j_1)</var> and <var>(i_2,\ j_2)</var> as <var>|i_1 - i_2| + |j_1 - j_2|</var>.</p>
<p>Snuke is painting each square in red, yellow, green or blue.
Here, for a given positive integer <var>d</var>, he wants to satisfy the following condition:</p>
<ul>
<li>No two squares with distance exactly <var>d</var> have the same color.</li>
</ul>
<p>Find a way to paint the squares satisfying the condition.
It can be shown that a solution always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ H, W β€ 500</var></li>
<li><var>1 β€ d β€ H + W - 2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>d</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a way to paint the squares satisfying the condition, in the following format. If the square <var>(i,\ j)</var> is painted in red, yellow, green or blue, <var>c_{ij}</var> should be <code>R</code>, <code>Y</code>, <code>G</code> or <code>B</code>, respectively.</p>
<pre><var>c_{11}</var><var>c_{12}</var><var>...</var><var>c_{1W}</var>
<var>:</var>
<var>c_{H1}</var><var>c_{H2}</var><var>...</var><var>c_{HW}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>RY
GR
</pre>
<p>There are four pairs of squares with distance exactly <var>1</var>.
As shown below, no two such squares have the same color.</p>
<ul>
<li><var>(1,\ 1)</var>, <var>(1,\ 2)</var> : <code>R</code>, <code>Y</code></li>
<li><var>(1,\ 2)</var>, <var>(2,\ 2)</var> : <code>Y</code>, <code>R</code></li>
<li><var>(2,\ 2)</var>, <var>(2,\ 1)</var> : <code>R</code>, <code>G</code></li>
<li><var>(2,\ 1)</var>, <var>(1,\ 1)</var> : <code>G</code>, <code>R</code></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>RYB
RGB
</pre>
<p>There are six pairs of squares with distance exactly <var>2</var>.
As shown below, no two such squares have the same color.</p>
<ul>
<li><var>(1,\ 1)</var> , <var>(1,\ 3)</var> : <code>R</code> , <code>B</code></li>
<li><var>(1,\ 3)</var> , <var>(2,\ 2)</var> : <code>B</code> , <code>G</code></li>
<li><var>(2,\ 2)</var> , <var>(1,\ 1)</var> : <code>G</code> , <code>R</code></li>
<li><var>(2,\ 1)</var> , <var>(2,\ 3)</var> : <code>R</code> , <code>B</code></li>
<li><var>(2,\ 3)</var> , <var>(1,\ 2)</var> : <code>B</code> , <code>Y</code></li>
<li><var>(1,\ 2)</var> , <var>(2,\ 1)</var> : <code>Y</code> , <code>R</code></li>
</ul></section>
</div>
</span> | [
[
"2 2 1\n",
"2 2 1\n"
]
] |
p03595 | CODE FESTIVAL 2017 qual A - Modern Painting | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo got interested in modern art. He decided to draw a big picture on the board with <var>N+2</var> rows and <var>M+2</var> columns of squares constructed in the venue of CODE FESTIVAL 2017, using some people.</p>
<p>The square at the <var>(i+1)</var>-th row and <var>(j+1)</var>-th column in the board is represented by the pair of integers <var>(i,j)</var>. That is, the top-left square is <var>(0,0)</var>, and the bottom-right square is <var>(N+1,M+1)</var>.
Initially, the squares <var>(x,y)</var> satisfying <var>1 \leq x \leq N</var> and <var>1 \leq y \leq M</var> are painted white, and the other (outermost) squares are painted black.</p>
<p>Ringo arranged people at some of the outermost squares, facing inward.
More specifically, the arrangement of people is represented by four strings <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var>, as follows:</p>
<ul>
<li>For each row except the top and bottom, if the <var>i</var>-th character <var>(1 \leq i \leq N)</var> in <var>A</var> is <code>1</code>, place a person facing right at the square <var>(i,0)</var>; otherwise, do nothing.</li>
<li>For each row except the top and bottom, if the <var>i</var>-th character <var>(1 \leq i \leq N)</var> in <var>B</var> is <code>1</code>, place a person facing left at the square <var>(i,M+1)</var>; otherwise, do nothing.</li>
<li>For each column except the leftmost and rightmost, if the <var>i</var>-th character <var>(1 \leq i \leq M)</var> in <var>C</var> is <code>1</code>, place a person facing down at the square <var>(0,i)</var>; otherwise, do nothing.</li>
<li>For each column except the leftmost and rightmost, if the <var>i</var>-th character <var>(1 \leq i \leq M)</var> in <var>D</var> is <code>1</code>, place a person facing up at the square <var>(N+1,i)</var>; otherwise, do nothing.</li>
</ul>
<p>Each person has a sufficient amount of non-white paint. No two people have paint of the same color.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/code-festival-2017-quala/46a627606452b904221672922d269290.png">
<p>An example of an arrangement of people (For convenience, black squares are displayed in gray)</p>
</img></div>
<p>Ringo repeats the following sequence of operations until all people are dismissed from the venue.</p>
<ul>
<li>Select a person who is still in the venue.</li>
<li>The selected person repeats the following action while the square in front of him/her is white: move one square forward, and paint the square he/she enters with his/her paint. When the square in front of him/her is not white, he/she stops doing the action.</li>
<li>The person is now dismissed from the venue.</li>
</ul>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/code-festival-2017-quala/406bcaf4d52da2ae3b09eedf63ff302e.png">
<p>An example of a way the board is painted</p>
</img></div>
<p>How many different states of the board can Ringo obtain at the end of the process? Find the count modulo <var>998244353</var>.</p>
<p>Two states of the board are considered different when there is a square painted in different colors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 10^5</var></li>
<li><var>|A|=|B|=N</var></li>
<li><var>|C|=|D|=M</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> consist of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A</var>
<var>B</var>
<var>C</var>
<var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different states of the board Ringo can obtain at the end of the process, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
10
01
10
01
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six possible states as shown below.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2017-quala/1dd467cdff8a517c9555abfca0915e2e.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
11
11
11
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 4
111
111
1111
1111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1276
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>17 21
11001010101011101
11001010011010111
111010101110101111100
011010110110101000111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>548356548
</pre>
<p>Be sure to find the count modulo <var>998244353</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>3 4
000
101
1111
0010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>21
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>9 13
111100001
010101011
0000000000000
1010111111101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>177856
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 7</h3><pre>23 30
01010010101010010001110
11010100100100101010101
000101001001010010101010101101
101001000100101001010010101000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 7</h3><pre>734524988
</pre></section>
</div>
</span> | [
[
"2 2\n10\n01\n10\n01\n",
"2 2\n10\n01\n10\n01\n"
]
] |
p03596 | CODE FESTIVAL 2017 qual A - Squeezing Slimes | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>A</var> slimes lining up in a row.
Initially, the sizes of the slimes are all <var>1</var>.</p>
<p>Snuke can repeatedly perform the following operation.</p>
<ul>
<li>Choose a positive even number <var>M</var>. Then, select <var>M</var> consecutive slimes and form <var>M / 2</var> pairs from those slimes as follows: pair the <var>1</var>-st and <var>2</var>-nd of them from the left, the <var>3</var>-rd and <var>4</var>-th of them, <var>...</var>, the <var>(M-1)</var>-th and <var>M</var>-th of them. Combine each pair of slimes into one larger slime. Here, the size of a combined slime is the sum of the individual slimes before combination. The order of the <var>M / 2</var> combined slimes remain the same as the <var>M / 2</var> pairs of slimes before combination.</li>
</ul>
<p>Snuke wants to get to the situation where there are exactly <var>N</var> slimes, and the size of the <var>i</var>-th (<var>1 β€ i β€ N</var>) slime from the left is <var>a_i</var>.
Find the minimum number of operations required to achieve his goal.</p>
<p>Note that <var>A</var> is not directly given as input. Assume <var>A = a_1 + a_2 + ... + a_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ N β€ 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 β€ a_i β€ 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve Snuke's goal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One way to achieve Snuke's goal is as follows.
Here, the selected slimes are marked in bold.</p>
<ul>
<li>(1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, 1) β (1, <strong>2</strong>, <strong>2</strong>, 1)</li>
<li>(<strong>1</strong>, <strong>2</strong>, <strong>2</strong>, <strong>1</strong>) β (<strong>3</strong>, <strong>3</strong>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2 1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>One way to achieve Snuke's goal is as follows.</p>
<ul>
<li>(<strong>1</strong>, <strong>1</strong>, 1, 1, 1, 1, 1) β (<strong>2</strong>, 1, 1, 1, 1, 1)</li>
<li>(2, 1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>) β (2, 1, <strong>2</strong>, <strong>2</strong>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
3 1 4 1 5 9 2 6 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
</pre></section>
</div>
</span> | [
[
"2\n3 3\n",
"2\n3 3\n"
]
] |
p03597 | AtCoder Beginner Contest 074 - Bichrome Cells | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>N \times N</var> square grid.</p>
<p>We will paint each square in the grid either black or white.</p>
<p>If we paint exactly <var>A</var> squares white, how many squares will be painted black?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq A \leq N^2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of squares that will be painted black.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are nine squares in a <var>3 \times 3</var> square grid.
Four of them will be painted white, so the remaining five squares will be painted black.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>19
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>261
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre>
<p>As zero squares will be painted white, all the squares will be painted black.</p></section>
</div>
</span> | [
[
"3\n4\n",
"3\n4\n"
]
] |
p03598 | AtCoder Beginner Contest 074 - Collecting Balls (Easy Version) | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> balls in the <var>xy</var>-plane. The coordinates of the <var>i</var>-th of them is <var>(x_i, i)</var>.
Thus, we have one ball on each of the <var>N</var> lines <var>y = 1</var>, <var>y = 2</var>, <var>...</var>, <var>y = N</var>.</p>
<p>In order to collect these balls, Snuke prepared <var>2N</var> robots, <var>N</var> of type A and <var>N</var> of type B.
Then, he placed the <var>i</var>-th type-A robot at coordinates <var>(0, i)</var>, and the <var>i</var>-th type-B robot at coordinates <var>(K, i)</var>.
Thus, now we have one type-A robot and one type-B robot on each of the <var>N</var> lines <var>y = 1</var>, <var>y = 2</var>, <var>...</var>, <var>y = N</var>.</p>
<p>When activated, each type of robot will operate as follows.</p>
<ul>
<li>
<p>When a type-A robot is activated at coordinates <var>(0, a)</var>, it will move to the position of the ball on the line <var>y = a</var>, collect the ball, move back to its original position <var>(0, a)</var> and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
<li>
<p>When a type-B robot is activated at coordinates <var>(K, b)</var>, it will move to the position of the ball on the line <var>y = b</var>, collect the ball, move back to its original position <var>(K, b)</var> and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
</ul>
<p>Snuke will activate some of the <var>2N</var> robots to collect all of the balls. Find the minimum possible total distance covered by robots.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq K \leq 100</var></li>
<li><var>0 < x_i < K</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>K</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the minimum possible total distance covered by robots.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
10
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are just one ball, one type-A robot and one type-B robot.</p>
<p>If the type-A robot is used to collect the ball, the distance from the robot to the ball is <var>2</var>, and the distance from the ball to the original position of the robot is also <var>2</var>, for a total distance of <var>4</var>.</p>
<p>Similarly, if the type-B robot is used, the total distance covered will be <var>16</var>.</p>
<p>Thus, the total distance covered will be minimized when the type-A robot is used. The output should be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
9
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre>
<p>The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
20
11 12 9 17 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>74
</pre></section>
</div>
</span> | [
[
"1\n10\n2\n",
"1\n10\n2\n"
]
] |
p03599 | AtCoder Beginner Contest 074 - Sugar Water | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p>
<ul>
<li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li>
<li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li>
<li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li>
<li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li>
</ul>
<p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p>
<p>Snuke will make sugar water with the highest possible density.</p>
<p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.</p>
<p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent.
Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B \leq 30</var></li>
<li><var>1 \leq C < D \leq 30</var></li>
<li><var>1 \leq E \leq 100</var></li>
<li><var>100A \leq F \leq 3</var> <var>000</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 10 20 15 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110 10
</pre>
<p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p>
<p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:</p>
<ul>
<li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li>
<li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 1 2 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200 100
</pre>
<p>There are other acceptable outputs, such as:</p>
<pre>400 200
</pre>
<p>However, the output below is not acceptable:</p>
<pre>300 150
</pre>
<p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>17 19 22 26 55 2802
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2634 934
</pre></section>
</div>
</span> | [
[
"1 2 10 20 15 200\n",
"1 2 10 20 15 200\n"
]
] |
p03600 | AtCoder Beginner Contest 074 - Restoring Road Network | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li>
<li>Different roads may have had different lengths, but all the lengths were positive integers.</li>
</ul>
<p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p>
<p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>.
If such a network exist, find the shortest possible total length of the roads.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li>If <var>i β j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li>
<li><var>A_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>...</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>.
If it exists, print the shortest possible total length of the roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 3
1 0 2
3 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The network below satisfies the condition:</p>
<ul>
<li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li>
<li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li>
<li>City <var>3</var> and City <var>1</var> is not connected by a road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 3
1 0 1
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>.
However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p>
<p>Thus, we conclude that there exists no network that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3000000000
</pre></section>
</div>
</span> | [
[
"3\n0 1 3\n1 0 2\n3 2 0\n",
"3\n0 1 3\n1 0 2\n3 2 0\n"
]
] |
p03601 | AtCoder Regular Contest 083 - Sugar Water | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p>
<ul>
<li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li>
<li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li>
<li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li>
<li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li>
</ul>
<p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p>
<p>Snuke will make sugar water with the highest possible density.</p>
<p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.</p>
<p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent.
Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B \leq 30</var></li>
<li><var>1 \leq C < D \leq 30</var></li>
<li><var>1 \leq E \leq 100</var></li>
<li><var>100A \leq F \leq 3</var> <var>000</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 10 20 15 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110 10
</pre>
<p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p>
<p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:</p>
<ul>
<li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li>
<li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 1 2 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200 100
</pre>
<p>There are other acceptable outputs, such as:</p>
<pre>400 200
</pre>
<p>However, the output below is not acceptable:</p>
<pre>300 150
</pre>
<p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>17 19 22 26 55 2802
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2634 934
</pre></section>
</div>
</span> | [
[
"1 2 10 20 15 200\n",
"1 2 10 20 15 200\n"
]
] |
p03602 | AtCoder Regular Contest 083 - Restoring Road Network | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li>
<li>Different roads may have had different lengths, but all the lengths were positive integers.</li>
</ul>
<p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p>
<p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>.
If such a network exist, find the shortest possible total length of the roads.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li>If <var>i β j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li>
<li><var>A_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>...</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>.
If it exists, print the shortest possible total length of the roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 3
1 0 2
3 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The network below satisfies the condition:</p>
<ul>
<li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li>
<li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li>
<li>City <var>3</var> and City <var>1</var> is not connected by a road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 3
1 0 1
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>.
However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p>
<p>Thus, we conclude that there exists no network that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3000000000
</pre></section>
</div>
</span> | [
[
"3\n0 1 3\n1 0 2\n3 2 0\n",
"3\n0 1 3\n1 0 2\n3 2 0\n"
]
] |
p03603 | AtCoder Regular Contest 083 - Bichrome Tree | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices. Vertex <var>1</var> is the root of the tree, and the parent of Vertex <var>i</var> (<var>2 \leq i \leq N</var>) is Vertex <var>P_i</var>.</p>
<p>To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.</p>
<p>Snuke has a favorite integer sequence, <var>X_1, X_2, ..., X_N</var>, so he wants to allocate colors and weights so that the following condition is satisfied for all <var>v</var>.</p>
<ul>
<li>The total weight of the vertices with the same color as <var>v</var> among the vertices contained in the subtree whose root is <var>v</var>, is <var>X_v</var>.</li>
</ul>
<p>Here, <em>the subtree whose root is</em> <var>v</var> is the tree consisting of Vertex <var>v</var> and all of its descendants.</p>
<p>Determine whether it is possible to allocate colors and weights in this way.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1</var> <var>000</var></li>
<li><var>1 \leq P_i \leq i - 1</var></li>
<li><var>0 \leq X_i \leq 5</var> <var>000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>P_2</var> <var>P_3</var> <var>...</var> <var>P_N</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1
4 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
<p>For example, the following allocation satisfies the condition:</p>
<ul>
<li>Set the color of Vertex <var>1</var> to white and its weight to <var>2</var>.</li>
<li>Set the color of Vertex <var>2</var> to black and its weight to <var>3</var>.</li>
<li>Set the color of Vertex <var>3</var> to white and its weight to <var>2</var>.</li>
</ul>
<p>There are also other possible allocations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>If the same color is allocated to Vertex <var>2</var> and Vertex <var>3</var>, Vertex <var>2</var> cannot be allocated a non-negative weight.</p>
<p>If different colors are allocated to Vertex <var>2</var> and <var>3</var>, no matter which color is allocated to Vertex <var>1</var>, it cannot be allocated a non-negative weight.</p>
<p>Thus, there exists no allocation of colors and weights that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
1 1 1 3 4 5 5
4 1 6 2 2 1 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>POSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>POSSIBLE
</pre></section>
</div>
</span> | [
[
"3\n1 1\n4 3 2\n",
"3\n1 1\n4 3 2\n"
]
] |
p03604 | AtCoder Regular Contest 083 - Collecting Balls | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> balls in the <var>xy</var>-plane. The coordinates of the <var>i</var>-th of them is <var>(x_i, y_i)</var>.
Here, <var>x_i</var> and <var>y_i</var> are integers between <var>1</var> and <var>N</var> (inclusive) for all <var>i</var>, and no two balls occupy the same coordinates.</p>
<p>In order to collect these balls, Snuke prepared <var>2N</var> robots, <var>N</var> of type A and <var>N</var> of type B.
Then, he placed the type-A robots at coordinates <var>(1, 0), (2, 0), ..., (N, 0)</var>, and the type-B robots at coordinates <var>(0, 1), (0, 2), ..., (0, N)</var>, one at each position.</p>
<p>When activated, each type of robot will operate as follows.</p>
<ul>
<li>
<p>When a type-A robot is activated at coordinates <var>(a, 0)</var>, it will move to the position of the ball with the lowest <var>y</var>-coordinate among the balls on the line <var>x = a</var>, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
<li>
<p>When a type-B robot is activated at coordinates <var>(0, b)</var>, it will move to the position of the ball with the lowest <var>x</var>-coordinate among the balls on the line <var>y = b</var>, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
</ul>
<p>Once deactivated, a robot cannot be activated again. Also, while a robot is operating, no new robot can be activated until the operating robot is deactivated.</p>
<p>When Snuke was about to activate a robot, he noticed that he may fail to collect all the balls, depending on the order of activating the robots.</p>
<p>Among the <var>(2N)!</var> possible orders of activating the robots, find the number of the ones such that all the balls can be collected, modulo <var>1</var> <var>000</var> <var>000</var> <var>007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq x_i \leq N</var></li>
<li><var>1 \leq y_i \leq N</var></li>
<li>If <var>i β j</var>, either <var>x_i β x_j</var> or <var>y_i β y_j</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>...</var>
<var>x_{2N}</var> <var>y_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of the orders of activating the robots such that all the balls can be collected, modulo <var>1</var> <var>000</var> <var>000</var> <var>007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 1
1 2
2 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>We will refer to the robots placed at <var>(1, 0)</var> and <var>(2, 0)</var> as A1 and A2, respectively, and the robots placed at <var>(0, 1)</var> and <var>(0, 2)</var> as B1 and B2, respectively.
There are eight orders of activation that satisfy the condition, as follows:</p>
<ul>
<li>A1, B1, A2, B2</li>
<li>A1, B1, B2, A2</li>
<li>A1, B2, B1, A2</li>
<li>A2, B1, A1, B2</li>
<li>B1, A1, B2, A2</li>
<li>B1, A1, A2, B2</li>
<li>B1, A2, A1, B2</li>
<li>B2, A1, B1, A2</li>
</ul>
<p>Thus, the output should be <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
3 2
1 2
4 1
4 2
2 2
4 4
2 1
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7392
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 1
2 2
3 3
4 4
1 2
2 1
3 4
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4480
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
6 2
5 1
6 8
7 8
6 5
5 7
4 3
1 4
7 6
8 3
2 8
3 6
3 2
8 5
1 5
5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>82060779
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>3
1 1
1 2
1 3
2 1
2 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>0
</pre>
<p>When there is no order of activation that satisfies the condition, the output should be <var>0</var>.</p></section>
</div>
</span> | [
[
"2\n1 1\n1 2\n2 1\n2 2\n",
"2\n1 1\n1 2\n2 1\n2 2\n"
]
] |
p03605 | AtCoder Beginner Contest 073 - September 9 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is September <var>9</var> in Japan now.</p>
<p>You are given a two-digit integer <var>N</var>. Answer the question: Is <var>9</var> contained in the decimal notation of <var>N</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>10β€Nβ€99</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>9</var> is contained in the decimal notation of <var>N</var>, print <code>Yes</code>; if not, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>29
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The one's digit of <var>29</var> is <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>72
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>72</var> does not contain <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>91
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> | [
[
"29\n",
"29\n"
]
] |
p03606 | AtCoder Beginner Contest 073 - Theater | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is working as a receptionist at a theater.</p>
<p>The theater has <var>100000</var> seats, numbered from <var>1</var> to <var>100000</var>.</p>
<p>According to her memo, <var>N</var> groups of audiences have come so far, and the <var>i</var>-th group occupies the consecutive seats from Seat <var>l_i</var> to Seat <var>r_i</var> (inclusive).</p>
<p>How many people are sitting at the theater now?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€1000</var></li>
<li><var>1β€l_iβ€r_iβ€100000</var></li>
<li>No seat is occupied by more than one person.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>l_1</var> <var>r_1</var>
<var>:</var>
<var>l_N</var> <var>r_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of people sitting at the theater.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
24 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>There are <var>7</var> people, sitting at Seat <var>24,25,26,27,28,29</var> and <var>30</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
6 8
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre></section>
</div>
</span> | [
[
"1\n24 30\n",
"1\n24 30\n"
]
] |
p03607 | AtCoder Beginner Contest 073 - Write and Erase | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are playing the following game with Joisino.</p>
<ul>
<li>Initially, you have a blank sheet of paper.</li>
<li>Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated <var>N</var> times.</li>
<li>Then, you are asked a question: How many numbers are written on the sheet now?</li>
</ul>
<p>The numbers announced by Joisino are given as <var>A_1, ... ,A_N</var> in the order she announces them. How many numbers will be written on the sheet at the end of the game?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€100000</var></li>
<li><var>1β€A_iβ€1000000000(=10^9)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print how many numbers will be written on the sheet at the end of the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
6
2
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The game proceeds as follows:</p>
<ul>
<li>
<p><var>6</var> is not written on the sheet, so write <var>6</var>.</p>
</li>
<li>
<p><var>2</var> is not written on the sheet, so write <var>2</var>.</p>
</li>
<li>
<p><var>6</var> is written on the sheet, so erase <var>6</var>.</p>
</li>
</ul>
<p>Thus, the sheet contains only <var>2</var> in the end. The answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2
5
5
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It is possible that no number is written on the sheet in the end.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
12
22
16
22
18
12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> | [
[
"3\n6\n2\n6\n",
"3\n6\n2\n6\n"
]
] |
p03608 | AtCoder Beginner Contest 073 - joisino's travel | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns in the State of Atcoder, connected by <var>M</var> bidirectional roads.</p>
<p>The <var>i</var>-th road connects Town <var>A_i</var> and <var>B_i</var> and has a length of <var>C_i</var>.</p>
<p>Joisino is visiting <var>R</var> towns in the state, <var>r_1,r_2,..,r_R</var> (not necessarily in this order).</p>
<p>She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.</p>
<p>If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2β€Nβ€200</var></li>
<li><var>1β€Mβ€NΓ(N-1)/2</var></li>
<li><var>2β€Rβ€min(8,N)</var> (<var>min(8,N)</var> is the smaller of <var>8</var> and <var>N</var>.)</li>
<li><var>r_iβ r_j (iβ j)</var></li>
<li><var>1β€A_i,B_iβ€N, A_iβ B_i</var></li>
<li><var>(A_i,B_i)β (A_j,B_j),(A_i,B_i)β (B_j,A_j) (iβ j)</var></li>
<li><var>1β€C_iβ€100000</var></li>
<li>Every town can be reached from every town by road.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>R</var>
<var>r_1</var> <var>...</var> <var>r_R</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var> <var>C_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 3
1 2 3
1 2 1
2 3 1
3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, if she visits the towns in the order of <var>1</var>, <var>2</var>, <var>3</var>, the distance traveled will be <var>2</var>, which is the minimum possible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
1 3
2 3 2
1 3 6
1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>The shortest distance between Towns <var>1</var> and <var>3</var> is <var>4</var>. Thus, whether she visits Town <var>1</var> or <var>3</var> first, the distance traveled will be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> | [
[
"3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n",
"3 3 3\n1 2 3\n1 2 1\n2 3 1\n3 1 4\n"
]
] |
p03609 | AtCoder Beginner Contest 072 - Sandglass2 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sandglass that runs for <var>X</var> seconds. The sand drops from the upper bulb at a rate of <var>1</var> gram per second. That is, the upper bulb initially contains <var>X</var> grams of sand.</p>
<p>How many grams of sand will the upper bulb contains after <var>t</var> seconds?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Xβ€10^9</var></li>
<li><var>1β€tβ€10^9</var></li>
<li><var>X</var> and <var>t</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>t</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of sand in the upper bulb after <var>t</var> second.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>100 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>83
</pre>
<p><var>17</var> out of the initial <var>100</var> grams of sand will be consumed, resulting in <var>83</var> grams.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>48 58
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>All <var>48</var> grams of sand will be gone, resulting in <var>0</var> grams.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> | [
[
"100 17\n",
"100 17\n"
]
] |
p03610 | AtCoder Beginner Contest 072 - OddString | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>s</var> consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Each character in <var>s</var> is a lowercase English letter.</li>
<li><var>1β€|s|β€10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string obtained by concatenating all the characters in the odd-numbered positions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>acdr
</pre>
<p>Extract the first character <code>a</code>, the third character <code>c</code>, the fifth character <code>d</code> and the seventh character <code>r</code> to obtain <code>acdr</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aa
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>z
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>fukuokayamaguchi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>fkoaaauh
</pre></section>
</div>
</span> | [
[
"atcoder\n",
"atcoder\n"
]
] |
p03611 | AtCoder Beginner Contest 072 - Together | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>, <var>a_1,a_2,...,a_N</var>.</p>
<p>For each <var>1β€iβ€N</var>, you have three choices: add <var>1</var> to <var>a_i</var>, subtract <var>1</var> from <var>a_i</var> or do nothing.</p>
<p>After these operations, you select an integer <var>X</var> and count the number of <var>i</var> such that <var>a_i=X</var>.</p>
<p>Maximize this count by making optimal choices.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€10^5</var></li>
<li><var>0β€a_i<10^5 (1β€iβ€N)</var></li>
<li><var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> .. <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of <var>i</var> such that <var>a_i=X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
3 1 4 1 5 9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, turn the sequence into <var>2,2,3,2,6,9,2</var> and select <var>X=2</var> to obtain <var>4</var>, the maximum possible count.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
0 1 2 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> | [
[
"7\n3 1 4 1 5 9 2\n",
"7\n3 1 4 1 5 9 2\n"
]
] |
p03612 | AtCoder Beginner Contest 072 - Derangement | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a permutation <var>p_1,p_2,...,p_N</var> consisting of <var>1</var>,<var>2</var>,..,<var>N</var>.
You can perform the following operation any number of times (possibly zero):</p>
<p>Operation: Swap two <strong>adjacent</strong> elements in the permutation.</p>
<p>You want to have <var>p_i β i</var> for all <var>1β€iβ€N</var>.
Find the minimum required number of operations to achieve this.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2β€Nβ€10^5</var></li>
<li><var>p_1,p_2,..,p_N</var> is a permutation of <var>1,2,..,N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> .. <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required number of operations</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 4 3 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Swap <var>1</var> and <var>4</var>, then swap <var>1</var> and <var>3</var>. <var>p</var> is now <var>4,3,1,5,2</var> and satisfies the condition.
This is the minimum possible number, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Swapping <var>1</var> and <var>2</var> satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
1 2 4 9 5 8 7 3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre></section>
</div>
</span> | [
[
"5\n1 4 3 5 2\n",
"5\n1 4 3 5 2\n"
]
] |
p03613 | AtCoder Regular Contest 082 - Together | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>, <var>a_1,a_2,...,a_N</var>.</p>
<p>For each <var>1β€iβ€N</var>, you have three choices: add <var>1</var> to <var>a_i</var>, subtract <var>1</var> from <var>a_i</var> or do nothing.</p>
<p>After these operations, you select an integer <var>X</var> and count the number of <var>i</var> such that <var>a_i=X</var>.</p>
<p>Maximize this count by making optimal choices.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€10^5</var></li>
<li><var>0β€a_i<10^5 (1β€iβ€N)</var></li>
<li><var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> .. <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of <var>i</var> such that <var>a_i=X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
3 1 4 1 5 9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, turn the sequence into <var>2,2,3,2,6,9,2</var> and select <var>X=2</var> to obtain <var>4</var>, the maximum possible count.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
0 1 2 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> | [
[
"7\n3 1 4 1 5 9 2\n",
"7\n3 1 4 1 5 9 2\n"
]
] |
p03614 | AtCoder Regular Contest 082 - Derangement | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a permutation <var>p_1,p_2,...,p_N</var> consisting of <var>1</var>,<var>2</var>,..,<var>N</var>.
You can perform the following operation any number of times (possibly zero):</p>
<p>Operation: Swap two <strong>adjacent</strong> elements in the permutation.</p>
<p>You want to have <var>p_i β i</var> for all <var>1β€iβ€N</var>.
Find the minimum required number of operations to achieve this.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2β€Nβ€10^5</var></li>
<li><var>p_1,p_2,..,p_N</var> is a permutation of <var>1,2,..,N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> .. <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required number of operations</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 4 3 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Swap <var>1</var> and <var>4</var>, then swap <var>1</var> and <var>3</var>. <var>p</var> is now <var>4,3,1,5,2</var> and satisfies the condition.
This is the minimum possible number, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Swapping <var>1</var> and <var>2</var> satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
1 2 4 9 5 8 7 3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre></section>
</div>
</span> | [
[
"5\n1 4 3 5 2\n",
"5\n1 4 3 5 2\n"
]
] |
p03615 | AtCoder Regular Contest 082 - ConvexScore | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> points <var>(x_i,y_i)</var> located on a two-dimensional plane.
Consider a subset <var>S</var> of the <var>N</var> points that forms a convex polygon.
Here, we say a set of points <var>S</var> <em>forms a convex polygon</em> when there exists a convex polygon with a positive area that has the same set of vertices as <var>S</var>. All the interior angles of the polygon must be strictly less than <var>180Β°</var>.</p>
<div style="text-align: center;">
<img alt="cddb0c267926c2add885ca153c47ad8a.png" src="https://atcoder.jp/img/arc082/cddb0c267926c2add885ca153c47ad8a.png">
</img></div>
<p>For example, in the figure above, {<var>A,C,E</var>} and {<var>B,D,E</var>} form convex polygons; {<var>A,C,D,E</var>}, {<var>A,B,C,E</var>}, {<var>A,B,C</var>}, {<var>D,E</var>} and {} do not.</p>
<p>For a given set <var>S</var>, let <var>n</var> be the number of the points among the <var>N</var> points that are inside the convex hull of <var>S</var> (including the boundary and vertices). Then, we will define the <em>score</em> of <var>S</var> as <var>2^{n-|S|}</var>.</p>
<p>Compute the scores of all possible sets <var>S</var> that form convex polygons, and find the sum of all those scores.</p>
<p>However, since the sum can be extremely large, print the sum modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€200</var></li>
<li><var>0β€x_i,y_i<10^4 (1β€iβ€N)</var></li>
<li>If <var>iβ j</var>, <var>x_iβ x_j</var> or <var>y_iβ y_j</var>.</li>
<li><var>x_i</var> and <var>y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of all the scores modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
0 0
0 1
1 0
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>We have five possible sets as <var>S</var>, four sets that form triangles and one set that forms a square. Each of them has a score of <var>2^0=1</var>, so the answer is <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0
0 1
0 2
0 3
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>We have three "triangles" with a score of <var>1</var> each, two "triangles" with a score of <var>2</var> each, and one "triangle" with a score of <var>4</var>. Thus, the answer is <var>11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
3141 2718
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>There are no possible set as <var>S</var>, so the answer is <var>0</var>.</p></section>
</div>
</span> | [
[
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n0 0\n0 1\n1 0\n1 1\n"
]
] |
p03616 | AtCoder Regular Contest 082 - Sandglass | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand.
When we put the sandglass, either bulb <var>A</var> or <var>B</var> lies on top of the other and becomes the <em>upper bulb</em>. The other bulb becomes the <em>lower bulb</em>.</p>
<p>The sand drops from the upper bulb to the lower bulb at a rate of <var>1</var> gram per second.
When the upper bulb no longer contains any sand, nothing happens.</p>
<p>Initially at time <var>0</var>, bulb A is the upper bulb and contains <var>a</var> grams of sand; bulb B contains <var>X-a</var> grams of sand (for a total of <var>X</var> grams).</p>
<p>We will turn over the sandglass at time <var>r_1,r_2,..,r_K</var>. Assume that this is an instantaneous action and takes no time. Here, time <var>t</var> refer to the time <var>t</var> seconds after time <var>0</var>.</p>
<p>You are given <var>Q</var> queries.
Each query is in the form of <var>(t_i,a_i)</var>.
For each query, assume that <var>a=a_i</var> and find the amount of sand that would be contained in bulb A at time <var>t_i</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Xβ€10^9</var></li>
<li><var>1β€Kβ€10^5</var></li>
<li><var>1β€r_1<r_2< .. <r_Kβ€10^9</var></li>
<li><var>1β€Qβ€10^5</var></li>
<li><var>0β€t_1<t_2< .. <t_Qβ€10^9</var></li>
<li><var>0β€a_iβ€X (1β€iβ€Q)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>X</var>
<var>K</var>
<var>r_1</var> <var>r_2</var> .. <var>r_K</var>
<var>Q</var>
<var>t_1</var> <var>a_1</var>
<var>t_2</var> <var>a_2</var>
<var>:</var>
<var>t_Q</var> <var>a_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each query, print the answer in its own line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>180
3
60 120 180
3
30 90
61 1
180 180
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>60
1
120
</pre>
<p>In the first query, <var>30</var> out of the initial <var>90</var> grams of sand will drop from bulb A, resulting in <var>60</var> grams.
In the second query, the initial <var>1</var> gram of sand will drop from bulb A, and nothing will happen for the next <var>59</var> seconds. Then, we will turn over the sandglass, and <var>1</var> second after this, bulb <var>A</var> contains <var>1</var> gram of sand at the time in question.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100
1
100000
4
0 100
90 100
100 100
101 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
10
0
0
</pre>
<p>In every query, the upper bulb initially contains <var>100</var> grams, and the question in time comes before we turn over the sandglass.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>19
52
91
10
58
42
100
</pre></section>
</div>
</span> | [
[
"180\n3\n60 120 180\n3\n30 90\n61 1\n180 180\n",
"180\n3\n60 120 180\n3\n30 90\n61 1\n180 180\n"
]
] |
p03617 | AtCoder Grand Contest 019 - Ice Tea Store | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You've come to your favorite store Infinitesco to buy some ice tea.</p>
<p>The store sells ice tea in bottles of different volumes at different costs.
Specifically, a <var>0.25</var>-liter bottle costs <var>Q</var> yen, a <var>0.5</var>-liter bottle costs <var>H</var> yen, a <var>1</var>-liter bottle costs <var>S</var> yen, and a <var>2</var>-liter bottle costs <var>D</var> yen.
The store has an infinite supply of bottles of each type.</p>
<p>You want to buy exactly <var>N</var> liters of ice tea. How many yen do you have to spend?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq Q, H, S, D \leq 10^8</var></li>
<li><var>1 \leq N \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var> <var>H</var> <var>S</var> <var>D</var>
<var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest number of yen you have to spend to buy exactly <var>N</var> liters of ice tea.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>20 30 70 90
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>150
</pre>
<p>Buy one <var>2</var>-liter bottle and two <var>0.5</var>-liter bottles. You'll get <var>3</var> liters for <var>90 + 30 + 30 = 150</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10000 1000 100 10
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>Even though a <var>2</var>-liter bottle costs just <var>10</var> yen, you need only <var>1</var> liter.
Thus, you have to buy a <var>1</var>-liter bottle for <var>100</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 100 1000 10000
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>40
</pre>
<p>Now it's better to buy four <var>0.25</var>-liter bottles for <var>10 + 10 + 10 + 10 = 40</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>12345678 87654321 12345678 87654321
123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1524157763907942
</pre></section>
</div>
</span> | [
[
"20 30 70 90\n3\n",
"20 30 70 90\n3\n"
]
] |
p03618 | AtCoder Grand Contest 019 - Reverse and Compare | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have a string <var>A = A_1 A_2 ... A_n</var> consisting of lowercase English letters.</p>
<p>You can choose any two indices <var>i</var> and <var>j</var> such that <var>1 \leq i \leq j \leq n</var> and reverse substring <var>A_i A_{i+1} ... A_j</var>.</p>
<p>You can perform this operation at most once.</p>
<p>How many different strings can you obtain?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |A| \leq 200,000</var></li>
<li><var>A</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different strings you can obtain by reversing any substring in <var>A</var> at most once.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aatt
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>You can obtain <code>aatt</code> (don't do anything), <code>atat</code> (reverse <var>A[2..3]</var>), <code>atta</code> (reverse <var>A[2..4]</var>), <code>ttaa</code> (reverse <var>A[1..4]</var>) and <code>taat</code> (reverse <var>A[1..3]</var>).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>xxxxxxxxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Whatever substring you reverse, you'll always get <code>xxxxxxxxxx</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abracadabra
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>44
</pre></section>
</div>
</span> | [
[
"aatt\n",
"aatt\n"
]
] |
p03619 | AtCoder Grand Contest 019 - Fountain Walk | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the city of Nevermore, there are <var>10^8</var> streets and <var>10^8</var> avenues, both numbered from <var>0</var> to <var>10^8-1</var>.
All streets run straight from west to east, and all avenues run straight from south to north.
The distance between neighboring streets and between neighboring avenues is exactly <var>100</var> meters.</p>
<p>Every street intersects every avenue. Every intersection can be described by pair <var>(x, y)</var>, where <var>x</var> is avenue ID and <var>y</var> is street ID.</p>
<p>There are <var>N</var> fountains in the city, situated at intersections <var>(X_i, Y_i)</var>.
Unlike normal intersections, there's a circle with radius <var>10</var> meters centered at the intersection, and there are no road parts inside this circle.</p>
<p>The picture below shows an example of how a part of the city with roads and fountains may look like.</p>
<div style="text-align: center;">
<img alt="1f931bf0c98ec6f07e612b0282cdb094.png" src="https://img.atcoder.jp/agc019/1f931bf0c98ec6f07e612b0282cdb094.png">
</img></div>
<p>City governors don't like encountering more than one fountain while moving along the same road.
Therefore, every street contains at most one fountain on it, as well as every avenue.</p>
<p>Citizens can move along streets, avenues and fountain perimeters.
What is the shortest distance one needs to cover in order to get from intersection <var>(x_1, y_1)</var> to intersection <var>(x_2, y_2)</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq x_1, y_1, x_2, y_2 < 10^8</var></li>
<li><var>1 \leq N \leq 200,000</var></li>
<li><var>0 \leq X_i, Y_i < 10^8</var></li>
<li><var>X_i \neq X_j</var> for <var>i \neq j</var></li>
<li><var>Y_i \neq Y_j</var> for <var>i \neq j</var></li>
<li>Intersections <var>(x_1, y_1)</var> and <var>(x_2, y_2)</var> are different and don't contain fountains.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var>
<var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the shortest possible distance one needs to cover in order to get from intersection <var>(x_1, y_1)</var> to intersection <var>(x_2, y_2)</var>, in meters.
Your answer will be considered correct if its absolute or relative error doesn't exceed <var>10^{-11}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 6 5
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>891.415926535897938
</pre>
<p>One possible shortest path is shown on the picture below. The path starts at the blue point, finishes at the purple point and follows along the red line.</p>
<div style="text-align: center;">
<img alt="c49e52b9b79003f61b8a6efa5dad8ba3.png" src="https://img.atcoder.jp/agc019/c49e52b9b79003f61b8a6efa5dad8ba3.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5 6 4
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>400.000000000000000
</pre>
<div style="text-align: center;">
<img alt="f9090ab734c89424c413f3b583376990.png" src="https://img.atcoder.jp/agc019/f9090ab734c89424c413f3b583376990.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2 2 2
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>211.415926535897938
</pre>
<div style="text-align: center;">
<img alt="4b76416161f27cad20333a9ac636e00f.png" src="https://img.atcoder.jp/agc019/4b76416161f27cad20333a9ac636e00f.png"/>
</div></section>
</div>
</span> | [
[
"1 1 6 5\n3\n3 2\n5 3\n2 4\n",
"1 1 6 5\n3\n3 2\n5 3\n2 4\n"
]
] |
p03620 | AtCoder Grand Contest 019 - Shift and Flip | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have two strings <var>A = A_1 A_2 ... A_n</var> and <var>B = B_1 B_2 ... B_n</var> of the same length consisting of <var>0</var> and <var>1</var>.</p>
<p>You can transform <var>A</var> using the following operations in any order and as many times as you want:</p>
<ul>
<li>Shift <var>A</var> by one character to the left (i.e., if <var>A = A_1 A_2 ... A_n</var>, replace <var>A</var> with <var>A_2 A_3 ... A_n A_1</var>).</li>
<li>Shift <var>A</var> by one character to the right (i.e., if <var>A = A_1 A_2 ... A_n</var>, replace <var>A</var> with <var>A_n A_1 A_2 ... A_{n-1}</var>).</li>
<li>Choose any <var>i</var> such that <var>B_i = 1</var>. Flip <var>A_i</var> (i.e., set <var>A_i = 1 - A_i</var>).</li>
</ul>
<p>You goal is to make strings <var>A</var> and <var>B</var> equal.</p>
<p>Print the smallest number of operations required to achieve this, or <var>-1</var> if the goal is unreachable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |A| = |B| \leq 2,000</var></li>
<li><var>A</var> and <var>B</var> consist of <var>0</var> and <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var>
<var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest number of operations required to make strings <var>A</var> and <var>B</var> equal, or <var>-1</var> if the goal is unreachable.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1010
1100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Here is one fastest way to achieve the goal:</p>
<ul>
<li>Flip <var>A_1</var>: <var>A = 0010</var></li>
<li>Shift <var>A</var> to the left: <var>A = 0100</var></li>
<li>Flip <var>A_1</var> again: <var>A = 1100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>There is no way to flip the only bit in <var>A</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11010
10001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>Here is one fastest way to achieve the goal:</p>
<ul>
<li>Shift <var>A</var> to the right: <var>A = 01101</var></li>
<li>Flip <var>A_5</var>: <var>A = 01100</var></li>
<li>Shift <var>A</var> to the left: <var>A = 11000</var></li>
<li>Shift <var>A</var> to the left again: <var>A = 10001</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>0100100
1111111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
<p>Flip <var>A_1</var>, <var>A_3</var>, <var>A_4</var>, <var>A_6</var> and <var>A_7</var> in any order.</p></section>
</div>
</span> | [
[
"1010\n1100\n",
"1010\n1100\n"
]
] |
p03621 | AtCoder Grand Contest 019 - Shuffle and Swap | <span class="lang-en">
<p>Score : <var>1700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have two strings <var>A = A_1 A_2 ... A_n</var> and <var>B = B_1 B_2 ... B_n</var> of the same length consisting of <var>0</var> and <var>1</var>.
The number of <var>1</var>'s in <var>A</var> and <var>B</var> is equal.</p>
<p>You've decided to transform <var>A</var> using the following algorithm:</p>
<ul>
<li>Let <var>a_1</var>, <var>a_2</var>, ..., <var>a_k</var> be the indices of <var>1</var>'s in <var>A</var>.</li>
<li>Let <var>b_1</var>, <var>b_2</var>, ..., <var>b_k</var> be the indices of <var>1</var>'s in <var>B</var>.</li>
<li>Replace <var>a</var> and <var>b</var> with their random permutations, chosen independently and uniformly.</li>
<li>For each <var>i</var> from <var>1</var> to <var>k</var>, in order, swap <var>A_{a_i}</var> and <var>A_{b_i}</var>.</li>
</ul>
<p>Let <var>P</var> be the probability that strings <var>A</var> and <var>B</var> become equal after the procedure above.</p>
<p>Let <var>Z = P \times (k!)^2</var>. Clearly, <var>Z</var> is an integer.</p>
<p>Find <var>Z</var> modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |A| = |B| \leq 10,000</var></li>
<li><var>A</var> and <var>B</var> consist of <var>0</var> and <var>1</var>.</li>
<li><var>A</var> and <var>B</var> contain the same number of <var>1</var>'s.</li>
<li><var>A</var> and <var>B</var> contain at least one <var>1</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>1200</var> points will be awarded for passing the testset satisfying <var>1 \leq |A| = |B| \leq 500</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var>
<var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value of <var>Z</var> modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1010
1100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>After the first two steps, <var>a = [1, 3]</var> and <var>b = [1, 2]</var>. There are <var>4</var> possible scenarios after shuffling <var>a</var> and <var>b</var>:</p>
<ul>
<li><var>a = [1, 3]</var>, <var>b = [1, 2]</var>. Initially, <var>A = 1010</var>. After swap(<var>A_1</var>, <var>A_1</var>), <var>A = 1010</var>. After swap(<var>A_3</var>, <var>A_2</var>), <var>A = 1100</var>.</li>
<li><var>a = [1, 3]</var>, <var>b = [2, 1]</var>. Initially, <var>A = 1010</var>. After swap(<var>A_1</var>, <var>A_2</var>), <var>A = 0110</var>. After swap(<var>A_3</var>, <var>A_1</var>), <var>A = 1100</var>.</li>
<li><var>a = [3, 1]</var>, <var>b = [1, 2]</var>. Initially, <var>A = 1010</var>. After swap(<var>A_3</var>, <var>A_1</var>), <var>A = 1010</var>. After swap(<var>A_1</var>, <var>A_2</var>), <var>A = 0110</var>.</li>
<li><var>a = [3, 1]</var>, <var>b = [2, 1]</var>. Initially, <var>A = 1010</var>. After swap(<var>A_3</var>, <var>A_2</var>), <var>A = 1100</var>. After swap(<var>A_1</var>, <var>A_1</var>), <var>A = 1100</var>.</li>
</ul>
<p>Out of <var>4</var> scenarios, <var>3</var> of them result in <var>A = B</var>. Therefore, <var>P = 3</var> / <var>4</var>, and <var>Z = 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>01001
01001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>No swap ever changes <var>A</var>, so we'll always have <var>A = B</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>101010
010101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36
</pre>
<p>Every possible sequence of three swaps puts the <var>1</var>'s in <var>A</var> into the right places.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1101011011110
0111101011101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>932171449
</pre></section>
</div>
</span> | [
[
"1010\n1100\n",
"1010\n1100\n"
]
] |
p03622 | AtCoder Grand Contest 019 - Yes or No | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are participating in a quiz with <var>N + M</var> questions and Yes/No answers.</p>
<p>It's known in advance that there are <var>N</var> questions with answer Yes and <var>M</var> questions with answer No, but the questions are given to you in random order.</p>
<p>You have no idea about correct answers to any of the questions.
You answer questions one by one, and for each question you answer, you get to know the correct answer immediately after answering.</p>
<p>Suppose you follow a strategy maximizing the expected number of correct answers you give.</p>
<p>Let this expected number be <var>P/Q</var>, an irreducible fraction. Let <var>M = 998244353</var>.
It can be proven that a unique integer <var>R</var> between <var>0</var> and <var>M - 1</var> exists such that <var>P = Q \times R</var> modulo <var>M</var>,
and it is equal to <var>P \times Q^{-1}</var> modulo <var>M</var>, where <var>Q^{-1}</var> is the modular inverse of <var>Q</var>.
Find <var>R</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, M \leq 500,000</var></li>
<li>Both <var>N</var> and <var>M</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>1500</var> points will be awarded for passing the testset satisfying <var>N = M</var> and <var>1 \leq N, M \leq 10^5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let <var>P/Q</var> be the expected number of correct answers you give if you follow an optimal strategy, represented as an irreducible fraction.
Print <var>P \times Q^{-1}</var> modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>499122178
</pre>
<p>There are two questions.
You may answer randomly to the first question, and you'll succeed with 50% probability.
Then, since you know the second answer is different from the first one, you'll succeed with 100% probability.</p>
<p>The expected number of your correct answers is <var>3</var> / <var>2</var>.
Thus, <var>P = 3</var>, <var>Q = 2</var>, <var>Q^{-1} = 499122177</var> (modulo <var>998244353</var>), and <var>P \times Q^{-1} = 499122178</var> (again, modulo <var>998244353</var>).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>831870297
</pre>
<p>The expected number of your correct answers is <var>17</var> / <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>770074220
</pre>
<p>The expected number of your correct answers is <var>169</var> / <var>35</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>208827570
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>42 23
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>362936761
</pre></section>
</div>
</span> | [
[
"1 1\n",
"1 1\n"
]
] |
p03623 | AtCoder Beginner Contest 071 - Meal Delivery | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke lives at position <var>x</var> on a number line.
On this line, there are two stores <var>A</var> and <var>B</var>, respectively at position <var>a</var> and <var>b</var>, that offer food for delivery.</p>
<p>Snuke decided to get food delivery from the closer of stores <var>A</var> and <var>B</var>.
Find out which store is closer to Snuke's residence.</p>
<p>Here, the distance between two points <var>s</var> and <var>t</var> on a number line is represented by <var>|s-t|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq x \leq 1000</var></li>
<li><var>1 \leq a \leq 1000</var></li>
<li><var>1 \leq b \leq 1000</var></li>
<li><var>x, a</var> and <var>b</var> are pairwise distinct.</li>
<li>The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are different.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x</var> <var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If store <var>A</var> is closer, print <code>A</code>; if store <var>B</var> is closer, print <code>B</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>B
</pre>
<p>The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are <var>3</var> and <var>2</var>, respectively.
Since store <var>B</var> is closer, print <code>B</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 999 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>A
</pre></section>
</div>
</span> | [
[
"5 2 7\n",
"5 2 7\n"
]
] |
p03624 | AtCoder Beginner Contest 071 - Not Found | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in <var>S</var>.
If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var> (<var>|S|</var> is the length of string <var>S</var>.)</li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest lowercase English letter that does not occur in <var>S</var>.
If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoderregularcontest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p>The string <code>atcoderregularcontest</code> contains <code>a</code>, but does not contain <code>b</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abcdefghijklmnopqrstuvwxyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>None
</pre>
<p>This string contains every lowercase English letter.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>d
</pre></section>
</div>
</span> | [
[
"atcoderregularcontest\n",
"atcoderregularcontest\n"
]
] |
p03625 | AtCoder Beginner Contest 071 - Make a Rectangle | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> sticks with negligible thickness.
The length of the <var>i</var>-th stick is <var>A_i</var>.</p>
<p>Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible area of the rectangle.
If no rectangle can be formed, print <var>0</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
3 1 2 4 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>1 \times 2</var> rectangle can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No rectangle can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
3 3 3 3 4 4 4 5 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>20
</pre></section>
</div>
</span> | [
[
"6\n3 1 2 4 2 1\n",
"6\n3 1 2 4 2 1\n"
]
] |
p03626 | AtCoder Beginner Contest 071 - Coloring Dominoes | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with a <var>2 \times N</var> grid.
Snuke covered the board with <var>N</var> dominoes without overlaps.
Here, a domino can cover a <var>1 \times 2</var> or <var>2 \times 1</var> square.</p>
<p>Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.</p>
<p>Find the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
<p>The arrangement of the dominoes is given to you as two strings <var>S_1</var> and <var>S_2</var> in the following manner:</p>
<ul>
<li>Each domino is represented by a different English letter (lowercase or uppercase).</li>
<li>The <var>j</var>-th character in <var>S_i</var> represents the domino that occupies the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 52</var></li>
<li><var>|S_1| = |S_2| = N</var></li>
<li><var>S_1</var> and <var>S_2</var> consist of lowercase and uppercase English letters.</li>
<li><var>S_1</var> and <var>S_2</var> represent a valid arrangement of dominoes.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_1</var>
<var>S_2</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
aab
ccb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six ways as shown below:</p>
<p><img alt="" src="https://atcoder.jp/img/arc081/899673bd23529f4fb5e41c6e7d5bc372.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
Z
Z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Note that it is not always necessary to use all the colors.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>958681902
</pre></section>
</div>
</span> | [
[
"3\naab\nccb\n",
"3\naab\nccb\n"
]
] |
p03627 | AtCoder Regular Contest 081 - Make a Rectangle | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> sticks with negligible thickness.
The length of the <var>i</var>-th stick is <var>A_i</var>.</p>
<p>Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible area of the rectangle.
If no rectangle can be formed, print <var>0</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
3 1 2 4 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>1 \times 2</var> rectangle can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No rectangle can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
3 3 3 3 4 4 4 5 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>20
</pre></section>
</div>
</span> | [
[
"6\n3 1 2 4 2 1\n",
"6\n3 1 2 4 2 1\n"
]
] |
p03628 | AtCoder Regular Contest 081 - Coloring Dominoes | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with a <var>2 \times N</var> grid.
Snuke covered the board with <var>N</var> dominoes without overlaps.
Here, a domino can cover a <var>1 \times 2</var> or <var>2 \times 1</var> square.</p>
<p>Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.</p>
<p>Find the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
<p>The arrangement of the dominoes is given to you as two strings <var>S_1</var> and <var>S_2</var> in the following manner:</p>
<ul>
<li>Each domino is represented by a different English letter (lowercase or uppercase).</li>
<li>The <var>j</var>-th character in <var>S_i</var> represents the domino that occupies the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 52</var></li>
<li><var>|S_1| = |S_2| = N</var></li>
<li><var>S_1</var> and <var>S_2</var> consist of lowercase and uppercase English letters.</li>
<li><var>S_1</var> and <var>S_2</var> represent a valid arrangement of dominoes.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_1</var>
<var>S_2</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
aab
ccb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six ways as shown below:</p>
<p><img alt="" src="https://atcoder.jp/img/arc081/899673bd23529f4fb5e41c6e7d5bc372.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
Z
Z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Note that it is not always necessary to use all the colors.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>958681902
</pre></section>
</div>
</span> | [
[
"3\naab\nccb\n",
"3\naab\nccb\n"
]
] |
p03629 | AtCoder Regular Contest 081 - Don't Be a Subsequence | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A subsequence of a string <var>S</var> is a string that can be obtained by deleting zero or more characters from <var>S</var> without changing the order of the remaining characters.
For example, <code>arc</code>, <code>artistic</code> and (an empty string) are all subsequences of <code>artistic</code>; <code>abc</code> and <code>ci</code> are not.</p>
<p>You are given a string <var>A</var> consisting of lowercase English letters.
Find the shortest string among the strings consisting of lowercase English letters that are not subsequences of <var>A</var>.
If there are more than one such string, find the lexicographically smallest one among them.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |A| \leq 2 \times 10^5</var></li>
<li><var>A</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string among the shortest strings consisting of lowercase English letters that are not subsequences of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoderregularcontest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p>The string <code>atcoderregularcontest</code> contains <code>a</code> as a subsequence, but not <code>b</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abcdefghijklmnopqrstuvwxyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aa
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>frqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnjcvtlpnclfkpervxmdbvrbrdn
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>aca
</pre></section>
</div>
</span> | [
[
"atcoderregularcontest\n",
"atcoderregularcontest\n"
]
] |
p03630 | AtCoder Regular Contest 081 - Flip and Rectangles | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with an <var>H \times W</var> grid.
Each square in the grid is painted in black or white. The square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left is black if the <var>j</var>-th character in <var>S_i</var> is <code>#</code>, and white if that character is <code>.</code>.</p>
<p>Snuke can perform the following operation on the grid any number of times:</p>
<ul>
<li>Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).</li>
</ul>
<p>Then, Snuke draws a rectangle along grid lines. Here, all the squares contained in the rectangle must be painted in black.</p>
<p>Find the maximum possible area of Snuke's rectangle when the operation is performed optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq H \leq 2000</var></li>
<li><var>2 \leq W \leq 2000</var></li>
<li><var>|S_i| = W</var></li>
<li><var>S_i</var> consists of <code>#</code> and <code>.</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>S_1</var>
<var>S_2</var>
<var>:</var>
<var>S_H</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible area of Snuke's rectangle.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
..#
##.
.#.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>If the first row from the top and the third column from the left are inverted, a <var>2 \times 3</var> rectangle can be drawn, as shown below:</p>
<p><img alt="" src="https://atcoder.jp/img/arc081/2995c3921ed4dffc8ee528b63b9c6118.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
....
....
....
....
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 8
##...#.#
##...#.#
..###.#.
#.##.#.#
.#..#.#.
..##.#.#
##.#.#..
...#.#..
###.#.##
###..###
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>27
</pre></section>
</div>
</span> | [
[
"3 3\n..#\n##.\n.#.\n",
"3 3\n..#\n##.\n.#.\n"
]
] |
p03631 | AtCoder Beginner Contest 070 - Palindromic Number | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a three-digit positive integer <var>N</var>.<br/>
Determine whether <var>N</var> is a <em>palindromic number</em>.<br/>
Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>100β€Nβ€999</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>N</var> is a palindromic number, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>575
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>N=575</var> is also <var>575</var> when read backward, so it is a palindromic number. You should print <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>123
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>N=123</var> becomes <var>321</var> when read backward, so it is not a palindromic number. You should print <code>No</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>812
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> | [
[
"575\n",
"575\n"
]
] |
p03632 | AtCoder Beginner Contest 070 - Two Switches | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice and Bob are controlling a robot. They each have one switch that controls the robot.<br/>
Alice started holding down her button <var>A</var> second after the start-up of the robot, and released her button <var>B</var> second after the start-up.<br/>
Bob started holding down his button <var>C</var> second after the start-up, and released his button <var>D</var> second after the start-up.<br/>
For how many seconds both Alice and Bob were holding down their buttons?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0β€A<Bβ€100</var></li>
<li><var>0β€C<Dβ€100</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0 75 25 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>50
</pre>
<p>Alice started holding down her button <var>0</var> second after the start-up of the robot, and released her button <var>75</var> second after the start-up.<br/>
Bob started holding down his button <var>25</var> second after the start-up, and released his button <var>100</var> second after the start-up.<br/>
Therefore, the time when both of them were holding down their buttons, is the <var>50</var> seconds from <var>25</var> seconds after the start-up to <var>75</var> seconds after the start-up.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0 33 66 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 90 20 80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>60
</pre></section>
</div>
</span> | [
[
"0 75 25 100\n",
"0 75 25 100\n"
]
] |
p03633 | AtCoder Beginner Contest 070 - Multiple Clocks | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> clocks. The hand of the <var>i</var>-th clock <var>(1β€iβ€N)</var> rotates through <var>360Β°</var> in exactly <var>T_i</var> seconds.<br/>
Initially, the hand of every clock stands still, pointing directly upward.<br/>
Now, Dolphin starts all the clocks simultaneously.<br/>
In how many seconds will the hand of every clock point directly upward again?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1β€Nβ€100</var> </li>
<li><var>1β€T_iβ€10^{18}</var> </li>
<li>All input values are integers. </li>
<li>The correct answer is at most <var>10^{18}</var> seconds.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var>
<var>T_1</var>
<var>:</var>
<var>T_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of seconds after which the hand of every clock point directly upward again.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>We have two clocks. The time when the hand of each clock points upward is as follows:</p>
<ul>
<li>Clock <var>1</var>: <var>2</var>, <var>4</var>, <var>6</var>, <var>...</var> seconds after the beginning</li>
<li>Clock <var>2</var>: <var>3</var>, <var>6</var>, <var>9</var>, <var>...</var> seconds after the beginning</li>
</ul>
<p>Therefore, it takes <var>6</var> seconds until the hands of both clocks point directly upward.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2
5
10
1000000000000000000
1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000000000000000
</pre></section>
</div>
</span> | [
[
"2\n2\n3\n",
"2\n2\n3\n"
]
] |
p03634 | AtCoder Beginner Contest 070 - Transit Tree Path | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices.<br/>
Here, a <em>tree</em> is a kind of graph, and more specifically, a connected undirected graph with <var>N-1</var> edges, where <var>N</var> is the number of its vertices.<br/>
The <var>i</var>-th edge <var>(1β€iβ€N-1)</var> connects Vertices <var>a_i</var> and <var>b_i</var>, and has a length of <var>c_i</var>.</p>
<p>You are also given <var>Q</var> queries and an integer <var>K</var>. In the <var>j</var>-th query <var>(1β€jβ€Q)</var>:</p>
<ul>
<li>find the length of the shortest path from Vertex <var>x_j</var> and Vertex <var>y_j</var> via Vertex <var>K</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3β€Nβ€10^5</var> </li>
<li><var>1β€a_i,b_iβ€N (1β€iβ€N-1)</var> </li>
<li><var>1β€c_iβ€10^9 (1β€iβ€N-1)</var> </li>
<li>The given graph is a tree.</li>
<li><var>1β€Qβ€10^5</var> </li>
<li><var>1β€Kβ€N</var> </li>
<li><var>1β€x_j,y_jβ€N (1β€jβ€Q)</var> </li>
<li><var>x_jβ y_j (1β€jβ€Q)</var> </li>
<li><var>x_jβ K,y_jβ K (1β€jβ€Q)</var> </li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_{N-1}</var>
<var>Q</var> <var>K</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_{Q}</var> <var>y_{Q}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the responses to the queries in <var>Q</var> lines.<br/>
In the <var>j</var>-th line <var>j(1β€jβ€Q)</var>, print the response to the <var>j</var>-th query.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
2
4
</pre>
<p>The shortest paths for the three queries are as follows:</p>
<ul>
<li>Query <var>1</var>: Vertex <var>2</var> β Vertex <var>1</var> β Vertex <var>2</var> β Vertex <var>4</var> : Length <var>1+1+1=3</var> </li>
<li>Query <var>2</var>: Vertex <var>2</var> β Vertex <var>1</var> β Vertex <var>3</var> : Length <var>1+1=2</var> </li>
<li>Query <var>3</var>: Vertex <var>4</var> β Vertex <var>2</var> β Vertex <var>1</var> β Vertex <var>3</var> β Vertex <var>5</var> : Length <var>1+1+1+1=4</var> </li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
1 2 1
1 3 3
1 4 5
1 5 7
1 6 9
1 7 11
3 2
1 3
4 5
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
14
22
</pre>
<p>The path for each query must pass Vertex <var>K=2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>17000000000
</pre></section>
</div>
</span> | [
[
"5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2 3\n4 5\n",
"5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2 3\n4 5\n"
]
] |
p03635 | AtCoder Beginner Contest 069 - K-City | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In <em>K-city</em>, there are <var>n</var> streets running east-west, and <var>m</var> streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ n, m β€ 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>m</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of blocks in K-city.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six blocks, as shown below:</p>
<div style="text-align: center;">
<img alt="9179be829dc9810539213537d4c7398c.png" src="https://atcoder.jp/img/abc069/9179be829dc9810539213537d4c7398c.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There are one block, as shown below:</p>
<div style="text-align: center;">
<img alt="997bfafa99be630b54d037225a5c68ea.png" src="https://atcoder.jp/img/abc069/997bfafa99be630b54d037225a5c68ea.png">
</img></div></section>
</div>
</span> | [
[
"3 4\n",
"3 4\n"
]
] |
p03636 | AtCoder Beginner Contest 069 - i18n | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The word <code>internationalization</code> is sometimes abbreviated to <code>i18n</code>.
This comes from the fact that there are <var>18</var> letters between the first <code>i</code> and the last <code>n</code>.</p>
<p>You are given a string <var>s</var> of length at least <var>3</var> consisting of lowercase English letters.
Abbreviate <var>s</var> in the same way.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 β€ |s| β€ 100</var> (<var>|s|</var> denotes the length of <var>s</var>.)</li>
<li><var>s</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the abbreviation of <var>s</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>internationalization
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>i18n
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>smiles
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>s4s
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>xyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>x1z
</pre></section>
</div>
</span> | [
[
"internationalization\n",
"internationalization\n"
]
] |
p03637 | AtCoder Beginner Contest 069 - 4-adjacent | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>.
Each <var>a_i</var> is a positive integer.</p>
<p>Snuke's objective is to permute the element in <var>a</var> so that the following condition is satisfied:</p>
<ul>
<li>For each <var>1 β€ i β€ N - 1</var>, the product of <var>a_i</var> and <var>a_{i + 1}</var> is a multiple of <var>4</var>.</li>
</ul>
<p>Determine whether Snuke can achieve his objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ N β€ 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 β€ a_i β€ 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Snuke can achieve his objective, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>One solution is <var>(1, 100, 10)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is impossible to permute <var>a</var> so that the condition is satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
2 7 1 8 2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> | [
[
"3\n1 10 100\n",
"3\n1 10 100\n"
]
] |
p03638 | AtCoder Beginner Contest 069 - Grid Coloring | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares.
Snuke is painting these squares in colors <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>.
Here, the following conditions should be satisfied:</p>
<ul>
<li>For each <var>i</var> (<var>1 β€ i β€ N</var>), there are exactly <var>a_i</var> squares painted in Color <var>i</var>. Here, <var>a_1 + a_2 + ... + a_N = H W</var>.</li>
<li>For each <var>i</var> (<var>1 β€ i β€ N</var>), the squares painted in Color <var>i</var> are <em>4-connected</em>. That is, every square painted in Color <var>i</var> can be reached from every square painted in Color <var>i</var> by repeatedly traveling to a horizontally or vertically adjacent square painted in Color <var>i</var>.</li>
</ul>
<p>Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ H, W β€ 100</var></li>
<li><var>1 β€ N β€ H W</var></li>
<li><var>a_i β₯ 1</var></li>
<li><var>a_1 + a_2 + ... + a_N = H W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one way to paint the squares that satisfies the conditions.
Output in the following format:</p>
<pre><var>c_{1 1}</var> <var>...</var> <var>c_{1 W}</var>
<var>:</var>
<var>c_{H 1}</var> <var>...</var> <var>c_{H W}</var>
</pre>
<p>Here, <var>c_{i j}</var> is the color of the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
3
2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 1
2 3
</pre>
<p>Below is an example of an invalid solution:</p>
<pre>1 2
3 1
</pre>
<p>This is because the squares painted in Color <var>1</var> are not 4-connected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> | [
[
"2 2\n3\n2 1 1\n",
"2 2\n3\n2 1 1\n"
]
] |
p03639 | AtCoder Regular Contest 080 - 4-adjacent | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>.
Each <var>a_i</var> is a positive integer.</p>
<p>Snuke's objective is to permute the element in <var>a</var> so that the following condition is satisfied:</p>
<ul>
<li>For each <var>1 β€ i β€ N - 1</var>, the product of <var>a_i</var> and <var>a_{i + 1}</var> is a multiple of <var>4</var>.</li>
</ul>
<p>Determine whether Snuke can achieve his objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ N β€ 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 β€ a_i β€ 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Snuke can achieve his objective, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>One solution is <var>(1, 100, 10)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is impossible to permute <var>a</var> so that the condition is satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
2 7 1 8 2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> | [
[
"3\n1 10 100\n",
"3\n1 10 100\n"
]
] |
p03640 | AtCoder Regular Contest 080 - Grid Coloring | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares.
Snuke is painting these squares in colors <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>.
Here, the following conditions should be satisfied:</p>
<ul>
<li>For each <var>i</var> (<var>1 β€ i β€ N</var>), there are exactly <var>a_i</var> squares painted in Color <var>i</var>. Here, <var>a_1 + a_2 + ... + a_N = H W</var>.</li>
<li>For each <var>i</var> (<var>1 β€ i β€ N</var>), the squares painted in Color <var>i</var> are <em>4-connected</em>. That is, every square painted in Color <var>i</var> can be reached from every square painted in Color <var>i</var> by repeatedly traveling to a horizontally or vertically adjacent square painted in Color <var>i</var>.</li>
</ul>
<p>Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ H, W β€ 100</var></li>
<li><var>1 β€ N β€ H W</var></li>
<li><var>a_i β₯ 1</var></li>
<li><var>a_1 + a_2 + ... + a_N = H W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one way to paint the squares that satisfies the conditions.
Output in the following format:</p>
<pre><var>c_{1 1}</var> <var>...</var> <var>c_{1 W}</var>
<var>:</var>
<var>c_{H 1}</var> <var>...</var> <var>c_{H W}</var>
</pre>
<p>Here, <var>c_{i j}</var> is the color of the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
3
2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 1
2 3
</pre>
<p>Below is an example of an invalid solution:</p>
<pre>1 2
3 1
</pre>
<p>This is because the squares painted in Color <var>1</var> are not 4-connected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> | [
[
"2 2\n3\n2 1 1\n",
"2 2\n3\n2 1 1\n"
]
] |
p03641 | AtCoder Regular Contest 080 - Young Maids | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive even number.</p>
<p>We have a permutation of <var>(1, 2, ..., N)</var>, <var>p = (p_1, p_2, ..., p_N)</var>.
Snuke is constructing another permutation of <var>(1, 2, ..., N)</var>, <var>q</var>, following the procedure below.</p>
<p>First, let <var>q</var> be an empty sequence.
Then, perform the following operation until <var>p</var> becomes empty:</p>
<ul>
<li>Select two adjacent elements in <var>p</var>, and call them <var>x</var> and <var>y</var> in order. Remove <var>x</var> and <var>y</var> from <var>p</var> (reducing the length of <var>p</var> by <var>2</var>), and insert <var>x</var> and <var>y</var>, preserving the original order, at the beginning of <var>q</var>.</li>
</ul>
<p>When <var>p</var> becomes empty, <var>q</var> will be a permutation of <var>(1, 2, ..., N)</var>.</p>
<p>Find the lexicographically smallest permutation that can be obtained as <var>q</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an even number.</li>
<li><var>2 β€ N β€ 2 Γ 10^5</var></li>
<li><var>p</var> is a permutation of <var>(1, 2, ..., N)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest permutation, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 2 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 1 2 4
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(3, 2, 4, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 4)</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 4)</var></td>
</tr>
</tbody>
</table>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
4 6 3 2 8 5 7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3 1 2 7 4 6 8 5
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(4, 6, 3, 2, 8, 5, 7, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>(4, 6, 3, 2, 7, 1)</var></td>
<td align="center"><var>(8, 5)</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>(3, 2, 7, 1)</var></td>
<td align="center"><var>(4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 7, 4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">β</td>
<td align="center">β</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 7, 4, 6, 8, 5)</var></td>
</tr>
</tbody>
</table></section>
</div>
</span> | [
[
"4\n3 2 4 1\n",
"4\n3 2 4 1\n"
]
] |
p03642 | AtCoder Regular Contest 080 - Prime Flip | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are infinitely many cards, numbered <var>1</var>, <var>2</var>, <var>3</var>, <var>...</var>
Initially, Cards <var>x_1</var>, <var>x_2</var>, <var>...</var>, <var>x_N</var> are face up, and the others are face down.</p>
<p>Snuke can perform the following operation repeatedly:</p>
<ul>
<li>Select a prime <var>p</var> greater than or equal to <var>3</var>. Then, select <var>p</var> consecutive cards and flip all of them.</li>
</ul>
<p>Snuke's objective is to have all the cards face down.
Find the minimum number of operations required to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ N β€ 100</var></li>
<li><var>1 β€ x_1 < x_2 < ... < x_N β€ 10^7</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Below is one way to achieve the objective in two operations:</p>
<ul>
<li>Select <var>p = 5</var> and flip Cards <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var> and <var>5</var>.</li>
<li>Select <var>p = 3</var> and flip Cards <var>1</var>, <var>2</var> and <var>3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
1 2 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Below is one way to achieve the objective in three operations:</p>
<ul>
<li>Select <var>p = 3</var> and flip Cards <var>1</var>, <var>2</var> and <var>3</var>.</li>
<li>Select <var>p = 3</var> and flip Cards <var>4</var>, <var>5</var> and <var>6</var>.</li>
<li>Select <var>p = 3</var> and flip Cards <var>7</var>, <var>8</var> and <var>9</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 10000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> | [
[
"2\n4 5\n",
"2\n4 5\n"
]
] |
p03643 | AtCoder Beginner Contest 068 - ABCxxx | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>This contest, <em>AtCoder Beginner Contest</em>, is abbreviated as <em>ABC</em>.</p>
<p>When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.</p>
<p>What is the abbreviation for the <var>N</var>-th round of ABC? Write a program to output the answer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>100 β€ N β€ 999</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the abbreviation for the <var>N</var>-th round of ABC.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ABC100
</pre>
<p>The 100th round of ABC is ABC100.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>425
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ABC425
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>ABC999
</pre></section>
</div>
</span> | [
[
"100\n",
"100\n"
]
] |
p03644 | AtCoder Beginner Contest 068 - Break Number | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi loves numbers divisible by <var>2</var>.</p>
<p>You are given a positive integer <var>N</var>. Among the integers between <var>1</var> and <var>N</var> (inclusive), find the one that can be divisible by <var>2</var> for the most number of times. The solution is always unique.</p>
<p>Here, the number of times an integer can be divisible by <var>2</var>, is how many times the integer can be divided by <var>2</var> without remainder.</p>
<p>For example,</p>
<ul>
<li><var>6</var> can be divided by <var>2</var> once: <var>6</var> -> <var>3</var>.</li>
<li><var>8</var> can be divided by <var>2</var> three times: <var>8</var> -> <var>4</var> -> <var>2</var> -> <var>1</var>.</li>
<li><var>3</var> can be divided by <var>2</var> zero times.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 β€ N β€ 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p><var>4</var> can be divided by <var>2</var> twice, which is the most number of times among <var>1</var>, <var>2</var>, ..., <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>32
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>64
</pre></section>
</div>
</span> | [
[
"7\n",
"7\n"
]
] |
p03645 | AtCoder Beginner Contest 068 - Cat Snuke and a Voyage | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, there is an archipelago of <var>N</var> islands, called Takahashi Islands.
For convenience, we will call them Island <var>1</var>, Island <var>2</var>, ..., Island <var>N</var>.</p>
<p>There are <var>M</var> kinds of regular boat services between these islands.
Each service connects two islands. The <var>i</var>-th service connects Island <var>a_i</var> and Island <var>b_i</var>.</p>
<p>Cat Snuke is on Island <var>1</var> now, and wants to go to Island <var>N</var>.
However, it turned out that there is no boat service from Island <var>1</var> to Island <var>N</var>, so he wants to know whether it is possible to go to Island <var>N</var> by using two boat services.</p>
<p>Help him.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 β€ N β€ 200</var> <var>000</var></li>
<li><var>1 β€ M β€ 200</var> <var>000</var></li>
<li><var>1 β€ a_i < b_i β€ N</var></li>
<li><var>(a_i, b_i) \neq (1, N)</var></li>
<li>If <var>i \neq j</var>, <var>(a_i, b_i) \neq (a_j, b_j)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to go to Island <var>N</var> by using two boat services, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>You have to use three boat services to get to Island <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 1
1 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>IMPOSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 5
1 3
4 5
2 3
2 4
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>POSSIBLE
</pre>
<p>You can get to Island <var>5</var> by using two boat services: Island <var>1</var> -> Island <var>4</var> -> Island <var>5</var>.</p></section>
</div>
</span> | [
[
"3 2\n1 2\n2 3\n",
"3 2\n1 2\n2 3\n"
]
] |
p03646 | AtCoder Beginner Contest 068 - Decrease (Contestant ver.) | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller.</p>
<ul>
<li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li>
</ul>
<p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p>
<p>You are given an integer <var>K</var>. Find an integer sequence <var>a_i</var> such that the number of times we will perform the above operation is exactly <var>K</var>. It can be shown that there is always such a sequence under the constraints on input and output in this problem.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 β€ K β€ 50 \times 10^{16}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a solution in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
<p>Here, <var>2 β€ N β€ 50</var> and <var>0 β€ a_i β€ 10^{16} + 1000</var> must hold.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
3 3 3 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
1 0 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
2 2
</pre>
<p>The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>7
27 0 0 0 0 0 0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1234567894848
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>10
1000 193 256 777 0 1 1192 1234567891011 48 425
</pre></section>
</div>
</span> | [
[
"0\n",
"0\n"
]
] |
p03647 | AtCoder Regular Contest 079 - Cat Snuke and a Voyage | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, there is an archipelago of <var>N</var> islands, called Takahashi Islands.
For convenience, we will call them Island <var>1</var>, Island <var>2</var>, ..., Island <var>N</var>.</p>
<p>There are <var>M</var> kinds of regular boat services between these islands.
Each service connects two islands. The <var>i</var>-th service connects Island <var>a_i</var> and Island <var>b_i</var>.</p>
<p>Cat Snuke is on Island <var>1</var> now, and wants to go to Island <var>N</var>.
However, it turned out that there is no boat service from Island <var>1</var> to Island <var>N</var>, so he wants to know whether it is possible to go to Island <var>N</var> by using two boat services.</p>
<p>Help him.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 β€ N β€ 200</var> <var>000</var></li>
<li><var>1 β€ M β€ 200</var> <var>000</var></li>
<li><var>1 β€ a_i < b_i β€ N</var></li>
<li><var>(a_i, b_i) \neq (1, N)</var></li>
<li>If <var>i \neq j</var>, <var>(a_i, b_i) \neq (a_j, b_j)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to go to Island <var>N</var> by using two boat services, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>You have to use three boat services to get to Island <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 1
1 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>IMPOSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 5
1 3
4 5
2 3
2 4
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>POSSIBLE
</pre>
<p>You can get to Island <var>5</var> by using two boat services: Island <var>1</var> -> Island <var>4</var> -> Island <var>5</var>.</p></section>
</div>
</span> | [
[
"3 2\n1 2\n2 3\n",
"3 2\n1 2\n2 3\n"
]
] |
p03648 | AtCoder Regular Contest 079 - Decrease (Contestant ver.) | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller.</p>
<ul>
<li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li>
</ul>
<p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p>
<p>You are given an integer <var>K</var>. Find an integer sequence <var>a_i</var> such that the number of times we will perform the above operation is exactly <var>K</var>. It can be shown that there is always such a sequence under the constraints on input and output in this problem.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 β€ K β€ 50 \times 10^{16}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a solution in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
<p>Here, <var>2 β€ N β€ 50</var> and <var>0 β€ a_i β€ 10^{16} + 1000</var> must hold.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
3 3 3 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
1 0 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
2 2
</pre>
<p>The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>7
27 0 0 0 0 0 0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1234567894848
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>10
1000 193 256 777 0 1 1192 1234567891011 48 425
</pre></section>
</div>
</span> | [
[
"0\n",
"0\n"
]
] |
p03649 | AtCoder Regular Contest 079 - Decrease (Judge ver.) | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller. (The operation is the same as the one in Problem D.)</p>
<ul>
<li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li>
</ul>
<p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p>
<p>You are given the sequence <var>a_i</var>. Find the number of times we will perform the above operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ N β€ 50</var></li>
<li><var>0 β€ a_i β€ 10^{16} + 1000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times the operation will be performed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 0 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7
27 0 0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10
1000 193 256 777 0 1 1192 1234567891011 48 425
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>1234567894848
</pre></section>
</div>
</span> | [
[
"4\n3 3 3 3\n",
"4\n3 3 3 3\n"
]
] |
p03650 | AtCoder Regular Contest 079 - Namori Grundy | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices and <var>N</var> edges. The vertices are numbered <var>1, 2, ..., N</var>.</p>
<p>The graph has the following <var>N</var> edges: <var>(p_1, 1), (p_2, 2), ..., (p_N, N)</var>, and the graph is weakly connected. Here, an edge from Vertex <var>u</var> to Vertex <var>v</var> is denoted by <var>(u, v)</var>, and a weakly connected graph is a graph which would be connected if each edge was bidirectional.</p>
<p>We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, <var>a_i</var> is the value assigned to Vertex <var>i</var>.</p>
<ul>
<li>Each <var>a_i</var> is a non-negative integer.</li>
<li>For each edge <var>(i, j)</var>, <var>a_i \neq a_j</var> holds.</li>
<li>For each <var>i</var> and each integer <var>x(0 β€ x < a_i)</var>, there exists a vertex <var>j</var> such that the edge <var>(i, j)</var> exists and <var>x = a_j</var> holds.</li>
</ul>
<p>Determine whether there exists such an assignment.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 β€ N β€ 200</var> <var>000</var></li>
<li><var>1 β€ p_i β€ N</var></li>
<li><var>p_i \neq i</var></li>
<li>The graph is weakly connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> ... <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the assignment is possible, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 3 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
<p>The assignment is possible: {<var>a_i</var>} = {<var>0, 1, 0, 1</var>} or {<var>a_i</var>} <var>=</var> {<var>1, 0, 1, 0</var>}.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>POSSIBLE
</pre>
<p>The assignment is possible: {<var>a_i</var>} <var>=</var> {<var>2, 0, 1, 0</var>}.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
4 5 6 5 6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>IMPOSSIBLE
</pre></section>
</div>
</span> | [
[
"4\n2 3 4 1\n",
"4\n2 3 4 1\n"
]
] |
p03651 | AtCoder Grand Contest 018 - Getting Difference | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a box containing <var>N</var> balls. The <var>i</var>-th ball has the integer <var>A_i</var> written on it.
Snuke can perform the following operation any number of times:</p>
<ul>
<li>Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.</li>
</ul>
<p>Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer <var>K</var> is written.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible for Snuke to reach the state where the box contains a ball on which the integer <var>K</var> is written, print <code>POSSIBLE</code>; if it is not possible, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 7
9 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
<p>First, take out the two balls <var>9</var> and <var>4</var>, and return them back along with a new ball, <var>abs(9-4)=5</var>.
Next, take out <var>3</var> and <var>5</var>, and return them back along with <var>abs(3-5)=2</var>.
Finally, take out <var>9</var> and <var>2</var>, and return them back along with <var>abs(9-2)=7</var>.
Now we have <var>7</var> in the box, and the answer is therefore <code>POSSIBLE</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
6 9 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>No matter what we do, it is not possible to have <var>5</var> in the box. The answer is therefore <code>IMPOSSIBLE</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 11
11 3 7 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>POSSIBLE
</pre>
<p>The box already contains <var>11</var> before we do anything. The answer is therefore <code>POSSIBLE</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 12
10 2 8 6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>IMPOSSIBLE
</pre></section>
</div>
</span> | [
[
"3 7\n9 3 4\n",
"3 7\n9 3 4\n"
]
] |
p03652 | AtCoder Grand Contest 018 - Sports Festival | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is hosting an sports meet.
There are <var>N</var> people who will participate. These people are conveniently numbered <var>1</var> through <var>N</var>.
Also, there are <var>M</var> options of sports for this event. These sports are numbered <var>1</var> through <var>M</var>.
Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.</p>
<p>Takahashi knows that Person <var>i</var>'s <var>j</var>-th favorite sport is Sport <var>A_{ij}</var>.
Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.</p>
<p>Takahashi is worried that one of the sports will attract too many people.
Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.
Find the minimum possible number of the participants in the sport with the largest number of participants.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li><var>1 \leq M \leq 300</var></li>
<li><var>A_{i1}</var> , <var>A_{i2}</var> , <var>...</var> , <var>A_{iM}</var> is a permutation of the integers from <var>1</var> to <var>M</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var>
<var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2M}</var>
<var>:</var>
<var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible number of the participants in the sport with the largest number of participants.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Assume that Sports <var>1</var>, <var>3</var> and <var>4</var> are selected to be played. In this case, Person <var>1</var> will participate in Sport <var>1</var>, Person <var>2</var> in Sport <var>3</var>, Person <var>3</var> in Sport <var>3</var> and Person <var>4</var> in Sport <var>4</var>.
Here, the sport with the largest number of participants is Sport <var>3</var>, with two participants.
There is no way to reduce the number of participants in the sport with the largest number of participants to <var>1</var>. Therefore, the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
2 1 3
2 1 3
2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.
Therefore, the answer is <var>3</var>.</p></section>
</div>
</span> | [
[
"4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n",
"4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n"
]
] |
p03653 | AtCoder Grand Contest 018 - Coins | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>X+Y+Z</var> people, conveniently numbered <var>1</var> through <var>X+Y+Z</var>.
Person <var>i</var> has <var>A_i</var> gold coins, <var>B_i</var> silver coins and <var>C_i</var> bronze coins.</p>
<p>Snuke is thinking of getting gold coins from <var>X</var> of those people, silver coins from <var>Y</var> of the people and bronze coins from <var>Z</var> of the people.
It is not possible to get two or more different colors of coins from a single person.
On the other hand, a person will give all of his/her coins of the color specified by Snuke.</p>
<p>Snuke would like to maximize the total number of coins of all colors he gets.
Find the maximum possible number of coins.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X</var></li>
<li><var>1 \leq Y</var></li>
<li><var>1 \leq Z</var></li>
<li><var>X+Y+Z \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq B_i \leq 10^9</var></li>
<li><var>1 \leq C_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var>
<var>:</var>
<var>A_{X+Y+Z}</var> <var>B_{X+Y+Z}</var> <var>C_{X+Y+Z}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible total number of coins of all colors he gets.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>18
</pre>
<p>Get silver coins from Person <var>1</var>, silver coins from Person <var>2</var>, bronze coins from Person <var>3</var> and gold coins from Person <var>4</var>.
In this case, the total number of coins will be <var>4+2+7+5=18</var>.
It is not possible to get <var>19</var> or more coins, and the answer is therefore <var>18</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>110
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3093929975
</pre></section>
</div>
</span> | [
[
"1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3\n",
"1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3\n"
]
] |
p03654 | AtCoder Grand Contest 018 - Tree and Hamilton Path | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>.
The <var>i</var>-th edge in this tree connects Vertices <var>A_i</var> and <var>B_i</var> and has a length of <var>C_i</var>.</p>
<p>Joisino created a complete graph with <var>N</var> vertices.
The length of the edge connecting Vertices <var>u</var> and <var>v</var> in this graph, is equal to the shortest distance between Vertices <var>u</var> and <var>v</var> in the tree above.</p>
<p>Joisino would like to know the length of the longest Hamiltonian path (see Notes) in this complete graph.
Find the length of that path.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A <em>Hamiltonian path</em> in a graph is a path in the graph that visits each vertex exactly once.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i < B_i \leq N</var></li>
<li>The given graph is a tree.</li>
<li><var>1 \leq C_i \leq 10^8</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var>
<var>:</var>
<var>A_{N-1}</var> <var>B_{N-1}</var> <var>C_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the longest Hamiltonian path in the complete graph created by Joisino.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 5
3 4 7
2 3 3
2 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>38
</pre>
<p>The length of the Hamiltonian path <var>5</var> β <var>3</var> β <var>1</var> β <var>4</var> β <var>2</var> is <var>5+8+15+10=38</var>. Since there is no Hamiltonian path with length <var>39</var> or greater in the graph, the answer is <var>38</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
2 8 8
1 5 1
4 8 2
2 5 4
3 8 6
6 8 9
2 7 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>132
</pre></section>
</div>
</span> | [
[
"5\n1 2 5\n3 4 7\n2 3 3\n2 5 2\n",
"5\n1 2 5\n3 4 7\n2 3 3\n2 5 2\n"
]
] |
p03655 | AtCoder Grand Contest 018 - Sightseeing Plan | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is planning on touring Takahashi Town.
The town is divided into square sections by north-south and east-west lines.
We will refer to the section that is the <var>x</var>-th from the west and the <var>y</var>-th from the north as <var>(x,y)</var>.</p>
<p>Joisino thinks that a <em>touring plan</em> is good if it satisfies the following conditions:</p>
<ul>
<li>
<p>Let <var>(p,q)</var> be the section where she starts the tour. Then, <var>X_1 \leq p \leq X_2</var> and <var>Y_1 \leq q \leq Y_2</var> hold.</p>
</li>
<li>
<p>Let <var>(s,t)</var> be the section where she has lunch. Then, <var>X_3 \leq s \leq X_4</var> and <var>Y_3 \leq t \leq Y_4</var> hold.</p>
</li>
<li>
<p>Let <var>(u,v)</var> be the section where she ends the tour. Then, <var>X_5 \leq u \leq X_6</var> and <var>Y_5 \leq v \leq Y_6</var> hold.</p>
</li>
<li>
<p>By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.</p>
</li>
</ul>
<p>Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way.
Joisino would like to know how many different good touring plans there are.
Find the number of the different good touring plans.
Since it may be extremely large, find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X_1 \leq X_2 < X_3 \leq X_4 < X_5 \leq X_6 \leq 10^6</var></li>
<li><var>1 \leq Y_1 \leq Y_2 < Y_3 \leq Y_4 < Y_5 \leq Y_6 \leq 10^6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X_1</var> <var>X_2</var> <var>X_3</var> <var>X_4</var> <var>X_5</var> <var>X_6</var>
<var>Y_1</var> <var>Y_2</var> <var>Y_3</var> <var>Y_4</var> <var>Y_5</var> <var>Y_6</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different good touring plans, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 2 2 3 4
1 1 2 2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The starting section will always be <var>(1,1)</var>, and the lunch section will always be <var>(2,2)</var>.
There are four good touring plans where <var>(3,3)</var> is the ending section, and six good touring plans where <var>(4,3)</var> is the ending section.
Therefore, the answer is <var>6+4=10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 3 4 5 6
1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2346
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>77523 89555 420588 604360 845669 973451
2743 188053 544330 647651 709337 988194
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>137477680
</pre></section>
</div>
</span> | [
[
"1 1 2 2 3 4\n1 1 2 2 3 3\n",
"1 1 2 2 3 4\n1 1 2 2 3 3\n"
]
] |