Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4 values |
|---|---|---|---|---|---|
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
import java.util.ArrayList;
import java.util.*;
public class Main {
public static void main(String[] args) {
Stack<Integer> s = new Stack();
int a;
Scanner in = new Scanner(System.in);
a=in.nextInt();
int k=-1;
while(a>0){
a--;
k++;
s.push(1);
while(k>0 && s.get(k)!=null && s.get(k-1)!=null && s.get(k) == s.get(k-1)){
s.pop();
int temp = s.pop();
s.push(temp+1);
k--;
}
}
for(int i=0;i<s.size();i++){
System.out.print(s.get(i)+" ");
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, i, foo;
cin >> n;
if (n == 1) {
cout << "1\n";
return 0;
}
stack<int> st, st2;
st.push(1);
for (i = 1; i < n; i++) {
foo = 1;
while (!st.empty() && foo == st.top()) {
foo += 1;
st.pop();
}
st.push(foo);
}
while (!st.empty()) {
st2.push(st.top());
st.pop();
}
while (!st2.empty()) {
cout << st2.top() << " ";
st2.pop();
}
cout << "\n";
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
int n;
int main() {
int i;
scanf("%d", &n);
for (i = 20; i >= 0; i--) {
if (n & (1 << i)) printf("%d ", i + 1);
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class slime {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
List<Integer> slimes = new ArrayList<>();
while (n > 0) {
int a = (int) (Math.log(n) / Math.log(2)) + 1;
slimes.add(a);
n -= Math.pow(2, a-1);
}
String s= "";
for(int a : slimes){
s+= a + " ";
}
System.out.println(s.trim());
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.*;
public class WunderA
{
private static StringTokenizer st;
public static void nextLine(BufferedReader br) throws IOException
{
st = new StringTokenizer(br.readLine());
}
public static int nextInt()
{
return Integer.parseInt(st.nextToken());
}
public static String next()
{
return st.nextToken();
}
public static long nextLong()
{
return Long.parseLong(st.nextToken());
}
public static double nextDouble()
{
return Double.parseDouble(st.nextToken());
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nextLine(br);
int n = nextInt();
for (int i = 20; i >= 0; i--)
{
if (((n >> i) & 1) == 1)
{
System.out.print((i+1) + " ");
}
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
;
vector<int> v;
int counter = 0;
v.push_back(1);
n--;
while (n--) {
v.push_back(1);
counter++;
while (v[v.size() - 1] == v[v.size() - 2]) {
v.pop_back();
v[v.size() - 1] += 1;
}
}
for (auto i : v) cout << i << " ";
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
bool perfectSquare(long double x) {
long double sr = sqrt(x);
return ((sr - floor(sr)) == 0);
}
long long modexp(long long n, long long p, long long c) {
if (p == 0) return 1;
long long ans = 1;
if (p % 2) ans = n % c;
return ((ans) * (modexp((n * n) % c, p / 2, c) % c)) % c;
}
void test_case() {
long long n;
cin >> n;
vector<long long> ans;
long long c = 1;
ans.push_back(1);
long long j = 1;
for (long long i = (1); i < (n); ++i) {
ans.push_back(1);
long long j = ans.size() - 1;
while (j >= 1 and ans[j] == ans[j - 1]) {
ans[j - 1] += 1;
ans.pop_back();
j--;
}
}
for (long long i = (0); i < (ans.size()); ++i) cout << ans[i] << " ";
cout << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) {
test_case();
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
int n;
cin >> n;
while (n > 1) {
int p = 1, k = 1;
while (n >= p * 2) p *= 2, k++;
cout << k << " ";
n -= p;
}
if (n > 0) cout << n;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = input()
x = []
for i in xrange(0,n):
x+=[1]
while(len(x)>=2 and x[-1]==x[-2]):
l1 = x.pop(-1)
l2 = x.pop(-1)
x+=[l1+1]
for i in x:
print i,
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(raw_input())
for i in xrange(20, -1, -1):
if n >> i:
print i + 1,
n -= 1 << i
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
ans = ""
for i in range(32, -1, -1):
if n & (1 << i) is not 0:
ans += str(i + 1)
ans += ' '
print(ans)
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = map(int, list(bin(input())[2:]))
print " ".join(map(str, [len(n)-i for i in xrange(len(n)) if n[i]]))
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | u = input()
i = 1
l = []
while u:
if u & (1 << (i-1)):
l.append(i)
u -= (1 << (i-1))
i += 1
for u in reversed(l): print u, | PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
void solve(bool);
void precalc();
clock_t start;
int main() {
start = clock();
int t = 1;
cout.sync_with_stdio(0);
cin.tie(0);
precalc();
cout.precision(10);
cout << fixed;
int testNum = 1;
while (t--) {
solve(true);
}
cout.flush();
return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
if (!w) return 1 % mod;
if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
return binpow(q * 1LL * q % mod, w / 2, mod);
}
template <typename T>
T gcd(T q, T w) {
while (w) {
q %= w;
swap(q, w);
}
return q;
}
template <typename T>
T lcm(T q, T w) {
return q / gcd(q, w) * w;
}
void precalc() {}
template <typename T>
void relax_min(T& cur, T val) {
cur = min(cur, val);
}
template <typename T>
void relax_max(T& cur, T val) {
cur = max(cur, val);
}
void solve(bool read) {
int n;
cin >> n;
vector<int> res;
for (int i = 0; i < 20; ++i) {
if (n & 1) {
res.push_back(i + 1);
}
n >>= 1;
}
reverse(res.begin(), res.end());
for (int x : res) {
cout << x << " ";
}
cout << endl;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int x[1000000];
int main() {
int n;
while (cin >> n) {
stack<int> st;
while (st.size()) {
st.pop();
}
memset(x, 0, sizeof(x));
for (int i = 0; i < n; i++) {
if (st.size() == 0) {
st.push(1);
} else if (st.top() == 1) {
st.pop();
st.push(2);
} else {
st.push(1);
}
while (st.size() >= 2) {
int num = st.top();
st.pop();
if ((st.top() - num) == 0) {
st.pop();
st.push(num + 1);
} else {
st.push(num);
break;
}
}
}
int num = st.size();
for (int i = 0; i < num; i++) {
x[i] = st.top();
st.pop();
}
cout << x[num - 1];
for (int i = num - 2; i >= 0; i--) {
printf(" %d", x[i]);
}
cout << endl;
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
podokonnik = []
while n > 0:
podokonnik.append(1)
while len(podokonnik) >= 2 and podokonnik[-1] == podokonnik[-2]:
podokonnik[-2] = podokonnik[-2] + 1
podokonnik.pop()
n -= 1
for elem in podokonnik:
print(elem, end=" ")
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | t=int(input())
while t:
for i in range (17):
if 2**i<=t<2**(i+1):
print(i+1,end=' ')
t=t-2**i
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input())
i=1
k=1
a=[]
while i<=n:
if i&n:
a.append(k)
i<<=1
k+=1
for i in range(len(a)-1,-1,-1):
print(a[i],end=' ') | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #IN THE NAME OF GOD
a=int(input())
b=bin(a)
i=2
while i<len(b):
if b[i]=='1':
print( len(b)-i,end=" ")
i+=1
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, a[100011], p = 0;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
a[p] = 1;
while (p > 0 && a[p] == a[p - 1]) {
a[p - 1]++;
p--;
}
++p;
}
for (int i = 0; i < p; i++) cout << a[i] << " ";
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
}
long long modpow(long long a, long long p, long long mod) {
long long ret = 1;
while (p) {
if (p & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
p /= 2;
}
return ret % mod;
}
long long power(long long a, long long p) {
long long ret = 1;
while (p) {
if (p & 1) ret = (ret * a);
a = (a * a);
p /= 2;
}
return ret;
}
vector<int> ans;
int main() {
FastIO();
int n;
cin >> n;
for (int i = 30; i >= 0; i--)
if (n & (1 << i)) cout << i + 1 << " ";
cout << '\n';
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import math
a=[]
n=int(input())
amari=n
while amari != 0:
a.append(math.floor(math.log(amari,2))+1)
amari -= 2**math.floor(math.log(amari,2))
print(' '.join(map(str,a))) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
n = int(input())
start = time.time()
ans = []
while(n > 1):
k = 1
t = 0
while( k <= n ):
k*=2
t += 1
k //= 2
ans.append(t)
n -= k
for i in ans:
print(i, end=' ')
if n == 1:
print(1)
else:
print()
finish = time.time()
#print(finish - start)
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.*;
public class a {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
int n = in.nextInt();
int[] nums = new int[100001];
int count = 0;
int num = 1;
int id = 1;
while(true) {
int next = 0;
while(next < 1 << (num - 1)) {
if(next + id >= 100001) break;
nums[next + id] = num;
next++;
}
id += next;
num++;
if(id >= 100001) break;
}
//System.out.println("HI");
ArrayList<Integer> vals = new ArrayList<Integer>();
while(n > 0) {
num = nums[n];
//System.out.println(n + " " + num);
int sub = 1 << (num - 1);
//System.out.println(sub);
vals.add(num);
n -= sub;
//System.out.println("New n " + n);
}
for(int i : vals)
System.out.print(i + " ");
System.out.println();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream i) {
br = new BufferedReader(new InputStreamReader(i));
st = new StringTokenizer("");
}
public String next() throws IOException {
if(st.hasMoreTokens())
return st.nextToken();
else
st = new StringTokenizer(br.readLine());
return next();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | b = list(bin(int(input()))[2:])[::-1]
out = list()
for i in range(len(b)):
if b[i] == '1':
out.append(i + 1)
print(" ".join(map(str,out[::-1]))) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class A618 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
br.close();
int bit = 1 << 30;
int count = 30;
while (bit > 0) {
if (bit <= a) {
System.out.printf("%d ", count + 1);
a -= bit;
}
bit >>= 1;
count--;
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.Stack;
import java.util.StringTokenizer;
public class WunderFund1 {
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
Stack<Integer> s = new Stack<>();
for (int i = 1; i <= n; ++i) {
s.push(1);
while (!s.isEmpty()) {
int top = s.pop();
if (s.isEmpty()) {
s.push(top);
break;
} else {
int top2 = s.pop();
if (top == top2) {
s.push(top + 1);
}
else {
s.push(top2);
s.push(top);
break;
}
}
}
}
for (int x: s) {
System.out.print(x + " ");
}
System.out.println();
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
inline int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
int main() {
scanf("%d", &n);
while (n) {
int t = log2(n);
printf("%d ", t + 1);
n -= qpow(2, t);
}
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | def solve(n):
a = [1]
n -= 1
while n:
a.append(1)
while len(a) >= 2 and a[-1] == a[-2]:
a[-1] = a.pop() + 1
n -= 1
return ' '.join(map(str, a))
def main():
n = int(input())
print(solve(n))
main()
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input());i=0;a=[]
while(n!=1):
i+=1
if n%2:a.insert(0,i)
n=n//2
print(i+1,*a) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #!/usr/bin/python3
import sys
n = int(sys.stdin.readline().rstrip())
A = []
for i in range(n):
A.append(1)
while len(A) >= 2 and A[-1] == A[-2]:
A.pop()
A[-1] += 1
print(" ".join(map(str, A)))
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] ans=new int[20];
Scanner input=new Scanner(System.in);
while(input.hasNext())
{
int n,pt=0;
n=input.nextInt();
Arrays.fill(ans, 0);
while(n>0)
{
ans[pt++]=n%2;
n/=2;
}
for(--pt;pt!=-1;pt--)
if(ans[pt]==1)
System.out.print((pt+1)+" ");
}
input.close();
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
/**
* Erasyl Abenov
*
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
try (PrintWriter out = new PrintWriter(outputStream)) {
Task solver = new Task();
solver.solve(1, in, out);
}
}
}
class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
ArrayList<Integer> list = new ArrayList<>();
int sum = 0;
while(n > 0){
sum++;
if(n%2 != 0) list.add(sum);
n /= 2;
}
for(int i = list.size() - 1; i >= 0; --i) out.print(list.get(i) + " ");
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public BigInteger nextBig() {
return new BigInteger(next());
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.Scanner;
public class Main{
public static int[]a = new int[100010];
public static void main(String[] args) {
// TODO Auto-generated method stub
int n;
Scanner in = new Scanner(System.in);
n = in.nextInt();
int j = 0;
a[j++] = 1;
for(int i = 1;i < n;i++) {
if(i == 1) {
a[j-1] = a[j-1]+1;
}
else {
a[j++] = 1;
while(j != 1&&a[j-1] == a[j-2]) {
// System.out.println(a[j-1]);
a[j-2] = a[j-2]+1;
j--;
}
}
}
for(int i = 0;i < j;i++) {
if(i != 0)
System.out.print(" ");
System.out.print(a[i]);
}
System.out.println();
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.*;
public class intro {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt(),k=0,i=0;
while (n>0){
i=1; k=0;
while (i*2<=n){
i=i*2;
k++;
}
System.out.print(k+1+" ");
n=n-i;
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
nn = n
a = []
while nn:
if len(a) > 1:
if a[0] != a[1] and a[-1] != a[-2]:
a.append(1)
nn -= 1
else:
a.append(1)
nn -= 1
while len(a) > 1 and (a[0] == a[1] or a[-1] == a[-2]):
if a[0] == a[1]:
a[1] += 1
a = a[1:]
if len(a) > 1 and a[-1] == a[-2]:
a[-2] += 1
a = a[:-1]
for i in a:
print(i, end=" ")
print() | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | # -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll
n = int(raw_input())
k = 0
a = []
for i in xrange(n):
a.append(1)
k += 1
while k >= 2 and a[-1] == a[-2]:
a.pop()
a[-1] += 1
k -= 1
print " ".join(map(str, a))
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input());i=0;a=[]
while(n!=1):
i+=1
if n%2:a.insert(0,i)
n=n//2
a.insert(0,i+1)
print(*a) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
deque<long long int> d;
int main() {
long long int n, i, k, x, y;
cin >> n;
for (i = 1; i <= n; i++) {
if (d.size() == 0)
d.push_back(1);
else {
d.push_back(1);
while (d.size() > 1) {
x = d.back();
d.pop_back();
y = d.back();
d.pop_back();
if (x == y) {
d.push_back(x + 1);
} else {
d.push_back(y);
d.push_back(x);
break;
}
}
}
}
while (!d.empty()) {
cout << d.front() << " ";
d.pop_front();
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String s = Integer.toBinaryString(n);
StringBuilder ans = new StringBuilder();
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == '1')
ans.append(s.length() - i + " ");
System.out.println(ans.toString().trim());
scan.close();
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
n = int(input())
l = []
while n > 0:
i = 0
while pow(2, i) <= n:
i += 1
l.append(i)
n -= pow(2, i-1)
for e in l:
print(e, end=" ")
print()
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
stack<int> S;
vector<int> ans;
int main() {
int n;
cin >> n;
while (n--) {
int t = 1;
while (!S.empty()) {
if (S.top() != t)
break;
else {
S.pop();
t += 1;
}
}
S.push(t);
}
while (!S.empty()) {
ans.push_back(S.top());
S.pop();
}
for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
cout << endl;
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k[n];
for (int i = 0; i < n; i++) k[i] = 2;
int o = 0;
while (n >= 1) {
k[o] = n % 2;
if (n == 1) k[o] = 1;
o++;
n = n / 2;
}
for (int i = o; i >= 0; i--) {
if (k[i] == 1) cout << (i + 1) << " ";
}
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int R() {
int x;
scanf("%d", &x);
return x;
};
vector<int> v;
int main() {
int n = R();
v.push_back(1);
for (int i = 0; i < n - 1; i++) {
v.push_back(1);
int b = v.size() - 1;
while (v[b] == v[b - 1] && b > 0) {
int x = v[b];
v.pop_back();
v.pop_back();
b = v.size();
v.push_back(x + 1);
}
}
for (auto i : v) {
printf("%d ", i);
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class SlimeCombining {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> ans = new ArrayList<>();
int x = 1;
while (n > 0){
if(n % 2 != 0)
ans.add(x);
n /= 2;
x++;
}
Collections.sort(ans);
System.out.print(ans.get(ans.size() - 1));
for(int i = ans.size() - 2;i >= 0;i--)
System.out.print(" " + ans.get(i));
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) {
Reader reader = new Reader(System.in);
PrintWriter writer = new PrintWriter(System.out);
int n = reader.readInt();
int arr[] = new int[n];
int i = -1;
while(n--> 0 ){
arr[++i] = 1;
if(i>0){
while(true){
if(i>0 && arr[i] == arr[i-1]){
arr[i-1] = arr[i-1]+1;
i = i-1;
}
else{
break;
}
}
}
}
for(int x = 0;x<=i;x++){
writer.print(arr[x]+" ");
}
writer.close();
}
public static class Reader{
BufferedReader br;
StringTokenizer st;
public Reader(InputStream is){
br = new BufferedReader(new InputStreamReader(is));
}
public String readToken(){
if(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){
}
}
return st.nextToken();
}
public String readWord(){
return readToken();
}
public int readInt(){
return Integer.parseInt(readToken());
}
public long readLong(){
return Long.parseLong(readToken());
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import sys
import math
import bisect
def main():
n = int(input())
A = []
for i in range(n):
val = 1
while len(A) and A[-1] == val:
A.pop()
val += 1
A.append(val)
print(' '.join(list(str(a) for a in A)))
if __name__ == "__main__":
main()
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a;
while (n--) {
a.push_back(1);
while (a.size() > 1 && a[a.size() - 1] == a[a.size() - 2]) {
int val = a[a.size() - 1];
a.pop_back();
a.pop_back();
a.push_back(val + 1);
}
}
for (int i = 0; i < a.size(); ++i) {
printf("%d ", a[i]);
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input())
b=bin(n)[2:]
x=b[::-1]
l=[]
for i in range(len(b)):
if(x[i]=='1'):
l.append(i+1)
print(*l[::-1])
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.lang.*;
import java.util.*;
import java.io.*;
public class test
{
Scanner sc=new Scanner(System.in);
PrintWriter pr=new PrintWriter(System.out,true);
public static void main(String... args)
{
test c=new test();
c.prop();
}
public void prop()
{
int n,count=1 ;
Stack<Integer> s=new Stack<Integer>();
s.push(0);
n=sc.nextInt();
for (int i=1; ;++i) {
if(n%2==0)
{
++count ;
n=n/2 ;
}else
{
s.push(count);
n=n-1 ;
}
if(n==0)
break ;
}
for (; ; ) {
n=s.pop();
if(n==0)
break ;
else
pr.print(n+" ");
}
pr.println("");
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
res = n
current = 1
current_idx = 1
ans = []
while res >= current:
if res & current == current:
ans.append(current_idx)
current *= 2
current_idx += 1
print(' '.join([str(i) for i in ans[::-1]]))
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import javax.lang.model.type.PrimitiveType;
import javax.management.Query;
import javax.swing.SortOrder;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
import javax.swing.text.html.MinimalHTMLWriter;
import java.util.Iterator;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
public class secondclss {
static Scanner myscanner= new Scanner(System.in);
public static void main(String[] args) {
long n;
n=myscanner.nextLong();
int c=0,p=2,x,i,pp=0;
int[] a=new int[100000];
a[1]=1;
for(i=1;i<n;i++)
{
a[p++]=1;
x=p-1;
while(pp>=0)
{
if(a[x]!=a[x-1])
break;
x--;
a[x]=a[x]+1;
}
p=x+1;
}
for(i=1;i<p;i++)
System.out.print(a[i]+" ");
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
slimes = []
for x in range(n):
slimes.append(1)
while len(slimes) >= 2 and slimes[-1] == slimes[-2]:
a = slimes[-1]
del slimes[-1], slimes[-1]
slimes.append(a + 1)
print(" ".join(map(str, slimes))) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.*;
public class Solution{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n,i,temp,j;
int[] digit=new int[21];
n=in.nextInt();
temp=n;
i=0;
while(temp>0){
if(temp%2==1){
digit[i]=1;
}
temp/=2;
i++;
}
for(j=i;j>=0;j--){
if(digit[j]==1){
System.out.print((j+1)+" ");
}
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | i = input()
st = ""
d = 2
n = 1
while (i != 0):
a = i%d
if (a == 1):
st = str(n)+" "+st
i = (i-a)/d
n += 1
print(st[:-1]) | PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
import math
s = ''
a = 1
while n > 0 :
a = int(math.log2(n)) + 1
s += str(a) + ' '
n -= 2 ** (a - 1)
print(s)
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
import java.util.Scanner;
public class SlimeCombining {
public static void main(String[] args) {
int n , cursor = 0;
int[] ans ;
Scanner inp = new Scanner(System.in);
n = inp.nextInt();
ans = new int[n];
ans[0] = 1 ;
n-- ;
while(n != 0){
ans[++cursor] = 1 ;
n-- ;
while(cursor >= 1 && ans[cursor]==(ans[cursor-1])){
cursor -- ;
ans[cursor] += 1 ;
}
}
for(int i = 0 ; i<= cursor ; i++)System.out.print(ans[i] + " ");
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input())
s=bin(n)[2:]
len = len(s)
for i in s :
if i=="1" :
print len,
len-=1 | PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
n = int(raw_input())
print " ".join(str(i + 1) for i in range(30, -1, -1) if n & (1 << i) )
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import math
n = input()
x = bin(n)[2:]
f = 2**(len(x)-1)
for e in range(len(x)):
if x[e]=="1":
print int(math.log(f,2)+1),
f/=2
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | def lenOfList(list):
sum=0
for x in list:
sum+=1
return sum
n=int(input())
abdo=""
row=[]
if n==1:
print (1)
else:
row.append(1)
while n>1:
n-=1
row.append(1)
while row[-1]==row[-2]:
row.append(row[-1]+1)
row.remove(row[-2])
row.remove(row[-2])
if lenOfList(row)<2:
break
for x in row:
abdo+=str(x)+" "
print(abdo)
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 |
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner a=new Scanner(System.in);
Stack<Integer> k=new Stack<Integer>();
Stack<Integer> k2=new Stack<Integer>();
int n=a.nextInt();
while(n>0){
k.push(1);
while(k2.isEmpty()){
k2.push(k.pop());
if(k.isEmpty()){
k.push(k2.pop());
break;
}
if(k.peek()==k2.peek()){
k.push(k.pop()+1);
k2.pop();
}
else{
k.push(k2.pop());
break;
}
}
n--;
}
while(!k.isEmpty())
k2.push(k.pop());
while(!k2.isEmpty())
System.out.print(k2.pop()+" ");
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author bibhuty(bibhuty.nit@gmail.com)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Task618A_SlimeCombining solver = new Task618A_SlimeCombining();
solver.solve(1, in, out);
out.close();
}
static class Task618A_SlimeCombining {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int current = (int) (Math.log(n) / Math.log(2));
for (int i = current; i >= 0 && n > 0; --i) {
if (Math.pow(2, i) <= n) {
out.print(i + 1, "");
n -= Math.pow(2, i);
}
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void close() {
writer.close();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
boolean isSpaceChar(int ch);
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
slime = []
i=1
while n!=0:
slime.append(1)
while len(slime)>1 and slime[-1]==slime[-2]:
slime[-2] = slime[-2] +1
slime.remove(slime[-1])
n=n-1
print(*slime) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class New1 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(in.readLine());
int rem = n;
while (rem!=0) {
int num = (int)(Math.log10(rem)/Math.log10(2));
int num1 = (int)Math.pow(2, num);
rem = n%num1;
out.write((num+1)+" ");
}
out.write("\n");
out.flush();
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | from math import log2
n = int(input())
l = 1 + int(log2(n))
out = []
while n:
#print (n, l, 2**l)
if n >= 2**l:
n -= 2**l
out.append(str(l+1))
l -= 1
print (' '.join(out))
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input())
arr=[0]*n
i=1
for i in range(n):
arr[i]=n%2
n//=2
for j in range(i,-1,-1):
if(arr[j]!=0):
print(j+1,end=" ")
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
public class test {
private static long GCD(long a, long b) {
if(b == 0) return a;
return GCD(b, a%b);
}
public static void main(String[] args) throws InterruptedException {
//new careercup().run();
//new CC().run();
//System.out.println(Integer.MAX_VALUE);
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Stack<Integer> stk = new Stack<>();
int shift = 1;
while(n > 0) {
if((n&1) == 1)
stk.push(shift);
shift++;
n >>= 1;
}
while(!stk.isEmpty())
System.out.print(stk.pop()+" ");
}catch(IOException io){
io.printStackTrace();
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.StringTokenizer;
public class A {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void solve() throws IOException {
int t = 1;
while (t-- > 0) {
solveTest();
}
}
void solveTest() throws IOException {
int n = readInt();
int pow = 1;
for(int i = 22; i >= 0; i--) {
if((n & (1<<i)) != 0) {
out.print((i+1) + " ");
}
}
}
void init() throws FileNotFoundException {
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
int[] readArr(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = readInt();
}
return res;
}
long[] readArrL(int n) throws IOException {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = readLong();
}
return res;
}
public static void main(String[] args) {
new A().run();
}
public void run() {
try {
long t1 = System.currentTimeMillis();
init();
solve();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class A {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(in, out);
out.close();
}
static class Solver {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
if (n == 0) {
out.print(0);
return;
}
ArrayList<Long> snakes = new ArrayList<Long>();
long p = 1;
boolean b = true;
for (int i = 0; i < n; i++) {
snakes.add((long) 1);
if (snakes.size() >= 2) {
while (b) {
if (snakes.get(snakes.size()-1) == snakes.get(snakes.size() - 2)) {
p = snakes.get(snakes.size() - 2) + 1;
snakes.remove(snakes.size() - 1);
snakes.remove(snakes.size() - 1);
snakes.add(snakes.size(), p);
}
if(snakes.size() == 1)
b = false;
if(snakes.size() >= 2 && snakes.get(snakes.size() - 1) != snakes.get(snakes.size() - 2))
b = false;
}
b = true;
}
}
for (Long l : snakes) {
out.print(l + " ");
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public float nextFloar() {
return Float.parseFloat(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
a = [2**i for i in range(17)]
i = 16
while n < a[i]:
i -= 1
while n > 0:
print(i+1, end =' ')
n -= a[i]
while i >= 0 and n < a[i]:
i -= 1
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int arr[30] = {}, n, i = 0;
cin >> n;
while (n > 0) arr[i] = n % 2, n /= 2, i++;
for (i = 29; i >= 0; i--)
if (arr[i]) cout << i + 1 << ' ';
cout << '\n';
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
int main() {
unsigned n;
scanf("%d", &n);
std::vector<int> output;
for (int i = 30; i >= 0; --i)
if (n & (1 << i)) output.push_back(i + 1);
for (std::size_t i = 0; i < output.size(); ++i) {
if (i != output.size() - 1)
printf("%d ", output[i]);
else
printf("%d\n", output[i]);
}
exit(0);
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
stack<long long> s;
int n;
while (scanf("%d", &n) == 1) {
s.push(1);
n--;
while (n--) {
long long tmp = 1;
while (!s.empty()) {
if (tmp == s.top()) {
tmp = tmp + 1;
s.pop();
} else
break;
}
s.push(tmp);
}
int num = s.size();
long long ans[num];
int count = 0;
while (!s.empty()) {
ans[count++] = s.top();
s.pop();
}
for (int i = num - 1; i >= 0; i--) {
if (i == 0)
printf("%lld\n", ans[i]);
else
printf("%lld ", ans[i]);
}
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | def slizni(n):
lst = list()
while n > 0:
if n % 2 == 0:
lst.append(0)
n //= 2
else:
lst.append(1)
n -= 1
n //= 2
a = lst[::-1]
b = list()
for i in range(len(a)):
if a[i] == 1:
b.append(len(a) - i)
return b
print(*slizni(int(input())))
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
ar = list()
i = int(1)
while n != 0:
if n % 2 != 0:
ar.append(i)
n //= 2
i += 1
ar = ar[::-1]
for t in ar:
print(t, end=' ')
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int o;
float n, x;
scanf("%f", &n);
while ((int)n) {
x = log(n) / log(2) + 1;
printf("%d ", (int)x);
o = (int)pow(2, (int)x - 1);
n -= o;
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=input()
deg = 30
while deg>=0 :
if (1<<deg) & n:
print deg+1,
deg -= 1
| PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | if __name__ == "__main__":
n = int(input())
res = []
while n:
res.append(n%2)
n //= 2
#res.reverse()
for i in range(len(res)):
if res[i]:
res[i] = i+1
res.reverse()
s = ""
for ares in res:
if ares:
s += str(ares) + " "
print(s.strip()) | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #!/usr/bin/python
# -*- coding: utf-8 -*-
n = input()
stack = []
stacks = []
def snack(stack):
newstack = [stack[0]]
tok = 0
for i in xrange(1, len(stack)):
if newstack[-1] == stack[i] and tok != 1:
tok = 1
newstack[-1] += 1
continue
newstack += [stack[i]]
return newstack
for i in xrange(n):
stack += [1]
while (len(set(stack)) != len(stack)):
stack = snack(stack)
stacks += [stack]
for i in stack:
print i, | PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | x=int(input())
L=[1];
for i in range(2,x+1):
L.append(1);
a=len(L)-1;
while(a>0):
if L[a]==L[a-1]:
L[a-1]=L[a]+1;
L[a:a+1]=[];
else:
break
a=len(L)-1;
if a==0:
break
for i in L:
print(i,end=' ')
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
int n;
int pp(int);
int main() {
scanf("%d", &n);
pp(n);
return 0;
}
int pp(int x) {
int a, b;
a = 1;
b = 0;
while (a < x) {
a *= 2;
b++;
}
if (a == x) {
printf("%d", b + 1);
return 0;
} else {
printf("%d ", b);
pp(x - a / 2);
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = input()
slime=[]
for i in xrange(n):
slime.append(1)
while len(slime)>1 and slime[-1]==slime[-2]:
slime.pop()
slime[-1]+=1
for i in slime:
print i, | PYTHON |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.*;
import java.io.*;
public class Slimes
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
ArrayList<Integer> e = new ArrayList<>();
for(int i=0;i<n;i++)
{
e.add(1);
while(e.size()!=1 && (e.get(e.size()-1)==e.get(e.size()-2)))
{
e.remove(e.size()-1);
e.set(e.size()-1,e.get(e.size()-1)+1);
}
}
for(int i=0;i<e.size();i++)
System.out.print(e.get(i)+ " ");
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.Stack;
import java.util.StringTokenizer;
/**
* Created by peacefrog on 1/29/16.
* Time : 11:06 PM
*/
public class Task_A {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
PrintWriter out;
long timeBegin, timeEnd;
public void runIO() throws IOException {
timeBegin = System.currentTimeMillis();
InputStream inputStream;
OutputStream outputStream;
if (ONLINE_JUDGE) {
inputStream = System.in;
Reader.init(inputStream);
outputStream = System.out;
out = new PrintWriter(outputStream);
} else {
inputStream = new FileInputStream("/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input");
Reader.init(inputStream);
out = new PrintWriter(System.out);
}
solve();
out.flush();
out.close();
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
/*
* Start Solution Here
*/
private void solve() throws IOException {
long n = Reader.nextLong(); //This Variable default in Code Template
Stack<Long> track = new Stack<>();
track.add(1L);
for (long i = 1; i <= n-1; i++) {
if(track.peek() == 1){
long up = track.pop()+1;
while (!track.isEmpty() ){
if(track.peek()!= up) break;
up ++;
track.pop();
}
track.add(up);
}
else track.add(1L);
}
for (Long aTrack : track) {
out.print(aTrack + " ");
}
}
public static void main(String[] args) throws IOException {
new Task_A().runIO();
}
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
static String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
static char nextChar() throws IOException {
return (char) reader.read();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
static int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n=int(input())
m=n
S=1
d=[]
while m>=1:
if m%2==0:
m=m//2
S=S+1
else:
d.append(S)
S=S+1
m=m//2
for i in range(1,len(d)+1):
print(d[len(d)-i],end=" ") | PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
for i in range(30, -1, -1):
cur = 2 ** i
if n >= cur:
print(i + 1, end = ' ')
n -= cur
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
public class cf {
public static void main(String[] args) {
try {
InputStream inputStream=System.in;
OutputStream outputStream=System.out;
//InputStream inputStream=new FileInputStream("file.in");
//OutputStream outputStream=new FileOutputStream("file.out");
InputReader in=new InputReader(inputStream);
PrintWriter out=new PrintWriter(outputStream);
Task task=new Task();
task.run(in,out);
out.close();
} catch (Exception e) {
if (e instanceof FileNotFoundException) {System.out.print("File not found.");}
else {e.printStackTrace();}
}
}
}
class InputReader {
private BufferedReader br;
private StringTokenizer st;
public InputReader(InputStream stream) {
br=new BufferedReader(new InputStreamReader(stream),32768);
st=null;
}
public String next() {
while (st==null || !st.hasMoreTokens()) {
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public int[] nextIntArray(int n) {
int[] a=new int[n];
for (int i=0;i<n;i++) {a[i]=nextInt();}
return a;
}
public long[] nextLongArray(int n) {
long[] a=new long[n];
for (int i=0;i<n;i++) {a[i]=nextLong();}
return a;
}
}
class Task {
public void run(InputReader in,PrintWriter out) {
int n=in.nextInt();
String s=Integer.toString(n,2);
for (int i=0;i<s.length();i++) {
if (s.charAt(i)=='1') {
out.print(s.length()-i+" ");
}
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxN = 55;
int ans[maxN];
int cnt[maxN][maxN];
int used[maxN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a;
for (int i = 0; i < n; i++) {
a.push_back(1);
while (a.size() >= 2 && a[a.size() - 1] == a[a.size() - 2]) {
a.pop_back();
a.back()++;
}
}
for (auto x : a) {
cout << x << " ";
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.*;
public class bucky{
public static void main (String args[]) {
Scanner input=new Scanner(System.in);
HashMap<String, Integer> map= new HashMap<String, Integer>();
HashMap<String, String> map2= new HashMap<String, String>();
int n=input.nextInt();
String sss=bazadoi(n);
// System.out.print(sss+" ");
for(int i=0;i<sss.length();i++)
if(sss.charAt(i)!='0') {
System.out.print(sss.length()-i); System.out.print(" ");}
}
public static String bazadoi (int a){
String result="";
while(a>1){
int rest=a%2;
String b=String.valueOf(rest);
result+=b;
a=a/2;
}
String f=String.valueOf(a);
result+=f;
String solutie="";
for(int i=result.length()-1;i>=0;i--)
solutie+=result.substring(i,i+1);
return solutie;
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
b = list(bin(n)[2:])
result=''
indices = []
b.reverse()
for i in range(0, len(b)):
if(b[i] == '1'):
indices.append(i)
indices.reverse()
for i in indices:
result += str(i + 1) + ' '
print(result)
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Nasko
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
Stack<Integer> st = new Stack<Integer>();
int N = in.nextInt();
for (int i = 0; i < N; ++i) {
st.push(1);
if (st.size() > 1) {
boolean can = true;
while (st.size() > 1 && can) {
int last = st.pop();
int lastTwo = st.pop();
if (last == lastTwo) {
st.push(last + 1);
} else {
st.push(lastTwo);
st.push(last);
can = false;
}
}
}
}
ArrayList<Integer> ar = new ArrayList<Integer>();
while (st.size() > 0) ar.add(st.pop());
for (int i = ar.size() - 1; i >= 0; --i) out.print(ar.get(i) + " ");
out.println();
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.io.*;
import java.util.StringTokenizer;
public class A {
void solve() {
int n = in.nextInt();
int t = (1<<16);
int ind = 16;
while (t > 0){
if (n >= t){
n -= t;
out.print(ind + 1 + " ");
}
t /=2;
ind--;
}
}
InputReader in;
PrintWriter out;
void runIO() {
in = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) {
new A().runIO();
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
try (Scanner in = new Scanner(System.in)) {
int n = in.nextInt();
List<Integer> array = new ArrayList<>();
for (int i = 1; i <= n; i++) {
array.add(1);
while (array.size() > 1 && array.get(array.size() - 1).equals(array.get(array.size() - 2))) {
array.set(array.size() - 2, array.get(array.size() - 1) + 1);
array.remove(array.size() - 1);
}
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < array.size(); i++) {
builder.append(array.get(i)).append(i + 1 < array.size() ? " " : "");
}
System.out.println(builder);
}
}
} | JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, s[100000] = {0};
cin >> n;
int l = 0;
while (n--) {
s[l++] = 1;
while (l > 1 && s[l - 1] == s[l - 2]) {
s[l - 2]++;
s[l - 1] = 0;
l--;
}
}
for (int i = 0; i < l; i++) {
if (s[i] > 0) printf("%d", s[i]);
if (i != l - 1) printf(" ");
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
l = "{:b}".format(n)
r = []
for i, c in enumerate(l):
if c=="1":
r += [str(len(l)-i)]
print(" ".join(r))
| PYTHON3 |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> K;
int x = 0;
for (int i = 30; i >= 0; i--) {
if (n & (1 << i)) K.push_back(i);
}
for (int i = 0; i < K.size(); i++) cout << K[i] + 1 << " ";
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int T = 2000;
int n;
stack<int> N;
int main() {
cin >> n;
int k = 1;
while (n != 0) {
int b = n % 2;
if (b) {
N.push(k);
}
k++;
n /= 2;
}
while (!N.empty()) {
int a = N.top();
N.pop();
cout << a << " ";
}
return 0;
}
| CPP |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | //package wunderfund2016;
import java.util.ArrayList;
import java.util.Scanner;
public class slimecombining {
public static ArrayList<Integer> twopac = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
for(int i = 0; i < 20; i++) {
twopac.add((int)Math.pow(2, i));
}
int N = s.nextInt();
System.out.println(comp(N, "").trim());
s.close();
}
public static String comp(int n, String cur) {
if(n == 0)
return cur;
if(n == 1)
return cur + " " + 1;
int sub = 0;
while(!twopac.contains(n - sub))
sub++;
return comp(sub, cur + " " + (twopac.indexOf((n - sub)) + 1));
}
}
| JAVA |
618_A. Slime Combining | Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.
Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
2 1
Input
8
Output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
1. 1
2. 2
3. 2 1
4. 3
5. 3 1
6. 3 2
7. 3 2 1
8. 4 | 2 | 7 | n = int(input())
a = []
while n > 0:
a.append(1)
n = n - 1
while len(a) > 1 and a[len(a) - 1] == a[len(a) - 2]:
x = a[len(a) - 1] + 1
a.pop()
a.pop()
a.append(x)
for i in a:
print(i, end=' ') | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.