A. Exam
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

Input

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

Output

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.

In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1.

If there are several possible answers, output any of them.

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

题意:给你n个数 1~n 问你最多选择多少个数 排列起来 使得相邻的两个数字是不连续的
题解:特判1~4 其余的插空排列
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<set>
11 #define ll __int64
12 using namespace std;
13 int n;
14 int a[5005];
15 int main()
16 {
17     scanf("%d",&n);
18     if(n==1||n==2){
19         printf("1\n1\n");
20         return 0;
21         }
22     if(n==3){
23         printf("2\n1 3\n");
24         return 0;
25     }
26     if(n==4){
27         printf("4\n3 1 4 2\n");
28         return 0;
29     }
30     int jishu=0;
31     if(n%2==1)
32         jishu=n/2+1;
33     else
34         jishu=n/2;
35     int chu=1;
36     for(int i=1;i<=jishu;i++){
37          a[2*i-1]=chu;
38          chu++;
39     }
40     for(int i=1;i<=(n-jishu);i++){
41          a[2*i]=chu;
42          chu++;
43     }
44     printf("%d\n",n);
45     for(int i=1;i<=n ;i++)
46         printf("%d ",a[i]);
47     return  0;
48 }

 

B. Covered Path
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

Input

The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

It is guaranteed that there is a way to complete the segment so that:

  • the speed in the first second equals v1,
  • the speed in the last second equals v2,
  • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
Output

Print the maximum possible length of the path segment in meters.

Examples
Input
5 6
4 2
Output
26
Input
10 10
10 0
Output
100
Note

In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.

In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.

 1 #include<bits/stdc++.h>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<queue>
 6 #include<stack>
 7 #include<vector>
 8 #include<map>
 9 #include<algorithm>
10 #define ll __int64
11 #define mod 1e9+7
12 #define PI acos(-1.0)
13 using namespace std;
14 int v1,v2;
15 int t,d;
16 int ans=0;
17 int minx;
18 int main()
19 {
20     scanf("%d %d",&v1,&v2);
21     scanf("%d %d",&t,&d);
22     int a=v1;
23     //ans=0;
24     int b=v2+d*(t-1);
25     for(int i=1;i<=t;i++)
26     {
27         ans=ans+min(a,b);
28         a+=d;
29         b-=d;
30     }
31     cout<<ans<<endl;
32     return 0;
33 }

 

C. Polycarpus' Dice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.

Input

The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.

Output

Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.

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

In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.

In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.

In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<set>
11 #define ll __int64
12 using namespace std;
13 ll A;
14 int n;
15 ll a[200005];
16 ll l[200005];
17 ll r[200005];
18 ll ans[200005];
19 int main()
20 {
21     scanf("%d %I64d",&n,&A);
22     for(int i=1;i<=n;i++)
23         scanf("%I64d",&a[i]);
24     l[0]=0;
25     l[n+1]=0;
26     for(int i=1;i<=n;i++)
27         l[i]=l[i-1]+a[i];
28     for(int i=n;i>=1;i--)
29         r[i]=r[i+1]+a[i];
30     ll low,high;
31     for(int i=1;i<=n;i++)
32     {
33         low=a[i];
34         high=0;
35         low=min(low,min(a[i],A-(min(A-1,l[i-1]+r[i+1]))));
36         high=max(high,min(a[i],A-(n-1)));
37         ans[i]=a[i]-(high-low+1);
38     }
39     for(int i=1;i<=n;i++)
40         printf("%I64d ",ans[i]);
41 
42     return 0;
43 }

 

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

On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in stayed in CTOP until the end of the day and never left.

At any time any three students could join together and start participating in a team contest, which lasted until the end of the day. The team did not distract from the contest for a minute, so when another student came in and greeted those who were present, he did not shake hands with the members of the contest writing team. Each team consisted of exactly three students, and each student could not become a member of more than one team. Different teams could start writing contest at different times.

Given how many present people shook the hands of each student, get a possible order in which the students could have come to CTOP. If such an order does not exist, then print that this is impossible.

Please note that some students could work independently until the end of the day, without participating in a team contest.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.

Output

If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the j-th student. If there are multiple answers, print any of them.

If the sought order of students doesn't exist, in a single line print "Impossible".

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

In the first sample from the statement the order of events could be as follows:

  • student 4 comes in (a4 = 0), he has no one to greet;
  • student 5 comes in (a5 = 1), he shakes hands with student 4;
  • student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5);
  • student 3 comes in (a3 = 3), he shakes hands with three students (students 4, 5, 1);
  • students 4, 5, 3 form a team and start writing a contest;
  • student 2 comes in (a2 = 1), he shakes hands with one student (number 1).

In the second sample from the statement the order of events could be as follows:

  • student 7 comes in (a7 = 0), he has nobody to greet;
  • student 5 comes in (a5 = 1), he shakes hands with student 7;
  • student 2 comes in (a2 = 2), he shakes hands with two students (students 7, 5);
  • students 7, 5, 2 form a team and start writing a contest;
  • student 1 comes in(a1 = 0), he has no one to greet (everyone is busy with the contest);
  • student 6 comes in (a6 = 1), he shakes hands with student 1;
  • student 8 comes in (a8 = 2), he shakes hands with two students (students 1, 6);
  • student 3 comes in (a3 = 3), he shakes hands with three students (students 1, 6, 8);
  • student 4 comes in (a4 = 4), he shakes hands with four students (students 1, 6, 8, 3);
  • students 8, 3, 4 form a team and start writing a contest;
  • student 9 comes in (a9 = 2), he shakes hands with two students (students 1, 6).

In the third sample from the statement the order of events is restored unambiguously:

  • student 1 comes in (a1 = 0), he has no one to greet;
  • student 3 comes in (or student 4) (a3 = a4 = 1), he shakes hands with student 1;
  • student 2 comes in (a2 = 2), he shakes hands with two students (students 1, 3 (or 4));
  • the remaining student 4 (or student 3), must shake one student's hand (a3 = a4 = 1) but it is impossible as there are only two scenarios: either a team formed and he doesn't greet anyone, or he greets all the three present people who work individually.
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<set>
11 #define ll __int64
12 using namespace std;
13 int n;
14 vector<int> ve[200005];
15 int ans[200005];
16 int main()
17 {
18     scanf("%d",&n);
19     int exm;
20     for(int i=1;i<=n;i++){
21      scanf("%d",&exm);
22      ve[exm].push_back(i);
23     }
24     int top=0;
25     int now=0;
26     while(top<n)
27     {
28         while(ve[now].size()==0)
29         {
30             now-=3;
31             if(now<0){
32                 printf("Impossible\n");
33                 return 0;
34             }
35         }
36         ans[++top]=ve[now].back();
37         ve[now].pop_back();
38         now++;
39     }
40     printf("Possible\n");
41     for(int i=1;i<=n;i++){
42         printf("%d ",ans[i]);
43     }
44     return 0;
45 }