A - ι⊥l

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

3 本の柱が等間隔に並んでいます。柱の高さは左から順に a メートル, b メートル, c メートル です。 柱の先端が同一直線上に並んでいる時、つまり b-a = c-b を満たしているとき、 この柱の並び方を美しいと呼びます。

柱の並び方が美しいかどうかを判定してください。

制約

  • 1 \leq a,b,c \leq 100
  • a,b,c は整数である。

入力

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

a b c

出力

柱の並び方が美しい場合 YES を、そうでない場合 NO1 行に出力せよ。


入力例 1

2 4 6

出力例 1

YES

4-2 = 6-4 であるため、この柱の並び方は美しいです。


入力例 2

2 5 6

出力例 2

NO

5-2 \neq 6-5 であるため、この柱の並び方は美しくありません。


入力例 3

3 2 1

出力例 3

YES

1-2 = 2-3 であるため、この柱の並び方は美しいです。

Score : 100 points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

Determine whether the arrangement of the poles is beautiful.

Constraints

  • 1 \leq a,b,c \leq 100
  • a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.


Sample Input 1

2 4 6

Sample Output 1

YES

Since 4-2 = 6-4, this arrangement of poles is beautiful.


Sample Input 2

2 5 6

Sample Output 2

NO

Since 5-2 \neq 6-5, this arrangement of poles is not beautiful.


Sample Input 3

3 2 1

Sample Output 3

YES

Since 1-2 = 2-3, this arrangement of poles is beautiful.

B - ∵∴∵

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

すぬけ君は新しくできたプログラミングコンテストに会員登録しました。 登録に使ったパスワードを覚えておく自信が無かったすぬけ君は、 手元の紙にパスワードをメモしておくことにしました。 ただし、そのままメモをすると誰かにパスワードを盗まれてしまうかもしれないので、 文字列の偶数番目の文字と奇数番目の文字をそれぞれ別々の紙にメモしておくことにしました。

パスワードの奇数番目の文字だけを順番を変えずに取り出した文字列 O と、 偶数番目の文字だけを順番を変えずに取り出した文字列 E が与えられます。 すぬけ君のかわりにパスワードを復元してください。

制約

  • O, E は小文字のアルファベット( a - z )からなる文字列
  • 1 \leq |O|,|E| \leq 50
  • |O| - |E|0 または 1 である。

入力

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

O
E

出力

パスワードを1行に出力せよ。


入力例 1

xyz
abc

出力例 1

xaybzc

xaybzc の奇数番目の文字のみを取り出すと、 xyz になり、 偶数番目の文字のみを取り出すと abc になります。


入力例 2

atcoderbeginnercontest
atcoderregularcontest

出力例 2

aattccooddeerrbreeggiunlnaerrccoonntteesstt

Score : 200 points

Problem Statement

Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.

You are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.

Constraints

  • O and E consists of lowercase English letters (a - z).
  • 1 \leq |O|,|E| \leq 50
  • |O| - |E| is either 0 or 1.

Input

Input is given from Standard Input in the following format:

O
E

Output

Print the original password.


Sample Input 1

xyz
abc

Sample Output 1

xaybzc

The original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.


Sample Input 2

atcoderbeginnercontest
atcoderregularcontest

Sample Output 2

aattccooddeerrbreeggiunlnaerrccoonntteesstt
C - Dubious Document

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

すぬけ君は、文字列の書かれた紙から文字をいくつか切り抜いて、並び替えて別の文字列を作るのが好きです。

明日になると、すぬけ君は文字列 S_1,...,S_n のうちどれか 1 つが書かれた紙がもらえます。 すぬけ君は文字列を作る事をとても楽しみにしているので、どんな文字列を作るか計画を立てることにしました。 ただし、すぬけ君はまだどの文字列が書かれた紙がもらえるかを知らないため、 どの文字列が書かれていた場合にも作れる文字列を考えることにしました。

S_1,...,S_n のどの文字列が書かれていても作れる文字列のうち、最長のものを求めてください。 最長のものが複数ある場合は、辞書順で最小のものを求めてください。

制約

  • 1 \leq n \leq 50
  • i = 1, ... , n に対して、 1 \leq |S_i| \leq 50
  • i = 1, ... , n に対して、 S_i は小文字のアルファベット( a - z )からなる文字列

入力

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

n
S_1
...
S_n

出力

条件を満たす最長の文字列のうち、辞書順で最小のものを出力せよ。 そのような文字列が空文字列である場合は、空行を出力せよ。


入力例 1

3
cbaa
daacc
acacac

出力例 1

aac

cbaa, daacc, acacac のどの文字列からも aa, aac, aca, caa などが作れます。 そのうち最も長いものは aac, aca, caa です。 この中で辞書順で最小のものは aac なので、 aac が答えになります。


入力例 2

3
a
aa
b

出力例 2



条件を満たす文字列は空文字列のみです。

Score : 300 points

Problem Statement

Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.

He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.

Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.

Constraints

  • 1 \leq n \leq 50
  • 1 \leq |S_i| \leq 50 for every i = 1, ..., n.
  • S_i consists of lowercase English letters (a - z) for every i = 1, ..., n.

Input

Input is given from Standard Input in the following format:

n
S_1
...
S_n

Output

Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.


Sample Input 1

3
cbaa
daacc
acacac

Sample Output 1

aac

The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth. Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.


Sample Input 2

3
a
aa
b

Sample Output 2



The answer is an empty string.

D - ###

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 500

問題文

2 次元平面上に x 軸と平行な直線が m 本と y 軸と平行な直線が n 本引いてあります。 x 軸と平行な直線のうち下から i 番目は y = y_i で表せます。 y 軸と平行な直線のうち左から i 番目は x = x_i で表せます。

この中に存在しているすべての長方形についてその面積を求め、 合計を 10^9+7 で割ったあまりを出力してください。

つまり、1\leq i < j\leq n1\leq k < l\leq m を満たすすべての組 (i,j,k,l) について、 直線 x=x_i, x=x_j, y=y_k, y=y_l で囲まれる 長方形の面積を求め、合計を 10^9+7 で割ったあまりを出力してください。

制約

  • 2 \leq n,m \leq 10^5
  • -10^9 \leq x_1 < ... < x_n \leq 10^9
  • -10^9 \leq y_1 < ... < y_m \leq 10^9
  • x_i, y_i は整数である。

入力

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

n m
x_1 x_2 ... x_n
y_1 y_2 ... y_m

出力

長方形の面積の合計を 10^9+7 で割ったあまりを 1 行に出力せよ。


入力例 1

3 3
1 3 4
1 3 6

出力例 1

60

この入力を図にすると、以下のようになります。

sample1-1

長方形 A,B,...,I それぞれの面積を合計すると 60 になります。

sample1-2


入力例 2

6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677

出力例 2

835067060

Score : 500 points

Problem Statement

On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.

For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.

That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.

Constraints

  • 2 \leq n,m \leq 10^5
  • -10^9 \leq x_1 < ... < x_n \leq 10^9
  • -10^9 \leq y_1 < ... < y_m \leq 10^9
  • x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

n m
x_1 x_2 ... x_n
y_1 y_2 ... y_m

Output

Print the total area of the rectangles, modulo 10^9+7.


Sample Input 1

3 3
1 3 4
1 3 6

Sample Output 1

60

The following figure illustrates this input:

sample1-1

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.

sample1-2


Sample Input 2

6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677

Sample Output 2

835067060