Codeforces Round #445 (Div. 2 ABC

A. ACM ICPC

In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.

After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.

Input

The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants

Output

Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

Examples
Input
1 3 2 1 2 1
Output
YES
Input
1 1 1 1 1 99
Output
NO
Note

In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.

In the second sample, score of participant number 6 is too high: his team score will be definitely greater.

求是否存在三个数只和等于另外三个数之和

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a[7];
 4 int main() {
 5     int sum = 0;
 6     for(int i = 0; i < 6; i ++) cin >> a[i], sum += a[i];
 7     if(sum&1) return 0*printf("NO\n");
 8     for(int i = 0; i < 6; i ++) {
 9         for(int j = i+1; j < 6; j++) {
10             for(int k = j+1; k < 6; k ++) {
11                 if(a[i]+a[j]+a[k] == sum/2) return 0*printf("YES\n");
12             }
13         }
14     }
15     printf("NO\n");
16     return 0;
17 }
B. Vlad and Cafes

Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.

First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.

Input

In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.

In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.

Output

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.

Examples
Input
5
1 3 2 1 2
Output
3
Input
6
2 1 2 2 4 1
Output
2
Note

In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.

In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

求最后一个去的咖啡店是哪个?

用map更新  求最小的值所对应的键就行。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 map<int, int> mp;
 4 int main() {
 5     int n, x;
 6     cin >> n;
 7     for(int i = 0; i < n; i ++) cin >> x, mp[x] = i;
 8     map<int, int> :: iterator it = mp.begin();
 9     int INF = 1e9, ans;
10     for(; it != mp.end(); it++) {
11         if((*it).second < INF) {
12             INF = (*it).second;
13             ans = (*it).first;
14         }
15     }
16     cout << ans << endl;
17     return 0;
18 }

 

C. Petya and Catacombs

A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.

Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:

  • If Petya has visited this room before, he writes down the minute he was in this room last time;
  • Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i.

Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0.

At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook.

The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook.

Output

In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.

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

In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.

In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.

求最少数量的房间数;每到一个房间有两种情况

1、已经访问过的,写下上次访问的时间

2、没有访问过的,写下一个小于当前时间的数字。

一开始在 时间0 房间1   由于求最少房间数量,每输入一个数就先判断是否是已经访问过的,否则就是没访问过的。这样求的房间数是最少的。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 map<int, int> mp;
 4 int main() {
 5     int n, x, ans = 1;
 6     cin >> n;
 7     mp[0] = 1;
 8     for(int i = 1; i <= n; i ++) {
 9         cin >>x;
10         if(mp[x]) {
11             mp[i] = mp[x];
12             mp[x] = 0;
13         } else {
14             ans ++;
15             mp[i] = ans;
16         }
17     }
18     cout << ans << endl;
19     return 0;
20 }

 

posted @ 2017-12-11 19:35  starry_sky  阅读(336)  评论(0编辑  收藏  举报