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 | 78d569fe093bb57fece12443b00be267 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.io.*;
import java.util.*;
public class C322C
{
public static StringTokenizer st;
public static void nextLine(BufferedReader br) throws IOException
{
st = new StringTokenizer(br.readLine());
}
public static String next()
{
return st.nextToken();
}
public static int nextInt()
{
return Integer.parseInt(st.nextToken());
}
public static long nextLong()
{
return Long.parseLong(st.nextToken());
}
public static double nextDouble()
{
return Double.parseDouble(st.nextToken());
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nextLine(br);
int n = nextInt();
int k = nextInt();
int[] a = new int[n];
nextLine(br);
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
int[] rem = new int[n];
int total = 0;
for (int i = 0; i < n; i++)
{
total += a[i] / 10;
rem[i] = a[i] % 10;
}
Arrays.sort(rem);
int count = 0;
int i;
for (i = n-1; i >= 0; i--)
{
if (rem[i] == 0) break;
if (k >= (10 - rem[i]))
{
k -= (10 - rem[i]);
count++;
}
else
{
break;
}
}
if (k >= 10)
{
int other = k / 10;
other = Math.min(other, n*10 - total - count);
count += other;
}
System.out.println(total + count);
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | 3dd5b8afe2cb85d412ab647178cba65d | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 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.StringTokenizer;
public class ProblemC {
public static void main(String[] args) {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
new ProblemC().solve(in, out);
out.close();
}
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int res = 0;
Pair[] a = new Pair[n];
for (int i = 0; i < n; i++) {
int t = in.nextInt();
int x = (t + 9) / 10;
int d = 10 * x - t;
a[i] = new Pair(t, d);
res += t / 10;
}
Arrays.sort(a);
int r = 0;
for (int i = 0; i < n; i++) {
if (k <= 0) {
out.print(res);
return;
} else {
Pair p = a[i];
if (k >= p.d && p.d > 0) {
res += 1;
k -= p.d;
}
r += 100 - (p.a + p.d);
}
}
res += Math.min(k / 10, r / 10);
out.print(res);
}
private static class Pair implements Comparable<Pair> {
int a;
int d;
Pair(int a, int d) {
this.a = a;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return d - p.d;
}
}
static class InputReader {
public BufferedReader br;
public StringTokenizer st;
public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | 0a632f0004c486b1fc04ed2bad6f7e31 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
public class tree {
public static void main(String []args) throws IOException{
BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
String lines[];
int n,k;
lines = in.readLine().trim().split("\\s+");
n = Integer.parseInt(lines[0]);
k = Integer.parseInt(lines[1]);
lines = in.readLine().trim().split("\\s+");
int ans=0;
int left=0;
int count[]= new int[10];
for(int i=0;i<n;i++){
int tep=Integer.parseInt(lines[i]);
ans+=tep/10;
if(tep%10!=0){
count[10-tep%10]++;
}
left+=(100-tep)/10;
}
for(int i=1;i<10&&k>0;i++){
if(i*count[i]<=k){
ans+=count[i];
k-=i*count[i];
}else{
ans+=k/i;
k=0;
}
}
if(k>0){
ans+=Math.min(left, k/10);
}
System.out.println(ans);
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | bd52452c438e8527bac0bf5fd7381066 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner x=new Scanner (System.in);
int n=x.nextInt();
int k=x.nextInt();
Integer arr[]=new Integer [n];
for(int i=0;i<n;i++){
arr[i]=x.nextInt();
}
Arrays.sort(arr, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
if(o1%10>o2%10)return 1;
else if(o1%10==o2%10)return 0;
else return -1;
}
});
boolean f=false;;
for(int i=arr.length-1;i>=0;i--){
if(k>=10-arr[i]%10&&arr[i]<=100&&arr[i]%10!=0){
k=k-(10-arr[i]%10);
arr[i]+=10-arr[i]%10;
}
}
for(int i=0;i<arr.length;i++){
if(arr[i]<100&&k>=100-arr[i]){
k-=100-arr[i];
arr[i]+=100-arr[i];
}
else if(arr[i]<100&&k>=10){
arr[i]+=k;
break;
}
}
long tot=0;
for(int i=0;i<arr.length;i++){
tot+=arr[i]/10;
}
System.out.println(tot);
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | eb72cac3dd7b37e04c7bb6d0fe895758 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.TreeSet;
/**
* Created by Tkachi on 2015/9/28.
*/
public class Task3 {
public static void main(String[] arg) throws IOException {
Task3 task = new Task3();
task.run();
}
private void run() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nAndK = br.readLine();
int n = Integer.parseInt(nAndK.split(" ")[0]);
int k = Integer.parseInt(nAndK.split(" ")[1]);
String str = br.readLine();
String[] skills = str.split(" ");
Comparator comp = new SkillComparator();
TreeSet<Skill> skillsSet = new TreeSet<Skill>(comp);
for(int i=0;i<n;i++){
skillsSet.add(new Skill(Integer.parseInt(skills[i])));
}
while(k>0){
Skill first = skillsSet.pollFirst();
if(first.getLevel()==10){
skillsSet.add(first);
break;
}else{
int pointAdd = Math.min(k, first.pointsToNextLevel());
k = k-pointAdd;
first.addPoints(pointAdd);
skillsSet.add(first);
}
}
long count = 0l;
for(Skill skill:skillsSet){
count = count + (long) skill.getLevel();
}
System.out.println(count);
}
private class SkillComparator implements Comparator<Skill>{
@Override
public int compare(Skill o1, Skill o2) {
if(o1.pointsToNextLevel()-o2.pointsToNextLevel() !=0){
return o1.pointsToNextLevel()-o2.pointsToNextLevel();
} else{
return -1;
}
}
}
private class Skill{
private int skillInt;
public Skill(int skillInt){
this.skillInt = skillInt;
}
public int getLevel(){
return skillInt/10;
}
public int pointsToNextLevel(){
if(getLevel()==10){
return Integer.MAX_VALUE;
}else {
return (10 * (getLevel() + 1) - skillInt);
}
}
public void addPoints(int i){
this.skillInt = i + skillInt;
}
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | dfed396b78dbd0879e674f6eae2eb9af | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class DevSkills581C {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
/*
* All possible inputs
int n = sc.nextInt(); // read input as integer
long k = sc.nextLong(); // read input as long
double d = sc.nextDouble(); // read input as double
String str = sc.next(); // read input as String
String s = sc.nextLine(); // read whole line as String
*/
//Pretty much looking for best possible way to level up character...
// I think the best strategy is just to improve the ones close to a 10 (round up)
// Do the closest one first until we have run out of improvement points
// if still have more left, then give to any skill
//Get input
int numSkills = sc.nextInt();
int numPoints = sc.nextInt();
Integer[] skills = new Integer[numSkills];
// skills but each number reversed, then sorted, then rereversed
//int[] sortSkills = new int[numSkills];
//int[] sortIntSkills = new int[numSkills];
//int[] indices = new int[numSkills];
int diff10 = 0;
int maxLvl = 0;
//Fill in the values; since we want to sort by the 1s column, fill in sortSkills too
for(int i= 0; i < numSkills; i++)
{
skills[i] = sc.nextInt();
maxLvl += skills[i]/10;
}
//Sort skills
Arrays.sort(skills, new Comparator<Integer>() {
public int compare(Integer num1, Integer num2)
{
String str1 = num1 +"";
String str2 = num2 +"";
return str2.charAt(str2.length()-1) - str1.charAt(str1.length()-1);
}
});
//Check what's in skills
// for(int i = 0; i < numSkills; i++)
// {
// System.out.println(skills[i]);
// }
//Spend the points
loop:
while(numPoints > 0)
{
for(int i = 0; i < numSkills; i++)
{
diff10 = 10 - (skills[i]%10);
if(diff10 <= numPoints && skills[i] < 100)
{
//System.out.println("diff " +diff10);
//System.out.println(skills[i]);
skills[i] += diff10;
numPoints -= diff10;
maxLvl++;
}
else if(numPoints < 10){
//System.out.println("numPts " + numPoints);
//System.out.println(skills[i]);
break loop;
}
}
// Arrays.sort(skills, new Comparator<Integer>() {
// public int compare(Integer num1, Integer num2)
// {
// String str1 = num1 +"";
// String str2 = num2 +"";
// return str2.charAt(str2.length()-1) - str1.charAt(str1.length()-1);
// }
// });
//If it goes through all of them, just add rest if able
int potential = numPoints/10;
while(potential > 0)
{
for(int i = 0; i < numSkills; i++)
{
while(skills[i] <=90 && potential > 0)
{
skills[i] += 10;
numPoints-=10;
potential--;
maxLvl++;
}
//System.out.println(skills[i]);
}
break loop;
}
}
// for(int i = 0; i < numSkills; i++)
// {
// System.out.println(skills[i]);
// }
out.println(maxLvl);
out.close();
}
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | 6e7a02c48335e4eecf68abe0e44e8f5e | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.io.*;
import java.util.Arrays;
public class Main {
static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int nextInt() throws IOException
{
in.nextToken();
return (int)in.nval;
}
static int n,k,a,ans;
static Pair[] aa=new Pair[1000000];
static class Pair implements Comparable<Pair>
{
int x,y;
Pair(int a,int b)
{
x=a;y=b;
}
public int compareTo(Pair p) {
return p.x-this.x;
}
}
public static void main(String[] args) throws IOException {
n=nextInt();k=nextInt();
for(int i=0;i<n;i++)
{
a=nextInt();
aa[i]=new Pair(a%10,a);
}
Arrays.sort(aa,0,n);
for(int i=0;i<n;i++)
{
if(aa[i].x==0||k<10-aa[i].x) break;
aa[i].y+=10-aa[i].x;
k-=10-aa[i].x;
}
if(k>=10)
{
for(int i=0;i<n;i++)
{
if(100-aa[i].y<k)
{
k-=100-aa[i].y;
aa[i].y=100;
}
else
{
aa[i].y+=k/10*10;
break;
}
}
}
for(int i=0;i<n;i++)
ans+=aa[i].y/10;
System.out.println(ans);
}
} | Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | 974bab4d8bdc3288a5005109b1e5f74b | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* Created by Юля on 28.09.2015.
*/
public class SolverC581 {
public static void main(String[] args) throws IOException {
new SolverC581().run();
}
BufferedReader br;
PrintWriter pw;
StringTokenizer tokenizer;
public String nextToken() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(br.readLine());
}
return tokenizer.nextToken();
}
public int nextInt() throws IOException, NumberFormatException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException, NumberFormatException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException, NumberFormatException {
return Double.parseDouble(nextToken());
}
public void run() throws IOException {
// br = new BufferedReader(new FileReader("input.txt"));
// pw = new PrintWriter("output.txt");
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
solve();
pw.flush();
pw.close();
}
class Skill implements Comparable<Skill>{
public int rank;
public int ed;
public Skill(int rank, int ed) {
this.rank = rank;
this.ed = ed;
}
@Override
public int compareTo(Skill o) {
return this.ed-o.ed;
}
}
private void solve() throws IOException {
int n=nextInt();
int k=nextInt();
Skill[] skills=new Skill[n];
long res=0;
for(int i=0;i<n;i++){
int zn=nextInt();
int zn1=zn;
if(zn%10==0)
zn=0;
else
zn=10-zn%10;
Skill skill=new Skill(zn1/10,zn);
skills[i]=skill;
}
Arrays.sort(skills);
long sum=0;
boolean ok=false;
for(int i=0;i<n;i++){
if(k>=skills[i].ed && skills[i].ed>0 && skills[i].rank<10){
skills[i].rank+=1;
res+=skills[i].rank;
k-=skills[i].ed;
skills[i].ed=0;
// ok=(i==n-1);
}else{
// if(skills[i].rank<=10){
res+=skills[i].rank;
// }
}
sum+=100-(skills[i].rank*10+skills[i].ed);
}
if(k>0){
long tmp=Math.min(k,sum);
res+=tmp/10;
}
pw.println(res);
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | cc6d89bedc42ee15931fa1a71fdd5b93 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.util.*;
public class Solution {
static Scanner scan = new Scanner(System.in);
static Random x = new Random();
public static void main(String[] args) throws Exception{
Solution sol = new Solution();
sol.run();
}
private void run() throws Exception {
int n = scan.nextInt(),
k = scan.nextInt();
int a[] = new int[n];
for (int i = 0; i < a.length; i++)
a[i] = scan.nextInt();
Arrays.sort(a);
int tmp = 0;
for (int j = 9; j > 0; j--) {
for (int i = 0; i < a.length; i++) {
if ((a[i] + 10 - j) % 10 == 0 && k - (10 - j) >= 0){
a[i] += 10 - j;
k -= 10 - j;
}
}
}
int i = 0;
while (k >= 10 && i < a.length){
if (a[i] < 100){
a[i] += 10;
k -= 10;
}
else
i++;
}
for (Integer x : a)
tmp += x / 10;
System.out.println(tmp);
}
}
| Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | a69e959f14f6a21f59b714220de1c4b9 | train_000.jsonl | 1443430800 | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Scanner in;
static PrintWriter out;
public static void main(String[] args) {
in = new Scanner(System.in);
new Main().solve();
}
void solve() {
int n = in.nextInt(), k = in.nextInt();
Integer[] arr = new Integer[n];
for (int i = 0; i < n; ++i)
arr[i] = in.nextInt();
Arrays.sort(arr, new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
if (a % 10 < b % 10) return 1;
if (a % 10 == b % 10) return 0;
return -1;
}
});
for (int i = 0; i < n; ++i)
while (arr[i] % 10 != 0 && k > 0) {
arr[i] ++;
k --;
}
for (int i = 0; i < n; ++i)
while (k >= 10 && arr[i] <= 90) {
k -= 10;
arr[i] += 10;
}
int answer = 0;
for (int i = 0; i < n; ++i)
answer += arr[i] / 10;
System.out.println(answer);
}
} | Java | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | 1 second | ["2", "5", "20"] | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to . | Java 7 | standard input | [
"implementation",
"sortings",
"math"
] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character. | 1,400 | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | standard output | |
PASSED | 43dcb944d9d6cb4a540f78b88ddc9a93 | train_000.jsonl | 1501425300 | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String args[])throws IOException {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
StringTokenizer st=new StringTokenizer(sc.readLine());
int n=ip(st.nextToken());
while (n-- > 0) {
st = new StringTokenizer(sc.readLine());
long a = lp(st.nextToken());
long b = lp(st.nextToken());
long c = (long) Math.cbrt(a * b);
boolean flag = (a % c == 0) && (b % c == 0) && (c*c*c == a * b);
out.println(flag ? "Yes" : "No");
}
out.close();
}
public static int ip(String s) {
return Integer.parseInt(s);
}
public static long lp(String s) {
return Long.parseLong(s);
}
} | Java | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | Java 8 | standard input | [
"math"
] | 933135ef124b35028c1f309d69515e44 | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | 1,700 | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | standard output | |
PASSED | 31cd2433946709c9d7830a9d1dc8ec00 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
public class solii_runner{
static class helper
{
public int Parent(int index)
{
return index >> 1;
}
public int Left(int index)
{
return (index << 1);
}
public int Right(int index)
{
return (index << 1) | 1;
}
}
static class min_heap extends helper{
private final int max_heap_size = 0xfffff;
private int [] heap = new int[max_heap_size];
private int heap_size = 0;
public min_heap()
{
}
public int size()
{
return heap_size;
}
public Boolean empty()
{
return heap_size < 1;
}
public int heap_min()
{
return heap[1];
}
public void extract_min()
{
//System.out.println(heap_min());
heap[1] = heap[heap_size];
heap_size --;
heapify(1);
}
public void insert(int x)
{
heap_size ++;
heap[heap_size] = x;
sift_up(heap_size);
}
private void sift_up(int index)
{
while(index > 1)
{
if(heap[ Parent(index) ] > heap[index])
{
int temp = heap[index];
heap[index] = heap[ Parent(index) ];
heap[ Parent(index) ] = temp;
index >>= 1;
}
else break;
}
}
private void heapify(int index)
{
while(index <= heap_size)
{
int pos = index;
if(Left(index) <= heap_size && heap[ Left(index) ] < heap[pos])
pos = Left(index);
if(Right(index) <= heap_size && heap[ Right(index) ] < heap[pos])
pos = Right(index);
if(pos == index)
break;
int temp = heap[index];
heap[index] = heap[pos];
heap[pos] = temp;
index = pos;
}
}
}
public static void main(String [] args)
{
//mysolii me = new mysolii(15);
//me.printer();
//me.printme();
//child_solii me = new child_solii();
//me.Print_Me();
//me.Print_Parent();
int n, ans = 0;
long total = 0;
Scanner in = new Scanner(System.in);
min_heap me = new min_heap();
n = in.nextInt();
for(int i = 0 ; i < n ; i ++)
{
me.insert(in.nextInt());
}
for(int i = 0 ; i < n ; i ++)
{
//System.out.println(me.heap_min());
if(total <= me.heap_min())
{
ans ++;
total += me.heap_min();
}
me.extract_min();
}
System.out.println(ans);
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 56f9f0b0a4858d1460f14b7683a8a544 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF545D{
public static void main(String[] args)throws Exception {
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt();
int a[] = new int[n];
for(int i = 0; i < n; i++){
a[i] = in.nextInt();
}
Arrays.sort(a);
int count = 0, lo = 0;
long sum = 0;
for(int i = 0; i < n; i++){
int key = bSearch(sum, lo, a);
if(sum <= a[key]){
count++;
lo = key+1;
sum += a[key];
if(lo == n) break;
}
else{
break;
}
}
pw.println(count);
pw.close();
}
static int bSearch(long num, int l, int [] arr){
int lo = l, hi = arr.length-1, mid = (lo+hi)/2;
long temp = 0;
while(lo < hi){
mid = (lo+hi)/2;
temp = arr[mid];
if( temp >= num) hi = mid;
else lo = mid+1;
}
return lo; //returns the lowest index where arr[lo] = num;
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext(){
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
}
catch (Exception e) {
return false;
}
return true;
}
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 97cf7630676f9c759d3c178bfa0943b0 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF545D{
public static boolean[] bol;
public static void main(String[] args)throws Exception {
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt();
int a[] = new int[n];
bol = new boolean[n];
for(int i = 0; i < n; i++){
a[i] = in.nextInt();
}
Arrays.sort(a);
int count = 0, lo = 0;
long sum = 0;
for(int i = 0; i < n; i++){
int key = bSearch(sum, lo, a);
// System.err.println(lo+" "+sum+" "+key);
if(sum <= a[key] && !bol[key]){
count++;
lo = key+1; if(lo == n) lo--;
bol[key] = true;
sum += a[key];
}
else{
break;
}
}
pw.println(count);
pw.close();
}
static int bSearch(long num, int l, int [] arr){
int lo = l, hi = arr.length-1, mid = (lo+hi)/2;
long temp = 0;
while(lo < hi){
mid = (lo+hi)/2;
temp = arr[mid];
if( temp >= num) hi = mid;
else lo = mid+1;
}
return lo; //returns the lowest index where arr[lo] = num;
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext(){
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
}
catch (Exception e) {
return false;
}
return true;
}
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | ba5ba654fb4bd04a194ef9068c3311a8 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
public class Main_545D {
public static void main(String[] args) throws IOException {
StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int n = readInt(tokenizer);
int[] array = readArray(n, tokenizer);
Arrays.sort(array);
int sum = 0;
int res = 0;
for (int i = 0; i < n; i++) {
if (array[i] >= sum ) {
sum+= array[i];
res++;
}
}
System.out.println(res);
}
public static int readInt(StreamTokenizer tokenizer) throws IOException {
tokenizer.nextToken();
return (int) tokenizer.nval;
}
public static int[] readArray(int size, StreamTokenizer tokenizer) throws IOException {
int[] result = new int[size];
for (int i = 0; i < size; i++) {
result[i] = readInt(tokenizer);
}
return result;
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 7c1d260c7beabbc774ec98eaf8596444 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
public class q {
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String a=s.nextLine();
String t=s.nextLine();
String b[]=t.split(" ");
int c[]=new int[b.length];
for(int i=0;i<b.length;i++)
{
c[i]=Integer.parseInt(b[i]);
}
Arrays.sort(c);
//for(int i=0;i<b.length;i++)
//{
//System.out.println(c[i]);
//}
int count=1;
int time=c[0];
for(int j=0;j<c.length;j++)
{
if(j+1<c.length)
{
if(time<=c[j+1])
{
count=count+1;
time=time+c[j+1];
}
}
}
System.out.print(count);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 81b06ecec8dc1efeb345108f1b3af727 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | //package helloworld;
import java.util.*;
import java.io.*;
public class QueueTime
{
public static void main(String[] args)throws Throwable
{
PrintWriter pw = new PrintWriter(System.out);
BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> t = new ArrayList<Integer>();
int n =Integer.parseInt(bf.readLine());
String [] s = bf.readLine().split(" ");
for(int i=0;i<n;i++)
{
t.add(Integer.parseInt(s[i]));
}
Collections.sort(t);int sum=t.get(0);int d=1;
for(int i=1;i<t.size();i++)
{
if(sum<=t.get(i))
{
sum+=t.get(i);
d++;
}
}
pw.println(d);
pw.close();
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 04aa3e207815be3952e8d46ed76cbbcf | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | // package CodeForces;
import java.util.*;
import java.io.*;
public class Problem_545D
{
public static void main(String[] args)throws Throwable
{
PrintWriter pw = new PrintWriter(System.out);
BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> t = new ArrayList<Integer>();
int n =Integer.parseInt(bf.readLine());
String [] s = bf.readLine().split(" ");
for(int i=0;i<n;i++)
{
t.add(Integer.parseInt(s[i]));
}
Collections.sort(t);
int sum=t.get(0);
int d=1;
for(int i=1;i<t.size();i++)
{
if(sum<=t.get(i))
{
sum+=t.get(i);
d++;
}
}
pw.println(d);
pw.close();
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | ce227df9741db7269e39d24d2d731352 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | //package helloworld;
import java.util.*;
import java.io.*;
public class QueueTime
{
public static void main(String[] args)throws Throwable
{
PrintWriter pw = new PrintWriter(System.out);
BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> t = new ArrayList<Integer>();
int n =Integer.parseInt(bf.readLine());
String [] s = bf.readLine().split(" ");
for(int i=0;i<n;i++)
{
t.add(Integer.parseInt(s[i]));
}
Collections.sort(t);int sum=t.get(0);int d=1;
for(int i=1;i<t.size();i++)
{
if(sum<=t.get(i))
{
sum+=t.get(i);
d++;
}
}
pw.println(d);
pw.close();
}
}
//code
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 546444c2a513ec8b42146edeaf4786b5 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | // Queues
// Codeforces code - 545D
import java.util.Arrays;
import java.util.Scanner;
public class q {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
long arr[] = new long[n];
for (int i= 0;i<n;i++)
{
arr[i] = scan.nextLong();
}
Arrays.sort(arr);
// System.out.println(Arrays.toString(arr));
long sum = arr[0], c = 1;
for (int i= 1;i<n;i++)
{
if (arr[i]>=sum)
{ c++;
sum+=arr[i];}
}
System.out.print(c);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | d0abc05fdd30870119b7fc45ac7f1e25 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
public class SolutionC {
public static void main(String args[]){
Scanner s1=new Scanner(System.in);
int n=s1.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=s1.nextInt();
}
Arrays.sort(arr);
long sum=0,count=0;
for(int i=0;i<n;i++){
int ext=arr[i];
if(sum<=ext){
sum+=ext;
count++;
}
}
System.out.println(count);
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | a225553d5ad751dbffd0c3d1b4a23cb7 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class pre422
{
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 obj = new FastReader();
int n = obj.nextInt(),arr[] = new int[n];
for(int i=0;i<n;i++) arr[i] = obj.nextInt();
Arrays.sort(arr);
int ans = 0,count = 0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]>=ans)
{
count++;
ans+=arr[i];
}
}
System.out.println(count);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 0fe4dbc0566efe0a6a1d3a7fca31db8e | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), ans = 0;
long counter = 0;
int arr[] = new int[n];
for (int i = 0; i < n; i++) arr[i] = in.nextInt();
Arrays.sort(arr);
for (int i = 0; i < n; i++) {
if (arr[i] >= counter) {
counter += arr[i];
ans++;
}
}
out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | bb92be94a877aecd36ee008831bbe78d | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
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);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), counter, ans = 1;
int arr[] = new int[n];
List<Integer> list = new ArrayList<>();
List<Integer> curr = new ArrayList<>();
curr.add(0);
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
Arrays.sort(arr);
for (int i = 0; i < n; i++) {
list.add(arr[i]);
}
curr.add(arr[0]);
list.remove(list.get(0));
for (int i = 1; ; i++) {
if (curr.size() != i + 1) break;
counter = curr.get(i);
for (int j = i - 1; j >= 0; j--) {
counter += curr.get(j);
}
for (int j = 0; j < list.size(); j++) {
if (list.get(j) >= counter) {
ans++;
curr.add(list.get(j));
list.remove(list.get(j));
break;
}
}
}
out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 3d8d3654f897cd2b988f6ad9e30f302d | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | //package Queue;
import java.util.PriorityQueue;
import java.util.Scanner;
/**
* Created by kanghuang on 5/23/15.
*/
public class D {
//greedy idea is biased
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for (int i = 0; i < n; i++){
pq.offer(reader.nextInt());
}
int acc = 0;
int m = 0;
while(!pq.isEmpty()){
int num = pq.poll();
if (acc <= num){
m++;
acc += num;
}
}
System.out.print(m);
}
// public static void main(String[] args){
// Scanner reader = new Scanner(System.in);
// int n = reader.nextInt();
// int[] A = new int[n];
// long [] sum = new long[n+1];
// for (int i = 0; i < n; i++){
// A[i] = reader.nextInt();
// }
// Arrays.sort(A);
// int d[] = new int [n+1];
// for (int i = 1; i <= n; i++){
// for (int j = i-1; j >=0; j--){
// if (sum[j] <= A[i-1]){
// if (d[i] > d[j] + 1){
// break;
// }
// d[i] = d[j] + 1;
// sum[i] = sum[j] + A[i-1];
// }
// }
// }
// int maxd = 0;
// for (int i = 1; i <= n; i++){
// maxd = Math.max(maxd, d[i]);
// }
// System.out.print(maxd);
// }
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 4d9b660722a6aa6847aa01b6b82b6241 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int n=sc.nextInt();
Integer arr[]=new Integer[n];
for (int i=0;i<n;i++)arr[i]=sc.nextInt();
Arrays.sort(arr);
int sum=0;int cnt=0;
for (int i=0;i<n;i++){
if (sum<=arr[i]){
sum+=arr[i];
cnt++;
}
}
System.out.println(cnt);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 7859ceaac2dda603b6aabe88ab4866b4 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
ArrayList<Integer> time = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
time.add(scan.nextInt());
}
Collections.sort(time);
int overTime = 0;
int res = 0;
for (int i = 0; i < time.size(); i++) {
if (overTime <= time.get(i)) {
++res;
overTime += time.get(i);
}
}
System.out.println(res);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 30fdd63733c5d26bc4f37d8f7f389c72 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] time = new int[n];
for (int i = 0; i < n; i++) {
time[i] = scan.nextInt();
}
Arrays.sort(time);
int overTime = 0;
int res = 0;
for (int i = 0; i < time.length; i++) {
if (overTime <= time[i]) {
++res;
overTime += time[i];
}
}
System.out.println(res);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 72348270a767e81c5d7595428b7368f7 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
public class Permatation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long c=0;
long max=0;
long n=sc.nextLong();
List<Long> timeForBeenServed = new ArrayList<Long>();
for(int i=0;i<n;i++)
{
timeForBeenServed.add(sc.nextLong());
}
Collections.sort(timeForBeenServed);
for(int i=0;i<timeForBeenServed.size();i++)
{
if(timeForBeenServed.get(i)>=max)
{
c++;
max+=timeForBeenServed.get(i);
}
}
System.out.println(c);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | d1d1675951a93371b06f269e9c2ae39b | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 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.StringTokenizer;
public class _18Queue {
public static void main(String[] args) {
FastInput input = new FastInput();
PrintWriter output = new PrintWriter(System.out);
int n = input.nextInt();
int[] servingTime = new int[n];
long waitingTimeTotal = 0;
for (int i = 0; i < n; i++) servingTime[i] = input.nextInt();
Arrays.sort(servingTime);
int res = 0;
for (int i = 0; i < n; i++) {
if (waitingTimeTotal > servingTime[i]) continue;
else {
waitingTimeTotal += servingTime[i];
res++;
}
}
output.println(res);
output.close();
}
static class FastInput {
BufferedReader br;
StringTokenizer st;
public FastInput() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | efad1ec14dbfc5bc2c158f328a61f73f | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t;
t = 1;//sc.nextInt();
while (t-->0){
solve(sc);
}
}
public static void solve(Scanner sc){
int n = sc.nextInt();
int ans = 0;
ArrayList<Integer> al = new ArrayList<>();
while (n-->0){
al.add(sc.nextInt());
}
Collections.sort(al);
int wait = 0;
for(int serve : al){
if(wait <= serve){
ans++;
wait = wait + serve;
}
}
System.out.println(ans);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 47204e0fc6b1b25b5bd1b040a3579f50 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
/**
* Created by William on 10/22/16.
*/
public class main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int[] a = new int[size];
ArrayList<Integer> aList = new ArrayList<>();
for(int i = 0; i < size; i++){
aList.add(in.nextInt());
}
aList.sort(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if(o1 < o2)
return -1;
else if(o1 > o2)
return 1;
else
return 0;
}
});
// System.out.println(aList.toString() + "\n");
// a[0] = aList.get(0);
// for(int i = 1; i < size; i++){
// a[i] = a[i-1] + aList.get(i);
// }
// for(int i = 0; i < size; i++)
// System.out.print(a[i] + ", ");
int finalReturn = 1;
int sum = aList.get(0);
for(int i = 1; i < size; i++){
if(aList.get(i) >= sum) {
sum +=aList.get(i);
finalReturn++;
}
}
System.out.println(finalReturn);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 94e6057a72ddd99b605d066df4fce424 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.util.*;
import java.io.*;
import java.math.*;
public class Fff {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int q=Integer.parseInt(bf.readLine());
String in[]=bf.readLine().split(" ");
ArrayList<Integer> al=new ArrayList();
for(int i=0;i<q;i++){int x=Integer.parseInt(in[i]);al.add(x);}
Collections.sort(al);
long ll=0l;
int count=0;
for(int i=0;i<q;i++){if(al.get(i)>=ll){count++;ll+=(long)al.get(i);}}
System.out.println(count);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 2fa0929f882a500bc13417931d72e997 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
public class Main {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n=Reader.nextInt();
Integer []a=new Integer[n];
for (int i = 0; i < n; i++) {
a[i]=Reader.nextInt();
}
Arrays.sort(a);
int sum=0,ans=0;
for (int i = 0; i < n; i++) {
if(sum<=a[i]){
ans++;
sum+=a[i];
}
}
System.out.println(ans);
}
}
class Reader {
static StringTokenizer tokenizer;
static BufferedReader reader;
public static void init(InputStream input) throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
tokenizer = new StringTokenizer("");
}
public static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static String nextLine() throws IOException {
return reader.readLine();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 89bcce5f6bdb310ea52018558e0f37eb | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
public class Main {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n=Reader.nextInt();
int[]time=new int[n];
for (int i = 0; i < n; i++) {
time[i]=Reader.nextInt();
}
Arrays.sort(time);
int sum=0,ans=0;
for (int i = 0; i < n; i++) {
if(sum<=time[i]){
ans++;
sum+=time[i];
}
}
System.out.println(ans);
}
}
class Reader {
static StringTokenizer tokenizer;
static BufferedReader reader;
public static void init(InputStream input) throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
tokenizer = new StringTokenizer("");
}
public static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static String nextLine() throws IOException {
return reader.readLine();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 389ac89e93bd0c2a13e4aad2fa125494 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
public class Main {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n=Reader.nextInt();
int []a=new int[n];
for (int i = 0; i < n; i++) {
a[i]=Reader.nextInt();
}
Arrays.sort(a);
int sum=0,ans=0;
for (int i = 0; i < n; i++) {
if(sum<=a[i]){
ans++;
sum+=a[i];
}
}
System.out.println(ans);
}
}
class Reader {
static StringTokenizer tokenizer;
static BufferedReader reader;
public static void init(InputStream input) throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
tokenizer = new StringTokenizer("");
}
public static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static String nextLine() throws IOException {
return reader.readLine();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 2b5c25b06135a2dae7441573a8e40112 | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.io.*;
import static java.lang.Integer.sum;
import java.lang.reflect.Array;
import java.util.*;
import java.math.*;
//import static java.lang.Math.*;
//import static java.lang.Integer.parseInt;
//import static java.lang.Long.parseLong;
//import static java.lang.Double.parseDouble;
//import static java.lang.String.*;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //(new FileReader("input.in"));
// StringBuilder out = new StringBuilder();
// StringTokenizer tk;
// Scanner s = new Scanner(System.in);
Reader.init(System.in);
//tk = new StringTokenizer(in.readLine());
int n = Reader.nextInt();
Integer [] a = new Integer[n];
for (int i = 0; i < n; i++) {
a[i]=Reader.nextInt();
}
Arrays.sort(a);
int sum = 0,c=0;
for (int i = 0; i < n; i++) {
if(sum<=a[i])
{
c++;
sum+=a[i];
}
}
System.out.println(c);
}
}
class Reader {
static StringTokenizer tokenizer;
static BufferedReader reader;
public static void init(InputStream input) throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
tokenizer = new StringTokenizer("");
}
public static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static String nextLine() throws IOException {
return reader.readLine();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | cbc511b5a1a6ecc912a417577a3735fc | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes |
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
public class Main {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n=Reader.nextInt();
int[]time=new int[n];
for (int i = 0; i < n; i++) {
time[i]=Reader.nextInt();
}
Arrays.sort(time);
int ans=0,sum=0;
for (int i = 0; i < n; i++) {
if(sum<=time[i]){
ans++;
sum+=time[i];
}
}
System.out.println(ans);
}
}
class Reader {
static StringTokenizer tokenizer;
static BufferedReader reader;
public static void init(InputStream input) throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
tokenizer = new StringTokenizer("");
}
public static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static String nextLine() throws IOException {
return reader.readLine();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 716080e074b282d1d6e55cdcdda9899a | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class D545 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(br.readLine());
StringTokenizer s=new StringTokenizer(br.readLine());
PriorityQueue<Integer> pq=new PriorityQueue<>();
for (int i = 0; i <n ; i++) {
pq.add(Integer.parseInt(s.nextToken()));
}
int count=0;
int val=0;
while(pq.isEmpty()==false)
{
int no=pq.poll();
if(no>=val)
{
count++;
val+=no;
}
}
System.out.println(count);
}
}
| Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 6704609d1722d9b6cfbafc4151ca999e | train_000.jsonl | 1432053000 | Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner in= new Scanner (System.in);
int a[]=new int[in.nextInt()];
for (int i = 0; i < a.length; i++)
a[i]=in.nextInt();
Arrays.sort(a);
int s=a[0],f=1;
for (int i = 1; i < a.length; i++) {
if(s<=a[i])
{
f++;
s+=a[i];
}
}
System.out.println(f);
}
} | Java | ["5\n15 2 1 5 3"] | 1 second | ["4"] | NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | 08c4d8db40a49184ad26c7d8098a8992 | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces. | 1,300 | Print a single number — the maximum number of not disappointed people in the queue. | standard output | |
PASSED | 96e80a552cea83f7765e6ef19026b1be | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author legionary
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int x = in.nextInt(), y = in.nextInt();
HashSet<Integer> s = new HashSet<>();
while (x != y) {
if (y < x) {
x = y;
break;
}
if (x % 2 == 1) {
if (x > 1) {
x--;
} else break;
} else {
x = 3 * (x / 2);
}
if (s.contains(x))
break;
s.add(x);
}
out.println(x == y ? "YES" : "NO");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 8ec15315ddb0ca3d65f4222752d197c9 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes |
import java.util.Scanner;
public class Problem1257B {
public static int magicStick1(int x, int y) {
return (x % 2 == 0) ? x = x * 3 / 2 : x > 1 ? x - 1 : 0;
}
public static void main(String[] args) {
Scanner key = new Scanner(System.in);
var num = key.nextInt();
var x = new int[num];
var y = new int[num];
for (int i = 0; i < num; i++) {
x[i] = key.nextInt();
y[i] = key.nextInt();
}
for (int i = 0; i < num; i++)
if (x[i] == y[i]) System.out.println("YES");
else if (x[i] == 1) System.out.println("NO");
else if (magicStick1(x[i], y[i]) >= y[i]) System.out.println("YES");
else if (magicStick1(magicStick1(x[i], y[i]), y[i]) == x[i]) System.out.println("NO");
else System.out.println("YES");
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 227847cb3faad421a069e44c1f5423a4 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class Problem1257Bv2 {
public static int magicStick1(int x, int y) {
if (x % 2 == 0) {
x = x*3/2;
return x;
} else if (x>1){
x--;
return x;
}
return 0;
}
public static void main(String[] args) {
var entrada = new Scanner(System.in);
int num = entrada.nextInt();
int[] x = new int[num];
int[] y = new int[num];
for (int i = 0; i < num; i++) {
x[i] = entrada.nextInt();
y[i] = entrada.nextInt();
}
for (int i = 0; i < num; i++) {
if (x[i] == y[i]) {
System.out.println("YES");
} else if (x[i]==1){
System.out.println("NO");
}else if (magicStick1(x[i],y[i])>=y[i]){
System.out.println("YES");
} else if (magicStick1(magicStick1(x[i],y[i]),y[i])==x[i]){
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | f249fdc101628c7004e8967f05ac304b | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class Problem1257Bv2 {
public static int magicStick1(int x, int y) {
if (x % 2 == 0) { x = x * 3 / 2; return x;
} else { return x > 1 ? x - 1 : 0; }
}
public static void main(String[] args) {
var entrada = new Scanner(System.in);
int num = entrada.nextInt();
int[] x = new int[num];
int[] y = new int[num];
for (int i = 0; i < num; i++) {
x[i] = entrada.nextInt();
y[i] = entrada.nextInt();
}
for (int i = 0; i < num; i++) {
if (x[i] == y[i]) {
System.out.println("YES");
} else if (x[i] == 1) {
System.out.println("NO");
} else if (magicStick1(x[i], y[i]) >= y[i]) {
System.out.println("YES");
} else if (magicStick1(magicStick1(x[i], y[i]), y[i]) == x[i]) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 6c6ced483871564242d40fd1976d59f5 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class Problem1257B {
public static int magicStick1(int x, int y) {
if (x % 2 == 0) {
x = x*3/2;
return x;
}
return 0;
}
public static int magicStick2(int x, int y){
if (x > 1) {
x--;
return x;
}
return 0;
}
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int num = entrada.nextInt();
int[] x = new int[num];
int[] y = new int[num];
for (int i = 0; i < num; i++) {
x[i] = entrada.nextInt();
y[i] = entrada.nextInt();
}
for (int i = 0; i < num; i++) {
if (x[i] == y[i]) {
System.out.println("YES");
} else if (x[i]==1){
System.out.println("NO");
}else if (magicStick1(x[i],y[i])>=y[i] || magicStick2(x[i],y[i])>=y[i]){
System.out.println("YES");
} else if (magicStick1(magicStick2(x[i],y[i]),y[i])==x[i] || magicStick2(magicStick1(x[i],y[i]),y[i])==x[i]){
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 9dbc85fd9d4df81c0a2bf0ab086adf73 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class codeforces_1257B {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t= sc. nextInt();
while(t-->0)
{
int x=sc.nextInt();
int y=sc.nextInt();
if(x==1 && y!=1)
{
System.out.println("no");
continue;
}
if((x==2 || x==3) && y>=4 )
{
System.out.println("no");
continue;
}
System.out.println("yes");
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 4564b8a6700aaaa47c1ca540a1ffa9b0 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
public class ED_R_76B {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
for(int i =0;i<t;i++) {
String xy = sc.nextLine();
String[] numbers = xy.split(" ");
long x=Integer.parseInt(numbers[0]);
long y=Integer.parseInt(numbers[1]);
if(x>=y||x>3)
System.out.println("YES");
else {
if(x==2&&y<=3)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 6a76b7bf84b74e1553916717b1661af9 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.util.Set;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Rustam Musin (t.me/musin_acm)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BVolshebnayaPalochka solver = new BVolshebnayaPalochka();
solver.solve(1, in, out);
out.close();
}
static class BVolshebnayaPalochka {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.readInt();
while (t == 19) ;
while (t-- > 0) {
long x = in.readLong();
long y = in.readLong();
Set<Long> used = new HashSet<>();
while (true) {
if (!used.add(x)) break;
if (x >= y) break;
if (x % 2 == 0) x = x * 3 / 2;
else if (x > 1) x--;
else break;
}
out.printLine(x >= y ? "YES" : "NO");
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
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 isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | fa9ffef337ec27002d48bb1d0f1f8be7 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.util.Set;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Rustam Musin (t.me/musin_acm)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
BVolshebnayaPalochka solver = new BVolshebnayaPalochka();
solver.solve(1, in, out);
out.close();
}
static class BVolshebnayaPalochka {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.readInt();
while (t-- > 0) {
long x = in.readLong();
long y = in.readLong();
Set<Long> used = new HashSet<>();
while (true) {
if (!used.add(x)) break;
if (x >= y) break;
if (x % 2 == 0) x = x * 3 / 2;
else if (x > 1) x--;
else break;
}
out.printLine(x >= y ? "YES" : "NO");
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
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 isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | ae9d3d75de731375e750e4dcbb702c13 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) throws IOException {
FastReader ip = new FastReader();
OutputStream output = System.out;
PrintWriter out = new PrintWriter(output);
int t=ip.nextInt();
while(t-->0){
long x=ip.nextLong();
long y=ip.nextLong();
if(x>=y){
out.println("Yes");
}else{
HashSet<Long> hs=new HashSet<>();
hs.add(x);
while(x<y){
if(x%2==0){
x=(x*3)/2;
}else{
x--;
}
if(hs.contains(x)){
break;
}else{
hs.add(x);
}
}
if(x>=y){
out.println("Yes");
}else{
out.println("No");
}
}
}
out.close();
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | adaa3062c8fb065374c0b2c67c5ace16 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes |
import java.io.*;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.pow;
import java.util.*;
public class Kaudo {
static Reader in =new Reader();
static List<Integer>[] gr;
static StringBuilder sd=new StringBuilder();
public static void main(String [] Mamo) throws IOException {
//احلام البشر لا حدود لها
//why we do? ::: becase we can
int t=in.nextInt();
while(t-->0){
int x=in.nextInt(),y=in.nextInt();
if(x>=y){sd.append("YES"+"\n");}
else if(x!=y&&x==1){sd.append("NO"+"\n");}
else if((x==2||x==3)&&y>3){sd.append("NO"+"\n");}
else{sd.append("YES"+"\n");}
}
System.out.print(sd);
}
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
public String s(){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 long l(){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 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 double d() throws IOException {return Double.parseDouble(s()) ;}
public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = nextInt();}return ret;}
}
}
class node implements Comparable<node>{
int x,y;
node(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int compareTo(node o) {
return x-o.x;
}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 57d04d6ce08127fc2acc3c42ad5717b1 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class MagicSpell
{
public static String Spell(int x,int y)
{
if(x==0)
{
if(y==0)
{
return "YES";
}
return "NO";
}
else if(x==1)
{
if(y==0||y==1)
{
return "YES";
}
return "NO";
}
else if(x==2)
{
if(y==0||y==1||y==2||y==3)
{
return "YES";
}
return "NO";
}
else if(x==3)
{
if(y==0||y==1||y==2||y==3)
{
return "YES";
}
return "NO";
}
return "YES";
}
public static void main(String[] args)
{
int k,n,i,j;
String result;
List<Integer>a=new ArrayList<Integer>();
List<Integer>b=new ArrayList<Integer>();
Scanner input=new Scanner(System.in);
n=input.nextInt();
for(k=0;k<n;k++)
{
i=input.nextInt();
j=input.nextInt();
a.add(i);
b.add(j);
}
for(k=0;k<n;k++)
{
result=Spell(a.get(k),b.get(k));
System.out.println(result);
}
input.close();
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 99cd07d1e8b426a6720aa87715dc54d7 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;import java.io.*;import java.math.BigInteger;
public class Main
{
public static void process()throws IOException
{
//Your code here
int x=ni();
int y=ni();
if(x==1)
{
if(y==1)
pn("YES");
else
pn("NO");
}
else if(x<4)
{
if(y<4)
pn("YES");
else
pn("NO");
}
else
pn("YES");
}
static FastReader sc=new FastReader();
//static AnotherReader sc;
static boolean multipleTC=true;
static long mod=1000000007;
static class FastReader{BufferedReader br;StringTokenizer st;public FastReader()
{br=new BufferedReader(new InputStreamReader(System.in));}String next()
{while(st==null||!st.hasMoreElements())
{try{st=new StringTokenizer(br.readLine());}
catch(IOException e){e.printStackTrace();}}
return st.nextToken();}int nextInt()
{return Integer.parseInt(next());}long nextLong()
{return Long.parseLong(next());}double nextDouble()
{return Double.parseDouble(next());}
String nextLine(){String str="";try
{str=br.readLine();}catch(IOException e)
{e.printStackTrace();}return str;}}
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
static void pn(Object o){System.out.println(o);}
static void p(Object o){System.out.print(o);}
static void pni(Object o){System.out.println(o);System.out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String[]args)throws IOException
{
//sc=new AnotherReader();
int t=(multipleTC)?ni():1;
while(t-->0)
process();
System.out.flush();
System.out.close();
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | ba80740c42300e76f60d1143d6df9e7e | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i=0;i<n;i++){
String ans="NO";
long x=Long.parseLong(String.valueOf(in.nextInt()));
long y=Long.parseLong(String.valueOf(in.nextInt()));
long oldex=0;
while(x<y){
if(x%2==0) {
x = (3 * x) / 2;
}
else{
x-=1;
if(x==0 || oldex==x)
break;
oldex=x;
}
}
if(x>=y){
ans="YES";
}
System.out.println(ans);
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | c970de4724a7c9e4b3fb196eff45df7b | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main {
public static StreamTokenizer sc=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static int nextint() throws IOException {
sc.nextToken();
return (int)sc.nval;
}
public static void main(String args[]) throws IOException {
PrintWriter out=new PrintWriter(System.out);
int t=nextint();
while(t-->0) {
int x=nextint();
int y=nextint();
if(y<=x) {
out.println("YES");
}else if(x==1){
out.println("NO");
}else if(x==2&&y!=3) {
out.println("NO");
}else if(x==2&&y==3) {
out.println("YES");
}
else if(x<=3) {
out.println("NO");
}else {
out.println("YES");
}
}
out.flush();
out.close();
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 24bd487c442123ab3e6acb932f2a2356 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cases = Integer.parseInt(in.nextLine());
for (int i = 0; i < cases; i++) {
String[] input = in.nextLine().split(" ");
int x = Integer.parseInt(input[0]);
int target = Integer.parseInt(input[1]);
System.out.println(obtainable(x, target ) ? "YES" : "NO");
}
}
public static boolean obtainable(int x, int target) {
if (target < 0) {
return false;
}
if (target <= x) {
return true;
}
if (x < 4) {
if (x >= 2 && target <= 3) {
return true;
}
return false;
}
return true;
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 0a85a4cc108c03fb6c60a590373be360 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
int x = sc.nextInt();
int y = sc.nextInt();
boolean ans = false;
int cnt = 0;
if(y<=x){
ans = true;
}
else{
if((x==3 && y>3) || (x==2 && y>3) || x==1){
ans = false;
}
else{
ans = true;
}
}
if(ans){
System.out.println("YES");
}
else{
System.out.println("NO");
}
t--;
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 8b6b2f8197cc4dbbfe1e7e77e397ea35 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes |
import java.util.Scanner;
public class mqgic_stick {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0) {
int x = s.nextInt();
int y = s.nextInt();
if (x>=y) {
System.out.println("YES");
}else if((x==1 && y>1) || (x==3 && y>3) || (x==2 &&y>3)) {
System.out.println("NO");
}else {
System.out.println("YES");
}
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 26bae37686192e6b056dc2f6d518c660 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.System.*;
/*
Shortcut-->
Arrays.stream(n).parallel().sum();
string builder fast_output -->
outer in java-->study
*/
public class cf_hai1 {
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) throws IOException {
cf_hai1.FastScanner sc = new cf_hai1.FastScanner();
int test_case = sc.nextInt();
// int test_case = 1;
for (int z = 0; z < test_case; z++) {
int x=sc.nextInt();
int y=sc.nextInt();
solve(x,y);
}
}
private static void solve(int x, int y) {
if(x==y){
out.println("YES");
return;
}
if(x==3 && y>3 || x==1 && y>1 || x==2 && y>3){
out.println("NO");
return;
}
out.println("YES");
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 07bf211775eccc07ced573d4a7559401 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class Task{
private int arr[][];
private int T;
public Task(){
fill();
for(int i=0; i<T; i++){
System.out.println(test(arr[i][0], arr[i][1]));
}
}
public static void main(String args[]){
new Task();
}
String test(int x, int y){
String ret = "NO";
if(x>=y){
ret = "YES";
} else if(x>3){
ret = "YES";
} else if(x==2&&y==3){
ret = "YES";
}
return ret;
}
void fill(){
Scanner scan = new Scanner(System.in);
T = scan.nextInt();
arr = new int[T][2];
for(int i=0; i<T; i++){
arr[i][0] = scan.nextInt();
arr[i][1] = scan.nextInt();
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 8f568cd16caff8fb7a83c708230e516e | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
public class Cf1257B {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t,x,y;
t=sc.nextInt();
while(t>0) {
x=sc.nextInt();
y=sc.nextInt();
if(x>3)
System.out.println("YES");
else if(x==1) {
if(y==1)
System.out.println("YES");
else
System.out.println("NO");
}
else{
if(y==1 || y==2 || y==3)
System.out.println("YES");
else
System.out.println("NO");
}
t--;
}
sc.close();
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | eabddd166b26d38df01b2541e672feab | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
boolean multiple = true;
long MOD;
@SuppressWarnings({"Duplicates", "ConstantConditions"})
void solve() throws Exception
{
long x = sc.nextLong();
long y = sc.nextLong();
boolean gay;
if (x == 1) gay = y == 1;
else if (x == 2) gay = y <= 3;
else if (x == 3) gay = y <= 3;
else gay = true;
System.out.println(gay ? "YES" : "NO");
}
StringBuilder ANS = new StringBuilder();
void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
/*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 353a43a8046523e840f3049ed36d9d1c | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.Scanner;
public class Wand {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
String[] out = new String[x];
for (int i = 0; i < x; i++) {
int a = scanner.nextInt();
int b = scanner.nextInt();
out[i] = wand(a, b);
}
for (int i = 0; i < x; i++) {
System.out.println(out[i]);
}
}
public static String wand (int a, int b) {
if (a >= b || a > 3 || (a == 2 && b == 3)){
return "Yes";
} else {
return "No";
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 9d6a5a0aaa31a57fb0fd77185eb73b25 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Y6
{ public static void fx(long a,long b)
{
if(a==b)
System.out.println("YES");
else
{
if(a>b)
System.out.println("YES");
else
{
if(a%2==0)
{
if(a==2){
if(b==3)
System.out.println("YES");
else
System.out.println("NO");
}
else
{ if(a!=3)
fx((3*(a))/2,b);
else
System.out.println("NO");
}
}
else
{
if(a==1)
System.out.println("NO");
else
fx(a-1,b);
}
}
}
}
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
String[] s=br.readLine().split(" ");
long a=Long.parseLong(s[0]);
long b=Long.parseLong(s[1]);
fx(a,b);
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 3a41d06fc28fe636e17a9cab7616ce8b | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0)
{
int x=sc.nextInt();
int y=sc.nextInt();
if(x>=y)
System.out.println("YES");
else if((x==1 && y>1) || (x==3 && y>3) ||(x==2 && y>3))
System.out.println("NO");
else
System.out.println("YES");
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 17f08f1f6c9b2aced8b34c7847c5d4a9 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.*;
import java.util.*;
public class A
{
static int x, y;
static int[] arr;
static char[] s;
public static void main(String[] args) throws IOException
{
Flash f = new Flash();
int T = f.ni();
for(int tc = 1; tc <= T; tc++){
x = f.ni(); y = f.ni(); sop(fn());
}
}
static String fn()
{
if(x == y) return "YES";
if(x == 1) return "NO";
if(x <= 3 && y > 3) return "NO";
return "YES";//
}
static void sort(int[] a){
List<Integer> A = new ArrayList<>();
for(int i : a) A.add(i);
Collections.sort(A);
for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
}
static int swap(int itself, int dummy){
return itself;
}
static void sop(Object o){ System.out.println(o); }
static void print(int[] a){
StringBuilder sb = new StringBuilder();
for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
System.out.println(sb);
}
static class Flash
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next(){
while(!st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
String ns(){
String s = new String();
try{
s = br.readLine().trim();
}catch(IOException e){
e.printStackTrace();
}
return s;
}
int ni(){
return Integer.parseInt(next());
}
int[] arr(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
long nl(){
return Long.parseLong(next());
}
double nd(){
return Double.parseDouble(next());
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 2c3225b6b7d9e7101bb31bed46792f8b | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.*;
import java.util.*;
public class A
{
static int x, y;
static int[] arr;
static char[] s;
public static void main(String[] args) throws IOException
{
Flash f = new Flash();
int T = f.ni();
for(int tc = 1; tc <= T; tc++){
x = f.ni(); y = f.ni(); sop(fn());
}
}
static String fn()
{
if(x == y) return "YES";
if(x == 1) return "NO";
if(x <= 3 && y > 3) return "NO";
return "YES";
}
static void sort(int[] a){
List<Integer> A = new ArrayList<>();
for(int i : a) A.add(i);
Collections.sort(A);
for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
}
static int swap(int itself, int dummy){
return itself;
}
static void sop(Object o){ System.out.println(o); }
static void print(int[] a){
StringBuilder sb = new StringBuilder();
for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
System.out.println(sb);
}
static class Flash
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next(){
while(!st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
String ns(){
String s = new String();
try{
s = br.readLine().trim();
}catch(IOException e){
e.printStackTrace();
}
return s;
}
int ni(){
return Integer.parseInt(next());
}
int[] arr(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
long nl(){
return Long.parseLong(next());
}
double nd(){
return Double.parseDouble(next());
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 48791b1214d2348578f6a1f91bc51796 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class test {
/*
* array list
*
* ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
*
* BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
*
* hash map
*
* HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int
* i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) {
* hm.put(ar[i],1); } else { hm.put(ar[i],++c); } }
*
* while loop
*
* int t=sc.nextInt(); while(t>0) { t--; }
*
* array input
*
* int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length;
* i++) { ar[i] = sc.nextInt(); }
*/
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class Pair {
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
private static final Scanner sc = new Scanner(System.in);
private static final FastReader fs = new FastReader();
private static final OutputWriter op = new OutputWriter(System.out);
static int[] getintarray(int n) {
int ar[] = new int[n];
for (int i = 0; i < n; i++) {
ar[i] = fs.nextInt();
}
return ar;
}
static long[] getlongarray(int n) {
long ar[] = new long[n];
for (int i = 0; i < n; i++) {
ar[i] = fs.nextLong();
}
return ar;
}
static int[][] get2darray(int n, int m) {
int ar[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ar[i][j] = fs.nextInt();
}
}
return ar;
}
static Pair[] getpairarray(int n) {
Pair ar[] = new Pair[n];
for (int i = 0; i < n; i++) {
ar[i] = new Pair(fs.nextInt(), fs.nextInt());
}
return ar;
}
static void printarray(int ar[]) {
System.out.println(Arrays.toString(ar));
}
static boolean checkmyArray(int[] ar)
{
int temp = ar[0];
for (int i = 1; i < ar.length; i++) {
if (temp != ar[i])
return false;
}
return true;
}
static int fact(int n) {
int fact = 1;
for (int i = 2; i <= n; i++) {
fact *= i;
}
return fact;
}
static int getans(int[] a, int[] b) {
int a1 = a[0];
int a2 = b[0];
int b1 = a[1];
int b2 = b[1];
int c1 = a[2];
int c2 = b[2];
if (((a1 == a2) && (b1 == b2) && (c1 == c2)))
return 0;
else if ((a2 - a1) == (b2 - b1) && (b2 - b1) == (c2 - c1))
return 1;
else if ((a2 / a1 == b2 / b1) && (b2 / b1 == c2 / c1) && (a2 / a1 == c2 / c1)
&& (a2 % a1 == 0 && b2 % b1 == 0 && c2 % c1 == 0))
return 1;
else if (((a1 == a2) && (b1 == b2)) || ((a1 == a2) && (c1 == c2)) || ((c1 == c2) && (b1 == b2))) {
return 1;
} else if (a1 == a2) {
if ((b2 - b1) == (c2 - c1) || ((b2 / b1 == c2 / c1) && (b2 % b1 == 0 && c2 % c1 == 0)))
return 1;
} else if (b1 == b2) {
if ((a2 - a1) == (c2 - c1) || ((a2 / a1 == c2 / c1) && (a2 % a1 == 0 && c2 % c1 == 0)))
return 1;
} else if (c1 == c2) {
if ((b2 - b1) == (a2 - a1) || ((b2 / b1 == a2 / a1) && (b2 % b1 == 0 && a2 % a1 == 0)))
return 1;
} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1))
&& ((a2 / a1 != b2 / b1) && (b2 / b1 != c2 / c1) && (a2 / a1 != c2 / c1)))) {
return 3;
} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1)))) {
if ((a2 / a1 == b2 / b1 && a2 % a1 != 0 && b2 % b1 != 0)
|| (a2 / a1 == c2 / c1 && a2 % a1 != 0 && c2 % c1 != 0)
|| (c2 / c1 == b2 / b1 && c2 % c1 != 0 && b2 % b1 != 0))
return 3;
}
return 2;
}
// function to find largest prime factor
static long maxPrimeFactors(long n) {
// Initialize the maximum prime
// factor variable with the
// lowest one
long maxPrime = -1;
// Print the number of 2s
// that divide n
while (n % 2 == 0) {
maxPrime = 2;
// equivalent to n /= 2
n >>= 1;
}
// n must be odd at this point,
// thus skip the even numbers
// and iterate only for odd
// integers
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
maxPrime = i;
n = n / i;
}
}
// This condition is to handle
// the case when n is a prime
// number greater than 2
if (n > 2)
maxPrime = n;
return maxPrime;
}
public static void main(String[] args) {
// int t = fs.nextInt();
//// int t = 1;
// while (t > 0) {
// int a[] = getintarray(3);
// int b[] = getintarray(3);
// int ans = getans(a, b);
// System.out.println(ans);
// }
int t = fs.nextInt();
// int t = 1;
while (t > 0) {
int x = fs.nextInt();
int y = fs.nextInt();
if (x == y) {
System.out.println("yes");
} else if (x <= 3) {
if (x == 1)
System.out.println("no");
else if (x == 2) {
if (y == 1 || y == 3)
System.out.println("yes");
else
System.out.println("no");
} else if (x == 3) {
if (y == 1 || y == 2) {
System.out.println("yes");
} else {
System.out.println("no");
}
}
} else
System.out.println("yes");
t--;
}
}
}/*
* 1 5 -2 -3 -1 -4 -6till here
*/
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | a578edab64175c4d2ff167173c7584f1 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes |
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
public static void process()throws IOException
{
int x=ni(),y=ni();
if(y<=x){
pn("YES");return;
}
if(x==2 && y>3){
pn("NO");
return;
}
if(x==3 && y>3){
pn("NO");
return;
}
if(x==1 && y!=1){
pn("NO");
return;
}
pn("YES");
}
static FastReader sc=new FastReader();
//static AnotherReader sc;
public static void main(String[]args)throws IOException
{
//sc=new AnotherReader();
int t=ni();
while(t-->0)
process();
System.out.flush();
System.out.close();
}
static void pn(Object o){System.out.println(o);}
static void p(Object o){System.out.print(o);}
static void pni(Object o){System.out.println(o);System.out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static boolean multipleTC=false;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class FastReader{BufferedReader br;StringTokenizer st;public FastReader()
{br=new BufferedReader(new InputStreamReader(System.in));}String next()
{while(st==null||!st.hasMoreElements())
{try{st=new StringTokenizer(br.readLine());}
catch(IOException e){e.printStackTrace();}}
return st.nextToken();}int nextInt()
{return Integer.parseInt(next());}long nextLong()
{return Long.parseLong(next());}double nextDouble()
{return Double.parseDouble(next());}
String nextLine(){String str="";try
{str=br.readLine();}catch(IOException e)
{e.printStackTrace();}return str;}}
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 5d7bca23da80aa21a3a6db743c05235b | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | //package cp;
import java.io.*;
import java.math.*;
import java.util.*;
public class Solution{
long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
void swap(long a,long b) {long temp=a;a=b;b=temp;}
StringBuilder sb=new StringBuilder();
Integer[] ARR=new Integer[5];
//Integer sort-TLE-Initialize object elements i.e a[0].
long ceil(int n) {return (long)Math.ceil(1.0*n/2);}
void divisor(long n,int start) {
int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
Solution obj=new Solution();
int t=Readers.nextInt();
while(t-->0) {
long x=Readers.nextLong();
long y=Readers.nextLong();
if(x>=4)System.out.println("YES");
else if(x==3 || x==2) {
if(y<=3)System.out.println("YES");
else System.out.println("NO");
}
else{
if(y==1)System.out.println("YES");
else System.out.println("NO");
}
}
out.flush();
}
}
class Readers {
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 long nextLong() throws IOException{
return Long.parseLong(next());
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 358913f9ef15b32116b8d313b3af206e | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.util.*;
public class Solution_1 {
public static void main(String[] args) {
// solution start :-)
//filling shape
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int x = sc.nextInt();
int y = sc.nextInt();
if(x>=y) System.out.println("YES");
else {
if(x>3) System.out.println("YES");
else {
if(x==2 && y==3) System.out.println("YES");
else System.out.println("NO");
}
}
}
// solution end \(^-^)/
// |
// / \
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 4c8eb60aa68af4ecb5432ce8c09ece23 | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BMagicStick solver = new BMagicStick();
solver.solve(1, in, out);
out.close();
}
static class BMagicStick {
public void solve(int testNumber, FastReader s, PrintWriter out) {
int t = s.nextInt();
while (t-- > 0) {
int a = s.nextInt();
int b = s.nextInt();
if (b <= a) {
out.println("YES");
continue;
}
if (a == 1) {
out.println("NO");
continue;
}
if (a == 2) {
if (b == 3) {
out.println("YES");
continue;
} else {
out.println("NO");
continue;
}
}
if (a == 3) {
out.println("NO");
continue;
}
out.println("YES");
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | e7f411464947f0c083067695e9007e4f | train_000.jsonl | 1573655700 | Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$$; If the chosen number $$$a$$$ is greater than one, then the spell will turn it into $$$a-1$$$. Note that if the number is even and greater than one, then Petya can choose which spell to apply.Petya now has only one number $$$x$$$. He wants to know if his favorite number $$$y$$$ can be obtained from $$$x$$$ using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave $$$x$$$ as it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class Main {
public void exec() {
int t = stdin.nextInt();
while (t-- > 0) {
long x = stdin.nextLong();
long y = stdin.nextLong();
if (x == 1) {
stdout.println(y==1 ? "YES" : "NO");
} else if (x == 2 || x == 3) {
stdout.println(y<=3 ? "YES" : "NO");
} else {
stdout.println("YES");
}
}
}
private static final Stdin stdin = new Stdin();
private static final Stdout stdout = new Stdout();
public static void main(String[] args) {
try {
new Main().exec();
} finally {
stdout.flush();
}
}
public static class Stdin {
private BufferedReader stdin;
private Deque<String> tokens;
private Pattern delim;
public Stdin() {
stdin = new BufferedReader(new InputStreamReader(System.in));
tokens = new ArrayDeque<>();
delim = Pattern.compile(" ");
}
public String nextString() {
try {
if (tokens.isEmpty()) {
String line = stdin.readLine();
if (line == null) {
throw new UncheckedIOException(new EOFException());
}
delim.splitAsStream(line).forEach(tokens::addLast);
}
return tokens.pollFirst();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public int nextInt() {
return Integer.parseInt(nextString());
}
public double nextDouble() {
return Double.parseDouble(nextString());
}
public long nextLong() {
return Long.parseLong(nextString());
}
public String[] nextStringArray(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++) a[i] = nextString();
return a;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) a[i] = nextDouble();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
}
public static class Stdout {
private PrintWriter stdout;
public Stdout() {
stdout = new PrintWriter(System.out, false);
}
public void printf(String format, Object ... args) {
String line = String.format(format, args);
if (line.endsWith(System.lineSeparator())) {
stdout.print(line);
} else {
stdout.println(line);
}
}
public void println(Object ... objs) {
String line = Arrays.stream(objs).map(Objects::toString).collect(Collectors.joining(" "));
stdout.println(line);
}
public void printDebug(Object ... objs) {
String line = Arrays.stream(objs).map(this::deepToString).collect(Collectors.joining(" "));
stdout.printf("DEBUG: %s%n", line);
stdout.flush();
}
private String deepToString(Object o) {
if (o == null) {
return "null";
}
// 配列の場合
if (o.getClass().isArray()) {
int len = Array.getLength(o);
String[] tokens = new String[len];
for (int i = 0; i < len; i++) {
tokens[i] = deepToString(Array.get(o, i));
}
return "{" + String.join(",", tokens) + "}";
}
return Objects.toString(o);
}
private void flush() {
stdout.flush();
}
}
} | Java | ["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"] | 1 second | ["YES\nYES\nNO\nYES\nNO\nYES\nYES"] | null | Java 11 | standard input | [
"math"
] | b3978805756262e17df738e049830427 | The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get. | 1,000 | For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | standard output | |
PASSED | 2fc34e2afa98a0480c4fa8c2fc3ae617 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws IOException {
int i, j;
FastReader in = new FastReader(System.in);
StringBuilder sb = new StringBuilder();
boolean testcases = true;
String s="abacaba";
int t = testcases ? in.nextInt() : 1;
int to = 0;
while (to++ < t) {
int n=in.nextInt();
char arr[]=in.next().toCharArray();
int c=0;
for(i=0;i<=n-7;i++){
int f=0;
for(j=i;j<i+7;j++){
if(arr[j]!=s.charAt(j-i)){
f=1;
break;
}
}
if(f==0){
c++;
}
}
if(c>1){
sb.append("NO\n");
continue;
}
if(c==1){
sb.append("YES\n");
for(i=0;i<n;i++){
if(arr[i]=='?')
arr[i]='d';
sb.append(arr[i]);
}
sb.append("\n");
}
else{
char ans[]=new char[n];
int f2=0;
outer:
for(i=0;i<=n-7;i++){
int f=0;
char ar[]=new char[n];
for(j=0;j<n;j++)
ar[j]=arr[j];
for(j=i;j<i+7;j++){
if(ar[j]==s.charAt(j-i) || ar[j]=='?') {
ar[j]=s.charAt(j-i);
continue;
}
f=1;
break;
}
if(f==0){
c=0;
for(j=Math.max(0,i-6);j<Math.min(i+7,n-6);j++){
int f1=0;
for(int k=j;k<j+7;k++){
if(ar[k]=='?' || ar[k]!=s.charAt(k-j)){
f1=1;
break;
}
}
if(f1==0)
c++;
}
if(c==1){
ans=ar;
f2=1;
break outer;
}
}
}
if(f2==0)
sb.append("NO\n");
else{
sb.append("YES\n");
for(i=0;i<n;i++){
if(ans[i]=='?')
ans[i]='d';
sb.append(ans[i]);
}
sb.append("\n");
}
}
}
System.out.print(sb);
}
}
class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 328437fb7e0cf0a1a2e501de43170aae | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes |
import java.util.Scanner;
public class Main {
static final int N = 100;
static final char aba[] = { 'a', 'b', 'a', 'c', 'a', 'b', 'a' };
static int check_num(int n, String str) {
int num = 0;
for (int i = 0; i + 7 <= n; i++) {
if (str.substring(i, i + 7).equals("abacaba"))
num++;
}
return num;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
sc.nextLine();
String str = sc.nextLine();
if (check_num(n, str) > 1) {
System.out.println("No");
continue;
}
String ans = null;
for (int i = 0; i + 7 <= n; i++) {
char tmp[] = str.toCharArray();
boolean flg = true;
for (int j = 0; j < 7; j++) {
if (tmp[i + j] == aba[j])
continue;
if (tmp[i + j] == '?') {
tmp[i + j] = aba[j];
continue;
}
flg = false;
}
if (!flg)
continue;
if (check_num(n, String.valueOf(tmp)) == 1) {
for (int j = 0; j < n; j++) {
if (tmp[j] == '?')
tmp[j] = 'd';
}
ans = String.valueOf(tmp);
}
}
if (ans != null) {
System.out.println("Yes");
System.out.println(ans);
} else {
System.out.println("No");
}
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 3c44efcb7f7dde0995f83c225c5a9aa6 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0){
int n = sc.nextInt();
String s = sc.next();
String toCheck = "abacaba";
int occurances = findOccurances(s);
if(occurances>1){
System.out.println("No");
}else if(occurances==1){
System.out.println("Yes");
System.out.println(formatString(s));
}else{
StringBuilder sb = new StringBuilder();
for(int i=0;i<s.length()-6;i++){
char[] ss = s.substring(i,i+7).toCharArray();
boolean isValid = true;
for(int j=0;j<7 && isValid;j++){
if(ss[j]=='?'){
ss[j]=toCheck.charAt(j);
}else if(ss[j]!=toCheck.charAt(j)){
isValid = false;
}
}
if(isValid){
sb.append(s, 0, i);
sb.append(toCheck);
sb.append(s.substring(i+7,s.length()));
if(findOccurances(sb.toString())==1){
break;
}else {
sb = new StringBuilder();
}
}
}
if(sb.length()==0){
System.out.println("No");
}else if(findOccurances(sb.toString())==1){
System.out.println("Yes");
System.out.println(formatString(sb.toString()));
}else{
System.out.println("No");
}
}
}
}
private static String formatString(String s) {
StringBuilder sb = new StringBuilder();
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='?'){
sb.append('d');
}else{
sb.append(s.charAt(i));
}
}
return sb.toString();
}
private static int findOccurances(String s){
int ans = 0;
for(int i=0;i<s.length()-6;i++){
if(s.substring(i,i+7).equals("abacaba")){
ans++;
}
}
return ans;
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 1ed899137f3e6ef9cf35194e361dfda2 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | //https://codeforces.com/contest/1379/problem/A
//package com.bhavesh.Round657;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class A {
private static int count(StringBuilder sb, String pattern, int n) {
int count = 0;
for (int k = 0; k <= n - pattern.length(); k++) {
if ((sb.substring(k, k + pattern.length())).equals(pattern))
count++;
}
return count;
}
private static void replaceEquals(StringBuilder sb, int n) {
for (int k = 0; k < n; k++) {
if (sb.charAt(k) == '?')
sb.setCharAt(k, 'z');
}
}
public static void solve(String s) {
final int n = s.length();
final String pattern = "abacaba";
final int m = 7;
StringBuilder SS = new StringBuilder(s);
int j;
int countS = count(SS, pattern, n);
if (countS == 1) {
replaceEquals(SS, n);
System.out.println("Yes");
System.out.println(SS.toString());
return;
}
else if (countS > 1) {
System.out.println("No");
return;
}
boolean found;
boolean done = false;
for (int i = 0; i <= n - m; i++) {
found = true;
StringBuilder sb = new StringBuilder(SS);
for (j = 0; j < m; j++) {
if (sb.charAt(i+j) != pattern.charAt(j) && sb.charAt(i+j) != '?') {
found = false;
break;
}
sb.setCharAt(i + j, pattern.charAt(j));
}
if (found && count(sb, pattern, n) == 1) {
replaceEquals(sb, n);
done = true;
System.out.println("Yes");
System.out.println(sb.toString());
break;
}
}
if (!done)
System.out.println("No");
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
solve(s);
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | b79acd5f839836521be2cad2b69bb4e8 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.io.*;
import java.util.*;
public class A {
static String t = "abacaba";
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int x = sc.nextInt();
while(x-->0) {
int n = sc.nextInt();
String str = sc.next();
solve(str,n);
}
}
static void solve(String str, int n) {
if(check(str)) {
System.out.println("YES");
process(str);
return;
}
for(int i = 0; i <= n-7;i++) {
StringBuilder sb = new StringBuilder(str);
boolean flag = true;
for(int j = 0; j < 7; j++) {
if(sb.charAt(i+j) != '?' && sb.charAt(i+j) != t.charAt(j)) {
flag = false;
break;
}
sb.setCharAt(i+j, t.charAt(j));
}
if(flag == true && check(sb.toString())) {
System.out.println("YES");
process(sb.toString());
return;
}
}
System.out.println("NO");
}
static boolean check(String str) {
int count = 0;
for(int i = 0; i <= str.length()-7; i++) {
String substring= str.substring(i, i+7);
if(substring.equals(t)) {
count++;
}
}
return count == 1;
}
static void process(String str) {
for(char c : str.toCharArray()) {
if(c == '?') {
System.out.print('z');
}
else {
System.out.print(c);
}
}
System.out.println();
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | d3ea1bc08ba091e7904b2c875f7725fb | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | /**
* @author vivek
* programming is thinking, not typing
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
//todo
public class Main {
private static void solveTC(int __) {
/* For Google */
// ans.append("Case #").append(__).append(": ");
//code start todo
int n = Integer.parseInt(scn.nextLine());
String target="abacaba";
String str=scn.nextLine();
int count=0;
for (int i = 0; i <= n-7; i++) {
if (str.substring(i).startsWith(target)){
count++;
}
}
if (count>1){
print("No\n");
return;
}
if (count==1){
print("Yes\n");
print(toOk(str,n)+"\n");
return;
}
ArrayList<String> list=new ArrayList<>();
outer:
for (int i = 0; i <=n-7 ; i++) {
String temp=str.substring(i,i+7);
for (int j = 0; j < 7; j++) {
if (temp.charAt(j)==target.charAt(j)||temp.charAt(j)=='?'){
}else {
continue outer;
}
}
list.add(toOk(str.substring(0,i),i)+target+toOk(str.substring(i+7),n-i-7));
}
for(String ele:list){
int count2=0;
for (int i = 0; i <= n-7; i++) {
if (ele.substring(i).startsWith(target)){
count2++;
}
}
if (count2==1){
print("Yes\n");
print(ele+"\n");
return;
}
}
print("No\n");
//code end
}
private static String toOk(String str,int n) {
StringBuilder ans= new StringBuilder();
for (int i = 0; i < n; i++) {
if (str.charAt(i)=='?'){
ans.append('d');
}else {
ans.append(str.charAt(i));
}
}
return ans.toString();
}
/**
* Don't copy other's templates, make your own <br>
* It would be much more beneficial
*/
public static void main(String[] args) {
// int limit= ;
// sieve(limit);
//todo
/*
try {
System.setOut(new PrintStream(new File("file_i_o\\output.txt")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
*/
scn = new Scanner();
ans = new StringBuilder();
int t = Integer.parseInt(scn.nextLine());
// int t = 1;
for (int i = 1; i <= t; i++) {
solveTC(i);
}
System.out.print(ans);
}
//Stuff for prime start
/**
* List containing prime numbers <br>
* <b>i<sup>th</sup></b> position contains <b>i<sup>th</sup></b> prime number <br>
* 0th index is <b>null</b>
*/
private static ArrayList<Integer> listOfPrimes;
/**
* query <b>i<sup>th</sup></b> element to get if its prime of not
*/
private static boolean[] isPrime;
/**
* Performs Sieve of Erathosnesis and initialise isPrime array and listOfPrimes list
*
* @param limit the number till which sieve is to be performed
*/
private static void sieve(int limit) {
listOfPrimes = new ArrayList<>();
listOfPrimes.add(null);
boolean[] array = new boolean[limit + 1];
Arrays.fill(array, true);
array[0] = false;
array[1] = false;
for (int i = 2; i <= limit; i++) {
if (array[i]) {
for (int j = i * i; j <= limit; j += i) {
array[j] = false;
}
}
}
isPrime = array;
for (int i = 0; i <= limit; i++) {
if (array[i]) {
listOfPrimes.add(i);
}
}
}
//stuff for prime end
/**
* Calculates the Least Common Multiple of two numbers
*
* @param a First number
* @param b Second Number
* @return Least Common Multiple of <b>a</b> and <b>b</b>
*/
private static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
/**
* Calculates the Greatest Common Divisor of two numbers
*
* @param a First number
* @param b Second Number
* @return Greatest Common Divisor of <b>a</b> and <b>b</b>
*/
private static long gcd(long a, long b) {
return (b == 0) ? a : gcd(b, a % b);
}
static void print(Object obj) {
ans.append(obj.toString());
}
static Scanner scn;
static StringBuilder ans;
//Fast Scanner
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() {
br = new BufferedReader(new
InputStreamReader(System.in));
//todo
/*
try {
br = new BufferedReader(new
InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt"))));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
*/
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
Integer[] nextIntegerArray(int n) {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++) {
array[i] = nextLong();
}
return array;
}
String[] nextStringArray() {
return nextLine().split(" ");
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++) {
array[i] = next();
}
return array;
}
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 3704752ff5b482b7beb3c2de384e2b29 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf1379a {
public static void main(String[] args) throws IOException {
int t = ri();
tt: while(t --> 0) {
int n = ri(), cnt = 0;
char[] s = rcha(), pat = "abacaba".toCharArray();
boolean possible = false;
List<Integer> inds = new ArrayList<>();
for(int i = 0; i <= n - 7; ++i) {
boolean ok = true, poss = true;
for(int j = 0; j < 7; ++j) {
if(s[i + j] != pat[j]) {
ok = false;
if(s[i + j] != '?') {
poss = false;
}
}
}
if(ok) {
++cnt;
} else if(poss) {
possible = true;
inds.add(i);
}
}
if(cnt == 1) {
pry();
for(char c : s) {
if(c == '?') {
pr('z');
} else {
pr(c);
}
}
prln();
} else if(cnt == 0 && possible) {
for(int ind : inds) {
char[] sc = new char[n];
for(int i = 0; i < n; ++i) {
sc[i] = s[i];
}
for(int i = 0; i < 7; ++i) {
sc[ind + i] = pat[i];
}
cnt = 0;
next: for(int i = 0; i <= n - 7; ++i) {
for(int j = 0; j < 7; ++j) {
if(sc[i + j] != pat[j]) {
continue next;
}
}
++cnt;
}
if(cnt == 1) {
pry();
for(char c : sc) {
if(c == '?') {
pr('z');
} else {
pr(c);
}
}
prln();
continue tt;
}
}
prn();
} else {
prn();
}
}
close();
}
static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
static StringTokenizer input;
static Random rand = new Random();
// references
// IBIG = 1e9 + 7
// IMAX ~= 2e10
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final int IMIN = -2147483648;
static final long LMAX = 9223372036854775807L;
static final long LMIN = -9223372036854775808L;
// math util
static int minof(int a, int b, int c) {return min(a, min(b, c));}
static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
static long minof(long a, long b, long c) {return min(a, min(b, c));}
static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
static int maxof(int a, int b, int c) {return max(a, max(b, c));}
static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
static long maxof(long a, long b, long c) {return max(a, max(b, c));}
static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static int floori(double d) {return (int)d;}
static int ceili(double d) {return (int)ceil(d);}
static long floorl(double d) {return (long)d;}
static long ceill(double d) {return (long)ceil(d);}
static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}
// array util
static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void reverse(double[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static <T> void reverse(T[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {T swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(char[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); char swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void rsort(int[] a) {shuffle(a); sort(a);}
static void rsort(long[] a) {shuffle(a); sort(a);}
static void rsort(double[] a) {shuffle(a); sort(a);}
static void rsort(char[] a) {shuffle(a); sort(a);}
static <T> void rsort(T[] a) {shuffle(a); sort(a);}
// graph util
static List<List<Integer>> graph(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}
static void connect(List<List<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}
static void connectDirected(List<List<Integer>> g, int u, int v) {g.get(u).add(v);};
// input
static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
static long rl() throws IOException {return Long.parseLong(__in.readLine());}
static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}
static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
static String rline() throws IOException {return __in.readLine();}
static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
static int ni() {return Integer.parseInt(input.nextToken());}
static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
static long nl() {return Long.parseLong(input.nextToken());}
// output
static void pr(int i) {__out.print(i);}
static void prln(int i) {__out.println(i);}
static void pr(long l) {__out.print(l);}
static void prln(long l) {__out.println(l);}
static void pr(double d) {__out.print(d);}
static void prln(double d) {__out.println(d);}
static void pr(char c) {__out.print(c);}
static void prln(char c) {__out.println(c);}
static void pr(char[] s) {__out.print(new String(s));}
static void prln(char[] s) {__out.println(new String(s));}
static void pr(String s) {__out.print(s);}
static void prln(String s) {__out.println(s);}
static void pr(Object o) {__out.print(o);}
static void prln(Object o) {__out.println(o);}
static void prln() {__out.println();}
static void pryes() {__out.println("yes");}
static void pry() {__out.println("Yes");}
static void prY() {__out.println("YES");}
static void prno() {__out.println("no");}
static void prn() {__out.println("No");}
static void prN() {__out.println("NO");}
static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
static void h() {__out.println("hlfd");}
static void flush() {__out.flush();}
static void close() {__out.close();}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | eb193c87d99acbc450154791e87955b0 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static boolean countOccurences(String s, String T) {
int cnt=0;
for(int i=0;i<=s.length()-7;i++) {
if(s.substring(i, i+7).equals(T)){
cnt++;
}
}
if(cnt==1) {
return true;
}
else {
return false;
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
String str=sc.next();
String T="abacaba";
boolean flag=true;
if(countOccurences(str,T)) {
System.out.println("Yes");
char c[]=str.toCharArray();
for(int i=0;i<n;i++) {
if(c[i]=='?')
c[i]='d';
}
for(char ch :c)
System.out.print(ch);
System.out.println();
flag=false;
}
else {
for(int i=0;i<=n-T.length();i++) {
char ch[]=str.toCharArray();
boolean flag1=true;
for(int j=0;j<7;j++) {
if(ch[i+j]!='?' && ch[i+j]!=T.charAt(j)) {
flag1=false ;
break;
}
ch[i+j]=T.charAt(j);
}
String str1=String.valueOf(ch);
if(flag1 && countOccurences(str1,T)) {
System.out.println("Yes");
char c[]=str1.toCharArray();
for(int k=0;k<n;k++) {
if(c[k]=='?')
c[k]='d';
}
for(char cho :c)
System.out.print(cho);
System.out.println();
flag=false;
break;
}
}
}
if(flag == true) {
System.out.println("No");
}
else {
flag=true;
}
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | dee7680ca3244ca568eecaad8a0ee500 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.Scanner;
public class Main{
public static final String pattern = "abacaba";
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
sc.nextLine();
for (int i = 0; i < k; i++){
sc.nextInt();
sc.nextLine();
String str = sc.nextLine();
Integer res = checkString(str);
if (res == null)
System.out.println("No");
else {
System.out.println("Yes");
String ans = "";
if (res == -1)
ans = str.replaceAll("\\?", "f");
else
ans = str.substring(0, res).replaceAll("\\?", "f") +
"abacaba" +
str.substring(res + 7).replaceAll("\\?", "f");
System.out.println(ans);
}
}
return;
}
public static Integer checkString(String str){
int cnt = 0;
Integer ind = null;
for (int i = 0; i <= str.length() - 7; i++){
String substr = str.substring(i, i + pattern.length());
if (substr.equals(pattern)) {
cnt++;
if (cnt >= 2)
return null;
continue;
}
boolean match = checkAbacaba(substr);
boolean checked = checkLeftRight(str, i);
if (match && checked)
ind = i;
}
if (cnt == 1)
return -1;
return ind;
}
public static boolean checkLeftRight(String str, int ind){
boolean okLeft = ((ind < 4) ||
!(str.substring(ind - 4, ind).equals("abac"))) &&
((ind < 6) ||
!(str.substring(ind - 6, ind).equals("abacab")));
boolean okRight = ((str.length() < ind + 11) ||
!(str.substring(ind + 7, ind + 11).equals("caba"))) &&
((str.length() < ind + 13) ||
!(str.substring(ind + 7, ind + 13).equals("bacaba")));
return okLeft && okRight;
}
public static boolean checkAbacaba(String substr){
for (int i = 0; i < substr.length(); i++){
if ((substr.charAt(i) != pattern.charAt(i)) && (substr.charAt(i) != '?')){
return false;
}
}
return true;
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | ad1c69fa6fb422cc1c2ac79ed7a6270c | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class A1379{
static int gcd(int a, int b)
{
if (a == 0)
return b;
if (b == 0)
return a;
int k;
for (k = 0; ((a | b) & 1) == 0; ++k)
{
a >>= 1;
b >>= 1;
}
while ((a & 1) == 0)
a >>= 1;
do {
while ((b & 1) == 0)
b >>= 1;
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
b = (b - a);
} while (b != 0);
return a << k;
}
static int lcm(int a,int b){
return a*b/gcd(a,b);
}
public static int binary(int arr[],int n, int a,int beg,int end){
while(beg<=end){
int mid=beg+(end-beg)/2;
if(arr[mid]==a)
return mid;
if(arr[mid]<a)
end=mid-1;
else
beg=mid+1;
}
return -1;
}
public static int binaryless(int arr[],int n, int a,int beg,int end){
while(beg<=end){
int mid=beg+(end-beg)/2;
if(arr[mid]>=a){
if(mid==1||arr[mid-1]<a)
return mid;
end=mid-1;
}
else{
beg=mid+1;
}
}
return -1;
}
public static void sieve(int t){
boolean srr[]=new boolean[t+1];
for(int i=2;i*i<=t;i++)
{
if(!srr[i])
{
for(int k=i*i;k<=t;k+=i)
srr[k]=true;
}
}
for(int i=2;i<t+1;i++){
if(!srr[i])
System.out.println(i);
}
}
static int power(int x, int y, int p)
{
int res = 1;
x = x % p;
while (y > 0)
{
if((y & 1)==1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static class Custom implements Comparable<Custom>{
int d;
int f;
public Custom(int d,int f){
this.d=d;
this.f=f;
}
public int compareTo(Custom t){
return this.d-t.d;
}
}
void solve() throws IOException {
int tt=nextInt();
while(tt--!=0){
int n=nextInt();
char[] s=next().toCharArray();
int p=0;
char[] copy=new char[n];
for(char c:s)
copy[p++]=c;
char[] t="abacaba".toCharArray();
boolean ans=false;
int no=0;
for(int i=0;i<=n-7;i++){
int j=0;
for( j=0;j<7;j++){
if(s[i+j]==t[j]);
else break;
}
if(j==7){
ans=true;
no++;
if(no>1)
break;
}
}
if(no>1){
pw.println("No");
continue;
}
if(ans){
pw.println("Yes");
for(char c:s)
pw.print(c=='?'?'t':c);
pw.println();
continue;
}
ans=false;
for(int i=0;i<=n-7;i++){
int j=0;
for( j=0;j<7;j++){
if(s[i+j]==t[j]||s[i+j]=='?');
else break;
}
if(j==7){
for(int k=0;k<7;k++){
s[i+k]=t[k];
}
if(ch(s,t)){
ans=true;
break;}
for(int k=0;k<7;k++)
s[i+k]=copy[i+k];
}
}
if(ans){
pw.println("Yes");
for(char c:s)
pw.print(c=='?'?'t':c);
pw.println();
continue;
}
pw.println("No");
}
}
boolean ch(char []s,char[] t){
int no=0;
for(int i=0;i<=s.length-7;i++){
int j=0;
for( j=0;j<7;j++){
if(s[i+j]==t[j]);
else break;
}
if(j==7){
no++;
}
}
if(no>1)
return false;
return true;
}
void disp(Object a){
System.out.println(a);
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
String nextLine()throws IOException{
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
StringTokenizer st;
BufferedReader br;
PrintWriter pw;
Scanner sc;
void run() throws IOException {
sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
long time = System.currentTimeMillis();
solve();
System.err.println("time = " + (System.currentTimeMillis() - time));
pw.close();
}
public static void main(String[] args) throws IOException {
new A1379().run();
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 9256af70293a531b6394199b7499f9d2 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import javax.swing.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static long[] tree;
static int m = 100000000;
static int k1,k2;
static boolean[] vis;
static tuple[] tuples;
public static void main(String[] args) throws IOException {
//BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
//PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//Scanner sc=new Scanner(System.in);
//Reader sc = new Reader();
int t=Integer.parseInt(reader.readLine());
for (int k = 0; k <t ; k++) {
int n=Integer.parseInt(reader.readLine());
StringBuilder s=new StringBuilder(reader.readLine());
StringBuilder r=new StringBuilder(s);
String o="abacaba";
boolean flag=false;
int count=0;
for (int i = 0; i <n-6 ; i++) {
String s1=s.substring(i,i+7);
if (s1.equals(o))count++;
}
if (count==0){
for (int i = 0; i <n-6 ; i++) {
String s1=s.substring(i,i+7);
int q=0,g=0;
for (int j = 0; j <7 ; j++) {
if (s1.charAt(j)!=o.charAt(j))g++;
if (s1.charAt(j)=='?')q++;
}
//System.out.println(q+" "+g);
if (q==g){
r.replace(i,i+7,o);
int c=0;
for (int l = 0; l <n-6 ; l++) {
String x=r.substring(l,l+7);
if (x.equals(o))c++;
}
if (c==1){
s.replace(i,i+7,o);
flag=true;
break;
}
r=new StringBuilder(s);
}
}
}
count=0;
for (int i = 0; i <n-6 ; i++) {
String s1=s.substring(i,i+7);
if (s1.equals(o))count++;
}
if (count==1){
for (int i = 0; i <s.length() ; i++) {
if (s.charAt(i)=='?')
s.replace(i,i+1,"z");
}
out.println("Yes");
out.println(s);
}
else
out.println("No");
}
out.close();
}
static boolean bfs(int a,int b){
Queue<Integer> queue=new LinkedList<>();
queue.add(a);
while (!queue.isEmpty()){
int now=queue.poll();
vis[now]=true;
for (int i = 0; i <k1 ; i++) {
if (!vis[i]){
if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
queue.add(i);
if (i==b){
Arrays.fill(vis,false);
return true;
}
}
}
}
}
Arrays.fill(vis,false);
return false;
}
static int find(int[] p,int x){
if (p[x]==x)return x;
return p[x]=find(p,p[x]);
}
static void union(int[] p,int a,int b){
p[find(p,b)]=find(p,a);
}
static void built(long[] a,int at,int l,int r,int n){
if (l==r){
tree[at]=a[l];
}
else {
int mid=(l+r)/2;
int right=2*at;
int left=(2*at)+1;
built(a,left,l,mid,n-1);
built(a,right,mid+1,r,n-1);
if (n%2==0)
tree[at]=tree[left]^tree[right];
else
tree[at]=tree[left]|tree[right];
}
}
static void update(int at,int l,int r,int i,long v,int n){
if (i<l || i>r)return;
if (l==r){
tree[at]=v;
}
else {
int mid=(l+r)/2;
int right=2*at;
int left=(2*at)+1;
update(left,l,mid,i,v,n-1);
update(right,mid+1,r,i,v,n-1);
if (n%2==0)
tree[at]=tree[left]^tree[right];
else
tree[at]=tree[left]|tree[right];
}
}
}
class node implements Comparable<node> {
Integer no;
Integer cost;
Vector<node> adj = new Vector<>();
public node(Integer no, Integer cost) {
this.no = no;
this.cost = cost;
}
@Override
public String toString() {
return "node{" +
"no=" + no +
", cost=" + cost +
'}';
}
@Override
public int compareTo(node o) {
return o.cost - this.cost;
}
}
class edge implements Comparable<edge> {
tuple u;
Double cost;
public edge(tuple u, Double cost) {
this.u = u;
this.cost = cost;
}
@Override
public int compareTo(edge o) {
return this.cost.compareTo(o.cost);
}
@Override
public String toString() {
return "edge{" +
"u=" + u +
", cost=" + cost +
'}';
}
}
///*
class tuple implements Comparable<tuple> {
Integer a;
Integer b;
public tuple(Integer a, Integer b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(tuple o) {
return (int) (this.b - o.b);
}
@Override
public String toString() {
return "tuple{" +
"a=" + a +
", b=" + b +
'}';
}
}
//*/
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];
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 | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 4890b55227d2084ee5baa23db8ff6299 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
// Reader re=new Reader();
Writer w=new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt(),c=0;
String s=sc.next();
for(int i=0;i<=n-7;i++){
if(s.substring(i,i+7).equals("abacaba"))c++;
}
if(c==0){
int f=0,index=0;
for(int i=0;i<=n-7;i++){
f=0;
c=0;
if((s.charAt(i)=='a' || s.charAt(i)=='?') &&
(s.charAt(i+1)=='b' || s.charAt(i+1)=='?') &&
(s.charAt(i+2)=='a' || s.charAt(i+2)=='?') &&
(s.charAt(i+3)=='c' || s.charAt(i+3)=='?') &&
(s.charAt(i+4)=='a' || s.charAt(i+4)=='?') &&
(s.charAt(i+5)=='b' || s.charAt(i+5)=='?') &&
(s.charAt(i+6)=='a' || s.charAt(i+6)=='?')
){
c=1;
if(i>3){
if((s.charAt(i-1)=='c') &&
(s.charAt(i-2)=='a') &&
(s.charAt(i-3)=='b') &&
(s.charAt(i-4)=='a')) f=1;
}
if(i>5){
if((s.charAt(i-1)=='b') &&
(s.charAt(i-2)=='a') &&
(s.charAt(i-3)=='c') &&
(s.charAt(i-4)=='a') &&
(s.charAt(i-5)=='b') &&
(s.charAt(i-6)=='a')) f=1;
}
if(i+10<n){
if((s.charAt(i+7)=='c') &&
(s.charAt(i+8)=='a') &&
(s.charAt(i+9)=='b') &&
(s.charAt(i+10)=='a')) f=1;
}
if(i+12<n){
if((s.charAt(i+7)=='b') &&
(s.charAt(i+8)=='a') &&
(s.charAt(i+9)=='c') &&
(s.charAt(i+10)=='a') &&
(s.charAt(i+11)=='b') &&
(s.charAt(i+12)=='a')) f=1;
}
}
if(f==0 && c==1){
index=i;
break;
}
}
if(c==0)System.out.println("No");
else{
if(f==1)System.out.println("No");
else{
System.out.println("Yes");
for(int i=0;i<n;i++){
if(i==index){
System.out.print("abacaba");
i+=6;
}
else{
if(s.charAt(i)=='?')System.out.print("z");
else System.out.print(s.charAt(i));
}
}
System.out.println();
}
}
}
else if(c==1){
System.out.println("Yes");
for(int i=0;i<n;i++){
if(s.charAt(i)=='?')System.out.print("z");
else System.out.print(s.charAt(i));
}
System.out.println();
}
else {
System.out.println("No");
}
}
w.flush();
w.close();
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 2fb40a8f402e81fa3fc9bb0359237c21 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.Scanner;
public class codeforces1 {
final static String T = "abacaba";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
boolean bool = false;
for (int i = 0; i <= s.length() - T.length(); i++) {
StringBuilder ss = new StringBuilder(s);
boolean b = true;
for (int j = 0; j < T.length(); j++) {
if (ss.charAt(i+j) != '?' && ss.charAt(i+j) != T.charAt(j)) {
b = false;
break;
}
ss.setCharAt(i+j, T.charAt(j));
}
if (b && count(ss.toString()) == 1) {
for (int j = 0; j < n; j++) {
if (ss.charAt(j) == '?')
ss.setCharAt(j, 'd');
}
bool = true;
System.out.println("YES");
System.out.println(ss);
break;
}
}
if (!bool)
System.out.println("NO");
}
}
private static int count(String string) {
int count = 0;
for (int i = 0; i <= string.length() - T.length(); i++) {
if (string.substring(i, i+T.length()).equals(T))
count++;
}
return count;
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | ae8d0fae581a226c160a3c2f98b6b024 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.io.*;
import java.util.InputMismatchException;
import java.util.*;
public class Acacius{
public static void main(String[] args) throws IOException{
FastReader sc = new FastReader();
char[] temp = "abacaba".toCharArray();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out),"ASCII"),512);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
char[] ch = sc.nextLine().toCharArray();
int count = 0;
for(int i=0;i<n-6;i++){
int x = 1;
for(int j=0;j<7;j++){
if(ch[i+j] != temp[j]){
x = 0;
break;
}
}
if(x!=0) count++;
}
if(count > 1) out.write("NO");
else if(count == 1){
out.write("YES");
out.write('\n');
for(int i=0;i<n;i++){
if(ch[i] == '?') ch[i] = 'd';
out.write(ch[i] + "");
}
}else{
int op = 0;
for(int i=0;i<n-6;i++){
char[] r = Arrays.copyOf(ch,n);
for(int j=0;j<7;j++){
if(ch[i+j] == '?') r[i+j] = temp[j];
}
if(r[i] == 'a' || r[i] == '?'){
if(Acacius.count(r,temp) == 1){
op = 1;
out.write("YES");
out.write('\n');
for(int j=0;j<n;j++){
if(r[j] == '?') r[j] = 'd';
out.write(r[j] + "");
}
break;
}
}
}
if(op == 0) out.write("NO");
}
out.write('\n');
}
out.flush();
}
public static int count(char[] ch,char[] temp){
int n = ch.length;
int count = 0;
outer:for(int i=0;i+6<n;++i){
int j = 0;
for(j=0;j<7;j++){
if(ch[i+j]!=temp[j]) continue outer;
}
count++;
}
return count;
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 4fe3524f5fc52cd8dd3ca488054f6599 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Demo61 {
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int t = fs.nextInt();
outside:
for (int i = 0; i < t; ++i) {
int n = fs.nextInt();
String s = fs.nextToken();
int f = s.indexOf("abacaba");
if (n < 7 || (f != -1 && s.indexOf("abacaba", f + 1) != -1)) {
System.out.println("No");
continue;
}
else if (f != -1) {
System.out.println("Yes");
System.out.println(s.replace('?', 'z'));
}
else {
for (int j = 0; j <= n - 7; ++j) {
if (!canBeTransformed(s, j)) {
continue;
}
else {
String firstPart = s.substring(0, j);
firstPart = firstPart.replace('?', 'z');
String endPart = s.substring(j + 7);
endPart = endPart.replace('?', 'z');
String result = firstPart + "abacaba" + endPart;
int ff = result.indexOf("abacaba");
if (ff != -1 && result.indexOf("abacaba", ff + 1) != -1) {
continue;
}
System.out.println("Yes");
System.out.println(firstPart + "abacaba" + endPart);
continue outside;
}
}
System.out.println("No");
}
}
}
private static boolean canBeTransformed(String s, int j) {
String other = "abacaba";
for (int k = j; k < j + 7; ++k) {
if (s.charAt(k) != '?' && s.charAt(k) != other.charAt(k - j)) {
return false;
}
}
return true;
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 7a0f2b9e75486e2e137e2c8b4a7ae28b | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | // import java.util.HashMap;
import java.util.Scanner;
public class Solution{
public static boolean check(int si , int ei , char ch[]){
String str = "abacaba";
for(int i = si ; i <= ei ; i++){
if(ch[i] != str.charAt(i - si)){
return false;
}
}
return true;
}
public static boolean checkqu(int si , int ei , char ch[]){
String str = "abacaba";
for(int i = si ; i <= ei ; i++){
if(ch[i] != '?' && ch[i] != str.charAt(i - si)){
return false;
}
}
return true;
}
public static boolean checksec(int si , int ei , char ch[]){
String str = "caba";
int j = 0;
for(int i = si ; i <= ei ; i++){
if(ch[i] != str.charAt(j)){
return false;
}
j++;
}
return true;
}
public static boolean precheck(int si , int ei , char ch[]){
String str = "abac";
int j = 0;
for(int i = si ; i <= ei ; i++){
if(ch[i] != str.charAt(j)){
return false;
} j++;
}
return true;
}
public static void place(int si , int ei , char ch[]){
String str = "abacaba";
for(int i = si ; i <= ei ; i++){
if(ch[i] == '?'){
ch[i] = str.charAt(i - si);
}
}
}
public static void main(String args[]){
Scanner scn = new Scanner(System.in);
int test = scn.nextInt();
StringBuilder sb = new StringBuilder();
while(test-- > 0){
int n = scn.nextInt();
scn.nextLine();
String str = scn.nextLine();
char ch[] = str.toCharArray();
int count = 0;
for(int i = 0 ; i < ch.length - 6 ; i++){
if(check(i, i + 6, ch)){
count++;
}
}
if(count >= 2){
sb.append("No");
sb.append("\n");
continue;
}
if(count == 1){
sb.append("Yes");
sb.append("\n");
for(char c : ch){
if(c == '?'){
sb.append('z');
}else{
sb.append(c);
}
}
sb.append("\n");
continue;
}
boolean flag = false;
if(count == 0){
for(int i = 0 ; i < ch.length - 6 ; i++){
if(checkqu(i, i + 6 , ch)){
if(i + 10 < ch.length && checksec(i + 7, i + 10, ch) || (i - 4 >= 0 && precheck(i - 4, i - 1, ch))){
// System.out.println("HELLO");
continue;
}else{
place(i, i + 6, ch);
sb.append("yes");
sb.append("\n");
for(char c : ch){
if(c == '?'){
sb.append('z');
}else{
sb.append(c);
}
}
sb.append("\n");
flag = true;
break;
}
}
}
if(!flag){
sb.append("No");
sb.append("\n");
}
}
}
// System.out.println();
System.out.println(sb.toString());
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | f902602de0a59fb261b9c53c5ab61b4b | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.Scanner;
public class Main
{
public static String a = "abacaba";
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-->0)
{
int n = scan.nextInt(),j=-1;
String s = scan.next(),x="";
boolean b = true;
if(n<7)b=false;
else if(s.contains(a))
{
if(s.indexOf(a)!=s.lastIndexOf(a))b = false;
}
else
{
if(s.contains("?"))
{
int c=0;
boolean d = false;
for(int i=0;i<=n-7;i++)
{
String s1 = s.substring(i,i+7);
if(!d)
{
if( (s1.charAt(0)!='a' && s1.charAt(0) !='?')||
(s1.charAt(1)!='b' && s1.charAt(1) !='?')||
(s1.charAt(2)!='a' && s1.charAt(2) !='?')||
(s1.charAt(3)!='c' && s1.charAt(3) !='?')||
(s1.charAt(4)!='a' && s1.charAt(4) !='?')||
(s1.charAt(5)!='b' && s1.charAt(5) !='?')||
(s1.charAt(6)!='a' && s1.charAt(6) !='?'))
{
//System.out.println(78);
b=false;
}
else
{
boolean aux=true;
//System.out.println(69);
if(i>3)
{
//System.out.println(7887);
if(s.substring(i-4,i).equals("abac"))
{
b=false;
aux=false;
}
}
if(i+7<=n-3)
{
// System.out.println(s.substring(i+7,i+11));
if(s.substring(i+7,i+11).equals("caba"))
{
b=false;
aux=false;
}
}
if(aux)
{
// System.out.println(420);
d=true;
b=true;
j=i;
}
}
}
//System.out.println(b+" "+d+" "+s1+" "+j);
}
}
else b = false;
}
if(b)
{
for(int i=0;i<n;i++)
{
if(i==j && j!=-1)
{
x+="abacaba";
i+=6;
}
else
{
if(s.charAt(i)=='?')x+="x";
else x+=s.charAt(i);
}//System.out.println(i);
}
}
System.out.println(b?"Yes\n"+x:"No");
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | fbd781c7c410e0945f4938f828dc9c8c | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
import java.io.*;
public class A {
static Scanner sc = new Scanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static int find(String s){
int start = 0;
int count = 0;
while (start != -1){
start = s.indexOf("abacaba", start);
if (start != -1){
start += 1;
count += 1;
}
}
return count;
}
static void solve() {
int n = sc.nextInt();
String s = sc.next();
char[] arr = s.toCharArray();
int start = 0;
int count = 0;
while (start != -1){
start = s.indexOf("abacaba", start);
if (start != -1){
start += 1;
count += 1;
}
}
if (count == 1){
pw.println("Yes");
pw.println(s.replace('?', 'z'));
return;
}
if (count > 1){
pw.println("No");
return;
}
char[] comp = {'a', 'b', 'a', 'c', 'a', 'b', 'a'};
for (int i = 0; i <= n - 7; i ++){
char[] duplicate = new char[n];
for (int j = 0; j < n; j ++){
duplicate[j] = arr[j];
}
boolean exists = true;
for (int j = i; j < i + 7; j ++) {
duplicate[j] = comp[j - i];
if (arr[j] != comp[j - i] && arr[j] != '?') {
exists = false;
}
}
if (exists){
if (find(String.valueOf(duplicate)) == 1){
pw.println("Yes");
pw.println(String.valueOf(duplicate).replace('?', 'z'));
return;
}
}
}
pw.println("No");
}
public static void main(String[] args){
int t = sc.nextInt();
for (int i = 0; i < t; i ++){
solve();
}
pw.close();
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | d8d08d8b4f83def3ee8ce71a10beaf2d | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int t=fs.nextInt();
while(t-->0)
{
int n=fs.nextInt();
String str=fs.next();
String req="abacaba";
String sub="";
StringBuffer sb=new StringBuffer(str);
int flag=0;
int gc=0;
for(int i=0;i<=str.length()-7;i++)
{
sub=sb.substring(i,i+7);
if(sub.equals(req))
{
gc++;
}
}
if(gc>1)
out.println("NO");
else if(gc==1)
{
str=str.replace('?','z');
out.println("YES");
out.println(str);
}
else
{
for(int i=0;i<=sb.length()-7;i++)
{
sub=sb.substring(i,i+7);
String f="";
for(int j=0;j<sub.length();j++)
{
char ch=sub.charAt(j);
if(ch==req.charAt(j) || ch=='?')
f+=req.charAt(j);
else
break;
}
if(f.equals(req))
{
StringBuffer temp=new StringBuffer(sb);
temp.replace(i,i+7,req);
int gk=0;
for(int k=0;k<=temp.length()-7;k++)
{
sub=temp.substring(k,k+7);
if(sub.equals(req))
{
gk++;
}
}
if(gk==1)
{
flag=1;
sb.replace(i,i+7,req);
break;
}
}
}
if(flag==1)
{
String sp=sb.toString();
sp=sp.replace('?','z');
out.println("YES");
out.println(sp);
}
else
out.println("NO");
}
}
out.flush();
out.close();
}
static void ruffleSort(int[] a) {
Random random=new Random();
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
}
class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
String nextLine() {
String str="";
try {
str=br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
} | Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | ab54284e10c43b6b577b013712581420 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes |
import java.util.*;
public class Div_2_657_A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
boolean test = t == 4744;
for (int tt = 1; tt <= t; tt++) {
sc.nextInt();
char[] s = sc.next().toCharArray();
char[] sub = "abacaba".toCharArray();
// if (test) {
// if (tt == 176 || tt == 177 || tt == 178 || tt == 179) {
// System.out.println(tt);
// System.out.println(new String(s));
// solve(s, sub);
// }
// }
// if (!test) {
// //solve(s, sub);
// solveA(s,sub);
// }
solveA(s,sub);
}
sc.close();
}
public static void solveA(char[] s, char[] sub) {
for (int i = 0; i <= s.length - 7; i++) {
char[] x = s.clone();
for (int j = 0; j <= 6; j++) {
if (x[i + j] == '?' || x[i + j] == sub[j]) {
x[i + j] = sub[j];
}
}
for (int j = 0; j < x.length; j++) {
x[j] = x[j] == '?' ? 'z' : x[j];
}
if (count(new String(x), new String(sub))) {
System.out.println("Yes");
for (char ch : x)
System.out.print(ch);
System.out.println();
return;
}
}
System.out.println("No");
}
private static void solve(char[] s, char[] sub) {
boolean match = false;
if (count(new String(s), new String(sub))) {
match = true;
}
if (match) {
for (int i = 0; i < s.length; i++) {
if (s[i] == '?') {
s[i] = 'z';
}
}
System.out.println("Yes");
System.out.println(new String(s));
return;
}
boolean valid = false;
for (int i = 0; i <= s.length - 7; i++) {
String part = "" + s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] + s[i + 5] + s[i + 6];
valid = check(part.toCharArray(), sub);
if (valid) {
s[i + 0] = s[i + 0] == '?' ? sub[0] : s[i + 0];
s[i + 1] = s[i + 1] == '?' ? sub[1] : s[i + 1];
s[i + 2] = s[i + 2] == '?' ? sub[2] : s[i + 2];
s[i + 3] = s[i + 3] == '?' ? sub[3] : s[i + 3];
s[i + 4] = s[i + 4] == '?' ? sub[4] : s[i + 4];
s[i + 5] = s[i + 5] == '?' ? sub[5] : s[i + 5];
s[i + 6] = s[i + 6] == '?' ? sub[6] : s[i + 6];
break;
}
}
for (int i = 0; i < s.length; i++) {
s[i] = s[i] == '?' ? 'z' : s[i];
}
if (!valid || !(count(new String(s), new String(sub)))) {
System.out.println("No");
return;
}
System.out.println("Yes");
System.out.println(new String(s));
}
private static boolean check(char[] part, char[] sub) {
for (int i = 0; i < part.length; i++) {
if (part[i] == '?') {
part[i] = sub[i];
} else if (part[i] == sub[i]) {
} else {
return false;
}
}
return true;
}
private static boolean count(String s, String sub) {
int c = 0;
for (int i = 0; i <= s.length() - 7; i++) {
if (s.substring(i, i + 7).equals(sub)) {
c++;
}
}
return c == 1;
}
}
/*
* 1 5 ??ac??acaba?a??c??a????
*/
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | 0108719402e542ca42cd403229557a0e | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Div_2_657_A {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
for (int tt = 1; tt <= t; tt++) {
sc.nextInt();
char[] s = sc.next().toCharArray();
char[] sub = "abacaba".toCharArray();
solveA(s, sub);
}
}
public static void solveA(char[] s, char[] sub) {
for (int i = 0; i <= s.length - 7; i++) {
char[] x = s.clone();
for (int j = 0; j <= 6; j++) {
if (x[i + j] == '?' || x[i + j] == sub[j]) {
x[i + j] = sub[j];
}
}
for (int j = 0; j < x.length; j++) {
x[j] = x[j] == '?' ? 'z' : x[j];
}
if (count(new String(x), new String(sub))) {
System.out.println("Yes");
for (char ch : x)
System.out.print(ch);
System.out.println();
return;
}
}
System.out.println("No");
}
private static boolean count(String s, String sub) {
int c = 0;
for (int i = 0; i <= s.length() - 7; i++) {
if (s.substring(i, i + 7).equals(sub)) {
c++;
}
}
return c == 1;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | a08b8a4f4d31dcd8a84b690a5344b051 | train_000.jsonl | 1595149200 | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once. | 512 megabytes |
import java.util.*;
public class Solutiona {
static String ansString = "abacaba";
private static void findAns(String s)
{
int count =0;
for(int i =0;i<=s.length()-7;i++)
{
if(s.substring(i,i+7).equals(ansString))
{
count++;
}
}
if(count==1)
{
System.out.println("Yes");
System.out.println(s.replace('?','d'));
return;
}
else if(count>1) {
System.out.println("No");
return;
}
else {
char [] ansArr = s.toCharArray();
int counter =0;
for(int i =0;i<=s.length()-7;i++)
{
ansArr =s.toCharArray();
for(int j =0;j<7;j++)
{
if(s.charAt(i+j)=='?')
{
ansArr[i+j] =ansString.charAt(j);
String temp =new String(ansArr);
if(j==6)
{
int cnt =0;
for(int k =0;k<=s.length()-7;k++)
{
if(temp.substring(k,k+7).equals(ansString))
{
cnt++;
}
}
if(cnt>1) {
break;
}
System.out.println("Yes");
System.out.println(temp.replace('?','d'));
return;
}
}
else if(s.charAt(i+j)!=ansString.charAt(j)){
break;
}
else {
if(j==6)
{
int cnt =0;
String temp =new String(ansArr);
for(int k =0;k<=s.length()-7;k++)
{
if(temp.substring(k,k+7).equals(ansString))
{
cnt++;
}
}
if(cnt>1) {
break;
}
System.out.println("Yes");
System.out.println(temp.replace('?','d'));
return;
}
}
}
}
if(counter==0)
{
System.out.println("No");
return;
}
}
}
public static void main(String [] args)
{
Scanner in =new Scanner(System.in);
int t= in.nextInt();
for(int i =0;i<t;i++)
{
int n =in.nextInt();
String s = in.next();
findAns(s);
}
}
}
| Java | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | 1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring. | Java 11 | standard input | [
"implementation",
"brute force",
"strings"
] | f6b7ad10382135b293bd3f2f3257d4d3 | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. | 1,500 | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer). | standard output | |
PASSED | afec1a0e65bd3eec20206ef747475477 | train_000.jsonl | 1509113100 | A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | 256 megabytes | import java.util.Scanner;
public class Crosswords {
public static void main( String[] args ) {
Scanner hi = new Scanner( System.in );
String[] badoof = hi.nextLine().split(" ");
String[] badyoof = hi.nextLine().split(" ");
int[] oof = new int[2];
int[] yoof = new int[badyoof.length];
for( int i = 0; i < 2; i++ ) {
oof[i] = Integer.parseInt( badoof[i] );
}
for( int i = 0; i < badyoof.length ; i++ ) {
yoof[i] = Integer.parseInt( badyoof[i] );
}
int ans = 0;
for( int i = 0; i < yoof.length ; i++) {
ans += yoof[i];
}
if( ans + oof[0] - 1 == oof[1] ) {
System.out.println( "YES" );
}
else {
System.out.println( "NO" );
}
}
}
| Java | ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"] | 1 second | ["NO", "YES", "NO"] | null | Java 8 | standard input | [
"implementation"
] | 080a3458eaea4903da7fa4cf531beba2 | The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding. | 1,100 | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | standard output | |
PASSED | 7fccf3c0306a1b840749d23b8562ca0d | train_000.jsonl | 1509113100 | A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | 256 megabytes | import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.FileAlreadyExistsException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException{
Scanner scan = new Scanner(System.in);
// Scanner scan = new Scanner(new File("input.txt"));
while (scan.hasNext()) {
int numElements = scan.nextInt();
int len = scan.nextInt();
int sum = 0;
for (int i = 0; i < numElements; i++) {
sum+= scan.nextInt();
}
int leftover = len-sum;
if(leftover - (numElements-1) == 0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"] | 1 second | ["NO", "YES", "NO"] | null | Java 8 | standard input | [
"implementation"
] | 080a3458eaea4903da7fa4cf531beba2 | The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding. | 1,100 | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | standard output | |
PASSED | 480e9387c000013590dfb480da4663e7 | train_000.jsonl | 1509113100 | A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | 256 megabytes | import java.util.*;
public class JapaneseCrosswordsStrikeBack
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int sum = 0;
sc.nextLine();
for(int i = 0; i < n; i++)
{
sum += sc.nextInt();
}
if (sum + n - 1 == x) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
} | Java | ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"] | 1 second | ["NO", "YES", "NO"] | null | Java 8 | standard input | [
"implementation"
] | 080a3458eaea4903da7fa4cf531beba2 | The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding. | 1,100 | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | standard output | |
PASSED | 452335c9f4fab75a7b0ae00249cbabd5 | train_000.jsonl | 1509113100 | A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.run(args);
}
private void run(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new File("C:\\toolbar_local\\workspace\\Testing\\codeforces\\in.txt"));
// Scanner sc = new Scanner(new File("/Users/dackhue.nguyen/toolbar_local/workspace/codeforces/in.txt"));
int n = sc.nextInt();
int x = sc.nextInt();
int sum = 0;
for (int i = 0; i < n; i++) {
sum += sc.nextInt();
}
boolean check = check(n, x, sum);
System.out.println(check ? "YES" : "NO");
}
private boolean check(int n, int x, int sum) {
if (n == 1) {
if (sum == x) {
return true;
} else {
return false;
}
}
if (n >= x) {
return false;
}
if (sum >= x) {
return false;
} else {
if (x - sum == n - 1) {
return true;
} else {
return false;
}
}
}
}
| Java | ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"] | 1 second | ["NO", "YES", "NO"] | null | Java 8 | standard input | [
"implementation"
] | 080a3458eaea4903da7fa4cf531beba2 | The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding. | 1,100 | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | standard output | |
PASSED | db91661a995bc84f9ee23de43233946b | train_000.jsonl | 1509113100 | A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | 256 megabytes | import java.io.*;
import java.util.*;
public class CF884B {
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 x = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
x -= n - 1;
for (int i = 0; i < n; i++)
x -= Integer.parseInt(st.nextToken());
System.out.println(x == 0 ? "YES" : "NO");
}
}
| Java | ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"] | 1 second | ["NO", "YES", "NO"] | null | Java 8 | standard input | [
"implementation"
] | 080a3458eaea4903da7fa4cf531beba2 | The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding. | 1,100 | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.