A - Task Failed Successfully

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

高橋君は N 日間のタスク目標を設定しました。

高橋君は i (1 \leq i \leq N) 日目に A_i 個のタスクを完了することを目標としており、実際には B_i 個のタスクを完了しました。

高橋君が目標より多くのタスクを完了した日数を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq A_i, B_i \leq 100
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

答えを出力せよ。


入力例 1

4
2 8
5 5
5 4
6 7

出力例 1

2

高橋君は 1 日目と 4 日目に目標より多くのタスクを完了しました。


入力例 2

5
1 1
1 1
1 1
1 1
1 1

出力例 2

0

入力例 3

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

出力例 3

3

Score : 100 points

Problem Statement

Takahashi set task goals for N days.

He aimed to complete A_i tasks on day i (1 \leq i \leq N), and actually completed B_i tasks.

Find the number of days when he completed more tasks than his goal.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq A_i, B_i \leq 100
  • All input values are integers.

Input

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Output the answer.


Sample Input 1

4
2 8
5 5
5 4
6 7

Sample Output 1

2

Takahashi completed more tasks than his goal on the 1st and 4th days.


Sample Input 2

5
1 1
1 1
1 1
1 1
1 1

Sample Output 2

0

Sample Input 3

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

Sample Output 3

3
B - 10yen Stamp

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

サンタさんに手紙を出したい高橋くんは、 X 円切手が 1 枚だけ貼られた封筒を用意しました。
サンタさんに手紙を届けるためには、貼られている切手の総額が Y 円以上である必要があります。
高橋くんは、この封筒に 10 円切手を何枚か貼り足すことで、貼られている切手の総額を Y 円以上にしたいです。
高橋くんはこの封筒に、最小で何枚の 10 円切手を貼り足す必要がありますか?

制約

  • X,Y は整数
  • 1 \le X,Y \le 1000

入力

入力は以下の形式で標準入力から与えられる。

X Y

出力

答えを整数として出力せよ。


入力例 1

80 94

出力例 1

2
  • 80 円切手に 0 枚の 10 円切手を貼り足せば総額が 80 円となり、これは手紙を届けるのに必要な 94 円未満です。
  • 80 円切手に 1 枚の 10 円切手を貼り足せば総額が 90 円となり、これは手紙を届けるのに必要な 94 円未満です。
  • 80 円切手に 2 枚の 10 円切手を貼り足せば総額が 100 円となり、これは手紙を届けるのに必要な 94 円以上です。

入力例 2

1000 63

出力例 2

0

もともと貼られている切手だけで金額が十分である可能性もあります。


入力例 3

270 750

出力例 3

48

Score : 100 points

Problem Statement

Takahashi wants to send a letter to Santa Claus. He has an envelope with an X-yen (Japanese currency) stamp stuck on it.
To be delivered to Santa Claus, the envelope must have stamps in a total value of at least Y yen.
Takahashi will put some more 10-yen stamps so that the envelope will have stamps worth at least Y yen in total.
At least how many more 10-yen stamps does Takahashi need to put on the envelope?

Constraints

  • X and Y are integers.
  • 1 \le X,Y \le 1000

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the answer as an integer.


Sample Input 1

80 94

Sample Output 1

2
  • After adding zero 10-yen stamps to the 80-yen stamp, the total is 80 yen, which is less than the required amount of 94 yen.
  • After adding one 10-yen stamp to the 80-yen stamp, the total is 90 yen, which is less than the required amount of 94 yen.
  • After adding two 10-yen stamps to the 80-yen stamp, the total is 100 yen, which is not less than the required amount of 94 yen.

Sample Input 2

1000 63

Sample Output 2

0

The envelope may already have a stamp with enough value.


Sample Input 3

270 750

Sample Output 3

48
C - Modulo Number

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

-10^{18} 以上 10^{18} 以下の整数 N が与えられます。

以下の条件を満たす 0 以上 998244353 未満の整数 x を求めてください。なお、答えが一意に定まることが証明できます。

  • N-x998244353 の倍数

制約

  • N-10^{18} 以上 10^{18} 以下の整数

入力

入力は以下の形式で標準入力から与えられる。

N

出力

答えを出力せよ。


入力例 1

998244354

出力例 1

1

998244354-1 = 998244353998244353 の倍数なので条件を満たします。


入力例 2

-9982443534

出力例 2

998244349

-9982443534-998244349= -10980687883998244353 の倍数なので条件を満たします。

Score : 200 points

Problem Statement

You are given an integer N between -10^{18} and 10^{18} (inclusive).

Find an integer x between 0 and 998244353 - 1 (inclusive) that satisfies the following condition. It can be proved that such an integer is unique.

  • N-x is a multiple of 998244353.

Constraints

  • N is an integer between -10^{18} and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

998244354

Sample Output 1

1

998244354-1 = 998244353 is a multiple of 998244353, so the condition is satisfied.


Sample Input 2

-9982443534

Sample Output 2

998244349

-9982443534-998244349= -10980687883 is a multiple of 998244353, so the condition is satisfied.

D - The Odd One Out

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

英小文字からなる長さ 3 以上の文字列 S が与えられます。
S はちょうど 2 種類の文字を含み、 1 文字だけ他の文字と異なります。その 1 文字を答えてください。

例えば、 Sodd なら o と答えてください。

制約

  • S は英小文字からなる長さ 3 以上 10 以下の文字列
  • S はちょうど 2 種類の文字を含み、 1 文字だけ他の文字と異なる

入力

入力は以下の形式で標準入力から与えられる。

S

出力

答えを出力せよ。


入力例 1

odd

出力例 1

o

odd のうち他の文字と異なるものは o です。


入力例 2

dad

出力例 2

a

dad のうち他の文字と異なるものは a です。


入力例 3

wwwwwwwwwv

出力例 3

v

wwwwwwwwwv のうち他の文字と異なるものは v です。

Score : 200 points

Problem Statement

You are given a string S of length at least 3 consisting of lowercase English letters.
S contains exactly two types of characters, and exactly one character is different from the others. Find that one character.

For example, if S is odd, report o.

Constraints

  • S is a string of length at least 3 and at most 10 consisting of lowercase English letters.
  • S contains exactly two types of characters, and exactly one character is different from the others.

Input

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

S

Output

Print the answer.


Sample Input 1

odd

Sample Output 1

o

In odd, the character different from the others is o.


Sample Input 2

dad

Sample Output 2

a

In dad, the character different from the others is a.


Sample Input 3

wwwwwwwwwv

Sample Output 3

v

In wwwwwwwwwv, the character different from the others is v.

E - Striped Horse

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

りんごさんは馬を縞模様に塗ってシマウマにしようとしています。

1 から N の番号がついた N 個のマスが一列に並んでいます。
最初、全てのマスは白色であり、マス i を黒く塗るためにはコストが C_i かかります。

以下の手順を一度だけ行い、いくつかのマスを黒く塗ることを考えます。

  • 正整数 x を自由に選ぶ。
  • 1 \leq i \leq N を満たす整数 i のうち、 (i+x)2W で割った余りが W より小さくなるもの全てに対し、マス i を黒く塗る。

この手順を行うためのコストの合計の最小値を求めてください。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1\leq T \leq 2\times 10^5
  • 1\leq N \leq 2\times 10^5
  • 1\leq W \leq 2\times 10^5
  • 1\leq C_i \leq 10^9
  • T 個のテストケースにおける N の総和は 2\times 10^5 以下
  • T 個のテストケースにおける W の総和は 2\times 10^5 以下
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。ここで \mathrm{case}_ii 番目のテストケースを意味する。

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

各テストケースは以下の形式で与えられる。

N W
C_1 \dots C_N

出力

T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。


入力例 1

4
8 2
1 10 10 1 1 10 10 1
8 3
1 10 10 1 1 10 10 1
8 4
1 10 10 1 1 10 10 1
4 100
100000 100000 100000 100000

出力例 1

4
12
22
0

1 番目のテストケースにおいて、x=4 として手順を実行すると、マス 1,4,5,8 が黒く塗られ、コストの合計は 4 となります。 コストの合計を 4 未満にすることはできないため、これが最小値となります。

Score : 300 points

Problem Statement

Ringo-san is trying to paint a horse with stripes to make it a zebra.

There are N squares numbered 1 to N arranged in a line.
Initially, all squares are white, and the cost of painting square i black is C_i.

Consider performing the following procedure once to paint some squares black:

  • Choose a positive integer x freely.
  • Paint square i black for all integers i satisfying 1 \leq i \leq N such that the remainder when (i+x) is divided by 2W is less than W.

Find the minimum total cost to perform this procedure.

You are given T test cases; solve each of them.

Constraints

  • 1\leq T \leq 2\times 10^5
  • 1\leq N \leq 2\times 10^5
  • 1\leq W \leq 2\times 10^5
  • 1\leq C_i \leq 10^9
  • The sum of N over the T test cases is at most 2\times 10^5.
  • The sum of W over the T test cases is at most 2\times 10^5.
  • All input values are integers.

Input

The input is given from Standard Input in the following format, where \mathrm{case}_i denotes the i-th test case.

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

Each test case is given in the following format:

N W
C_1 \dots C_N

Output

Output T lines. The i-th line should contain the answer for the i-th test case.


Sample Input 1

4
8 2
1 10 10 1 1 10 10 1
8 3
1 10 10 1 1 10 10 1
8 4
1 10 10 1 1 10 10 1
4 100
100000 100000 100000 100000

Sample Output 1

4
12
22
0

In the first test case, if the procedure is executed with x=4, squares 1,4,5,8 are painted black, and the total cost is 4. The total cost cannot be less than 4, so this is the minimum.

F - Make it Simple

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

頂点に 1 から N の、辺に 1 から M の番号がついた N 頂点 M 辺の無向グラフが与えられます。辺 i は頂点 u_i と頂点 v_i を結ぶ辺です。
グラフから辺を取り除いてグラフを単純にするためには、少なくとも何本の辺を取り除く必要がありますか?
ここでグラフが単純であるとは、グラフが自己ループや多重辺を含まないことをいいます。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 5 \times 10^5
  • 1 \leq u_i \leq N
  • 1 \leq v_i \leq N
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

出力

グラフを単純にするために取り除く必要がある辺の本数の最小値を出力せよ。


入力例 1

3 5
1 2
2 3
3 2
3 1
1 1

出力例 1

2

3 と辺 5 を取り除くとグラフを単純にすることが出来て、これが取り除く辺の本数が最小となる選び方の 1 つです。よって答えは 2 本です。


入力例 2

1 0

出力例 2

0

入力例 3

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

出力例 3

3

Score : 300 points

Problem Statement

You are given an undirected graph with N vertices and M edges, where the vertices are numbered 1 through N and the edges are numbered 1 through M. Edge i connects vertices u_i and v_i.
To make the graph simple by removing edges, what is the minimum number of edges that must be removed?
Here, a graph is called simple if and only if it does not contain self-loops or multi-edges.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 5 \times 10^5
  • 1 \leq u_i \leq N
  • 1 \leq v_i \leq N
  • All input values are integers.

Input

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

Output

Print the minimum number of edges that must be removed to make the graph simple.


Sample Input 1

3 5
1 2
2 3
3 2
3 1
1 1

Sample Output 1

2

By removing edges 3 and 5, the graph becomes simple. This is one of the ways to remove the minimum number of edges, so the answer is 2.


Sample Input 2

1 0

Sample Output 2

0

Sample Input 3

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

Sample Output 3

3
G - Kadomatsu Subsequence

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 425

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
以下を全て満たす整数の 3 つ組 (i,j,k) がいくつあるか求めてください。

  • 1 \le i,j,k \le N
  • A_i : A_j : A_k = 7:5:3
  • \min(i,j,k) = j または \max(i,j,k) = j

制約

  • 入力は全て整数
  • 1 \le N \le 3 \times 10^5
  • 1 \le A_i \le 10^9

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \dots A_N

出力

答えを出力せよ。


入力例 1

10
3 10 7 10 7 6 7 6 5 14

出力例 1

7

条件を満たす整数の 3 つ組 (i,j,k) は以下の 7 個です。

  • (3,9,1)
    • A_i : A_j : A_k = 7:5:3 であり、 \max(i,j,k) = j です。
  • (5,9,1)
    • A_i : A_j : A_k = 7:5:3 であり、 \max(i,j,k) = j です。
  • (7,9,1)
    • A_i : A_j : A_k = 7:5:3 であり、 \max(i,j,k) = j です。
  • (10,2,6)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3 であり、 \min(i,j,k) = j です。
  • (10,2,8)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3 であり、 \min(i,j,k) = j です。
  • (10,4,6)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3 であり、 \min(i,j,k) = j です。
  • (10,4,8)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3 であり、 \min(i,j,k) = j です。

入力例 2

6
210 210 210 210 210 210

出力例 2

0

入力例 3

21
49 30 50 21 35 15 21 70 35 9 50 70 21 49 30 50 70 15 9 21 30

出力例 3

34

Score : 425 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N.
Find the number of triples of integers (i,j,k) that satisfy all of the following:

  • 1 \le i,j,k \le N
  • A_i : A_j : A_k = 7:5:3
  • \min(i,j,k) = j or \max(i,j,k) = j.

Constraints

  • All input values are integers.
  • 1 \le N \le 3 \times 10^5
  • 1 \le A_i \le 10^9

Input

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

N
A_1 A_2 \dots A_N

Output

Output the answer.


Sample Input 1

10
3 10 7 10 7 6 7 6 5 14

Sample Output 1

7

The seven triples of integers (i,j,k) that satisfy the conditions are:

  • (3,9,1)
    • A_i : A_j : A_k = 7:5:3, and \max(i,j,k) = j.
  • (5,9,1)
    • A_i : A_j : A_k = 7:5:3, and \max(i,j,k) = j.
  • (7,9,1)
    • A_i : A_j : A_k = 7:5:3, and \max(i,j,k) = j.
  • (10,2,6)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3, and \min(i,j,k) = j.
  • (10,2,8)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3, and \min(i,j,k) = j.
  • (10,4,6)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3, and \min(i,j,k) = j.
  • (10,4,8)
    • A_i : A_j : A_k = 14:10:6 = 7:5:3, and \min(i,j,k) = j.

Sample Input 2

6
210 210 210 210 210 210

Sample Output 2

0

Sample Input 3

21
49 30 50 21 35 15 21 70 35 9 50 70 21 49 30 50 70 15 9 21 30

Sample Output 3

34
H - Remove Pairs

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 475

問題文

高橋君と青木君は N 枚のカードを使ってとあるゲームをします。i 枚目のカードの表面には A_i が、裏面には B_i が書かれています。初めに場には N 枚のカードが並べられており、高橋君を先手として、2 人は以下の操作を交互に繰り返します。

  • 場にあるカードの中から表面同士に同じ数が書かれている、または裏面同士に同じ数が書かれている 2 枚のカードの組を選び、そのカードを場から取り除く。このようなカードの組が存在しない場合、操作を行えない。

先に操作を行えなくなった方が負けとなり、もう一方が勝ちとなります。 両者がそれぞれ勝つために最適な操作を選ぶ時、どちらが勝つか求めてください。

制約

  • 1 \leq N \leq 18
  • 1 \leq A_i,B_i \leq 10^9
  • 入力は全て整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

2 人とも最適に操作を行なったとき、高橋君が勝つ場合は Takahashi と、青木君が勝つ場合は Aoki と出力せよ。


入力例 1

5
1 9
2 5
4 9
1 4
2 5

出力例 1

Aoki

髙橋君が最初に取り除いた 2 枚が

  • 1 枚目と 3 枚目のカードだった場合: 青木君は 2 枚目と 5 枚目のカードを取り除くことで勝つことができる。

  • 1 枚目と 4 枚目のカードだった場合: 青木君は 2 枚目と 5 枚目のカードを取り除くことで勝つことができる。

  • 2 枚目と 5 枚目のカードだった場合: 青木君は 1 枚目と 3 枚目のカードを取り除くことで勝つことができる。

髙橋君が最初の操作で取り除くことができるカードの組み合わせは以上の 3 通りのみで、髙橋君がどのような操作を行っても青木君が勝つことができるため、青木君が答えとなります。


入力例 2

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

出力例 2

Takahashi

Score : 475 points

Problem Statement

Takahashi and Aoki are playing a game using N cards. The front side of the i-th card has A_i written on it, and the back side has B_i written on it. Initially, the N cards are laid out on the table. With Takahashi going first, the two players take turns performing the following operation:

  • Choose a pair of cards from the table such that either the numbers on their front sides are the same or the numbers on their back sides are the same, and remove these two cards from the table. If no such pair of cards exists, the player cannot perform the operation.

The player who is first to be unable to perform the operation loses, and the other player wins. Determine who wins if both players play optimally.

Constraints

  • 1 \leq N \leq 18
  • 1 \leq A_i, B_i \leq 10^9
  • All input values are integers.

Input

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print Takahashi if Takahashi wins when both players play optimally, and Aoki otherwise.


Sample Input 1

5
1 9
2 5
4 9
1 4
2 5

Sample Output 1

Aoki

If Takahashi first removes

  • the first and third cards: Aoki can win by removing the second and fifth cards.

  • the first and fourth cards: Aoki can win by removing the second and fifth cards.

  • the second and fifth cards: Aoki can win by removing the first and third cards.

These are the only three pairs of cards Takahashi can remove in his first move, and Aoki can win in all cases. Therefore, the answer is Aoki.


Sample Input 2

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

Sample Output 2

Takahashi
I - Box in Box

実行時間制限: 2.5 sec / メモリ制限: 1024 MiB

配点 : 525

問題文

N 個の箱があります。 i 番目の箱は高さ・幅・奥行きがそれぞれ h_i,w_i,d_i の直方体の形をしています。

二つの箱であって、必要ならば回転させることで片方の高さ・幅・奥行きがもう片方の高さ・幅・奥行きをそれぞれ上回るようなものが存在するかを判定してください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq h_i,w_i,d_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
h_1 w_1 d_1
\vdots
h_N w_N d_N

出力

二つの箱であって、必要ならば回転させることで片方の高さ・幅・奥行きがもう片方の高さ・幅・奥行きをそれぞれ上回るようなものが存在するならば Yes と、そうでなければ No と出力せよ。


入力例 1

3
19 8 22
10 24 12
15 25 11

出力例 1

Yes

2 番目の箱を回転させて高さと奥行きを入れ替えると、3 番目の箱が高さ・幅・奥行きをそれぞれ上回ります。


入力例 2

3
19 8 22
10 25 12
15 24 11

出力例 2

No

入力例 3

2
1 1 2
1 2 2

出力例 3

No

Score : 525 points

Problem Statement

There are N boxes. The i-th box has a shape of a rectangular cuboid whose height, width, and depth are h_i,w_i, and d_i, respectively.

Determine if there are two boxes such that one's height, width, and depth are strictly greater than those of the other after rotating them if necessary.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq h_i,w_i,d_i \leq 10^9
  • All input values are integers.

Input

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

N
h_1 w_1 d_1
\vdots
h_N w_N d_N

Output

Print Yes if there are two boxes such that one's height, width, and depth are strictly greater than those of the other after rotating them if necessary; print No otherwise.


Sample Input 1

3
19 8 22
10 24 12
15 25 11

Sample Output 1

Yes

If you rotate the 2-nd box to swap its height and depth, the 3-rd box will have greater height, depth, and width.


Sample Input 2

3
19 8 22
10 25 12
15 24 11

Sample Output 2

No

Sample Input 3

2
1 1 2
1 2 2

Sample Output 3

No