Educational Codeforces Round 35 (Rated for Div. 2)

A. Nearest Minimums

You are given an array of n integer numbers a0,?a1,?...,?an?-?1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

Input

The first line contains positive integer n (2?≤?n?≤?105) — size of the given array. The second line contains n integers a0,?a1,?...,?an?-?1 (1?≤?ai?≤?109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Output

Print the only number — distance between two nearest minimums in the array.

Examples

Input

23 3

Output

1

Input

35 6 5

Output

2

Input

92 1 3 5 4 1 2 3 1

Output

3暴力一波
 1 // ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
 2 //
 3
 4 //#include "stdafx.h"
 5 #include<cmath>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11
12 const int INF = 0x3f3f3f3f;
13 const int maxn = (int)3e5;
14
15 int n;
16 struct node {
17     int num, id;
18     bool operator<(const node& i)const {
19         if (num == i.num) return id < i.id;
20         return num < i.num;
21     }
22 }a[maxn];
23
24 int main()
25 {
26     cin >> n;
27     for (int i = 1; i <= n; i++) {
28         int temp;
29         cin >> temp;
30         a[i].id = i;
31         a[i].num = temp;
32     }
33     sort(a + 1, a + n + 1);
34     int ans = INF;
35     if (a[1].num == a[2].num) {
36         for (int i = 2; i <= n; i++) {
37             if (a[i].num != a[1].num) break;
38             else ans = min(ans,abs(a[i].id - a[i - 1].id));
39         }
40     }
41     else {
42         for (int i = 2; i <= n; i++) {
43             if (a[i].num != a[2].num) break;
44             else ans = min(ans,abs(a[i].id - a[1].id));
45         }
46     }
47     cout << ans << endl;
48     return 0;
49 }

B. Two Cakes

It‘s New Year‘s Eve soon, so Ivan decided it‘s high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.

Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:

  1. Each piece of each cake is put on some plate;
  2. Each plate contains at least one piece of cake;
  3. No plate contains pieces of both cakes.

To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.

Help Ivan to calculate this number x!

Input

The first line contains three integers n, a and b (1?≤?a,?b?≤?100, 2?≤?n?≤?a?+?b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.

Output

Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.

Examples

Input

5 2 3

Output

1

Input

4 7 10

Output

3

Note

In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.

In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.

题解:列两个等式,假设a被分成x块,b被分成y块,最小的数为Xmin,则x*Xmin<=a,y*Xmin<=b。所以可知:Xmin=min(a/x,b/y)(x+y=n),剩下的是枚举块数x。

 1 // ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
 2 //
 3
 4 //#include "stdafx.h"
 5 #include<cmath>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11
12 const int INF = 0x3f3f3f3f;
13 const int maxn = (int)3e5;
14
15 int n, a, b;
16
17 int main()
18 {
19     while (cin >> n >> a >> b) {
20         int ans = 0;
21         if (n == a + b) ans = 1;
22         else {
23             for (int i = 1; i < n; i++) ans = max(ans, min(a / i, b / (n - i)));
24         }
25         cout << ans << endl;
26     }
27 }

C. Three Garlands

Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.

When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x?+?ki, x?+?2ki, x?+?3ki and so on.

Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1,?x2,?x3) at least one garland will be lit.

Help Mishka by telling him if it is possible to do this!

Input

The first line contains three integers k1, k2 and k3 (1?≤?ki?≤?1500) — time intervals of the garlands.

Output

If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.

Otherwise, print NO.

Examples

Input

2 2 3

Output

YES

Input

4 2 3

Output

NO

Note

In the first example Mishka can choose x1?=?1, x2?=?2, x3?=?1. The first garland will be lit during seconds 1,?3,?5,?7,?..., the second — 2,?4,?6,?8,?..., which already cover all the seconds after the 2-nd one. It doesn‘t even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1,?4,?7,?10,?..., though.

In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.

题解:靠一种感觉,只有数字1,2,3有用。cnt_1>0||cnt_2>1||cnt_3=3。但是还有一个4、4、2也是符合的。这组值我遗漏了!

 1 // ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
 2 //
 3
 4 #include "stdafx.h"
 5 #include<cmath>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11
12 const int INF = 0x3f3f3f3f;
13 const int maxn = (int)3e5;
14
15 int main()
16 {
17     int d[3], cnt1 = 0, cnt2 = 0, cnt3 = 0;
18     for (int i = 0; i < 3; i++) cin >> d[i];
19     for (int i = 0; i < 3; i++) {
20         if (d[i] == 2) cnt1++;
21         if (d[i] == 3) cnt2++;
22         if (d[i] == 1) cnt3++;
23     }
24     sort(d, d + 3);
25     if (d[0] == 2 && d[1] == 4 && d[2] == 4) cout << "YES" << endl;
26     else if (cnt1 >= 2 || cnt2 == 3 || cnt3 > 0) cout << "YES" << endl;
27     else cout << "NO" << endl;
28 }

D. Inversion Counting

A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i,?j) such that i?>?j and ai?<?aj. For example, a permutation [4,?1,?3,?2] contains 4 inversions: (2,?1), (3,?1), (4,?1), (4,?3).

You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l,?r] of the permutation. For example, if a?=?[1,?2,?3,?4] and a query l?=?2, r?=?4 is applied, then the resulting permutation is [1,?4,?3,?2].

After each query you have to determine whether the number of inversions is odd or even.

Input

The first line contains one integer n (1?≤?n?≤?1500) — the size of the permutation.

The second line contains n integers a1, a2, ..., an (1?≤?ai?≤?n) — the elements of the permutation. These integers are pairwise distinct.

The third line contains one integer m (1?≤?m?≤?2·105) — the number of queries to process.

Then m lines follow, i-th line containing two integers li, ri (1?≤?li?≤?ri?≤?n) denoting that i-th query is to reverse a segment [li,?ri] of the permutation. All queries are performed one after another.

Output

Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise.

Examples

Input

31 2 321 22 3

Output

oddeven

Input

41 2 4 341 11 41 42 3

Output

oddoddoddeven

Note

The first example:

  1. after the first query a?=?[2,?1,?3], inversion: (2,?1);
  2. after the second query a?=?[2,?3,?1], inversions: (3,?1), (3,?2).

题解:学过线性代数的童鞋是否记得一个定理:一个排列中,任意两个元素对换,排列改变奇偶性。具体证明我就不说了。这题完全是这个定理的模板题啊。。。

 1 // ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
 2 //
 3
 4 #include "stdafx.h"
 5 #include<cmath>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11
12 const int INF = 0x3f3f3f3f;
13 const int maxn = 2000;
14
15 int n, m;
16 int a[maxn];
17
18 int main()
19 {
20     while (cin >> n) {
21         int cnt = 0, ans = 0;
22         for (int i = 0; i < n; i++) cin >> a[i];
23         for (int i = 1; i < n; i++)
24             for (int j = 0; j < i; j++) if (a[j] > a[i]) cnt++;
25         bool flag = false;
26         if (cnt % 2) flag = true;
27
28         cin >> m;
29         while(m--){
30             int l, r;
31             cin >> l >> r;
32             ans += (r - l + 1)/2;
33             //cout << ans << endl;
34             if (ans % 2) {
35                 if (flag) cout << "even" << endl;
36                 else cout << "odd" << endl;
37             }
38             else {
39                 if (flag) cout << "odd" << endl;
40                 else cout << "even" << endl;
41             }
42         }
43     }
44
45 }

原文地址:https://www.cnblogs.com/zgglj-com/p/8146622.html

时间: 2024-08-30 09:46:07

Educational Codeforces Round 35 (Rated for Div. 2)的相关文章

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers

原文链接:https://www.cnblogs.com/xwl3109377858/p/11404050.html Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburg

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ? 给你一个有向图,给用最少的颜色给每条边染色,要保证不存在一个环中的所有边都是同一个颜色. [Solution] ? 用拓扑排序判断图中是否存在环,若图中不存在环,则所有边都是同一种颜色.否则,同一个环中,只要用两种颜色就可以满足题目条件,所以总的颜色数就是两种,对于一个环,一定会存在两种边:1.节点号小

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html