exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 2d4a91361b7f9a000e81681764cf672c | train_000.jsonl | 1557671700 | Let $$$c$$$ be some positive integer. Let's call an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers $$$c$$$-array, if for all $$$i$$$ condition $$$1 \leq a_i \leq c$$$ is satisfied. Let's call $$$c$$$-array $$$b_1, b_2, \ldots, b_k$$$ a subarray of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$, if there exists such set of $$$k$$$ indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ that $$$b_j = a_{i_j}$$$ for all $$$1 \leq j \leq k$$$. Let's define density of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$ as maximal non-negative integer $$$p$$$, such that any $$$c$$$-array, that contains $$$p$$$ numbers is a subarray of $$$a_1, a_2, \ldots, a_n$$$.You are given a number $$$c$$$ and some $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$. For all $$$0 \leq p \leq n$$$ find the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$, such that density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. Find these numbers by modulo $$$998\,244\,353$$$, because they can be too large. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf559F {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static final int P = 998244353;
static final int DBL_P = 2 * P;
static final long Q = 4L * P * P;
static int pow(int a, int b) {
int ret = 1;
for (; b > 0; b >>= 1) {
if ((b & 1) == 1) {
ret = (int) ((long) ret * a % P);
}
a = (int) ((long) a * a % P);
}
return ret;
}
int[][] bigC(int[] a, int c) {
int n = a.length;
int k = n / c;
long[][] dp = new long[n + 1][k + 1];
dp[0][0] = 1;
int[] cf = new int[n + 1];
int[] icf = new int[n + 1];
cf[0] = 0;
for (int i = 1; i < cf.length; i++) {
cf[i] = 2 * cf[i - 1] + 1;
if (cf[i] >= P) {
cf[i] -= P;
}
icf[i] = pow(cf[i], P - 2);
}
for (int i = 0; i < n; i++) {
int[] cnt = new int[c];
int nz = 0;
long prod = 1;
long[] src = dp[i];
for (int j = 0; j <= k; j++) {
src[j] %= P;
}
int upto = k - 1;
while (upto >= 0 && src[upto] == 0) {
upto--;
}
for (int j = i; j < n; j++) {
int x = a[j];
if (cnt[x] > 0) {
prod = prod * icf[cnt[x]] % P;
}
if (nz == c || (nz == c - 1 && cnt[x] == 0)) {
long[] dst = dp[j + 1];
for (int l = 0; l <= upto; l++) {
long tmp = dst[l + 1] + src[l] * prod;
if (tmp >= Q) {
tmp -= Q;
}
dst[l + 1] = tmp;
}
}
if (cnt[x] == 0) {
nz++;
}
cnt[x]++;
prod = prod * cf[cnt[x]] % P;
}
}
int[][] ret = new int[k + 1][n + 1];
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
ret[i][j] = (int) (dp[j][i] % P);
}
}
return ret;
}
static final Random rng = new Random();
int[][] smallC(int[] a, int c) {
int n = a.length;
int k = n / c;
int[][] dp = new int[k + 1][n + 1];
dp[0][0] = 1;
int[][] aux = new int[k + 1][1 << c];
aux[0][0] = 1;
int all = (1 << c) - 1;
for (int i = 0; i < n; i++) {
int x = a[i];
int mx = 1 << x;
for (int j = Math.min(k - 1, i / c); j >= 0; j--) {
int[] memo = aux[j];
int delta = memo[all ^ (1 << x)];
if (delta != 0) {
dp[j + 1][i + 1] += delta;
if (dp[j + 1][i + 1] >= P) {
dp[j + 1][i + 1] -= P;
}
aux[j + 1][0] += delta;
if (aux[j + 1][0] >= P) {
aux[j + 1][0] -= P;
}
}
int big = all ^ mx;
for (int mask = big;; mask = (mask - 1) & big) {
int z = mask ^ mx;
int tmp = (memo[z] << 1) + memo[mask];
if (tmp >= 0 && tmp < P) {
} else {
tmp -= P;
if (tmp >= P) {
tmp -= P;
}
}
/*
* if (tmp < 0 || tmp >= DBL_P) { tmp -= DBL_P; } else if
* (tmp >= P) { tmp -= P; }
*/
memo[z] = tmp;
if (mask == 0) {
break;
}
}
}
}
return dp;
}
void shuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
int j = rng.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int[] badCase(int n, int c) {
int[] a = new int[n];
int[] b = new int[c];
for (int i = 0; i < c; i++) {
b[i] = i;
}
for (int i = 0; i < n;) {
shuffle(b);
for (int j = 0; j < c && i < n; i++, j++) {
a[i] = b[j];
}
}
return a;
}
void solve() throws IOException {
// int n = 3000;
// int c = 13;
int n = nextInt();
int c = nextInt();
int[] a = new int[n];
// if (n == 3000 && c == 12) {
// a = badCase(n, c);
// } else {
for (int i = 0; i < n; i++) {
a[i] = nextInt() - 1;
}
// }
// int[][] dp = bigC(a, c);
int[][] dp = c > 12 ? bigC(a, c) : smallC(a, c);
int[] atL = new int[n + 2];
long p2 = 1;
for (int j = n; j >= 0; j--) {
for (int i = 0; i < dp.length; i++) {
atL[i] += (int) (p2 * dp[i][j] % P);
if (atL[i] >= P) {
atL[i] -= P;
}
}
p2 = 2 * p2 % P;
}
atL[0]--;
if (atL[0] < 0) {
atL[0] += P;
}
for (int i = 0; i <= n; i++) {
int x = atL[i] - atL[i + 1];
if (x < 0) {
x += P;
}
out.print(x + " ");
}
out.println();
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new cf559F().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| Java | ["4 1\n1 1 1 1", "3 3\n1 2 3", "5 2\n1 2 1 2 1"] | 6 seconds | ["0 4 6 4 1", "6 1 0 0", "10 17 4 0 0 0"] | NoteIn the first example, it's easy to see that the density of array will always be equal to its length. There exists $$$4$$$ sequences with one index, $$$6$$$ with two indices, $$$4$$$ with three and $$$1$$$ with four.In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from $$$1$$$ to $$$3$$$ in the array, so it won't satisfy the condition of density for $$$p \geq 1$$$. | Java 8 | standard input | [
"dp",
"math"
] | 95c277d67c04fc644989c3112c2b5ae7 | The first line contains two integers $$$n$$$ and $$$c$$$, separated by spaces ($$$1 \leq n, c \leq 3\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$1 \leq a_i \leq c$$$). | 3,500 | Print $$$n + 1$$$ numbers $$$s_0, s_1, \ldots, s_n$$$. $$$s_p$$$ should be equal to the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$ by modulo $$$998\,244\,353$$$, such that the density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. | standard output | |
PASSED | 5e55a3bb871bfdc136419cd293d6d5cf | train_000.jsonl | 1557671700 | Let $$$c$$$ be some positive integer. Let's call an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers $$$c$$$-array, if for all $$$i$$$ condition $$$1 \leq a_i \leq c$$$ is satisfied. Let's call $$$c$$$-array $$$b_1, b_2, \ldots, b_k$$$ a subarray of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$, if there exists such set of $$$k$$$ indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ that $$$b_j = a_{i_j}$$$ for all $$$1 \leq j \leq k$$$. Let's define density of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$ as maximal non-negative integer $$$p$$$, such that any $$$c$$$-array, that contains $$$p$$$ numbers is a subarray of $$$a_1, a_2, \ldots, a_n$$$.You are given a number $$$c$$$ and some $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$. For all $$$0 \leq p \leq n$$$ find the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$, such that density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. Find these numbers by modulo $$$998\,244\,353$$$, because they can be too large. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf559F {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static final int P = 998244353;
static final int DBL_P = 2 * P;
static final long Q = 4L * P * P;
static int pow(int a, int b) {
int ret = 1;
for (; b > 0; b >>= 1) {
if ((b & 1) == 1) {
ret = (int) ((long) ret * a % P);
}
a = (int) ((long) a * a % P);
}
return ret;
}
int[][] bigC(int[] a, int c) {
int n = a.length;
int k = n / c;
long[][] dp = new long[n + 1][k + 1];
dp[0][0] = 1;
int[] cf = new int[n + 1];
int[] icf = new int[n + 1];
cf[0] = 0;
for (int i = 1; i < cf.length; i++) {
cf[i] = 2 * cf[i - 1] + 1;
if (cf[i] >= P) {
cf[i] -= P;
}
icf[i] = pow(cf[i], P - 2);
}
for (int i = 0; i < n; i++) {
int[] cnt = new int[c];
int nz = 0;
long prod = 1;
long[] src = dp[i];
for (int j = 0; j <= k; j++) {
src[j] %= P;
}
int upto = k - 1;
while (upto >= 0 && src[upto] == 0) {
upto--;
}
for (int j = i; j < n; j++) {
int x = a[j];
if (cnt[x] > 0) {
prod = prod * icf[cnt[x]] % P;
}
if (nz == c || (nz == c - 1 && cnt[x] == 0)) {
long[] dst = dp[j + 1];
for (int l = 0; l <= upto; l++) {
long tmp = dst[l + 1] + src[l] * prod;
if (tmp >= Q) {
tmp -= Q;
}
dst[l + 1] = tmp;
}
}
if (cnt[x] == 0) {
nz++;
}
cnt[x]++;
prod = prod * cf[cnt[x]] % P;
}
}
int[][] ret = new int[k + 1][n + 1];
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
ret[i][j] = (int) (dp[j][i] % P);
}
}
return ret;
}
static final Random rng = new Random();
int[][] smallC(int[] a, int c) {
int n = a.length;
int k = n / c;
int[][] dp = new int[k + 1][n + 1];
dp[0][0] = 1;
int[][] aux = new int[k + 1][1 << c];
aux[0][0] = 1;
int all = (1 << c) - 1;
for (int i = 0; i < n; i++) {
int x = a[i];
int mx = 1 << x;
for (int j = Math.min(k - 1, i / c); j >= 0; j--) {
int[] memo = aux[j];
int delta = memo[all ^ (1 << x)];
if (delta != 0) {
dp[j + 1][i + 1] += delta;
if (dp[j + 1][i + 1] >= P) {
dp[j + 1][i + 1] -= P;
}
aux[j + 1][0] += delta;
if (aux[j + 1][0] >= P) {
aux[j + 1][0] -= P;
}
}
int big = all ^ mx;
for (int mask = big;; mask = (mask - 1) & big) {
int z = mask ^ mx;
int tmp = (memo[z] << 1) + memo[mask];
if (tmp >= 0 && tmp < P) {
} else {
tmp -= P;
if (tmp >= P) {
tmp -= P;
}
}
/*
* if (tmp < 0 || tmp >= DBL_P) { tmp -= DBL_P; } else if
* (tmp >= P) { tmp -= P; }
*/
memo[z] = tmp;
if (mask == 0) {
break;
}
}
}
}
return dp;
}
void shuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
int j = rng.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int[] badCase(int n, int c) {
int[] a = new int[n];
int[] b = new int[c];
for (int i = 0; i < c; i++) {
b[i] = i;
}
for (int i = 0; i < n;) {
shuffle(b);
for (int j = 0; j < c && i < n; i++, j++) {
a[i] = b[j];
}
}
return a;
}
void solve() throws IOException {
// int n = 3000;
// int c = 13;
int n = nextInt();
int c = nextInt();
int[] a = new int[n];
// if (n == 3000 && c == 12) {
// a = badCase(n, c);
// } else {
for (int i = 0; i < n; i++) {
a[i] = nextInt() - 1;
}
// }
// int[][] dp = bigC(a, c);
int[][] dp = c > 10 ? bigC(a, c) : smallC(a, c);
int[] atL = new int[n + 2];
long p2 = 1;
for (int j = n; j >= 0; j--) {
for (int i = 0; i < dp.length; i++) {
atL[i] = (int) ((atL[i] + p2 * dp[i][j]) % P);
}
p2 = 2 * p2 % P;
}
atL[0]--;
if (atL[0] < 0) {
atL[0] += P;
}
for (int i = 0; i <= n; i++) {
int x = atL[i] - atL[i + 1];
if (x < 0) {
x += P;
}
out.print(x + " ");
}
out.println();
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new cf559F().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| Java | ["4 1\n1 1 1 1", "3 3\n1 2 3", "5 2\n1 2 1 2 1"] | 6 seconds | ["0 4 6 4 1", "6 1 0 0", "10 17 4 0 0 0"] | NoteIn the first example, it's easy to see that the density of array will always be equal to its length. There exists $$$4$$$ sequences with one index, $$$6$$$ with two indices, $$$4$$$ with three and $$$1$$$ with four.In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from $$$1$$$ to $$$3$$$ in the array, so it won't satisfy the condition of density for $$$p \geq 1$$$. | Java 8 | standard input | [
"dp",
"math"
] | 95c277d67c04fc644989c3112c2b5ae7 | The first line contains two integers $$$n$$$ and $$$c$$$, separated by spaces ($$$1 \leq n, c \leq 3\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$1 \leq a_i \leq c$$$). | 3,500 | Print $$$n + 1$$$ numbers $$$s_0, s_1, \ldots, s_n$$$. $$$s_p$$$ should be equal to the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$ by modulo $$$998\,244\,353$$$, such that the density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. | standard output | |
PASSED | a9964caafd0d5b8a88b3cb6852f9136e | train_000.jsonl | 1557671700 | Let $$$c$$$ be some positive integer. Let's call an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers $$$c$$$-array, if for all $$$i$$$ condition $$$1 \leq a_i \leq c$$$ is satisfied. Let's call $$$c$$$-array $$$b_1, b_2, \ldots, b_k$$$ a subarray of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$, if there exists such set of $$$k$$$ indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ that $$$b_j = a_{i_j}$$$ for all $$$1 \leq j \leq k$$$. Let's define density of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$ as maximal non-negative integer $$$p$$$, such that any $$$c$$$-array, that contains $$$p$$$ numbers is a subarray of $$$a_1, a_2, \ldots, a_n$$$.You are given a number $$$c$$$ and some $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$. For all $$$0 \leq p \leq n$$$ find the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$, such that density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. Find these numbers by modulo $$$998\,244\,353$$$, because they can be too large. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf559F {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static final int P = 998244353;
static final int DBL_P = 2 * P;
static final long Q = 4L * P * P;
static int pow(int a, int b) {
int ret = 1;
for (; b > 0; b >>= 1) {
if ((b & 1) == 1) {
ret = (int) ((long) ret * a % P);
}
a = (int) ((long) a * a % P);
}
return ret;
}
int[][] bigC(int[] a, int c) {
int n = a.length;
int k = n / c;
long[][] dp = new long[n + 1][k + 1];
dp[0][0] = 1;
int[] cf = new int[n + 1];
int[] icf = new int[n + 1];
cf[0] = 0;
for (int i = 1; i < cf.length; i++) {
cf[i] = 2 * cf[i - 1] + 1;
if (cf[i] >= P) {
cf[i] -= P;
}
icf[i] = pow(cf[i], P - 2);
}
for (int i = 0; i < n; i++) {
int[] cnt = new int[c];
int nz = 0;
long prod = 1;
long[] src = dp[i];
for (int j = 0; j <= k; j++) {
src[j] %= P;
}
int upto = k - 1;
while (upto >= 0 && src[upto] == 0) {
upto--;
}
for (int j = i; j < n; j++) {
int x = a[j];
if (cnt[x] > 0) {
prod = prod * icf[cnt[x]] % P;
}
if (nz == c || (nz == c - 1 && cnt[x] == 0)) {
long[] dst = dp[j + 1];
for (int l = 0; l <= upto; l++) {
long tmp = dst[l + 1] + src[l] * prod;
if (tmp >= Q) {
tmp -= Q;
}
dst[l + 1] = tmp;
}
}
if (cnt[x] == 0) {
nz++;
}
cnt[x]++;
prod = prod * cf[cnt[x]] % P;
}
}
int[][] ret = new int[k + 1][n + 1];
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
ret[i][j] = (int) (dp[j][i] % P);
}
}
return ret;
}
static final Random rng = new Random();
int[][] smallC(int[] a, int c) {
int n = a.length;
int k = n / c;
int[][] dp = new int[k + 1][n + 1];
dp[0][0] = 1;
int[][] aux = new int[k + 1][1 << c];
aux[0][0] = 1;
int all = (1 << c) - 1;
for (int i = 0; i < n; i++) {
int x = a[i];
int mx = 1 << x;
for (int j = Math.min(k - 1, i / c); j >= 0; j--) {
int[] memo = aux[j];
int delta = memo[all ^ (1 << x)];
if (delta != 0) {
dp[j + 1][i + 1] += delta;
if (dp[j + 1][i + 1] >= P) {
dp[j + 1][i + 1] -= P;
}
aux[j + 1][0] += delta;
if (aux[j + 1][0] >= P) {
aux[j + 1][0] -= P;
}
}
int big = all ^ mx;
for (int mask = big;; mask = (mask - 1) & big) {
int z = mask ^ mx;
int tmp = (memo[z] << 1) + memo[mask];
if (tmp >= 0 && tmp < P) {
} else {
tmp -= P;
if (tmp >= P) {
tmp -= P;
}
}
/*
* if (tmp < 0 || tmp >= DBL_P) { tmp -= DBL_P; } else if
* (tmp >= P) { tmp -= P; }
*/
memo[z] = tmp;
if (mask == 0) {
break;
}
}
}
}
return dp;
}
void shuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
int j = rng.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int[] badCase(int n, int c) {
int[] a = new int[n];
int[] b = new int[c];
for (int i = 0; i < c; i++) {
b[i] = i;
}
for (int i = 0; i < n;) {
shuffle(b);
for (int j = 0; j < c && i < n; i++, j++) {
a[i] = b[j];
}
}
return a;
}
void solve() throws IOException {
// int n = 3000;
// int c = 13;
int n = nextInt();
int c = nextInt();
int[] a = new int[n];
// if (n == 3000 && c == 12) {
// a = badCase(n, c);
// } else {
for (int i = 0; i < n; i++) {
a[i] = nextInt() - 1;
}
// }
// int[][] dp = bigC(a, c);
int[][] dp = c > 11 ? bigC(a, c) : smallC(a, c);
int[] atL = new int[n + 2];
long p2 = 1;
for (int j = n; j >= 0; j--) {
for (int i = 0; i < dp.length; i++) {
atL[i] += (int) (p2 * dp[i][j] % P);
if (atL[i] >= P) {
atL[i] -= P;
}
}
p2 = 2 * p2 % P;
}
atL[0]--;
if (atL[0] < 0) {
atL[0] += P;
}
for (int i = 0; i <= n; i++) {
int x = atL[i] - atL[i + 1];
if (x < 0) {
x += P;
}
out.print(x + " ");
}
out.println();
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new cf559F().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| Java | ["4 1\n1 1 1 1", "3 3\n1 2 3", "5 2\n1 2 1 2 1"] | 6 seconds | ["0 4 6 4 1", "6 1 0 0", "10 17 4 0 0 0"] | NoteIn the first example, it's easy to see that the density of array will always be equal to its length. There exists $$$4$$$ sequences with one index, $$$6$$$ with two indices, $$$4$$$ with three and $$$1$$$ with four.In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from $$$1$$$ to $$$3$$$ in the array, so it won't satisfy the condition of density for $$$p \geq 1$$$. | Java 8 | standard input | [
"dp",
"math"
] | 95c277d67c04fc644989c3112c2b5ae7 | The first line contains two integers $$$n$$$ and $$$c$$$, separated by spaces ($$$1 \leq n, c \leq 3\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$1 \leq a_i \leq c$$$). | 3,500 | Print $$$n + 1$$$ numbers $$$s_0, s_1, \ldots, s_n$$$. $$$s_p$$$ should be equal to the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$ by modulo $$$998\,244\,353$$$, such that the density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. | standard output | |
PASSED | 60cc1d5b01feec9f7f87823ab349e129 | train_000.jsonl | 1557671700 | Let $$$c$$$ be some positive integer. Let's call an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers $$$c$$$-array, if for all $$$i$$$ condition $$$1 \leq a_i \leq c$$$ is satisfied. Let's call $$$c$$$-array $$$b_1, b_2, \ldots, b_k$$$ a subarray of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$, if there exists such set of $$$k$$$ indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ that $$$b_j = a_{i_j}$$$ for all $$$1 \leq j \leq k$$$. Let's define density of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$ as maximal non-negative integer $$$p$$$, such that any $$$c$$$-array, that contains $$$p$$$ numbers is a subarray of $$$a_1, a_2, \ldots, a_n$$$.You are given a number $$$c$$$ and some $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$. For all $$$0 \leq p \leq n$$$ find the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$, such that density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. Find these numbers by modulo $$$998\,244\,353$$$, because they can be too large. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf559F {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static final int P = 998244353;
static final int DBL_P = 2 * P;
static final long Q = 4L * P * P;
static int pow(int a, int b) {
int ret = 1;
for (; b > 0; b >>= 1) {
if ((b & 1) == 1) {
ret = (int) ((long) ret * a % P);
}
a = (int) ((long) a * a % P);
}
return ret;
}
int[][] bigC(int[] a, int c) {
int n = a.length;
int k = n / c;
long[][] dp = new long[n + 1][k + 1];
dp[0][0] = 1;
int[] cf = new int[n + 1];
int[] icf = new int[n + 1];
cf[0] = 0;
for (int i = 1; i < cf.length; i++) {
cf[i] = 2 * cf[i - 1] + 1;
if (cf[i] >= P) {
cf[i] -= P;
}
icf[i] = pow(cf[i], P - 2);
}
for (int i = 0; i < n; i++) {
int[] cnt = new int[c];
int nz = 0;
long prod = 1;
long[] src = dp[i];
for (int j = 0; j <= k; j++) {
src[j] %= P;
}
int upto = k - 1;
while (upto >= 0 && src[upto] == 0) {
upto--;
}
for (int j = i; j < n; j++) {
int x = a[j];
if (cnt[x] > 0) {
prod = prod * icf[cnt[x]] % P;
}
if (nz == c || (nz == c - 1 && cnt[x] == 0)) {
long[] dst = dp[j + 1];
for (int l = 0; l <= upto; l++) {
long tmp = dst[l + 1] + src[l] * prod;
if (tmp >= Q) {
tmp -= Q;
}
dst[l + 1] = tmp;
}
}
if (cnt[x] == 0) {
nz++;
}
cnt[x]++;
prod = prod * cf[cnt[x]] % P;
}
}
int[][] ret = new int[k + 1][n + 1];
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= n; j++) {
ret[i][j] = (int) (dp[j][i] % P);
}
}
return ret;
}
static final Random rng = new Random();
int[][] smallC(int[] a, int c) {
int n = a.length;
int k = n / c;
int[][] dp = new int[k + 1][n + 1];
dp[0][0] = 1;
int[][] aux = new int[k + 1][1 << c];
aux[0][0] = 1;
int all = (1 << c) - 1;
for (int i = 0; i < n; i++) {
int x = a[i];
int mx = 1 << x;
for (int j = Math.min(k - 1, i / c); j >= 0; j--) {
int[] memo = aux[j];
int delta = memo[all ^ (1 << x)];
if (delta != 0) {
dp[j + 1][i + 1] += delta;
if (dp[j + 1][i + 1] >= P) {
dp[j + 1][i + 1] -= P;
}
aux[j + 1][0] += delta;
if (aux[j + 1][0] >= P) {
aux[j + 1][0] -= P;
}
}
int big = all ^ mx;
for (int mask = big;; mask = (mask - 1) & big) {
int z = mask ^ mx;
int tmp = (memo[z] << 1) + memo[mask];
if (tmp >= 0 && tmp < P) {
} else {
tmp -= P;
if (tmp >= P) {
tmp -= P;
}
}
/*
* if (tmp < 0 || tmp >= DBL_P) { tmp -= DBL_P; } else if
* (tmp >= P) { tmp -= P; }
*/
memo[z] = tmp;
if (mask == 0) {
break;
}
}
}
}
return dp;
}
void shuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
int j = rng.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int[] badCase(int n, int c) {
int[] a = new int[n];
int[] b = new int[c];
for (int i = 0; i < c; i++) {
b[i] = i;
}
for (int i = 0; i < n;) {
shuffle(b);
for (int j = 0; j < c && i < n; i++, j++) {
a[i] = b[j];
}
}
return a;
}
void solve() throws IOException {
// int n = 3000;
// int c = 13;
int n = nextInt();
int c = nextInt();
int[] a = new int[n];
// if (n == 3000 && c == 12) {
// a = badCase(n, c);
// } else {
for (int i = 0; i < n; i++) {
a[i] = nextInt() - 1;
}
// }
// int[][] dp = bigC(a, c);
int[][] dp = c > 10 ? bigC(a, c) : smallC(a, c);
int[] atL = new int[n + 2];
long p2 = 1;
for (int j = n; j >= 0; j--) {
for (int i = 0; i < dp.length; i++) {
atL[i] += (int) (p2 * dp[i][j] % P);
if (atL[i] >= P) {
atL[i] -= P;
}
}
p2 = 2 * p2 % P;
}
atL[0]--;
if (atL[0] < 0) {
atL[0] += P;
}
for (int i = 0; i <= n; i++) {
int x = atL[i] - atL[i + 1];
if (x < 0) {
x += P;
}
out.print(x + " ");
}
out.println();
}
void inp() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new cf559F().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| Java | ["4 1\n1 1 1 1", "3 3\n1 2 3", "5 2\n1 2 1 2 1"] | 6 seconds | ["0 4 6 4 1", "6 1 0 0", "10 17 4 0 0 0"] | NoteIn the first example, it's easy to see that the density of array will always be equal to its length. There exists $$$4$$$ sequences with one index, $$$6$$$ with two indices, $$$4$$$ with three and $$$1$$$ with four.In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from $$$1$$$ to $$$3$$$ in the array, so it won't satisfy the condition of density for $$$p \geq 1$$$. | Java 8 | standard input | [
"dp",
"math"
] | 95c277d67c04fc644989c3112c2b5ae7 | The first line contains two integers $$$n$$$ and $$$c$$$, separated by spaces ($$$1 \leq n, c \leq 3\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$1 \leq a_i \leq c$$$). | 3,500 | Print $$$n + 1$$$ numbers $$$s_0, s_1, \ldots, s_n$$$. $$$s_p$$$ should be equal to the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$ by modulo $$$998\,244\,353$$$, such that the density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. | standard output | |
PASSED | 349a2fc777ee14c46f4a78f3d51ebb14 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes |
import java.util.*;
import java.io.*;
public class D {
public static void main(String[] args) {
FastReader in = new FastReader();
int t = in.nextInt();
while (t-- > 0) {
int a = in.nextInt();
int b = in.nextInt();
int min = Math.min(a, b);
int max = Math.max(a, b);
if(2 * min > max){
System.out.println((2 * min) * 2 * min);
} else{
System.out.println(max * max);
}
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | ec8bb7fb976b878bd05a309e656b9142 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class CodeChef
{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
int testcases = scan.nextInt();
for(int m=0; m<testcases; m++)
{
int a = scan.nextInt();
int b = scan.nextInt();
int area = 2*a*b;
int min = Math.min(a,b);
int max = Math.max(a,b);
int i=1;
while(true)
{
long square =(long) Math.pow(i, 2);
if(square>=area && (i>=max && i>=2*min)) { System.out.println(square); break; }
i++;
}
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | f78405af1cdf1f70527f4dbea6e5fd99 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class MinimalSquare {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Problem https://codeforces.com/problemset/problem/1360/A
// For more solutions check https://github.com/jontiboss
Reader reader = new Reader();
int tests = reader.nextInt();
for(int i =0;i<tests;i++) {
int x = reader.nextInt();
int y = reader.nextInt();
//you want to know if y or x is the smallest. Then you place the rectangles parallel to each other so that we could form a square.
//the short side will be multiplied by 2 and the long side will remain the same.
//you then want to calculate the area of the square which is area = side*side = side^2
System.out.println((int)Math.pow(Math.min(Math.max((x<<1), y), Math.max(x, (y<<1))),2));
}
}
static class Reader
{
BufferedReader br;
StringTokenizer st;
public Reader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
}
| Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | fdb6e1ed418c5de466079d82bde479a7 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | //package Div3_644;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n)
{
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(next());
}
return a;
}
}
public static void main(String[] args) {
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-- > 0)
{
int a=sc.nextInt();
int b=sc.nextInt();
int side=0;
side=Math.min(a, b); //picking smaller side;
side=side*2; //joining both of them.
side=Math.max(side, Math.max(a, b));
System.out.println(side*side);
}
}
}
| Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | eafbf4cc5daf04ae7755b964c6ceff3a | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
public class miniMalSquare {
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int tt = in.nextInt();
while(tt>0)
{
int n1 = in.nextInt();
int n2 = in.nextInt();
if(n1<n2) {
if (n1*2<n2)
System.out.println(n2*n2);
else
System.out.println(n1*2*n1*2);
}
else {
if(n2*2<n1)
System.out.println(n1 * n1);
else
System.out.println(n2*2*n2*2);
}
tt--;
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | 1e297d3d4e5d88261b5dd0c254e48699 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
import java.lang.Math;
public class codeforce{
public static void main(String args[]){
Scanner sj = new Scanner(System.in);
int t = sj.nextInt();
while(t-->0){
int a = sj.nextInt();
int b = sj.nextInt();
int ans = Math.min(Math.max(2*a, b), Math.max(a, 2*b));
System.out.println(ans*ans);
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | fe69de1e864ad0b26a832d6b3f541507 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
s.nextLine();
int[] ans = new int[t];
for (int i = 0; i < t; i++) {
int a = s.nextInt();
int b = s.nextInt();
int min = Math.min(a, b);
int max = Math.max(a, b);
int res = Math.max(min*2, max);
ans[i] = res*res;
}
for (int i = 0; i < ans.length; i++) {
System.out.println(ans[i]);
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | d1757de6e76a4391a8862d0ff6716088 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
s.nextLine();
int[] ans = new int[t];
for (int i = 0; i < t; i++) {
int a = s.nextInt();
int b = s.nextInt();
if (a < b) {
a = a * 2;
if (a > b) {
while (b < a) {
b++;
}
} else {
while (a < b) {
a++;
}
}
ans[i] = b * a;
} else {
b = b * 2;
if (a > b) {
while (b < a) {
b++;
}
} else {
while (a < b) {
a++;
}
}
ans[i] = a * b;
}
}
for (int i = 0; i < ans.length; i++) {
System.out.println(ans[i]);
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | d7a49f0a1c9a4937518f6fdfeb804a11 | train_000.jsonl | 1590327300 | Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding. The picture shows a square that contains red and green rectangles. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
t--;
int a,b;
a=sc.nextInt();
b=sc.nextInt();
int x = Math.min(a,b);
int y = Math.max(a,b);
x=2*x;
if( x< y)
{
x=x+y-x;
}
System.out.println(x*x);
}
}
} | Java | ["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"] | 2 seconds | ["16\n16\n4\n9\n64\n9\n64\n40000"] | NoteBelow are the answers for the first two test cases: | Java 8 | standard input | [
"greedy",
"math"
] | 3bb093fb17d6b76ae340fab44b08fcb8 | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles. | 800 | Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$. | standard output | |
PASSED | 10e1db0ebbafb0ac9a2cad01fe4ba6f1 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner snr=new Scanner(System.in);
int n=snr.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=snr.nextInt();
}
int sol=0;
Arrays.sort(a);
int max=a[n-1];
for(int i=0;i<n;i++)
sol+=max-a[i];
System.out.println(sol);
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 9b190453a7c57b0baf631ed34786fa6e | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class RENAMETHISBITCH {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
int max = sc.nextInt();
int sum = 0;
for (int i = 1; i < n; i++) {
int a = sc.nextInt();
if (max < a) {
sum += i * (a - max);
max = a;
}
else sum += (max - a);
}
System.out.println(sum);
}
catch (Exception e) {
e.printStackTrace();
}
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | eb54eaf22f13f0df8698ac51149e1870 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class P_758A {
public static final String NAME = "Holiday Of Equality";
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
int max = sc.nextInt();
int welfare = 0;
for (int i = 1; i < n; i++) {
int a = sc.nextInt();
if (max<a) {
welfare += i*(a-max);
max = a;
}
else welfare += (max-a);
}
System.out.println(welfare);
}
catch (Exception e) {
e.printStackTrace();
}
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 6906558b8e058cc565553007d8bf75c6 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
ow.write(""+sd);
ow.flush();
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 418f6c05222e073a4d1bbac15de54a8a | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
bw.write(""+sd);
bw.flush();
}
}//3 | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | d2f91c40f73b756ded48dfd25b805c44 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
bw.write(""+sd);
bw.flush();
}
}//2 | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 98919f1030913378bf999f3d8ee6181a | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
ow.write(""+sd);
ow.flush();
}
}//3 | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | a43f15637e33383540fc3d8abe1a074a | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
ow.write(""+sd);
ow.flush();
}
}//2 | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 98634bd92c596b8b368fa24f63c72691 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
OutputStreamWriter ow = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
bw.write(""+sd);
bw.flush();
}
}//1 | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | f32a3f5fd042227adb9f013aa59d2994 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int c,t,sd=0;
c=sc.nextInt();
int b[]=new int[c];
for(int i=0; i<c; i++)
{
b[i]=sc.nextInt();
}
Arrays.sort(b);
for(int i=0; i<c; i++)
sd=sd+(b[c-1]-b[i]);
System.out.println(sd);
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 6ae3c6f47ca5f2efc28698222373057b | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
public class Main
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int sum=0,i,max;
int[] a = new int[100];
for(i=0;i<n;i++)
a[i]=s.nextInt();
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
}
for(i=0;i<n;i++)
{
sum=sum+(-a[i]+max);
}
System.out.println(sum);
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | bd10305eaad5f14a45e576ab8d59cfad | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class _p000758A {
static public void main(final String[] args) throws java.io.IOException {
p000758A._main(args);
}
//begin p000758A.java
static private class p000758A extends Solver{public p000758A(){nameIn="p000758A.in"
;singleTest=true;}int n;int[]a;@Override protected void solve(){Arrays.sort(a);pw
.println(Arrays.stream(a,0,n-1).map(v->a[n-1]-v).sum());}@Override public void readInput
()throws IOException{n=sc.nextInt();sc.nextLine();a=Arrays.stream(sc.nextLine().trim
().split("\\s+")).mapToInt(Integer::valueOf).toArray();}static public void _main
(String[]args)throws IOException{new p000758A().run();}}
//end p000758A.java
//begin net/leksi/contest/Solver.java
static private abstract class Solver{protected String nameIn=null;protected String
nameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug
=false;protected boolean doNotPreprocess=false;protected Scanner sc=null;protected
PrintWriter pw=null;private void process()throws IOException{if(!singleTest){int
t=lineToIntArray()[0];while(t-->0){readInput();solve();}}else{readInput();solve(
);}}abstract protected void readInput()throws IOException;abstract protected void
solve()throws IOException;protected int[]lineToIntArray()throws IOException{return
Arrays.stream(sc.nextLine().trim().split("\\s+")).mapToInt(Integer::valueOf).toArray
();}protected long[]lineToLongArray()throws IOException{return Arrays.stream(sc.nextLine
().trim().split("\\s+")).mapToLong(Long::valueOf).toArray();}protected String intArrayToString
(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors
.joining(" "));}protected String longArrayToString(final long[]a){return Arrays.stream
(a).mapToObj(Long::toString).collect(Collectors.joining(" "));}protected List<Long>
longArrayToList(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect
(Collectors.toList());}protected List<Integer>intArrayToList(final int[]a){return
Arrays.stream(a).mapToObj(Integer::valueOf).collect(Collectors.toList());}protected
List<Long>intArrayToLongList(final int[]a){return Arrays.stream(a).mapToObj(Long
::valueOf).collect(Collectors.toList());}protected void run()throws IOException{
try{try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0=select_output
();){sc=new Scanner(fis);pw=pw0;process();}}catch(IOException ex){try(PrintWriter
pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process();}}}private PrintWriter
select_output()throws FileNotFoundException{if(nameOut !=null){return new PrintWriter
(nameOut);}return new PrintWriter(System.out);}}
//end net/leksi/contest/Solver.java
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 76980cc0db6941cc7a17231aabaccd69 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Collectors;
public class p000758A {
static public void main(String[] args) throws IOException {
new Solver() {{{ nameIn = "p000758A.in"; singleTest = true;}}
@Override
public void process(BufferedReader br, PrintWriter pw) throws IOException {
int n = readIntArray(br)[0];
int[] a = readIntArray(br);
Arrays.sort(a);
pw.println(Arrays.stream(a, 0, n - 1).map(v -> a[n - 1] - v).sum());
}
}.run();
}
// begin import package net.leksi.contest;
static abstract class Solver{protected String nameIn=null;protected String nameOut=null
;protected boolean singleTest=false;private void preProcess(final BufferedReader
br,final PrintWriter pw)throws IOException{if(!singleTest){int t=Integer.valueOf
(br.readLine().trim());while(t-->0){process(br,pw);}}else{process(br,pw);}}abstract
public void process(final BufferedReader br,final PrintWriter pw)throws IOException
;protected int[]readIntArray(final BufferedReader br)throws IOException{return Arrays
.stream(br.readLine().trim().split("\\s+")).mapToInt(v->Integer.valueOf(v)).toArray
();}protected long[]readLongArray(final BufferedReader br)throws IOException{return
Arrays.stream(br.readLine().trim().split("\\s+")).mapToLong(v->Long.valueOf(v)).toArray
();}protected String readString(final BufferedReader br)throws IOException{return
br.readLine().trim();}protected String intArrayToString(final int[]a){return Arrays
.stream(a).mapToObj(v->Integer.toString(v)).collect(Collectors.joining(" "));}protected
String longArrayToString(final long[]a){return Arrays.stream(a).mapToObj(v->Long
.toString(v)).collect(Collectors.joining(" "));}public void run()throws IOException
{try{try(FileReader fr=new FileReader(nameIn);BufferedReader br=new BufferedReader
(fr);PrintWriter pw=select_output();){preProcess(br,pw);}}catch(Exception ex){try
(InputStreamReader fr=new InputStreamReader(System.in);BufferedReader br=new BufferedReader
(fr);PrintWriter pw=select_output();){preProcess(br,pw);}}}private PrintWriter select_output
()throws FileNotFoundException{if(nameOut !=null){return new PrintWriter(nameOut
);}return new PrintWriter(System.out);}}
// end import package net.leksi.contest;
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 9c90c4129fe775870be2e1ec6e3104ce | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author ittraining
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int r=sc.nextInt(); int op=0;
int arr[]=new int[r];
for(int a=0; a<r;a++){
arr[a]=sc.nextInt();
}
Arrays.sort(arr);
int big=arr[r-1];
for(int b=0;b<arr.length-1;b++){
if(arr[b]<=big){
int dif=big-arr[b];
op=op+dif;
}
}
System.out.println(op);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | a3efac97656abe09f2fc7a65f9e33b04 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
long max = 0;
long a[] = new long[(int)n];
for(int i=0; i<n; i++){
a[i] = s.nextLong();
if(a[i] > max){
max = a[i];
}
}
int count = 0;
for(int i =0; i<n; i++){
count += max - a[i];
}
System.out.println(count);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 429442a50afca8a6be9124759b673b93 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
public class Main{
public static void main(String [] args){
//try{
//File fin = new File("input.txt");
//File fout = new File("output.txt");
Scanner in = new Scanner(System.in);
//PrintWriter pw = new PrintWriter(System.out);
int n = in.nextInt();
int comp = 0;
int[] na = new int[n];
for(int i=0; i<n; i++){
int a = in.nextInt();
na[i] = a;
}
Arrays.sort(na);
int mx = na[na.length-1];
int count = 0;
for(int i : na){
count += (mx-i);
//pw.print(i+" ");
}
System.out.print(""+count);
//pw.close();
/*}
catch(Exception e){
e.printStackTrace();
}*/
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | bd6375f0aaa2c77e4cad903d6077bd04 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class Holiday {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s.next());
}
int max=arr[0];
for(int i=0;i<n;i++){
if(arr[i]>max){
max=arr[i];
}
}
int count=0;
for(int i=0;i<n;i++){
count=count+(max-arr[i]);
}
System.out.println(count);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 7f9274492875adae705f0c9a8657d611 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class Holiday {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s.next());
}
int max=arr[0];
for(int i=0;i<n;i++){
if(arr[i]>max){
max=arr[i];
}
}
int count=0;
for(int i=0;i<n;i++){
count=count+(max-arr[i]);
}
System.out.println(count);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | a067f16923dc3d07303aaaa48c8e6834 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes |
import java.io.*;
import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
private static int[][] direct = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
private static AWriter writer = new AWriter(System.out);
private static AReader reader = new AReader(System.in);
private static int[] a;
private static int[] b;
private static Set<Integer> left;
private static Set<Integer> right;
public static void main(String[] args) throws IOException {
int n=reader.nextInt();
int ans=0;
a=new int[n];
int max=-1;
for(int i=0;i<n;i++){
a[i]=reader.nextInt();
if(a[i]>max)
max=a[i];
}
for(int i=0;i<n;i++){
ans+=max-a[i];
}
writer.println(ans);
writer.close();
reader.close();
}
}
class AReader implements Closeable {
private BufferedReader reader;
private StringTokenizer tokenizer;
public AReader(InputStream inputStream) {
reader = new BufferedReader(new InputStreamReader(inputStream));
tokenizer = new StringTokenizer("");
}
private String innerNextLine() {
try {
return reader.readLine();
} catch (IOException ex) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String nextLine = innerNextLine();
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public String nextLine() {
tokenizer = new StringTokenizer("");
return innerNextLine();
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.valueOf(next());
}
public long nextLong() {
return Long.valueOf(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
public BigDecimal nextBigDecimal(){ return new BigDecimal(next()); }
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
@Override
public void close() throws IOException {
reader.close();
}
}
// Fast writer for ACM By Azure99
class AWriter implements Closeable {
private BufferedWriter writer;
public AWriter(OutputStream outputStream) {
writer = new BufferedWriter(new OutputStreamWriter(outputStream));
}
public void print(Object object) throws IOException {
writer.write(object.toString());
}
public void println(Object object) throws IOException {
writer.write(object.toString());
writer.write("\n");
}
@Override
public void close() throws IOException {
writer.close();
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | c1569eb6416586520c085408de69aa4e | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes |
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if( n == 1)
System.out.println("0");
else
{
int []wel = new int [1000010];
int maxx = 0;
for (int i = 1; i <= n ; i++)
{
wel[i] = sc.nextInt();
maxx = Math.max(maxx, wel[i]);
}
int tot = 0;
for (int i = 1; i <= n; i++)
{
tot += maxx-wel[i];
}
System.out.println(tot);
}
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 4fec86f21f54c59489ba8e347c9893cf | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
public class Ravenstvo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0;i< n;i++) {
a[i] = sc.nextInt();
}
int max = maxOf(a);
int[] na = new int[n];
for (int i =0;i < n;i++) {
na[i] = max - a[i];
}
int sum = sumOf(na);
System.out.println(sum);
}
public static int maxOf(int[] a) {
int n = a.length;
int m = a[0];
for (int i = 0;i < n;i++) {
if (m < a[i]) {
m = a[i];
}
}
return m;
}
public static int sumOf(int[] a) {
int n = a.length;
int s = 0;
for (int i=0;i <n;i++) {
s += a[i];
}
return s;
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 693867f3c8f6aafbee42d6dcd9c88f2f | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
public class Equality{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int max = -999999999;
int counter = 0;
int list [] = new int [n];
for(int i = 0;i < n;i++){
list[i] = in.nextInt();
}
for(int i = 0; i < n;i++){
if(max < list[i]){
max = list[i];
}
}
for(int i = 0; i < n;i++){
counter += max-list[i];
}
System.out.print(counter);
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 01a37916f57f78ebe86a7cc6593b5b5c | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
public class Practice{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int max = -999999999;
int counter = 0;
int list [] = new int [n];
for(int i = 0;i < n;i++){
list[i] = in.nextInt();
}
for(int i = 0; i < n;i++){
if(max < list[i]){
max = list[i];
}
}
for(int i = 0; i < n;i++){
counter += max-list[i];
}
System.out.print(counter);
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 6760afb681b840aff1fa7dbc29100e94 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | /*
Problem Name: Holiday Of Equality
URL: http://codeforces.com/contest/758/problem/A
*/
import java.util.*;
public class Holiday_Of_Equality{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] citizen = new int[110];
int largest = -999999;
for(int i = 1;i<=n;i++){
citizen[i] = sc.nextInt();
if(citizen[i]>largest){
largest = citizen[i];
}
}
int sum = 0;
for(int i = 1;i<=n;i++){
sum += (largest - citizen[i]);
}
System.out.println(sum);
}
} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | ed5d2ba12f53e97a7cd6a551bfe3c1eb | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
int sum = 0;
for(int i=0;i<n-1;i++) {
sum+=a[n-1]-a[i];
}
System.out.println(sum);
}} | Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | af5dd7f3389e319e4264024c0b16c641 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class HolidayOfEquality {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Problem https://codeforces.com/problemset/problem/758/A
// https://github.com/jontiboss
Reader scan = new Reader();
int n = scan.nextInt();
int[] sum = new int[n];
int max = 0;
// save all the cities in an array and find out what is the largest city because we want to find the smallest difference, to get a cheap price.
for(int i=0;i<sum.length;i++) {
int temp = scan.nextInt();
sum[i] = temp;
if(temp>max)
max = temp;
}
int answer = 0;
// the cheapest price is the total difference of max-sum[k]
for(int k = 0;k<sum.length;k++) {
answer = answer + Math.abs(max-sum[k]);
}
System.out.println(answer);
}
static class Reader
{
BufferedReader br;
StringTokenizer st;
public Reader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 62f99e1836beb54a077fd3d139f823f6 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class HolidayOfEquality {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] sum = new int[n];
int max = 0;
for(int i=0;i<sum.length;i++) {
int temp = scan.nextInt();
sum[i] = temp;
if(temp>max)
max = temp;
}
int answer = 0;
for(int k = 0;k<sum.length;k++) {
answer = answer + Math.abs(max-sum[k]);
}
scan.close();
System.out.println(answer);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 904baeaa876dac72fe88c4831ffe3191 | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Holiday_Equality {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0, max=0;
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
max=a[n-1];
for (int i = 0; i < n; i++) {
a[i] = max - a[i];
sum = sum + a[i];
}
System.out.println(sum);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 6bd1993041e4cdc44ed40063b3f4924f | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.Scanner;
public class JavaApplication15 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] tab = new int[n];
int i;
tab[0] = sc.nextInt();
int max = tab[0];
int s = tab[0];
for (i = 1; i < n; i++) {
tab[i] = sc.nextInt();
s += tab[i];
if (tab[i] > max) {
max = tab[i];
}
}
System.out.println(max * n - s);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 3382aa83927d3ad5d066f99e20141aac | train_000.jsonl | 1484838300 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
*
* @author HP
*/
public class JavaApplication16 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner s = new Scanner(System.in);
int n = s.nextInt();
List<Integer>L=new ArrayList<Integer>();
int s1=0;
for(int i=0;i<n;i++)
{
int a=s.nextInt();
L.add(a);
s1+=a;
}
int b=Collections.max(L);
System.out.println(b*n-s1);
}
}
| Java | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | 1 second | ["10", "1", "4", "0"] | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | Java 8 | standard input | [
"implementation",
"math"
] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | 800 | In the only line print the integer S — the minimum number of burles which are had to spend. | standard output | |
PASSED | 198ddca23c66484004f8115549bbb006 | train_000.jsonl | 1407511800 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution
{
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class Ele implements Comparable<Ele>
{
public int x,y;
Ele(int x,int y)
{
this.x=x;this.y=y;
}
public int compareTo(Ele ob) {
if(ob.x!=x)return x-ob.x;
return this.y-ob.y;
}
}
int a[][];int b[][];
int solve(int i,int j)// 0-none, 1-true,2-false
{
//System.out.println(i+" "+j);
if (i==a.length-1 || j==a.length-1) return 1;
else {
if (b[i][j]!=0) return b[i][j];
b[i][j]=2;
if (a[i+1][j]==1)
b[i][j]=solve(i+1,j);
if (a[i][j+1]==1)
b[i][j]=Math.min(b[i][j],solve(i,j+1));
return b[i][j];
}
}
long gcd(long a,long b)
{
long min=Math.min(a,b);
long max=Math.max(a,b);
while (max%min!=0)
{
a=max%min;
max=min;min=a;
}
return min;
}
public static void main(String[] args) throws IOException
{
Reader sc=new Reader();Solution G=new Solution();
PrintWriter o = new PrintWriter(System.out);
int t=1;
//int t=sc.nextInt();
int n,x,y,s1,s2;long a[],b[];
int s;boolean b1,b2;
//String s1;//int s2;
//long l;long a[];
ArrayList<Integer> ob1=new ArrayList<>();
HashMap<Integer,Integer> m=new HashMap<>();
ArrayList<Integer> ob2=new ArrayList<>();
ArrayList<Integer> ob3=new ArrayList<>();
while (t-->0)
{
n=sc.nextInt();a=new long[100005];b=new long[100005];
for (int i=0;i<n;i++)
{
a[sc.nextInt()]++;
}
b[1]=a[1];
for (int i=2;i<100005;i++)
{
b[i]=Math.max(b[i-1],b[i-2]+a[i]*i);
}
//o.println(ob3);
o.println(b[100004]);
//o.println("Done");
ob1.clear();ob2.clear();ob3.clear();m.clear();
}
//o.println("HI");
o.flush();
o.close();
}
} | Java | ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3"] | 1 second | ["2", "4", "10"] | NoteConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | Java 11 | standard input | [
"dp"
] | 41b3e726b8146dc733244ee8415383c0 | The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). | 1,500 | Print a single integer — the maximum number of points that Alex can earn. | standard output | |
PASSED | 976308fc90607232b4b187b6723f3dd2 | train_000.jsonl | 1407511800 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. | 256 megabytes | import java.util.Scanner;
public class Main {
static long []cnt=new long[100005];
static long []dp=new long[100005];
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
for(int i=0;i<n;i++){
int x=cin.nextInt();
cnt[x]++;
}
dp[1]=cnt[1];
for(int i=2;i<100005;i++){
dp[i]=Math.max(dp[i-1],dp[i-2]+i*cnt[i]);
}
System.out.println(dp[100004]);
}
}
| Java | ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3"] | 1 second | ["2", "4", "10"] | NoteConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | Java 11 | standard input | [
"dp"
] | 41b3e726b8146dc733244ee8415383c0 | The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). | 1,500 | Print a single integer — the maximum number of points that Alex can earn. | standard output | |
PASSED | 55bf78cb2c68cbb9952d311d94679823 | train_000.jsonl | 1407511800 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. | 256 megabytes | import java.util.*;
public class cf260div2C {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];long cnt[]=new long[100001];
for(int i=0;i<n;i++)
{arr[i]=sc.nextInt();
cnt[arr[i]]++;}
cnt[0]=0;
long dp[]=new long[100001];
dp[0]=0;
dp[1]=cnt[1];
for(int i=2;i<=100000;i++)
{dp[i]=Math.max(dp[i-1],dp[i-2]+i*cnt[i]);}
System.out.println(dp[100000]);
sc.close();
}
} | Java | ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3"] | 1 second | ["2", "4", "10"] | NoteConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | Java 11 | standard input | [
"dp"
] | 41b3e726b8146dc733244ee8415383c0 | The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). | 1,500 | Print a single integer — the maximum number of points that Alex can earn. | standard output | |
PASSED | 1b71de694b522f32c023e7e54d571a78 | train_000.jsonl | 1407511800 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
int[] bucket = new int[100001];
long[] ans = new long[100002];
for(int i =0 ;i<n; i++) {
arr[i] = sc.nextInt();
}
for(int i = 0; i<100001; i++) bucket[i] = 0;
for(int i = 0; i<n; i++) {
bucket[arr[i]] += 1;
}
ans[100001] = 0;
ans[100000] = bucket[100000]*100000l;
for(int i = (100000-1); i>0; i--) {
ans[i] = Math.max((long)bucket[i]*i + ans[i+2], ans[i+1]);
}
System.out.println(ans[1]);
}
} | Java | ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3"] | 1 second | ["2", "4", "10"] | NoteConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | Java 11 | standard input | [
"dp"
] | 41b3e726b8146dc733244ee8415383c0 | The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). | 1,500 | Print a single integer — the maximum number of points that Alex can earn. | standard output | |
PASSED | e3fc3adabea0fc3ecd815ebf23524c0c | train_000.jsonl | 1407511800 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.BufferedOutputStream;
public class Boredom{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static PrintWriter out;
public static void printArr(int[] arr){
for(int i = 0;i<arr.length;i++){
out.print(arr[i] + " ");
}
out.println();
}
public static void main(String[] args){
FastReader s = new FastReader();
out=new PrintWriter (new BufferedOutputStream(System.out));
int t = 1;
for(int u = 0;u<t;u++){
int n = s.nextInt();
int[] arr = new int[n];
long[] f = new long[100001];
int max = -1;
for(int i = 0;i<n;i++){
arr[i] = s.nextInt();
f[arr[i]]++;
max = Math.max(max, arr[i]);
}
long[] res = new long[100001];
res[0] = 0;
res[1] = f[1];
for(int i = 2;i<=max;i++){
res[i] = Math.max(res[i-1], res[i-2] + i*f[i]);
}
out.println(res[max]);
}
out.close();
}
} | Java | ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3"] | 1 second | ["2", "4", "10"] | NoteConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | Java 11 | standard input | [
"dp"
] | 41b3e726b8146dc733244ee8415383c0 | The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). | 1,500 | Print a single integer — the maximum number of points that Alex can earn. | standard output | |
PASSED | 862c6cd02aacea83bf9f16f90815a739 | train_000.jsonl | 1554041100 | You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (including $$$s$$$ and $$$t$$$) in lexicographical order. For example, for $$$k=2$$$, $$$s=$$$"az" and $$$t=$$$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].Your task is to print the median (the middle element) of this list. For the example above this will be "bc".It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class CF2 {
public static final int BASE = 'z' - 'a' + 1;
// 14:12-
public static void main(String[] args) throws Exception {
try (BufferedInputStream in = new BufferedInputStream(System.in);
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
Scanner sc = new Scanner(in);
int k = sc.nextInt();
String s = sc.next();
String t = sc.next();
int[] a = toNum(k, s);
int[] b = toNum(k, t);
int[] x = new int[a.length + 10];
for (int i = 0; i < a.length; i++) {
x[i + 10] = a[i] + b[i];
}
for (int i = x.length - 1; i > 0; i--) {
if (x[i] >= BASE) {
x[i] -= BASE;
x[i - 1] += 1;
}
}
for (int i = x.length - 1; i >= 0; i--) {
int rest = x[i] % 2;
x[i] /= 2;
if (rest > 0) {
x[i + 1] += rest * BASE / 2;
}
}
for (int i = x.length - 1; i > 0; i--) {
if (x[i] >= BASE) {
x[i] -= BASE;
x[i - 1] += 1;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 10; i < x.length; i++) {
sb.append((char) (x[i] + 'a'));
}
out.println(sb.toString());
}
}
private static int[] toNum(int k, String s) {
int[] vals = new int[k];
for (int i = 0; i < s.length(); i++) vals[i] = s.charAt(i) - 'a';
return vals;
}
} | Java | ["2\naz\nbf", "5\nafogk\nasdji", "6\nnijfvj\ntvqhwp"] | 2 seconds | ["bc", "alvuw", "qoztvz"] | null | Java 8 | standard input | [
"number theory",
"bitmasks",
"math",
"strings"
] | 5f4009d4065f5ad39e662095f8f5c068 | The first line of the input contains one integer $$$k$$$ ($$$1 \le k \le 2 \cdot 10^5$$$) — the length of strings. The second line of the input contains one string $$$s$$$ consisting of exactly $$$k$$$ lowercase Latin letters. The third line of the input contains one string $$$t$$$ consisting of exactly $$$k$$$ lowercase Latin letters. It is guaranteed that $$$s$$$ is lexicographically less than $$$t$$$. It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 1,900 | Print one string consisting exactly of $$$k$$$ lowercase Latin letters — the median (the middle element) of list of strings of length $$$k$$$ lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | standard output | |
PASSED | b576c27d2e24cb8a4d2940e73f11f822 | train_000.jsonl | 1554041100 | You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (including $$$s$$$ and $$$t$$$) in lexicographical order. For example, for $$$k=2$$$, $$$s=$$$"az" and $$$t=$$$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].Your task is to print the median (the middle element) of this list. For the example above this will be "bc".It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;
public class P1144E {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = in.nextInt();
String s = in.readString();
String t = in.readString();
int k = s.length();
int[] a = new int[k];
int[] b = new int[k];
for(int i=0; i<s.length(); i++) {
a[i] = (int)(s.charAt(i)-'a');
b[i] = (int)(t.charAt(i)-'a');
}
int carry=0;
for(int i=k-1; i>=0; i--) {
a[i] = a[i]+b[i]+carry;
if (a[i]>=26) {
carry=1;
a[i]-=26;
} else {
carry=0;
}
a[i]%=26;
}
// for(int x: a) {
// System.out.print(x+" ");
// }
// System.out.println();
// System.out.println("CARRY is "+carry);
for(int i=0; i<k; i++) {
a[i] = (a[i]+26*carry);
if (a[i]%2!=0) {
carry=1;
} else {
carry=0;
}
a[i]/=2;
}
for(int x: a) {
System.out.print((char)(x+'a')+"");
}
System.out.println();
w.flush();
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 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 {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["2\naz\nbf", "5\nafogk\nasdji", "6\nnijfvj\ntvqhwp"] | 2 seconds | ["bc", "alvuw", "qoztvz"] | null | Java 8 | standard input | [
"number theory",
"bitmasks",
"math",
"strings"
] | 5f4009d4065f5ad39e662095f8f5c068 | The first line of the input contains one integer $$$k$$$ ($$$1 \le k \le 2 \cdot 10^5$$$) — the length of strings. The second line of the input contains one string $$$s$$$ consisting of exactly $$$k$$$ lowercase Latin letters. The third line of the input contains one string $$$t$$$ consisting of exactly $$$k$$$ lowercase Latin letters. It is guaranteed that $$$s$$$ is lexicographically less than $$$t$$$. It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 1,900 | Print one string consisting exactly of $$$k$$$ lowercase Latin letters — the median (the middle element) of list of strings of length $$$k$$$ lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | standard output | |
PASSED | 3de59957cd0c1c1af9486fe103f42678 | train_000.jsonl | 1554041100 | You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (including $$$s$$$ and $$$t$$$) in lexicographical order. For example, for $$$k=2$$$, $$$s=$$$"az" and $$$t=$$$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].Your task is to print the median (the middle element) of this list. For the example above this will be "bc".It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
@SuppressWarnings("Duplicates")
public class ProblemEv2 {
public static void main(String[] args) throws IOException{
//Reader sc = new Reader();
PrintWriter pw = new PrintWriter(System.out);
//Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int len = Integer.parseInt(br.readLine());
String l1 = br.readLine();
String l2 = br.readLine();
int[] sol = new int[len];
int MOD = 26;
for (int i = 0; i < len; i++) {
int val = l1.charAt(i)-'a'+l2.charAt(i)-'a';
sol[i] += val / 2;
if (val%2==1)sol[i+1]+=MOD/2;
}
char[] prin = new char[len];
for (int i = len-1; i >-1 ; i--) {
if (sol[i]>=MOD){
sol[i-1]+=sol[i]/MOD;
sol[i] = sol[i]%MOD;
}
prin[i] = (char)(sol[i]+'a');
}
pw.println(new String(prin));
pw.flush();
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["2\naz\nbf", "5\nafogk\nasdji", "6\nnijfvj\ntvqhwp"] | 2 seconds | ["bc", "alvuw", "qoztvz"] | null | Java 8 | standard input | [
"number theory",
"bitmasks",
"math",
"strings"
] | 5f4009d4065f5ad39e662095f8f5c068 | The first line of the input contains one integer $$$k$$$ ($$$1 \le k \le 2 \cdot 10^5$$$) — the length of strings. The second line of the input contains one string $$$s$$$ consisting of exactly $$$k$$$ lowercase Latin letters. The third line of the input contains one string $$$t$$$ consisting of exactly $$$k$$$ lowercase Latin letters. It is guaranteed that $$$s$$$ is lexicographically less than $$$t$$$. It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 1,900 | Print one string consisting exactly of $$$k$$$ lowercase Latin letters — the median (the middle element) of list of strings of length $$$k$$$ lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | standard output | |
PASSED | d1f32b666405e750a60b14b4e646c0b8 | train_000.jsonl | 1554041100 | You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (including $$$s$$$ and $$$t$$$) in lexicographical order. For example, for $$$k=2$$$, $$$s=$$$"az" and $$$t=$$$"bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].Your task is to print the median (the middle element) of this list. For the example above this will be "bc".It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 256 megabytes | import java.util.Scanner;
public class E {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = Integer.parseInt(sc.nextLine());
String s = sc.nextLine();
String t = sc.nextLine();
//System.out.println(s);
//System.out.println(t);
// long startTime =System.currentTimeMillis();
char[] l1 = new char[k];
char[] l2 = new char[k];
for(int i = 0; i < k; i++) {
l1[i] = s.charAt(k-i-1);
l2[i] = t.charAt(k-i-1);
}
char[] sum = new char[k+1];
int carry = 0;
for(int i = 0; i < k; i++) {
sum[i] = (char) ((l1[i] - 97) + (l2[i] - 97));
sum[i] += carry;
carry = sum[i] / 26;
sum[i] %= 26;
// System.out.println((int) sum[i]);
sum[i] += 97;
}
sum[k] = (char) (carry + 97);
//System.out.println(sum);
char[] ans= new char[k+1];
carry = 0;
for(int i = k; i>=0; i--) {
ans[i] = (char) ((sum[i] - 97)/2);
int Ncarry = (sum[i] -97) - (2*ans[i]);
ans[i] += (13*carry);
carry = Ncarry;
ans[i] += 97;
}
//System.out.println(ans);
StringBuilder a = new StringBuilder(k);
for(int i =0; i<k; i++) {
a.append(ans[k-1-i]);
}
System.out.println(a);
// System.err.println(System.currentTimeMillis()-startTime);
sc.close();
}
/*private static String randString(int n) {
String s = "";
for(int i =0; i<n; i++) {
s += (char) (97 + ((int) (Math.random() * 26)));
}
return s;
}*/
}
| Java | ["2\naz\nbf", "5\nafogk\nasdji", "6\nnijfvj\ntvqhwp"] | 2 seconds | ["bc", "alvuw", "qoztvz"] | null | Java 8 | standard input | [
"number theory",
"bitmasks",
"math",
"strings"
] | 5f4009d4065f5ad39e662095f8f5c068 | The first line of the input contains one integer $$$k$$$ ($$$1 \le k \le 2 \cdot 10^5$$$) — the length of strings. The second line of the input contains one string $$$s$$$ consisting of exactly $$$k$$$ lowercase Latin letters. The third line of the input contains one string $$$t$$$ consisting of exactly $$$k$$$ lowercase Latin letters. It is guaranteed that $$$s$$$ is lexicographically less than $$$t$$$. It is guaranteed that there is an odd number of strings lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | 1,900 | Print one string consisting exactly of $$$k$$$ lowercase Latin letters — the median (the middle element) of list of strings of length $$$k$$$ lexicographically not less than $$$s$$$ and not greater than $$$t$$$. | standard output | |
PASSED | 74e21ca4a5c29e5c9cd9a92c7f3d5151 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int t=1;
while(t-->0){
int n=Integer.parseInt(br.readLine());
String[] in = br.readLine().split(" ");
long[] arr = new long[n];
int sum=0;
boolean ch = false;
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(in[i]);
}
Arrays.sort(arr);
if(n>2){
int a=0;
int b = (n)/2;
long temp[] = new long[n];
for(int i=0;i<n;i++){
if(i%2==0){
temp[i]=arr[b++];
}
else{
temp[i]=arr[a++]; }
}
int su=0;
for(int i=1;i<n-1;i+=2){
if(temp[i-1]>temp[i]&&temp[i+1]>temp[i]){
su++;
}
}
System.out.println(su);
for(long i:temp){
System.out.print(i+" ");
}
}
else{
System.out.println(0);
for(long i: arr){
System.out.print(i+" ");
}
}
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | a42509343c10878f3c160db84aab38bb | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class TaskD1 {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
// Start writing your solution here. -------------------------------------
/*
int n = sc.nextInt(); // read input as integer
long k = sc.nextLong(); // read input as long
double d = sc.nextDouble(); // read input as double
String str = sc.next(); // read input as String
String s = sc.nextLine(); // read whole line as String
int result = 3*n;
out.println(result); // print via PrintWriter
*/
// Stop writing your solution here. -------------------------------------
int n = sc.nextInt();
int[] nums = new int[n];
int[] result = new int[n];
for (int i=0; i<n; i++) {
nums[i] = sc.nextInt();
}
Arrays.sort(nums);
for (int i=0; 2*i<n; i++) {
result[2 * i] = nums[n - i - 1];
}
for (int i=0; 2*i+1<n; i++) {
result[2*i+1] = nums[i];
}
out.println(Math.max(0, (n-1)/2));
for (int i=0; i<n; i++) {
out.println(result[i]);
}
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 90cf857ef8726fdca7106dd6bca97936 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes |
import java.util.*;
public class segementTree {
public static int mod=1000000007;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
Arrays.sort(arr);
int ans[]=new int[n];
if(n%2!=0)
System.out.println(n/2);
else
System.out.println(n/2-1);
int j=n-1;
int k=0;
for(int i=0;i<n;i++) {
if(i%2==0)
ans[i]=arr[j--];
else
ans[i]=arr[k++];
System.out.print(ans[i]+" ");
}
System.out.println();
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 37c080f6994e10677f6db1a1b03959a4 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
var sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
var a = new int[n];
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(sc.next());
}
Arrays.sort(a);
var pw = new PrintWriter(System.out);
pw.println((n-1)/2);
int n2 = n/2;
for(int i = 0; i < n2; i++){
pw.print(a[n2+i] + " ");
pw.print(a[i] + " ");
}
if(n%2 == 1){
pw.print(a[n-1]);
}
pw.flush();
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | b5932bcee3d2df21c5b0f608f416a13d | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package javaapplication2;
import java.util.*;
import java.util.Arrays;
/**
*
* @author DELL
*/
public class JavaApplication2 {
/**
* @param args the command line arguments
*/
static int ans(char[] w,char[] v,int a,int b,int[][] t){
if(a==0 || b==0)return 0;
if(t[a][b]!=-1)return t[a][b];
if(w[a-1]==v[b-1]){
return t[a][b]=1+ans(w,v,a-1,b-1,t);
}
else{
return t[a][b]=Math.max(ans(w,v,a-1,b,t),ans(w,v,a,b-1,t));
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
Arrays.sort(a);
if(n%2==0)System.out.println((n/2)-1);
else if(n%2!=0) System.out.println(n/2);
//System.out.println();
for(int i=0;i<n/2;i++){
System.out.print(a[n-i-1]+" "+a[i]+" ");
}
if(n%2!=0)System.out.print(a[n/2]);
System.out.println();
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | d1957057356eec04378496fa50c6b6eb | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.awt.dnd.InvalidDnDOperationException;
import java.io.*;
import java.lang.reflect.Array;
import java.nio.charset.CharsetEncoder;
import java.util.*;
public class Main {
private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
private static final boolean OFFLINE_WITHOUT_FILES = false;
void solve() throws IOException {
int n = readInt();
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = readInt();
}
sortArrayInt(arr);
int left = 0;
int right = n;
while (left < right) {
int middle = (right + left) / 2;
int[] down = Arrays.copyOfRange(arr, 0, middle);
int[] up = Arrays.copyOfRange(arr, n - middle - 1, n);
boolean good = true&&(middle<(n-middle));
for (int i = 0; i < down.length; ++i) {
if (down[i] >= up[i]) {
good = false;
break;
}
}
if (left==(right-1)){
break;
}
if (good) {
left = middle;
} else {
right=middle;
}
}
out.println(left);
int LEFT=left;
int TO=left;
int FROM=n-left-1;
boolean printTO=false;
while (0<left){
out.print(arr[FROM]+" "+arr[TO-left]+" ");
--left;
++FROM;
}
out.print(arr[n-1]+" ");
for (int i=LEFT;i<n-LEFT-1;++i){
out.print(arr[i]+" ");
}
}
long func1(long x) {
return (2l * x + 2l) * (2l * x + 1l) / 2l;
}
void printDefaultList(List<Integer> arr) {
for (Integer el : arr) {
out.print(el + " ");
}
out.println();
}
void printDefaultArr(int[] arr) {
for (int i = 0; i < arr.length; ++i) {
out.print(arr[i] + " ");
}
out.println();
}
public static void main(String[] args) {
new Main();
}
BufferedReader in;
PrintWriter out;
StringTokenizer tok;
Main() {
try {
long timeStart = System.currentTimeMillis();
if (ONLINE_JUDGE || OFFLINE_WITHOUT_FILES) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("C:\\Users\\asker\\IdeaProjects\\untitled3\\src\\input.txt"));
out = new PrintWriter("C:\\Users\\asker\\IdeaProjects\\untitled3\\src\\output.txt");
}
tok = new StringTokenizer("");
solve();
out.close();
long timeEnd = System.currentTimeMillis();
System.err.println("time = " + (timeEnd - timeStart) + " compiled");
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
String readLine() throws IOException {
return in.readLine();
}
String delimiter = " ";
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
String nextLine = readLine();
if (nextLine == null)
return null;
tok = new StringTokenizer(nextLine);
}
return tok.nextToken(delimiter);
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
int[] sortArrayInt(int[] a) {
Integer[] arr = new Integer[a.length];
for (int i = 0; i < a.length; i++) {
arr[i] = a[i];
}
Arrays.sort(arr);
for (int i = 0; i < a.length; i++) {
a[i] = arr[i];
}
return a;
}
void sortArrayLong(long[] a) {
Long[] arr = new Long[a.length];
for (int i = 0; i < a.length; i++) {
arr[i] = a[i];
}
Arrays.sort(arr);
for (int i = 0; i < a.length; i++) {
a[i] = arr[i];
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 53b42998882f3d46b96944734f8e6795 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class problemD {
private static void solve() throws Exception {
int n = fs.nextInt();
ArrayList<Integer> a = new ArrayList<>(n);
for (int i = 0 ; i < n ; i ++ ) a.add(fs.nextInt());
Collections.sort(a);
int ans = 0 ;
int[] A = new int[n];
int ind = 0 ;
for (int i = 1; i < n ; i += 2) {
A[i] = a.get(ind);
ind++;
if (i != n-1) {
ans++;
}
}
for (int i = 0 ; i < n; i += 2) {
A[i] = a.get(ind);
ind++;
}
out.println(ans);
for (int i = 0 ; i < n ; i ++ ) {
out.print(A[i]);
out.print(' ');
}
out.println();
}
private static FastScanner fs = new FastScanner();
private static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
out.close();
}
static void debug(Object... O) {
System.err.print("DEBUG ");
System.err.println(Arrays.deepToString(O));
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextString() {
return next();
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 05cba2631b4bc2262a922ea9c691605d | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes |
import java.io.*;
import java.util.*;
// Author- Prashant Gupta
public class D {
public static void main(String[] args) throws IOException {
// write your code here
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
// Scanner sc = new Scanner(System.in);
Reader sc = new Reader();
int t = 1;
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
if (n % 2 == 0) {
out.println(n / 2 - 1);
} else {
out.println(n / 2);
}
int i = n - 1, j = 0;
boolean flag = true;
while (j <= i) {
if (flag) {
out.print(a[i] + " ");
i--;
} else {
out.print(a[j] + " ");
j++;
}
flag = !flag;
}
out.println();
}
out.close();
}
/*-------------------------------------------------------------------------------------*/
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long power(long x, long y) {
long res = 1;
while (x > 0) {
if (y % 2 == 0) {
x *= x;
y /= 2;
} else {
res *= x;
y--;
}
}
return res;
}
public static long lcm(long x, long y) {
return (x * y) / gcd(x, y);
}
public static int lowerBound(Vector<Integer> v, int e) {
int start = 0, end = v.size() - 1, ind = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (v.get(mid) == e) {
ind = mid;
break;
} else if (v.get(mid) < e) {
ind = mid + 1;
start = mid + 1;
} else {
end = mid - 1;
}
}
return ind;
}
// Fast I/p
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | d117e6826f5de23952c45eed74795be9 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class Codeforces{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String[] arr=sc.nextLine().split(" ");
Arrays.sort(arr,new Comparator<String>() {
public int compare(String s1,String s2) {
return Integer.valueOf(s2)-Integer.valueOf(s1);
}
});
if(n%2==0) {
String[] high=Arrays.copyOfRange(arr,0,(n/2));
String[] low=Arrays.copyOfRange(arr,(n/2),n);
if(n%2==0) System.out.println(n/2-1);
else System.out.println(n/2);
for(int i=0;i<n/2;i++) {
if(i==0) {
System.out.print(high[i]+" "+low[i]);
}
else {
System.out.print(" "+high[i]+" "+low[i]);
}
}
if(n%2!=0) System.out.print(" "+high[n/2]);
}
else {
String[] high=Arrays.copyOfRange(arr,0,(n/2)+1);
String[] low=Arrays.copyOfRange(arr,(n/2)+1,n);
if(n%2==0) System.out.println(n/2-1);
else System.out.println(n/2);
for(int i=0;i<n/2;i++) {
if(i==0) {
System.out.print(high[i]+" "+low[i]);
}
else {
System.out.print(" "+high[i]+" "+low[i]);
}
}
if(n%2!=0) System.out.print(" "+high[n/2]);
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 411ad360dc50bb7c61247e1b8560cf8f | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)throws java.lang.Exception {
FastReader sc = new FastReader();
// StringBuffer sb = new StringBuffer();
// ArrayList<Integer> al=new ArrayList<>();
// ArrayList<Integer> al=new ArrayList<>(101);
int n=sc.nextInt();
long[] b=new long[n];
long[] a=new long[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLong();
Arrays.sort(a);
if(n==1)
{
System.out.println(0);
System.out.println(a[0]);
}
else if(n==2)
{
System.out.println(0);
System.out.println(a[0]+" "+a[1]);
}
else if(n==3)
{
System.out.println(1);
System.out.println(a[1]+" "+a[0]+" "+a[2]);
}
else if(n==4)
{
System.out.println(1);
System.out.println(a[1]+" "+a[0]+" "+a[2]+" "+a[3]);
}
else if((n & 1)==1)
{
long f=(2*n)/5;
if(n>5)
f++;
int x=(n-1)/2;
int m=0;
for(int i=1;i<n;i+=2)
{
b[i]=a[m++];}
for(int i=0;i<n;i+=2)
{
b[i]=a[m++];
}
System.out.println((n-1)/2);
for(long z:b)
System.out.print(z+" ");
}
else
{
long q=n-1;
long f=(2*q)/5;
if(q>5)
f++;
int x=(n-1)/2;
int m=0;
for(int i=1;i<n;i+=2)
{
b[i]=a[m++];}
for(int i=0;i<n;i+=2)
{
b[i]=a[m++];
}
System.out.println((n-1)/2);
for(long z:b)
System.out.print(z+" ");
}
System.out.println();
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 8050a59c81052d0613fb46edfa0a6b6b | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class SagesBirthday {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int buys = 0;
int cakes = sc.nextInt();
int[] arr = new int[cakes];
for(int i = 0;i < cakes; i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
for(int i = 1; i < arr.length-1; i+=2){
if(i == 1){
int tmp = arr[0];
int tmp1 = arr[1];
arr[0] = arr[2];
arr[1] = tmp;
arr[2] = tmp1;
}else{
int tmp = arr[i-1];
arr[i-1] = arr[i];
arr[i] = tmp;}
}
for(int i = 1; i < arr.length-1; i++){
if(arr[i-1] > arr[i] && arr [i] < arr[i+1])
buys++;
}
System.out.println(buys);
for(int i : arr)
System.out.print(i + " ");
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | be0fa3c640d08c532a9400d5463cda02 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class SagesBirthday {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int buys = 0;
int cakes = sc.nextInt();
int[] arr = new int[cakes];
for(int i = 0;i < cakes; i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
for(int i = 1; i < arr.length-1; i+=2){
if(i == 1){
int tmp = arr[0];
int tmp1 = arr[1];
arr[0] = arr[2];
arr[1] = tmp;
arr[2] = tmp1;
}else{
int tmp = arr[i-1];
arr[i-1] = arr[i];
arr[i] = tmp;
}
if(arr[i-1] > arr[i] && arr [i] < arr[i+1])
buys++;
}
System.out.println(buys);
for(int i : arr)
System.out.print(i + " ");
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | bab5e8c32d24d5e8434b43a0069e8643 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class Sage
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long ar[]= new long[n];
long ar1[]=new long[n];
for(int i =0;i<n;i++)
ar[i]=sc.nextLong();
Arrays.sort(ar);
int j=1;
for( int i = 0;i<n/2;i++)
{
ar1[j]=ar[i];
j=j+2;
}
j=0;
for( int i = n/2;i<n;i++)
{
ar1[j]=ar[i];
j=j+2;
}
int sum=0;
for(int k=1;k<n-1;k++)
{
if(ar1[k]<ar1[k-1] && ar1[k]<ar1[k+1])
sum++;
}
System.out.println(sum);
for(int j1=0;j1<n;j1++)
System.out.print(ar1[j1] +" ");
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 28362d89d2616913e72cd9a90a5376d2 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class Yo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
if(n%2==0)
System.out.println(n/2-1);
else
System.out.println(n/2);
int k=n/2;
int j=0;
for(int i=0;i<n;i++)
{
if(i%2==0)
System.out.print(arr[k++]+" ");
else
System.out.print(arr[j++]+" ");
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 8fd2109789034b1aaf0b85e364647a00 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | //package ru.ilinchik.codeforces;
import java.util.Arrays;
import java.util.Scanner;
public class D671 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
solve(a);
in.close();
}
private static void solve(int[] a) {
Arrays.sort(a);
System.out.println(a.length % 2 != 0 ? a.length / 2 : a.length / 2 - 1);
int l = 0;
for (int i = a.length / 2; i < a.length; i++) {
System.out.print(a[i]);
if (l < a.length / 2) System.out.print(" " + a[l++] + " ");
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 313ce9eb73f8dbaa0411e33a6f8ae60f | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
int q=t;
ArrayList<Integer> arr = new ArrayList<Integer>();
while(q-->0){
int p = s.nextInt();
arr.add(p);
}
Collections.sort(arr);
int ans = 1;
if(t%2==0) ans = t/2-1;
else ans = t/2;
//if(ans==0) ans=1;
System.out.println(ans);
for(int i =0 ;i<t/2 ; i++){
System.out.print(arr.get(i+t/2)+" ");
System.out.print(arr.get(i)+" ");
}
if(t%2!=0) System.out.print(arr.get(arr.size()-1));
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 6670234a452e5880c0fbb3ff3b75d00c | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class T4 {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
long n = Long.parseLong(br.readLine());
List<Long> a = Arrays.stream(br.readLine().split(" ")).map(Long::parseLong).sorted().collect(Collectors.toList());
solve(n, a);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void solve(long n, List<Long> a) {
if (n<=2) {
System.out.println("0");
for (int i = 0; i < a.size(); i++) {
System.out.print(a.get(i) + " ");
}
} else {
System.out.println((n-1)/2);
for (int i = 0; i < a.size()-1; i+=2) {
System.out.print(a.get(i+1) + " " + a.get(i) + " ");
}
if (n%2==1) {
System.out.print(a.get(a.size()-1));
}
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 00420bb85132dbfbeb520ca085145d5f | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
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);
Solution.solve(in, out);
out.close();
}
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 double nextDouble() {
return Double.parseDouble(next());
}
public long[] readArray(int n)
{
long[] arr=new long[n];
for(int i=0;i<n;i++) arr[i]=nextLong();
return arr;
}
}
}
class Solution
{
public static void solve(Main.InputReader in, PrintWriter out)
{
int n=in.nextInt();
long[] arr=in.readArray(n);
Arrays.sort(arr);
long[] ans=new long[n];
int count=0;
int res=(n-1)/2;
for(int i=1;i<n;i+=2,count++) ans[i]=arr[count];
for(int i=0;i<n;i+=2,count++)ans[i]=arr[count];
out.println(res);
for(long i:ans) out.print(i+" ");
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | bf68f6899821cc3e048ad8e135fdb409 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
static long MOD = (long) (1e9 + 7);
static long powerLL(long x, long n)
{
long result = 1;
while (n > 0)
{
if (n % 2 == 1)
{
result = result * x % MOD;
}
n = n / 2;
x = x * x % MOD;
}
return result;
}
static long powerStrings(String sa, String sb)
{
long a = 0, b = 0;
for (int i = 0; i < sa.length(); i++)
{
a = (a * 10 + (sa.charAt(i) - '0')) %
MOD;
}
for (int i = 0; i < sb.length(); i++)
{
b = (b * 10 + (sb.charAt(i) - '0')) %
(MOD - 1);
}
return powerLL(a, b);
}
static long gcd(long a, long b)
{
if (a==0) return b;
else return gcd(b%a,a);
}
static long lcm(long a, long b)
{
return (a*b)/gcd(a,b);
}
static int lower_bound(List<Integer> list, int k)
{
int s = 0;
int e = list.size();
while (s!=e)
{
int mid = (s+e)>>1;
if (list.get(mid)<k) s = mid+1;
else e = mid;
}
if (s == list.size()) return -1;
return s;
}
static int upper_bound(List<Integer> list, int k)
{
int s = 0;
int e = list.size();
while (s!=e)
{
int mid = (s+e)>>1;
if (list.get(mid)<=k) s = mid+1;
else e = mid;
}
if (s == list.size()) return -1;
return s;
}
public static void main(String[] args) throws java.lang.Exception
{
try
{
//FastReader fr = new FastReader();
Reader fr = new Reader();
try(OutputStream out = new BufferedOutputStream(System.out))
{
int n = fr.nextInt();
List<Long> list = new ArrayList<>();
for (int i=0;i<n;i++) list.add(fr.nextLong());
Collections.sort(list);
long[] arr = new long[n];
if (n<=2)
{
out.write((0+"\n").getBytes());
for (long i : list) out.write((i+" ").getBytes());
}
else
{
int k = 0;
for (int i=1;i<n;i+=2) arr[i] = list.get(k++);
for (int i=0;i<n;i+=2) arr[i] = list.get(k++);
long ans = 0;
if ((n&1) == 1) ans = (n>>1);
else ans = (n>>1)-1;
out.write((ans+"\n").getBytes());
for (long i : arr) out.write((i+" ").getBytes());
}
out.flush();
}
}
catch(Exception e){}
finally{}
}
}
//(()) () (()((()()()()))) | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 1ae5ba2483707bfb15f24d68a84a833e | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import com.sun.source.tree.Tree;
import javax.naming.spi.DirObjectFactory;
import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.nio.file.LinkOption;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
try (PrintWriter or = new PrintWriter(System.out)) {
int t = 1;
while (t-->0){
int n = in.nextInt();
Integer[]a=new Integer[n];
for (int i = 0; i < n; i++) {
a[i]=in.nextInt();
}
Arrays.sort(a);
int[]ans=new int[n];
if (n==2){
or.println(0);
or.println(a[0]+" "+a[1]);
continue;
}
or.println((n-1)/2);
int idx=0;
for (int i = n/2; i < n&&idx<n; i++,idx+=2) {
ans[idx]=a[i];
}
idx=1;
for (int i = 0; i < n&&idx<n; i++,idx+=2) {
ans[idx]=a[i];
}
for(int y:ans)or.print(y+" ");
or.println();
}
}
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | be86d52bfa5a25ef7ba7576ae215c0af | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
public class SagesBirthday
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
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 printLine(Object...objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush() {
writer.flush();
}
}
public static void main(String ags[])
{
FastReader sc=new FastReader();
OutputWriter out=new OutputWriter(System.out);
int n=sc.nextInt();
List<Integer> list=new ArrayList();
for(int i=0;i<n;i++)
{
int a=sc.nextInt();
list.add(a);
}
if(n%2==0)
System.out.println((n-1)/2);
else
System.out.println(n/2);
if(n==1)
{
System.out.println(list.get(0));
System.exit(0);
}
if(n==2)
{
System.out.println(list.get(0)+" "+list.get(1));
System.exit(0);
}
Collections.sort(list);
Integer as[]=new Integer[list.size()];
as=list.toArray(as);
Integer des[]=as.clone();
int i=0,j=list.size()-1,c=0;
while(as[i]!=des[j])
{
if(c%2==0)
{
out.print(des[j]+" ");
j--;
}
else
{
out.print(as[i]+" ");
i++;
}
c++;
}
out.printLine(as[i]);
out.flush();
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 992baf8af84c1bebacb7c32def2db2e2 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.Writer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.concurrent.TimeUnit;
public class D{
static class pair{
int val, idx;
pair(int a, int b){
val=a;
idx=b;
}
public String toString(){
return "(val: "+val+" idx: "+idx+")";
}
}
static class ProblemSolver{
public void solveTheProblem(InputReader in,OutputWriter out, NumberTheory nt){
int test=1;//in.nextInt();
while(test-- >0){
int n;
n=in.nextInt();
int ar[]= new int[n];
ar=in.nextIntArray(n);
Arrays.sort(ar);
if(n==1){
out.println(0);
out.println(ar[0]);
continue;
}
int k=(n%2==0)? (n-1)/2:n/2;
int temp=0;
String s="";
out.println(k);
for(int i=k;i<n;i++){
if(temp<k)
out.print(ar[i]+" "+ar[temp++]+" ");
// s+=ar[i]+" "+ar[temp++]+" ";
else out.print(ar[i]+" ");
// s+=ar[i]+" ";
}
out.println();
// if(n%2!=0) s+=n;
// out.println(s.trim());
}
}
}
public static void main(String[] args)throws InterruptedException{
int checkTimeELAPSED=0;
if(checkTimeELAPSED==0){
InputStream inputStream=System.in;
OutputStream outputStream=System.out;
InputReader in=new InputReader(inputStream);
OutputWriter out=new OutputWriter(outputStream);
NumberTheory nt= new NumberTheory();
ProblemSolver problemSolver=new ProblemSolver();
problemSolver.solveTheProblem(in,out, nt);
out.flush();
out.close();
}
else{
long startTime = System.nanoTime();
InputStream inputStream=System.in;
OutputStream outputStream=System.out;
InputReader in=new InputReader(inputStream);
OutputWriter out=new OutputWriter(outputStream);
NumberTheory nt= new NumberTheory();
ProblemSolver problemSolver=new ProblemSolver();
problemSolver.solveTheProblem(in,out, nt);
long endTime = System.nanoTime();
long timeElapsed = endTime - startTime;
out.println("Execution time in nanoseconds : " + timeElapsed);
out.println("Execution time in milliseconds : "+ timeElapsed / 1000000);
out.println("Execution time in seconds : "+ timeElapsed / 1000000000);
out.flush();
out.close();
}
}
static class InputReader {
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private 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 peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
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 long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long 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 String nextLine() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextLine());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextLine();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n){
int[] array=new int[n];
for(int i=0;i<n;++i)array[i]=nextInt();
return array;
}
public int[] nextIntSortedArray(int n){
int array[]=nextIntArray(n);
Arrays.sort(array);
return array;
}
public ArrayList<Integer> nextIntArrayList(int n){
ArrayList<Integer> ar= new ArrayList<>();
for(int i=0;i<n;i++)
ar.add(nextInt());
return ar;
}
public ArrayList<Long> nextLongArrayList(int n){
ArrayList<Long> ar= new ArrayList<>();
for(int i=0;i<n;i++)
ar.add(nextLong());
return ar;
}
public int[] nextSumIntArray(int n){
int[] array=new int[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public long[] nextLongArray(int n){
long[] array=new long[n];
for(int i=0;i<n;++i)array[i]=nextLong();
return array;
}
public long[] nextSumLongArray(int n){
long[] array=new long[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public long[] nextSortedLongArray(int n){
long array[]=nextLongArray(n);
Arrays.sort(array);
return array;
}
public int[][] nextIntMatrix(int n,int m){
int[][] matrix=new int[n][m];
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
matrix[i][j]=nextInt();
return matrix;
}
public int[][] nextIntMatrix(int n){
return nextIntMatrix(n,n);
}
public long[][] nextLongMatrix(int n,int m){
long[][] matrix=new long[n][m];
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
matrix[i][j]=nextLong();
return matrix;
}
public long[][] nextLongMatrix(int n){
return nextLongMatrix(n,n);
}
public char[][] nextCharMatrix(int n,int m){
char[][] matrix=new char[n][m];
for(int i=0;i<n;++i)
matrix[i]=next().toCharArray();
return matrix;
}
public char[][] nextCharMatrix(int n){
return nextCharMatrix(n,n);
}
}
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(char[] array) {
// writer.print(array);
// }
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void print(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(double[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(char[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(String[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(int[][] matrix){
for(int i=0;i<matrix.length;++i){
println(matrix[i]);
}
}
public void print(double[][] matrix){
for(int i=0;i<matrix.length;++i){
println(matrix[i]);
}
}
public void print(long[][] matrix){
for(int i=0;i<matrix.length;++i){
println(matrix[i]);
}
}
public void print(char[][] matrix){
for(int i=0;i<matrix.length;++i){
println(matrix[i]);
}
}
public void print(String[][] matrix){
for(int i=0;i<matrix.length;++i){
println(matrix[i]);
}
}
public void println(int[] array) {
print(array);
writer.println();
}
public void println(double[] array) {
print(array);
writer.println();
}
public void println(long[] array) {
print(array);
writer.println();
}
// public void println(char[] array) {
// print(array);
// writer.println();
// }
public void println(String[] array) {
print(array);
writer.println();
}
public void println() {
writer.println();
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void print(char i) {
writer.print(i);
}
public void println(char i) {
writer.println(i);
}
public void println(char[] array) {
writer.println(array);
}
public void printf(String format, Object... objects) {
writer.printf(format, objects);
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
public void print(long i) {
writer.print(i);
}
public void println(long i) {
writer.println(i);
}
public void print(int i) {
writer.print(i);
}
public void println(int i) {
writer.println(i);
}
public void separateLines(int[] array) {
for (int i : array) {
println(i);
}
}
}
static class NumberTheory{
/**
* Modular Arithmetic:
* 1. (a+b)%c=(a%c+b%c)%c
* 2. (a*b)%c=(a%c*b%c)%c
* 3. (a-b)%c=(a%c-b%c+c)%c
* 4. (a/b)%c=(a%c*(b^-1)%c)%c -- (b^-1 is multiplicative modulo inverse)
*/
//Modular Addition
public int modularAddition(int a,int b,int MOD){
return (a%MOD+b%MOD)%MOD;
}
public long modularAddition(long a,long b,long MOD){
return (a%MOD+b%MOD)%MOD;
}
//Modular Multiplication
public int modularMultiplication(int a,int b,int MOD){
return ((a%MOD)*(b%MOD))%MOD;
}
public long modularMultiplication(long a,long b,long MOD){
return ((a%MOD)*(b%MOD))%MOD;
}
//Modular Subtraction
public int modularSubtraction(int a,int b,int MOD){
return (a%MOD-b%MOD+MOD)%MOD;
}
public long modularSubtraction(long a,long b,long MOD){
return (a%MOD-b%MOD+MOD)%MOD;
}
/**
* Binary Exponentiation
*/
public int binaryExponentiation(int x,int n){
if(n==0)return 1;
else if(n%2==0)return binaryExponentiation(x*x,n/2);
else return x*binaryExponentiation(x*x,(n-1)/2);
}
public long binaryExponentiation(long x,long n){
long result=1;
while(n>0){
if(n%2==1)result*=x;
x=x*x;
n/=2;
}
return result;
}
/**
* Modular Exponentiation
*/
public int modularExponentiation(int x,int n,int MOD){
if(n==0)return 1%MOD;
else if(n%2==0)return modularExponentiation(modularMultiplication(x,x,MOD),n/2,MOD);
else return modularMultiplication(x,modularExponentiation(modularMultiplication(x,x,MOD),(n-1)/2,MOD),MOD);
}
public long modularExponentiation(long x,long n,long MOD){
long result=1;
while(n>0){
if(n%2==1)result=modularMultiplication(result,x,MOD);
x=modularMultiplication(x,x,MOD);
n/=2;
}
return result;
}
/**
* Factorial of a number
*/
public long factorials(long n){
if(n==0)return 1;
return n*factorials(n-1);
}
/**
* Prime factors of a number
*/
public ArrayList<Integer> distinctPrimeFactors(int n){
ArrayList<Integer> factorials=new ArrayList<>();
int limit=(int)Math.sqrt(n);
if(n%2==0){
factorials.add(2);
while(n%2==0)n/=2;
}
for(int i=3;i<=limit;i+=2){
if(n%i==0){
factorials.add(i);
while(n%i==0)n/=i;
}
}
if(n>2)factorials.add(n);
return factorials;
}
public ArrayList<Long> distinctPrimeFactors(long n){
ArrayList<Long> factorials=new ArrayList<>();
long limit=(long)Math.sqrt(n);
if(n%2==0){
factorials.add((long)2);
while(n%2==0)n/=2;
}
for(long i=3;i<=limit;i+=2){
if(n%i==0){
factorials.add(i);
while(n%i==0)n/=i;
}
}
if(n>2)factorials.add(n);
return factorials;
}
public ArrayList<Integer> primeFactors(int n){
ArrayList<Integer> factorials=new ArrayList<>();
int limit=(int)Math.sqrt(n);
if(n%2==0){
factorials.add(2);
while(n%2==0)n/=2;
}
for(int i=3;i<=limit;i+=2){
if(n%i==0){
factorials.add(i);
while(n%i==0)n/=i;
}
}
if(n>2)factorials.add(n);
return factorials;
}
public ArrayList<Long> primeFactors(long n){
ArrayList<Long> factorials=new ArrayList<>();
long limit=(long)Math.sqrt(n);
if(n%2==0){
factorials.add((long)2);
while(n%2==0)n/=2;
}
for(long i=3;i<=limit;i+=2){
if(n%i==0){
factorials.add(i);
while(n%i==0)n/=i;
}
}
if(n>2)factorials.add(n);
return factorials;
}
/**
* Combination: nCr
*/
//Naive version
//(n,r)=(n-1,r-1)+(n-1,r) for r!=0 or r!=n
//(n,0)=(n,n)=1
public int binomialCoefficientRecursive(int n,int k){
if(k==0 || k==n)return 1;//base case
return binomialCoefficientRecursive(n-1,k-1)+binomialCoefficientRecursive(n-1,k);//recursion
}
//Dynamic Programming version(Uses bottom up approach to fill the table)
//Time complexity: O(n*k)
//Space complexity: O(n*k)
public long binomialCoefficientIterative(int n,int k){
long[][] C=new long[n+1][k+1];
for(int i=0;i<=n;++i){
for(int j=0;j<=Math.min(n,k);++j){
if(j==0 || j==i)C[i][j]=1;
else C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}
return C[n][k];
}
//Pascal's Triangle version(Space efficient program)
//Time complexity: O(n*k)
//Space complexity: O(k)
public long nCr(int n,int r){
int[] C=new int[r+1];
C[0]=1;//nC0=1
for(int i=1;i<=n;++i)
for(int j=Math.min(i,r);j>0;--j)
C[j]=C[j]+C[j-1];
return C[r];
}
/**
* Catlan number:
* - Time complexity: O(n*n)
* - Auxiliary space: O(n)
*
* NOTE: Time complexity could be reduced to O(n) but it is
* possible if and only if n is small or else there is
* a chance of getting an overflow. To decrease the time
* complexity to O(n) just remember nCr=nCn-r
*/
public long catlanNumber(int n){
long[] catlan=new long[n+1];
catlan[0]=catlan[1]=1;
for(int i=2;i<=n;++i)
for(int j=0;j<i;++j)
catlan[i]+=catlan[j]*catlan[i-1-j];
return catlan[n];
}
/**
* Greatest Common Divisor(GCD)
* - It is also known as Highest Common Factor(HCF)
* - Time complexity: log(min(a,b))
* - Auxiliary Space: O(1)
*/
public int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a %b);
}
public long gcd(long a,long b){
if(b==0)return a;
return gcd(b,a%b);
}
/**
* Extended Euclid's Algorithm:
* - ax+by=gcd(a,b)
* - Time complexity:
* -
*/
/**
* Least Common Multiple(LCM):
* - Time complexity: log(min(a,b))
* - Auxiliary Space: O(1)
*/
public long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
}
}
//
// "8, .m8"
// I8Im ,mI8"
// ,8I""I8,mI8m
// "I8mm, ,I8 I8 "I8, ,m"
// "I88I88I8m ,I8" "I8""==mm ,mI8"
// ___ ,mI8" "8I8" I8, ,mI8I8"
// .,mI8I8I8I8I88, ,m8" ,I8I8I8I888"
// "I8Im, "I88, ,8" ,II8" "88,
// `"I8, "I8, ,8" ,I8" "I8,
// "I8m "I888 ,I8" "I8,
// "8m "I8 88" "I8,
// I8, I8 88 "I8,
// 88, I8, "I8 "I8
// "I8, "I8, "I8, I8;.
// "I8, "I8, "I8 .,mmmI8888888m,.
// I8, "I8, I8, .mI8I88"""". .. "I8888
// "I8, "I8 mI8I88"". . . . . .,m8" "8
// I8m, __ ;I8 ,II88" . . . . .,;miI88"
// "I88I8I88I88,,I88" . . . ,mmiiI8888"
// ,I8". . ."I8I8". . . mi888888888"
// ,I8 . . . .,I88I. . .i88888888888"
// I8. . . .,mII88Ima. .i88888888888"
// ,8"..,mI88I88I88I8Imi888888888888"
// I8.,I8I""" ""II88888888888
// ;I8I8" ""I8888888
// "" "I88888
// "I888
// "I88,
// "I88
// "88,
// I88, ______ __
// ______ "I88__ .mI88I88I88I88I88,
// .,mI88I88I88, ,mI88, I88""" ,mI8". . . . "I8,..8,
// ,I888' . . . "I88.\ "8, I88 ,I8". . . . / :;I8 \ 8,
// .mI8' . . . / .:"I8.\ 88 "88, ,8". . . / .;mI8I8I8,\ 8
// ,I8'. . . / . .:;,I8I8I888 I88 ,8". . / .:mI8"' "I8,:8
// ,I8'. . . / . .:;,mI8" `"I88 I88 I8. . / .m8" "I8I
// ,I8 . . / . .:;,mI8" "I88888 88,. / ,m8 "8'
// I8'. . / . .;,mI8" "II888 ,I8I8,.,I8"
// I8 . . / . .,mI8" I8888888' """
// `I8,. / ;,mI8" II888
// "I8I, /,mI8" __I888
// "I8888" """I88
// "" I88
// I88__
// I88"""
// I88
// I88
// __I88
// """I88
// I88
// I88
// I88__
// I88"""
// I88
// BITSY ___ CHUCK
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 50db91840d581b4a41e720c27de66cce | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
public class D1 {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
int ar[] = sc.nextIntArray(n);
sort(ar);
int ans[] = new int[n];
int k = 0;
for(int i = n-1; i >= 0 && k < n; i--) {
ans[k] = ar[i];
k += 2;
}
k = 1;
for(int i = 0; i < n && k < n; i++) {
ans[k] = ar[i];
k += 2;
}
int x = 0;
for(int i = 1; i < n - 1; i++)
if(ans[i] < ans[i-1] && ans[i] < ans[i+1])
x++;
println(x + "");
println(ans);
}
static final Random random = new Random();
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public List<Integer>[] adjacencyList(int nodes, int edges) {
return adjacencyList(nodes, edges, false);
}
public List<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) {
List<Integer>[] adj = new ArrayList[nodes + 1];
Arrays.setAll(adj, (i) -> new ArrayList<>());
for (int i = 0; i < edges; i++) {
int a = nextInt(), b = nextInt();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
static int findDistance(List<Integer> G[], int nodes, int src, int dst) {
LinkedList<Integer> queue = new LinkedList<>();
int dist[] = new int[nodes + 1];
int ans = -1;
dist[src] = 0;
queue.add(src);
while(queue.size() > 0) {
int u = queue.poll();
if(u == dst) {
ans = dist[u];
}
for(int v : G[u]) {
if(dist[v] >= 0)
continue;
queue.add(v);
dist[v] = dist[u] + 1;
}
}
return ans;
}
static void sort(int A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(long A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(double A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void shuffleArray(int[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
int tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(long[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
long tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(double[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
double tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static int[] subArray(int A[], int x, int y) {
int B[] = new int[y - x + 1];
for(int i = x; i <= y; i++)
B[i-x] = A[i];
return B;
}
static int[] toArray(List<Integer> L) {
return L.stream().mapToInt(x -> x).toArray();
}
static void println(int[] A) {
for(int e: A) System.out.print(e + " ");
System.out.println();
}
static void println(long[] A) {
for(long e: A) System.out.print(e + " ");
System.out.println();
}
static void println(List arr) {
for(Object e: arr) System.out.print(e + " ");
System.out.println();
}
static void print(String s) {
System.out.print(s);
}
static void println(String s) {
System.out.println(s);
}
static List<Integer> toList(int ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Long> toList(long ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Double> toList(double ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static long gcd(long a, long b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
private static int abs(int a){ return (a>=0) ? a: -a; }
private static int min(int... ins){ return Arrays.stream(ins).min().getAsInt(); }
private static int max(int... ins){ return Arrays.stream(ins).max().getAsInt(); }
private static int sum(int... ins){ return Arrays.stream(ins).sum(); }
private static long abs(long a){ return (a>=0) ? a: -a; }
private static long min(long... ins){ return Arrays.stream(ins).min().getAsLong(); }
private static long max(long... ins){ return Arrays.stream(ins).max().getAsLong(); }
private static long sum(long... ins){ return Arrays.stream(ins).sum(); }
private static double abs(double a){ return (a>=0) ? a: -a; }
private static double min(double... ins){ return Arrays.stream(ins).min().getAsDouble(); }
private static double max(double... ins){ return Arrays.stream(ins).max().getAsDouble(); }
private static double sum(double... ins){ return Arrays.stream(ins).sum(); }
private static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) { this.x = x; this.y = y; }
Pair() {}
@Override
public int compareTo(Pair other) {
return x == other.x ? y - other.y : x - other.x;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return x == pair.x &&
y == pair.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 6b33663b1ccee86e954b90dae8c7d5e8 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
public class D1 {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
int ar[] = sc.nextIntArray(n);
sort(ar);
for(int i = 0; i < n-1; i+=2) {
int tmp = ar[i];
ar[i] = ar[i+1];
ar[i+1] = tmp;
}
int x = 0;
for(int i = 1; i < n - 1; i++)
if(ar[i] < ar[i-1] && ar[i] < ar[i+1])
x++;
println(x + "");
println(ar);
}
static final Random random = new Random();
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public List<Integer>[] adjacencyList(int nodes, int edges) {
return adjacencyList(nodes, edges, false);
}
public List<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) {
List<Integer>[] adj = new ArrayList[nodes + 1];
Arrays.setAll(adj, (i) -> new ArrayList<>());
for (int i = 0; i < edges; i++) {
int a = nextInt(), b = nextInt();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
static int findDistance(List<Integer> G[], int nodes, int src, int dst) {
LinkedList<Integer> queue = new LinkedList<>();
int dist[] = new int[nodes + 1];
int ans = -1;
dist[src] = 0;
queue.add(src);
while(queue.size() > 0) {
int u = queue.poll();
if(u == dst) {
ans = dist[u];
}
for(int v : G[u]) {
if(dist[v] >= 0)
continue;
queue.add(v);
dist[v] = dist[u] + 1;
}
}
return ans;
}
static void sort(int A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(long A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(double A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void shuffleArray(int[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
int tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(long[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
long tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(double[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
double tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static int[] subArray(int A[], int x, int y) {
int B[] = new int[y - x + 1];
for(int i = x; i <= y; i++)
B[i-x] = A[i];
return B;
}
static int[] toArray(List<Integer> L) {
return L.stream().mapToInt(x -> x).toArray();
}
static void println(int[] A) {
for(int e: A) System.out.print(e + " ");
System.out.println();
}
static void println(long[] A) {
for(long e: A) System.out.print(e + " ");
System.out.println();
}
static void println(List arr) {
for(Object e: arr) System.out.print(e + " ");
System.out.println();
}
static void print(String s) {
System.out.print(s);
}
static void println(String s) {
System.out.println(s);
}
static List<Integer> toList(int ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Long> toList(long ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Double> toList(double ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static long gcd(long a, long b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
private static int abs(int a){ return (a>=0) ? a: -a; }
private static int min(int... ins){ return Arrays.stream(ins).min().getAsInt(); }
private static int max(int... ins){ return Arrays.stream(ins).max().getAsInt(); }
private static int sum(int... ins){ return Arrays.stream(ins).sum(); }
private static long abs(long a){ return (a>=0) ? a: -a; }
private static long min(long... ins){ return Arrays.stream(ins).min().getAsLong(); }
private static long max(long... ins){ return Arrays.stream(ins).max().getAsLong(); }
private static long sum(long... ins){ return Arrays.stream(ins).sum(); }
private static double abs(double a){ return (a>=0) ? a: -a; }
private static double min(double... ins){ return Arrays.stream(ins).min().getAsDouble(); }
private static double max(double... ins){ return Arrays.stream(ins).max().getAsDouble(); }
private static double sum(double... ins){ return Arrays.stream(ins).sum(); }
private static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) { this.x = x; this.y = y; }
Pair() {}
@Override
public int compareTo(Pair other) {
return x == other.x ? y - other.y : x - other.x;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return x == pair.x &&
y == pair.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 8e0e2dc533672c7bfb3581b6db8e088a | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader in = new FastReader();
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int n = in.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;++i)
arr[i] = in.nextInt();
Arrays.sort(arr);
if(n<=2){
out.println(0);
for(int i=0;i<n;++i)
out.print(arr[i]+" ");
out.close();
}
int[] formatted = new int[n];
int ans = (int)Math.ceil((n-2)/2.0);
for(int i=1;i<n;i+=2)
formatted[i] = arr[i/2];
for(int i=0;i<n;i+=2)
formatted[i] = arr[i/2+ans];
out.println(ans);
if(n%2==0)
formatted[n-1] = arr[n-1];
for(int i=0;i<n;++i)
out.print(formatted[i]+" ");
out.close();
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | a55c35dc40f534c403c8dafd5c2a9514 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Main o = new Main();
int n = in.nextInt();
long[] arr = new long[n];
for (int i = 0; i < n; ++i) arr[i] = in.nextInt();
Arrays.sort(arr);
long[] ordered = new long[n];
int pointer = 0;
for (int i = (n/2-1)+1; i < n && pointer < n; i++) {
ordered[pointer] = arr[i];
pointer += 2;
}
pointer = 1;
for (int i = 0; i < (n-(n/2-1)) && pointer < n; i++) {
ordered[pointer] = arr[i];
pointer += 2;
}
System.out.println(n%2 == 0 ? n/2-1 : n/2);
for (long i : ordered) System.out.print(i + " ");
in.close();
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | bbf9c669ea035b5007c0ffde709a4d9e | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
public class D_671_1 {
static int p=1000000007;
public static void main(String[] args) throws Exception{
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
FastReader sc=new FastReader();
// long k = sc.nextLong();
int n=sc.nextInt();
String inp[]=sc.nextLine().split(" ");
Integer ar[]=new Integer[n];
for(int i=0;i<n;i++)
{
ar[i]=Integer.parseInt(inp[i]);
}
Arrays.sort(ar);
StringBuilder sb=new StringBuilder();
int c=0;
for(int i=0;i<n/2;i++)
{
c++;
sb.append(ar[n-1-i]+" "+ar[i]+" ");
}
if(n%2!=0)
{
sb.append(ar[n-1-n/2]);
}
c=n%2==0?(n/2)-1:n/2;
System.out.println(c);
System.out.println(sb.toString());
// out.write(sb.toString());
out.flush();
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 4b333ecce0c657c9a788c4d5430030d6 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.io.*;
import java.util.*;
public class D_671_1 {
static int p=1000000007;
public static void main(String[] args) throws Exception{
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
FastReader sc=new FastReader();
// long k = sc.nextLong();
int n=sc.nextInt();
String inp[]=sc.nextLine().split(" ");
Integer ar[]=new Integer[n];
HashMap<Integer,Integer> h1=new HashMap<>();
for(int i=0;i<n;i++)
{
ar[i]=Integer.parseInt(inp[i]);
h1.put(ar[i],h1.getOrDefault(ar[i],0)+1);
}
Arrays.sort(ar);
int sm=-1,lm=-1;
int res[]=new int[n];
int i=0;
int j=n/2;
StringBuilder sb=new StringBuilder();
for(int k=0;k<n;k++)
{
if(k%2==0)
res[k]=ar[j+i];
else
res[k]=ar[i++];
sb.append(res[k]+" ");
}
int c=0;
for(i=1;i+1<n;i++)
{
if(res[i-1]>res[i]&&res[i+1]>res[i])
c++;
}
System.out.println(c);
System.out.println(sb.toString());
// out.write(sb.toString());
out.flush();
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | ef1739a90fd183b68ae71886c2349985 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
import java.io.*;
public class D {
static FastReader f = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
//int t = f.nextInt();
//while(t-- > 0)
solve();
out.close();
}
static void solve() {
int n = f.nextInt();
if(n == 1) {
out.println(0);
out.println(f.nextInt());
return;
}
int[] ans = new int[n];
int[] arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = f.nextInt();
}
Arrays.sort(arr);
int max = n-2, min = 0;
ans[0] = arr[n-1];
for(int i = 1;i<n;i++) {
if(i % 2 == 0) {
ans[i] = arr[max];
max--;
} else {
ans[i] = arr[min];
min++;
}
}
int cnt = 0;
for(int i=1;i<n-1;i++) {
if(ans[i-1] > ans[i] && ans[i] < ans[i+1])
cnt++;
}
out.println(cnt);
for(int i : ans) {
out.print(i+" ");
}
}
static class FastReader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch(IOException ioe) {
ioe.printStackTrace();
}
return s;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 5da5ff081c76f1e7d14b8612bbdb8f6c | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class Birthday
{
public static void process()throws IOException
{
int n = ni();
int[] a = nai(n);
ruffleSort(a);
if(n == 1 || n == 2){
pn(0);
for(int i = 0; i < n; i++)
p(a[i]+" ");
pn("");
return;
}
pn((n-1)/2);
for(int i = 1; i < n; i+=2){
p(a[i]+" "+a[i-1]+" ");
}
if(n%2 == 1)
pn(a[n-1]);
else
pn("");
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
//t=ni();
while(t-->0) {process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static long power(long k, long c, long mod){
long y = 1;
while(c > 0){
if(c%2 == 1)
y = y * k % mod;
c = c/2;
k = k * k % mod;
}
return y;
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n = a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 3b002f0ca75d8b3e8e176c443ad5012c | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class Birthday
{
public static void process()throws IOException
{
int n = ni();
int[] a = nai(n);
ruffleSort(a);
int c = 0, total = 0;
int[] ans = new int[n];
for(int i = 1; i < n-1; i+=2){
ans[i] = a[c];
a[c] = -1;
c++;
}
if(n%2 == 0){
ans[n-1] = a[c];
a[c] = -1;
}
c = 0;
for(int i = 0; i < n; i++){
if(a[i] != -1){
ans[c] = a[i];
c += 2;
if(c == n)
c--;
}
}
for(int i = 1; i < n-1; i++){
if(ans[i] < ans[i-1] && ans[i] < ans[i+1])
total++;
}
pn(total);
for(int i : ans)
p(i+" ");
pn("");
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
//t=ni();
while(t-->0) {process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static long power(long k, long c, long mod){
long y = 1;
while(c > 0){
if(c%2 == 1)
y = y * k % mod;
c = c/2;
k = k * k % mod;
}
return y;
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n = a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 298c3adaa40d656240c6268e17555b46 | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<n;i++)
list.add(sc.nextInt());
Collections.sort(list);
System.out.println((list.size()-1)/2);
for(int i=0,j=list.size()-1,k=0;k<list.size();k++)
{
if(k%2!=0)
System.out.print(list.get(i++)+" ");
else
System.out.print(list.get(j--)+" ");
}
/*int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int k=sc.nextInt();
int arr[]=new int[n];
int cnt=0,neg=0,pos=0;
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
if(arr[i]==k)
cnt++;
else if(arr[i]>k)
neg+=arr[i]-k;
else
pos+=k-arr[i];
}
if(cnt==n)
System.out.println(0);
else if(pos==neg)
System.out.println(1);
else
{
System.out.println(pos);
if((pos+neg)%2==0)
System.out.println(2);
else
System.out.println(3);
}
}*/
}
} | Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | aecc650beb4198dd8bd1d2f2261fc3ba | train_000.jsonl | 1600526100 | This is the easy version of the problem. The difference between the versions is that in the easy version all prices $$$a_i$$$ are different. You can make hacks if and only if you solved both versions of the problem.Today is Sage's birthday, and she will go shopping to buy ice spheres. All $$$n$$$ ice spheres are placed in a row and they are numbered from $$$1$$$ to $$$n$$$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int n = sc.nextInt();
long[] x = new long[n];
for(int i=0;i<n;i++)
x[i] = sc.nextLong();
Arrays.sort(x);
long[] ans = new long[n];
int j=0;
for(int i=1;i<n;i+=2)
ans[i] = x[j++];
for(int i=0;i<n;i+=2)
ans[i] = x[j++];
long a=0;
for(int i=1;i<n-1;i++){
if(ans[i-1]>ans[i]&& ans[i]<ans[i+1])
a++;
}
System.out.println(a);
for(int i=0;i<n;i++)
System.out.print(ans[i]+" ");
System.out.println();
}
}
| Java | ["5\n1 2 3 4 5"] | 1 second | ["2\n3 1 4 2 5"] | NoteIn the example it's not possible to place ice spheres in any order so that Sage would buy $$$3$$$ of them. If the ice spheres are placed like this $$$(3, 1, 4, 2, 5)$$$, then Sage will buy two spheres: one for $$$1$$$ and one for $$$2$$$, because they are cheap. | Java 11 | standard input | [
"constructive algorithms",
"binary search",
"sortings",
"greedy"
] | bcd9439fbf6aedf6882612d5f7d6220f | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of ice spheres in the shop. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ — the prices of ice spheres. | 1,000 | In the first line print the maximum number of ice spheres that Sage can buy. In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them. | standard output | |
PASSED | 039831ae03d8a9784aaf5283c43d7a02 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.io.*;
import java.util.*;
public class Main{
//public static Reader sc = new Reader();
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException{
String s = br.readLine();
TreeSet<Character> tr = new TreeSet<Character>();
out.println("Mike");
tr.add(s.charAt(0));
for (int i = 01; i < s.length(); i++) {
if (tr.first() < s.charAt(i)) {
out.println("Ann");
}
else {
out.println("Mike");
}
tr.add(s.charAt(i));
}
out.close();
}
static long ceil(long a, long b) {
return (a+b-1)/b;
}
static long powMod(long base, long exp, long mod) {
if (base == 0 || base == 1) return base;
if (exp == 0) return 1;
if (exp == 1) return base % mod;
long R = powMod(base, exp/2, mod) % mod;
R *= R;
R %= mod;
if ((exp & 1) == 1) {
return base * R % mod;
}
else return R % mod;
}
static long pow(long base, long exp) {
if (base == 0 || base == 1) return base;
if (exp == 0) return 1;
if (exp == 1) return base;
long R = pow(base, exp/2);
if ((exp & 1) == 1) {
return R * R * base;
}
else return R * R;
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
{
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, Integer.max(cnt-1, 0));
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 1842314ad911a16c65a45c721d34e7dd | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes |
import java.util.*;
public class B {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
char a[] = sc.next().toCharArray();
System.out.println("Mike");
char min = a[0];
for(int i = 1 ;i < a.length ;i++) {
if(a[i] > min) {
sb.append("Ann"+"\n");
}else {
sb.append("Mike"+"\n");
if(a[i] < min) {
min = a[i];
}
}
}
System.out.println(sb);
}
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | c121942e9205e4a5e853868b638959c3 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.io.*;
public final class Codeforces{
public static void main(String[] args) throws IOException{
StringBuffer buff=new StringBuffer();
BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
String s=buffer.readLine();
int n=s.length();
String alpha=new String("abcdefghijklmnopqrstuvwxyz");
char min=(char)123;
for(int i=0;i<n;i++){
char ch=s.charAt(i);
if(ch>min){
buff.append("Ann"+"\n");
}
else{
buff.append("Mike"+"\n");
min=ch;
}
}
System.out.print(buff);
buffer.close();
}
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 2074faee828619a75564c5a08139f1dd | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.awt.Point;
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Winner {
static class Solver {
public void solve(MyReader in, PrintWriter out) {
String s = in.next();
int n = s.length();
char min = s.charAt(0);
boolean[] hasLess = new boolean[n];
hasLess[0] = false;
for(int i= 1;i<n;i++){
char c = s.charAt(i);
if(c > min)hasLess[i] = true;
else min = c;
}
for(var b : hasLess){
if(b)out.println("Ann");
else out.println("Mike");
}
}
}
public static void main(String[] args) {
MyReader mr = new MyReader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
new Solver().solve(mr, out);
out.close();
}
// static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}};
// static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}, {-1,-1},{-1,1}, {1,1}, {1,-1}};
static class MyReader {
BufferedReader br;
StringTokenizer st;
MyReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String res = "";
try {
res = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Integer[] nextIntegerArray(int n) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Long[] nextLongArray(int n) {
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
String[] nextStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = next();
}
return arr;
}
}
static void swap(int[] arr, int i, int j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 80aab9802e62ed74ffb413c730351b36 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println(solve(s));
sc.close();
}
static String solve(String s) {
char min = s.charAt(0);
List<String> result = Stream.of("Mike").collect(Collectors.toList());
for (int i = 1; i < s.length(); i++) {
char ch = s.charAt(i);
if (min < ch) {
result.add("Ann");
} else {
result.add("Mike");
min = ch;
}
}
return String.join("\n", result);
}
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | c27e3621b196f9363a7531e807547182 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
FastScanner sc=new FastScanner(System.in);
PrintWriter out=new PrintWriter(System.out);
String s=sc.next();
char c[]=s.toCharArray();
int pre[]=new int[c.length];
for(int i=0;i<c.length;i++){
if(i==0) pre[0]=0;
else pre[i]=c[i]>c[pre[i-1]]?pre[i-1]:i;
//System.out.println(pre[i]);
if(pre[i]<i) out.println("Ann");
else out.println("Mike");
}
out.flush();
out.close();
}
static class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
}
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++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
// Jacob Garbage
public int[] nextIntArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextInt();
return ret;
}
public long[] nextLongArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextLong();
return ret;
}
public int[][] next2DIntArray(int N, int M) {
int[][] ret = new int[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextIntArray(M);
return ret;
}
public double[] nextDoubleArray(int N) {
double[] ret = new double[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextDouble();
return ret;
}
public double[][] next2DDoubleArray(int N, int M) {
double[][] ret = new double[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextDoubleArray(M);
return ret;
}
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | fc966d70d8ab062d82a0f44e1c5825e2 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.Point;
// SHIVAM GUPTA :
//NSIT
//decoder_1671
// STOP NOT TILL IT IS DONE OR U DIE .
// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................
// ASCII = 48 + i ;// 2^28 = 268,435,456 > 2* 10^8 // log 10 base 2 = 3.3219
// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4
// FOR ANY ODD NO N : N,N-1,N-2
//ALL ARE PAIRWISE COPRIME
//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS
// two consecutive odds are always coprime to each other
// two consecutive even have always gcd = 2 ;
public class Main
{
// static int[] arr = new int[100002] ; // static int[] dp = new int[100002] ;
static PrintWriter out;
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
out=new PrintWriter(System.out);
}
String next(){
while(st==null || !st.hasMoreElements()){
try{
st= new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str=br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
////////////////////////////////////////////////////////////////////////////////////
public static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
/////////////////////////////////////////////////////////////////////////////////////////
public static int sumOfDigits(long n)
{
if( n< 0)return -1 ;
int sum = 0;
while( n > 0)
{
sum = sum + (int)( n %10) ;
n /= 10 ;
}
return sum ;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
public static long arraySum(int[] arr , int start , int end)
{
long ans = 0 ;
for(int i = start ; i <= end ; i++)ans += arr[i] ;
return ans ;
}
/////////////////////////////////////////////////////////////////////////////////
public static int mod(int x)
{
if(x <0)return -1*x ;
else return x ;
}
public static long mod(long x)
{
if(x <0)return -1*x ;
else return x ;
}
////////////////////////////////////////////////////////////////////////////////
public static void swapArray(int[] arr , int start , int end)
{
while(start < end)
{
int temp = arr[start] ;
arr[start] = arr[end];
arr[end] = temp;
start++ ;end-- ;
}
}
//////////////////////////////////////////////////////////////////////////////////
public static int[][] rotate(int[][] input){
int n =input.length;
int m = input[0].length ;
int[][] output = new int [m][n];
for (int i=0; i<n; i++)
for (int j=0;j<m; j++)
output [j][n-1-i] = input[i][j];
return output;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
public static int countBits(long n)
{
int count = 0;
while (n != 0)
{
count++;
n = (n) >> (1L) ;
}
return count;
}
/////////////////////////////////////////// ////////////////////////////////////////////////
public static boolean isPowerOfTwo(long n)
{
if(n==0)
return false;
if(((n ) & (n-1)) == 0 ) return true ;
else return false ;
}
/////////////////////////////////////////////////////////////////////////////////////
public static int min(int a ,int b , int c, int d)
{
int[] arr = new int[4] ;
arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;
return arr[0];
}
/////////////////////////////////////////////////////////////////////////////
public static int max(int a ,int b , int c, int d)
{
int[] arr = new int[4] ;
arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;
return arr[3];
}
///////////////////////////////////////////////////////////////////////////////////
public static String reverse(String input)
{
StringBuilder str = new StringBuilder("") ;
for(int i =input.length()-1 ; i >= 0 ; i-- )
{
str.append(input.charAt(i));
}
return str.toString() ;
}
///////////////////////////////////////////////////////////////////////////////////////////
public static boolean sameParity(long a ,long b )
{
long x = a% 2L; long y = b%2L ;
if(x==y)return true ;
else return false ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public static boolean isPossibleTriangle(int a ,int b , int c)
{
if( a + b > c && c+b > a && a +c > b)return true ;
else return false ;
}
////////////////////////////////////////////////////////////////////////////////////////////
static long xnor(long num1, long num2) {
if (num1 < num2) {
long temp = num1;
num1 = num2;
num2 = temp;
}
num1 = togglebit(num1);
return num1 ^ num2;
}
static long togglebit(long n) {
if (n == 0)
return 1;
long i = n;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
return i ^ n;
}
///////////////////////////////////////////////////////////////////////////////////////////////
public static int xorOfFirstN(int n)
{
if( n % 4 ==0)return n ;
else if( n % 4 == 1)return 1 ;
else if( n % 4 == 2)return n+1 ;
else return 0 ;
}
//////////////////////////////////////////////////////////////////////////////////////////////
public static int gcd(int a, int b )
{
if(b==0)return a ;
else return gcd(b,a%b) ;
}
public static long gcd(long a, long b )
{
if(b==0)return a ;
else return gcd(b,a%b) ;
}
////////////////////////////////////////////////////////////////////////////////////
public static int lcm(int a, int b ,int c , int d )
{
int temp = lcm(a,b , c) ;
int ans = lcm(temp ,d ) ;
return ans ;
}
///////////////////////////////////////////////////////////////////////////////////////////
public static int lcm(int a, int b ,int c )
{
int temp = lcm(a,b) ;
int ans = lcm(temp ,c) ;
return ans ;
}
////////////////////////////////////////////////////////////////////////////////////////
public static int lcm(int a , int b )
{
int gc = gcd(a,b);
return (a*b)/gc ;
}
public static long lcm(long a , long b )
{
long gc = gcd(a,b);
return (a*b)/gc ;
}
///////////////////////////////////////////////////////////////////////////////////////////
static boolean isPrime(long n)
{
if(n==1)
{
return false ;
}
boolean ans = true ;
for(long i = 2L; i*i <= n ;i++)
{
if(n% i ==0)
{
ans = false ;break ;
}
}
return ans ;
}
///////////////////////////////////////////////////////////////////////////
static int sieve = 1000000 ;
static boolean[] prime = new boolean[sieve + 1] ;
public static void sieveOfEratosthenes()
{
// FALSE == prime
// TRUE == COMPOSITE
// FALSE== 1
// time complexity = 0(NlogLogN)== o(N)
// gives prime nos bw 1 to N
for(int i = 4; i<= sieve ; i++)
{
prime[i] = true ;
i++ ;
}
for(int p = 3; p*p <= sieve; p++)
{
if(prime[p] == false)
{
for(int i = p*p; i <= sieve; i += p)
prime[i] = true;
}
p++ ;
}
}
///////////////////////////////////////////////////////////////////////////////////
public static void sortD(int[] arr , int s , int e)
{
sort(arr ,s , e) ;
int i =s ; int j = e ;
while( i < j)
{
int temp = arr[i] ;
arr[i] =arr[j] ;
arr[j] = temp ;
i++ ; j-- ;
}
return ;
}
public static void sortD(long[] arr , int s , int e)
{
sort(arr ,s , e) ;
int i =s ; int j = e ;
while( i < j)
{
long temp = arr[i] ;
arr[i] =arr[j] ;
arr[j] = temp ;
i++ ; j-- ;
}
return ;
}
/////////////////////////////////////////////////////////////////////////////////////////
public static long countSubarraysSumToK(long[] arr ,long sum )
{
HashMap<Long,Long> map = new HashMap<>() ;
int n = arr.length ;
long prefixsum = 0 ;
long count = 0L ;
for(int i = 0; i < n ; i++)
{
prefixsum = prefixsum + arr[i] ;
if(sum == prefixsum)count = count+1 ;
if(map.containsKey(prefixsum -sum))
{
count = count + map.get(prefixsum -sum) ;
}
if(map.containsKey(prefixsum ))
{
map.put(prefixsum , map.get(prefixsum) +1 );
}
else{
map.put(prefixsum , 1L );
}
}
return count ;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// KMP ALGORITHM : TIME COMPL:O(N+M)
// FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING
//RETURN THE ARRAYLIST OF INDEXES
// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING
public static ArrayList<Integer> kmpAlgorithm(String str , String pat)
{
ArrayList<Integer> list =new ArrayList<>();
int n = str.length() ;
int m = pat.length() ;
String q = pat + "#" + str ;
int[] lps =new int[n+m+1] ;
longestPefixSuffix(lps, q,(n+m+1)) ;
for(int i =m+1 ; i < (n+m+1) ; i++ )
{
if(lps[i] == m)
{
list.add(i-2*m) ;
}
}
return list ;
}
public static void longestPefixSuffix(int[] lps ,String str , int n)
{
lps[0] = 0 ;
for(int i = 1 ; i<= n-1; i++)
{
int l = lps[i-1] ;
while( l > 0 && str.charAt(i) != str.charAt(l))
{
l = lps[l-1] ;
}
if(str.charAt(i) == str.charAt(l))
{
l++ ;
}
lps[i] = l ;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n
// TOTIENT(N) = count of nos less than ornequal to n and greater than 1 whose gcd with n is 1
// or n and the no will be coprime in nature
//time : O(n*(log(logn)))
public static void eulerTotientFunction(int[] arr ,int n )
{
for(int i = 1; i <= n ;i++)arr[i] =i ;
for(int i= 2 ; i<= n ;i++)
{
if(arr[i] == i)
{
arr[i] =i-1 ;
for(int j =2*i ; j<= n ; j+= i )
{
arr[j] = (arr[j]*(i-1))/i ;
}
}
}
return ;
}
/////////////////////////////////////////////////////////////////////////////////////////////
public static long nCr(int n,int k)
{
long ans=1L;
k=k>n-k?n-k:k;
int j=1;
for(;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
///////////////////////////////////////////////////////////////////////////////////////////
public static ArrayList<Integer> allFactors(int n)
{
ArrayList<Integer> list = new ArrayList<>() ;
for(int i = 1; i*i <= n ;i++)
{
if( n % i == 0)
{
if(i*i == n)
{
list.add(i) ;
}
else{
list.add(i) ;
list.add(n/i) ;
}
}
}
return list ;
}
public static ArrayList<Long> allFactors(long n)
{
ArrayList<Long> list = new ArrayList<>() ;
for(long i = 1L; i*i <= n ;i++)
{
if( n % i == 0)
{
if(i*i == n)
{
list.add(i) ;
}
else{
list.add(i) ;
list.add(n/i) ;
}
}
}
return list ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
static final int MAXN = 10000001;
static int spf[] = new int[MAXN];
static void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
spf[i] = i;
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
if (spf[i] == i)
{
for (int j=i*i; j<MAXN; j+=i)
if (spf[j]==j)
spf[j] = i;
}
}
}
// The above code works well for n upto the order of 10^7.
// Beyond this we will face memory issues.
// Time Complexity: The precomputation for smallest prime factor is done in O(n log log n)
// using sieve.
// Where as in the calculation step we are dividing the number every time by
// the smallest prime number till it becomes 1.
// So, let’s consider a worst case in which every time the SPF is 2 .
// Therefore will have log n division steps.
// Hence, We can say that our Time Complexity will be O(log n) in worst case.
static Vector<Integer> getFactorization(int x)
{
Vector<Integer> ret = new Vector<>();
while (x != 1)
{
ret.add(spf[x]);
x = x / spf[x];
}
return ret;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
public static void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int[n1];
int R[] = new int[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
public static void sort(int arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
public static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
public static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
public static long knapsack(int[] weight,long value[],int maxWeight){
int n= value.length ;
//dp[i] stores the profit with KnapSack capacity "i"
long []dp = new long[maxWeight+1];
//initially profit with 0 to W KnapSack capacity is 0
Arrays.fill(dp, 0);
// iterate through all items
for(int i=0; i < n; i++)
//traverse dp array from right to left
for(int j = maxWeight; j >= weight[i]; j--)
dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]);
/*above line finds out maximum of dp[j](excluding ith element value)
and val[i] + dp[j-wt[i]] (including ith element value and the
profit with "KnapSack capacity - ith element weight") */
return dp[maxWeight];
}
///////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// to return max sum of any subarray in given array
public static long kadanesAlgorithm(long[] arr)
{
long[] dp = new long[arr.length] ;
dp[0] = arr[0] ;
long max = dp[0] ;
for(int i = 1; i < arr.length ; i++)
{
if(dp[i-1] > 0)
{
dp[i] = dp[i-1] + arr[i] ;
}
else{
dp[i] = arr[i] ;
}
if(dp[i] > max)max = dp[i] ;
}
return max ;
}
/////////////////////////////////////////////////////////////////////////////////////////////
public static long kadanesAlgorithm(int[] arr)
{
long[] dp = new long[arr.length] ;
dp[0] = arr[0] ;
long max = dp[0] ;
for(int i = 1; i < arr.length ; i++)
{
if(dp[i-1] > 0)
{
dp[i] = dp[i-1] + arr[i] ;
}
else{
dp[i] = arr[i] ;
}
if(dp[i] > max)max = dp[i] ;
}
return max ;
}
///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
public static long binarySerachGreater(int[] arr , int start , int end , int val)
{
// fing total no of elements strictly grater than val in sorted array arr
if(start > end)return 0 ; //Base case
int mid = (start + end)/2 ;
if(arr[mid] <=val)
{
return binarySerachGreater(arr,mid+1, end ,val) ;
}
else{
return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ;
}
}
//////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING
// JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive
//Function for swapping the characters at position I with character at position j
public static String swapString(String a, int i, int j) {
char[] b =a.toCharArray();
char ch;
ch = b[i];
b[i] = b[j];
b[j] = ch;
return String.valueOf(b);
}
//Function for generating different permutations of the string
public static void generatePermutation(String str, int start, int end)
{
//Prints the permutations
if (start == end-1)
System.out.println(str);
else
{
for (int i = start; i < end; i++)
{
//Swapping the string by fixing a character
str = swapString(str,start,i);
//Recursively calling function generatePermutation() for rest of the characters
generatePermutation(str,start+1,end);
//Backtracking and swapping the characters again.
str = swapString(str,start,i);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
public static long factMod(long n, long mod) {
if (n <= 1) return 1;
long ans = 1;
for (int i = 1; i <= n; i++) {
ans = (ans * i) % mod;
}
return ans;
}
/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
public static long power(long x ,long n)
{
//time comp : o(logn)
if(n==0)return 1L ;
if(n==1)return x;
long ans =1L ;
while(n>0)
{
if(n % 2 ==1)
{
ans = ans *x ;
}
n /= 2 ;
x = x*x ;
}
return ans ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public static long powerMod(long x, long n, long mod) {
//time comp : o(logn)
if(n==0)return 1L ;
if(n==1)return x;
long ans = 1;
while (n > 0) {
if (n % 2 == 1) ans = (ans * x) % mod;
x = (x * x) % mod;
n /= 2;
}
return ans;
}
//////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*
lowerBound - finds largest element equal or less than value paased
upperBound - finds smallest element equal or more than value passed
if not present return -1;
*/
public static long lowerBound(long[] arr,long k)
{
long ans=-1;
int start=0;
int end=arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]<=k)
{
ans=arr[mid];
start=mid+1;
}
else
{
end=mid-1;
}
}
return ans;
}
public static int lowerBound(int[] arr,int k)
{
int ans=-1;
int start=0;
int end=arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]<=k)
{
ans=arr[mid];
start=mid+1;
}
else
{
end=mid-1;
}
}
return ans;
}
public static long upperBound(long[] arr,long k)
{
long ans=-1;
int start=0;
int end=arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]>=k)
{
ans=arr[mid];
end=mid-1;
}
else
{
start=mid+1;
}
}
return ans;
}
public static int upperBound(int[] arr,int k)
{
int ans=-1;
int start=0;
int end=arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]>=k)
{
ans=arr[mid];
end=mid-1;
}
else
{
start=mid+1;
}
}
return ans;
}
//////////////////////////////////////////////////////////////////////////////////////////
public static void printArray(int[] arr , int si ,int ei)
{
for(int i = si ; i <= ei ; i++)
{
out.print(arr[i] +" ") ;
}
}
public static void printArrayln(int[] arr , int si ,int ei)
{
for(int i = si ; i <= ei ; i++)
{
out.print(arr[i] +" ") ;
}
out.println() ;
}
public static void printLArray(long[] arr , int si , int ei)
{
for(int i = si ; i <= ei ; i++)
{
out.print(arr[i] +" ") ;
}
}
public static void printLArrayln(long[] arr , int si , int ei)
{
for(int i = si ; i <= ei ; i++)
{
out.print(arr[i] +" ") ;
}
out.println() ;
}
public static void printtwodArray(int[][] ans)
{
for(int i = 0; i< ans.length ; i++)
{
for(int j = 0 ; j < ans[0].length ; j++)out.print(ans[i][j] +" ");
out.println() ;
}
out.println() ;
}
static long modPow(long a, long x, long p) {
//calculates a^x mod p in logarithmic time.
long res = 1;
while(x > 0) {
if( x % 2 != 0) {
res = (res * a) % p;
}
a = (a * a) % p;
x /= 2;
}
return res;
}
static long modInverse(long a, long p) {
//calculates the modular multiplicative of a mod m.
//(assuming p is prime).
return modPow(a, p-2, p);
}
static long modBinomial(long n, long k, long p) {
// calculates C(n,k) mod p (assuming p is prime).
long numerator = 1; // n * (n-1) * ... * (n-k+1)
for (int i=0; i<k; i++) {
numerator = (numerator * (n-i) ) % p;
}
long denominator = 1; // k!
for (int i=1; i<=k; i++) {
denominator = (denominator * i) % p;
}
// numerator / denominator mod p.
return ( numerator* modInverse(denominator,p) ) % p;
}
/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
static ArrayList<Integer>[] tree ;
// static long[] child;
// static int mod= 1000000007 ;
// static int[][] pre = new int[3001][3001];
// static int[][] suf = new int[3001][3001] ;
//program to calculate noof nodes in subtree for every vertex including itself
public static void countNoOfNodesInsubtree(int child ,int par , int[] dp)
{
int count = 1 ;
for(int x : tree[child])
{
if(x== par)continue ;
countNoOfNodesInsubtree(x,child,dp) ;
count= count + dp[x] ;
}
dp[child] = count ;
}
public static void depth(int child ,int par , int[] dp , int d )
{
dp[child] =d ;
for(int x : tree[child])
{
if(x== par)continue ;
depth(x,child,dp,d+1) ;
}
}
public static void dfs(int sv , boolean[] vis)
{
vis[sv] = true ;
for(int x : tree[sv])
{
if( !vis[x])
{
dfs(x ,vis) ;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
public static void solve()
{
FastReader scn = new FastReader() ;
//Scanner scn = new Scanner(System.in);
//int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;
// product of first 11 prime nos is greater than 10 ^ 12;
//ArrayList<Integer> list = new ArrayList<>() ;
ArrayList<Long> list = new ArrayList<>() ;
ArrayList<Long> listl = new ArrayList<>() ;
ArrayList<Integer> lista = new ArrayList<>() ;
ArrayList<Integer> listb = new ArrayList<>() ;
//ArrayList<String> lists = new ArrayList<>() ;
HashMap<Integer,Integer> map = new HashMap<>() ;
//HashMap<Character,Integer> map = new HashMap<>() ;
//HashMap<Long,Long> map = new HashMap<>() ;
HashMap<Integer,Integer> map1 = new HashMap<>() ;
HashMap<Integer,Integer> map2 = new HashMap<>() ;
//HashMap<String,Integer> maps = new HashMap<>() ;
//HashMap<Integer,Boolean> mapb = new HashMap<>() ;
//HashMap<Point,Integer> point = new HashMap<>() ;
// Set<Long> set = new HashSet<>() ;
Set<Integer> set = new HashSet<>() ;
//Set<Character> set = new HashSet<>() ;
Set<Integer> setx = new HashSet<>() ;
Set<Integer> sety = new HashSet<>() ;
StringBuilder sb =new StringBuilder("") ;
//Collections.sort(list);
//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;
//else map.put(arr[i],1) ;
// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;
// else map.put(temp,1) ;
//int bit =Integer.bitCount(n);
// gives total no of set bits in n;
// Arrays.sort(arr, new Comparator<Pair>() {
// @Override
// public int compare(Pair a, Pair b) {
// if (a.first != b.first) {
// return a.first - b.first; // for increasing order of first
// }
// return a.second - b.second ; //if first is same then sort on second basis
// }
// });
int testcases = 1;
//testcases = scn.nextInt() ;
for(int testcase =1 ; testcase <= testcases ;testcase++)
{
//if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;
//if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;
// int n = scn.nextInt() ;int m = scn.nextInt() ;
// tree = new ArrayList[n] ;
// for(int i = 0; i< n; i++)
// {
// tree[i] = new ArrayList<Integer>();
// }
// for(int i = 0 ; i <= m-1 ; i++)
// {
// int fv = scn.nextInt()-1 ; int sv = scn.nextInt()-1 ;
// tree[fv].add(sv) ;
// tree[sv].add(fv) ;
// }
// boolean[] visited = new boolean[n] ;
// int ans = 0 ;
// for(int i = 0 ; i < n ; i++)
// {
// if(!visited[i])
// {
// dfs(i , visited ) ;
// ans++ ;
// }
// }
String s = scn.next() ;
out.println("Mike") ;
char[] arr= new char[s.length()] ;
arr[0] = s.charAt(0) ;
for(int i = 1; i < s.length() ; i++ )
{
char c = arr[i-1] ;
char t = s.charAt(i) ;
if(c >t)arr[i] =t;
else arr[i] = c ;
}
for(int i = 1 ; i < s.length() ; i++ )
{
if(arr[i]>= s.charAt(i))out.println("Mike") ;
else out.println("Ann") ;
}
sb.delete(0 , sb.length()) ;
list.clear() ;listb.clear() ;
map.clear() ;
map1.clear() ;
map2.clear() ;
set.clear() ;sety.clear() ;
} // test case end loop
out.flush() ;
} // solve fn ends
public static void main (String[] args) throws java.lang.Exception
{
solve() ;
}
}
class Pair
{
int first ;
int second ;
@Override
public String toString() {
String ans = "" ;
ans += this.first ;
ans += " ";
ans += this.second ;
return ans ;
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | cbd21b110dc7deb572e3cf6f51ef84af | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF1220C extends PrintWriter {
CF1220C() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1220C o = new CF1220C(); o.main(); o.flush();
}
void main() {
byte[] cc = sc.next().getBytes();
int n = cc.length;
int m = 'z';
for (int i = 0; i < n; i++) {
println(m < cc[i] ? "Ann" : "Mike");
m = Math.min(m, cc[i]);
}
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 77ff6e4e9a8d41aad18084e2a5dc0cbe | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String str = sc.next();
char arr[] = str.toCharArray(), minchar=arr[0];
out.println("Mike");
for(int i=1; i<arr.length; i++) {
if(arr[i]>minchar)
out.println("Ann");
else
out.println("Mike");
if(minchar>arr[i])
minchar = arr[i];
}
out.flush();
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 29daadc22721fa5cdcbfa37104950d5b | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Competetive {
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
char s[]=sc.next().toCharArray();
out.println("Mike");
char c=s[0];
for(int i=1;i<s.length;i++) {
if(c<s[i]) {
out.println("Ann");
}
else {
c=s[i];
out.println("Mike");
}
}
out.close();
}
public static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 11c5b2221dea2f07879edd94f48025b2 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.io.*;
import java.util.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class C_Substring_Game_in_the_Lesson {
public static PrintWriter out;
public static InputReader in;
public static long MOD = (long)1e9+7;
public static void main(String[] args)throws IOException {
in = new InputReader(System.in);
out = new PrintWriter(System.out);
int cases = 1;
for(int t = 0; t < cases; t++){
char[] c = in.next().toCharArray();
int[] mn = new int[c.length];
int[] mx = new int[c.length];
int v = 50;
for(int i=0;i<c.length;i++){
v = min(c[i]-'a',v);
mn[i] = v;
}
v = -1;
for(int i=c.length-1;i>=0;i--){
v = max(v,c[i]-'a');
mx[i] = v;
}
for(int i=0;i<c.length;i++){
int ix = c[i]-'a';
if(i>0 && mn[i-1]<ix){
out.println("Ann"); continue;
}
out.println("Mike");
// if(i>0) out.println(mn[i-1]);
// if(i+1<c.length) out.println(mx[i+1]);
}
}
out.close();
}
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 int[] nextArrI(int n) {
int[] a=new int[n];
for(int i=0; i<n; i++) a[i]=nextInt();
return a;
}
public long[] nextArrL(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | 1046abf8f40849bbbd796c4a769e53e1 | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.util.*;
import java.io.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static int gcd(int a,int b)
{
if(a>b)
return gcd(b,a);
if(b%a==0)
return a;
return gcd(b%a,a);
}
public static void main(String args[])
{
FastReader fs=new FastReader();
PrintWriter pw=new PrintWriter(System.out);
char c[]=fs.nextLine().toCharArray();
int n=c.length;
StringBuffer sb=new StringBuffer();
TreeSet<Character> ts=new TreeSet<>();
ArrayList<String> ans=new ArrayList<>();
ans.add("Mike");
ts.add(c[0]);
for(int i=1;i<n;i++)
{
char ch=(char)(c[i]-1);
if(ts.floor(ch)==null)
ans.add("Mike");
else
ans.add("Ann");
ts.add(c[i]);
}
for(String s:ans)
pw.println(s);
pw.flush();
pw.close();
}
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | c8779e15d648a86951502750a4dd515f | train_000.jsonl | 1568822700 | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$. | 256 mebibytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
boolean multiple = false;
long MOD = 998244353;
@SuppressWarnings("Duplicates")
void solve() throws Exception
{
String s = sc.nextToken();
int n = s.length();
int[] arr = new int[n];
arr[0] = s.charAt(0) - 'a';
for (int i = 1; i < n; i++)
arr[i] = min(s.charAt(i) - 'a', arr[i - 1]);
for (int i = 0; i < n; i++)
{
if (i == 0) pl("Mike");
else pl((arr[i - 1] < s.charAt(i) - 'a') ? "Ann" : "Mike");
}
}
long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
StringBuilder ANS = new StringBuilder();
void p(String s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
void pl(String s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
/*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
} | Java | ["abba", "cba"] | 2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | null | Java 11 | null | [
"greedy",
"games",
"strings"
] | 1e107d9fb8bead4ad942b857685304c4 | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | 1,300 | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | null | |
PASSED | add80bef14bdaa326f10d4b75769dc5a | train_000.jsonl | 1519058100 | Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class File {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Flat radius:
double R = sc.nextDouble();
// Flat coordinates:
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
// Fafa coordinates:
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
if (!contains(x1, y1, R, x2, y2)) {
System.out.println(x1 + " " + y1 + " " + R);
return;
}
// If Fafa is in the center of the flat.
if (x1 == x2 && y1 == y2) {
double dR = R / 2.0;
double dx = x1;
double dy = y2 - dR;
System.out.println(dx + " " + dy + " " + dR);
return;
}
// Get slope of x2, y2 from origin.
// Be careful of 0's.
// Slope = x2 / y2
double distance = getLength(x1, y1, x2, y2);
double diameter = distance + R;
double answerR = diameter / 2.0;
// (x2 - answerX) / answerR = (x2 - x1) / distance
// =>
// answerX = x2 - answerR * (x2 - x1) / distance
// answerY = y2 - answerR * (y2 - y1) / distance
double answerX = x2 - answerR * (x2 - x1) / distance;
double answerY = y2 - answerR * (y2 - y1) / distance;
System.out.println(answerX + " " + answerY + " " + answerR);
}
public static double getLength(double x1, double y1, double x2, double y2) {
double d_x = Math.abs(x1 - x2);
double d_y = Math.abs(y1 - y2);
return Math.sqrt(d_x*d_x + d_y*d_y);
}
public static boolean contains(double x1, double y1, double R, double x2, double y2) {
double d_x = Math.abs(x2 - x1);
double d_y = Math.abs(y2 - y1);
double distance = Math.sqrt(d_x*d_x + d_y*d_y);
return distance < R;
}
} | Java | ["5 3 3 1 1", "10 5 5 5 15"] | 1 second | ["3.7677669529663684 3.7677669529663684 3.914213562373095", "5.0 5.0 10.0"] | null | Java 11 | standard input | [
"geometry"
] | 29d4ca13888c0e172dde315b66380fe5 | The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105). | 1,600 | Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range. Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range. | standard output | |
PASSED | bdf80909f1329f38dad9e049388479eb | train_000.jsonl | 1519058100 | Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area. | 256 megabytes | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF935C extends PrintWriter {
CF935C() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF935C o = new CF935C(); o.main(); o.flush();
}
void main() {
int R = sc.nextInt();
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
double r, x, y;
if ((long) (x1 - x2) * (x1 - x2) + (long) (y1 - y2) * (y1 - y2) >= (long) R * R) {
r = R;
x = x1;
y = y1;
} else if (x1 == x2 && y1 == y2) {
r = R / 2.0;
x = x1 + r;
y = y1;
} else {
double d = Math.hypot(x1 - x2, y1 - y2);
r = (R + d) / 2;
double x3 = -R / d * (x2 - x1) + x1;
double y3 = -R / d * (y2 - y1) + y1;
x = (x2 + x3) / 2;
y = (y2 + y3) / 2;
}
println(x + " " + y + " " + r);
}
}
| Java | ["5 3 3 1 1", "10 5 5 5 15"] | 1 second | ["3.7677669529663684 3.7677669529663684 3.914213562373095", "5.0 5.0 10.0"] | null | Java 11 | standard input | [
"geometry"
] | 29d4ca13888c0e172dde315b66380fe5 | The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105). | 1,600 | Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range. Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.