Petya is a big fan of mathematics, esecially 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 n instead 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
3
1 2
4
1 3
12
5 7
1 #include <iostream> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 int n,b; 7 cin>>n; 8 9 for(int i=n/2;i>=1;--i) 10 { 11 b=n-i; 12 int w=0; 13 for(int j=2;j<=i;j++) 14 { 15 if(b%j==0&&i%j==0) 16 { 17 w=1; 18 break; 19 } 20 21 } 22 if(w==0) 23 { 24 cout<<i<<" "<<b; 25 return 0; 26 } 27 } 28 cout<<"1 "<<n-1; 29 return 0; 30 }
B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to 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 ≤ 109, 0 ≤ k ≤ n).
Output
Print the minimum possible and the maximum possible number of apartments good for Maxim.
Example
6 3
1 3
Note
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 long long n,k; 6 cin>>n>>k; 7 if(k==0||k==n) 8 { 9 cout<<"0 0"; 10 return 0; 11 } 12 else 13 { 14 long long t=3*k,w=n-k; 15 if(t<=n) 16 cout<<"1 "<<2*k; 17 else 18 cout<<"1 "<<w; 19 } 20 return 0; 21 }
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
5 2
4 2 1 10 2
3 6 7 4 5
E
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.
Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).
Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?
Peter is pretty good at math, but now he asks you to help.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.
The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.
Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
Examples
3
1 2 3
2
1
1
5
1 1 5 1 1
2
2
2
2
2
Note
In the first sample test:
In Peter‘s first test, there‘s only one cycle with 1 vertex. First player cannot make a move and loses.
In his second test, there‘s one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can‘t make any move and loses.
In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1, 1, 2, 2 vertices. Second player‘s only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size 1 and wins.
In the second sample test:
Having cycles of size 1 is like not having them (because no one can make a move on them).
In Peter‘s third test: There a cycle of size 5 (others don‘t matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2 and 3.
- If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player‘s only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can‘t make any move and loses.
- If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins.
1 #include <iostream> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 int n,a[100005]; 7 cin>>n; 8 int sum=0; 9 for(int i=0;i<n;i++) 10 { 11 cin>>a[i]; 12 sum+=a[i]-1; 13 if(sum%2!=0) 14 cout<<"1"<<endl; 15 else 16 cout<<"2"<<endl; 17 } 18 return 0; 19 }