A. Fraction
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).

During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to ninstead of the expected decimal notation.

Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction  such that sum of its numerator and denominator equals n. Help Petya deal with this problem.

Input

In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.

Output

Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.

Examples
input
3
output
1 2
input
4
output
1 3
input
12
output
5 7

求一小于1的 分子分母不可约的分数中的最大。
#include<bits/stdc++.h>
using namespace std;

bool f(const int m,const int n) {
	int d1,d2,d3=1;
	if(m<=n) {                    //将小数放到d1中
		d1=m;
		d2=n;
	} else {
		d1=n;
		d2=m;
	}
	while(d3!=0) {
		d3=d2%d1;
		d2=d1;
		d1=d3;
	}

	if(d2==1)return 1;
	else return 0;

}

int main() {
	int n;
	while(cin>>n) {
		int fenzi;
		for(int i=1; i<=n; i++) {
			fenzi = n-i;
			if(fenzi%i==0)continue;
			if(f(fenzi,i)&&fenzi<i) {
				cout<<fenzi<<" "<<i<<endl;
				break;
			}
		}

	}
	return 0;
}


B. Maxim Buys an Apartment
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.

Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.

Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.

Input

The only line of the input contains two integers: n and k (1 ≤ n ≤ 1090 ≤ k ≤ n).

Output

Print the minimum possible and the maximum possible number of apartments good for Maxim.

Example
input
6 3
output
1 3
Note

In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 12 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 13 and5 were inhabited. In this case all other apartments: 24 and 6 are good.


n个房子 k个已经有人 买房子的时候旁边两间至少有一间已经有人买 问最多和最少的购房选择。分段讨论即可。

#include<bits/stdc++.h>
using namespace std;

int main(){
	long long n,k;
	while(cin>>n>>k){
		int s = n-k;
		if(k==0)cout<<"0 0"<<endl;
		else if(k==n){
			cout<<"0 0"<<endl;	
		}
		else if(k*2<=s){
			cout<<"1 "<<k*2<<endl;	
		}
		else if(s>=k+1){
			cout<<"1 "<<s<<endl;	
		}
		else{
			cout<<"1 "<<s<<endl;
		}
		
	}
	return 0;	
}



C. Planning
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.

Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created.

All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.

Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 107), here ci is the cost of delaying the i-th flight for one minute.

Output

The first line must contain the minimum possible total cost of delaying the flights.

The second line must contain n different integers t1, t2, ..., tn (k + 1 ≤ ti ≤ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.

Example
input
5 2
4 2 1 10 2
output
20
3 6 7 4 5 
Note

Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.

However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20burles.


每个航班都有一个滞后时间代价,求一个新的排列顺序,使得delay的代价的差的和最小。

他么的又忘了longlong强转了...


#include<bits/stdc++.h>
using namespace std;

struct aa {
	long long  c;
	long long poss;
	long long pos;
} a[300005];

bool cmp(aa x , aa y) {
	if(x.c!=y.c)	return x.c>y.c;
	else if(x.c==y.c&&x.pos!=y.pos)return x.pos>y.pos;
}

bool cmp1(aa x , aa y) {
	if(x.pos!=y.pos)	return x.pos<y.pos;
}

int main() {
	long long n,k;
	while(cin>>n>>k) {
		for(int i=1; i<=n; i++) {
			cin>>a[i].c;
			a[i].pos=i;
		}
		sort(a+1,a+n+1,cmp);
		long long sum =0;
		set <long long> res;
		set <long long> ::iterator x;
		for(int i =k+1; i<=k+n+1; i++)
			res.insert(i);
		for(int i =1; i<=n; i++) {
			x = res.lower_bound(a[i].pos);
			long long temp = *x;
			a[i].poss = temp;
			res.erase(temp);
			sum+=a[i].c*((temp-a[i].pos));
		}
		sort(a+1,a+n+1,cmp1);
		cout<<sum<<endl;
		for(int i=1; i<n; i++) {
			cout<<a[i].poss<<" ";
		}
		cout<<a[n].poss<<endl;
	}
	return 0;
}