diff --git a/617/a.cpp b/617/a.cpp new file mode 100644 index 0000000..a97b7c5 --- /dev/null +++ b/617/a.cpp @@ -0,0 +1,80 @@ +#include + +namespace helpers { + +using namespace std; + +long pow(long base, long exp) { + if (exp == 0) return 1; + long half = pow(base, exp / 2); + if (exp % 2 == 0) return half * half; + return half * half * base; +} + +template +void answer(const T &ans) { + cout << ans << "\n"; +} + +} // namespace helpers + +namespace { + +using namespace std; +using namespace helpers; + +int steps(int distance) { + int count = 0; + + for (auto step : {5, 4, 3, 2, 1}) { + count += distance / step; + distance %= step; + } + + return count; +} + +void solve() { + int d; + cin >> d; + answer(steps(d)); +} + +} // namespace + +// for single test case, comment out for ‹N› test cases +#define SINGLE + +#ifdef TEST + +#include "../.common/cpp/catch_amalgamated.hpp" + +TEST_CASE("examples") { + CHECK(steps(5) == 1); + CHECK(steps(12) == 3); +} + +#else + +int main(void) { + +#ifdef SINGLE + + solve(); + +#else + + // for multiple test cases + int N; + std::cin >> N >> std::ws; + + for (auto i = 0; i < N; ++i) { + solve(); + } + +#endif + + return 0; +} + +#endif diff --git a/617/index.html b/617/index.html new file mode 100644 index 0000000..954bca8 --- /dev/null +++ b/617/index.html @@ -0,0 +1,1035 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Problems - Codeforces + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+
+ + +
+ +
Codeforces Round 340 (Div. 2)
+
+ +
+
+ + + +
+
+ +
+ +
A. Elephant
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.

Input

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.

Output

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

Examples
Input
5
Output
1
Input
12
Output
3
Note

In the first sample the elephant needs to make one step of length 5 to reach the point x.

In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.

+
+ + + + + +
+
+ + +
+ +
B. Chocolate
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.

You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.

Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.

The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Output

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

Examples
Input
3
0 1 0
Output
1
Input
5
1 0 1 0 1
Output
4
Note

In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.

In the second sample you can break the bar in four ways:

10|10|1

1|010|1

10|1|01

1|01|01

+
+ + + + + +
+
+ + +
+ +
C. Watering Flowers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A flowerbed has many flowers and two fountains.

You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.

You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

Input

The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.

Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.

It is guaranteed that all n + 2 points in the input are distinct.

Output

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

Examples
Input
2 -1 0 5 3
0 2
5 2
Output
6
Input
4 0 0 5 0
9 4
8 3
-1 0
1 4
Output
33
Note

The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):

+
+ + + + + +
+
+ + +
+ +
D. Polyline
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.

Input

Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.

Output

Print a single number — the minimum possible number of segments of the polyline.

Examples
Input
1 -1
1 1
1 2
Output
1
Input
-1 -1
-1 3
4 3
Output
2
Input
1 1
2 3
3 2
Output
3
Note

The variant of the polyline in the first sample: The variant of the polyline in the second sample: The variant of the polyline in the third sample:

+
+ + + + + +
+
+ + +
+ +
E. XOR and Favorite Number
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is equal to k.

Input

The first line of the input contains integers n, m and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively.

The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array.

Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.

Output

Print m lines, answer the queries in the order they appear in the input.

Examples
Input
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
Input
5 3 1
1 1 1 1 1
1 5
2 4
1 3
Output
9
4
4
Note

In the first sample the suitable pairs of i and j for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query.

In the second sample xor equals 1 for all subarrays of an odd length.

+
+ + + + + +
+
+ + + +
+
+ + +