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 | c160b334f28365f2c56150099e8f71b3 | train_001.jsonl | 1277823600 | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class solver implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
// final boolean OJ = System.getProperty("ONLINE_JUDGE") != null;
void init() throws FileNotFoundException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
// try {
// in = new BufferedReader(new FileReader("input.txt"));
// out = new PrintWriter("output.txt");
// } catch (Throwable e) {
// in = new BufferedReader(new InputStreamReader(System.in));
// out = new PrintWriter(System.out);
// }
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
public static void main(String[] args) {
new Thread(null, new solver(), "", 128 * (1L << 20)).start();
}
public void run() {
try {
init();
long time = System.currentTimeMillis();
solve();
System.err.println(System.currentTimeMillis() - time);
out.close();
} catch (IOException e) {
System.err.println(e.getMessage());
System.exit(-1);
}
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class Pair implements Comparable<Pair> {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return y - o.y;
}
}
int[] iMasWithSort(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) {
a[i] = readInt();
}
Arrays.sort(a);
int[] sorted = new int[n];
for (int i = 0; i < n; i++) {
sorted[i] = a[i];
}
return sorted;
}
int[] iMas(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = readInt();
}
return a;
}
void solve() throws IOException {
int n=readInt();
Pair[] p=new Pair[n];
for (int i=0;i<n;i++){
int left=readInt();
int right=readInt();
if (left>right) {
int t=left;
left=right;
right=t;
}
p[i]=new Pair(left,right);
}
Arrays.sort(p);
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i=0;i<n;i++){
if (p[i].y==Integer.MIN_VALUE) continue;
list.add(p[i].y);
for (int j=0;j<n;j++){
if (i==j) continue;
if (p[j].x <= p[i].y && p[i].y<=p[j].y){
p[j].y = Integer.MIN_VALUE;
}
}
}
out.println(list.size());
for (int x:list){
out.print(x+" ");
}
}
} | Java | ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7"] | 1 second | ["1\n2", "3\n7 10 3"] | null | Java 7 | standard input | [
"sortings",
"greedy"
] | 60558a2148f7c9741bb310412f655ee4 | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | 1,900 | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | standard output | |
PASSED | bb1a1562a2f4144e09d67e7da708246c | train_001.jsonl | 1277823600 | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | 256 megabytes | import java.util.*;
import java.awt.Point;
public class Segments {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
Point array[] = new Point[n];
for (int i = 0; i < n; i++) {
int a = cin.nextInt();
int b = cin.nextInt();
array[i] = new Point(Math.min(a, b), Math.max(a, b));
}
cin.close();
Arrays.sort(array, new solver());
StringBuilder str = new StringBuilder(array[0].y + " ");
int cur = array[0].y;
int ans = 1;
for (int i = 1; i < n; i++) {
if (array[i].x > cur) {
ans++;
str.append(array[i].y + " ");
cur = array[i].y;
}
}
System.out.println(ans);
System.out.print(str);
}
static class solver implements Comparator<Point> {
public int compare(Point a, Point b) {
if (a.y == b.y)
return b.x - a.x;
return a.y - b.y;
}
}
} | Java | ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7"] | 1 second | ["1\n2", "3\n7 10 3"] | null | Java 7 | standard input | [
"sortings",
"greedy"
] | 60558a2148f7c9741bb310412f655ee4 | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | 1,900 | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | standard output | |
PASSED | 77b1e933d3c7b00f45df97fdea044e78 | train_001.jsonl | 1277823600 | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | 256 megabytes | import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Niyaz Nigmatullin
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
}
class TaskD {
public void solve(int testNumber, FastScanner in, FastPrinter out) {
int n = in.nextInt();
Segment[] a = new Segment[n];
for (int i = 0; i < n; i++) {
a[i] = new Segment(in.nextInt(), in.nextInt());
}
Arrays.sort(a, new Comparator<Segment>() {
public int compare(Segment o1, Segment o2) {
return o1.b - o2.b;
}
});
int last = Integer.MIN_VALUE;
List<Integer> answer = new ArrayList<Integer>();
for (Segment e : a) {
if (last < e.a) {
answer.add(e.b);
last = e.b;
}
}
out.println(answer.size());
out.printArray(ArrayUtils.toPrimitiveArrayInteger(answer));
}
static class Segment {
int a;
int b;
Segment(int a, int b) {
if (a > b) {
int t = a;
a = b;
b = t;
}
this.a = a;
this.b = b;
}
}
}
class FastScanner extends BufferedReader {
boolean isEOF;
public FastScanner(InputStream is) {
super(new InputStreamReader(is));
}
public int read() {
try {
int ret = super.read();
if (isEOF && ret < 0) {
throw new InputMismatchException();
}
isEOF = ret == -1;
return ret;
} catch (IOException e) {
throw new InputMismatchException();
}
}
static boolean isWhiteSpace(int c) {
return c >= -1 && c <= 32;
}
public int nextInt() {
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int ret = 0;
while (!isWhiteSpace(c)) {
if (c < '0' || c > '9') {
throw new NumberFormatException("digit expected " + (char) c
+ " found");
}
ret = ret * 10 + c - '0';
c = read();
}
return ret * sgn;
}
}
class FastPrinter extends PrintWriter {
public FastPrinter(OutputStream out) {
super(out);
}
public FastPrinter(Writer out) {
super(out);
}
public void printArray(int[] a) {
for (int i = 0; i < a.length; i++) {
if (i > 0) {
print(' ');
}
print(a[i]);
}
println();
}
}
class ArrayUtils {
static public int[] toPrimitiveArrayInteger(List<Integer> list) {
int[] ret = new int[list.size()];
for (int i = 0; i < ret.length; i++) {
ret[i] = list.get(i);
}
return ret;
}
}
| Java | ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7"] | 1 second | ["1\n2", "3\n7 10 3"] | null | Java 7 | standard input | [
"sortings",
"greedy"
] | 60558a2148f7c9741bb310412f655ee4 | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | 1,900 | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | standard output | |
PASSED | 199765fc16fe3bddedf04490a0e330a2 | train_001.jsonl | 1277823600 | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main (String args []) throws Exception {
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
int n = Integer.parseInt(in.readLine().trim());
Line [] lines = new Line [n];
for (int i=0; i<n; i++) {
StringTokenizer st = new StringTokenizer (in.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
if (a>b) {
int temp = a;
a = b;
b = temp;
}
lines[i] = new Line(a,b);
}
Arrays.sort(lines);
ArrayList<Integer> ans = new ArrayList<Integer>();
int ind = 1;
int left = lines[0].a;
int right = lines[0].b;
int count = 0;
StringBuilder sb = new StringBuilder();
while (ind < n) {
Line cur = lines[ind];
if (cur.a >= left && cur.a <= right) {
right = Math.min (right, cur.b);
}
else {
sb.append(right + " ");
left = cur.a;
right = cur.b;
count++;
}
ind++;
}
sb.append(right);
System.out.println (count+1);
System.out.println (sb);
}
}
class Line implements Comparable<Line> {
int a, b;
public Line (int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo (Line o) {
if (a==o.a) return b - o.b;
return a - o.a;
}
} | Java | ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7"] | 1 second | ["1\n2", "3\n7 10 3"] | null | Java 7 | standard input | [
"sortings",
"greedy"
] | 60558a2148f7c9741bb310412f655ee4 | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | 1,900 | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | standard output | |
PASSED | 96399506c25512e3e082eb28039981dd | train_001.jsonl | 1277823600 | You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | 256 megabytes | import java.util.*;
import java.awt.Point;
public class nail {
public static void main(String [] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
Point array[]=new Point[n];
for(int i=0;i<n;i++){
int a=in.nextInt();
int b=in.nextInt();
array[i]=new Point(Math.min(a,b),Math.max(a,b));
}
Arrays.sort(array,new solver());
StringBuilder str=new StringBuilder(array[0].y+" ");
int cur=array[0].y;
int ans=1;
for(int i=1;i<n;i++){
if(array[i].x>cur){
ans++;
str.append(array[i].y+" ");
cur=array[i].y;
}
}
System.out.println(ans);
System.out.print(str);
}
static class solver implements Comparator<Point>{
public int compare(Point a,Point b){
if(a.y==b.y)
return b.x-a.x;
return a.y-b.y;
}
}
}
| Java | ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7"] | 1 second | ["1\n2", "3\n7 10 3"] | null | Java 7 | standard input | [
"sortings",
"greedy"
] | 60558a2148f7c9741bb310412f655ee4 | The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | 1,900 | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | standard output | |
PASSED | 5625edcb53e4c6069ffb403af2f51069 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
/**
*
* @author Тимур
*/
public class JavaApplication5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int K = in.nextInt();
int C = in.nextInt();
int P = 0;
int Last = 0;
int D = 0;
for (int i = 1; i <= N; i++) {
if (D == 0) {
if (C != 0) {
D = in.nextInt();
C = C - 1;
}
}
if (i == D) {
if (C != 0) {
D = in.nextInt();
C = C - 1;
}
P = P + 1;
Last = i;
continue;
}
if (Last + K == i) {
P = P + 1;
Last = i;
}
}
System.out.print(P);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | b7b0123f60aee309af983335e87883cb | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
/**
*
* @author matve
*/
public class JavaApplication26 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int c = in.nextInt();
int p = 0;
int last = 0;
int a[] = new int[c];
for(int i = 0;i < c;i++){
a[i] = in.nextInt();
}
int j = 0;
for(int i = 1;i <= n;i++){
if(j < c && i == a[j]){
p = p + 1;
last = i;
j++;
} else {
if(i == last + k){
p = p + 1;
last = i;
}
}
}
System.out.print(p);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 5e65477503ffbd6dad90decbc55f42ad | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
int res = 0;
int lim = 0;
int i = 1;
boolean alreadyIncreased = false;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String first;
try {
first = bf.readLine();
} catch (IOException e) {
System.out.println("Error Occurred @ BF1");
return;
}
String second;
try {
second = bf.readLine();
} catch (IOException e) {
System.out.println("Error Occurred @ BF2");
return;
}
StringTokenizer st1 = new StringTokenizer(first);
StringTokenizer st2 = new StringTokenizer(second);
int N = Integer.parseInt(st1.nextToken());
int K = Integer.parseInt(st1.nextToken());
int C = Integer.parseInt(st2.nextToken());
int n = 0;
if (st2.hasMoreTokens())
n = Integer.parseInt(st2.nextToken());
while (i <= N) {
lim++;
if (i == n || lim == K) {
res++;
lim = 0;
if (i == n && st2.hasMoreTokens())
n = Integer.parseInt(st2.nextToken());
}
i++;
}
System.out.println(res);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 3cb5cfb996fc5d9a4c86b2bf98e83c4e | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
/**
* _54A
* θ(n) time
* θ(c) space
*
* @author artyom
*/
public class _54A implements Runnable {
private BufferedReader in;
private StringTokenizer tok;
private Object solve() throws IOException {
int n = nextInt(), k = nextInt(), c = nextInt();
int[] a = readIntArray(c);
int cnt = 0;
for (int i = 1, p = 0, j = 0; i <= n; i++) {
if (j < c && a[j] == i) {
p = i;
cnt++;
j++;
} else if (i - p == k) {
p = i;
cnt++;
}
}
return cnt;
}
//--------------------------------------------------------------
public static void main(String[] args) {
new _54A().run();
}
@Override
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
PrintStream out = System.out;
out.print(solve());
in.close();
} catch (IOException e) {
System.exit(0);
}
}
private String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 3cebd9b162e7601e154d90b534c6728c | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class Presents {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int k = input.nextInt();
int p = input.nextInt();
int[] arr = new int[p];
for(int i=0;i<p;i++)arr[i] = input.nextInt();
// int z = arr[0];
int counter=0;
if(p!=0){
counter+=(arr[0]-1)/k;
counter+=(n-arr[p-1])/k;
for(int i=1; i<p;i++){
counter+=(arr[i]-arr[i-1]-1)/k;
}
System.out.println(counter+p);
}
else{
System.out.println(n/k);
}
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 70b9ae6b1f1aaf8735e3b3f52759053e | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A54 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tok.nextToken());
int k = Integer.parseInt(tok.nextToken());
tok = new StringTokenizer(br.readLine());
int c = Integer.parseInt(tok.nextToken());
boolean[] holiday = new boolean[n];
for (int i = 0; i < c; i++) {
holiday[Integer.parseInt(tok.nextToken())-1] = true;
}
int count = 0;
int nPres = 0;
for (int i = 0; i < n; i++) {
count++;
if (holiday[i] || count==k) {
nPres++;
count = 0;
}
}
System.out.println(nPres);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 5b6617fa7d6f82f2208a5bd747fc638f | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Presents
{
public static void main(String[]args) throws NumberFormatException, IOException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String f = bf.readLine();
StringTokenizer st = new StringTokenizer(f);
String s = bf.readLine();
StringTokenizer st2 = new StringTokenizer(s);
int N = Integer.parseInt((String) st.nextElement());
int K = Integer.parseInt((String) st.nextElement());
int C = Integer.parseInt((String) st2.nextElement());
Queue <Integer> Q = new LinkedList<>();
while (st2.hasMoreTokens())
{
Q.add(Integer.parseInt((String) st2.nextElement()));
C--;
}
int i = 1;
int l = K-1;
int j = 0;
int p;
if (Q.isEmpty() == false)
p = Q.peek();
else
p = 0;
boolean Y = true;
while (i <= N)
{
if (i == p)
{
j++;
if (Q.isEmpty() == false)
{
Q.remove(Q.peek());
if (Q.isEmpty() == false)
p = Q.peek();
}
Y = false;
}
if (l == 0 && Y == true)
{
j++;
Y = false;
}
if (Y == false)
{
l=K-1;
Y = true;
}
else
l--;
i++;
}
System.out.print(j);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 8e34b8fbd2574d1a26a591a86d60317d | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class File1{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int c = in.nextInt();
int l = 0;
ArrayList<Integer> gd = new ArrayList<Integer>();
gd.add(0);
int a[] = new int[c+1];
for(int i=0;i<c;i++) a[i] = in.nextInt();
a[c] = 1000;
int x = 0;
while(x<=n){
if(x+k<a[l]){
if(x+k<=n) gd.add(x+k);
x = x+k;
}
else{
gd.add(a[l]);
x = a[l];
l++;
}
}
System.out.println(gd.size()-1);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 8 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | e01922c8d3d11e7a720047837cfeabaf | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class game {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n1=in.nextInt();
int n2=in.nextInt();
int c=in.nextInt();
int[] a=new int[c];
int q=0;
for (int i=0;i<c;i++)
a[i]=in.nextInt();
int k=c;
boolean test=true;
int h=1;
for (int i=1;i<=n1;i++)
{
test=true;
for (int j=0;j<c;j++)
if (a[j]==i)
{test=false;h=1;break;}
if((h==n2)&&(test))
{
h=1;
q++;
}
else if(test)
h++;
}
out.println(q+k);
in.close();
out.close();
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | dc1e0f87c7862d6d97bec846ca2a16c0 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | /**
* Created by IntelliJ IDEA.
* User: shakhov
* Date: 15.06.2011
* Time: 15:22:46
* To change this template use File | Settings | File Templates.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class CodeForces {
public void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int c = nextInt();
int arr[] = new int[c];
for (int i = 0; i < c; i++) {
arr[i] = nextInt();
}
int counter = 0;
if (c != 0) {
Arrays.sort(arr);
if ((arr[0] - 1) / k > 0) {
counter += (arr[0] - 1) / k;
}
for (int i = 1; i < c; i++) {
if ((arr[i] - arr[i - 1] - 1) / k > 0) {
counter += (arr[i] - arr[i - 1] - 1) / k;
}
}
if ((n - arr[c - 1]/ k > 0)) {
counter += (n - arr[c - 1]) / k;
}
} else {
counter=n/k;
}
writer.print(counter + c);
}
public static void main(String[] args) {
new CodeForces().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
//reader = new BufferedReader(new FileReader("LifeWithoutZeros.in"));
tokenizer = null;
writer = new PrintWriter(System.out);
//writer = new PrintWriter(new BufferedWriter(new FileWriter("LifeWithoutZeros.out")));
//long t=new Date().getTime();
solve();
//writer.println(t-new Date().getTime());
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | acc22e722469662125628e60dc472eac | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
StreamTokenizer in; PrintWriter out; boolean oj;
BufferedReader br; Reader reader; Writer writer;
void init() throws IOException {
Locale.setDefault(Locale.US);
oj = System.getProperty("ONLINE_JUDGE") != null;
reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
br = new BufferedReader(reader);
in = new StreamTokenizer(br);
out = new PrintWriter(writer);
}
void run() throws IOException {
long beginTime = System.currentTimeMillis();
init();
solve();
if(!oj){
long endTime = System.currentTimeMillis();
if (!oj) {
System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("Running time = " + (endTime - beginTime));
}
}
out.flush();
}
void solve() throws IOException {
int n=nI(), k=nI(), c=nI(), r=0, t, x=0;
for(int i=0; i<c; i++){
r+=(t=(nI()-x))/k+(t%k>0?1:0);
x=t+x;
}
out.println(r+(n-x)/k);
}
int nI() throws IOException {
in.nextToken();
return (int) in.nval;
}
long nL() throws IOException {
in.nextToken();
return (long) in.nval;
}
String nS() throws IOException {
in.nextToken();
return in.sval;
}
double nD() throws IOException {
in.nextToken();
return in.nval;
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 8062a3d53c602a375a89adc6387daee2 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int c = in.nextInt();
int[] hol = new int[c];
for (int i = 0; i < c; i++)
hol[i] = in.nextInt();
int cnt = 0;
int cur = 0;
for (int i = k; i <= n; i += k) {
if(cur < c && i >= hol[cur]){
i = hol[cur];
cur++;
}
cnt++;
}
if(cur < c)
cnt+=c-cur;
System.out.println(cnt);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | fcef55066d227db28343c6920acd7617 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes |
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author madis
*/
public class Jan11 {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
int N = in.nextInt();
boolean a[] = new boolean[N+1];
int K = in.nextInt();
int c = in.nextInt();
for(int i = 0;i<c;i++){
int w = in.nextInt();
a[w] = true;
}
int count = 0;
for(int i = 1;i<=N;i++){
count++;
if(a[i])count=0;
if(count==K){
a[i] = true;
count=0;
}
}
count=0;
for(int i =1;i<=N;i++){
if(a[i])count++;
}
System.out.print(count);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | cc1657acda7689d56b151e3e402b2ab9 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class Main {
public static void main( String[] args ) {
Scanner sc = new Scanner( System.in );
int n = sc.nextInt(), k = sc.nextInt(), c = sc.nextInt();
int[] holiday = new int[c];
for ( int i=0; i<c; i++ ) holiday[i] = sc.nextInt();
int res = 0, ind = 0, ctr = 0;
for ( int i=1; i<=n; i++ ) {
ctr++;
if ( ind < c && holiday[ind] == i ) {
res++; ind++; ctr=0;
}
if ( ctr == k ) {
res++; ctr=0;
}
}
System.out.println( res );
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 6a775f2bee089094fcf81b97c3028018 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class Present{
public static void main(String[]args){
Scanner i = new Scanner(System.in);
int n = i.nextInt();
int k = i.nextInt();
int c = i.nextInt();
ArrayList<Integer> m = new ArrayList<Integer>();
for(int e = 0; e < c;e++){
m.add(i.nextInt());
}
int ac = 0;
if(m.size()>0){
int j = m.get(0);
j = j-k ;
while(j>= 1 ){
ac++;
j = j-k ;
}
j = m.get(m.size()-1);
j = j+k ;
while(j<= n ){
ac++;
j = j+k ;
}
int le = m.size();
int z = 0;
j = m.get(z);
if(m.get(m.size()-1) - j >k){
while(z+1 < m.size()){
if(m.get(z+1)-m.get(z)<= k){
j = m.get(z+1);
}
else{
j = m.get(z) + k;
while(j < m.get(z+1)){
ac++;
j += k;
}
}
z++;
}
}
System.out.print(ac+le);
}
else{
ac =0;
int l = 0;
while(l +k <= n){
ac++;
l = l+k;
}
System.out.print(ac);
}
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | f1d2c0d0e325f04d994f053f32b16148 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
public class cbr50a {
private StreamTokenizer in;
public static void main(String[] args) throws IOException {
new cbr50a().run();
}
private void run() throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int n = nextInt(), k = nextInt();
int r = 0, p = 0;
int c = nextInt();
for (int i = 0; i < c; i++) {
int d = nextInt();
r += (d - p) / k;
if ((d - p) % k != 0)
r++;
p = d;
}
r += (n - p) / k;
PrintWriter out = new PrintWriter(System.out);
out.print(r);
out.flush();
}
private int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 89b59047330beaafccabb9d0221d220b | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 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.StringTokenizer;
public class ProblemA {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer st = new StringTokenizer(stdin.readLine());
int n = Integer.valueOf(st.nextToken());
int k = Integer.valueOf(st.nextToken());
int r = 0;
st = new StringTokenizer(stdin.readLine());
st.nextToken();
int p = 0;
while(st.hasMoreTokens()) {
r++;
int t = Integer.valueOf(st.nextToken());
r += (t - 1 - p)/k;
p = t;
}
r += (n - p)/k;
out.println(r);
out.flush();
out.close();
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | bef4f1b9748d9d107e3ef94a992ec3fb | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
public class A {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int c = nextInt();
HashSet<Integer> list = new HashSet<Integer>();
for (int i = 0; i < c; ++i) {
list.add(nextInt());
}
int count = 0;
int next = k;
for (int i = 1; i <= n; ++i) {
if (list.contains(i)) {
++count;
next = i + k;
} else if (i == next) {
++count;
next = i + k;
}
}
out.println(count);
}
public void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
out.close();
in.close();
}
void eat(String s) {
st = new StringTokenizer(s);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
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());
}
public static void main(String[] args) throws IOException {
new A().run();
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 8a64e62e54c8177792e484cdf6e3f31d | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.* ;
import java.io.* ;
import java.math.* ;
/************************
* *
* Lord Klotski *
* *
***********************/
public class Codeforces_2011_Jan10_A
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in) ;
int N = input.nextInt() ; int K = input.nextInt() ;
int C = input.nextInt() ; int[] arr = new int[C] ;
for (int i = 0 ;i < C ; i ++) arr[i] = input.nextInt() ;
int n = 0 ; int last = 0 ; int presents = 0 ;
for (int i = 1 ; i <= N ; i ++)
{
if (n < C)
{
if (arr[n] == i)
{
presents++;
last = i; n ++ ;
continue;
}
}
if (i-last == K) { presents ++ ; last = i ; continue ;}
}
System.out.println(presents);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 9c1b4c25fb1e0cb7e30a219d3dc8fda7 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class Presents
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int N = sc.nextInt();
int K = sc.nextInt();
int C = sc.nextInt();
boolean day[] = new boolean[N + 1];
for (int i = 0; i < C; i++)
day[sc.nextInt()] = true;
int cnt = 0, ck = 0;
for (int i = 1; i < day.length; i++)
{
if (day[i]){
ck = 0;
cnt++;
}
else
{
ck++;
if (ck == K)
{
ck = 0;
day[i] = true;
cnt++;
}
}
}
// for (int i = 0; i < day.length; i++) if(day[i]) System.out.print(i + " ");
// System.out.println();
System.out.println(cnt);
}
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 31a865fdd795e5ae1dac83a2b3c9b541 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
import java.math.*;
public class Main {
void run() throws IOException {
int n = nint(), k = nint(), c = nint();
HashSet <Integer> h = new HashSet();
for (int i = 0; i < c; i++) {
h.add(nint());
}
int t = k, r = 0;
for (int i = 1; i <= n; i++) {
if (i == t || h.contains(i)) {
r++;
t = i + k;
}
}
out.println(r);
}
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
//final String FILENAME = "input";
//in = new BufferedReader(new FileReader(new File(FILENAME + ".in")));
//out = new PrintWriter(new File(FILENAME + ".out"));
in = new BufferedReader(new InputStreamReader(System.in));
//in = new Scanner(System.in);
out = new PrintWriter(System.out);
st = new StringTokenizer(" ");
new Main().run();
out.close();
}
static BufferedReader in;
//static Scanner in;
static PrintWriter out;
static StringTokenizer st;
String token() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nint() throws IOException {
return Integer.parseInt(token());
}
long nlong() throws IOException {
return Long.parseLong(token());
}
double ndouble() throws IOException {
return Double.parseDouble(token());
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | f5401ca3003e281834e2b5bdfb19b9df | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;
public class Main implements Runnable {
StringTokenizer tokenizer = new StringTokenizer("");
BufferedReader in;
PrintStream out;
public static void main(String[] args) {
new Thread(new Main()).start();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintStream(System.out);
int n = nextInt(), k = nextInt();
boolean [] w = new boolean [n + 1];
int c = nextInt();
for (int i = 0; i < c; i++) {
w[nextInt()] = true;
}
int p = 0, ans = 0;
for (int i = 1; i <= n; i++) {
p++;
if (w[i]) {
ans++;
p = 0;
}
if (p == k) {
ans++;
p = 0;
}
}
out.println(ans);
} catch (Exception e) {
e.printStackTrace();
}
}
boolean seekForToken() {
while (!tokenizer.hasMoreTokens()) {
String s = null;
try {
s = in.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (s == null)
return false;
tokenizer = new StringTokenizer(s);
}
return true;
}
String nextToken() {
return seekForToken() ? tokenizer.nextToken() : null;
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
BigInteger nextBig() {
return new BigInteger(nextToken());
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 4f950cd65f29f0643b4197573ac8ef54 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
boolean day[] = new boolean[n+1];
for(int i=0; i<c; i++)
day[sc.nextInt()] = true;
int p = 0;
for(int i=1; i<=n; i++) {
if(day[i]) {
p = i;
}
else if(i - p == k) {
day[i] = true;
p = i;
}
}
int cnt = 0;
for(int i=1; i<=n; i++)
if(day[i]) cnt++;
System.out.println(cnt);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 58a66ba9dac43dd25ff9922fee58397f | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class A
{
PrintWriter out;
BufferedReader in;
StringTokenizer ss;
static void dbg(String s){System.out.println(s);};
String next_token() throws IOException
{while (!ss.hasMoreTokens())ss=new StringTokenizer(in.readLine());
return ss.nextToken();}
Double _double() throws IOException
{return Double.parseDouble (next_token());}
int _int() throws IOException
{return Integer.parseInt (next_token());}
long _long() throws IOException
{return Long.parseLong (next_token());}
void run()throws IOException
{
in = new BufferedReader(new InputStreamReader(System.in));
out= new PrintWriter(System.out);
String name="";
/*in = new BufferedReader(new FileReader(name+".in"));
out = new PrintWriter(new File(name+".out")); */
ss = new StringTokenizer(" ");
int n=_int();
int k=_int();
int c=_int();
int A[]=new int[c+1];
for(int i=0;i<c;i++)A[i]=_int();
A[c]=n+1;
int past=0;
int raspr=0;
int ans=0;
for(int i=1;i<=n;i++){
if(A[raspr]==i){ans++;raspr++;past=i;}
else{
if(i-past>=k){ans++;past=i;}
}
}
out.println(ans);
out.close();
}
public static void main(String[] args)throws Exception
{
try{new A().run();}catch (Exception e){int Ar[]=new int[2];Ar[1+2]=2;};
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | bcd1fc0902ee33c343426b663e8e9a57 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
boolean file = false;
public static void main(String[] args) throws Exception {
new Thread(new Solution()).start();
}
private String next() throws Exception {
if (st == null || !st.hasMoreElements())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
private int nextInt() throws Exception {
return Integer.parseInt(next());
}
private long nextLong() throws Exception {
return Long.parseLong(next());
}
private double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public void run() {
try {
if (file)
in = new BufferedReader(new FileReader("in.txt"));
else
in = new BufferedReader(new InputStreamReader(System.in));
if (file)
out = new PrintWriter(new FileWriter("out.txt"));
else
out = new PrintWriter(System.out);
solve();
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
out.close();
}
}
public void solve() throws Exception {
int n = nextInt(), k = nextInt(), c = nextInt(), a[] = new int[c];
for(int i=0; i<c; i++)
a[i] = nextInt();
int cnt = 0, ans = 0, pos = 0;
for(int i=1; i<=n; i++){
if(a.length > 0 && pos < a.length && i == a[pos]){
pos++;
ans++;
cnt = 0;
continue;
}
cnt++;
if(cnt == k){
cnt = 0;
ans++;
}
}
out.println(ans);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | d548809465266b9fa87ef0bdf4f0198e | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
try {
if (new File("input.txt").exists())
System.setIn(new FileInputStream("input.txt"));
} catch (SecurityException e) {
}
new Thread(null, new Runnable() {
public void run() {
try {
new Main().run();
} catch (Throwable e) {
e.printStackTrace();
exit(999);
}
}
}, "1", 1 << 23).start();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
private void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt(), k = nextInt();
int c = nextInt();
int[] cel = new int[c];
for (int i = 0; i < c; i++) {
cel[i] = nextInt();
}
int ans = 0;
for (int cur = 0, id = 0; cur <= n;) {
ans++;
if (id < c) {
if (cur + k >= cel[id]) {
cur = cel[id];
id++;
} else {
cur += k;
}
} else {
cur += k;
}
}
out.print(ans - 1);
in.close();
out.close();
}
void chk(boolean b) {
if (b)
return;
System.out.println(new Error().getStackTrace()[1]);
exit(999);
}
void deb(String fmt, Object... args) {
System.out.printf(Locale.US, fmt + "%n", args);
}
String nextToken() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextLine() throws IOException {
st = new StringTokenizer("");
return in.readLine();
}
boolean EOF() throws IOException {
while (!st.hasMoreTokens()) {
String s = in.readLine();
if (s == null)
return true;
st = new StringTokenizer(s);
}
return false;
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 559e68de13bb7002593e9bf005a1a668 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
StringTokenizer a = new StringTokenizer(in.readLine());
boolean [] days = new boolean[Integer.parseInt(a.nextToken())];
int interval = Integer.parseInt(a.nextToken());
a = new StringTokenizer(in.readLine());
a.nextToken();
while (a.hasMoreTokens()){
days[Integer.parseInt(a.nextToken())-1]=true;
}
int nopre =0;
int num =0;
for (int i = 0; i < days.length; i++) {
nopre++;
if(days[i]){
num++;
nopre=0;
}else if (nopre==interval){
num++;
nopre=0;
}
}
System.out.println(num);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 0be5c65c09865034ca078ed24d9407dc | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt(), k = s.nextInt();
int c = s.nextInt();
int a = 0;
int result = 0;
for(int i = 0; i < c; ++i){
int x = s.nextInt();
int d = x - a;
result += d / k + (d % k > 0 ? 1 : 0);
a = x;
}
System.out.println(result + (n-a) / k);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 3e0aa468e4e092924409244cff0608a6 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class a {
public static boolean[] covered;
public static int n,k,count;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
int c = in.nextInt();
count = 0;
covered = new boolean[n+1];
covered[0] = true;
for(int i=0; i<c; i++) {
covered[in.nextInt()] = true;
count++;
}
int run = 0;
for(int i=0; i<=n; i++) {
run++;
if(covered[i]) run = 0;
if(run == k) {
run = 0;
count++;
}
}
System.out.println(count);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | cb701ee7cf6086132b9095c811aa3c6a | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class L7 {
public static void main(String[] args) throws FileNotFoundException {
//File source = new File("in.txt");
//FileInputStream in = new FileInputStream(source);
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int c=in.nextInt();
int []p=new int[c];
boolean []b=new boolean[n];
for(int q=0;q<c;q++)
{
p[q]=in.nextInt();
b[p[q]-1]=true;
}
int result=0;
for(int w=-1,q=0;q<n;q++)
{
if(b[q])
{
w=q;
result++;
}
if(q-w==k){w=q;result++;}
}
System.out.println(result);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | d7aa2da29a1c1db44c8f723c2fd43dd0 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class A50 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int c = in.nextInt();
Vector<Integer> holidays = new Vector<Integer>();
for (int i = 0; i < c; i++) holidays.add(in.nextInt());
boolean[] mark = new boolean[1000];
Arrays.fill(mark, false);
for (int i = 0; i < c; i++) mark[holidays.get(i)] = true;
int cnt = 1, res = 0;
for (int i = 1; i <= n; i++){
cnt %= k;
if (mark[i] == true) { res++; cnt = 0; }
else if (cnt == 0) res++;
cnt++;
//System.out.println(cnt);
}
System.out.println(res);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 96433a44df083844ce3a3bc42e7056aa | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes |
/**
* Created by IntelliJ IDEA.
* User: aircube
* Date: 11.01.11
* Time: 4:14
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Template {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
public static void main(String[] args) throws IOException {
new Template().run();
}
void run() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
st = null;
out = new PrintWriter(System.out);
solve();
br.close();
out.close();
}
void solve() throws IOException {
int n = nextInt(), k = nextInt();
int c = nextInt();
int p[] = new int[c];
for(int i = 0; i < c; ++i)
p[i] = nextInt();
Arrays.sort(p);
int res = 0;
int lst = 0;
for(int i = 1; i <= n; ++i) {
if (i - lst == k || Arrays.binarySearch(p, i) >= 0) {
res ++ ;
lst = i;
}
}
out.print(res);
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | dff6edcd650d3aa45178d77e020e8f71 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class A // #50
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n, k, c, hol, r = 0, hasNext = 0;
n = in.nextInt(); //days
k = in.nextInt(); //at least every k days
c = in.nextInt(); //hols
int[] days = new int[n+1];
days[0] = 1;
for (int i = 0; i < c; i++)
{
hol = in.nextInt();
days[hol] = 1;
}
for (int i = 0; i <= n-k; i++)
{
hasNext = 0;
if (days[i] == 1)
{
for (int j = i+1; j <= i+k; j++)
{
if (days[j] == 1)
{
hasNext = 1;
}
}
}
if (days[i] == 1 && hasNext == 0)
{
days[i+k] = 1;
}
}
for (int i = 1; i <= n; i++)
{
if (days[i] == 1)
{
r++;
}
}
System.out.println(r);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | f0b315836eb83aed893dff7f2f610d34 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class P054A {
public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
int n = inScanner.nextInt();
int k = inScanner.nextInt();
int c = inScanner.nextInt();
int sum = 0;
int previous = 0;
int holiday;
for (int i = 0; i < c; i++) {
holiday = inScanner.nextInt();
sum += 1 + (holiday - 1 - previous) / k;
previous = holiday;
}
sum += (n - previous) / k;
System.out.println(sum);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | a5db8ec5d373ee6a058f3c540aae47a5 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class A54 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
boolean[] can = new boolean[n+1];
int c = Integer.parseInt(st.nextToken());
while(c-- > 0)
can[Integer.parseInt(st.nextToken())] = true;
int last = 0;
int ret = 0;
for(int i = 1; i <= n; i++) {
if(can[i] || i - last == k) {
ret++;
last = i;
}
}
System.out.println(ret);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 2c71c167310356ff73e408ad8e6c5d0e | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
private static Scanner sc = new Scanner(new InputStreamReader(System.in));
public static void main (String[] args) throws IOException {
int n = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int ans = 0;
int x = 0, y = 0;
while (c-- > 0) {
y = x;
x = sc.nextInt();
ans += 1 + ((x - y - 1) / k);
}
ans += (n - x) / k;
System.out.println(ans);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 3c9a6a2d00da504ffe56edc32dcdf25c | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
private static Scanner sc = new Scanner(new InputStreamReader(System.in));
public static void main (String[] args) throws IOException {
int n = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int ans = 0;
int x = 0, y = 0;
while (c-- > 0) {
y = x;
x = sc.nextInt();
ans += 1 + ((x - y - 1) / k);
}
ans += (n - x) / k;
System.out.println(ans);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 61895a84d156e6f859685accfe7f3ec5 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
boolean[]need = new boolean[n+1];
for (int i = 1; i <= c; i++) {
need[sc.nextInt()] = true;
}
int ans = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
cnt++;
if (cnt==k || need[i]) {
cnt = 0;
ans++;
}
}
System.out.println(ans);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 4874fddb4e2822a2bf3edfac50558c87 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int n = r.nextInt();
int k = r.nextInt();
int m = r.nextInt();
boolean[] holiday = new boolean[n+1];
for(int i = 0; i < m; i++)
holiday[r.nextInt()] = true;
int res = 0;
int remain = 0;
for(int i = 0; i <= n; i++, remain--){
if(holiday[i]){
remain = k;
res++;
}else{
if(remain == 0){
res++;
remain = k;
}
}
}
System.out.println(res-1);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | b30f2669d80ea5f81877b2a84a5c3c61 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;
public class Main implements Runnable {
StringTokenizer tokenizer = new StringTokenizer("");
BufferedReader in;
//PrintWriter out;
PrintStream out;
String problem = "square";
public static void main(String[] args) {
new Thread(new Main()).start();
}
public void run() {
try {
//in = new BufferedReader(new FileReader(problem + ".in"));
//out = new PrintWriter(problem + ".out");
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintStream(System.out);
int n = nextInt();
int k = nextInt();
boolean a [] = new boolean [n];
int ans = 0;
int c = nextInt();
for (int i=0; i<c; i++){
a[nextInt()-1] = true;
}
int last=-1;
for (int i=0; i<n; i++){
if (a[i]==true) {last = i; ans++;}
if ((!a[i])&(i==last+k)) {last = i; ans++; a[i] = true;}
}
out.print(ans);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
boolean seekForToken() {
while (!tokenizer.hasMoreTokens()) {
String s = null;
try {
s = in.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (s == null)
return false;
tokenizer = new StringTokenizer(s);
}
return true;
}
String nextToken() {
return seekForToken() ? tokenizer.nextToken() : null;
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
BigInteger nextBig() {
return new BigInteger(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 4568830054bb1e99995b8ececf1bc54e | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
public static void main(String[] args) throws Exception {
if (new File("input.txt").exists()){
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
}
new Thread(new Solution()).start();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st;
private String next() throws Exception {
if (st == null || !st.hasMoreElements())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
private int nextInt() throws Exception {
return Integer.parseInt(next());
}
private long nextLong() throws Exception {
return Long.parseLong(next());
}
private double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
out.close();
}
}
public void solve() throws Exception {
int n = nextInt(), k = nextInt(), c = nextInt();
boolean [] p = new boolean[n+1];
for(int i = 0; i < c; ++i)
p[nextInt()] = true;
for(int i=1, curr = 1; i <= n; i++, curr++){
if (p[i]){
curr = 0;
}
else if (curr == k){
p[i] = true;
curr=0;
}
}
int count = 0;
for(int i = 1; i <= n; i++)
if (p[i])count++;
out.println(count);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 5b76066449dce608c3987adc7ffd3a3b | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes |
import java.util.*;
import java.io.*;
public class L{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int days = sc.nextInt();
int k = sc.nextInt();
int h = sc.nextInt();
int current =0;
int[] holidays = new int[h];
for(int a=0;a<h;a++){
holidays[a]=sc.nextInt();;
}
int next=0;
int pres=0;
while(current<days){
if(next==h||(current+k)<holidays[next]){
current+=k;
if(current<=days)pres++;
}
else{
current=holidays[next];
pres++;
next++;
}
}
System.out.print(pres);
System.exit(0);
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 928d757efb84820a3750370711e56606 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | /*
* Hello! You are trying to hack my solution, are you? =)
* Don't be afraid of the size, it's just a dump of useful methods like gcd, or n-th Fib number.
* And I'm just too lazy to create a new .java for every task.
* And if you were successful to hack my solution, please, send me this test as a message or to [email protected].
* It can help me improve my skills and i'd be very grateful for that.
* Sorry for time you spent reading this message. =)
* Good luck, unknown rival. =)
* */
import java.io.*;
import java.math.*;
import java.util.*;
public class Abra {
void solve() throws IOException {
int n = nextInt(), k = nextInt();
int c = nextInt();
boolean[] a = new boolean[366];
for (int i = 0; i < c; i++)
a[nextInt()] = true;
c = 1;
int r = 0;
for (int i = 1; i <= n; i++) {
if (a[i] || c == k) {
c = 0;
r++;
}
c++;
}
out.println(r);
}
public static void main(String[] args) throws IOException {
new Abra().run();
}
StreamTokenizer in;
PrintWriter out;
boolean oj;
BufferedReader br;
void init() throws IOException {
oj = System.getProperty("ONLINE_JUDGE") != null;
Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
br = new BufferedReader(reader);
in = new StreamTokenizer(br);
out = new PrintWriter(writer);
}
long selectionTime = 0;
void startSelection() {
selectionTime -= System.currentTimeMillis();
}
void stopSelection() {
selectionTime += System.currentTimeMillis();
}
void run() throws IOException {
long beginTime = System.currentTimeMillis();
long beginMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
init();
solve();
long endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long endTime = System.currentTimeMillis();
if (!oj) {
System.out.println("Memory used = " + (endMem - beginMem));
System.out.println("Total memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("Running time = " + (endTime - beginTime));
}
out.flush();
}
int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
int fastNextInt() throws IOException {
int r = 0, d = 1;
char c = (char) br.read();
while (!lib.isDigitChar(c) && c != '-')
c = (char) br.read();
while (true) {
if (c == '-') {
d = -1;
} else {
r += (c - '0') * d;
d *= 10;
}
c = (char) br.read();
if (!lib.isDigitChar(c) && c != '-') break;
}
return r;
}
long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
String nextString() throws IOException {
in.nextToken();
return in.sval;
}
double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
myLib lib = new myLib();
static class myLib {
long fact(long x) {
long a = 1;
for (long i = 2; i <= x; i++) {
a *= i;
}
return a;
}
long digitSum(String x) {
long a = 0;
for (int i = 0; i < x.length(); i++) {
a += x.charAt(i) - '0';
}
return a;
}
long digitSum(long x) {
long a = 0;
while (x > 0) {
a += x % 10;
x /= 10;
}
return a;
}
long digitMul(long x) {
long a = 1;
while (x > 0) {
a *= x % 10;
x /= 10;
}
return a;
}
int digitCubesSum(int x) {
int a = 0;
while (x > 0) {
a += (x % 10) * (x % 10) * (x % 10);
x /= 10;
}
return a;
}
double pif(double ax, double ay, double bx, double by) {
return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
double pif3D(double ax, double ay, double az, double bx, double by, double bz) {
return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by) + (az - bz) * (az - bz));
}
double pif3D(double[] a, double[] b) {
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));
}
long gcd(long a, long b) {
if (a == 0 || b == 0) return 1;
if (a < b) {
long c = b;
b = a;
a = c;
}
while (a % b != 0) {
a = a % b;
if (a < b) {
long c = b;
b = a;
a = c;
}
}
return b;
}
int gcd(int a, int b) {
if (a == 0 || b == 0) return 1;
if (a < b) {
int c = b;
b = a;
a = c;
}
while (a % b != 0) {
a = a % b;
if (a < b) {
int c = b;
b = a;
a = c;
}
}
return b;
}
long lcm(long a, long b) {
return a * b / gcd(a, b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int countOccurences(String x, String y) {
int a = 0, i = 0;
while (true) {
i = y.indexOf(x);
if (i == -1) break;
a++;
y = y.substring(i + 1);
}
return a;
}
int[] findPrimes(int x) {
boolean[] forErato = new boolean[x - 1];
List<Integer> t = new Vector<Integer>();
int l = 0, j = 0;
for (int i = 2; i < x; i++) {
if (forErato[i - 2]) continue;
t.add(i);
l++;
j = i * 2;
while (j < x) {
forErato[j - 2] = true;
j += i;
}
}
int[] primes = new int[l];
Iterator<Integer> iterator = t.iterator();
for (int i = 0; iterator.hasNext(); i++) {
primes[i] = iterator.next().intValue();
}
return primes;
}
int rev(int x) {
int a = 0;
while (x > 0) {
a = a * 10 + x % 10;
x /= 10;
}
return a;
}
class myDate {
int d, m, y;
int[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public myDate(int da, int ma, int ya) {
d = da;
m = ma;
y = ya;
if ((ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) && !(d == 29 && m == 2 && y % 4 == 0)) {
d = 1;
m = 1;
y = 9999999;
}
}
void incYear(int x) {
for (int i = 0; i < x; i++) {
y++;
if (m == 2 && d == 29) {
m = 3;
d = 1;
return;
}
if (m == 3 && d == 1) {
if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
m = 2;
d = 29;
}
return;
}
}
}
boolean less(myDate x) {
if (y < x.y) return true;
if (y > x.y) return false;
if (m < x.m) return true;
if (m > x.m) return false;
if (d < x.d) return true;
if (d > x.d) return false;
return true;
}
void inc() {
if ((d == 31) && (m == 12)) {
y++;
d = 1;
m = 1;
} else {
if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
ml[1] = 29;
}
if (d == ml[m - 1]) {
m++;
d = 1;
} else
d++;
}
}
}
int partition(int n, int l, int m) {// n - sum, l - length, m - every
// part
// <= m
if (n < l) return 0;
if (n < l + 2) return 1;
if (l == 1) return 1;
int c = 0;
for (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {
c += partition(n - i, l - 1, i);
}
return c;
}
int rifmQuality(String a, String b) {
if (a.length() > b.length()) {
String c = a;
a = b;
b = c;
}
int c = 0, d = b.length() - a.length();
for (int i = a.length() - 1; i >= 0; i--) {
if (a.charAt(i) == b.charAt(i + d)) c++;
else
break;
}
return c;
}
String numSym = "0123456789ABCDEF";
String ZFromXToYNotation(int x, int y, String z) {
if (z.equals("0")) return "0";
String a = "";
// long q = 0, t = 1;
BigInteger q = BigInteger.ZERO, t = BigInteger.ONE;
for (int i = z.length() - 1; i >= 0; i--) {
q = q.add(t.multiply(BigInteger.valueOf(z.charAt(i) - 48)));
t = t.multiply(BigInteger.valueOf(x));
}
while (q.compareTo(BigInteger.ZERO) == 1) {
a = numSym.charAt((int) (q.mod(BigInteger.valueOf(y)).intValue())) + a;
q = q.divide(BigInteger.valueOf(y));
}
return a;
}
double angleFromXY(int x, int y) {
if ((x == 0) && (y > 0)) return Math.PI / 2;
if ((x == 0) && (y < 0)) return -Math.PI / 2;
if ((y == 0) && (x > 0)) return 0;
if ((y == 0) && (x < 0)) return Math.PI;
if (x > 0) return Math.atan((double) y / x);
else {
if (y > 0) return Math.atan((double) y / x) + Math.PI;
else
return Math.atan((double) y / x) - Math.PI;
}
}
static boolean isNumber(String x) {
try {
Integer.parseInt(x);
} catch (NumberFormatException ex) {
return false;
}
return true;
}
static boolean stringContainsOf(String x, String c) {
for (int i = 0; i < x.length(); i++) {
if (c.indexOf(x.charAt(i)) == -1) return false;
}
return true;
}
long pow(long a, long n) { // b > 0
if (n == 0) return 1;
long k = n, b = 1, c = a;
while (k != 0) {
if (k % 2 == 0) {
k /= 2;
c *= c;
} else {
k--;
b *= c;
}
}
return b;
}
int pow(int a, int n) { // b > 0
if (n == 0) return 1;
int k = n, b = 1, c = a;
while (k != 0) {
if (k % 2 == 0) {
k /= 2;
c *= c;
} else {
k--;
b *= c;
}
}
return b;
}
double pow(double a, int n) { // b > 0
if (n == 0) return 1;
double k = n, b = 1, c = a;
while (k != 0) {
if (k % 2 == 0) {
k /= 2;
c *= c;
} else {
k--;
b *= c;
}
}
return b;
}
double log2(double x) {
return Math.log(x) / Math.log(2);
}
int lpd(int[] primes, int x) {// least prime divisor
int i;
for (i = 0; primes[i] <= x / 2; i++) {
if (x % primes[i] == 0) {
return primes[i];
}
}
;
return x;
}
int np(int[] primes, int x) {// number of prime number
for (int i = 0; true; i++) {
if (primes[i] == x) return i;
}
}
int[] dijkstra(int[][] map, int n, int s) {
int[] p = new int[n];
boolean[] b = new boolean[n];
Arrays.fill(p, Integer.MAX_VALUE);
p[s] = 0;
b[s] = true;
for (int i = 0; i < n; i++) {
if (i != s) p[i] = map[s][i];
}
while (true) {
int m = Integer.MAX_VALUE, mi = -1;
for (int i = 0; i < n; i++) {
if (!b[i] && (p[i] < m)) {
mi = i;
m = p[i];
}
}
if (mi == -1) break;
b[mi] = true;
for (int i = 0; i < n; i++)
if (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];
}
return p;
}
boolean isLatinChar(char x) {
if (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;
else
return false;
}
boolean isBigLatinChar(char x) {
if (x >= 'A' && x <= 'Z') return true;
else
return false;
}
boolean isSmallLatinChar(char x) {
if (x >= 'a' && x <= 'z') return true;
else
return false;
}
boolean isDigitChar(char x) {
if (x >= '0' && x <= '9') return true;
else
return false;
}
class NotANumberException extends Exception {
private static final long serialVersionUID = 1L;
String mistake;
NotANumberException() {
mistake = "Unknown.";
}
NotANumberException(String message) {
mistake = message;
}
}
class Real {
String num = "0";
long exp = 0;
boolean pos = true;
long length() {
return num.length();
}
void check(String x) throws NotANumberException {
if (!stringContainsOf(x, "0123456789+-.eE")) throw new NotANumberException("Illegal character.");
long j = 0;
for (long i = 0; i < x.length(); i++) {
if ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {
if (j == 0) j = 1;
else
if (j == 5) j = 6;
else
throw new NotANumberException("Unexpected sign.");
} else
if ("0123456789".indexOf(x.charAt((int) i)) != -1) {
if (j == 0) j = 2;
else
if (j == 1) j = 2;
else
if (j == 2)
;
else
if (j == 3) j = 4;
else
if (j == 4)
;
else
if (j == 5) j = 6;
else
if (j == 6)
;
else
throw new NotANumberException("Unexpected digit.");
} else
if (x.charAt((int) i) == '.') {
if (j == 0) j = 3;
else
if (j == 1) j = 3;
else
if (j == 2) j = 3;
else
throw new NotANumberException("Unexpected dot.");
} else
if ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {
if (j == 2) j = 5;
else
if (j == 4) j = 5;
else
throw new NotANumberException("Unexpected exponent.");
} else
throw new NotANumberException("O_o.");
}
if ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException("Unexpected end.");
}
public Real(String x) throws NotANumberException {
check(x);
if (x.charAt(0) == '-') pos = false;
long j = 0;
String e = "";
boolean epos = true;
for (long i = 0; i < x.length(); i++) {
if ("0123456789".indexOf(x.charAt((int) i)) != -1) {
if (j == 0) num += x.charAt((int) i);
if (j == 1) {
num += x.charAt((int) i);
exp--;
}
if (j == 2) e += x.charAt((int) i);
}
if (x.charAt((int) i) == '.') {
if (j == 0) j = 1;
}
if ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {
j = 2;
if (x.charAt((int) (i + 1)) == '-') epos = false;
}
}
while ((num.length() > 1) && (num.charAt(0) == '0'))
num = num.substring(1);
while ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {
num = num.substring(0, num.length() - 1);
exp++;
}
if (num.equals("0")) {
exp = 0;
pos = true;
return;
}
while ((e.length() > 1) && (e.charAt(0) == '0'))
e = e.substring(1);
try {
if (e != "") if (epos) exp += Long.parseLong(e);
else
exp -= Long.parseLong(e);
} catch (NumberFormatException exc) {
if (!epos) {
num = "0";
exp = 0;
pos = true;
} else {
throw new NotANumberException("Too long exponent");
}
}
}
public Real() {
}
String toString(long mantissa) {
String a = "", b = "";
if (exp >= 0) {
a = num;
if (!pos) a = '-' + a;
for (long i = 0; i < exp; i++)
a += '0';
for (long i = 0; i < mantissa; i++)
b += '0';
if (mantissa == 0) return a;
else
return a + "." + b;
} else {
if (exp + length() <= 0) {
a = "0";
if (mantissa == 0) {
return a;
}
if (mantissa < -(exp + length() - 1)) {
for (long i = 0; i < mantissa; i++)
b += '0';
return a + "." + b;
} else {
if (!pos) a = '-' + a;
for (long i = 0; i < mantissa; i++)
if (i < -(exp + length())) b += '0';
else
if (i + exp >= 0) b += '0';
else
b += num.charAt((int) (i + exp + length()));
return a + "." + b;
}
} else {
if (!pos) a = "-";
for (long i = 0; i < exp + length(); i++)
a += num.charAt((int) i);
if (mantissa == 0) return a;
for (long i = exp + length(); i < exp + length() + mantissa; i++)
if (i < length()) b += num.charAt((int) i);
else
b += '0';
return a + "." + b;
}
}
}
}
boolean containsRepeats(int... num) {
Set<Integer> s = new TreeSet<Integer>();
for (int d : num)
if (!s.contains(d)) s.add(d);
else
return true;
return false;
}
int[] rotateDice(int[] a, int n) {
int[] c = new int[6];
if (n == 0) {
c[0] = a[1];
c[1] = a[5];
c[2] = a[2];
c[3] = a[0];
c[4] = a[4];
c[5] = a[3];
}
if (n == 1) {
c[0] = a[2];
c[1] = a[1];
c[2] = a[5];
c[3] = a[3];
c[4] = a[0];
c[5] = a[4];
}
if (n == 2) {
c[0] = a[3];
c[1] = a[0];
c[2] = a[2];
c[3] = a[5];
c[4] = a[4];
c[5] = a[1];
}
if (n == 3) {
c[0] = a[4];
c[1] = a[1];
c[2] = a[0];
c[3] = a[3];
c[4] = a[5];
c[5] = a[2];
}
if (n == 4) {
c[0] = a[0];
c[1] = a[2];
c[2] = a[3];
c[3] = a[4];
c[4] = a[1];
c[5] = a[5];
}
if (n == 5) {
c[0] = a[0];
c[1] = a[4];
c[2] = a[1];
c[3] = a[2];
c[4] = a[3];
c[5] = a[5];
}
return c;
}
int min(int... a) {
int c = Integer.MAX_VALUE;
for (int d : a)
if (d < c) c = d;
return c;
}
int max(int... a) {
int c = Integer.MIN_VALUE;
for (int d : a)
if (d > c) c = d;
return c;
}
double maxD(double... a) {
double c = Double.MIN_VALUE;
for (double d : a)
if (d > c) c = d;
return c;
}
double minD(double... a) {
double c = Double.MAX_VALUE;
for (double d : a)
if (d < c) c = d;
return c;
}
int[] normalizeDice(int[] a) {
int[] c = a.clone();
if (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);
else
if (c[2] == 0) c = rotateDice(c, 1);
else
if (c[3] == 0) c = rotateDice(c, 2);
else
if (c[4] == 0) c = rotateDice(c, 3);
else
if (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);
while (c[1] != min(c[1], c[2], c[3], c[4]))
c = rotateDice(c, 4);
return c;
}
boolean sameDice(int[] a, int[] b) {
for (int i = 0; i < 6; i++)
if (a[i] != b[i]) return false;
return true;
}
final double goldenRatio = (1 + Math.sqrt(5)) / 2;
final double aGoldenRatio = (1 - Math.sqrt(5)) / 2;
long Fib(int n) {
if (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));
else
return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));
return Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));
}
class japaneeseComparator implements Comparator<String> {
@Override
public int compare(String a, String b) {
int ai = 0, bi = 0;
boolean m = false, ns = false;
if (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {
if (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') m = true;
else
return -1;
}
if (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {
if (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') m = true;
else
return 1;
}
a += "!";
b += "!";
int na = 0, nb = 0;
while (true) {
if (a.charAt(ai) == '!') {
if (b.charAt(bi) == '!') break;
return -1;
}
if (b.charAt(bi) == '!') {
return 1;
}
if (m) {
int ab = -1, bb = -1;
while (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {
if (ab == -1) ab = ai;
ai++;
}
while (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {
if (bb == -1) bb = bi;
bi++;
}
m = !m;
if (ab == -1) {
if (bb == -1) continue;
else
return 1;
}
if (bb == -1) return -1;
while (a.charAt(ab) == '0' && ab + 1 != ai) {
ab++;
if (!ns) na++;
}
while (b.charAt(bb) == '0' && bb + 1 != bi) {
bb++;
if (!ns) nb++;
}
if (na != nb) ns = true;
if (ai - ab < bi - bb) return -1;
if (ai - ab > bi - bb) return 1;
for (int i = 0; i < ai - ab; i++) {
if (a.charAt(ab + i) < b.charAt(bb + i)) return -1;
if (a.charAt(ab + i) > b.charAt(bb + i)) return 1;
}
} else {
m = !m;
while (true) {
if (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a' && b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') {
if (a.charAt(ai) < b.charAt(bi)) return -1;
if (a.charAt(ai) > b.charAt(bi)) return 1;
ai++;
bi++;
} else
if (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a') return 1;
else
if (b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') return -1;
else
break;
}
}
}
if (na < nb) return 1;
if (na > nb) return -1;
return 0;
}
}
Random random = new Random();
}
void readIntArray(int[] a) throws IOException {
for (int i = 0; i < a.length; i++)
a[i] = nextInt();
}
String readChars(int l) throws IOException {
String r = "";
for (int i = 0; i < l; i++)
r += (char) br.read();
return r;
}
class fraction{
long num = 0, den = 1;
void reduce(){
long d = lib.gcd(num, den);
num /= d;
den /= d;
}
fraction(long ch, long zn) {
num = ch;
den = zn;
reduce();
}
fraction add(fraction t) {
long nd = lib.lcm(den, t.den);
fraction r = new fraction(nd / den * num + nd / t.den * t.num, nd);
r.reduce();
return r;
}
public String toString(){
return num + "/" + den;
}
}
/*
* class cubeWithLetters { String consts = "ЧКТФЭЦ"; char[][] letters = { {
* 'А', 'Б', 'Г', 'В' }, { 'Д', 'Е', 'З', 'Ж' }, { 'И', 'Л', 'Н', 'М' }, {
* 'О', 'П', 'С', 'Р' }, { 'У', 'Х', 'Щ', 'Ш' }, { 'Ы', 'Ь', 'Я', 'Ю' } };
*
* char get(char x) { if (consts.indexOf(x) != -1) return x; for (int i = 0;
* i < 7; i++) { for (int j = 0; j < 4; j++) { if (letters[i][j] == x) { if
* (j == 0) return letters[i][3]; else return letters[i][j - 1]; } } }
* return '!'; }
*
* void subrotate(int x) { char t = letters[x][0]; letters[x][0] =
* letters[x][3]; letters[x][3] = letters[x][2]; letters[x][2] =
* letters[x][1]; letters[x][1] = t; }
*
* void rotate(int x) { subrotate(x); char t; if (x == 0) { t =
* letters[1][0]; letters[1][0] = letters[2][0]; letters[2][0] =
* letters[3][0]; letters[3][0] = letters[5][2]; letters[5][2] = t;
*
* t = letters[1][1]; letters[1][1] = letters[2][1]; letters[2][1] =
* letters[3][1]; letters[3][1] = letters[5][3]; letters[5][3] = t; } if (x
* == 1) { t = letters[2][0]; letters[2][0] = letters[0][0]; letters[0][0] =
* letters[5][0]; letters[5][0] = letters[4][0]; letters[4][0] = t;
*
* t = letters[2][3]; letters[2][3] = letters[0][3]; letters[0][3] =
* letters[5][3]; letters[5][3] = letters[4][3]; letters[4][3] = t; } if (x
* == 2) { t = letters[0][3]; letters[0][3] = letters[1][2]; letters[1][2] =
* letters[4][1]; letters[4][1] = letters[3][0]; letters[3][0] = t;
*
* t = letters[0][2]; letters[0][2] = letters[1][1]; letters[1][1] =
* letters[4][0]; letters[4][0] = letters[3][3]; letters[3][3] = t; } if (x
* == 3) { t = letters[2][1]; letters[2][1] = letters[4][1]; letters[4][1] =
* letters[5][1]; letters[5][1] = letters[0][1]; letters[0][1] = t;
*
* t = letters[2][2]; letters[2][2] = letters[4][2]; letters[4][2] =
* letters[5][2]; letters[5][2] = letters[0][2]; letters[0][2] = t; } if (x
* == 4) { t = letters[2][3]; letters[2][3] = letters[1][3]; letters[1][3] =
* letters[5][1]; letters[5][1] = letters[3][3]; letters[3][3] = t;
*
* t = letters[2][2]; letters[2][2] = letters[1][2]; letters[1][2] =
* letters[5][0]; letters[5][0] = letters[3][2]; letters[3][2] = t; } if (x
* == 5) { t = letters[4][3]; letters[4][3] = letters[1][0]; letters[1][0] =
* letters[0][1]; letters[0][1] = letters[3][2]; letters[3][2] = t;
*
* t = letters[4][2]; letters[4][2] = letters[1][3]; letters[1][3] =
* letters[0][0]; letters[0][0] = letters[3][1]; letters[3][1] = t; } }
*
* public String toString(){ return " " + letters[0][0] + letters[0][1] +
* "\n" + " " + letters[0][3] + letters[0][2] + "\n" + letters[1][0] +
* letters[1][1] + letters[2][0] + letters[2][1] + letters[3][0] +
* letters[3][1] + "\n" + letters[1][3] + letters[1][2] + letters[2][3] +
* letters[2][2] + letters[3][3] + letters[3][2] + "\n" + " " +
* letters[4][0] + letters[4][1] + "\n" + " " + letters[4][3] +
* letters[4][2] + "\n" + " " + letters[5][0] + letters[5][1] + "\n" + " "
* + letters[5][3] + letters[5][2] + "\n"; } }
*
*
* Vector<Integer>[] a; int n, mc, c1, c2; int[] col;
*
* void wave(int x, int p) { for (Iterator<Integer> i = a[x].iterator();
* i.hasNext(); ) { int t = i.next(); if (t == x || t == p) continue; if
* (col[t] == 0) { col[t] = mc; wave(t, x); } else { c1 = x; c2 = t; } } }
*
* void solve() throws IOException {
*
* String s = "ЕПОЕЬРИТСГХЖЗТЯПСТАПДСБИСТЧК"; //String s =
* "ЗЬУОЫТВЗТЯПУБОЫТЕАЫШХЯАТЧК"; cubeWithLetters cube = new
* cubeWithLetters(); for (int x = 0; x < 4; x++) { for (int y = x + 1; y <
* 5; y++) { for (int z = y + 1; z < 6; z++) { cube = new cubeWithLetters();
* out.println(cube.toString()); cube.rotate(x);
* out.println(cube.toString()); cube.rotate(y);
* out.println(cube.toString()); cube.rotate(z);
* out.println(cube.toString()); out.print(x + " " + y + " " + z + " = ");
* for (int i = 0; i < s.length(); i++) { out.print(cube.get(s.charAt(i)));
* } out.println(); } } }
*
* int a = nextInt(), b = nextInt(), x = nextInt(), y = nextInt();
* out.print((lib.min(a / (x / lib.gcd(x, y)), b / (y / lib.gcd(x, y))) * (x
* / lib.gcd(x, y))) + " " + (lib.min(a / (x / lib.gcd(x, y)), b / (y /
* lib.gcd(x, y))) * (y / lib.gcd(x, y)))); }
*/
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 46e0fe6cf726933e9d77aff3c9a083aa | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
// static Scanner in;
static PrintWriter out;
static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
public static void main(String[] args) throws Exception {
// in = new Scanner(System.in);
out = new PrintWriter(System.out);
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int n = next();
int k = next();
int c = next();
int[] red = new int[c + 2];
red[0] = 0;
red[c + 1] = n + 1;
for (int i = 0; i < c; i++) red[i + 1] = next();
int answ = c;
for (int i = 0; i <= c; i++) answ += (red[i + 1] - red[i] - 1)/k;
out.println(answ);
out.close();
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | bfadd5e25c3b50b8f1da3dc28e516532 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public
class Main {
static Scanner in = new Scanner(System.in);
public static
void main(String[] args) {
int n = in.nextInt();
int k = in.nextInt();
int c = in.nextInt();
boolean[] a = new boolean[500];
for(int i = 0; i < c; i++) {
int x = in.nextInt();
a[x] = true;
}
int ct = 0;
for(int i = 1, z = 0; i <= n; i++)
if(a[i] || i - z == k) {
ct++;
z = i;
}
jout(ct + "\n");
}
public static
void jout(Object ob) {System.out.print(ob);}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | cdf84784a690efcb345211f9318ecd39 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{
input.init(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = input.nextInt(), k = input.nextInt(), m = input.nextInt();
int[] data = new int[m];
for(int i = 0; i<m; i++) data[i] = input.nextInt();
int at = 0, last = 0, cur = 0, res = 0;
while(at<n)
{
at++;
if(cur<m && data[cur] == at)
{
res++;
cur++;
last = at;
}
else if(at - last >= k)
{
res++;
last = at;
}
}
out.println(res);
out.close();
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 11a1edba72b15ebc3f20fd38023a0cf3 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedInputStream;
import java.util.Scanner;
public class Presents { //Round #50 - Presents
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int numDays = sc.nextInt();
int atLeastDays = sc.nextInt();
int numHolidays = sc.nextInt();
int[] holidays = new int[numHolidays];
for(int i = 0; i < holidays.length; i++) {
holidays[i] = sc.nextInt();
}
int minPresents = 0;
int numDaysNotReceived = 0;
for(int day = 1; day <= numDays; day++) {
numDaysNotReceived++;
boolean contains = false;
for(int i = 0; i < holidays.length; i++) {
if(holidays[i] == day) {
contains = true;
break;
}
}
if(contains) {
minPresents++;
numDaysNotReceived = 0;
}
if(numDaysNotReceived == atLeastDays) {
minPresents++;
numDaysNotReceived = 0;
}
}
System.out.println(minPresents);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 8113196f640d05763cfd8bdff518d852 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Presents {
private void solve() throws IOException {
int n = nextInt() , k = nextInt() , c = nextInt();
boolean[] holidays = new boolean[n + 1];
for (int i = 0; i < c; i++) holidays[nextInt()] = true;
int res = 0;
int end = 0;
for (int i = 1; i <= n; i++) {
if (holidays[i]) {
res++;
end = i;
// System.out.println(end);
}
else {
if (i - end >= k) {
res++;
end = i;
}
}
}
System.out.println(res);
}
public static void main(String[] args) {
new Presents().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int[] readIntArray(int size) throws IOException {
int[] res = new int[size];
for (int i = 0; i < size; i++) {
res[i] = nextInt();
}
return res;
}
long[] readLongArray(int size) throws IOException {
long[] res = new long[size];
for (int i = 0; i < size; i++) {
res[i] = nextLong();
}
return res;
}
double[] readDoubleArray(int size) throws IOException {
double[] res = new double[size];
for (int i = 0; i < size; i++) {
res[i] = nextDouble();
}
return res;
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BigInteger nextBigInteger() throws IOException {
return new BigInteger(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 99c5bb6b4ca81d170977042d2e2db0e9 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.Scanner;
public class A054 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), k = in.nextInt(), c = in.nextInt();
boolean[] holiday = new boolean[9001];
for (int x = 0; x < c; x++) {
holiday[in.nextInt()] = true;
}
int prev = 0;
int count = 0;
for (int x = 1; x <= n; x++) {
if (holiday[x] || x - prev == k) {
prev = x;
count++;
}
}
System.out.println(count);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | b55e372035eb8999840b3689171c1e62 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes | import java.util.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, k, c, i, ok = 0, ans = 0;
n = in.nextInt();
k = in.nextInt();
c = in.nextInt();
int[] co = new int[c];
for (i = 0; i < co.length; i++) {
if (in.hasNextInt()) {
co[i] = in.nextInt();
}
}
int[] no = new int[n];
for (i = 0; i < no.length; ++i) {
no[i] = 0;
}
for (i = 0; i < co.length; ++i) {
no[co[i]-1] = 1;
}
for (i = 0; i < no.length; ++i) {
if (no[i] != 0)
{
ok = 0;
continue;
}
ok = ok + 1;
if (ok == k) {
no[i] += 1;
ok=0;
}
}
for (i = 0; i < no.length; ++i) {
ans += no[i];
}
System.out.println(ans);
// TODO code application logic here
}
} | Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | 20e3cb935a66d948440c6e1fd144ca97 | train_001.jsonl | 1294733700 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: on each holiday day the Hedgehog will necessarily receive a present, he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | 256 megabytes |
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author madi
*/
public class Round50A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] in = sc.nextLine().split(" ");
int n = Integer.parseInt(in[0]);
int k = Integer.parseInt(in[1]);
in = sc.nextLine().split(" ");
int c = Integer.parseInt(in[0]);
int[] a = new int[c + 1];
a[0] = 0;
for (int i = 1; i < c + 1; i++) {
a[i] = Integer.parseInt(in[i]);
}
boolean[] p = new boolean[n + 1];
int i = 1;
int counter = 0;
while (i <= n) {
counter++;
if (counter == k) {
counter = 0;
p[i] = true;
}
for (int j = 1; j < c + 1; j++) {
if (a[j] == i) {
p[i] = true;
counter = 0;
break;
}
}
i++;
}
int count = 0;
for (int q = 1; q < n + 1; q++) {
if (p[q]) {
count++;
}
}
System.out.println(count);
}
}
| Java | ["5 2\n1 3", "10 1\n3 6 7 8"] | 2 seconds | ["3", "10"] | null | Java 6 | standard input | [
"implementation"
] | 07b750dbf7f942eab80d4260103c7472 | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | 1,300 | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | standard output | |
PASSED | a5d99481b05b9c0d6298380677f9e5a6 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class CodeParsing {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String s = br.readLine();
int cntX = 0, cntY = 0;
for(int i = 0 ; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'x')
cntX++;
else
cntY++;
}
StringBuilder ans = new StringBuilder();
char c = 'x';
int cnt = cntX - cntY;
if (cntY > cntX) {
c = 'y';
cnt = cntY - cntX;
}
for(int i = 0; i < cnt; i++) {
ans.append(c);
}
bw.write(ans.toString());
bw.flush();
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | cd0a36f7ac5496e6f069313976810e2f | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class CodeParsing {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static void solve() throws Exception {
char[] c = next().toCharArray();
StringBuilder sb = new StringBuilder();
for (char ci : c)
if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ci)
sb.deleteCharAt(sb.length() - 1);
else
sb.append(ci);
out.println(sb);
}
public static void main(String args[]) {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static int[] nextIntArray(int len, int start) throws IOException {
int[] a = new int[len];
for (int i = start; i < len; i++)
a[i] = nextInt();
return a;
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static long[] nextLongArray(int len, int start) throws IOException {
long[] a = new long[len];
for (int i = start; i < len; i++)
a[i] = nextLong();
return a;
}
static String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 2dd98010268e5c72ef621af0bfd631f6 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solver extends ASolver {
String s;
StringBuilder result = new StringBuilder();
public static void main(String[] args) throws IOException {
Solver solution = new Solver();
solution.readData();
solution.solve();
solution.writeData();
}
@Override
public void readData() throws IOException {
s = next();
}
public void solve() {
int xCount = 0, yCount = 0;
for (char c : s.toCharArray()) {
if ('x' == c) {
xCount++;
} else {
yCount++;
}
}
char charToPrint = xCount > yCount ? 'x' : 'y';
for (int i = 0; i < Math.abs(xCount - yCount); i++){
result.append(charToPrint);
}
}
public void writeData() {
System.out.println(result);
}
}
abstract class ASolver {
protected StringTokenizer tokens;
protected BufferedReader input;
public ASolver() {
input = new BufferedReader(new InputStreamReader(System.in));
}
public abstract void readData() throws IOException;
public void writeData(String result) {
System.out.println(result);
}
public void writeData(int result) {
System.out.println(result);
}
public void writeData(long result) {
System.out.println(result);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String next() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine());
}
return tokens.nextToken();
}
public String nextLine() throws IOException {
return input.readLine();
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | ea112e9ccdf97234d48153fee055b390 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.*;
public class MainClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
StringBuilder s = new StringBuilder(sc.next());
int y = 0, x = 0;
for (int i=0;i<s.length();i++){
if(s.charAt(i)=='y')
y++;
else
x++;
}
int count = Math.abs(x-y);
char [] out = new char[count];
Arrays.fill(out,(x>y? 'x':'y'));
System.out.println(out);
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 644606e5e2bf5e78a0abdc17d02aa8c3 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import static java.lang.Math.*;
public class CodeParsing implements Closeable {
private InputReader in = new InputReader(System.in);
private PrintWriter out = new PrintWriter(System.out);
public void solve() {
char[] s = in.next().toCharArray();
int x = 0, y = 0;
for (char c : s) {
if (c == 'x') x++;
else y++;
}
int min = min(x, y);
x -= min;
y -= min;
char c = x != 0 ? 'x' : 'y';
for (int i = 0; i < max(x, y); i++) {
out.print(c);
}
}
@Override
public void close() throws IOException {
in.close();
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 ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public void close() throws IOException {
reader.close();
}
}
public static void main(String[] args) throws IOException {
try (CodeParsing instance = new CodeParsing()) {
instance.solve();
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 9f32cca40dc0f83cb0ae704e9ce60816 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.Closeable;
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.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
public class B implements Closeable {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
StringTokenizer stringTokenizer;
B() throws IOException {
// reader = new BufferedReader(new FileReader("input.txt"));
// writer = new PrintWriter(new FileWriter("output.txt"));
}
String next() throws IOException {
while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
stringTokenizer = new StringTokenizer(reader.readLine());
}
return stringTokenizer.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());
}
final int MOD = 1000 * 1000 * 1000 + 7;
int sum(int a, int b) {
a += b;
return a >= MOD ? a - MOD : a;
}
int product(int a, int b) {
return (int) (1l * a * b % MOD);
}
int pow(int x, long k) {
int result = 1;
while (k > 0) {
if (k % 2 == 1) {
result = product(result, x);
}
x = product(x, x);
k /= 2;
}
return result;
}
@SuppressWarnings("unchecked")
void solve() throws IOException {
int[] f = new int[2];
for (char c : next().toCharArray()) {
f[c - 'x']++;
}
int min = Integer.MAX_VALUE;
for (int i : f) {
min = Math.min(min, i);
}
for(int i = 0; i < 2; i++) {
for(int j = 0; j < f[i] - min; j++) {
writer.print((char)('x' + i));
}
}
}
public static void main(String[] args) throws IOException {
try (B b = new B()) {
b.solve();
}
}
@Override
public void close() throws IOException {
reader.close();
writer.close();
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | e7dd1659e680055b41fe1075292af47d | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
StringBuilder sb = new StringBuilder(in.next());
StringBuilder res = new StringBuilder();
int x = 0;
int y = 0;
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == 'x') x++;
else y++;
}
if (y > x) {
y -= x;
for (int i = 0; i < y; i++) res.append('y');
} else {
x -= y;
for (int i = 0; i < x; i++) res.append('x');
}
out.println(res.toString());
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
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();
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 55b746c6fb31fbbb63f55f87c46f9e38 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B255 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = 0;
int y = 0;
for (char c : in.next().toCharArray()) {
if (c == 'x') {
x++;
} else {
y++;
}
}
char[] array;
if (x >= y) {
x -= y;
array = new char[x];
Arrays.fill(array, 'x');
} else {
y -= x;
array = new char[y];
Arrays.fill(array, 'y');
}
System.out.println(new String(array));
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | f47c80a4282e6614bce2244adb78ee24 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Problem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s = input.next();
int sum_of_x = 0 , sum_of_y = 0 ;
for ( int i = 0 ; i < s.length() ; i++ )
{
if (s.charAt(i) == 'x')
sum_of_x++;
else
sum_of_y++;
}
char [] ch = new char[Math.abs(sum_of_x-sum_of_y)];
char printed =(sum_of_x > sum_of_y )? 'x' : 'y';
Arrays.fill(ch,printed);
System.out.print(ch);
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | c4649fba24b48ade76436d1d746580e7 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.*;
import java.io.*;
//Current File Class
public class HELL
{
///collections are like arraydeque deque list set,map etc
// how to keep reading input from user until endof file
// are there any built in sort function for all containers
// how to initialize a size for a vector and fill it with 3
static Scanner cin=new Scanner(System.in);
public static void main(String[] args)
{
int xCount=0,yCount=0,x=0;
String s=cin.nextLine();
StringBuilder res=new StringBuilder();
for(int j=0;j<s.length();++j)
x=(s.charAt(j)=='x') ? ++xCount : ++yCount;
if(xCount>yCount)
for(int j=0;j<xCount-yCount;++j)
res.insert(res.length(),'x');
else
for(int j=0;j<yCount-xCount;++j)
res.insert(res.length(),'y');
System.out.println(res);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | c6e1510750cbb6267af9bcc3637c1217 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ProplemSolving {
public static void main(String[] args) throws IOException {
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
StringBuffer s=new StringBuffer();
char a[]=r.readLine().toCharArray();
int x=0,y=0;
for(int i=0;i<a.length;i++){
if(a[i]=='x')x++;
else y++;
}
if (x>y){
for (int i=0;i<x-y;i++){
s.append("x");
}
}else{
for (int i=0;i<y-x;i++){
s.append("y");
}
}
String ans=s.toString();
System.out.println(ans);
}} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | fdfe1e43039d460435d3b987e28108f8 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.lang.Math;
public class ACM {
private static int gcdThing(long a, long b) {
BigInteger b1 = BigInteger.valueOf(a);
BigInteger b2 = BigInteger.valueOf(b);
BigInteger gcd = b1.gcd(b2);
return gcd.intValue();
}
public static int binarySearch(long data[],long key)
{
int count=-1;
int low = 0;
int high = data.length - 1;
while(high >= low) {
int middle = (low + high) / 2;
if(data[middle] == key) {
return middle;
}
if(data[middle] < key) {
low = middle + 1;
count=middle;
}
if(data[middle] > key) {
high = middle - 1;
}
}
return count;
}
/**/
public static int InsertionSort(int[] input){
int count=0;
int temp;
for (int i = 1; i < input.length; i++) {
for(int j = i ; j > 0 ; j--){
if(input[j] < input[j-1]){
temp = input[j];
input[j] = input[j-1];
input[j-1] = temp;
count++;
}
}
}
return count;
}
public static void main(String[] args) {
FastScanner input = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// int n = input.nextInt();
char[] s = input.next().toCharArray();
int x=0,y=0;
for(char a:s){
if(a=='x')
x++;
else
y++;
}
if(x>y){
for(int i=0;i<(x-y);i++)
// System.out.print("x");
// System.out.println("");
out.print("x");
out.println();
}
else{
for(int i=0;i<(y-x);i++)
out.print("y");
out.println();
}
out.flush();
out.close();
}// end main method
}
class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastScanner(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public 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();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isLineEndChar(c));
return res.toString();
}
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 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 boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isLineEndChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | ab3086c05cbf3ac5ccb6603e2c8a9254 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class CodeParsing {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.flush();
}
static class TaskB{
void solve(int test , InputReader in , PrintWriter out) throws IOException{
char[] s = in.next().toCharArray();
int n = s.length;
int cntx = 0 , cnty = 0;
for (int i = 0; i < n; i++) {
if(s[i] == 'x')
cntx++;
else cnty++;
}
int diff = Math.abs(cntx-cnty);
for (int i = 0; i < diff; i++) {
if(cntx > cnty)
out.print('x');
else out.print('y');
}
out.println();
}
}
static class InputReader{
public BufferedReader reader;
public StringTokenizer tk;
public InputReader(InputStream stream){
reader = new BufferedReader(new InputStreamReader(stream));
tk = null;
}
String next(){
while (tk == null || !tk.hasMoreTokens()) {
try{
tk = new StringTokenizer(reader.readLine());
}
catch(IOException e){
throw new RuntimeException();
}
}
return tk.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | cb0125a7894a2d64a7876665bb0f50e2 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = br.readLine();
if(!str.contains("x") || !str.contains("y")) {
bw.append(str+"\n");
}else {
int x = 0, y =0;
for(char ch:str.toCharArray()) {
if(ch == 'x') x++;
if(ch == 'y') y++;
}
StringBuilder ans = new StringBuilder();
if(x > y) {
for(int i=0;i<(x-y);i++)
ans.append('x');
}else if(x < y){
for(int i=0;i<(y-x);i++)
ans.append('y');
}
bw.append(ans.toString()+"\n");
}
bw.flush();
} catch (Exception e) {
// TODO: handle exception
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | c6c48c29040a7861669daa8a45cb1d34 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.Scanner;
public class b {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
in.close();
StringBuilder ans = new StringBuilder();
int x = 0;
for (int i = 0; i < str.length(); i++) {
x += str.charAt(i) == 'x' ? 1 : -1;
}
for (int i = 0; i < Math.abs(x); i++) {
ans.append(x > 0 ? 'x' : 'y');
}
System.out.println(ans.toString());
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 3fd01d227439a5e6f0c63843806ba416 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CodeParsing {
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();
String s = sc.next();
int x = 0;
int y = 0;
for(int i=0; i<s.length(); i++)
{
if(s.charAt(i)=='x')
{
x++;
}
else
{
y++;
}
}
int m = Math.abs(x-y);
char a;
StringBuilder sb = new StringBuilder();
if(x>y)
{
a = 'x';
}
else
{
a = 'y';
}
for(int i=0; i<m; i++)
{
sb.append(a);
}
System.out.println(sb.toString());
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 246758d5c677ac82e24c21aec1ffb712 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static long mod= (long) (1e9 +7);
public static void main(String args[]){
InputReader s= new InputReader(System.in);
OutputStream outputStream= System.out;
PrintWriter out= new PrintWriter(outputStream);
String input= s.nextLine();
int countx=0, county=0;
for(int i=0;i<input.length();i++){
if(input.charAt(i)=='x'){
countx++;
}
else county++;
}
for (int i = 0; i < Math.abs(countx - county); i++){
out.print(countx > county ? 'x' : 'y');
}
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream inputstream) {
reader = new BufferedReader(new InputStreamReader(inputstream));
tokenizer = null;
}
public String nextLine(){
String fullLine=null;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine=reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
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 long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
public static long binomialCoeff(int n, int k)
{
long C[][]= new long[n+1][k+1];
int i, j;
// Caculate value of Binomial Coefficient in bottom up manner
for (i = 0; i <= n; i++)
{
for (j = 0; j <= Math.min(i, k); j++)
{
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1;
// Calculate value using previosly stored values
else
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
return C[n][k];
}
public static int gcd(int number1, int number2) {
if(number2 == 0){
return number1;
}
return gcd(number2, number1%number2);
}
public static int combinations(int n,int r){
if(n==r) return 1;
if(r==1) return n;
if(r==0) return 1;
return combinations(n-1,r)+ combinations(n-1,r-1);
}
public static int expo(int a, int b){
if (b==1)
return a;
if (b==2)
return a*a;
if (b%2==0){
return expo(expo(a,b/2),2);
}
else{
return a*expo(expo(a,(b-1)/2),2);
}
}
public static void sieve(int N){
int arr[]= new int[N+1];
for(int i=2;i<Math.sqrt(N);i++){
if(arr[i]==0){
for(int j= i*i;j<= N;j= j+i){
arr[j]=1;
}
}
}
// All the i for which arr[i]==0 are prime numbers.
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 50bf74bc256234c8ef89a8d2d3f3e4ae | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
//import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
static PrintWriter pr = new PrintWriter(System.out);
static final double EPS=1e-9;
public static void main(String args[]) throws IOException{
Scanner sc = new Scanner(System.in);
int X=0;
int Y=0;
String s = sc.nextLine();
for(int i=0; i<s.length(); i++){
if(s.charAt(i)=='x')
X++;
else
Y++;
}
if(X>=Y){
for(int i=0; i<X-Y; i++)
pr.print("x");
pr.println();
}else{
for(int i=0; i<Y-X; i++)
pr.print("y");
pr.println();
}
pr.close();
}
static class triple implements Comparable<triple>{
int weight,inclusion, index;
triple(int weight, int inclusion, int index){
this.weight = weight;
this.inclusion = inclusion;
this.index = index;
}
public int compareTo(triple t){
if(weight!=t.weight){
return weight-t.weight;
}else
return t.inclusion-inclusion;
}
}
static class Point implements Comparable<Point>{
double x,y;
Point(double a, double b){
x = a;
y = b;
}
public int compareTo(Point p){
if(Math.abs(x-p.x)>EPS) return x>p.x?1:-1;
if(Math.abs(y-p.y)>EPS) return y>p.y?1:-1;
return 0;
}
public double dist(Point p){
return Math.sqrt(sq(x-p.x)+sq(y-p.y));
}
public double sq(double x){
return x*x;
}
Point translate(Vector v){
return new Point(x+v.x, y+v.y);
}
static double distToLine(Point p,Point a, Point b){
if(a.compareTo(b)==0)
return p.dist(a);
Vector ap = new Vector(a,p), ab = new Vector(a,b);
double u = ap.dot(ab)/ab.norm2();
Point c = a.translate(ab.scale(u));
return p.dist(c);
}
static double distToLineSegment(Point p ,Point a, Point b){
Vector ap = new Vector(a,p), ab = new Vector(a,b);
double u = ap.dot(ab)/ab.norm2();
if(u<0.0) return p.dist(a);
if(u>1.0) return p.dist(b);
return distToLine(p,a,b);
}
}
static class Vector{
double x, y;
Vector(double a, double b){
x = a;
y = b;
}
Vector(Point a, Point b){
this(b.x-a.x, b.y-a.y);
}
double dot(Vector v){
return x*v.x+y*v.y;
}
double norm2(){
return x*x+y*y;
}
Vector scale(double s){
return new Vector(x*s, y*s);
}
}
static class Scanner{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException{
while(st==null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException{
return Integer.parseInt(next());
}
public long nextLong() throws IOException{
return Long.parseLong(next());
}
public double nextDouble() throws IOException{
return Double.parseDouble(next());
}
public String nextLine() throws IOException{
return br.readLine();
}
public boolean ready() throws IOException{
return br.ready();
}
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 6dde689928429c163fc2a8ad2dac13ae | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.Scanner;
import java.lang.Math;
public class omar{
public static void main(String[] args){
Scanner user_input=new Scanner(System.in);
StringBuffer omar=new StringBuffer();
String x=user_input.next();
char k[]=x.toCharArray();
int r=0;
int e=0;
for(int i=0;i<k.length;i++){
if(k[i]=='x'){
r++;
}
else{
e++;
}
}
if(r>e){
for(int c=0;c<r-e;c++){
omar.append('x');
}
}
else{
for(int u=0;u<e-r;u++){
omar.append('y');
}
}
System.out.println(omar.toString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 47861d266bd906315c6ba06f6d023458 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
public class Main {
public static void main(String[] args) throws IOException{
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
String str = sc.nextToken();
int x =0 ;
int y= 0;
for(int i=0;i<str.length();i++)
if(str.charAt(i)=='x')x++;
else
y++;
if(x>y)
for(int i=1;i<=x-y;i++)
out.print('x');
else
for(int i=1;i<=-x+y;i++)
out.print('y');
out.close();
}
static void shuffle(int[] a)
{
int n = a.length;
for(int i = 0; i < n; ++i)
{
int r = i + (int)(Math.random() * (n - i));
int tmp = a[r];
a[r] = a[i];
a[i] = tmp;
}
}
static void generate(int[] p, int L, int R) {
if (L == R) {
}else {
for (int i = L; i <= R; i++) {
int tmp = p[L]; p[L] = p[i]; p[i] = tmp;//swap
generate(p, L+1, R);//recurse
tmp = p[L]; p[L] = p[i]; p[i] = tmp;//unswap
}
}
}
}
class point implements Comparable{
int x ;int y ;
point(int x ,int y){
this.x=x;
this.y=y;
}
@Override
public int compareTo(Object arg0) {
// TODO Auto-generated method stub
point p = (point)arg0;
if(p.x>this.x)return -1;
if(p.x<this.x)return 1;
return 0;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | f53fee47885c0c8da0ec29095c23a534 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.stream.Collectors;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
//Reader pm =new Reader();
Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
String s = pm.next();
int n = s.length();
int x =0, y=0;
for(int i=0;i<n;i++){
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuffer sb = new StringBuffer();
if(x > y){
int loop = x-y;
while(loop-- > 0)
sb.append("x");
System.out.println(sb);
}
else{
int loop = y-x;
while(loop-- > 0)
sb.append("y");
System.out.println(sb);
}
}
private static int binarySearchPM(int[] arr, int key){
int n = arr.length;
int mid = -1;
int begin = 0,end=n;
while(begin <= end){
mid = (begin+end) / 2;
if(mid == n){
return n;
}
if(key < arr[mid]){
end = mid-1;
} else if(key > arr[mid]){
begin = mid+1;
} else {
return mid;
}
}
//System.out.println(begin+" "+end);
return -begin; //expected Index
}
private static List<Integer> setToList(Set<Integer> s){
List<Integer> al = s.stream().collect(Collectors.toList());
return al;
}
private static List<Integer> mapValToList(HashMap<Integer,Integer> map){
return map.values().stream().collect(Collectors.toList());
}
private static List<Integer> mapKeyToList(HashMap<Integer,Integer> map){
return map.keySet().stream().collect(Collectors.toList());
}
private static HashMap<Integer, Integer> sortByKey(HashMap<Integer,Integer> map){
return map
.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue())
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
}
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 | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 8 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 30672c6a097c7062dc52711d31a75274 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class CodeParsing {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
char[] xy = in.next().toCharArray();
int x = 0, y = 0;
for (int i = 0; i < xy.length; i++) {
if (xy[i] == 'x') x++;
else y++;
}
char r = x > y ? 'x' : 'y';
StringBuilder sb = new StringBuilder();
for (int i = 0; i < Math.abs(x-y); i++) {
sb.append(r);
}
out.print(sb.toString());
out.close();
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 81e3aef1959d88afc6dbf7fb7e02627b | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.PrintWriter;
import java.util.Scanner;
/**
*
* @author gargon
*/
public class JavaApplication39 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int cnt_x = 0;
int cnt_y = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'x') {
cnt_x++;
} else {
cnt_y++;
}
}
PrintWriter pw = new PrintWriter(System.out);
if (cnt_x > cnt_y) {
int cnt = cnt_x - cnt_y;
for (int i = 0; i < cnt; i++) {
pw.write('x');
}
} else {
int cnt = cnt_y - cnt_x;
for (int i = 0; i < cnt; i++) {
pw.write('y');
}
}
pw.close();
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 5d64cff8eb25b9533892f86982f06f01 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException
{
new B().run();
}
InputReader in;
PrintWriter out;
public void run() throws IOException
{
in = new InputReader( System.in );
out = new PrintWriter( System.out );
solution();
out.close();
}
/* Start the solution here */
private void solution() throws IOException
{
String s = in.next();
int x = 0, y = 0;
for (int i=0; i<s.length(); i++)
{
if ( s.charAt(i) == 'x' ) x++;
else y++;
}
if ( x > y ) for (int i=0; i<x-y; i++) out.print("x");
else for (int i=0; i<y-x; i++) out.print("y");
}
}
class InputReader
{
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream in)
{
br = new BufferedReader(new InputStreamReader(in));
st = null;
}
public String next() throws IOException
{
while (st==null || !st.hasMoreTokens())
{
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | a6ac776058b5dd85f2bcae322754d1c0 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x=0,y=0;
while(true){
int c = br.read();
if((c != 'x') && (c!='y')){
break;
}
if(c == 'x'){
x++;
}else{
y++;
}
}
char c = 'y';
if(x>y){
c = 'x';
}
for (int i = 0; i < Math.abs(x-y); i++) {
System.out.print(c);
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 8b30b2a28ddcfa762ea5bac34f3bb617 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author zulkan
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf255b_codeParsign {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
//br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(System.in);
//out = new PrintWriter("output.txt");
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
public static void initB() {
try {
br = new BufferedReader(new FileReader("input.txt"));
sc = new Scanner(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
}
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Integer temp2[] = new Integer[n];
for (int i = 0; i < n; i++) {
temp2[i] = Integer.parseInt(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void print(Object a) {
out.println(a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static BigInteger getFact(long in) {
BigInteger ot = new BigInteger("1");
for (Integer i = 1; i <= in; i++) {
ot = ot.multiply(new BigInteger(i.toString()));
}
return ot;
}
public static String gbase(int a, int base) {
StringBuilder out = new StringBuilder();
int temp = a;
while (temp > 0) {
//out = temp % base + out;
out.insert(0, temp % base);
temp /= base;
}
return out.toString();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve() {
String s = getString();
String s1=s.replaceAll("y", "");
String s2=s.replaceAll("x","");
if(s1.length()-s2.length()>0){
print(s1.substring(0,s1.length()-s2.length()));
}else
print(s2.substring(0,s2.length()-s1.length()));
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | ba7f3f975f8066b935fa3d9052f34a22 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 7e7f74d7c42b6c47f2bc11823ef4a294 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
int diff = Math.abs(a - b);
StringBuilder sb = new StringBuilder();
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb.toString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 3375fbb502667cf27fef2af521eade0e | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | fbc72dcb68e325379cdb702ef99e8ac5 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
int diff = Math.abs(a - b);
StringBuilder sb = new StringBuilder();
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb.toString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 377de8516e62dd50882fa158d15d02e2 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
int diff = Math.abs(a - b);
StringBuilder sb = new StringBuilder();
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 949c4ab7265e4691c35420c189e47886 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | d91844ee5eccb1102d6631fc4e35c12e | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int a = 0;
int b = 0;
for(int i=0; i<s.length(); ++i) {
if(s.charAt(i)=='x') a++;
else b++;
}
int diff = Math.abs(a-b);
StringBuilder sb = new StringBuilder();
for(int i=0; i<diff; ++i) {
if(a>b) sb.append('x');
else sb.append('y');
}
System.out.println(sb.toString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 77f92258e255455fa57a7a89a13d0c3a | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder sb = new StringBuilder();
int diff = Math.abs(x - y);
if (x > y) {
for (int i = 0; i < diff; i++) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; i++) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | abf02b43157d246ea05ca8c2f46b1502 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | d45a72fae774c0e981f85dd4b9df8a2d | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder sb = new StringBuilder();
int diff = Math.abs(x - y);
if (x > y) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 931cab541c322d18c0524add5f1af8c3 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
static BufferedReader stdin = new BufferedReader(new
InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
public static void main(String[] args) throws Exception {
char[] cc = readString().toCharArray();
int[] sum = new int[300];
for (char c : cc)
sum[c]++;
int m = Math.min(sum['x'], sum['y']);
StringBuilder sb = new StringBuilder();
while (sum['x'] --> m)
sb.append('x');
while (sum['y'] --> m)
sb.append('y');
System.out.println(sb);
}
static String readString() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(stdin.readLine());
}
return st.nextToken();
}
static int readInt() throws Exception {
return Integer.parseInt(readString());
}
static long readLong() throws Exception {
return Long.parseLong(readString());
}
static double readDouble() throws Exception {
return Double.parseDouble(readString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 2b99ec79d95692e889e1dc276794f98f | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 0c16b9c25552b7e9de740d56e21a8a9e | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(new InputStreamReader(System.in));
String s = sc.next();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
int diff = Math.abs(a - b);
StringBuilder sb = new StringBuilder();
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb.toString());
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | e93dd74f9ea0c2704ac0050ac15a4cba | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
StringBuilder sb = new StringBuilder();
int diff = Math.abs(a - b);
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 9eae90a5003b36eb479410547808a8e1 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = 0;
int b = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'x')
a++;
else
b++;
}
StringBuilder sb = new StringBuilder();
int diff = Math.abs(a - b);
if (a > b) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | 7d8a03393b4f284721104234755b5090 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder out = new StringBuilder();
int diff = Math.abs(x - y);
if(x > y){
for (int i = 0; i < diff; i++)
out.append('x');
}else{
for (int i = 0; i < diff; i++)
out.append('y');
}
System.out.println(out);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | a897450913442d43ca47affdb9201b3a | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(new InputStreamReader(System.in));
// String s = sc.next();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'x')
x++;
else
y++;
}
StringBuilder sb = new StringBuilder();
int diff = Math.abs(x - y);
if (x > y) {
for (int i = 0; i < diff; ++i) {
sb.append('x');
}
} else {
for (int i = 0; i < diff; ++i) {
sb.append('y');
}
}
System.out.println(sb);
}
} | Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output | |
PASSED | ad1cb01eea6bc9defcf4dadde6651b44 | train_001.jsonl | 1355671800 | Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. | 256 megabytes | //package Round_156;
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class b {
void solve() throws Exception {
char a[] = in.next().toCharArray();
boolean u[] = new boolean[a.length];
int n = a.length;
int l = -1;
int x = 0;
int y = 0;
for (int i = 0; i<n; i++){
if (a[i] == 'y'){
y++;
}else if (a[i] == 'x'){
x++;
}
}
if (x > y){
for (int i = 0; i<x - y; i++)
out.print('x');
}else
for (int i = 0; i<y - x; i++)
out.print('y');
}
FastScanner in;
PrintWriter out;
String input = "";
String output = "";
void run() {
try {
if (input.length() > 0) {
in = new FastScanner(new BufferedReader(new FileReader(input)));
} else
in = new FastScanner(new BufferedReader(new InputStreamReader(
System.in)));
if (output.length() > 0)
out = new PrintWriter(new FileWriter(output));
else
out = new PrintWriter(System.out);
solve();
out.flush();
out.close();
} catch (Exception ex) {
ex.printStackTrace();
out.flush();
out.close();
} finally {
out.close();
}
}
public static void main(String[] args) {
new b().run();
}
class FastScanner {
BufferedReader bf;
StringTokenizer st;
public FastScanner(BufferedReader bf) {
this.bf = bf;
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(bf.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public String nextLine() throws IOException {
return bf.readLine();
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
}
| Java | ["x", "yxyxy", "xxxxxy"] | 2 seconds | ["x", "y", "xxxx"] | NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx". | Java 6 | standard input | [
"implementation"
] | 528459e7624f90372cb2c3a915529a23 | The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. | 1,200 | In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.