A - CAPS LOCK

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

配点 : 100

問題文

英小文字のみからなる文字列 S が与えられます。

S の各文字を英大文字に変換して得られる文字列 T を出力してください。

制約

  • S は英小文字のみからなる、長さが 1 以上 100 以下の文字列

入力

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

S

出力

T を出力せよ。


入力例 1

abc

出力例 1

ABC

abc の各文字を英大文字に変換すると ABC になります。


入力例 2

a

出力例 2

A

入力例 3

abcdefghjiklnmoqprstvuwxyz

出力例 3

ABCDEFGHJIKLNMOQPRSTVUWXYZ

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters.

Uppercase each character of S and print the resulting string T.

Constraints

  • S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.

Input

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

S

Output

Print T.


Sample Input 1

abc

Sample Output 1

ABC

Uppercase each character of abc, and you have ABC.


Sample Input 2

a

Sample Output 2

A

Sample Input 3

abcdefghjiklnmoqprstvuwxyz

Sample Output 3

ABCDEFGHJIKLNMOQPRSTVUWXYZ
B - Growth Record

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

配点 : 100

問題文

高橋君は N 歳の誕生日を迎えました。この時の彼の身長は T cmです。
また、以下のことが分かっています。

  • 高橋君は 0 歳の誕生日(生まれた当日)から X 歳の誕生日までの間、毎年身長が D cmずつ伸びた。より厳密に書くと、i=1,2,\ldots,X それぞれに対し、i-1 歳の誕生日から i 歳の誕生日までの間に身長が D cm伸びた。
  • 高橋君は X 歳の誕生日から N 歳の誕生日までの間、身長が変化していない。

高橋君の M 歳の誕生日の時の身長が何cmだったかを求めてください。

制約

  • 0 \leq M \lt N \leq 100
  • 1 \leq X \leq N
  • 1 \leq T \leq 200
  • 1 \leq D \leq 100
  • 高橋君の 0 歳の誕生日の時の身長は 1 cm以上である
  • 入力はすべて整数

入力

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

N M X T D

出力

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


入力例 1

38 20 17 168 3

出力例 1

168

この例では、高橋君の 38 歳の誕生日の時の身長が 168 cmです。また、17 歳の誕生日から 38 歳の誕生日までの間、身長が変化していません。
このことから、20 歳の誕生日の時の身長は 168 cmだったと言え、これが答えになります。


入力例 2

1 0 1 3 2

出力例 2

1

この例において、高橋君は 0(=M) 歳の誕生日の時の身長が 1 cmで、1(=N) 歳の誕生日の時の身長が 3(=T) cmです。


入力例 3

100 10 100 180 1

出力例 3

90

Score : 100 points

Problem Statement

Takahashi had his N-th birthday, when he was T centimeters tall.
Additionally, we know the following facts:

  • In each year between Takahashi's birth (0-th birthday) and his X-th birthday, his height increased by D centimeters. More formally, for each i = 1, 2, \ldots, X, his height increased by D centimeters between his (i-1)-th birthday and his i-th birthday.
  • Between Takahashi's X-th birthday and his N-th birthday, his height did not change.

Find Takahashi's height on his M-th birthday, in centimeters.

Constraints

  • 0 \leq M \lt N \leq 100
  • 1 \leq X \leq N
  • 1 \leq T \leq 200
  • 1 \leq D \leq 100
  • Takahashi was at least 1 centimeter tall at his birth.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M X T D

Output

Print the answer as an integer.


Sample Input 1

38 20 17 168 3

Sample Output 1

168

In this sample, Takahashi was 168 centimeters tall on his 38-th birthday. Also, his height did not change between his 17-th birthday and 38-th birthday.
From these facts, we find that he was 168 centimeters tall on his 20-th birthday, so the answer is 168.


Sample Input 2

1 0 1 3 2

Sample Output 2

1

In this sample, Takahashi was 1 centimeter tall on his 0(=M)-th birthday and 3(=T) centimeters tall on his 1(=N)-st birthday.


Sample Input 3

100 10 100 180 1

Sample Output 3

90
C - Delimiter

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

配点 : 150

問題文

N 個の整数 A_1,A_2,\dots,A_N が、 1 行に 1 つずつ、 N 行にわたって与えられます。但し、 N は入力では与えられません。
さらに、以下が保証されます。

  • A_i \neq 0 ( 1 \le i \le N-1 )
  • A_N = 0

A_N, A_{N-1},\dots,A_1 をこの順に出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 100
  • 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
  • A_N = 0

入力

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

A_1
A_2
\vdots
A_N

出力

A_N, A_{N-1},\dots,A_1 をこの順に、改行区切りで整数として出力せよ。


入力例 1

3
2
1
0

出力例 1

0
1
2
3

繰り返しになりますが、 N は入力では与えられないことに注意してください。
この入力においては N=4 で、 A=(3,2,1,0) です。


入力例 2

0

出力例 2

0

A=(0) です。


入力例 3

123
456
789
987
654
321
0

出力例 3

0
321
654
987
789
456
123

Score: 150 points

Problem Statement

You are given N integers A_1,A_2,\dots,A_N, one per line, over N lines. However, N is not given in the input.
Furthermore, the following is guaranteed:

  • A_i \neq 0 ( 1 \le i \le N-1 )
  • A_N = 0

Print A_N, A_{N-1},\dots,A_1 in this order.

Constraints

  • All input values are integers.
  • 1 \le N \le 100
  • 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
  • A_N = 0

Input

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

A_1
A_2
\vdots
A_N

Output

Print A_N, A_{N-1}, \dots, A_1 in this order, as integers, separated by newlines.


Sample Input 1

3
2
1
0

Sample Output 1

0
1
2
3

Note again that N is not given in the input. Here, N=4 and A=(3,2,1,0).


Sample Input 2

0

Sample Output 2

0

A=(0).


Sample Input 3

123
456
789
987
654
321
0

Sample Output 3

0
321
654
987
789
456
123
D - Prefix and Suffix

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

配点 : 200

問題文

英小文字からなる文字列 S, T が与えられます。S の長さは NT の長さは M です。(N \leq M が制約で保証されています)

ST接頭辞 であるとは、T のはじめ N 文字からなる文字列が S と一致することを言います。
ST接尾辞 であるとは、T の後ろ N 文字からなる文字列が S と一致することを言います。

ST の接頭辞であり、かつ接尾辞でもある場合は 0 を、
ST の接頭辞であるが、接尾辞でない場合は 1 を、
ST の接尾辞であるが、接頭辞でない場合は 2 を、
ST の接頭辞でも接尾辞でもない場合は 3 を出力してください。

制約

  • 1 \leq N \leq M \leq 100
  • S は英小文字からなる長さ N の文字列
  • T は英小文字からなる長さ M の文字列

入力

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

N M
S
T

出力

問題文の指示に従って答えを出力せよ。


入力例 1

3 7
abc
abcdefg

出力例 1

1

ST の接頭辞ですが接尾辞ではありません。よって 1 を出力します。


入力例 2

3 4
abc
aabc

出力例 2

2

ST の接尾辞ですが接頭辞ではありません。


入力例 3

3 3
abc
xyz

出力例 3

3

ST の接頭辞でも接尾辞でもありません。


入力例 4

3 3
aaa
aaa

出力例 4

0

ST が完全に一致する場合もあります。この場合、ST の接頭辞であり、かつ接尾辞でもあります。

Score : 200 points

Problem Statement

You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M, respectively. (The constraints guarantee that N \leq M.)

S is said to be a prefix of T when the first N characters of T coincide S.
S is said to be a suffix of T when the last N characters of T coincide S.

If S is both a prefix and a suffix of T, print 0;
If S is a prefix of T but not a suffix, print 1;
If S is a suffix of T but not a prefix, print 2;
If S is neither a prefix nor a suffix of T, print 3.

Constraints

  • 1 \leq N \leq M \leq 100
  • S is a string of length N consisting of lowercase English letters.
  • T is a string of length M consisting of lowercase English letters.

Input

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

N M
S
T

Output

Print the answer according to the instructions in the problem statement.


Sample Input 1

3 7
abc
abcdefg

Sample Output 1

1

S is a prefix of T but not a suffix, so you should print 1.


Sample Input 2

3 4
abc
aabc

Sample Output 2

2

S is a suffix of T but not a prefix.


Sample Input 3

3 3
abc
xyz

Sample Output 3

3

S is neither a prefix nor a suffix of T.


Sample Input 4

3 3
aaa
aaa

Sample Output 4

0

S and T may coincide, in which case S is both a prefix and a suffix of T.

E - T-shirts

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

配点 : 300

問題文

AtCoder 社はロゴ入りの T シャツを販売しています。

高橋君の N 日間の予定が 0, 1, 2 のみからなる長さ N の文字列 S で与えられます。
具体的には、1\leq i\leq N をみたす整数 i について、

  • Si 文字目が 0 のとき、i 日目に何の予定も入っていません。
  • Si 文字目が 1 のとき、i 日目に高橋君は食事に行く予定があります。
  • Si 文字目が 2 のとき、i 日目に高橋君は競技プログラミングのイベントに行く予定が入っています。

高橋君は無地の T シャツを M 枚持っており、1 日目の直前の時点ですべて洗濯済みの状態となっています。
これに加えて、次の条件をみたすように行動できるように、高橋君は AtCoder のロゴ入りの T シャツを何枚か購入する事にしました。

  • 食事に行く日には、無地の T シャツ 1 枚またはロゴ入りの T シャツ 1 枚を着用する。
  • 競技プログラミングのイベントに行く日にはロゴ入りの T シャツ 1 枚を着用する。
  • 何の予定もない日には T シャツを着用しない。加えて、その時点で着用済みの T シャツを全て洗濯する。 洗濯した T シャツは翌日から着用できる。
  • 一度着用した T シャツは次に洗濯するまで着用できない。

N 日間のうち予定が入っている日すべてについて、条件をみたす T シャツを着用できるようにするために、高橋君は最低何枚のTシャツを購入する必要があるか求めてください。 新しく T シャツを購入する必要がないならば 0 を出力してください。
ただし、購入した T シャツも 1 日目の直前の時点ですべて洗濯済みの状態で存在するものとします。

制約

  • 1\leq M\leq N\leq 1000
  • S0, 1, 2 のみからなる長さ N の文字列
  • N,M は整数

入力

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

N M
S

出力

問題文の条件をみたすように行動するために 高橋君が購入する必要のある T シャツの枚数の最小値を出力せよ。
新しく購入する必要がないならば 0 を出力せよ。


入力例 1

6 1
112022

出力例 1

2

高橋君がロゴ入りの T シャツを 2 枚購入したとき、次のようにして高橋君は T シャツを着用することができます。

  • 1 日目、高橋君はロゴ入りの T シャツを着用して食事に行きます。
  • 2 日目、高橋君は無地の T シャツを着用して食事に行きます。
  • 3 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
  • 4 日目、高橋君は予定がないため、着用した T シャツをすべて洗濯します。これにより、1,2,3 日目に着用した T シャツを再び着用することが可能になります。
  • 5 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
  • 6 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。

高橋君がロゴ入りの T シャツを 1 枚以下しか購入しなかった場合には、 どのようにしても条件をみたすように T シャツを着用することができません。
よって、2 を出力します。


入力例 2

3 1
222

出力例 2

3

入力例 3

2 1
01

出力例 3

0

高橋君は新しく T シャツを購入する必要はありません。

Score : 300 points

Problem Statement

AtCoder Inc. sells T-shirts with its logo.

You are given Takahashi's schedule for N days as a string S of length N consisting of 0, 1, and 2.
Specifically, for an integer i satisfying 1\leq i\leq N,

  • if the i-th character of S is 0, he has no plan scheduled for the i-th day;
  • if the i-th character of S is 1, he plans to go out for a meal on the i-th day;
  • if the i-th character of S is 2, he plans to attend a competitive programming event on the i-th day.

Takahashi has M plain T-shirts, all washed and ready to wear just before the first day.
In addition, to be able to satisfy the following conditions, he will buy several AtCoder logo T-shirts.

  • On days he goes out for a meal, he will wear a plain or logo T-shirt.
  • On days he attends a competitive programming event, he will wear a logo T-shirt.
  • On days with no plans, he will not wear any T-shirts. Also, he will wash all T-shirts worn at that point. He can wear them again from the next day onwards.
  • Once he wears a T-shirt, he cannot wear it again until he washes it.

Determine the minimum number of T-shirts he needs to buy to be able to wear appropriate T-shirts on all scheduled days during the N days. If he does not need to buy new T-shirts, print 0.
Assume that the purchased T-shirts are also washed and ready to use just before the first day.

Constraints

  • 1\leq M\leq N\leq 1000
  • S is a string of length N consisting of 0, 1, and 2.
  • N and M are integers.

Input

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

N M
S

Output

Print the minimum number of T-shirts Takahashi needs to buy to be able to satisfy the conditions in the problem statement.
If he does not need to buy new T-shirts, print 0.


Sample Input 1

6 1
112022

Sample Output 1

2

If Takahashi buys two logo T-shirts, he can wear T-shirts as follows:

  • On the first day, he wears a logo T-shirt to go out for a meal.
  • On the second day, he wears a plain T-shirt to go out for a meal.
  • On the third day, he wears a logo T-shirt to attend a competitive programming event.
  • On the fourth day, he has no plans, so he washes all the worn T-shirts. This allows him to reuse the T-shirts worn on the first, second, and third days.
  • On the fifth day, he wears a logo T-shirt to attend a competitive programming event.
  • On the sixth day, he wears a logo T-shirt to attend a competitive programming event.

If he buys one or fewer logo T-shirts, he cannot use T-shirts to meet the conditions no matter what. Hence, print 2.


Sample Input 2

3 1
222

Sample Output 2

3

Sample Input 3

2 1
01

Sample Output 3

0

He does not need to buy new T-shirts.

F - Popcorn

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

配点 : 300

問題文

AtCoder Land には 1 から N までの番号が付けられた N 個のポップコーン売り場があります。 売られているポップコーンの味には味 1,2,\dots,MM 種類がありますが、すべての売り場ですべての味のポップコーンを売っているわけではありません。

高橋君は、それぞれのポップコーン売り場でどの味のポップコーンを売っているかの情報を入手しました。 この情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N によって表され、S_ij 文字目が o であるとき売り場 i が味 j のポップコーンを売っていることを、 x であるとき売っていないことを示します。 どの売り場も最低 1 種類の味のポップコーンを売っており、どの味のポップコーンも最低 1 つの売り場で売られています。

高橋君は全種類のポップコーンを食べたがっていますが、あまり何度も移動はしたくありません。 高橋君がすべての味のポップコーンを購入するためには最低何個の売り場を訪れる必要があるか求めてください。

制約

  • N,M は整数
  • 1\leq N,M \leq 10
  • S_io および x からなる長さ M の文字列
  • すべての i\ (1\leq i\leq N) について、S_i の中には o1 つ以上存在する
  • すべての j\ (1\leq j\leq M) について、S_ij 文字目が o であるような i1 つ以上存在する

入力

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

N M
S_1
S_2
\vdots
S_N

出力

高橋君がすべての味のポップコーンを購入するために訪れる必要がある売り場の個数の最小値を出力せよ。


入力例 1

3 5
oooxx
xooox
xxooo

出力例 1

2

1 つめの売り場と 3 つめの売り場を訪れることで、すべての味のポップコーンを購入することができます。 1 つの売り場ですべての味のポップコーンを購入することはできないので、答えは 2 です。


入力例 2

3 2
oo
ox
xo

出力例 2

1

入力例 3

8 6
xxoxxo
xxoxxx
xoxxxx
xxxoxx
xxoooo
xxxxox
xoxxox
oxoxxo

出力例 3

3

Score : 300 points

Problem Statement

In AtCoder Land, there are N popcorn stands numbered 1 to N. They have M different flavors of popcorn, labeled 1, 2, \dots, M, but not every stand sells all flavors of popcorn.

Takahashi has obtained information about which flavors of popcorn are sold at each stand. This information is represented by N strings S_1, S_2, \dots, S_N of length M. If the j-th character of S_i is o, it means that stand i sells flavor j of popcorn. If it is x, it means that stand i does not sell flavor j. Each stand sells at least one flavor of popcorn, and each flavor of popcorn is sold at least at one stand.

Takahashi wants to try all the flavors of popcorn but does not want to move around too much. Determine the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.

Constraints

  • N and M are integers.
  • 1 \leq N, M \leq 10
  • Each S_i is a string of length M consisting of o and x.
  • For every i (1 \leq i \leq N), there is at least one o in S_i.
  • For every j (1 \leq j \leq M), there is at least one i such that the j-th character of S_i is o.

Input

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

N M
S_1
S_2
\vdots
S_N

Output

Print the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.


Sample Input 1

3 5
oooxx
xooox
xxooo

Sample Output 1

2

By visiting the 1st and 3rd stands, you can buy all the flavors of popcorn. It is impossible to buy all the flavors from a single stand, so the answer is 2.


Sample Input 2

3 2
oo
ox
xo

Sample Output 2

1

Sample Input 3

8 6
xxoxxo
xxoxxx
xoxxxx
xxxoxx
xxoooo
xxxxox
xoxxox
oxoxxo

Sample Output 3

3
G - Make Bipartite 2

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

配点 : 400

問題文

N 個の頂点と M 本の辺からなる単純な(すなわち、自己ループも多重辺も含まない)無向グラフ G が与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結びます。

1 \leq u \lt v \leq N を満たす整数の組 (u, v) であって、下記の 2 つの条件をともに満たすものの個数を出力してください。

  • グラフ G において、頂点 u と頂点 v を結ぶ辺は存在しない。
  • グラフ G に、頂点 u と頂点 v を結ぶ辺を追加して得られるグラフは、二部グラフである。
二部グラフとは?

無向グラフが二部グラフであるとは、下記の条件を満たすように各頂点を黒または白のどちらかの色で塗ることができることを言います。

  • 同じ色に塗られた頂点どうしを結ぶ辺は存在しない。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min \lbrace 2 \times 10^5, N(N-1)/2 \rbrace
  • 1 \leq u_i, v_i \leq N
  • グラフ G は単純
  • 入力はすべて整数

入力

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

出力

答えを出力せよ。


入力例 1

5 4
4 2
3 1
5 2
3 2

出力例 1

2

問題文中の条件を満たす整数の組 (u, v) は、(1, 4)(1, 5)2 つです。よって、2 を出力します。
他の組については、例えば、(1, 3) はグラフ G において頂点 1 と頂点 3 を結ぶ辺が存在することから、 (4, 5) はグラフ G に頂点 4 と頂点 5 を結ぶ辺を追加して得られるグラフが二部グラフではないことから、 それぞれ問題文中の条件を満たしません。


入力例 2

4 3
3 1
3 2
1 2

出力例 2

0

与えられるグラフが二部グラフであったり連結であるとは限らないことに注意してください。


入力例 3

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

出力例 3

9

Score : 400 points

Problem Statement

You are given a simple undirected graph G with N vertices and M edges (a simple graph does not contain self-loops or multi-edges). For i = 1, 2, \ldots, M, the i-th edge connects vertex u_i and vertex v_i.

Print the number of pairs of integers (u, v) that satisfy 1 \leq u \lt v \leq N and both of the following conditions.

  • The graph G does not have an edge connecting vertex u and vertex v.
  • Adding an edge connecting vertex u and vertex v in the graph G results in a bipartite graph.
What is a bipartite graph?

An undirected graph is said to be bipartite if and only if one can paint each vertex black or white to satisfy the following condition.

  • No edge connects vertices painted in the same color.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min \lbrace 2 \times 10^5, N(N-1)/2 \rbrace
  • 1 \leq u_i, v_i \leq N
  • The graph G is simple.
  • All values in the input 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 answer.


Sample Input 1

5 4
4 2
3 1
5 2
3 2

Sample Output 1

2

We have two pairs of integers (u, v) that satisfy the conditions in the problem statement: (1, 4) and (1, 5). Thus, you should print 2.
The other pairs do not satisfy the conditions. For instance, for (1, 3), the graph G has an edge connecting vertex 1 and vertex 3; for (4, 5), adding an edge connecting vertex 4 and vertex 5 in the graph G does not result in a bipartite graph.


Sample Input 2

4 3
3 1
3 2
1 2

Sample Output 2

0

Note that the given graph may not be bipartite or connected.


Sample Input 3

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

Sample Output 3

9
H - Takahashi is Slime 2

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

配点 : 450

問題文

H 行横 W 列のマス目があります。 上から i 行目 (1\leq i\leq H)、左から j 列目 (1\leq j\leq W) のマスをマス (i,j) と呼ぶことにします。

はじめ、マス (i,j) には強さ S _ {i,j} のスライムがおり、マス (P,Q) にいるスライムが高橋くんです。

高橋くんが以下の行動を好きな回数(0 回でもよい)行ったあとの、高橋くんの強さとしてありえる最大値を求めてください。

  • 高橋くんに隣接するスライムのうち、強さが高橋くんの強さの \dfrac1X未満のものを選んで吸収する。 その結果、吸収されたスライムは消滅し、高橋君の強さは吸収したスライムの強さだけ増加する。

上記の行動の際、スライムが吸収され消滅したことで生じた隙間は直ちに高橋くんによって埋められ、消滅したスライムに隣接していたスライム(それらが存在すれば)は新たに高橋くんと隣接します(入出力例1の説明も参照してください)。

制約

  • 1\leq H,W\leq500
  • 1\leq P\leq H
  • 1\leq Q\leq W
  • 1\leq X\leq10^9
  • 1\leq S _ {i,j}\leq10^{12}
  • 入力はすべて整数

入力

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

H W X 
P Q
S _ {1,1} S _ {1,2} \ldots S _ {1,W}
S _ {2,1} S _ {2,2} \ldots S _ {2,W}
\vdots
S _ {H,1} S _ {H,2} \ldots S _ {H,W}

出力

高橋くんが行動を行ったあとの高橋くんの強さとしてありえる最大値を出力せよ。


入力例 1

3 3 2
2 2
14 6 9
4 9 20
17 15 7

出力例 1

28

はじめ、それぞれのマスにいるスライムの強さは以下の図のようになっています。

例えば、高橋くんは次のように行動を行うことができます。

  • マス (2,1) にいるスライムを吸収する。高橋くんの強さは 9+4=13 となり、新たにマス (1,1) のスライムとマス (3,1) のスライムが高橋くんと隣接する。
  • マス (1,2) にいるスライムを吸収する。高橋くんの強さは 13+6=19 となり、新たにマス (1,3) のスライムが高橋くんと隣接する。
  • マス (1,3) にいるスライムを吸収する。高橋くんの強さは 19+9=28 となる。

以上の行動を行ったあと、高橋くんの強さは 28 となります。

高橋くんがどのように行動を行っても、高橋くんの強さを 28 より大きくすることはできないため、28 を出力してください。

高橋くんの強さの \dfrac12 倍未満のスライムしか吸収できないことに注意してください。 例えば、上図の右側の状態からマス (1,1) にいるスライムを吸収することはできません。


入力例 2

3 4 1
1 1
5 10 1 1
10 1 1 1
1 1 1 1

出力例 2

5

高橋くんはどのスライムも吸収できません。


入力例 3

8 10 2
1 5
388 130 971 202 487 924 247 286 237 316
117 166 918 106 336 928 493 391 235 398
124 280 425 955 212 988 227 222 307 226
336 302 478 246 950 368 291 236 170 101
370 200 204 141 287 410 388 314 205 460
291 104 348 337 404 399 416 263 415 339
105 420 302 334 231 481 466 366 401 452
119 432 292 403 371 417 351 231 482 184

出力例 3

1343

Score : 450 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the cell at the i-th row (1\leq i\leq H) from the top and j-th column (1\leq j\leq W) from the left.

Initially, there is a slime with strength S _ {i,j} in cell (i,j), and Takahashi is the slime in the cell (P,Q).

Find the maximum possible strength of Takahashi after performing the following action any number of times (possibly zero):

  • Among the slimes adjacent to him, choose one whose strength is strictly less than \dfrac{1}{X} times his strength and absorb it. As a result, the absorbed slime disappears, and Takahashi's strength increases by the strength of the absorbed slime.

When performing the above action, the gap left by the disappeared slime is immediately filled by Takahashi, and the slimes that were adjacent to the disappeared one (if any) become newly adjacent to Takahashi (refer to the explanation in sample 1).

Constraints

  • 1\leq H,W\leq500
  • 1\leq P\leq H
  • 1\leq Q\leq W
  • 1\leq X\leq10^9
  • 1\leq S _ {i,j}\leq10^{12}
  • All input values are integers.

Input

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

H W X 
P Q
S _ {1,1} S _ {1,2} \ldots S _ {1,W}
S _ {2,1} S _ {2,2} \ldots S _ {2,W}
\vdots
S _ {H,1} S _ {H,2} \ldots S _ {H,W}

Output

Print the maximum possible strength of Takahashi after performing the action.


Sample Input 1

3 3 2
2 2
14 6 9
4 9 20
17 15 7

Sample Output 1

28

Initially, the strength of the slime in each cell is as follows:

For example, Takahashi can act as follows:

  • Absorb the slime in cell (2,1). His strength becomes 9+4=13, and the slimes in cells (1,1) and (3,1) become newly adjacent to him.
  • Absorb the slime in cell (1,2). His strength becomes 13+6=19, and the slime in cell (1,3) becomes newly adjacent to him.
  • Absorb the slime in cell (1,3). His strength becomes 19+9=28.

After these actions, his strength is 28.

No matter how he acts, it is impossible to get a strength greater than 28, so print 28.

Note that Takahashi can only absorb slimes whose strength is strictly less than half of his strength. For example, in the figure on the right above, he cannot absorb the slime in cell (1,1).


Sample Input 2

3 4 1
1 1
5 10 1 1
10 1 1 1
1 1 1 1

Sample Output 2

5

He cannot absorb any slimes.


Sample Input 3

8 10 2
1 5
388 130 971 202 487 924 247 286 237 316
117 166 918 106 336 928 493 391 235 398
124 280 425 955 212 988 227 222 307 226
336 302 478 246 950 368 291 236 170 101
370 200 204 141 287 410 388 314 205 460
291 104 348 337 404 399 416 263 415 339
105 420 302 334 231 481 466 366 401 452
119 432 292 403 371 417 351 231 482 184

Sample Output 3

1343
I - Oddly Similar

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

配点 : 550

問題文

N 個の長さ M の数列 A_1, A_2, \ldots, A_N があります。i 番目の数列は M 個の整数 A_{i,1}, A_{i,2}, \ldots, A_{i,M} で表されます。

それぞれの長さが M の数列 X,Y について、X_i = Y_i となるような i(1 \leq i \leq M) の個数が奇数であるときに、XY は似ていると言います。

1 \leq i < j \leq N を満たす整数の組 (i,j) のうち、A_iA_j が似ているものの個数を求めてください。

制約

  • 1 \leq N \leq 2000
  • 1 \leq M \leq 2000
  • 1 \leq A_{i,j} \leq 999
  • 入力は全て整数である。

入力

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

N M
A_{1,1} A_{1,2} \ldots A_{1,M}
A_{2,1} A_{2,2} \ldots A_{2,M}
\vdots
A_{N,1} A_{N,2} \ldots A_{N,M}

出力

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


入力例 1

3 3
1 2 3
1 3 4
2 3 4

出力例 1

1

(i,j) = (1,2) は条件を満たします。なぜならば、A_{1,k} = A_{2,k} となるような kk=11 個だけだからです。

(i,j) = (1,3) ,(2,3) は条件を満たさないため、条件を満たす (i,j) の組は (1,2) だけです。


入力例 2

6 5
8 27 27 10 24
27 8 2 4 5
15 27 26 17 24
27 27 27 27 27
27 7 22 11 27
19 27 27 27 27

出力例 2

5

Score: 550 points

Problem Statement

There are N sequences of length M, denoted as A_1, A_2, \ldots, A_N. The i-th sequence is represented by M integers A_{i,1}, A_{i,2}, \ldots, A_{i,M}.

Two sequences X and Y of length M are said to be similar if and only if the number of indices i (1 \leq i \leq M) such that X_i = Y_i is odd.

Find the number of pairs of integers (i,j) satisfying 1 \leq i < j \leq N such that A_i and A_j are similar.

Constraints

  • 1 \leq N \leq 2000
  • 1 \leq M \leq 2000
  • 1 \leq A_{i,j} \leq 999
  • All input values are integers.

Input

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

N M
A_{1,1} A_{1,2} \ldots A_{1,M}
A_{2,1} A_{2,2} \ldots A_{2,M}
\vdots
A_{N,1} A_{N,2} \ldots A_{N,M}

Output

Print the answer as an integer.


Sample Input 1

3 3
1 2 3
1 3 4
2 3 4

Sample Output 1

1

The pair (i,j) = (1,2) satisfies the condition because there is only one index k such that A_{1,k} = A_{2,k}, which is k=1.

The pairs (i,j) = (1,3), (2,3) do not satisfy the condition, making (1,2) the only pair that does.


Sample Input 2

6 5
8 27 27 10 24
27 8 2 4 5
15 27 26 17 24
27 27 27 27 27
27 7 22 11 27
19 27 27 27 27

Sample Output 2

5