alexjercan/bugnet huggingface dataset:
Sleeping Time

Miki is a high school student.
She has a part time job, so she cannot take enough sleep on weekdays.
She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her.

She is now trying to figure that out with the following algorithm:

Begin with the numbers K, R and L.

She tries to sleep for H=(R+L)/2 hours.

If she feels the time is longer than or equal to the optimal length, then update L with H. Otherwise, update R with H.

After repeating step 2 and 3 for K nights, she decides her optimal sleeping time to be T' = (R+L)/2.

If her feeling is always correct, the steps described above should give her a very accurate optimal sleeping time.
But unfortunately, she makes mistake in step 3 with the probability P.

Assume you know the optimal sleeping time T for Miki.
You have to calculate the probability PP that the absolute difference of T' and T is smaller or equal to E.
It is guaranteed that the answer remains unaffected by the change of E in 10^{-10}.

Input

The input follows the format shown below

K R L

P

E

T

Where the integers 0 \leq K \leq 30, 0 \leq R \leq L \leq 12 are the parameters for the algorithm described above.
The decimal numbers on the following three lines of the input gives the parameters for the estimation. You can assume 0 \leq P \leq 1, 0 \leq E \leq 12, 0 \leq T \leq 12.

Output

Output PP in one line.

The output should not contain an error greater than 10^{-5}.

Sample Input 1

3 0 2
0.10000000000
0.50000000000
1.00000000000

Output for the Sample Input 1

0.900000

Sample Input 2

3 0 2
0.10000000000
0.37499999977
1.00000000000

Output for the Sample Input 2

0.810000

Sample Input 3

3 0 2
0.10000000000
0.00000100000
0.37500000000

Output for the Sample Input 3

0.729000

Sample Input 4

3 0 2
0.20000000000
0.00000100000
0.37500000000

Output for the Sample Input 4

0.512000
On or Off

Saving electricity is very important!

You are in the office represented as R \times C grid that consists of walls and rooms.
It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms.
It takes 1 unit of time for you to move to the next room (that is, the grid adjacent to the current room).
Rooms are so dark that you need to switch on a light when you enter a room.
When you leave the room, you can either leave the light on, or
of course you can switch off the light. Each room keeps consuming electric power while the light is on.

Today you have a lot of tasks across the office.
Tasks are given as a list of coordinates, and they need to be done in the specified order.
To save electricity, you want to finish all the tasks with the minimal amount of electric power.

The problem is not so easy though, because you will consume electricity not only when light is on, but also when you switch on/off the light.

Luckily, you know the cost of power consumption per unit time and also the cost to switch on/off the light for all the rooms in the office.
Besides, you are so smart that you don't need any time to do the tasks themselves.
So please figure out the optimal strategy to minimize the amount of electric power consumed.

After you finished all the tasks, please DO NOT leave the light on at any room.
It's obviously wasting!

Input

The first line of the input contains three positive integers R (0 \lt R \leq 50), C (0 \lt C \leq 50) and M (2 \leq M \leq 1000).
The following R lines, which contain C characters each, describe the layout of the office.
'.' describes a room and '#' describes a wall.

This is followed by three matrices with R rows, C columns each.
Every elements of the matrices are positive integers.
The (r, c) element in the first matrix describes the power consumption per unit of time for the room at the coordinate (r, c).
The (r, c) element in the second matrix and the third matrix describe the cost to turn on the light and the cost to turn off the light, respectively, in the room at the coordinate (r, c).

Each of the last M lines contains two positive integers, which describe the coodinates of the room for you to do the task.

Note that you cannot do the i-th task if any of the j-th task (0 \leq j \leq i) is left undone.

Output

Print one integer that describes the minimal amount of electric power consumed when you finished all the tasks.

Sample Input 1

1 3 2
...
1 1 1
1 2 1
1 1 1
0 0
0 2

Output for the Sample Input 1

7

Sample Input 2

3 3 5
...
.##
..#
1 1 1
1 0 0
1 1 0
3 3 3
3 0 0
3 3 0
5 4 5
4 0 0
5 4 0
1 0
2 1
0 2
2 0
0 0

Output for the Sample Input 2

77

Sample Input 3

5 5 10
#.###
#....
###.#
..#.#
#....
0 12 0 0 0
0 4 3 2 10
0 0 0 99 0
11 13 0 2 0
0 1 1 2 1
0 4 0 0 0
0 13 8 2 4
0 0 0 16 0
1 1 0 2 0
0 2 3 1 99
0 2 0 0 0
0 12 2 12 2
0 0 0 3 0
4 14 0 16 0
0 2 14 2 90
0 1
3 0
4 4
1 4
1 1
4 4
1 1
4 3
3 0
1 4

Output for the Sample Input 3

777
Marathon Match

N people run a marathon.
There are M resting places on the way.
For each resting place, the i-th runner takes a break with probability P_i percent.
When the i-th runner takes a break, he gets rest for T_i time.

The i-th runner runs at constant speed V_i, and
the distance of the marathon is L.

You are requested to compute the probability for each runner to win the first place.
If a runner arrives at the goal with another person at the same time, they are not considered to win the first place.

Input

A dataset is given in the following format:

N M L

P_1 T_1 V_1

P_2 T_2 V_2

...

P_N T_N V_N

The first line of a dataset contains three integers N (1 \leq N \leq 100), M (0 \leq M \leq 50) and L (1 \leq L \leq 100,000).
N is the number of runners.
M is the number of resting places.
L is the distance of the marathon.

Each of the following N lines contains three integers P_i (0 \leq P_i \leq 100), T_i (0 \leq T_i \leq 100) and V_i (0 \leq V_i \leq 100) describing the i-th runner.
P_i is the probability to take a break.
T_i is the time of resting.
V_i is the speed.

Output

For each runner, you should answer the probability of winning.
The i-th line in the output should be the probability that the i-th runner wins the marathon.
Each number in the output should not contain an error greater than 10^{-5}.

Sample Input 1

2 2 50
30 50 1
30 50 2

Output for the Sample Input 1

0.28770000
0.71230000

Sample Input 2

2 1 100
100 100 10
0 100 1

Output for the Sample Input 2

0.00000000
1.00000000

Sample Input 3

3 1 100
50 1 1
50 1 1
50 1 1

Output for the Sample Input 3

0.12500000
0.12500000
0.12500000

Sample Input 4

2 2 50
30 0 1
30 50 2

Output for the Sample Input 4

0.51000000
0.49000000
Reverse Roads

ICP city has an express company whose trucks run from the crossing S to the crossing T.
The president of the company is feeling upset because all the roads in the city are one-way, and are severely congested.
So, he planned to improve the maximum flow (edge disjoint paths) from the crossing S to the crossing T by reversing the traffic direction on some of the roads.

Your task is writing a program to calculate the maximized flow from S to T by reversing some roads, and the list of the reversed roads.

Input

The first line of a data set contains two integers N (2 \leq N \leq 300) and M (0 \leq M \leq {\rm min} (1\,000,\ N(N-1)/2)).
N is the number of crossings in the city and M is the number of roads.

The following M lines describe one-way roads in the city.
The i-th line (1-based) contains two integers X_i and Y_i (1 \leq X_i, Y_i \leq N, X_i \neq Y_i).
X_i is the ID number (1-based) of the starting point of the i-th road and Y_i is that of the terminal point.
The last line contains two integers S and T (1 \leq S, T \leq N, S \neq T, 1-based).

The capacity of each road is 1.

You can assume that i \neq j implies either X_i \neq X_j or Y_i \neq Y_j,
and either X_i \neq Y_j or X_j \neq Y_i.

Output

In the first line, print the maximized flow by reversing some roads.
In the second line, print the number R of the reversed roads.
In each of the following R lines, print the ID number (1-based) of a reversed road.
You may not print the same ID number more than once.

If there are multiple answers which would give us the same flow capacity, you can print any of them.

Sample Input 1

2 1
2 1
2 1

Output for the Sample Input 1

1
0

Sample Input 2

2 1
1 2
2 1

Output for the Sample Input 2

1
1
1

Sample Input 3

3 3
3 2
1 2
3 1
1 3

Output for the Sample Input 3

2
2
1
3
Beautiful Currency

KM country has N kinds of coins and each coin has its value a_i.

The king of the country, Kita_masa, thought that the current currency system is poor,
and he decided to make it beautiful by changing the values of some (possibly no) coins.

A currency system is called beautiful
if each coin has an integer value and the (i+1)-th smallest value is divisible by the i-th smallest value for all i (1 \leq i \leq N-1).

For example, the set {1, 5, 10, 50, 100, 500} is considered as a beautiful system,
while the set {1, 5, 10, 25, 50, 100} is NOT,
because 25 is not divisible by 10.

Since changing the currency system may confuse citizens,
the king, Kita_masa, wants to minimize the maximum value of the confusion ratios.
Here, the confusion ratio for the change in the i-th coin is defined as |a_i - b_i| / a_i,
where a_i and b_i is the value of i-th coin before and after the structure changes, respectively.

Note that Kita_masa can change the value of each existing coin,
but he cannot introduce new coins nor eliminate existing coins.
After the modification, the values of two or more coins may coincide.

Input

Each dataset contains two lines.
The first line contains a single integer, N,
and the second line contains N integers, {a_i}.

You may assume the following constraints:

1 \leq N \leq 20

1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5

Output

Output one number that represents the minimum of the maximum value of the confusion ratios.
The value may be printed with an arbitrary number of decimal digits,
but may not contain an absolute error greater than or equal to 10^{-8}.

Sample Input 1

3
6 11 12

Output for the Sample Input 1

0.090909090909

Sample Input 2

3
6 11 24

Output for the Sample Input 2

0.090909090909

Sample Input 3

3
6 11 30

Output for the Sample Input 3

0.166666666667
Rabbit Party

A rabbit Taro decided to hold a party and invite some friends as guests.
He has n rabbit friends, and m pairs of rabbits are also friends with each other.

Friendliness of each pair is expressed with a positive integer.
If two rabbits are not friends, their friendliness is assumed to be 0.

When a rabbit is invited to the party, his satisfaction score is defined as the minimal friendliness with any other guests.
The satisfaction of the party itself is defined as the sum of satisfaction score for all the guests.

To maximize satisfaction scores for the party, who should Taro invite?
Write a program to calculate the maximal possible satisfaction score for the party.

Input

The first line of the input contains two integers, n and m (1 \leq n \leq 100, 0 \leq m \leq 100).
The rabbits are numbered from 1 to n.

Each of the following m lines has three integers, u, v and f.
u and v (1 \leq u, v \leq n, u \neq v, 1 \leq f \leq 1,000,000) stands for the rabbits' number, and f stands for their friendliness.

You may assume that the friendliness of a pair of rabbits will be given at most once.

Output

Output the maximal possible satisfaction score of the party in a line.

Sample Input 1

3 3
1 2 3
2 3 1
3 1 2

Output for the Sample Input 1

6

Sample Input 2

2 1
1 2 5

Output for the Sample Input 2

10

Sample Input 3

1 0

Output for the Sample Input 3

0

Sample Input 4

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

Output for the Sample Input 4

16
Palindrome Generator

A palidrome craftsperson starts to work in the early morning,
with the clear air allowing him to polish up his palindromes.

On this morning, he is making his pieces to submit to the International Contest for Palindrome Craftspeople.

By the way, in order to make palindromes, he uses a special dictionary which contains a set of words and a set of ordered pairs of the words.
Any words and any ordered pairs of consecutive words in his palindromes must appear in the dictionary.

We already have his dictionary, so let's estimate how long a palindrome he can make.

Input

The first line in the data set consists of two integers N (1 \leq N \leq 100) and M (0 \leq M \leq 1\,000).
N describes the number of words in the dictionary and M describes the number of ordered pairs of words.

The following N lines describe the words he can use.
The i-th line (1-based) contains the word i, which consists of only lower-case letters and whose length is between 1 and 10, inclusive.

The following M lines describe the ordered pairs of consecutive words he can use.
The j-th line (1-based) contains two integers X_j and Y_j (1 \leq X_j, Y_j \leq N).
X_j describes the (1-based) index of the former word in the palindrome and Y_j describes that of the latter word.

Output

Print the maximal length of the possible palindrome in a line.
If he can make no palidromes, print "0".
If he can make arbitrary long palindromes, print "-1".

Sample Input 1

2 2
ab
ba
1 1
1 2

Output for the Sample Input 1

4

Sample Input 2

2 2
ab
ba
1 1
2 2

Output for the Sample Input 2

0

Sample Input 3

2 2
ab
a
1 1
1 2

Output for the Sample Input 3

-1
White Bird

Angry Birds is a mobile game of a big craze all over the world.
You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver.

You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb.
The white bird follows a parabolic trajectory from the initial position,
and it can vertically drop egg bombs on the way.

In order to make it easy to solve, the following conditions hold for the stages.

N obstacles are put on the stage.

Each obstacle is a rectangle whose sides are parallel to the coordinate axes.

The pig is put on the point (X, Y).

You can launch the white bird in any direction at an initial velocity V from the origin.

If the white bird collides with an obstacle, it becomes unable to drop egg bombs.

If the egg bomb collides with an obstacle, the egg bomb is vanished.

The acceleration of gravity is 9.8 {\rm m/s^2}.
Gravity exerts a force on the objects in the decreasing direction of y-coordinate.

Input

A dataset follows the format shown below:

N V X Y

L_1 B_1 R_1 T_1

...

L_N B_N R_N T_N

All inputs are integer.

N: the number of obstacles

V: the initial speed of the white bird

X, Y: the position of the pig

(0 \leq N \leq 50, 0 \leq V \leq 50, 0 \leq X, Y \leq 300, X \neq 0)

for 1 \leq i \leq N,

L_i: the x-coordinate of the left side of the i-th obstacle

B_i: the y-coordinate of the bottom side of the i-th obstacle

R_i: the x-coordinate of the right side of the i-th obstacle

T_i: the y-coordinate of the top side of the i-th obstacle

(0 \leq L_i, B_i, R_i, T_i \leq 300)

It is guaranteed that the answer remains unaffected by a change of L_i, B_i, R_i and T_i in 10^{-6}.

Output

Yes/No

You should answer whether the white bird can drop an egg bomb toward the pig.

Sample Input 1

0 7 3 1

Output for the Sample Input 1

Yes

Sample Input 2

1 7 3 1
1 1 2 2

Output for the Sample Input 2

No

Sample Input 3

1 7 2 2
0 1 1 2

Output for the Sample Input 3

No
Vector Compression

You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors.
Since the result may become very large, you are thinking of
compressing it. Fortunately you already have a good compression method
for vectors with small absolute values, all you have to do is to
preprocess the vectors and make them small.

You can record the set of vectors in any order you like.
Let's assume you process them in the order v_1, v_2,..., v_M.
Each vector v_i is recorded either as is, or as a difference vector.
When it is recorded as a difference,
you can arbitrarily pick up an already chosen vector v_j (j<i) and a real value r.
Then the actual vector value recorded is (v_i - r v_j).
The values of r and j do not affect the compression ratio so much, so you don't have to care about them.

Given a set of vectors,
your task is to write a program that calculates the minimum sum of the squared length of the recorded vectors.

Input

The input is like the following style.

N M

v_{1,1} v_{1,2} ... v_{1,N}

...

v_{M,1} v_{M,2} ... v_{M,N}

The first line contains two integers N and M (1 \leq N, M \leq 100),
where N is the dimension of each vector,
and M is the number of the vectors.
Each of the following M lines contains N floating point values v_{i,j} (-1.0 \leq v_{i,j} \leq 1.0)
which represents the j-th element value of the i-th vector.

Output

Output the minimum sum of the squared length of the recorded vectors.
The output should not contain an absolute error greater than 10^{-6}.

Sample Input 1

2 3
1.0 1.0
-1.0 0.0
0.5 0.5

Output for the Sample Input 1

1.0

Sample Input 2

1 1
1.0

Output for the Sample Input 2

1.0

Sample Input 3

4 3
1.0 1.0 0.0 0.0
-1.0 0.0 -1.0 0.0
0.5 0.5 0.5 0.5

Output for the Sample Input 3

3.0
〜魔女からこの世界を守るためキュゥべえと共に戦う 5 人の魔法少女達の物語〜

問題 A

問題文

薔薇園の魔女 GERTRUD は幅 W メートル，高さ H メートルの長方形の庭でバラを育てている．庭は一辺 1 メートルの正方形で区切られており，W\times H のブロックに分けられている．各ブロックはバラが育てられているか育てられていないかのどちらかである．

ただ驚くべきことに，この庭で育てられているバラはブロックを越えて絡み合い 1 つの生命体となっている．この生命体は辺を共有しているブロック間を越えて絡み合うことができ，どこかある 1 点を共有していれば同じ生命体となる．

巴マミは庭の左下の角から直線に必殺技「ティロ・フィナーレ」で巨大な銃を撃ち，その弾丸が通る直線上でその生命体を分割した時，生命体が出来る限り多くの分割数に分断されるようにすることによりダメージを与えたい．ティロ・フィナーレは最大でこの生物を何分割できるか求めよ．

入力形式

入力は以下の形式で与えられる．

H\ W\\
f_{11} f_{12} ... f_{1W}\\
f_{21} f_{22} ... f_{2W}\\
...\\
f_{H1} f_{H2} ... f_{HW}\\

H は庭の高さ，W は庭の幅を表す．

f_{ij} は庭の各ブロックを表す文字であり，上から i 行目，左から j 列目のブロックの状態を表す．ブロックにバラが育てられている場合は f_{ij} は '#' となり，そうでない場合は '.' となる．

出力形式

生命体を直線で分割する時に，最大でいくつの部分に分割できるかを1行で出力せよ．

制約

1 ≤ H ≤ 600

1 ≤ W ≤ 600

f_{ij}は '#', '.'のいずれかである．

少なくとも 1 つはf_{ij} = '#' となるマス f_{ij} が存在する．

2 つのブロックが辺を共有するとき，それらは隣接していると呼ぶことにする．任意の 2 つの異なる '#' のブロック f_A, f_B に対して，f_A から隣接している '#' のブロックを辿っていって f_B に着くことができる．(すなわち，薔薇のブロックは連結である．)

入力中で 1 行目の行，H 行目の行，1 列目の列，または W 列目の列にあるブロックを盤面の端のブロックと呼ぶことにする．任意の '.' のブロック f_C に対して，f_C から隣接している '.' のブロックを辿っていって，ある '.' の盤面の端のブロックに着くことができる．(すなわち，入力に"空洞"のブロックは存在しない．)

入出力例

入力例 1

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

出力例1

4

このとき以下のように 4 つの部分に分割することができる．

入力例 2

3 3
#.#
###
#.#

出力例 2

3

入力例 3

10 9
.........
.........
####.....
#..#.##..
#..#..#..
#..##.###
#..##...#
##..##.##
###.#..#.
###.####.

出力例 3

6

入力例 4

10 11
###########
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#
#.#.#.#.#.#

出力例 4

7

入力例 5

25 38
...........#...............#..........
...........###..........####..........
...........#####.......####...........
............###############...........
............###############...........
............##############............
.............#############............
............###############...........
...........#################..........
.......#...#################...#......
.......##.##################..##......
........####################.##.......
..........####################........
.........#####..########..#####.......
.......######....#####....######......
......########...#####..########.#....
....#######..#...#####..#..########...
..#########.....#######......#######..
...#######......#######........###....
..####.........#########........###...
...............#########..............
..............##########..............
..............##########..............
...............########...............
...............########...............

出力例 5

8

Problem Setter: Flat35
問題文

お菓子の魔女 CHARLOTTE は巴マミとクッキーゲームを楽しんでいる．クッキーゲームは 8\times 8 の格子状に区切られたテーブルクロスの上にチーズクッキーとチョコレートクッキーを置いて行われる．各格子には高々 1 個のチョコレートクッキーまたはチーズクッキーしか置くことはできない．

お菓子の魔女はチーズクッキーを，巴マミはチョコレートクッキーを交互に置いてゲームを行う．自分のクッキーを置いたあと，そのクッキーから上下左右斜めの各 8 方向について，置くクッキーとすでに置いていた自分のクッキーの間に相手のクッキーのみが直線に並んでいた場合に，その挟まれた相手のクッキーのすべてが自分のクッキーで置き換えられる．クッキーゲームのプレイヤーは自分のターンが回ってきた時，1 つ自分のクッキーを置くことができる．ただし，相手のクッキーを少なくとも 1 つ以上自分のクッキーに置き換えられなければならない．そのような置き場がない場合，自分のターンをパスをしなければならない．

お菓子の魔女も巴マミも考えるのが少々苦手である．そこで，回ってきたターン毎にそのターンの中で置き換えられるクッキーの数を最大化することを考えることにした．巴マミのターンのときに置き換えられるクッキーの数を最大にするようなクッキーを置く場所の候補が複数ある場合は，より上の場所を，それでも複数ある場合はより左の場所を選択することにした．また同様に，お菓子の魔女のターンのときに候補が複数ある場合はより下の場所を，それでも複数ある場合はより右の場所を選択することにした．

テーブルクロスに置かれたクッキーの状態が与えられるので，巴マミからはじめ，彼女たちがそこからクッキーゲームを行い，共に新たなクッキーが置けなくなるまでゲームを続けた時のテーブルクロスの上に置かれたクッキーの状態を求めよ．

入力形式

入力は以下の形式で与えられる．

s_{11} s_{12} ... s_{18}\\
s_{21} s_{22} ... s_{28}\\
...\\
s_{81} s_{82} ... s_{88}\\

s_{ij} はテーブルクロスに置かれたクッキーの初期状態を表す文字で，上から i 行目，左から j 列目の格子の状態を表す．チョコレートクッキーが置かれているときs_{ij}は 'o' であり，チーズクッキーが置かれているときは 'x', 何も置かれていないときは '.' となる．

出力形式

クッキーゲームが行われた後のテーブルクロスの上に置かれたクッキーの状態を，入力形式と同じ形式で出力せよ．

制約

s_{ij} は 'o', 'x', '.' のいずれかである．

入出力例

入力例 1

ooox....
.x......
ooo.....
........
........
........
........
........

出力例1

ooooo...
.o......
ooo.....
...o....
....o...
........
........
........

入力例 2

........
........
........
...ox...
...xo...
........
........
........

出力例 2

xxxxxxxx
xxxooxxx
xxxxooxx
xxxxxxxx
ooxxooox
ooxoooox
oxooooox
ooooooox

入力例 3

........
........
..ooo...
..oxo...
..ooo...
........
........
........

出力例 3

........
........
..ooo...
..ooo...
..ooo...
.....o..
......o.
........

Problem Setter: Flat35
問題文

世の中の少女たちはキュゥべえと契約し願いを叶えてもらい，それとひきかえに魔法少女となる．使う魔法の形・効果は願いに強く影響を受ける．魔法少女さやかちゃんは最近キュゥべえと契約した新米魔法少女である．さやかの願いは「事故のため指が動かなくなり，音楽を演奏するのを諦めていた男の子を助けること」であったので，作る魔方陣は音符が輪の上に並んだ形をしている．

さやかは N 個の音符を持っており，それらを輪の上に並べることによって魔方陣を作る．音符をどのような順番で並べるかは彼女の自由である．魔方陣を作るために精神力が消費され，その量は音符の配置によって以下のように決まる．

まず， M 個の正の整数からなる音楽的美しさ S_1,\ ...,\ S_M が定められている，

各音符は音程を持っており，音程は 1 から M の整数 K_1,\ ...,\ K_N で表される．

音程が a,\ b\ (a≤b) であるような 2 つの音符の間の反発力とは， [(S_a\ +\ ...\ +\ S_b) / L] で定められる量である．ここで，L は入力で与えられる定数であり，実数 x に対して [x] は x を越えない最大の整数を表すものとする．

さやかの消費する精神力は，各2つの隣り合う音符 (N 組存在する) の間の反発力の合計値である．

例えば音楽的美しさがそれぞれ \{100,\ 200,\ 300,\ 400,\ 500\} で，音程が \{1,\ 3,\ 5,\ 4\} である音符をこの順番で並べて魔方陣を作った時，消費される精神力は 37\ (=[(100+200+300)/99]+[(300+400+500)/99]+[(500+400)/99]+[(400+300+200+100)/99]) となる．

使うべき音符の音程の組み合わせと各音程の音楽的美しさが与えられるので，消費される精神力の最小値を求めよ．

入力形式

入力は以下の形式で与えられる．

N\ M\ L\\
K_1\ K_2\ …\ K_N\\
S_1\ S_2\ …\ S_M

N はさやかの持っている音符の数，M は音楽的美しさの値の個数，L は反発力を定めるのに使われる定数である．

K_i は音符の音程を表し，S_j は音楽的美しさを表す．

出力形式

消費される精神力の最小値を 1 行に出力せよ．

制約

3 ≤ N ≤ 2,000

1 ≤ M ≤ 105

1 ≤ L ≤ 105

1 ≤ K_i ≤ M

1 ≤ S_j ≤ 105

入力値は全て整数である．

入出力例

入力例 1

4 5 99
1 4 5 3
100 200 300 400 500

出力例1

37

入力例 2

3 1 99
1 1 1
100

出力例 2

3

Problem Setter: Flat35
問題文

ハコの魔女 H.N.ELLY はとある動画サイトの熱狂的なファンである．ハコの魔女の強さはその時々のその動画サイトからの転送速度に応じて変化するのではないかと美樹さやかは考えた．そこで動画サイトからハコの魔女の持つコンピュータまでの過去の転送速度 (=単位時間あたりのデータの転送量) を調べたい．

初期のインターネットのネットワークの構造とそれ以降のネットワークの構造の変化を表すクエリが与えられるので，各変化について変化した直後の動画サイトからハコの魔女の持つコンピュータまでの転送速度を求めよ．

インターネットは複数の転送装置からなるものと見なし，各々をつなぐ回線は双方向に情報を送ることができ，その転送速度の最大は 1 であるとする．また，ネットワークは常に動画サイトからハコの魔女へ送られるデータの転送速度を最大化するように運ぶものとする．

入力形式

入力は以下の形式で与えられる．

N\ E\ Q\\
F_1\ T_1\\
F_2\ T_2\\
…\\
F_E\ T_E\\
M_1\ A_1\ B_1\\
M_2\ A_2\ B_2\\
...\\
M_Q\ A_Q\ B_Q\\

N は動画サイトとハコの魔女の持つコンピュータを含めた転送装置の数である．番号が 1 である転送装置は動画サイトであり，番号が N である転送装置はハコの魔女の持つコンピュータである．E は初期状態で接続されている転送装置の組み合わせの数であり，Q はインターネットが変化した回数である．初期のインターネットは F_i と T_i が転送速度 1 で双方向に接続されていることを表す．

ネットワークの変化は時系列順に与えられ，j 番目の変化は M_j が 1 であれば A_j,\ B_j 間がつながれたことを表し，M_j が 2 であれば A_j,\ B_j 間の接続が切れたことを表す．

出力形式

各変化の直後における，動画サイトからハコの魔女の持つコンピュータまでの転送速度を出力せよ．

制約

2 \leq N \leq 500

0 \leq E \leq 20,000

1 \leq Q \leq 1,000

1 \leq F_i \leq N,\ 1 \leq T_i \leq N,\ F_i \neq T_i \ (1 \leq i \leq E)

すべての \{F_i, T_i\} のペアは異なる．

1 \leq M_j \leq 2,\ 1 \leq A_j \leq N\ ,\ 1 \leq B_j \leq N\ ,\ A_j \neq B_j (1 \leq j \leq Q)

ネットワークのどの段階においても次のことが成り立つ : どの 2 つの転送装置の間も高々 1 つの回線でしか繋がれていない．
2 つの転送装置の間が既に繋がれている状態でそれらの間を接続するようなクエリが来たり，2 つの転送装置の間が回線で繋がれていない状態でそれらの間の接続を切るようなクエリが来ることはない．

入出力例

入力例 1

2 1 2
1 2
2 1 2
1 2 1

出力例1

0
1

最初の変化の後，ハコの魔女のコンピュータと動画サイトは繋がらなくなっているので転送速度は 0 である．

2 度目の変化の後は両者は直接繋がっており，転送速度は 1 になる．

入力例 2

3 0 4
1 2 3
1 2 1
1 3 1
2 2 3

出力例 2

0
1
2
1

入力例 3

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

出力例 3

1
2
2
2
2
2
2
1

入力例 4

12 38 6
1 2
1 3
1 4
1 5
2 3
2 4
2 5
2 6
2 7
2 8
2 12
3 4
3 5
3 6
3 7
3 8
4 5
4 6
4 7
4 8
5 6
5 7
5 8
6 7
6 8
6 9
6 10
6 12
7 8
7 9
7 10
8 9
8 10
9 10
9 11
9 12
10 11
11 12
2 6 12
2 9 12
1 9 12
1 6 12
2 6 12
1 6 12

出力例 4

3
2
3
4
3
4

Problem Setter: Flat35