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 | fe76f178ee3453f9cce4f272e40f9e7e | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static int N;
static long x;
static int[] d = new int[200002];
static long[] S = new long[200002];
static long[] H = new long[200002];
static long Answer;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
x = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) {
d[i] = Integer.parseInt(st.nextToken());
}
S[N+1] = H[N+1] = 0;
for (int i = N; i >= 1; i--) {
S[i] = S[i+1]+d[i];
H[i] = H[i+1]+((long)(1+d[i])*d[i])/2;
}
Answer = 0;
solve();
bw.write(Answer + "\n");
bw.flush();
bw.close();
}
private static void solve() {
long sd = S[2]-S[N+1], day, hug;
for (int s = 2, e = 1; e <= N; e++) {
sd += d[e];
while (x <= sd) {
sd -= d[s++];
if (N < s) s = 1;
}
hug = (s == (e%N)+1)? 0 : (s <= e)? H[s]-H[e+1] : (H[s]-H[N+1])+(H[1]-H[e+1]);
int ix = (1 < s)? s-1 : N;
day = x-sd;
hug += ((d[ix]-day+1+d[ix])*day)/2;
Answer = Math.max(Answer, hug);
}
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 0ff7828c671315d235515af6d282332d | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static int N;
static long x;
static int[] d = new int[200002];
static long[] S = new long[200002];
static long[] H = new long[200002];
static long Answer;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
x = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) {
d[i] = Integer.parseInt(st.nextToken());
}
S[N+1] = H[N+1] = 0;
for (int i = N; i >= 1; i--) {
S[i] = S[i+1]+d[i];
H[i] = H[i+1]+((long)(1+d[i])*d[i])/2;
}
Answer = 0;
solve();
bw.write(Answer + "\n");
bw.flush();
bw.close();
}
private static void solve() {
long day, hug;
for (int i = 1; i <= N; i++) {
day = x;
if (day <= d[i]) hug = ((d[i]-day+1+d[i])*day)/2;
else {
day -= d[i]; hug = H[i]-H[i+1];
int start = 1, end = i-1;
if (day > S[1]-S[i]) {
day -= S[1]-S[i]; hug += H[1]-H[i];
end = N;
}
if (0 < day) {
int s = start, e = end, m, ix = 1;
while (s <= e) {
m = (s+e)/2;
if (day <= S[m]-S[end+1]) { ix = m; s = m+1; }
else { e = m-1; }
}
day -= S[ix+1]-S[end+1]; hug += H[ix+1]-H[end+1];
hug += ((d[ix]-day+1+d[ix])*day)/2;
}
}
Answer = Math.max(Answer, hug);
}
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 4632a0c6868cbda773d157d3ccb907d8 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.math.* ;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
//class Declaration
static class pair implements Comparable<pair>{
int x;
int y;
pair (int i,int j)
{ x=i; y=j;
}
public int compareTo(pair p){
if(this.x!=p.x) { return this.x-p.x;}
else { return this.y-p.y;}
}
public int hashCode() { return (x+" "+y).hashCode();}
public String toString(){ return x+" "+y;}
public boolean equals(Object o){
pair x = (pair) o ;
return (x.x==this.x&&x.y==this.y);}
}
// int[] dx = {0,0,1,-1};
// int[] dy = {1,-1,0,0};
// int[] ddx = {0,0,1,-1,1,-1,1,-1};
// int[] ddy = {1,-1,0,0,1,-1,-1,1};
long mod = (long)1e9 + 7;
int inf = (int)1e9 +5;
void solve() throws Exception{
int n=ni();
long x=nl();
long [] arr = new long[2*n+1];
long[] ans = new long[2*n+1] ;
for(int i=1;i<=n;++i){
arr[i] = nl();;
arr[i+n] = arr[i];
}
long[] prefix = new long[2*n+1];
for(int i=1;i<prefix.length;++i){
prefix[i] = prefix[i-1] + arr[i];
ans[i] = ans[i-1] + arr[i]*(arr[i]+1)/2 ;
}
long fa = -1 ;
for(int i=1;i<=n;++i){
int limit = bs(prefix,i,x) ;
//pn("for i = "+i);
//pn("limit : "+limit);
long spaceRemain = Math.min(arr[limit]-(x - (prefix[limit-1]-prefix[i-1])),arr[i]-1);
//pn("spaceRemain :" + spaceRemain);
long delta = arr[i]*(arr[i]+1)/2 - spaceRemain*(spaceRemain+1)/2 ;
long lastMonthDays = (x - (prefix[limit-1]-prefix[i-1])) +spaceRemain ;
//pn("lastMonthDays :"+lastMonthDays);
long pa = ans[limit-1] - ans[i] + delta + lastMonthDays*(lastMonthDays+1)/2;
//pn("for i :"+i+" ans "+pa);
//pn("");
fa = Math.max(fa,pa);
}
pn(fa);
}
int bs(long[] prefix,int s,long x){
int ind = s ;
int start = s ;
int end = prefix.length -1 ;
while(start<=end){
int mid = (start+end)/2 ;
if(prefix[mid]-prefix[s-1] >= x){
ind = mid ;
end = mid -1 ;
}
else{
start = mid + 1 ;
}
}
return ind ;
}
long pow(long a,long b){
long result = 1;
while(b>0){
if(b%2==1) result = (result * a) % mod;
b/=2;
a=(a*a)%mod;
}
return result;
}
void print(Object o){
System.out.println(o);
System.out.flush();
}
long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
void run() throws Exception{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Main().run(); }
//output methods
private void pn(Object o)
{
out.println(o);
}
private void p(Object o)
{
out.print(o);
}
private ArrayList<ArrayList<Integer>> ng(int n,int e){
ArrayList<ArrayList<Integer>> g = new ArrayList<>();
for(int i=0;i<=n;++i) g.add(new ArrayList<>());
for(int i=0;i<e;++i){
int u =ni(),v=ni();
g.get(u).add(v);
g.get(v).add(u);
}
return g ;
}
private ArrayList<ArrayList<pair>> nwg(int n,int e){
ArrayList<ArrayList<pair>> g = new ArrayList<>();
for(int i=0;i<=n;++i) g.add(new ArrayList<>());
for(int i=0;i<e;++i){
int u =ni(),v=ni(),w=ni();
g.get(u).add(new pair(w,v));
g.get(v).add(new pair(w,u));
}
return g ;
}
//input methods
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
void watch(Object ... a) throws Exception{
int i=1;
print("watch starts :");
for(Object o : a ) {
//print(o);
boolean notfound = true;
if(o.getClass().isArray()){
String type = o.getClass().getName().toString();
//print("type is "+type);
switch (type) {
case "[I":{
int[] test = (int[])o ;
print(i+" "+Arrays.toString(test));
break;
}
case "[[I":{
int[][] obj = (int[][])o;
print(i+" "+Arrays.deepToString(obj));
break;
}
case "[J" : {
long[] obj = (long[])o ;
print(i+" "+Arrays.toString(obj));
break;
}
case "[[J": {
long[][] obj = (long[][])o;
print(i+" "+Arrays.deepToString(obj));
break;
}
case "[D" :{
double[] obj= (double[])o;
print(i+" "+Arrays.toString(obj));
break;
}
case "[[D" :{
double[][] obj = (double[][])o;
print(i+" "+Arrays.deepToString(obj));
break;
}
case "[Ljava.lang.String": {
String[] obj = (String[])o ;
print(i+" "+Arrays.toString(obj));
break;
}
case "[[Ljava.lang.String": {
String[][] obj = (String[][])o ;
print(i+" "+Arrays.deepToString(obj));
break ;
}
case "[C" :{
char[] obj = (char[])o ;
print(i+" "+Arrays.toString(obj));
break;
}
case "[[C" :{
char[][] obj = (char[][])o;
print(i+" "+Arrays.deepToString(obj));
break;
}
default:{
print(i+" type not identified");
break;
}
}
notfound = false;
}
if(o.getClass() == ArrayList.class){
print(i+" al: "+o);
notfound = false;
}
if(o.getClass() == HashSet.class){
print(i+" hs: "+o);
notfound = false;
}
if(o.getClass() == TreeSet.class){
print(i+" ts: "+o);
notfound = false;
}
if(o.getClass() == TreeMap.class){
print(i+" tm: "+o);
notfound = false;
}
if(o.getClass() == HashMap.class){
print(i+" hm: "+o);
notfound = false;
}
if(o.getClass() == LinkedList.class){
print(i+" ll: "+o);
notfound = false;
}
if(o.getClass() == PriorityQueue.class){
print(i+" pq : "+o);
notfound = false;
}
if(o.getClass() == pair.class){
print(i+" pq : "+o);
notfound = false;
}
if(notfound){
print(i+" unknown: "+o);
}
i++;
}
print("watch ends ");
}
} | Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 6f329b5eb45b8ca5c92335a8e4049d34 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class Main {
private static final int MAXN = 5000;
private static final String NO = "NO";
private static final String YES = "YES";
InputStream is;
PrintWriter out;
String INPUT = "";
private static final long MOD = 1000000007L;
void solve() {
int n = ni();
long x = nl();
long[] a = new long[2 * n];
for (int i = 0; i < n; i++)
a[i] = a[i + n] = nl();
n *= 2;
int l = 0;
long cnt = 0;
long sum = 0;
long ans = 0;
// for (int r = 0; r < n; r++) {
// ans = Math.max(ans, sum + f(1, Math.min(a[r], x - cnt)));
// cnt += a[r];
// sum += f(1, a[r]);
// while (cnt >= x) {
// cnt -= a[l];
// sum -= f(1, a[l++]);
// }
// }
// tr(a);
cnt = 0;
sum = 0;
int r = n - 1;
for (l = n - 1; l >= 0; l--) {
cnt += a[l];
sum += f(1, a[l]);
while (cnt - a[r] > x) {
cnt -= a[r];
sum -= f(1, a[r--]);
}
ans = Math.max(ans, sum - f(0, Math.max(0, cnt - x)));
// tr(l, r, cnt, sum, ans, Math.max(0, cnt - x));
}
out.println(ans);
}
private long f(long s, long e) {
// tr(">", s, e);
return (e - s + 1) * (e + s) / 2;
}
long power(long a, long b) {
long x = 1, y = a;
while (b > 0) {
if (b % 2 != 0) {
x = (x * y) % MOD;
}
y = (y * y) % MOD;
b /= 2;
}
return x % MOD;
}
private long gcd(long a, long b) {
while (a != 0) {
long tmp = b % a;
b = a;
a = tmp;
}
return b;
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty())
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private boolean vis[];
private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
// ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n) {
if (!(isSpaceChar(b)))
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private List<Integer> na2(int n) {
List<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < n; i++)
a.add(ni());
return a;
}
private int[][] na(int n, int m) {
int[][] a = new int[n][];
for (int i = 0; i < n; i++)
a[i] = na(m);
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long[] nl(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nl();
return a;
}
private long[][] nl(int n, int m) {
long[][] a = new long[n][];
for (int i = 0; i < n; i++)
a[i] = nl(m);
return a;
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
public class Pair<K, V> {
/**
* Key of this <code>Pair</code>.
*/
private K key;
/**
* Gets the key for this pair.
*
* @return key for this pair
*/
public K getKey() {
return key;
}
/**
* Value of this this <code>Pair</code>.
*/
private V value;
/**
* Gets the value for this pair.
*
* @return value for this pair
*/
public V getValue() {
return value;
}
/**
* Creates a new pair
*
* @param key The key for this pair
* @param value The value to use for this pair
*/
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
/**
* <p>
* <code>String</code> representation of this <code>Pair</code>.
* </p>
*
* <p>
* The default name/value delimiter '=' is always used.
* </p>
*
* @return <code>String</code> representation of this <code>Pair</code>
*/
@Override
public String toString() {
return key + "=" + value;
}
/**
* <p>
* Generate a hash code for this <code>Pair</code>.
* </p>
*
* <p>
* The hash code is calculated using both the name and the value of the
* <code>Pair</code>.
* </p>
*
* @return hash code for this <code>Pair</code>
*/
@Override
public int hashCode() {
// name's hashCode is multiplied by an arbitrary prime number (13)
// in order to make sure there is a difference in the hashCode between
// these two parameters:
// name: a value: aa
// name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
}
/**
* <p>
* Test this <code>Pair</code> for equality with another <code>Object</code>.
* </p>
*
* <p>
* If the <code>Object</code> to be tested is not a <code>Pair</code> or is
* <code>null</code>, then this method returns <code>false</code>.
* </p>
*
* <p>
* Two <code>Pair</code>s are considered equal if and only if both the names and
* values are equal.
* </p>
*
* @param o the <code>Object</code> to test for equality with this
* <code>Pair</code>
* @return <code>true</code> if the given <code>Object</code> is equal to this
* <code>Pair</code> else <code>false</code>
*/
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o instanceof Pair) {
Pair pair = (Pair) o;
if (key != null ? !key.equals(pair.key) : pair.key != null)
return false;
if (value != null ? !value.equals(pair.value) : pair.value != null)
return false;
return true;
}
return false;
}
}
} | Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | ffa059b6d062b2d5e94b85bfd4b762f7 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
static class pair implements Comparable
{
int f;
int s;
pair(int fi, int se)
{
f=fi;
s=se;
}
public int compareTo(Object o)//desc order
{
pair pr=(pair)o;
if(s>pr.s)
return -1;
if(s==pr.s)
{
if(f>pr.f)
return 1;
else
return -1;
}
else
return 1;
}
public boolean equals(Object o)
{
pair ob=(pair)o;
if(o!=null)
{
if((ob.f==this.f)&&(ob.s==this.s))
return true;
}
return false;
}
public int hashCode()
{
return (this.f+" "+this.s).hashCode();
}
}
public class triplet implements Comparable
{
int f;
int s;
long t;
triplet(int f,int s,long t)
{
this.f=f;
this.s=s;
this.t=t;
}
public boolean equals(Object o)
{
triplet ob=(triplet)o;
if(o!=null)
{
if((ob.f==this.f)&&(ob.s==this.s)&&(ob.t==this.t))
return true;
}
return false;
}
public int hashCode()
{
return (this.f+" "+this.s+" "+this.t).hashCode();
}
public int compareTo(Object o)//asc order
{
triplet tr=(triplet)o;
if(t>tr.t)
return 1;
else
return -1;
}
}
void merge1(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2)
{
if (L[i]<=R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
void sort1(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort1(arr, l, m);
sort1(arr , m+1, r);
merge1(arr, l, m, r);
}
}
public static void main(String args[])throws Exception
{
new Thread(null,new Solution(),"Solution",1<<27).start();
}
public int justlarge(long a[],int l,int r,long x)
{
int p=0;
while(l<=r)
{
int mid=(l+r)/2;
if(a[mid]<x)
{
l=mid+1;
}
else
{
p=mid;
r = mid - 1;
}
}
return p;
}
public void run()
{
try
{
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=in.ni();
long x=in.nl();
long d[]=new long[2*n+1];
for(int i=1;i<=n;i++)
{
d[i]=in.nl();
d[n+i]=d[i];
}
long sumd[]=new long[2*n+1];
long sum[]=new long[2*n+1];
for(int i=1;i<=2*n;i++)
{
sumd[i]=sumd[i-1]+d[i];
sum[i]=sum[i-1]+(d[i]*(d[i]+1))/2;
}
long max=0;
for(int i=2*n;i>=1;i--)
{
long r=sumd[i];
long y=sumd[i]-x;
long l=y+1;
if(l<=0)
break;
int p=justlarge(sumd,1,2*n,l);
long ans=sum[i]-sum[p];
long qq=d[p]-(sumd[p]-l+1);
long q=(d[p]*(d[p]+1))/2 - (qq*(qq+1))/2;
ans+=q;
//System.out.println(i+" "+d[i]+" "+sumd[i]+" "+p+" "+sumd[p]+" "+qq+" "+l+" "+q+" "+ans);
max=Math.max(max,ans);
}
out.println(max);
out.close();
}
catch(Exception e){
System.out.println(e);
//throw new RuntimeException();
}
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 83d247f65ccdd38a37e356c4988b5624 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
public static void main(String[] args) throws Exception {
new template().run();
}
public void run() throws Exception {
FastScanner f = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = f.nextInt(); long x = f.nextLong();
long[] arr = new long[2*n];
for(int i = 0; i < n; i++)
arr[i] = arr[i+n] = f.nextLong();
int l = 0;
long sum = 0;
long ans = 0;
long cur = 0;
for(int i = 0; i < arr.length; i++) {
sum += arr[i];
cur += (arr[i]+1)*arr[i]/2;
while(sum > x) {
cur -= (arr[l]+1)*arr[l]/2;
sum -= arr[l++];
}
long add = 0;
if(l != 0) {
long v = x-sum;
add = arr[l-1]*(arr[l-1]+1)/2-(arr[l-1]-v)*(arr[l-1]+1-v)/2;
}
ans = Math.max(ans, cur+add);
}
out.println(ans);
out.flush();
}
static class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 18454789b25a3f4a9d7c305ad3b68d57 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | //package javaapplication5;
import java.io.*;
import java.util.*;
public class utkarsh {
BufferedReader br;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (3e18);
long sigma(long n) {
return n * (n + 1) / 2;
}
void solve() {
int n = ni(); long x = nl();
long d[] = new long[n];
long a[] = new long[n];
long pre_d[] = new long[n];
long pre_a[] = new long[n];
for(int i = 0; i < n; i++) {
d[i] = nl();
pre_d[i] = d[i];
if(i > 0) pre_d[i] += pre_d[i-1];
a[i] = d[i] * (d[i] + 1) / 2;
pre_a[i] = a[i];
if(i > 0) pre_a[i] += pre_a[i-1];
}
long ans = 0;
for(int i = 0; i < n; i++) {
int l = i-n, r = i;
while(l <= r) {
int m = (l + r) / 2;
long sum_d;
if(m < 0) sum_d = pre_d[n-1] - pre_d[m+n] + pre_d[i];
else sum_d = pre_d[i] - pre_d[m];
if(sum_d > x) l = m + 1;
else r = m - 1;
}
long sum_d;
if(l < 0) sum_d = pre_d[n-1] - pre_d[l+n] + pre_d[i];
else sum_d = pre_d[i] - pre_d[l];
long sum_a;
if(l < 0) sum_a = pre_a[n-1] - pre_a[l+n] + pre_a[i];
else sum_a = pre_a[i] - pre_a[l];
if(l < 0) l += n;
sum_a += a[l] - sigma(d[l] - (x - sum_d));
ans = Math.max(ans, sum_a);
}
out.println(ans);
}
long mp(long b, long e) {
long r = 1;
while(e > 0) {
if( (e&1) == 1 ) r = (r * b) % mod;
b = (b * b) % mod;
e >>= 1;
}
return r;
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
StringTokenizer ip;
String ns() {
if(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) {
new utkarsh().run();
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | f4ce4826c95d7a61eb94713bc504dafa | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes |
// Spaghetti code
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static int mod=(int)(1e9+7);
static int mod2=998244353;
static PrintWriter pw;
static class FastReader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(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 next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
public 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 i(){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(next()) ;}
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 void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li)arr[li]=i();}
public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}}
public void printIntArr(int [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
public void printLongArr(long [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; }}
public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a)
public int findMax(int [] arr){int res=Integer.MIN_VALUE;for(int num:arr)res=Math.max(res,num);return res;}
}
public static void main(String[] args) throws IOException {
FastReader fr = new FastReader();
pw = new PrintWriter(System.out);
/*
inputCopy
3 2
1 3 1
outputCopy
5
inputCopy
3 6
3 3 3
outputCopy
12
inputCopy
5 6
4 2 3 1 3
outputCopy
15
200000 200000000000
3 10
5 8 1
*/
//Press Ctrl+Win+Alt+L for reformatting indentation
int t = 1;
for (int ti = 0; ti < t; ++ti) {
int n = fr.i();
long d = fr.l();
long ans = 0;
long[] arr = new long[2 * n];
for (int ni = 0; ni < n; ++ni) arr[ni] = fr.l();
for (int ni = n; ni < 2 * n; ++ni) arr[ni] = arr[ni - n];
// Arrays.fill(arr,1000000);
long[] added = new long[2 * n];
long curSum = 0, cur = 0;
int start = 0;
for (int ni = 0; ni < arr.length; ++ni) {
curSum += arr[ni];
// System.err.println("Start : "+start+" "+ni+" "+curSum+" "+ans);
if (curSum > d) {
while (curSum > d) {
curSum -= arr[start];
cur -= added[start];
added[start] = 0;
++start;
}
if (curSum == 0) {
cur = added[ni] = getVal(arr[ni]) - getVal(arr[ni] - d);
ans = Math.max(ans, cur);
curSum = 0;
cur = 0;
arr[ni] = 0;
added[ni] = 0;
} else {
long diff = d - curSum;
// System.err.println("diff="+diff);
int prev = (start - 1 + arr.length) % arr.length;
added[prev] = getVal(arr[prev]) - getVal(arr[prev] - diff);
curSum += diff;
arr[prev] = diff;
cur += added[prev];
added[ni] = getVal(arr[ni]);
cur += added[ni];
ans = Math.max(ans, cur);
if (added[prev] > 0) --start;
}
} else {
added[ni] = getVal(arr[ni]);
cur += added[ni];
ans = Math.max(ans, cur);
}
// System.err.println("End : "+start+" "+curSum+" "+ans);
// System.err.println(Arrays.toString(added));
}
pw.println(ans);
}
pw.flush();
pw.close();
}
private static long getVal(long l) {
return (l * (l + 1)) / 2;
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 66fcbd079a92ff9db8b3f3b1410ee279 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes |
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Solution
{
static class Pair<A,B>
{
A parent;
B rank;
Pair(A parent,B rank)
{
this.rank=rank;
this.parent=parent;
}
}
static class Node{
int x;
int y;
Node(int i,int j)
{
x=i;
y=j;
}
}
static int m=1000000007;
static ArrayList<Integer> graph[];
static boolean visited[];
static int fact[];
public static void main (String[] args) throws IOException
{
StringBuilder sb = new StringBuilder();
FastReader s1 = new FastReader();
int n=s1.I();
long days=s1.L();
int ar[] = new int[2*n+1];
for(int i=1;i<=n;i++)
{
ar[i]=s1.I();
ar[n+i]=ar[i];
}
long pre1[] = new long[2*n+1];
long pre2[] = new long[2*n+1];
for(int i=1;i<2*n+1;i++)
{
long temp=ar[i];
pre1[i]=pre1[i-1]+((temp*(temp+1))/2);
pre2[i]=pre2[i-1]+ar[i];
}
long maxi=0;
for(int i=2*n;i>=n+1;i--)
{
long find=pre2[i]-days;
int left=1;
int right=i;
int ans=i;
while(left<right)
{
int mid=(left+right)/2;
if(pre2[mid]>=find && pre2[mid-1]<find)
{
ans=mid;
break;
}
if(pre2[mid]>find)
right=mid;
if(pre2[mid]<find)
left=mid+1;
}
long sum=pre1[i]-pre1[ans];
long demo=pre2[ans]-find;
long temp=sum(ar[ans])-sum(ar[ans]-demo);
sum+=temp;
if(sum>maxi)
maxi=sum;
}
System.out.println(maxi);
}
static long sum(long a)
{
return (a*(a+1))/2;
}
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 I()
{
return Integer.parseInt(next());
}
long L()
{
return Long.parseLong(next());
}
double D()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static long gcd(long a,long b)
{
if(a%b==0)
return b;
return gcd(b,a%b);
}
static float power(float x, int y)
{
float temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
{
if(y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
static long pow(long x, long y)
{
int p = 1000000007;
long res = 1;
x = x % p;
if(x<0)
x+=p;
while (y > 0)
{
if((y & 1)==1){
res = (res * x) % p;
if(res<0)
res+=p;
}
y = y >> 1;
x = (x * x) % p;
if(x<0)
x=x+p;
}
res=res%p;
if(res<0)
res+=p;
return res;
}
static void sieveOfEratosthenes(int n)
{
ArrayList<Integer> prime=new ArrayList<Integer>();
boolean Prime[] = new boolean[n+1];
for(int i=2;i<n;i++)
Prime[i] = true;
for(int p = 2; p*p <=n; p++)
{
if(Prime[p] == true)
{
prime.add(p);
for(int i = p*p; i <= n; i += p)
Prime[i] = false;
}
}
}
} | Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 30f2e4141ed950e365a8a2055363f007 | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes |
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Solution
{
static class Pair<A,B>
{
A parent;
B rank;
Pair(A parent,B rank)
{
this.rank=rank;
this.parent=parent;
}
}
static class Node{
int x;
int y;
Node(int i,int j)
{
x=i;
y=j;
}
}
static int m=1000000007;
static ArrayList<Integer> graph[];
static boolean visited[];
static int fact[];
public static void main (String[] args) throws IOException
{
StringBuilder sb = new StringBuilder();
FastReader s1 = new FastReader();
int n=s1.I();
long days=s1.L();
int ar[] = new int[2*n+1];
for(int i=1;i<=n;i++)
{
ar[i]=s1.I();
ar[n+i]=ar[i];
}
long pre1[] = new long[2*n+1];
long pre2[] = new long[2*n+1];
for(int i=1;i<2*n+1;i++)
{
long temp=ar[i];
pre1[i]=pre1[i-1]+((temp*(temp+1))/2);
pre2[i]=pre2[i-1]+ar[i];
}
long maxi=0;
for(int i=2*n;i>=n+1;i--)
{
long find=pre2[i]-days;
int left=1;
int right=i;
int ans=i;
while(left<=right)
{
int mid=(left+right)/2;
if(pre2[mid]>find){
right=mid-1;
ans=mid;
}
else
left=mid+1;
}
long sum=pre1[i]-pre1[ans-1];
long demo=pre2[ans]-find;
long temp=sum(pre2[i]-days-pre2[ans-1]);
sum-=temp;
if(sum>maxi)
maxi=sum;
}
System.out.println(maxi);
}
static long sum(long a)
{
return (a*(a+1))/2;
}
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 I()
{
return Integer.parseInt(next());
}
long L()
{
return Long.parseLong(next());
}
double D()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static long gcd(long a,long b)
{
if(a%b==0)
return b;
return gcd(b,a%b);
}
static float power(float x, int y)
{
float temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
{
if(y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
static long pow(long x, long y)
{
int p = 1000000007;
long res = 1;
x = x % p;
if(x<0)
x+=p;
while (y > 0)
{
if((y & 1)==1){
res = (res * x) % p;
if(res<0)
res+=p;
}
y = y >> 1;
x = (x * x) % p;
if(x<0)
x=x+p;
}
res=res%p;
if(res<0)
res+=p;
return res;
}
static void sieveOfEratosthenes(int n)
{
ArrayList<Integer> prime=new ArrayList<Integer>();
boolean Prime[] = new boolean[n+1];
for(int i=2;i<n;i++)
Prime[i] = true;
for(int p = 2; p*p <=n; p++)
{
if(Prime[p] == true)
{
prime.add(p);
for(int i = p*p; i <= n; i += p)
Prime[i] = false;
}
}
}
} | Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | dc0e15da076298f3b83597ad342125da | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.util.*;
public class Main {
final static int maxn=(int)1e6+10;
final static int mod=(int)2e5+10;
static long num[]=new long [maxn];
static int d[]=new int [maxn];
static long sum[]=new long [maxn];
static long sumday[]=new long [maxn];
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int n;long x;
n=input.nextInt();x=input.nextLong();
Arrays.fill(num, 0);
for(int i=1;i<=maxn-5;i++)
num[i]=num[i-1]+i;
for(int i=0;i<n;i++)d[i]=input.nextInt();
for(int i=n;i<2*n;i++)d[i]=d[i%n];
sum[0]=num[d[1]];sumday[0]=d[0];
for(int i=1;i<n*2;i++)
{sum[i]+=sum[i-1]+num[d[i]];sumday[i]+=sumday[i-1]+d[i];}
int l=0;long daysum=0;long ans=0;
for(int i=0;i<2*n;i++)
{
daysum+=d[i];
while(daysum-d[l]>=x)
{daysum-=d[l];l++;}
if(daysum>=x)
{
long prians=sum[i]-sum[l];
long restday=x-(sumday[i]-sumday[l]);
prians+=(long)(d[l]-restday+1+d[l])*restday/2;
ans=Math.max(ans, prians);
}
}
System.out.println(ans);
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 0c581845e9b1e5d128d96247ef2f31ee | train_000.jsonl | 1590503700 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $$$x$$$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $$$x$$$ consecutive (successive) days visiting Coronavirus-chan.They use a very unusual calendar in Naha: there are $$$n$$$ months in a year, $$$i$$$-th month lasts exactly $$$d_i$$$ days. Days in the $$$i$$$-th month are numbered from $$$1$$$ to $$$d_i$$$. There are no leap years in Naha.The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $$$j$$$ hugs if you visit Coronavirus-chan on the $$$j$$$-th day of the month.You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author out_of_the_box
*/
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);
DTheBestVacation solver = new DTheBestVacation();
solver.solve(1, in, out);
out.close();
}
static class DTheBestVacation {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int N = in.nextInt();
long x = in.nextLong();
int[] D = in.nextIntArray(N);
int[] d = Stream.concat(Arrays.stream(D).boxed(), Arrays.stream(D).boxed()).mapToInt(i -> i).toArray();
int n = 2 * N;
long ans = 0L;
long[] pre = new long[n];
// long[] post = new long[n];
pre[0] = d[0];
long[] monthVal = new long[n];
long[] preMonVal = new long[n];
for (int i = 0; i < n; i++) {
long dl = d[i];
monthVal[i] = (dl * (dl + 1L)) / 2L;
}
preMonVal[0] = monthVal[0];
for (int i = 1; i < n; i++) {
preMonVal[i] = preMonVal[i - 1] + monthVal[i];
}
for (int i = 1; i < n; i++) {
pre[i] = pre[i - 1] + d[i];
}
// post[n-1] = d[n-1];
// for (int i = n-2; i >= 0; i--) {
// post[i] = post[i+1] + d[i];
// }
for (int i = 0; i < n; i++) {
ans = Math.max(ans, getStart(i, n, x, pre, preMonVal));
}
for (int i = 0; i < n; i++) {
ans = Math.max(ans, getEnd(i, n, x, pre, preMonVal, d));
}
out.println(ans);
}
private long getStart(int i, int n, long x, long[] pre, long[] preMonthVal) {
Function<Integer, Boolean> func = ind -> getPreCount(i, ind, pre) > x;
int j = BinarySearch.searchLastZero(i - 1, n, func);
long done = getPreCount(i, j, pre);
if (j == i - 1) {
return (x * (x + 1L)) / 2L;
}
long rem = x - done;
if (j == n - 1) {
if (rem != 0L) {
return 0L;
} else {
return getPreCount(i, j, preMonthVal);
}
}
long ret = getPreCount(i, j, preMonthVal);
ret += (rem * (rem + 1L)) / 2L;
return ret;
}
private long getPreCount(int i, int j, long[] pre) {
if (i > j) return 0L;
if (i == 0) return pre[j];
return pre[j] - pre[i - 1];
}
private long getEnd(int i, int n, long x, long[] pre, long[] preMonthVal, int[] d) {
Function<Integer, Boolean> func = ind -> getPreCount(ind, i, pre) <= x;
int j = BinarySearch.searchFirstOne(-1, i + 1, func);
if (j == (i + 1)) {
return getFromEndOfMonth(x, d[i]);
}
long done = getPreCount(j, i, pre);
long rem = x - done;
if (j == 0) {
if (rem != 0L) {
return 0L;
} else {
return getPreCount(j, i, preMonthVal);
}
}
long ret = getPreCount(j, i, preMonthVal);
ret += getFromEndOfMonth(rem, d[j - 1]);
return ret;
}
private long getFromEndOfMonth(long x, long tot) {
if (x > tot) {
throw new RuntimeException(String.format("Total needed from month [%d] is larger than month size [%d]",
x, tot));
}
long base = tot - x;
return (base * x) + ((x * (x + 1L)) / 2L);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
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 close() {
writer.close();
}
public void println(long i) {
writer.println(i);
}
}
static class BinarySearch {
public static int searchFirstOne(int start, int end, Function<Integer, Boolean> valueFunc) {
int low = start;
int high = end;
while ((high - low) > 1) {
int mid = low + (high - low) / 2;
if (valueFunc.apply(mid)) {
high = mid;
} else {
low = mid;
}
}
return high;
}
public static int searchLastZero(int start, int end, Function<Integer, Boolean> valueFunc) {
int low = start;
int high = end;
while ((high - low) > 1) {
int mid = low + (high - low) / 2;
if (valueFunc.apply(mid)) {
high = mid;
} else {
low = mid;
}
}
return low;
}
}
}
| Java | ["3 2\n1 3 1", "3 6\n3 3 3", "5 6\n4 2 3 1 3"] | 2 seconds | ["5", "12", "15"] | NoteIn the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $$$\{1,1,2,3,1\}$$$. Coronavirus-chan will hug you the most if you come on the third day of the year: $$$2+3=5$$$ hugs.In the second test case, the numbers of the days are $$$\{1,2,3,1,2,3,1,2,3\}$$$. You will get the most hugs if you arrive on the third day of the year: $$$3+1+2+3+1+2=12$$$ hugs.In the third test case, the numbers of the days are $$$\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$$$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $$$2+3+1+2+3+4=15$$$ times. | Java 8 | standard input | [
"greedy",
"two pointers",
"implementation",
"binary search",
"brute force"
] | 9ba374e20305d93ba42ef152e2cad5b5 | The first line of input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of months in the year and the number of days you can spend with your friend. The second line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$, $$$d_i$$$ is the number of days in the $$$i$$$-th month ($$$1 \le d_i \le 10^6$$$). It is guaranteed that $$$1 \le x \le d_1 + d_2 + \ldots + d_n$$$. | 1,900 | Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. | standard output | |
PASSED | 30169bdab021fc839637e05b9029b2b2 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | //package e75;
import java.util.*;
import java.io.*;
public class Main {
BufferedReader in;
StringTokenizer str = null;
private int nextInt() throws Exception{
if (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return Integer.parseInt(str.nextToken());
}
private int find(int x){
if (x != p[x]) return p[x] = find(p[x]);
return x;
}
int []p;
public void run() throws Exception{
//in = new BufferedReader(new FileReader("input.txt"));
in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = nextInt();
int m = nextInt();
p = new int[n];
for(int i=1;i<n;i++) p[i] = i;
int mod = 1000000009;
int ret = 1;
for(int i=0;i<m;i++){
int x = nextInt() - 1;
int y = nextInt() - 1;
int a = find(x);
int b = find(y);
if (a == b){
ret*=2;
ret%=mod;
}else{
p[a] = b;
}
out.println((ret-1));
}
out.close();
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | e874a94b795c07e0f88e6c6fe61d80ca | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SkiBase {
private static class UnionSet {
private int[] parent;
private UnionSet(int size){
parent = new int[size];
for(int i = 0; i < size; i++){
parent[i] = i;
}
}
private int getParent(int a){
if(parent[a] == a) return a;
return parent[a] = getParent(parent[a]);
}
private void join(int a, int b){
parent[getParent(a)] = getParent(b);
}
private boolean isJoined(int a, int b){
return getParent(a) == getParent(b);
}
}
public static void main(String[] args) throws Exception {
final int MOD = 1000000009;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
UnionSet uset = new UnionSet(n);
int total = 0;
for(int i = 1; i <= m; i++){
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
a--;b--;
if(uset.isJoined(a, b) == false){
uset.join(a, b);
}else{
total = total * 2;
total++;
total = total % MOD;
}
System.out.println(total);
}
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | 5628a692ca6ff9938f4ef87d0bdd4b60 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
/**
* @param args
*/
static int N, M;
static int[] p;
static long[] c;
static long mod = 1000000009;
public static void main(String[] args) {
InputReader r = new InputReader(System.in);
N = r.nextInt();
M = r.nextInt();
p = new int[N];
for(int i = 0; i < N; i++)
p[i] = i;
c = new long[N];
long ret = 1;
for(int k = 0; k < M; k++){
int i = r.nextInt() - 1;
int j = r.nextInt() - 1;
if(find(i) == find(j)){
ret = (ret * modPow(c[find(i)] + 1, mod - 2)) % mod;
ret = (ret * ((2 * c[find(i)] + 1 + 1) % mod)) % mod;
c[find(i)] = (c[find(i)] * 2 + 1) % mod;
}else{
ret = (ret * modPow(c[find(i)] + 1, mod - 2)) % mod;
ret = (ret * modPow(c[find(j)] + 1, mod - 2)) % mod;
union(i, j);
ret = (ret * (c[find(i)] + 1)) % mod;
}
// System.out.println(Arrays.toString(c));
System.out.println((ret - 1 + mod) % mod);
}
}
private static long modPow(long l, long p) {
if(p == 0)return 1;
else{
if(p % 2 == 0){
long ret = modPow(l, p / 2);
return (ret * ret) % mod;
}else{
long ret = modPow(l, p - 1);
return (l * ret) % mod;
}
}
}
private static void union(int i, int j) {
long to = ((c[find(i)] + 1) * (c[find(j)] + 1) - 1 + mod) % mod;
c[find(i)] = to;
p[find(j)] = find(i);
}
private static int find(int i) {
if(p[i] == i)return i;
else return p[i] = find(p[i]);
}
static class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
static class P implements Comparable<P>{
int i, s, o;
public P(int ii, int si){
i = ii;
s = si;
o = s;
}
@Override
public int compareTo(P b) {
return b.s - s;
}
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | d0debac0a60b9baf18daa1428faa5150 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import java.io.*;
import java.util.*;
public class E implements Runnable{
BufferedReader in;
StringTokenizer token = null;
public int nextInt(){
try{
while (token==null || !token.hasMoreElements())
token = new StringTokenizer(in.readLine());
return Integer.parseInt(token.nextToken());
} catch (Exception ex){
ex.printStackTrace(System.err);
return Integer.MIN_VALUE;
}
}
int[] p;
int mod = 1000000009;
int find(int x){
if (x != p[x])
p[x] = find(p[x]);
return p[x];
}
@Override
public void run() {
try{
in = new BufferedReader(new InputStreamReader(System.in));
int n = nextInt(), m = nextInt();
p = new int[n];
for (int i=0; i<n; ++i)
p[i] = i;
int res = 1;
for (int i=0; i<m; ++i){
int a = find(nextInt() - 1), b = find(nextInt() - 1);
if (a == b)
res = 2 * res; else
p[a] = b;
res = res % mod;
System.out.println(res - 1);
}
in.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
public static void main(String[] args) {
(new Thread(new E())).start();
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | c242cc07ef4c02dfa62ed34a614a266e | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class E {
static int[] P;
static int[] rank;
static int[] cycles;
public static void create(int x) {
P[x] = x;
rank[x] = 0;
}
public static void merge(int x, int y) {
int px = find(x);
int py = find(y);
if (rank[px] > rank[py]) {
P[py] = px;
cycles[px] += cycles[py];
} else {
P[px] = py;
cycles[py] += cycles[px];
}
if (rank[px] == rank[py])
rank[py] = rank[py] + 1;
}
public static int find(int x) {
if (x != P[x])
P[x] = find(P[x]);
return P[x];
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] S = in.readLine().split(" ");
int n = Integer.parseInt(S[0]);
int m = Integer.parseInt(S[1]);
P = new int[n];
rank = new int[n];
cycles = new int[n];
int mod = 1000000009;
for (int i = 0; i < n; i++)
create(i);
int sum = 1;
for (int i = 0; i < m; i++) {
S = in.readLine().split(" ");
int x = Integer.parseInt(S[0]) - 1;
int y = Integer.parseInt(S[1]) - 1;
if (find(x) == find(y)) {
sum = sum * 2;
sum %= mod;
} else
merge(x, y);
System.out.println((sum + mod - 1) % mod);
}
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | c0e8c9d52b228025228aeb0b0de584b3 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class E {
boolean showDebug = true;
class DisjointSet {
int[] parent, rank;
public DisjointSet(int size) {
parent = new int[size];
rank = new int[size];
for (int i=0; i<size; i++)
parent[i]=i;
}
int find(int x) {
if (parent[x]!=x)
parent[x]=find(parent[x]);
return parent[x];
}
boolean union(int x, int y) {
int parentX = find(x);
int parentY = find(y);
if (parentY==parentX) return false;
if (rank[parentX]>rank[parentY])
parent[parentY] = parentX;
else
parent[parentX] = parentY;
if (rank[parentX]==rank[parentY])
rank[parentY]++;
return true;
}
}
public void solve() throws Exception {
int n = nextInt(), m = nextInt();
DisjointSet ds = new DisjointSet(n);
int res = 0;
while (m-->0) {
if (!ds.union(nextInt()-1, nextInt()-1)) res+=res+1;
if (res>=1000000009) res-=1000000009;
println(res);
}
}
////////////////////////////////////////////////////////////////////////////
double EPS = 1e-7;
int INF = Integer.MAX_VALUE;
long INFL = Long.MAX_VALUE;
double INFD = Double.MAX_VALUE;
int[] dx = {0,1,0,-1};
int[] dy = {-1,0,1,0};
int[] dx8 = {0,1,1,1,0,-1,-1,-1};
int[] dy8 = {-1,-1,0,1,1,1,0,-1};
int[] knightMovesX = {1,2,2,1,-1,-2,-2,-1};
int[] knightMovesY = {-2,-1,1,2,2,1,-1,-2};
@SuppressWarnings("serial")
class IncMap extends HashMap<Object, Integer> {
boolean add(Object key, int amount) {
Integer i = get(key);
if (i!=null) {
put(key, i+amount);
return false;
} else {
put(key, amount);
return true;
}
}
boolean add(Object key) {
return add(key, 1);
}
}
int min(int... nums) {
int r = INF;
for (int i: nums)
if (i<r) r=i;
return r;
}
int max(int... nums) {
int r = -INF;
for (int i: nums)
if (i>r) r=i;
return r;
}
long minL(long... nums) {
long r = INFL;
for (long i: nums)
if (i<r) r=i;
return r;
}
long maxL(long... nums) {
long r = -INFL;
for (long i: nums)
if (i>r) r=i;
return r;
}
double minD(double... nums) {
double r = INFD;
for (double i: nums)
if (i<r) r=i;
return r;
}
double maxD(double... nums) {
double r = -INFD;
for (double i: nums)
if (i>r) r=i;
return r;
}
long sumArr(int[] arr) {
long res = 0;
for (int i: arr)
res+=i;
return res;
}
long sumArr(long[] arr) {
long res = 0;
for (long i: arr)
res+=i;
return res;
}
double sumArr(double[] arr) {
double res = 0;
for (double i: arr)
res+=i;
return res;
}
long partsFitCnt(long partSize, long wholeSize) {
return (partSize+wholeSize-1)/partSize;
}
boolean odd(long i) {
return (i&1)==1;
}
int digitSum(long i) {
i = abs(i);
int r = 0;
while (i>0) {
r+=i%10;
i/=10;
}
return r;
}
long digitProd(long i) {
if (i==0) return 0;
i = abs(i);
long r = 1;
while (i>0) {
r*=i%10;
i/=10;
}
return r;
}
long gcd (long a, long b) {
while (b>0) {
a%=b;
a^=b; b^=a; a^=b;
}
return a;
}
long lcm(long a, long b) {
return (a*b)/gcd(a,b);
}
double log_2 = log(2);
double log2(double i) {
return log(i)/log_2;
}
long binpow(int x, int n) {
long r = 1;
while (n>0) {
if ((n&1)!=0) r*=x;
x*=x;
n>>=1;
}
return r;
}
long fac(int i) {
if (i>20) throw new IllegalArgumentException();
return i<=1 ? 1:fac(i-1)*i;
}
double dist(double x, double y, double xx, double yy) {
return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
}
boolean isPalindrome(String s) {
for (int i=0; i<s.length()/2; i++)
if (s.charAt(i)!=s.charAt(s.length()-1-i)) return false;
return true;
}
int occurenciesCnt(String s, String pattern) {
int res = 0;
for (int i=0; i<s.length()-pattern.length()+1; i++)
if (s.substring(i, i+pattern.length()).equals(pattern)) res++;
return res;
}
int occurenciesCnt(String s, char pattern) {
int res = 0;
for (int i=0; i<s.length(); i++)
if (s.charAt(i)==pattern) res++;
return res;
}
int[] months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
boolean isLeapYear(int y) {
return y%4==0 && (y%400==0 || y%100!=0);
}
boolean isValidDate(int d, int m, int y) {
if (isLeapYear(y) && m==2 && d==29) return true;
return m>0 && m<=12 && d>0 && d<=months[d];
}
int[] nextDay(int d, int m, int y) {
if (d>=months[m])
if (m==2 && d==28 && isLeapYear(y)) d++;
else {d=1; m++;}
else
d++;
if (m==13) {d=1; m=1; y++;}
return new int[] {d,m,y};
}
String str(Object o) {
return o.toString();
}
long timer = System.currentTimeMillis();
void startTimer() {
timer = System.currentTimeMillis();
}
void stopTimer() {
System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
}
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
String nextLine() throws IOException {
return in.readLine();
}
char nextChar() throws IOException {
int c = 0;
while (c<=' ') c=in.read();
return (char)c;
}
String nextWord() throws IOException {
StringBuilder sb = new StringBuilder();
int c = 0;
while (c<=' ') c=in.read();
while (c>' ') {
sb.append((char)c);
c = in.read();
}
return sb.toString();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextWord());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextWord());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextWord());
}
int[] nextArr(int size) throws NumberFormatException, IOException {
int[] arr = new int[size];
for (int i=0; i<size; i++)
arr[i] = nextInt();
return arr;
}
long[] nextArrL(int size) throws NumberFormatException, IOException {
long[] arr = new long[size];
for (int i=0; i<size; i++)
arr[i] = nextLong();
return arr;
}
double[] nextArrD(int size) throws NumberFormatException, IOException {
double[] arr = new double[size];
for (int i=0; i<size; i++)
arr[i] = nextDouble();
return arr;
}
String[] nextArrS(int size) throws NumberFormatException, IOException {
String[] arr = new String[size];
for (int i=0; i<size; i++)
arr[i] = nextWord();
return arr;
}
char[][] nextArrCh(int rows, int columns) throws IOException {
char[][] arr = new char[rows][columns];
for (int i=0; i<rows; i++)
for (int j=0; j<columns; j++)
arr[i][j] = nextChar();
return arr;
}
void print(Object o) throws IOException {
out.write(o.toString());
}
void println(Object o) throws IOException {
out.write(o.toString());
out.newLine();
}
void print(Object... o) throws IOException {
for (int i=0; i<o.length; i++) {
if (i!=0) out.write(' ');
out.write(o[i].toString());
}
}
void println(Object... o) throws IOException {
print(o);
out.newLine();
}
void printn(Object o, int n) throws IOException {
String s = o.toString();
for (int i=0; i<n; i++) {
out.write(s);
if (i!=n-1) out.write(' ');
}
}
void printnln(Object o, int n) throws IOException {
printn(o, n);
out.newLine();
}
void printArr(int[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Integer.toString(arr[i]));
}
}
void printArr(long[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Long.toString(arr[i]));
}
}
void printArr(double[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Double.toString(arr[i]));
}
}
void printArr(String[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(arr[i]);
}
}
void printArr(char[] arr) throws IOException {
for (char c: arr) out.write(c);
}
void printlnArr(int[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(long[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(double[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(String[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(char[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void debug(Object... o) {
if (showDebug) System.err.println(Arrays.deepToString(o));
}
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.US);
new E().solve();
out.flush();
out.close(); in.close();
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | 42696321359ccd9f2bb4d072423ed1f8 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class E {
boolean showDebug = true;
class DisjointSet {
int[] parent, rank;
public DisjointSet(int size) {
parent = new int[size];
rank = new int[size];
for (int i=0; i<size; i++)
parent[i]=i;
}
public int find(int x) {
if (parent[x]!=x)
parent[x]=find(parent[x]);
return parent[x];
}
public void union(int x, int y) {
int parentX = find(x);
int parentY = find(y);
if (rank[parentX]>rank[parentY])
parent[parentY] = parentX;
else
parent[parentX] = parentY;
if (rank[parentX]==rank[parentY])
rank[parentY]++;
}
}
public void solve() throws Exception {
int n = nextInt(), m = nextInt();
DisjointSet ds = new DisjointSet(n);
int res = 0;
while (m-->0) {
int a=nextInt()-1, b=nextInt()-1;
if (ds.find(a)==ds.find(b)) res+=res+1;
else ds.union(a, b);
if (res>=1000000009) res-=1000000009;
println(res);
}
}
////////////////////////////////////////////////////////////////////////////
double EPS = 1e-7;
int INF = Integer.MAX_VALUE;
long INFL = Long.MAX_VALUE;
double INFD = Double.MAX_VALUE;
int[] dx = {0,1,0,-1};
int[] dy = {-1,0,1,0};
int[] dx8 = {0,1,1,1,0,-1,-1,-1};
int[] dy8 = {-1,-1,0,1,1,1,0,-1};
int[] knightMovesX = {1,2,2,1,-1,-2,-2,-1};
int[] knightMovesY = {-2,-1,1,2,2,1,-1,-2};
@SuppressWarnings("serial")
class IncMap extends HashMap<Object, Integer> {
boolean add(Object key, int amount) {
Integer i = get(key);
if (i!=null) {
put(key, i+amount);
return false;
} else {
put(key, amount);
return true;
}
}
boolean add(Object key) {
return add(key, 1);
}
}
int min(int... nums) {
int r = INF;
for (int i: nums)
if (i<r) r=i;
return r;
}
int max(int... nums) {
int r = -INF;
for (int i: nums)
if (i>r) r=i;
return r;
}
long minL(long... nums) {
long r = INFL;
for (long i: nums)
if (i<r) r=i;
return r;
}
long maxL(long... nums) {
long r = -INFL;
for (long i: nums)
if (i>r) r=i;
return r;
}
double minD(double... nums) {
double r = INFD;
for (double i: nums)
if (i<r) r=i;
return r;
}
double maxD(double... nums) {
double r = -INFD;
for (double i: nums)
if (i>r) r=i;
return r;
}
long sumArr(int[] arr) {
long res = 0;
for (int i: arr)
res+=i;
return res;
}
long sumArr(long[] arr) {
long res = 0;
for (long i: arr)
res+=i;
return res;
}
double sumArr(double[] arr) {
double res = 0;
for (double i: arr)
res+=i;
return res;
}
long partsFitCnt(long partSize, long wholeSize) {
return (partSize+wholeSize-1)/partSize;
}
boolean odd(long i) {
return (i&1)==1;
}
int digitSum(long i) {
i = abs(i);
int r = 0;
while (i>0) {
r+=i%10;
i/=10;
}
return r;
}
long digitProd(long i) {
if (i==0) return 0;
i = abs(i);
long r = 1;
while (i>0) {
r*=i%10;
i/=10;
}
return r;
}
long gcd (long a, long b) {
while (b>0) {
a%=b;
a^=b; b^=a; a^=b;
}
return a;
}
long lcm(long a, long b) {
return (a*b)/gcd(a,b);
}
double log_2 = log(2);
double log2(double i) {
return log(i)/log_2;
}
long binpow(int x, int n) {
long r = 1;
while (n>0) {
if ((n&1)!=0) r*=x;
x*=x;
n>>=1;
}
return r;
}
long fac(int i) {
if (i>20) throw new IllegalArgumentException();
return i<=1 ? 1:fac(i-1)*i;
}
double dist(double x, double y, double xx, double yy) {
return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
}
boolean isPalindrome(String s) {
for (int i=0; i<s.length()/2; i++)
if (s.charAt(i)!=s.charAt(s.length()-1-i)) return false;
return true;
}
int occurenciesCnt(String s, String pattern) {
int res = 0;
for (int i=0; i<s.length()-pattern.length()+1; i++)
if (s.substring(i, i+pattern.length()).equals(pattern)) res++;
return res;
}
int occurenciesCnt(String s, char pattern) {
int res = 0;
for (int i=0; i<s.length(); i++)
if (s.charAt(i)==pattern) res++;
return res;
}
int[] months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
boolean isLeapYear(int y) {
return y%4==0 && (y%400==0 || y%100!=0);
}
boolean isValidDate(int d, int m, int y) {
if (isLeapYear(y) && m==2 && d==29) return true;
return m>0 && m<=12 && d>0 && d<=months[d];
}
int[] nextDay(int d, int m, int y) {
if (d>=months[m])
if (m==2 && d==28 && isLeapYear(y)) d++;
else {d=1; m++;}
else
d++;
if (m==13) {d=1; m=1; y++;}
return new int[] {d,m,y};
}
String str(Object o) {
return o.toString();
}
long timer = System.currentTimeMillis();
void startTimer() {
timer = System.currentTimeMillis();
}
void stopTimer() {
System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
}
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
String nextLine() throws IOException {
return in.readLine();
}
char nextChar() throws IOException {
int c = 0;
while (c<=' ') c=in.read();
return (char)c;
}
String nextWord() throws IOException {
StringBuilder sb = new StringBuilder();
int c = 0;
while (c<=' ') c=in.read();
while (c>' ') {
sb.append((char)c);
c = in.read();
}
return sb.toString();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextWord());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextWord());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextWord());
}
int[] nextArr(int size) throws NumberFormatException, IOException {
int[] arr = new int[size];
for (int i=0; i<size; i++)
arr[i] = nextInt();
return arr;
}
long[] nextArrL(int size) throws NumberFormatException, IOException {
long[] arr = new long[size];
for (int i=0; i<size; i++)
arr[i] = nextLong();
return arr;
}
double[] nextArrD(int size) throws NumberFormatException, IOException {
double[] arr = new double[size];
for (int i=0; i<size; i++)
arr[i] = nextDouble();
return arr;
}
String[] nextArrS(int size) throws NumberFormatException, IOException {
String[] arr = new String[size];
for (int i=0; i<size; i++)
arr[i] = nextWord();
return arr;
}
char[][] nextArrCh(int rows, int columns) throws IOException {
char[][] arr = new char[rows][columns];
for (int i=0; i<rows; i++)
for (int j=0; j<columns; j++)
arr[i][j] = nextChar();
return arr;
}
void print(Object o) throws IOException {
out.write(o.toString());
}
void println(Object o) throws IOException {
out.write(o.toString());
out.newLine();
}
void print(Object... o) throws IOException {
for (int i=0; i<o.length; i++) {
if (i!=0) out.write(' ');
out.write(o[i].toString());
}
}
void println(Object... o) throws IOException {
print(o);
out.newLine();
}
void printn(Object o, int n) throws IOException {
String s = o.toString();
for (int i=0; i<n; i++) {
out.write(s);
if (i!=n-1) out.write(' ');
}
}
void printnln(Object o, int n) throws IOException {
printn(o, n);
out.newLine();
}
void printArr(int[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Integer.toString(arr[i]));
}
}
void printArr(long[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Long.toString(arr[i]));
}
}
void printArr(double[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Double.toString(arr[i]));
}
}
void printArr(String[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(arr[i]);
}
}
void printArr(char[] arr) throws IOException {
for (char c: arr) out.write(c);
}
void printlnArr(int[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(long[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(double[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(String[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(char[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void debug(Object... o) {
if (showDebug) System.err.println(Arrays.deepToString(o));
}
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.US);
new E().solve();
out.flush();
out.close(); in.close();
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | 779f32b0c38c9836fca26494605ef9e4 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class E {
boolean showDebug = true;
class DisjointSet {
int[] parent, rank;
public DisjointSet(int size) {
parent = new int[size];
rank = new int[size];
for (int i=0; i<size; i++)
parent[i]=i;
}
public int find(int x) {
if (parent[x]!=x)
parent[x]=find(parent[x]);
return parent[x];
}
public void union(int x, int y) {
int parentX = find(x);
int parentY = find(y);
if (rank[parentX]>rank[parentY])
parent[parentY] = parentX;
else
parent[parentX] = parentY;
if (rank[parentX]==rank[parentY])
rank[parentY]++;
}
}
public void solve() throws Exception {
int n = nextInt(), m = nextInt();
DisjointSet ds = new DisjointSet(n);
int res = 0;
while (m-->0) {
int a=nextInt()-1, b=nextInt()-1;
if (ds.find(a)==ds.find(b)) res+=res+1;
if (res>=1000000009) res-=1000000009;
else ds.union(a, b);
println(res);
}
}
////////////////////////////////////////////////////////////////////////////
double EPS = 1e-7;
int INF = Integer.MAX_VALUE;
long INFL = Long.MAX_VALUE;
double INFD = Double.MAX_VALUE;
int[] dx = {0,1,0,-1};
int[] dy = {-1,0,1,0};
int[] dx8 = {0,1,1,1,0,-1,-1,-1};
int[] dy8 = {-1,-1,0,1,1,1,0,-1};
int[] knightMovesX = {1,2,2,1,-1,-2,-2,-1};
int[] knightMovesY = {-2,-1,1,2,2,1,-1,-2};
@SuppressWarnings("serial")
class IncMap extends HashMap<Object, Integer> {
boolean add(Object key, int amount) {
Integer i = get(key);
if (i!=null) {
put(key, i+amount);
return false;
} else {
put(key, amount);
return true;
}
}
boolean add(Object key) {
return add(key, 1);
}
}
int min(int... nums) {
int r = INF;
for (int i: nums)
if (i<r) r=i;
return r;
}
int max(int... nums) {
int r = -INF;
for (int i: nums)
if (i>r) r=i;
return r;
}
long minL(long... nums) {
long r = INFL;
for (long i: nums)
if (i<r) r=i;
return r;
}
long maxL(long... nums) {
long r = -INFL;
for (long i: nums)
if (i>r) r=i;
return r;
}
double minD(double... nums) {
double r = INFD;
for (double i: nums)
if (i<r) r=i;
return r;
}
double maxD(double... nums) {
double r = -INFD;
for (double i: nums)
if (i>r) r=i;
return r;
}
long sumArr(int[] arr) {
long res = 0;
for (int i: arr)
res+=i;
return res;
}
long sumArr(long[] arr) {
long res = 0;
for (long i: arr)
res+=i;
return res;
}
double sumArr(double[] arr) {
double res = 0;
for (double i: arr)
res+=i;
return res;
}
long partsFitCnt(long partSize, long wholeSize) {
return (partSize+wholeSize-1)/partSize;
}
boolean odd(long i) {
return (i&1)==1;
}
int digitSum(long i) {
i = abs(i);
int r = 0;
while (i>0) {
r+=i%10;
i/=10;
}
return r;
}
long digitProd(long i) {
if (i==0) return 0;
i = abs(i);
long r = 1;
while (i>0) {
r*=i%10;
i/=10;
}
return r;
}
long gcd (long a, long b) {
while (b>0) {
a%=b;
a^=b; b^=a; a^=b;
}
return a;
}
long lcm(long a, long b) {
return (a*b)/gcd(a,b);
}
double log_2 = log(2);
double log2(double i) {
return log(i)/log_2;
}
long binpow(int x, int n) {
long r = 1;
while (n>0) {
if ((n&1)!=0) r*=x;
x*=x;
n>>=1;
}
return r;
}
long fac(int i) {
if (i>20) throw new IllegalArgumentException();
return i<=1 ? 1:fac(i-1)*i;
}
double dist(double x, double y, double xx, double yy) {
return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
}
boolean isPalindrome(String s) {
for (int i=0; i<s.length()/2; i++)
if (s.charAt(i)!=s.charAt(s.length()-1-i)) return false;
return true;
}
int occurenciesCnt(String s, String pattern) {
int res = 0;
for (int i=0; i<s.length()-pattern.length()+1; i++)
if (s.substring(i, i+pattern.length()).equals(pattern)) res++;
return res;
}
int occurenciesCnt(String s, char pattern) {
int res = 0;
for (int i=0; i<s.length(); i++)
if (s.charAt(i)==pattern) res++;
return res;
}
int[] months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
boolean isLeapYear(int y) {
return y%4==0 && (y%400==0 || y%100!=0);
}
boolean isValidDate(int d, int m, int y) {
if (isLeapYear(y) && m==2 && d==29) return true;
return m>0 && m<=12 && d>0 && d<=months[d];
}
int[] nextDay(int d, int m, int y) {
if (d>=months[m])
if (m==2 && d==28 && isLeapYear(y)) d++;
else {d=1; m++;}
else
d++;
if (m==13) {d=1; m=1; y++;}
return new int[] {d,m,y};
}
String str(Object o) {
return o.toString();
}
long timer = System.currentTimeMillis();
void startTimer() {
timer = System.currentTimeMillis();
}
void stopTimer() {
System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
}
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
String nextLine() throws IOException {
return in.readLine();
}
char nextChar() throws IOException {
int c = 0;
while (c<=' ') c=in.read();
return (char)c;
}
String nextWord() throws IOException {
StringBuilder sb = new StringBuilder();
int c = 0;
while (c<=' ') c=in.read();
while (c>' ') {
sb.append((char)c);
c = in.read();
}
return sb.toString();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextWord());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextWord());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextWord());
}
int[] nextArr(int size) throws NumberFormatException, IOException {
int[] arr = new int[size];
for (int i=0; i<size; i++)
arr[i] = nextInt();
return arr;
}
long[] nextArrL(int size) throws NumberFormatException, IOException {
long[] arr = new long[size];
for (int i=0; i<size; i++)
arr[i] = nextLong();
return arr;
}
double[] nextArrD(int size) throws NumberFormatException, IOException {
double[] arr = new double[size];
for (int i=0; i<size; i++)
arr[i] = nextDouble();
return arr;
}
String[] nextArrS(int size) throws NumberFormatException, IOException {
String[] arr = new String[size];
for (int i=0; i<size; i++)
arr[i] = nextWord();
return arr;
}
char[][] nextArrCh(int rows, int columns) throws IOException {
char[][] arr = new char[rows][columns];
for (int i=0; i<rows; i++)
for (int j=0; j<columns; j++)
arr[i][j] = nextChar();
return arr;
}
void print(Object o) throws IOException {
out.write(o.toString());
}
void println(Object o) throws IOException {
out.write(o.toString());
out.newLine();
}
void print(Object... o) throws IOException {
for (int i=0; i<o.length; i++) {
if (i!=0) out.write(' ');
out.write(o[i].toString());
}
}
void println(Object... o) throws IOException {
print(o);
out.newLine();
}
void printn(Object o, int n) throws IOException {
String s = o.toString();
for (int i=0; i<n; i++) {
out.write(s);
if (i!=n-1) out.write(' ');
}
}
void printnln(Object o, int n) throws IOException {
printn(o, n);
out.newLine();
}
void printArr(int[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Integer.toString(arr[i]));
}
}
void printArr(long[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Long.toString(arr[i]));
}
}
void printArr(double[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(Double.toString(arr[i]));
}
}
void printArr(String[] arr) throws IOException {
for (int i=0; i<arr.length; i++) {
if (i!=0) out.write(' ');
out.write(arr[i]);
}
}
void printArr(char[] arr) throws IOException {
for (char c: arr) out.write(c);
}
void printlnArr(int[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(long[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(double[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(String[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void printlnArr(char[] arr) throws IOException {
printArr(arr);
out.newLine();
}
void debug(Object... o) {
if (showDebug) System.err.println(Arrays.deepToString(o));
}
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.US);
new E().solve();
out.flush();
out.close(); in.close();
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | ef54c781e3ea6098dbeafa9bbea79774 | train_000.jsonl | 1308582000 | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.Track is the route with the following properties: The route is closed, that is, it begins and ends in one and the same junction. The route contains at least one road. The route doesn't go on one road more than once, however it can visit any junction any number of times. Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.Two ski bases are considered different if they consist of different road sets.After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* Author -
* User: kansal
* Date: 6/16/11
* Time: 8:26 PM
*/
public class E {
public static void main(String[] args) {
reader = new BufferedReader(new InputStreamReader(System.in));
int n = nextInt(), m = nextInt();
int[] root = new int[n+1];
for(int i = 1; i <= n; ++i) root[i] = i;
int res = 1;
for(int i = 0; i < m; ++i) {
int a = nextInt(), b = nextInt();
int pa = getRoot(a, root), pb = getRoot(b, root);
if (pa == pb) {
res = (res << 1) % MOD;
}
else {
merge(pa, pb, root);
}
System.out.println(res-1);
}
}
private static void merge(int pa, int pb, int[] root) {
if (pa > pb) {
int t = pa;
pa = pb;
pb = t;
}
root[pa] = pb;
}
static final int MOD = 1000000009;
public static int getRoot(int x, int[] root) {
if (root[x] == x) {
return x;
}
return root[x] = getRoot(root[x], root);
}
public static BufferedReader reader;
public static StringTokenizer tokenizer = null;
static String nextToken() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
static public int nextInt() {
return Integer.parseInt(nextToken());
}
static public long nextLong() {
return Long.parseLong(nextToken());
}
static public String next() {
return nextToken();
}
static public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
| Java | ["3 4\n1 3\n2 3\n1 2\n1 2"] | 2 seconds | ["0\n0\n1\n3"] | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can choose a subset of roads in three ways: In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1. | Java 6 | standard input | [
"data structures",
"dsu",
"graphs"
] | f80dc7b12479551b857408f4c29c276b | The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions. | 2,300 | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9). | standard output | |
PASSED | 65c7dec889d2d61ee2effbb31953c4cd | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class E {
public StringBuilder interleave(int n, char first, char second) throws Exception {
StringBuilder sb = new StringBuilder("");
for(int i = 0; i < n; i++) {
sb.append(first);
sb.append(second);
}
return sb;
}
public StringBuilder all(int n, char first) throws Exception {
StringBuilder sb = new StringBuilder("");
for(int i = 0; i < n; i++) {
sb.append(first);
}
return sb;
}
public void realMain() throws Exception {
BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);
String in = fin.readLine();
String[] ar = in.split(" ");
int n = Integer.parseInt(ar[0]);
in = fin.readLine();
String s = in;
in = fin.readLine();
String t = in;
char p1 = ' ', p2 = ' ', p3 = ' ';
p1 = s.charAt(0);
if(s.charAt(1) != p1) {
p2 = s.charAt(1);
}
if(t.charAt(0) != p1) {
if(p2 == ' ') {
p2 = t.charAt(0);
} else if(t.charAt(0) != p2) {
p3 = t.charAt(0);
}
}
if(t.charAt(1) != p1) {
if(p2 == ' ') {
p2 = t.charAt(1);
} else if(p3 == ' ' && t.charAt(1) != p2) {
p3 = t.charAt(1);
}
}
System.out.println("YES");
char first, second, third;
if(p2 == ' ') {
first = p1;
if(first == 'a') {
second = 'b';
third = 'c';
} else if(first == 'b') {
second = 'a';
third = 'c';
} else {
second = 'a';
third = 'b';
}
System.out.print( interleave(n, first, second) );
System.out.println( all(n, third) );
return;
}
boolean isfirstdouble = (s.charAt(0) == s.charAt(1));
boolean isseconddouble = (t.charAt(0) == t.charAt(1));
//System.out.println(isfirstdouble + " " + isseconddouble);
if(isfirstdouble && isseconddouble) {
first = p1;
second = p2;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(interleave(n, first, second));
System.out.println(all(n, third));
return;
}
if(isfirstdouble) {
first = p1;
if(t.charAt(0) == p1) {
second = p2;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(all(n, second));
System.out.println(interleave(n, first, third));
return;
}
if(t.charAt(1) == p1) {
second = p2;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(interleave(n, first, third));
System.out.println(all(n, second));
return;
}
second = p2;
third = p3;
System.out.print(all(n, third));
System.out.println(interleave(n, first, second));
return;
}
if(isseconddouble) {
if(p1 == t.charAt(0)) {
first = p1;
second = p2;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(all(n, second));
System.out.println(interleave(n, first, third));
return;
}
if(p2 == t.charAt(0)) {
first = p2;
second = p1;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(interleave(n, first, third));
System.out.println(all(n, second));
return;
}
first = p1;
second = p2;
third = p3;
System.out.print(interleave(n, first, third));
System.out.println(all(n, second));
return;
}
if(p3 == ' ') {
first = p1;
second = p2;
third = ' ';
if(first == 'a' && second == 'b') {
third = 'c';
}
if(first == 'a' && second == 'c') {
third = 'b';
}
if(first == 'b' && second == 'a') {
third = 'c';
}
if(first == 'b' && second == 'c') {
third = 'a';
}
if(first == 'c' && second == 'a') {
third = 'b';
}
if(first == 'c' && second == 'b') {
third = 'a';
}
System.out.print(interleave(n, first, third));
System.out.println(all(n, second));
return;
}
if(s.charAt(0) == t.charAt(0)) {
first = p1;
second = p2;
third = p3;
System.out.print(all(n, third));
System.out.print(all(n, second));
System.out.println(all(n, first));
return;
}
if(s.charAt(1) == t.charAt(1)) {
first = p2;
second = p1;
third = p3;
System.out.print(all(n, first));
System.out.print(all(n, second));
System.out.println(all(n, third));
return;
}
if(s.charAt(0) == t.charAt(1)) {
first = p1;
second = p2;
third = p3;
System.out.print(all(n, second));
System.out.print(all(n, first));
System.out.println(all(n, third));
return;
}
first = p2;
second = p1;
third = p3;
System.out.print(all(n, third));
System.out.print(all(n, first));
System.out.println(all(n, second));
return;
}
public static void main(String[] args) throws Exception {
E e = new E();
e.realMain();
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | fdc25c6c4726bc19753fcf03e835f861 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Codeforces {
static boolean isp[] = new boolean[1000001];
public static void main(String[] args) throws IOException{
Scanner s = new Scanner(System.in);
StringBuffer sb = new StringBuffer();
int n = s.nextInt();
String a = s.next();
String b = s.next();
char str[] = new char[3];
for(int i = 0; i < 3; i++) {
str[0] = (char)('a' + i);
for(int j = 0; j < 3; j++) {
if(j != i) {
str[1] = (char)('a' + j);
for(int k = 0; k < 3; k++) {
if(k != i && k != j) {
str[2] = (char)('a' + k);
boolean bl = fun(str, n, a, b);
if(bl) return;
}
}
}
}
}
System.out.println("NO");
}
private static boolean fun(char sr[], int n, String a, String b) {
char x = a.charAt(0);
char y = a.charAt(1);
char p = b.charAt(0);
char q = b.charAt(1);
char str[] = new char[3 * n];
for(int i = 0; i < n; i++) {
str[3 * i] = sr[0];
str[3 * i + 1] = sr[1];
str[3 * i + 2] = sr[2];
}
boolean bol = true;
for(int i = 1; i < 3 * n; i++) {
if(str[i] == y && str[i - 1] == x) {
bol = false;
break;
}
if(str[i] == q && str[i - 1] == p) {
bol = false;
break;
}
}
if(bol) {
System.out.println("YES");
System.out.println(str);
return true;
}
bol = true;
char str1[] = new char[3 * n];
for(int i = 0; i < n; i++) {
str1[i * 1] = sr[0];
str1[i + n] = sr[1];
str1[i + (2 * n)] = sr[2];
}
for(int i = 1; i < 3 * n; i++) {
if(str1[i] == y && str1[i - 1] == x) {
bol = false;
break;
}
if(str1[i] == q && str1[i - 1] == p) {
bol = false;
break;
}
}
if(bol) {
System.out.println("YES");
System.out.println(str1);
return true;
}
return false;
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 9633f8ce23fea0e743c6c3bd89b9583d | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Solver {
public static void main(String[] args) throws IOException {
new Solver().read();
}
static Scanner in = new Scanner(System.in);
static PrintWriter out;
static int n;
void read() throws IOException {
out = new PrintWriter(System.out);
int test = 1;
while (test-- > 0) {
n = in.nextInt();
hs = new HashSet<>();
hs.add(in.next());
hs.add(in.next());
solve();
}
}
static int book[];
static HashSet<String> hs;
void rec(int ind){
if(ind == 3){
String perm = "";
for (int i = 0; i < 3; i++) {
perm+=((char)('a' + book[i]));
}
HashSet<String>ch = new HashSet<>();
if(n == 1){
ch.add(perm.substring(0,2));
ch.add(perm.substring(1,3));
ch.retainAll(hs);
if(ch.size() == 0){
System.out.println("YES");
System.out.print(perm);
System.exit(0);
}
}else{
ch.add(perm.charAt(0) + "" + perm.charAt(0));
ch.add(perm.charAt(1) + "" + perm.charAt(1));
ch.add(perm.charAt(2) + "" + perm.charAt(2));
ch.add(perm.substring(0,2));
ch.add(perm.substring(1,3));
ch.retainAll(hs);
if(ch.size() == 0){
System.out.println("YES");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
System.out.print(perm.charAt(i));
}
}
System.exit(0);
}
ch.clear();
ch.add(perm.substring(0,2));
ch.add(perm.substring(1,3));
ch.add(perm.charAt(2) + "" + perm.charAt(0));
ch.retainAll(hs);
if(ch.size() == 0){
System.out.println("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(perm.charAt(j));
}
}
System.exit(0);
}
}
return;
}
for (int i = 0; i < 3; i++) {
if(ind == 0)book[ind] = i;
else{
if(book[ind - 1] == i)continue;
if(ind == 2)if(book[ind - 2] == i)continue;
book[ind] = i;
}
rec(ind+1);
}
}
void solve() throws IOException {
book = new int[3];
rec(0);
System.out.println("NO");
}
}
class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() throws IOException {
while (!st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | cade708d84fb485ebb0420ddade4513b | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import javax.print.attribute.standard.PrinterMessageFromOperator;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
new Main().run();}
// int[] h,ne,to,wt;
// int ct = 0;
// int n;
// void graph(int n,int m){
// h = new int[n];
// Arrays.fill(h,-1);
//// sccno = new int[n];
//// dfn = new int[n];
//// low = new int[n];
//// iscut = new boolean[n];
// ne = new int[2*m];
// to = new int[2*m];
// wt = new int[2*m];
// ct = 0;
// }
// void add(int u,int v,int w){
// to[ct] = v;
// ne[ct] = h[u];
// wt[ct] = w;
// h[u] = ct++;
// }
//
// int color[],dfn[],low[],stack[] = new int[1000000],cnt[];
// int sccno[];
// boolean iscut[];
// int time = 0,top = 0;
// int scc_cnt = 0;
//
// // 有向图的强连通分量
// void tarjan(int u) {
// low[u] = dfn[u]= ++time;
// stack[top++] = u;
// for(int i=h[u];i!=-1;i=ne[i]) {
// int v = to[i];
// if(dfn[v]==0) {
// tarjan(v);
// low[u]=Math.min(low[u],low[v]);
// } else if(sccno[v]==0) {
// // dfn>0 but sccno==0, means it's in current stack
// low[u]=Math.min(low[u],low[v]);
// }
// }
//
// if(dfn[u]==low[u]) {
// sccno[u] = ++scc_cnt;
// while(stack[top-1]!=u) {
// sccno[stack[top-1]] = scc_cnt;
// --top;
// }
// --top;
// }
// }
//
// //缩点, topology sort
// int[] h1,to1,ne1;
// int ct1 = 0;
// void point(){
// for(int i=0;i<n;i++) {
// if(dfn[i]==0) tarjan(i);//有可能图不连通,所以要循环判断。
// }
// // 入度
// int du[] = new int[scc_cnt+1];
// h1 = new int[scc_cnt+1];
// Arrays.fill(h1, -1);
// to1 = new int[scc_cnt*scc_cnt];
// ne1 = new int[scc_cnt*scc_cnt];
// // scc_cnt 个点
//
// for(int i=1;i<=n;i++) {
// for(int j=h[i]; j!=-1; j=ne[j]) {
// int y = to[j];
// if(sccno[i] != sccno[y]) {
// // add(sccno[i],sccno[y]); // 建新图
// to1[ct1] = sccno[y];
// ne1[ct1] = h[sccno[i]];
// h[sccno[i]] = ct1++;
// du[sccno[y]]++; //存入度
// }
// }
// }
//
// int q[] = new int[100000];
// int end = 0;
// int st = 0;
// for(int i=1;i<=scc_cnt;++i){
// if(du[i]==0){
// q[end++] = i;
// }
// }
//
// int dp[] = new int[scc_cnt+1];
// while(st<end){
// int cur = q[st++];
// for(int i=h1[cur];i!=-1;i=ne1[i]){
// int y = to[i];
// // dp[y] += dp[cur];
// if(--du[y]==0){
// q[end++] = y;
// }
// }
// }
// }
//
//
//
//
// int fa[];
// int faw[];
//
// int dep = -1;
// int pt = 0;
// void go(int rt,int f,int dd){
//
// int p = 0;
// stk[p] = rt;
// lk[p] = 0;
// fk[p] = f;p++;
// while(p>0) {
// int cur = stk[p - 1];
// int fp = fk[p - 1];
// int ll = lk[p - 1];
// p--;
//
//
// if (ll > dep) {
// dep = ll;
// pt = cur;
// }
// for (int i = h[cur]; i != -1; i = ne[i]) {
// int v = to[i];
// if (fp == v) continue;
//
// stk[p] = v;
// lk[p] = ll + wt[i];
// fk[p] = cur;
// p++;
// }
// }
// }
// int pt1 = -1;
// void go1(int rt,int f,int dd){
//
// int p = 0;
// stk[p] = rt;
// lk[p] = 0;
// fk[p] = f;p++;
// while(p>0) {
// int cur = stk[p - 1];
// int fp = fk[p - 1];
// int ll = lk[p - 1];
// p--;
//
//
// if (ll > dep) {
// dep = ll;
// pt1 = cur;
// }
//
// fa[cur] = fp;
// for (int i = h[cur]; i != -1; i = ne[i]) {
// int v = to[i];
// if (v == fp) continue;
// faw[v] = wt[i];
// stk[p] = v;
// lk[p] = ll + wt[i];
// fk[p] = cur;
// p++;
// }
// }
// }
//
// int r = 0;
// int stk[] = new int[301];
// int fk[] = new int[301];
// int lk[] = new int[301];
// void ddfs(int rt,int t1,int t2,int t3,int l){
//
//
// int p = 0;
// stk[p] = rt;
// lk[p] = 0;
// fk[p] = t3;p++;
// while(p>0){
// int cur = stk[p-1];
// int fp = fk[p-1];
// int ll = lk[p-1];
// p--;
// r = Math.max(r,ll);
// for(int i=h[cur];i!=-1;i=ne[i]){
// int v = to[i];
// if(v==t1||v==t2||v==fp) continue;
// stk[p] = v;
// lk[p] = ll+wt[i];
// fk[p] = cur;p++;
// }
// }
//
//
//
// }
static long mul(long a, long b, long p)
{
long res=0,base=a;
while(b>0)
{
if((b&1L)>0)
res=(res+base)%p;
base=(base+base)%p;
b>>=1;
}
return res;
}
static long mod_pow(long k,long n,long p){
long res = 1L;
long temp = k;
while(n!=0L){
if((n&1L)==1L){
res = (res*temp)%p;
}
temp = (temp*temp)%p;
n = n>>1L;
}
return res%p;
}
int ct = 0;
int f[] =new int[200001];
int b[] =new int[200001];
int str[] =new int[200001];
void go(int rt,List<Integer> g[]){
str[ct] = rt;
f[rt] = ct;
for(int cd:g[rt]){
ct++;
go(cd,g);
}
b[rt] = ct;
}
int add =0;
void sort(long a[]) {
Random rd = new Random();
for (int i = 1; i < a.length; ++i) {
int p = rd.nextInt(i); long x = a[p]; a[p] = a[i]; a[i] = x;
}
Arrays.sort(a);
}
void dfs(int from,int k){
}
void add(int u,int v){
to[ct] = u;
ne[ct] = h[v];
h[v] = ct++;
}
int r =0;
void dfs1(int c,int ff){
clr[c][aa[c]]++;
for(int j=h[c];j!=-1;j=ne[j]){
if(to[j]==ff) continue;
dfs1(to[j],c);
clr[c][1] += clr[to[j]][1];
clr[c][2] += clr[to[j]][2];
if(clr[to[j]][1]==s1&&clr[to[j]][2]==0||clr[to[j]][2]==s2&&clr[to[j]][1]==0){
r++;
}
}
}
int[] h,ne,to,fa;
int clr[][];
int aa[];
int s1 = 0;
int s2 = 0;
boolean f(int n){
int c = 0;
while(n>0){
c += n%10;
n /=10;
}
return (c&3)==0;
}
int[][] next(String s){
int len = s.length();
int ne[][] = new int[len+1][26];
Arrays.fill(ne[len], -1);
for(int i=len-1;i>=0;--i){
ne[i] = ne[i+1].clone();
ne[i][s.charAt(i)-'a'] = i+1;
}
return ne;
}
void sort(int a[]){
Random rd =new Random();
for(int i=1;i<a.length;++i){
int id = rd.nextInt(i);
int t = a[id];
a[id] = a[i];
a[i] = t;
}
}
boolean same(String s){
return s.charAt(0)==s.charAt(1);
}
boolean next_perm(int[] a){
int len = a.length;
for(int i=len-2,j = 0;i>=0;--i){
if(a[i]<a[i+1]){
j = len-1;
for(;a[j]<=a[i];--j);
int p = a[j];
a[j] = a[i];
a[i] = p;
j = i+1;
for(int ed = len-1;j<ed;--ed) {
p = a[ed];
a[ed] = a[j];
a[j++] = p;
}
return true;
}
}
return false;
}
void print1(int c[],int n){
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;++i){
for(int j=0;j<3;++j) {
sb.appendCodePoint(c[j]+'a');
}
}
println(sb);
}
void print2(int c[],int n){
StringBuilder sb = new StringBuilder();
for(int j=0;j<3;++j) {
for (int i = 0; i < n; ++i) {
sb.appendCodePoint(c[j]+'a');
}
}
println(sb);
}
void solve() {
int n = ni();
String a = ns();
String b = ns();
println("YES");
int cc[] = {0,1,2};
do{
if(same(a)||same(b)) {
boolean ok = true;
for (int i = 0; i < 3; ++i) {
StringBuilder sb = new StringBuilder();
sb.appendCodePoint(cc[i] + 'a');
sb.appendCodePoint(cc[(i + 1) % 3] + 'a');
String cur = sb.toString();
if (cur.equals(a) || cur.equals(b)) {
ok = false;
break;
}
}
if (ok) {
// has same case;
print1(cc, n);
return;
}
}else {
// ugly case
boolean ok = true;
for (int i = 0; i < 2; ++i) {
StringBuilder sb = new StringBuilder();
sb.appendCodePoint(cc[i] + 'a');
sb.appendCodePoint(cc[i + 1] + 'a');
String cur = sb.toString();
if (cur.equals(a) || cur.equals(b)) {
ok = false;
break;
}
}
if (ok) {
print2(cc, n);
return;
}
}
}while(next_perm(cc));
//N , M , K , a , b , c , d . 其中N , M是矩阵的行列数;K 是上锁的房间数目,(a, b)是起始位置,(c, d)是出口位置
// int n = ni();
// int m = ni();
// int k = ni();
// int a = ni();
// int b = ni();
// int c = ni();
// int d = ni();
//
//
// char cc[][] = nm(n,m);
// char keys[][] = new char[n][m];
//
// char ky = 'a';
// for(int i=0;i<k;++i){
// int x = ni();
// int y = ni();
// keys[x][y] = ky;
// ky++;
// }
// int f1[] = {a,b,0};
//
// int dd[][] = {{0,1},{0,-1},{1,0},{-1,0}};
//
// Queue<int[]> q = new LinkedList<>();
// q.offer(f1);
// int ts = 1;
//
// boolean vis[][][] = new boolean[n][m][33];
//
// while(q.size()>0){
// int sz = q.size();
// while(sz-->0) {
// int cur[] = q.poll();
// vis[cur[0]][cur[1]][cur[2]] = true;
//
// int x = cur[0];
// int y = cur[1];
//
// for (int u[] : dd) {
// int lx = x + u[0];
// int ly = y + u[1];
// if (lx >= 0 && ly >= 0 && lx < n && ly < m && (cc[lx][ly] != '#')&&!vis[lx][ly][cur[2]]){
// char ck =cc[lx][ly];
// if(ck=='.'){
// if(lx==c&&ly==d){
// println(ts); return;
// }
// if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {
// int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));
// q.offer(new int[]{lx, ly, cao});
// vis[lx][ly][cao] = true;
// }else {
//
// q.offer(new int[]{lx, ly, cur[2]});
// }
//
// }else if(ck>='A'&&ck<='Z'){
// int g = 1<<(ck-'A');
// if((g&cur[2])>0){
// if(lx==c&&ly==d){
// println(ts); return;
// }
// if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {
//
// int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));
// q.offer(new int[]{lx, ly, cao});
// vis[lx][ly][cao] = true;;
// }else {
//
// q.offer(new int[]{lx, ly, cur[2]});
// }
// }
// }
// }
// }
//
// }
// ts++;
// }
// println(-1);
// int n = ni();
//
// HashSet<String> st = new HashSet<>();
// HashMap<String,Integer> mp = new HashMap<>();
//
//
// for(int i=0;i<n;++i){
// String s = ns();
// int id= 1;
// if(mp.containsKey(s)){
// int u = mp.get(s);
// id = u;
//
// }
//
// if(st.contains(s)) {
//
// while (true) {
// String ts = s + id;
// if (!st.contains(ts)) {
// s = ts;
// break;
// }
// id++;
// }
// mp.put(s,id+1);
// }else{
// mp.put(s,1);
// }
// println(s);
// st.add(s);
//
// }
// int t = ni();
//
// for(int i=0;i<t;++i){
// int n = ni();
// long w[] = nal(n);
//
// Map<Long,Long> mp = new HashMap<>();
// PriorityQueue<long[]> q =new PriorityQueue<>((xx,xy)->{return Long.compare(xx[0],xy[0]);});
//
// for(int j=0;j<n;++j){
// q.offer(new long[]{w[j],0});
// mp.put(w[j],mp.getOrDefault(w[j],0L)+1L);
// }
//
// while(q.size()>=2){
// long f[] = q.poll();
// long y1 = f[1];
// if(y1==0){
// y1 = mp.get(f[0]);
// if(y1==1){
// mp.remove(f[0]);
// }else{
// mp.put(f[0],y1-1);
// }
// }
// long g[] = q.poll();
// long y2 = g[1];
// if(y2==0){
// y2 = mp.get(g[0]);
// if(y2==1){
// mp.remove(g[0]);
// }else{
// mp.put(g[0],y2-1);
// }
// }
// q.offer(new long[]{f[0]+g[0],2L*y1*y2});
//
// }
// long r[] = q.poll();
// println(r[1]);
//
//
//
//
// }
// int o= 9*8*7*6;
// println(o);
// int t = ni();
// for(int i=0;i<t;++i){
// long a = nl();
// int k = ni();
// if(k==1){
// println(a);
// continue;
// }
//
// int f = (int)(a%10L);
// int s = 1;
// int j = 0;
// for(;j<30;j+=2){
// int u = f-j;
// if(u<0){
// u = 10+u;
// }
// s = u*s;
// s = s%10;
// if(s==k){
// break;
// }
// }
//
// if(s==k) {
// println(a - j - 2);
// }else{
// println(-1);
// }
//
//
//
//
// }
// int m = ni();
// h = new int[n];
// to = new int[2*(n-1)];
// ne = new int[2*(n-1)];
// wt = new int[2*(n-1)];
//
// for(int i=0;i<n-1;++i){
// int u = ni()-1;
// int v = ni()-1;
//
// }
// long a[] = nal(n);
// int n = ni();
// int k = ni();
// t1 = new long[200002];
//
// int p[][] = new int[n][3];
//
// for(int i=0;i<n;++i){
// p[i][0] = ni();
// p[i][1] = ni();
// p[i][2] = i+1;
// }
// Arrays.sort(p, new Comparator<int[]>() {
// @Override
// public int compare(int[] x, int[] y) {
// if(x[1]!=y[1]){
// return Integer.compare(x[1],y[1]);
// }
// return Integer.compare(y[0], x[0]);
// }
// });
//
// for(int i=0;i<n;++i){
// int ck = p[i][0];
//
// }
}
// int []h,to,ne,wt;
long t1[];
// long t2[];
void update(long[] t,int i,long v){
for(;i<t.length;i+=(i&-i)){
t[i] += v;
}
}
long get(long[] t,int i){
long s = 0;
for(;i>0;i-=(i&-i)){
s += t[i];
}
return s;
}
int equal_bigger(long t[],long v){
int s=0,p=0;
for(int i=Integer.numberOfTrailingZeros(Integer.highestOneBit(t.length));i>=0;--i) {
if(p+(1<<i)< t.length && s + t[p+(1<<i)] < v){
v -= t[p+(1<<i)];
p |= 1<<i;
}
}
return p+1;
}
static class S{
int l = 0;
int r = 0 ;
long le = 0;
long ri = 0;
long tot = 0;
long all = 0;
public S(int l,int r) {
this.l = l;
this.r = r;
}
}
static S a[];
static int[] o;
static void init(int[] f){
o = f;
int len = o.length;
a = new S[len*4];
build(1,0,len-1);
}
static void build(int num,int l,int r){
S cur = new S(l,r);
if(l==r){
a[num] = cur;
return;
}else{
int m = (l+r)>>1;
int le = num<<1;
int ri = le|1;
build(le, l,m);
build(ri, m+1,r);
a[num] = cur;
pushup(num, le, ri);
}
}
// static int query(int num,int l,int r){
//
// if(a[num].l>=l&&a[num].r<=r){
// return a[num].tot;
// }else{
// int m = (a[num].l+a[num].r)>>1;
// int le = num<<1;
// int ri = le|1;
// pushdown(num, le, ri);
// int ma = 1;
// int mi = 100000001;
// if(l<=m) {
// int r1 = query(le, l, r);
// ma = ma*r1;
//
// }
// if(r>m){
// int r2 = query(ri, l, r);
// ma = ma*r2;
// }
// return ma;
// }
// }
static long dd = 10007;
static void update(int num,int l,long v){
if(a[num].l==a[num].r){
a[num].le = v%dd;
a[num].ri = v%dd;
a[num].all = v%dd;
a[num].tot = v%dd;
}else{
int m = (a[num].l+a[num].r)>>1;
int le = num<<1;
int ri = le|1;
pushdown(num, le, ri);
if(l<=m){
update(le,l,v);
}
if(l>m){
update(ri,l,v);
}
pushup(num,le,ri);
}
}
static void pushup(int num,int le,int ri){
a[num].all = (a[le].all*a[ri].all)%dd;
a[num].le = (a[le].le + a[le].all*a[ri].le)%dd;
a[num].ri = (a[ri].ri + a[ri].all*a[le].ri)%dd;
a[num].tot = (a[le].tot + a[ri].tot + a[le].ri*a[ri].le)%dd;
//a[num].res[1] = Math.min(a[le].res[1],a[ri].res[1]);
}
static void pushdown(int num,int le,int ri){
}
long gcd(long a,long b){ return b==0?a: gcd(b,a%b);}
int gcd(int a,int b){ return b==0?a: gcd(b,a%b);}
InputStream is;PrintWriter out;
void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}
private byte[] inbuf = new byte[2];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {lenbuf = is.read(inbuf);} catch (IOException e) {throw new InputMismatchException();}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];}
private boolean isSpaceChar(int c) {return !(c >= 33 && c <= 126);}
private int skip() {int b;while((b = readByte()) != -1 && isSpaceChar(b));return b;}
private double nd() {return Double.parseDouble(ns());}
private char nc() {return (char) skip();}
private char ncc() {int b;while((b = readByte()) != -1 && !(b >= 32 && b <= 126));return (char)b;}
private String ns() {int b = skip();StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);b = readByte(); }
return sb.toString();}
private char[] ns(int n) {char[] buf = new char[n];int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b;b = readByte(); }
return n == p ? buf : Arrays.copyOf(buf, p);}
private String nline() {int b = skip();StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b);b = readByte(); }
return sb.toString();}
private char[][] nm(int n, int m) {char[][] a = new char[n][];for (int i = 0; i < n; i++) a[i] = ns(m);return a;}
private int[] na(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = ni();return a;}
private long[] nal(int n) { long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nl();return a;}
private int ni() { int num = 0, b; boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
if (b == '-') { minus = true; b = readByte(); }
while (true) {
if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
else return minus ? -num : num;
b = readByte();}}
private long nl() { long num = 0; int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
if (b == '-') { minus = true; b = readByte(); }
while (true) {
if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
else return minus ? -num : num;
b = readByte();}}
void print(Object obj){out.print(obj);}
void println(Object obj){out.println(obj);}
void println(){out.println();}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | b13c2373ae6722175771e483595460af | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
solve();
}
}, "1", 1 << 26).start();
}
static void solve () {
FastReader fr =new FastReader(); PrintWriter op =new PrintWriter(System.out);
int n =fr.nextInt() ,i ,j ,k ,l ;String s =fr.next() ,t =fr.next() ; int arr[] ;
boolean vld[][] =new boolean[3][3] ;
if ((s.charAt(0)==s.charAt(1)) || (t.charAt(0)==t.charAt(1)) || s.equals(t)) {
vld[s.charAt(0)-97][s.charAt(1)-97] =true ; vld[t.charAt(0)-97][t.charAt(1)-97] =true ;
arr =new int[4] ; arr[0] =0 ;arr[3] =-1 ;
out: for (i =1 ; i<3 ; ++i) {
if (!vld[0][i]) {
arr[1] =i ;
for (j =0 ; j<3 ; ++j) {
if (i!=j && !vld[i][j]) {
arr[2] =j ;
for (k =0 ; k<3 ; ++k) {
if (j!=k && !vld[j][k]) arr[3] =k ;
if (arr[0]==arr[3]) break out ;
}
}
}
}
}
op.println("YES") ; for (i =0 ; i<3*n ; ++i) op.print((char)(arr[i%3]+97)) ;
}
else {
arr =new int[3*n+1] ;
if (s.charAt(0)==t.charAt(0)) {
arr[0] =((s.charAt(0)-97)^1)%3 ; vld[arr[0]][s.charAt(0)-97] =vld[arr[0]][arr[0]] =true;
for (i =0 ; i<3 ; ++i) {
if (!vld[arr[0]][i]) break;
}
arr[1] =i ;
for (i =2 ; i<2*n ; ++i) arr[i] =arr[i%2] ;
for ( ; i<3*n ; ++i) arr[i] =s.charAt(0)-97 ;
}
else if (s.charAt(1)==t.charAt(1)) {
for (i =0 ; i<n ; ++i) arr[i] =s.charAt(1)-97 ;
arr[i] =s.charAt(0)-97 ; arr[i+1] =t.charAt(0)-97 ;
for (j =i+2 ; j<3*n ; ++j) arr[j] =arr[j-2] ;
}
else if (!(s.charAt(0)==t.charAt(1) && s.charAt(1)==t.charAt(0))) {
vld[s.charAt(0)-97][s.charAt(1)-97] =true ; vld[t.charAt(0)-97][t.charAt(1)-97] =true ;
out: for (i =0 ; i<3; ++i) {
arr[0] =i ;
for (j =0 ; j<3 ; ++j) {
if (i!=j && !vld[i][j]) {
arr[1] =j ;
for (k =0 ; k<3 ; ++k) {
if (k!=i && j!=k && !vld[j][k]) {
arr[2] =k ;
for (l =0 ; l<3 ; ++l) {
if (k!=l && j!=l && !vld[k][l]) arr[3] =l ;
if (arr[0]==arr[3]) break out ;
}
}
}
}
}
}
for (i =3 ; i<3*n ; ++i) arr[i] =arr[i%3] ;
}
else {
for (i =0 ; i<n ; ++i) arr[i] =s.charAt(0)-97 ;
j =3-(s.charAt(0)+s.charAt(1)-194) ;
for ( ; i<2*n ; ++i) arr[i] =j ;
for ( ; i<3*n ; ++i) arr[i] =s.charAt(1)-97 ;
}
op.println("YES") ; for (i =0 ; i<3*n ; ++i) op.print((char)(arr[i]+97)) ;
}
op.flush(); op.close();
}
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();
}
String nextLine() {
String str ="";
try
{
str =br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next()) ;
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 57199266c0f76cd98263d5d725de8192 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.util.*;
import java.io.*;
import java.text.*;
public class E {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
String x = sc.next();
String y = sc.next();
HashSet<String> abc = new HashSet<String>();
HashSet<String> acb = new HashSet<String>();
abc.add("ab");
abc.add("bc");
abc.add("ca");
acb.add("ac");
acb.add("cb");
acb.add("ba");
int s1 =0;
int s2 =0;
if(abc.contains(x))
s1++;
if(abc.contains(y))
s1++;
if(acb.contains(x))
s2++;
if(acb.contains(y))
s2++;
pw.println("YES");
if(s1 ==0) {
for(int i=0;i<n;i++)
pw.print("abc");
}else if(s2 ==0) {
for(int i=0;i<n;i++)
pw.print("acb");
}else {
if(y.charAt(0) == x.charAt(0)) {
for(int i=0;i<3;i++) {
if('a'+i != y.charAt(0)) {
for(int j=0;j<n;j++)
pw.print((char)('a'+i));
}
}
for(int i=0;i<n;i++)
pw.print(x.charAt(0));
}else if(y.charAt(1)==x.charAt(1)) {
for(int i=0;i<n;i++)
pw.print(x.charAt(1));
for(int i=0;i<3;i++) {
if('a'+i != y.charAt(1)) {
for(int j=0;j<n;j++)
pw.print((char)('a'+i));
}
}
}else {
for(int i=0;i<n;i++) {
pw.print(x.charAt(0));
}
for(int i=0;i<3;i++) {
if('a'+i != x.charAt(0) && 'a'+i != x.charAt(1)) {
for(int j=0;j<n;j++) {
pw.print((char)('a'+i));
}
}
}
for(int i=0;i<n;i++) {
pw.print(x.charAt(1));
}
}
}
pw.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | ae9d0ce9ed3888f1ad8fba6ddef71dfb | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class E {
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
static InputReader r = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
int n = r.nextInt();
ArrayList<String> list = new ArrayList<String>();
list.add(r.next()); list.add(r.next());
Collections.sort(list);
pw.println("YES");
if(list.get(0).equals(list.get(1))){
if(list.get(0).equals("aa")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(0).equals("ab")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(0).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(0).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(0).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(0).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
} else if(list.get(0).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(0).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(0).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
}
if(list.get(0).equals("aa")){
if(list.get(1).equals("ab")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("ab")){
if(list.get(1).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("a");
}
} else if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("ac");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
}
} else if(list.get(0).equals("ac")){
if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("ba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("ba")){
if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("bc");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("bb")){
if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("bc")){
if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
}
} else if(list.get(0).equals("ca")){
if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
}
} else if(list.get(0).equals("cb")){
if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
}
}
pw.println();
pw.close();
}
}
/**
* _ _ _
* | | | | | |
* ___ ___ __| | ___ | |__ _ _ __| | __ _ _ __ _ __ ___ _ __ _ _ __ _ ___
* / __/ _ \ / _` |/ _ \ | '_ \| | | | / _` |/ _` | '__| '__/ _ \ '_ \ | | | |/ _` |/ _ \
* | (_| (_) | (_| | __/ | |_) | |_| | | (_| | (_| | | | | | __/ | | | | |_| | (_| | (_) |
* \___\___/ \__,_|\___| |_.__/ \__, | \__,_|\__,_|_| |_| \___|_| |_| \__, |\__,_|\___/
* __/ | ______ __/ |
* |___/ |______|___/
*/ | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | d8941d2fa372bfe76c065ed3bf95e4ec | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWriter(System.out);
// String one[] = {"aa", "bb", "cc", "ab", "ac", "ba", "bc", "ca", "cb"};
int n = sc.nextInt();
String s = sc.next(), t = sc.next();
String poss[] = {"abc", "acb", "bca", "bac", "cab", "cba"};
boolean found = false;
for (String cand : poss) {
if (check(s, t, (cand + (n == 1 ? "" : cand)).toCharArray())) {
found = true;
out.println("YES");
StringBuilder hop = new StringBuilder();
while (n-- > 0) {
out.print(cand);
hop.append(cand);
}
if (!check(s, t, hop.toString().toCharArray())) {
System.err.println("HAO");
}
break;
}
}
if (!found) {
String[] cand = {generate('a', n), generate('b', n), generate('c', n)};
for (String cur : poss) {
StringBuilder tmp = new StringBuilder();
for (int i = 0; i < 3; i++) {
int idx = cur.charAt(i) - 'a';
tmp.append(cand[idx]);
}
String tt = tmp.toString();
if (check(s, t, tt.toCharArray())) {
found = true;
out.println("YES");
out.print(tt);
break;
}
}
}
if (!found) out.println("NO");
else out.println();
out.flush();
out.close();
}
static String generate(char d, int n) {
StringBuilder ans = new StringBuilder();
while (n-- > 0)
ans.append(d);
return ans.toString();
}
static boolean check(String s, String t, char[] cand) {
for (int i = 0; i < cand.length - 1; i++) {
String tmp = cand[i] + "" + cand[i + 1];
if (tmp.equals(s) || tmp.equals(t)) return false;
}
return true;
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
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());
}
int[] nextIntArray(int n) throws IOException {
int[] ans = new int[n];
for (int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 91ee07811bae5b6458cb66cec41e29fd | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | /**
* Created at 03:18 on 2019-08-31
*/
import java.io.*;
import java.util.*;
public class Main {
static FastScanner sc = new FastScanner();
static Output out = new Output(System.out);
static final int[] dx = {0, 1, 0, -1};
static final int[] dy = {-1, 0, 1, 0};
static final long MOD = (long) (1e9 + 7);
static final long INF = Long.MAX_VALUE / 2;
static final int e5 = (int) 1e5;
public static class Solver {
public Solver() {
int N = sc.nextInt();
String S = sc.next();
String T = sc.next();
boolean[][] banned = new boolean[256][256];
banned[S.charAt(0)][S.charAt(1)] = true;
banned[T.charAt(0)][T.charAt(1)] = true;
StringBuilder ans = new StringBuilder();
for (char ch1='a'; ch1<='c'; ch1++) {
for (char ch2='a'; ch2<='c'; ch2++) {
if (ch1 == ch2) continue;
char ch3 = (char)('a' ^ 'b' ^ 'c' ^ ch1 ^ ch2);
if (!banned[ch1][ch2] && !banned[ch2][ch3] && !banned[ch3][ch1]) {
for (int i=0; i<N; i++) {
ans.append(new char[]{ch1, ch2, ch3});
}
out.println("YES");
out.println(ans);
return;
}
if (!banned[ch1][ch2] && !banned[ch2][ch3] && !banned[ch1][ch1] && !banned[ch2][ch2] && !banned[ch3][ch3]) {
for (int i=0; i<N; i++) ans.append(ch1);
for (int i=0; i<N; i++) ans.append(ch2);
for (int i=0; i<N; i++) ans.append(ch3);
out.println("YES");
out.println(ans);
return;
}
}
}
out.println("NO");
}
}
public static void main(String[] args) {
new Solver();
out.flush();
}
static class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++];
else return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
private void skipUnprintable() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
}
public boolean hasNext() {
skipUnprintable();
return hasNextByte();
}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextIntArray(int N, boolean oneBased) {
if (oneBased) {
int[] array = new int[N + 1];
for (int i = 1; i <= N; i++) {
array[i] = sc.nextInt();
}
return array;
} else {
int[] array = new int[N];
for (int i = 0; i < N; i++) {
array[i] = sc.nextInt();
}
return array;
}
}
public long[] nextLongArray(int N, boolean oneBased) {
if (oneBased) {
long[] array = new long[N + 1];
for (int i = 1; i <= N; i++) {
array[i] = sc.nextLong();
}
return array;
} else {
long[] array = new long[N];
for (int i = 0; i < N; i++) {
array[i] = sc.nextLong();
}
return array;
}
}
}
static class Output extends PrintWriter {
public Output(PrintStream ps) {
super(ps);
}
public void print(int[] a, String separator) {
for (int i = 0; i < a.length; i++) {
if (i == 0) print(a[i]);
else print(separator + a[i]);
}
println();
}
public void print(long[] a, String separator) {
for (int i = 0; i < a.length; i++) {
if (i == 0) print(a[i]);
else print(separator + a[i]);
}
println();
}
public void print(String[] a, String separator) {
for (int i = 0; i < a.length; i++) {
if (i == 0) print(a[i]);
else print(separator + a[i]);
}
println();
}
public void print(ArrayList a, String separator) {
for (int i = 0; i < a.size(); i++) {
if (i == 0) print(a.get(i));
else print(separator + a.get(i));
}
println();
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | c583035e3ff7420b6def00eebb89f115 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author /\
*/
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);
ETwoSmallStrings solver = new ETwoSmallStrings();
solver.solve(1, in, out);
out.close();
}
static class ETwoSmallStrings {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
String str1 = in.nextLine();
String str2 = in.nextLine();
List<Character> al = new ArrayList<Character>() {{
add('a');
add('b');
add('c');
}};
Set<Character> hs = new HashSet<Character>() {{
add(str1.charAt(0));
add(str1.charAt(1));
add(str2.charAt(0));
add(str2.charAt(1));
}};
StringBuilder res = new StringBuilder();
if (hs.size() == 1) {
StringBuilder temp = new StringBuilder();
al.remove((Character) str1.charAt(0));
temp.append(al.get(0));
temp.append(str1.charAt(0));
temp.append(al.get(1));
for (int i = 0; i < n; i++) {
res.append(temp);
}
} else if (hs.size() == 2) {
if (str1.charAt(0) == str1.charAt(1) || str2.charAt(0) == str2.charAt(1)) {
char x = 'a';
char y;
char z;
int idx = 0;
if (str1.charAt(0) == str1.charAt(1)) {
for (int i = 0; i < 2; i++) {
Character c = str2.charAt(i);
if (str2.charAt(i) != str1.charAt(0)) {
x = c;
al.remove(c);
idx = i;
break;
}
}
al.remove((Character) str1.charAt(0));
y = str1.charAt(0);
z = al.get(0);
} else {
for (int i = 0; i < 2; i++) {
Character c = str1.charAt(i);
if (c != str2.charAt(0)) {
x = c;
al.remove(c);
idx = i;
break;
}
}
al.remove((Character) str2.charAt(0));
y = str2.charAt(0);
z = al.get(0);
}
StringBuilder temp = new StringBuilder();
if (idx == 1) {
temp.append(x);
temp.append(y);
temp.append(z);
} else {
temp.append(z);
temp.append(y);
temp.append(x);
}
for (int i = 0; i < n; i++) {
res.append(temp);
}
} else {
List<Character> temp = new ArrayList<>();
for (Character c : hs) {
al.remove(c);
temp.add(c);
}
for (int i = 0; i < n; i++) {
res.append(temp.get(0));
}
for (int i = 0; i < n; i++) {
res.append(al.get(0));
}
for (int i = 0; i < n; i++) {
res.append(temp.get(1));
}
}
} else { //size = 3
if (str1.charAt(0) == str1.charAt(1) || str2.charAt(0) == str2.charAt(1)) {
char x;
char y;
char z;
if (str1.charAt(0) == str1.charAt(1)) {
x = str2.charAt(0);
y = str1.charAt(0);
z = str2.charAt(1);
} else {
x = str1.charAt(0);
y = str2.charAt(0);
z = str1.charAt(1);
}
StringBuilder temp = new StringBuilder();
temp.append(x);
temp.append(y);
temp.append(z);
for (int i = 0; i < n; i++) {
res.append(temp);
}
} else {
char x;
char y;
char z;
if (str1.charAt(0) == str2.charAt(0)) {
y = str1.charAt(0);
z = str1.charAt(1);
x = str2.charAt(1);
} else if (str1.charAt(0) == str2.charAt(1)) {
x = str1.charAt(0);
y = str1.charAt(1);
z = str2.charAt(0);
} else if (str1.charAt(1) == str2.charAt(0)) {
x = str1.charAt(0);
y = str1.charAt(1);
z = str2.charAt(1);
} else {
y = str1.charAt(0);
x = str1.charAt(1);
z = str2.charAt(0);
}
for (int i = 0; i < n; i++) {
res.append(x);
}
for (int i = 0; i < n; i++) {
res.append(z);
}
for (int i = 0; i < n; i++) {
res.append(y);
}
}
}
out.println("YES");
out.println(res);
}
}
static class Scanner {
private StringTokenizer st;
private BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 6a35db5da2cfefbbe351ebe890c6d8ec | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.TreeSet;
public class Solution implements Runnable
{
static final long MAX = 464897L;
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Solution(),"Solution",1<<26).start();
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long lcm(long a,long b) {
return (a*b)/gcd(a,b);
}
int maxn = 1000005;
long MOD = 998244353;
long prime = 29;
ArrayList<Integer> adj[];
HashMap<Integer,Integer> tmap = new HashMap();
int[] val;
int[] ans;
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = sc.nextInt();
String a = sc.next();
String b = sc.next();
StringBuilder st = new StringBuilder();
if(a.charAt(0) == b.charAt(0)) {
if(a.charAt(0) == a.charAt(1) || a.charAt(0) == b.charAt(1)) {
if(a.equals(b)) {
for(int i = 0;i < n;i++) {
st.append("abc");
}
}else {
char temp = (char)(97+98+99-a.charAt(1)-b.charAt(1));
char temp2 = (char)(97+98+99-a.charAt(0) - temp);
for(int i = 0;i < n;i++) {
st.append(a.charAt(0) + "" + temp + "" + temp2);
}
}
}else {
if(a.equals(b)){
char temp = (char)(97+98+99-a.charAt(0)-b.charAt(1));
for(int i = 0;i < n;i++) {
st.append(a.charAt(0) + "" + temp + b.charAt(1));
}
}else {
char c1 = a.charAt(1);
char c2 = b.charAt(1);
for(int i = 0;i < n;i++) {
st.append(c1+""+c2);
}
for(int i = 0;i < n;i++) {
st.append(a.charAt(0));
}
}
}
}else {
char temp = (char)(97+98+99-a.charAt(0)-b.charAt(0));
if(a.charAt(0) == a.charAt(1) && b.charAt(0) == b.charAt(1)) {
for(int i = 0;i < n;i++) {
st.append("abc");
}
}else {
if(a.charAt(0) == a.charAt(1)) {
for(int i = 0;i < n;i++) {
st.append(a.charAt(0) + "" + temp);
}
for(int i = 0;i < n;i++) {
st.append(b.charAt(0));
}
}else if(b.charAt(0) == b.charAt(1)){
for(int i = 0;i < n;i++) {
st.append(b.charAt(0) + "" + temp);
}
for(int i = 0;i < n;i++) {
st.append(a.charAt(0));
}
}else {
if(a.charAt(1) == temp && b.charAt(1) == temp) {
for(int i = 0;i < n;i++) {
st.append(temp);
}
for(int i = 0;i < n;i++) {
st.append(a.charAt(0)+""+b.charAt(0));
}
}else {
if(temp != a.charAt(1)) {
for(int i = 0;i < n;i++) {
st.append(a.charAt(0)+""+ temp);
}
for(int i = 0;i < n;i++) {
st.append(b.charAt(0));
}
}
else {
for(int i = 0;i < n;i++) {
st.append(b.charAt(0)+""+ temp);
}
for(int i = 0;i < n;i++) {
st.append(a.charAt(0));
}
}
}
}
}
}
w.println("YES");
w.print(st.toString());
w.close();
}
static long power(long a,long b,long mod) {
long ans = 1;
a = a % mod;
while(b != 0) {
if(b % 2 == 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b = b/2;
}
return ans;
}
class Pair implements Comparable<Pair>{
int a;
int b;
int c;
Pair(int a,int b,int c){
this.b = b;
this.a = a;
this.c = c;
}
public boolean equals(Object o) {
Pair p = (Pair)o;
return this.a == p.a && this.b == p.b && this.c == p.c;
}
public int hashCode(){
return Long.hashCode(a)*27 + Long.hashCode(b)*31;
}
public int compareTo(Pair p) {
return Long.compare(this.a,p.a);
}
}
class Pair3 implements Comparable<Pair3>{
int a;
int b;
int c;
Pair3(int a,int b,int c){
this.b = b;
this.a = a;
this.c = c;
}
public boolean equals(Object o) {
Pair3 p = (Pair3)o;
return this.a == p.a && this.b == p.b && this.c == p.c;
}
public int hashCode(){
return Long.hashCode(a)*27 + Long.hashCode(b)*31;
}
public int compareTo(Pair3 p) {
return Long.compare(this.b,p.b);
}
}
class Pair2 implements Comparable<Pair2>{
int a;
int b;
int c;
Pair2(int a,int b,int c){
this.b = b;
this.a = a;
this.c = c;
}
public boolean equals(Object o) {
Pair2 p = (Pair2)o;
return this.a == p.a && this.b == p.b && this.c == p.c;
}
public int hashCode(){
return Long.hashCode(a)*27 + Long.hashCode(b)*31 + Long.hashCode(c)*3;
}
public int compareTo(Pair2 p) {
return Long.compare(p.a,this.a);
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 1cc78e60e4af272ae63b6f2c8133daef | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author sarthakmanna
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
ETwoSmallStrings solver = new ETwoSmallStrings();
solver.solve(1, in, out);
out.close();
}
static class ETwoSmallStrings {
int N;
HashSet<Integer>[] graph;
public void solve(int testNumber, FastReader in, FastWriter out) {
int i, j, k;
out.println("YES");
StringBuilder sb = new StringBuilder();
graph = new HashSet[3];
for (i = 0; i < 3; ++i) {
graph[i] = new HashSet<>();
for (j = 0; j < 3; ++j) graph[i].add(j);
}
String[] A = new String[2];
N = in.nextInt();
for (i = 0; i < 2; ++i) {
String S = A[i] = in.next();
int a = S.charAt(0) - 'a', b = S.charAt(1) - 'a';
graph[a].remove(b);
}
boolean[] sink = new boolean[3];
boolean present = false;
for (i = 0; i < 3; ++i) {
boolean isSink = true;
for (int itr : graph[i]) if (itr != i) isSink = false;
if (isSink) sink[i] = present = true;
}
if (present) {
int start;
for (start = 0; sink[start]; ++start) ;
for (i = 0; i < N * 2; ++i) {
sb.append((char) (start + 'a'));
start = (start + 1) % 3;
if (sink[start]) start = (start + 1) % 3;
}
int sinkInd;
for (sinkInd = 0; !sink[sinkInd]; ++sinkInd) ;
for (i = 0; i < N; ++i) {
sb.append((char) (sinkInd + 'a'));
}
} else {
System.err.println("YES");
if (canGo1()) {
for (i = 0; i < N * 3; ++i) sb.append((char) (i % 3 + 'a'));
} else if (canGo2()) {
for (i = N * 3; i > 0; --i) sb.append((char) (i % 3 + 'a'));
} else {
System.err.println("YYY");
j = -7;
lbl:
{
for (i = 0; i < 3; ++i)
for (j = 0; j < i; ++j) {
if (!graph[i].contains(j) && !graph[j].contains(i)) break lbl;
}
}
if (i < 3 && j < 3) {
int a = i, b = j;
for (i = 0; i < N * 2; ++i) {
sb.append((char) (a + 'a'));
a = (a + 1) % 3;
if (a == b) a = (a + 1) % 3;
}
for (i = 0; i < N; ++i) sb.append((char) (b + 'a'));
} else {
System.err.println("Y");
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j)
if (i != j) {
if (graph[j].contains(i)) break;
}
if (j >= 3) break;
}
int a = i;
for (i = 0; i < N; ++i) sb.append((char) (a + 'a'));
int start = (a + 1) % 3;
for (i = 0; i < N * 2; ++i) {
sb.append((char) (start + 'a'));
start = (start + 1) % 3;
if (start == a) start = (start + 1) % 3;
}
}
}
}
/*if (sb.length() != N * 3 || sb.toString().contains(A[0]) || sb.toString().contains(A[1]))
System.exit(7 / 0);
verify(sb.toString());*/
out.println(sb);
out.flush();
}
boolean canGo1() {
return graph[0].contains(1) && graph[1].contains(2) && graph[2].contains(0);
}
boolean canGo2() {
return graph[2].contains(1) && graph[1].contains(0) && graph[0].contains(2);
}
}
static class FastReader {
static private byte[] buf = new byte[2048];
static private int index;
static private int total;
static private InputStream in;
public FastReader(InputStream is) {
try {
in = is;
} catch (Exception e) {
}
}
private int scan() {
try {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
} catch (Exception e) {
return 7 / 0;
}
}
public String next() {
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();
}
public int nextInt() {
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;
}
}
static class FastWriter {
static private BufferedWriter bw;
public FastWriter(OutputStream os) {
bw = new BufferedWriter(new OutputStreamWriter(os));
}
public FastWriter(Writer w) {
bw = new BufferedWriter(w);
}
public void print(Object a) {
try {
bw.write(a.toString());
} catch (Exception e) {
}
}
public void println(Object a) {
print(a);
print("\n");
}
public void flush() {
try {
bw.flush();
} catch (Exception e) {
}
}
public void close() {
try {
bw.close();
} catch (Exception e) {
}
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 7f8687529427798c45bed481456c169c | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;
public class cf1 implements Runnable {
long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
long power(long x, long y, long p)
{
long res = 1;
x=x % p;
while (y > 0)
{
if((y & 1)==1)
res = ((res%p) * (x%p))% p;
y =y >> 1;
x =((x%p)*(x%p))%p;
}
return res;
}
public void run() {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=in.nextInt();
String s=in.next();
String t=in.next();
String[] per= {"abc","acb","bca","bac","cba","cab"};
ArrayList<String> al=new ArrayList<>();
String ans="";
for(int i=0;i<5;i++)
{
String ss=per[i];
if(ss.contains(s) || ss.contains(t))
continue;
else
{
al.add(per[i]); //possible by rep.
String check=String.valueOf(per[i].charAt(2))+String.valueOf(per[i].charAt(0));
if(!check.equals(s) && !check.equals(t))
{
ans=per[i];
break;
}
}
}
if(ans.length()==0)
{
StringBuffer ans2=new StringBuffer("");
int f=0;
for(int i=0;i<al.size();i++)
{
ans2=new StringBuffer("");
for(int j=0;j<n;j++)
ans2.append(al.get(i).charAt(0));
for(int j=0;j<n;j++)
ans2.append(al.get(i).charAt(1));
for(int j=0;j<n;j++)
ans2.append(al.get(i).charAt(2));
if(!ans2.toString().contains(s) && !ans2.toString().contains(t))
{
f=1;
break;
}
}
if(f==1)
{
w.println("YES");
w.println(ans2);
}
else
w.println("NO");
}
else
{
w.println("YES");
for(int i=0;i<n;i++)
w.print(ans);
w.println();
}
w.close();
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new cf1(),"cf1",1<<26).start();
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | a54f1cbf2d13c4ce6109deffee36a358 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter pw;
static int n;
static TreeSet<String> tr;
public static boolean has(String d) {
return tr.contains(d);
}
public static void doo(char d) {
int g[] = new int[3];
for (int i = 0; i < 3; i++) {
if ('a' + i == d) {
g[i]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (g[j] == 0) {
System.out.print((char) (j + 'a'));
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (g[j] == 1) {
System.out.print((char) (j + 'a'));
}
}
}
}
public static void doo1(char d) {
int g[] = new int[3];
for (int i = 0; i < 3; i++) {
if ('a' + i == d) {
g[i]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (g[j] == 1) {
System.out.print((char) (j + 'a'));
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (g[j] == 0) {
System.out.print((char) (j + 'a'));
}
}
}
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
n = sc.nextInt();
String s = sc.next();
String t = sc.next();
tr = new TreeSet<>();
tr.add(s);
System.out.println("YES");
tr.add(t);
if (s.charAt(0) == s.charAt(1) && t.charAt(0) == t.charAt(1)) {
for (int i = 0; i < n; i++) {
System.out.print("abc");
}
return;
} else if (s.charAt(0) == s.charAt(1) || t.charAt(0) == t.charAt(1)) {
String ans = "abc";
if (has("ab")) {
ans = "bac";
}
if (has("bc")) {
ans = "acb";
}
if (has("ca")) {
ans = "bac";
}
for (int i = 0; i < n; i++) {
System.out.print(ans);
}
return;
} else {
if ((s.charAt(0) == t.charAt(0))&&s!=t) {
doo(s.charAt(0));
return;
}
if ((s.charAt(1) == t.charAt(1))&&s!=t) {
doo1(s.charAt(1));
return;
}
String ans = "abc";
if (has("ab")) {
ans = "acb";
}
if (has("bc")) {
ans = "bac";
}
for (int i = 0; i < n; i++) {
System.out.print(ans.charAt(0));
}
for (int i = 0; i < n; i++) {
System.out.print(ans.charAt(1));
}
for (int i = 0; i < n; i++) {
System.out.print(ans.charAt(2));
}
}
}
}
class Scan {
static BufferedReader br;
static StringTokenizer st = new StringTokenizer("");
public static int nextInt() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return Integer.parseInt(st.nextToken());
}
public static String next() throws IOException {
while (!st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return (st.nextToken());
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 746eb20103719e2eb92e31461c4b00fe | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF1213E extends PrintWriter {
CF1213E() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1213E o = new CF1213E(); o.main(); o.flush();
}
char[] cc;
int n;
void fill1(int a, int b, int c) {
for (int i = 0; i < n * 2; i++)
cc[i] = (char) ((i % 2 == 0 ? a : b) + 'a');
for (int i = n * 2; i < n * 3; i++)
cc[i] = (char) (c + 'a');
}
void fill2(int a, int b, int c) {
for (int i = 0; i < n; i++)
cc[i] = (char) (a + 'a');
for (int i = n; i < n * 3; i++)
cc[i] = (char) ((i % 2 == 0 ? b : c) + 'a');
}
void fill3(int a, int b, int c) {
for (int i = 0; i < n; i++)
cc[i] = (char) (a + 'a');
for (int i = n; i < n * 2; i++)
cc[i] = (char) (b + 'a');
for (int i = n * 2; i < n * 3; i++)
cc[i] = (char) (c + 'a');
}
void main() {
n = sc.nextInt();
cc = new char[n * 3];
char[] s = sc.next().toCharArray();
char[] t = sc.next().toCharArray();
if (t[0] == t[1]) {
char[] tmp = s; s = t; t = tmp;
}
int s0 = s[0] - 'a';
int s1 = s[1] - 'a';
int t0 = t[0] - 'a';
int t1 = t[1] - 'a';
int a, b, c;
if (s0 == s1) {
a = s0;
if (t0 == t1) {
// aa bb
if (t0 == s0)
b = a == 0 ? 1 : 0;
else
b = t0;
c = 3 - a - b;
fill1(a, b, c);
} else if (t0 == s0) {
// aa ab
b = t1;
c = 3 - a - b;
fill2(b, a, c);
} else if (t1 == s0) {
// aa ba
b = t0;
c = 3 - a - b;
fill1(a, c, b);
} else {
// aa bc
b = t0;
c = t1;
fill1(a, c, b);
}
} else {
a = s0;
b = s1;
c = 3 - a - b;
if (t0 == a && t1 == b || t0 == b && t1 == a)
fill3(a, c, b);
else if (t0 == b && t1 == c)
fill3(c, b, a);
else if (t0 == c && t1 == b)
fill3(b, a, c);
else if (t0 == a && t1 == c)
fill3(c, b, a);
else if (t0 == c && t1 == a)
fill3(b, a, c);
}
println("YES");
println(cc);
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 5bc3247a73c152f6f349055b95ad1e93 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes |
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
String str1 = s.next(), str2 = s.next();
String[] arr = new String[] {"abc", "acb", "bac", "bca", "cab", "cba"};
int idx = -1;
for(int i = 0; i < arr.length; i++) {
boolean possible = true;
for(int j = 0; j < 3; j++) {
String st = arr[i].charAt(j) + "" + arr[i].charAt((j + 1) % 3);
if(st.equals(str1) || st.equals(str2)) {
possible = false;
break;
}
}
if(possible) {
idx = i;
break;
}
}
if(idx != -1) {
StringBuffer strbf = new StringBuffer();
for(int i = 0; i < n; i++) {
strbf.append(arr[idx]);
}
System.out.println("YES");
System.out.println(strbf);
return;
}
idx = -1;
for(int i = 0; i < arr.length; i++) {
boolean possible = true;
for(int j = 0; j < 2; j++) {
String st = arr[i].charAt(j) + "" + arr[i].charAt((j + 1) % 3);
if(st.equals(str1) || st.equals(str2)) {
possible = false;
break;
}
}
if(possible) {
idx = i;
break;
}
}
if(idx != -1) {
StringBuffer strbf = new StringBuffer();
for(int i = 0; i < n; i++) {
strbf.append(arr[idx].charAt(0));
}
for(int i = 0; i < n; i++) {
strbf.append(arr[idx].charAt(1));
}
for(int i = 0; i < n; i++) {
strbf.append(arr[idx].charAt(2));
}
System.out.println("YES");
System.out.println(strbf);
return;
}
System.out.println("NO");
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | c06ca477f8d43d5a87d67d878313d96a | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.function.Consumer;
public class MainE {
static int N;
static String S, T;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
N = sc.nextInt();
S = sc.next();
T = sc.next();
String ans = solve();
if( ans != null ) {
System.out.println("YES");
System.out.println(ans);
} else {
System.out.println("NO");
}
}
static String solve() {
List<char[]> C = new ArrayList<>();
heapPermutation("abc".toCharArray(), 3, c -> {
C.add( Arrays.copyOf(c, 3) );
});
for (char[] c : C) {
// abc -> abcabcabc
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) sb.append(c);
String ans = sb.toString();
boolean ok = true;
for (int i = 0; i < ans.length()-1; i++) {
char u = ans.charAt(i);
char v = ans.charAt(i+1);
if( S.charAt(0) == u && S.charAt(1) == v || T.charAt(0) == u && T.charAt(1) == v ) {
ok = false;
break;
}
}
if( ok ) return ans;
}
// abc -> aaabbbccc
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) sb.append(c[0]);
for (int i = 0; i < N; i++) sb.append(c[1]);
for (int i = 0; i < N; i++) sb.append(c[2]);
String ans = sb.toString();
boolean ok = true;
for (int i = 0; i < ans.length()-1; i++) {
char u = ans.charAt(i);
char v = ans.charAt(i+1);
if( S.charAt(0) == u && S.charAt(1) == v || T.charAt(0) == u && T.charAt(1) == v ) {
ok = false;
break;
}
}
if( ok ) return ans;
}
}
return null; // 無いはず
}
static void heapPermutation(char[] arr, int size, Consumer<char[]> c) {
if (size == 1) {
c.accept(arr);
}
for (int i = 0; i < size; i++) {
heapPermutation(arr, size-1, c);
if (size % 2 == 1) {
char temp = arr[0];
arr[0] = arr[size-1];
arr[size-1] = temp;
} else {
char temp = arr[i];
arr[i] = arr[size-1];
arr[size-1] = temp;
}
}
}
@SuppressWarnings("unused")
static class FastScanner {
private BufferedReader reader;
private StringTokenizer tokenizer;
FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
long nextLong() {
return Long.parseLong(next());
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
int[] nextIntArray(int n, int delta) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt() + delta;
return a;
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
}
static void writeLines(int[] as) {
PrintWriter pw = new PrintWriter(System.out);
for (int a : as) pw.println(a);
pw.flush();
}
static void writeLines(long[] as) {
PrintWriter pw = new PrintWriter(System.out);
for (long a : as) pw.println(a);
pw.flush();
}
static void writeSingleLine(int[] as) {
PrintWriter pw = new PrintWriter(System.out);
for (int i = 0; i < as.length; i++) {
if (i != 0) pw.print(" ");
pw.print(as[i]);
}
pw.println();
pw.flush();
}
static int max(int... as) {
int max = Integer.MIN_VALUE;
for (int a : as) max = Math.max(a, max);
return max;
}
static int min(int... as) {
int min = Integer.MAX_VALUE;
for (int a : as) min = Math.min(a, min);
return min;
}
static void debug(Object... args) {
StringJoiner j = new StringJoiner(" ");
for (Object arg : args) {
if (arg == null) j.add("null");
else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
else j.add(arg.toString());
}
System.err.println(j.toString());
}
static void printSingleLine(int[] array) {
PrintWriter pw = new PrintWriter(System.out);
for (int i = 0; i < array.length; i++) {
if (i != 0) pw.print(" ");
pw.print(array[i]);
}
pw.println();
pw.flush();
}
static int lowerBound(int[] array, int value) {
int lo = 0, hi = array.length, mid;
while (lo < hi) {
mid = (hi + lo) / 2;
if (array[mid] < value) lo = mid + 1;
else hi = mid;
}
return lo;
}
static int upperBound(int[] array, int value) {
int lo = 0, hi = array.length, mid;
while (lo < hi) {
mid = (hi + lo) / 2;
if (array[mid] <= value) lo = mid + 1;
else hi = mid;
}
return lo;
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 1fb8a3a4082cda7272d0af58dbea81bb | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes |
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class CF1213E {
static boolean nextPermutation(char[] c)
{
int first = getFirst(c);
if(first == -1)
return false;
int toSwap = c.length - 1;
while (c[first] >= c[toSwap])
--toSwap;
swap(c, first++, toSwap);
toSwap = c.length - 1;
while(first < toSwap)
swap(c, first++, toSwap--);
return true;
}
static int getFirst(char[] c)
{
for ( int i = c.length - 2; i >= 0; i--)
if (c[i] < c[i + 1])
return i;
return -1;
}
static void swap(char[] c,int i, int j)
{
char tmp = c[i];
c[i] = c[j];
c[j] = tmp;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int N = sc.nextInt();
char [] c = new char[] {'a', 'b', 'c'};
String s = sc.next(),
t = sc.next();
do {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < N; ++j) {
sb.append(c[i]);
}
}
String ss = sb.toString();
if (!ss.contains(s) && !ss.contains(t)) {
System.out.println("YES");
System.out.println(ss);
return;
} else {
int index = 0;
sb = new StringBuilder();
for (int i = 0; i < 3 * N; ++i) {
sb.append(c[index]);
index = (index + 1) % 3;
}
ss = new String(sb.toString());
if (!ss.contains(s) && !ss.contains(t)) {
System.out.println("YES");
System.out.println(ss);
return;
}
}
} while(nextPermutation(c));
System.out.println("NO");
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 82eed43c91425225a49221cbe9f40006 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class Solution {
static String s;
static String t;
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt();
s = in.nextLine();
t = in.nextLine();
String[] pattern1 = {"abc", "acb", "bac", "bca", "cab", "cba"};
if (n == 1) {
for (String ans : pattern1) {
if (!ans.contains(s) && !ans.contains(t)) {
System.out.println("YES\n" + ans);
return;
}
}
System.out.println("NO");
return;
}
for (String p : pattern1) {
String ans = p + p;
if (!ans.contains(s) && !ans.contains(t)) {
System.out.println("YES");
for (int i = 0; i < n; ++i) {
System.out.print(p);
}
System.out.println();
return;
}
}
for (String p : pattern1) {
StringBuilder sb = new StringBuilder();
sb.append(p.charAt(0));
sb.append(p.charAt(0));
sb.append(p.charAt(1));
sb.append(p.charAt(1));
sb.append(p.charAt(2));
sb.append(p.charAt(2));
String ans = sb.toString();
if (!ans.contains(s) && !ans.contains(t)) {
System.out.println("YES");
sb = new StringBuilder();
for (int i = 0; i < n; ++i) {
sb.append(p.charAt(0));
}
for (int i = 0; i < n; ++i) {
sb.append(p.charAt(1));
}
for (int i = 0; i < n; ++i) {
sb.append(p.charAt(2));
}
System.out.println(sb.toString());
return;
}
}
System.out.println("NO");
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1) {
throw new InputMismatchException();
}
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 9a59fe80c51396c9bbd629a40b99a169 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
Task582E solver = new Task582E();
solver.solve(1, in, out);
out.close();
}
static class Task582E {
public void solve(int testNumber, InputReader in, OutputWriter out) {
String arr[] = {"abc", "acb", "bac", "bca", "cab", "cba"};
int n = in.nextInt();
String s = in.nextString();
String t = in.nextString();
int i, j;
outer:
for (i = 0; i < 6; i++) {
for (j = 0; j < 3; j++) {
String cur = arr[i].charAt(j) + "" + arr[i].charAt((j + 1) % 3);
if (cur.equals(s) || cur.equals(t)) {
continue outer;
}
}
break;
}
if (i == 6) {
if (n == 1) {
if (s.charAt(0) == t.charAt(0)) {
for (i = 0; i < 6; i++) {
if (arr[i].charAt(2) == s.charAt(0)) {
out.println("YES");
out.println(arr[i]);
return;
}
}
}
if (s.charAt(1) == t.charAt(1)) {
for (i = 0; i < 6; i++) {
if (arr[i].charAt(0) == s.charAt(1)) {
out.println("YES");
out.println(arr[i]);
return;
}
}
}
if (s.charAt(0) == t.charAt(1) && s.charAt(1) == t.charAt(0)) {
for (i = 0; i < 6; i++) {
if (arr[i].charAt(1) != s.charAt(1) && arr[i].charAt(1) != s.charAt(0)) {
out.println("YES");
out.println(arr[i]);
return;
}
}
}
}
if (s.charAt(0) == t.charAt(0)) {
StringBuilder ans = new StringBuilder();
for (i = 0; i < n; i++)
ans.append(s.charAt(1));
for (i = 0; i < n; i++)
ans.append(t.charAt(1));
for (i = 0; i < n; i++)
ans.append(s.charAt(0));
out.println("YES");
out.println(ans.toString());
return;
}
if (s.charAt(1) == t.charAt(1)) {
StringBuilder ans = new StringBuilder();
for (i = 0; i < n; i++)
ans.append(s.charAt(1));
for (i = 0; i < n; i++)
ans.append(t.charAt(0));
for (i = 0; i < n; i++)
ans.append(s.charAt(0));
out.println("YES");
out.println(ans.toString());
return;
}
if (s.charAt(0) == t.charAt(1) && s.charAt(1) == t.charAt(0)) {
StringBuilder ans = new StringBuilder();
for (i = 0; i < n; i++)
ans.append(s.charAt(0));
if (s.charAt(0) != 'a' && s.charAt(1) != 'a')
for (i = 0; i < n; i++)
ans.append('a');
if (s.charAt(0) != 'b' && s.charAt(1) != 'b')
for (i = 0; i < n; i++)
ans.append('b');
if (s.charAt(0) != 'c' && s.charAt(1) != 'c')
for (i = 0; i < n; i++)
ans.append('c');
for (i = 0; i < n; i++)
ans.append(s.charAt(1));
out.println("YES");
out.println(ans.toString());
return;
}
}
StringBuilder ans = new StringBuilder();
for (j = 0; j < 3 * n; j++) {
ans.append(arr[i].charAt((j % 3)));
}
out.println("YES");
out.println(ans.toString());
}
}
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 println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | a48f7071ca82d569d3d690a3f9dc6117 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static class pair{
int cost;int occ;
pair(int x,int y){
cost=x;occ=y;
}
}
public static void main(String[] args) throws IOException {
MScanner sc=new MScanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
pw.println("YES");
int n=sc.nextInt();
char[]s=sc.nextLine().toCharArray();
char[]t=sc.nextLine().toCharArray();
if(s[0]==t[1] && s[1]==t[0] && s[0]!=s[1]) {
for(int i=0;i<n;i++)pw.print(s[0]);
TreeSet<Character>ts=new TreeSet<Character>();
ts.add('a');ts.add('b');ts.add('c');
ts.remove(s[0]);ts.remove(s[1]);
for(int i=0;i<n;i++)pw.print(ts.first());
for(int i=0;i<n;i++)pw.print(s[1]);
}
else {
if(s[0]==t[0] && s[1]!=t[1] && s[1]!=s[0] && t[1]!=t[0]) {
for(int i=0;i<n;i++) {
pw.print(s[1]);
}
for(int i=0;i<n;i++) {
pw.print(t[1]);
}
for(int i=0;i<n;i++) {
pw.print(s[0]);
}
}
else {
if(s[1]==t[1] && s[0]!=t[0] && s[1]!=s[0] && t[1]!=t[0]) {
for(int i=0;i<n;i++) {
pw.print(s[1]);
}
for(int i=0;i<n;i++) {
pw.print(t[0]);
}
for(int i=0;i<n;i++) {
pw.print(s[0]);
}
}
else {
ArrayList<Character>p=new ArrayList<Character>();
if(s[0]!=s[1]) {
p.add(s[1]);p.add(s[0]);
}
else {
p.add(s[0]);
}
if(t[0]!=t[1]) {
int idx=p.indexOf(t[1]);
if(idx!=-1) {
if(!p.contains(t[0]))
p.add(idx+1, t[0]);
}
else {
int indx=p.indexOf(t[0]);
if(indx!=-1) {
if(!p.contains(t[1]))
p.add(indx, t[1]);
}
else {
if(!p.contains(t[1]))
p.add(t[1]);
if(!p.contains(t[0]))
p.add(t[0]);
}
}
}
if(!p.contains('a')) {
p.add('a');
}
if(!p.contains('b')) {
p.add('b');
}
if(!p.contains('c')) {
p.add('c');
}
String x=p.get(0)+""+p.get(1)+""+p.get(2);
for(int i=0;i<n;i++)pw.print(x);
}
}
}
pw.flush();
}
static class MScanner {
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public MScanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | c41f6117dd06dfef1af5c334e9090d2e | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class TaskE {
public static void main(String[] arg) {
final FastScanner in = new FastScanner(System.in);
final PrintWriter out = new PrintWriter(System.out);
final int n = in.nextInt();
final String a = in.next();
final String b = in.next();
Solution solution = new Solution();
String sol = solution.solution(n, a, b);
if (sol.isEmpty()) {
out.println("NO");
} else {
out.println("YES");
out.println(sol);
}
out.close();
in.close();
}
private static class Solution {
private String solution(final int n, final String a, final String b) {
String [] perm = {"abc", "acb", "bac", "bca", "cab", "cba"};
for(String s:perm) {
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++) {
sb.append(s);
}
String res = sb.toString();
if(res.contains(a)==false && res.contains(b)==false) {
return res;
}
sb = new StringBuilder();
for(int i=0;i<3*n;i++) {
sb.append(s.charAt(i/n));
}
res = sb.toString();
if(res.contains(a)==false && res.contains(b)==false) {
return res;
}
}
return "";
}
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream stream) {
try {
br = new BufferedReader(new InputStreamReader(stream));
} catch (Exception e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readIntArr(int n) {
int[] result = new int[n];
for (int i = 0; i < n; i++) {
result[i] = Integer.parseInt(next());
}
return result;
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 1b50cffb314015517c58ece48af0476a | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class E {
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
static InputReader r = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
int n = r.nextInt();
ArrayList<String> list = new ArrayList<String>();
list.add(r.next()); list.add(r.next());
Collections.sort(list);
pw.println("YES");
if(list.get(0).equals(list.get(1))){
if(list.get(0).equals("aa")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(0).equals("ab")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(0).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(0).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(0).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(0).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
} else if(list.get(0).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(0).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(0).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
}
if(list.get(0).equals("aa")){
if(list.get(1).equals("ab")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("ab")){
if(list.get(1).equals("ac")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("a");
}
} else if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("ac");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("bac");
}
}
} else if(list.get(0).equals("ac")){
if(list.get(1).equals("ba")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("ba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("ba")){
if(list.get(1).equals("bb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("c");
}
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("bc");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("bca");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("bb")){
if(list.get(1).equals("bc")){
for(int i = 0; i < n; i++){
pw.print("cba");
}
} else if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("abc");
}
}
} else if(list.get(0).equals("bc")){
if(list.get(1).equals("ca")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
} else if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
}
} else if(list.get(0).equals("ca")){
if(list.get(1).equals("cb")){
for(int i = 0; i < n; i++){
pw.print("a");
}
for(int i = 0; i < n; i++){
pw.print("b");
}
for(int i = 0; i < n; i++){
pw.print("c");
}
} else if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("acb");
}
}
} else if(list.get(0).equals("cb")){
if(list.get(1).equals("cc")){
for(int i = 0; i < n; i++){
pw.print("cab");
}
}
}
pw.println();
pw.close();
}
}
/**
* _ _ _
* | | | | | |
* ___ ___ __| | ___ | |__ _ _ __| | __ _ _ __ _ __ ___ _ __ _ _ __ _ ___
* / __/ _ \ / _` |/ _ \ | '_ \| | | | / _` |/ _` | '__| '__/ _ \ '_ \ | | | |/ _` |/ _ \
* | (_| (_) | (_| | __/ | |_) | |_| | | (_| | (_| | | | | | __/ | | | | |_| | (_| | (_) |
* \___\___/ \__,_|\___| |_.__/ \__, | \__,_|\__,_|_| |_| \___|_| |_| \__, |\__,_|\___/
* __/ | ______ __/ |
* |___/ |______|___/
*/ | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 88433ca107fa4efc3e522f092fbdc5f5 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
static char c1,c2,c3,c4;
public static boolean check(StringBuilder s)
{
for(int i=0;i<s.length()-1;i++)
{
if(s.charAt(i)==c1 && s.charAt(i+1)==c2)
return false;
if(s.charAt(i)==c3 && s.charAt(i+1)==c4)
return false;
}
return true;
}
public static void main (String[] args)throws IOException {
//code
FastReader in=new FastReader(System.in);
StringBuilder sb=new StringBuilder();
int i,j,sum,cost,k;
int n=in.nextInt();
String s1=in.nextLine();
String s2=in.nextLine();
StringBuilder sb1;
char ch1,ch2,ch3;
c1=s1.charAt(0);
c2=s1.charAt(1);
c3=s2.charAt(0);
c4=s2.charAt(1);
String comb[]={"abc","acb","bac","bca","cab","cba"};
for(i=0;i<6;i++)
{
ch1=comb[i].charAt(0);
ch2=comb[i].charAt(1);
ch3=comb[i].charAt(2);
sb1=new StringBuilder();
for(j=0;j<n;j++)
sb1.append(comb[i]);
if(check(sb1))
{
System.out.println("YES\n"+sb1);
System.exit(0);
}
sb1=new StringBuilder();
for(j=0;j<3;j++)
{
for(k=0;k<n;k++)
sb1.append(comb[i].charAt(j));
}
if(check(sb1))
{
System.out.println("YES\n"+sb1);
System.exit(0);
}
}
System.out.println("NO");
}
}
class Node implements Comparable<Node>
{
int val,pos;
public Node(int val,int pos)
{
this.val=val;
this.pos=pos;
}
public int compareTo(Node x)
{
if(this.val>x.val)
return -1;
else if(this.val<x.val)
return 1;
else
return 0;
}
}
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();
}
String nextLine() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c != 10 && c != 13; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
char nextChar() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
return (char) c;
}
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 | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 004c15a258609d8787f0045dec07fc1c | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class E582TwoSmallStrings {
static PrintWriter pr = new PrintWriter(System.out);
public static class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt();
String s = in.next();
String t = in.next();
ans(n,s,t);
pr.flush();
}
private static void ans(int n, String s, String t) {
String[] buf = { "abc", "acb", "cba", "bca", "bac", "cab"};
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 6; i++) {
StringBuilder str = new StringBuilder();
for (int j = 0; j < n; j++) {
str.append(buf[i]);
}
list.add(new String(str));
str = new StringBuilder();
for (int j = 0; j < 3; j++) {
for (int k = 0; k < n; k++) {
str.append(buf[i].charAt(j));
}
}
list.add(new String(str));
}
for (String str: list) {
if (!str.contains(s) && !str.contains(t)){
pr.println("YES");
pr.print(str);
return;
}
}
pr.print("NO");
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | a63420eb76b569bc37e48ff0cef21c18 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class E implements Runnable {
FastReader scn;
PrintWriter out;
String INPUT = "";
void solve() {
int n = scn.nextInt();
String s1 = scn.next(), s2 = scn.next();
if(c1(s1) && c1(s2)) {
String s = "abc";
out.println("YES");
for(int i = 0; i < n; i++) {
out.print(s);
}
out.println();
return;
}
if(c2(s1) && c2(s2)) {
String s = "bac";
out.println("YES");
for(int i = 0; i < n; i++) {
out.print(s);
}
out.println();
return;
}
if(c3(s1) && c3(s2)) {
out.println("YES");
for(int i = 0; i < n; i++) {
out.print('b');
}
for(int i = 0; i < n; i++) {
out.print('c');
}
for(int i = 0; i < n; i++) {
out.print('a');
}
out.println();
return;
}
if(c4(s1) && c4(s2)) {
out.println("YES");
for(int i = 0; i < n; i++) {
out.print('a');
}
for(int i = 0; i < n; i++) {
out.print('c');
}
for(int i = 0; i < n; i++) {
out.print('b');
}
out.println();
return;
}
if(c5(s1) && c5(s2)) {
out.println("YES");
for(int i = 0; i < n; i++) {
out.print('b');
}
for(int i = 0; i < n; i++) {
out.print('a');
}
for(int i = 0; i < n; i++) {
out.print('c');
}
out.println();
return;
}
if(c6(s1, s2)) {
out.println("YES");
for(int i = 0; i < n; i++) {
out.print('a');
}
for(int i = 0; i < n; i++) {
out.print('b');
}
for(int i = 0; i < n; i++) {
out.print('c');
}
out.println();
return;
}
if(c7(s1, s2)) {
out.println("YES");
for(int i = 0; i < n; i++) {
out.print('c');
}
for(int i = 0; i < n; i++) {
out.print('b');
}
for(int i = 0; i < n; i++) {
out.print('a');
}
out.println();
return;
}
out.println("NO");
}
boolean c1(String s) {
if(s.equals("ab") || s.equals("bc") || s.equals("ca")) {
return false;
}
return true;
}
boolean c2(String s) {
if(s.equals("ac") || s.equals("ba") || s.equals("cb")) {
return false;
}
return true;
}
boolean c3(String s) {
if(s.equals("bc") || s.equals("ca")) {
return false;
}
return true;
}
boolean c4(String s) {
if(s.equals("ac") || s.equals("cb")) {
return false;
}
return true;
}
boolean c5(String s) {
if(s.equals("ba") || s.equals("ac")) {
return false;
}
return true;
}
boolean c6(String s1, String s2) {
if(s1.equals("ac") && s2.equals("ca")) {
return true;
}
if(s2.equals("ac") && s1.equals("ca")) {
return true;
}
return false;
}
boolean c7(String s1, String s2) {
if(s1.equals("bc") && s2.equals("ac")) {
return true;
}
if(s2.equals("bc") && s1.equals("ac")) {
return true;
}
return false;
}
public void run() {
long time = System.currentTimeMillis();
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
out = new PrintWriter(System.out);
scn = new FastReader(oj);
solve();
out.flush();
if (!oj) {
System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
}
}
public static void main(String[] args) {
new Thread(null, new E(), "Main", 1 << 26).start();
}
class FastReader {
InputStream is;
public FastReader(boolean onlineJudge) {
is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
}
byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
double nextDouble() {
return Double.parseDouble(next());
}
char nextChar() {
return (char) skip();
}
String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
String nextLine() {
int b = skip();
StringBuilder sb = new StringBuilder();
while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
char[] next(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
char[][] nextMatrix(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = next(m);
return map;
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] next2DInt(int n, int m) {
int[][] arr = new int[n][];
for (int i = 0; i < n; i++) {
arr[i] = nextIntArray(m);
}
return arr;
}
long[][] next2DLong(int n, int m) {
long[][] arr = new long[n][];
for (int i = 0; i < n; i++) {
arr[i] = nextLongArray(m);
}
return arr;
}
int[] shuffle(int[] arr) {
Random r = new Random();
for (int i = 1, j; i < arr.length; i++) {
j = r.nextInt(i);
int c = arr[i];
arr[i] = arr[j];
arr[j] = c;
}
return arr;
}
long[] shuffle(long[] arr) {
Random r = new Random();
for (int i = 1, j; i < arr.length; i++) {
j = r.nextInt(i);
long c = arr[i];
arr[i] = arr[j];
arr[j] = c;
}
return arr;
}
int[] uniq(int[] arr) {
arr = scn.shuffle(arr);
Arrays.sort(arr);
int[] rv = new int[arr.length];
int pos = 0;
rv[pos++] = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] != arr[i - 1]) {
rv[pos++] = arr[i];
}
}
return Arrays.copyOf(rv, pos);
}
long[] uniq(long[] arr) {
arr = scn.shuffle(arr);
Arrays.sort(arr);
long[] rv = new long[arr.length];
int pos = 0;
rv[pos++] = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] != arr[i - 1]) {
rv[pos++] = arr[i];
}
}
return Arrays.copyOf(rv, pos);
}
int[] reverse(int[] arr) {
int l = 0, r = arr.length - 1;
while (l < r) {
arr[l] = arr[l] ^ arr[r];
arr[r] = arr[l] ^ arr[r];
arr[l] = arr[l] ^ arr[r];
l++;
r--;
}
return arr;
}
long[] reverse(long[] arr) {
int l = 0, r = arr.length - 1;
while (l < r) {
arr[l] = arr[l] ^ arr[r];
arr[r] = arr[l] ^ arr[r];
arr[l] = arr[l] ^ arr[r];
l++;
r--;
}
return arr;
}
int[] compress(int[] arr) {
int n = arr.length;
int[] rv = Arrays.copyOf(arr, n);
rv = uniq(rv);
for (int i = 0; i < n; i++) {
arr[i] = Arrays.binarySearch(rv, arr[i]);
}
return arr;
}
long[] compress(long[] arr) {
int n = arr.length;
long[] rv = Arrays.copyOf(arr, n);
rv = uniq(rv);
for (int i = 0; i < n; i++) {
arr[i] = Arrays.binarySearch(rv, arr[i]);
}
return arr;
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 76590fe29a772c0727a5c0d2a3895c4e | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | // package Quarantine;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
public class SmallStrings {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String a=br.readLine();
String b=br.readLine();
HashSet<String> poss=new HashSet<>();
String com[]={"abc","acb","bac","bca","cab","cba"};
for(int i=0;i<6;i++){
String str=com[i];
poss.add(getStr(str,n));
StringBuilder temp=new StringBuilder();
for(int j=0;j<3;j++){
temp.append(getStr(str.charAt(j)+"",n));
}
poss.add(temp.toString());
}
for(String str:poss){
if(possible(str,a,b)){
System.out.println("YES");
System.out.println(str);
return;
}
}
System.out.println("NO");
}
public static String getStr(String str,int n){
StringBuilder ans=new StringBuilder();
for(int i=0;i<n;i++){
ans.append(str);
}
return ans.toString();
}
public static boolean possible(String str,String a,String b){
for(int i=0;i+1<str.length();i++){
String temp=str.substring(i,i+2);
if(a.compareTo(temp)==0||b.compareTo(temp)==0){
return false;
}
}
return true;
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 5ea0678e603381132b9f8bdd52908844 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* 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 sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, sc, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader sc, PrintWriter out) {
String[] buf= {"abc","acb","bac","bca","cab","cba"};
int n=sc.nextInt();
String s=sc.next();
String t=sc.next();
ArrayList<String> res=new ArrayList<String>();
for(int i=0;i<buf.length;i++) {
StringBuilder temp=new StringBuilder();
for(int j=0;j<n;j++)
temp.append(buf[i]);
res.add(new String(temp));
temp=new StringBuilder();
for(int j=0;j<n;j++)
temp.append(buf[i].charAt(0));
for(int j=0;j<n;j++)
temp.append(buf[i].charAt(1));
for(int j=0;j<n;j++)
temp.append(buf[i].charAt(2));
res.add(new String(temp));
}
for(String temp:res) {
if(!temp.contains(s)&&!temp.contains(t)) {
out.println("YES");
out.println(temp);
return ;
}
}
out.println("NO");
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 7cdcebc2f4a9ff6eea286277420c8f9f | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | //package cf582d3;
import java.io.*;
import java.util.*;
public class E {
static char[] s, t;
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int n = sc.nextInt();
s = sc.nextLine().toCharArray();
t = sc.nextLine().toCharArray();
out.println("YES");
if(s[0] == s[1] && t[0] == t[1]) {
for(int i = 0; i < n; i++)
out.print("abc");
} else if(s[0] == s[1] || t[0] == t[1]) {
if(s[0] == s[1]) swap();
if(s[0] == t[0] || s[1] == t[0]) {
char c = (char)('a' + 'b' + 'c' - s[0] - s[1]);
char d = (char)(s[0] + s[1] - t[0]);
for(int i = 0; i < n; i++)
out.print(d);
for(int i = 0; i < n; i++)
out.print(c + "" + t[0]);
} else {
for(int i = 0; i < n; i++)
out.print(s[0]);
for(int i = 0; i < n; i++)
out.print(t[0] + "" + s[1]);
}
} else if(s[0] == t[1] && s[1] == t[0]) {
char c = (char)('a' + 'b' + 'c' - s[0] - s[1]);
for(int i = 0; i < n; i++)
out.print(s[0]);
for(int i = 0; i < n; i++)
out.print(c);
for(int i = 0; i < n; i++)
out.print(s[1]);
} else {
if(s[0] == t[0]) {
for(int i = 0; i < 3; i++)
if(i + 'a' != s[0])
for(int j = 0; j < n; j++)
out.print((char)(i + 'a'));
for(int i = 0; i < n; i++)
out.print(s[0]);
} else {
if(s[0] != t[1]) swap();
for(int i = 0; i < n; i++)
out.print(s[1]);
for(int i = 0; i < n; i++)
out.print(s[0]);
for(int i = 0; i < n; i++)
out.print(t[0]);
}
}
out.close();
}
static void swap() {
char[] x = {s[0], s[1]};
s = new char[] {t[0], t[1]};
t = new char[] {x[0], x[1]};
}
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static class MyScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreElements())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException 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\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | a77db49ce4c3cb4aa95652984815644e | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n=Integer.parseInt(in.nextLine());
String s=in.nextLine(),t=in.nextLine();
if(s.equals("aa")||s.equals("bb")||s.equals("cc")) {
if(t.equals("aa")||t.equals("bb")||t.contentEquals("cc")|| (!t.equals("ab")&&!t.equals("bc")&&!t.equals("ca"))) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("abc");
}
}else {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("cba");
}
}
}else if(t.equals("aa")||t.equals("bb")||t.equals("cc")) {
if(!s.equals("ab") && !s.equals("bc") && !s.equals("ca")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("abc");
}
}else {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("cba");
}
}
}else {
if(!s.equals("ab")&&!s.equals("bc")&&!t.equals("ab")&&!t.equals("bc")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("a");
}
for(int i=0;i<n;i++) {
System.out.print("b");
}
for(int i=0;i<n;i++) {
System.out.print("c");
}
}else if(!s.equals("cb")&&!s.equals("ba")&&!t.equals("cb")&&!t.equals("ba")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("c");
}
for(int i=0;i<n;i++) {
System.out.print("b");
}
for(int i=0;i<n;i++) {
System.out.print("a");
}
}else if(!s.equals("ab")&&!s.equals("ca")&&!t.equals("ab")&&!t.equals("ca")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("c");
}
for(int i=0;i<n;i++) {
System.out.print("a");
}
for(int i=0;i<n;i++) {
System.out.print("b");
}
}else if(!s.equals("ac")&&!s.equals("cb")&&!t.equals("ac")&&!t.equals("cb")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("a");
}
for(int i=0;i<n;i++) {
System.out.print("c");
}
for(int i=0;i<n;i++) {
System.out.print("b");
}
}else if(!s.equals("bc")&&!s.equals("ca")&&!t.equals("bc")&&!t.equals("ca")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("b");
}
for(int i=0;i<n;i++) {
System.out.print("c");
}
for(int i=0;i<n;i++) {
System.out.print("a");
}
}else if(!s.equals("ba")&&!s.equals("ac")&&!t.equals("ba")&&!t.equals("ac")) {
System.out.println("YES");
for(int i=0;i<n;i++) {
System.out.print("b");
}
for(int i=0;i<n;i++) {
System.out.print("a");
}
for(int i=0;i<n;i++) {
System.out.print("c");
}
}
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 963fd62c2bf8b8a4bda2d50eeee70ff6 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.util.NoSuchElementException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Ruins He
*/
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);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
static class TaskE {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
char[] s = in.nextChars();
char[] t = in.nextChars();
boolean[][] possible = new boolean[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
possible[i][j] = true;
}
}
possible[s[0] - 'a'][s[1] - 'a'] = false;
possible[t[0] - 'a'][t[1] - 'a'] = false;
String result = findOne(possible, n);
if (result != null) {
out.println("YES").println(result);
} else {
out.println("NO");
}
}
private String findOne(boolean[][] possible, int n) {
if (!possible[0][0] || !possible[1][1] || !possible[2][2]) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
continue;
}
for (int k = 0; k < 3; k++) {
if (i == k || j == k) {
continue;
}
if (possible[i][j] && possible[j][k] && (n == 1 || possible[k][i])) {
char[] chars = new char[3 * n];
for (int p = 0; p < chars.length; p++) {
int q = p % 3 == 0 ? i : (p % 3 == 1 ? j : k);
chars[p] = (char) (q + 'a');
}
return String.valueOf(chars);
}
}
}
}
} else {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
continue;
}
for (int k = 0; k < 3; k++) {
if (i == k || j == k) {
continue;
}
if (possible[i][j] && possible[j][k]) {
char[] chars = new char[3 * n];
Arrays.fill(chars, 0, n, (char) (i + 'a'));
Arrays.fill(chars, n, 2 * n, (char) (j + 'a'));
Arrays.fill(chars, 2 * n, 3 * n, (char) (k + 'a'));
return String.valueOf(chars);
}
}
}
}
}
return null;
}
}
static class OutputWriter {
private final PrintWriter writer;
private OutputWriter(Writer writer, boolean autoFlush) {
this.writer = new PrintWriter(new BufferedWriter(writer, 32767), autoFlush);
}
public OutputWriter(Writer writer) {
this(writer, true);
}
public OutputWriter(OutputStream outputStream) {
this(new OutputStreamWriter(outputStream), false);
}
public OutputWriter println(String string) {
writer.println(string);
return this;
}
public void close() {
writer.close();
}
}
static class InputReader {
public final BufferedReader reader;
public StringTokenizer tokenizer = null;
public InputReader(Reader reader) {
this.reader = new BufferedReader(reader, 32767);
}
public InputReader(InputStream inputStream) {
this(new InputStreamReader(inputStream));
}
public String next() {
if (hasNext()) return tokenizer.nextToken();
else throw new NoSuchElementException();
}
public int nextInt() {
return Integer.parseInt(next());
}
public char[] nextChars() {
return next().toCharArray();
}
public boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
String nextLine = reader.readLine();
if (nextLine == null) return false;
tokenizer = new StringTokenizer(nextLine);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.hasMoreTokens();
}
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | d694bde8fd655295d7bdd090a999e66b | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class CF {
public static boolean validTriplet(char positions[], HashSet<String>set){
int arrayLen = positions.length;
for(int i = 0;i < arrayLen;i++){
String currentString = positions[i] + "" + positions[(i + 1) % arrayLen];
if(set.contains(currentString)){
return false;
}
}
return true;
}
public static boolean validDoublet(char positions[], HashSet<String>set){
int arrayLen = positions.length;
for(int i = 0;i < arrayLen - 1;i++){
String currentString = positions[i] + "" + positions[i + 1];
if(set.contains(currentString)){
return false;
}
}
return true;
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String first = br.readLine();
String second = br.readLine();
HashSet<String>set = new HashSet<>();
set.add(first);
set.add(second);
char array[] = new char[]{'a', 'b', 'c'};
char triplet[] = null;
char doublet[] = null;
outer: for(int i = 0;i < array.length;i++){
char positions[] = new char[array.length];
positions[i] = 'a';
for(int j = 0;j < array.length;j++){
if(j == i){
continue;
}
positions[j] = 'b';
for(int k = 0;k < array.length;k++){
if(k == j || k == i){
continue;
}
positions[k] = 'c';
if(validTriplet(positions, set)){
triplet = positions.clone();
break outer;
}
if(validDoublet(positions, set)){
doublet = positions.clone();
}
}
}
}
StringBuilder sb = new StringBuilder();
if(triplet != null) {
System.out.println("YES");
for (int i = 1; i <= n; i++) {
for (int j = 0; j < triplet.length; j++) {
sb.append(triplet[j]);
}
}
} else if(doublet != null){
System.out.println("YES");
for(int i = 0;i < doublet.length;i++){
for(int j = 0;j < n;j++){
sb.append(doublet[i]);
}
}
} else {
System.out.println("NO");
}
System.out.println(sb);
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 19a8ffe491cd0692d5a86a06f1e2f6ca | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import sun.util.resources.cldr.ar.CalendarData_ar_YE;
import java.io.*;
import java.util.*;
public class l {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////// /////////
//////// /////////
//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////
//////// HHHH HHHH EEEEEEEEEEEEE MMMMMM MMMMMM OOO OOO SSSS SSS EEEEEEEEEEEEE /////////
//////// HHHH HHHH EEEEE MMMM MMM MMM MMMM OOO OOO SSSS SSS EEEEE /////////
//////// HHHH HHHH EEEEE MMMM MMMMMM MMMM OOO OOO SSSS EEEEE /////////
//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSSSSS EEEEE /////////
//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSS EEEEEEEEEEE /////////
//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSSS EEEEEEEEEEE /////////
//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSS EEEEE /////////
//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSS SSSS EEEEE /////////
//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOO OOO SSS SSSS EEEEEEEEEEEEE /////////
//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////
//////// /////////
//////// /////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
String s = sc.nextLine();
String t = sc.nextLine();
for (int i =0;i<3;i++)
for (int j =0;j<3;j++) {
if (i == j) continue;
for (int k = 0; k < 3; k++) {
if (i == k || j == k) continue;
String now = "";
now += (char) (i + 'a');
now += (char) (j + 'a');
now += (char) (k + 'a');
StringBuilder x = new StringBuilder();
for (int l = 0; l < n; l++) {
x.append(now);
}
String z = x.toString();
if (!z.contains(s) && !z.contains(t)) {
pw.println("YES");
pw.println(z);
pw.flush();
return;
}
x= new StringBuilder();
char ss=(char)(i+'a');
for (int l = 0; l < n; l++) {
x.append(ss);
}
ss=(char)(j+'a');
for (int l = 0; l < n; l++) {
x.append(ss);
}
ss=(char)(k+'a');
for (int l = 0; l < n; l++) {
x.append(ss);
}
z=x.toString();
if (!z.contains(s) && !z.contains(t)) {
pw.println("YES");
pw.println(z);
pw.flush();
return;
}
}
}
pw.println("NO");
pw.flush();
}
// static class pair implements Comparable<pair>{
// int u,v;
// pair(int a,int b){
// u=a;
// v=b;
// }
//
// @Override
// public int compareTo(pair pair) {
// return u==pair.u?v-pair.v:u-pair.u;
// }
// }
// static class Edge implements Comparable<Edge>{
// int node,cost;
// Edge(int a,int b){
// node=a;
// cost=b;
// }
//
// @Override
// public int compareTo(Edge edge) {
// return edge.cost-cost;
// }
// }
// static long gcd(long a, long b) {
// if (a == 0) return b;
// return gcd(b % a, a);
// }
//
// static int inver(long x, int mod) {
// int a = (int) x;
// int e = (mod - 2);
// int res = 1;
// while (e > 0) {
// if ((e & 1) == 1) {
// //System.out.println(res*a);
// res = (int) ((1l * res * a) % mod);
// }
// a = (int) ((1l * a * a) % mod);
// e >>= 1;
// }
// //out.println(res+" "+x);
// return res % mod;
// }
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 40eebcaad29e4c9dea6c9d711ac65dad | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
String s = reader.readLine();
String t = reader.readLine();
String[] perm = new String[] {"abc", "acb", "bac", "bca", "cab", "cba"};
for (String permString : perm) {
List<String> disallowed = new LinkedList<>();
disallowed.add("" + permString.charAt(0) + permString.charAt(1));
disallowed.add("" + permString.charAt(1) + permString.charAt(2) + "");
disallowed.add("" + permString.charAt(2) + permString.charAt(0) + "");
boolean ok = true;
for (String disString : disallowed) {
if (disString.equals(s) || disString.equals(t)) {
ok = false;
break;
}
}
if (ok) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < n; i++) {
builder.append(permString);
}
System.out.println("YES");
System.out.println(builder.toString());
return;
}
disallowed.clear();
if (n > 1) {
disallowed.add("aa");
disallowed.add("bb");
disallowed.add("cc");
}
disallowed.add("" + permString.charAt(0) + permString.charAt(1) + "");
disallowed.add("" + permString.charAt(1) + permString.charAt(2) + "");
ok = true;
for (String disString : disallowed) {
if (disString.equals(s) || disString.equals(t)) {
ok = false;
break;
}
}
if (ok) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
builder.append(permString.charAt(i));
}
}
System.out.println("YES");
System.out.println(builder.toString());
return;
}
}
System.out.println("NO");
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 70cb88b2444c2e6015f6a0c4d158aa77 | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class E
{
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok;
public void go() throws IOException
{
ntok();
int n = ipar();
ntok();
String s = spar();
ntok();
String t = spar();
String ans = "";
boolean allRep = false;
for (int i = 0; i < 3; i++)
{
for (int e = 0; e < 3; e++)
{
for (int w = 0; w < 3; w++)
{
if (i == e || e == w || i == w)
{
continue;
}
char[] word = new char[3];
word[i] = 'a';
word[e] = 'b';
word[w] = 'c';
String q = new String(word);
String qDouble = n > 1 ? q+q : q;
String rep;
if (n > 1)
{
rep = new String(new char[] {word[0], word[0], word[1], word[1], word[2], word[2]});
}
else
{
rep = q;
}
if (qDouble.indexOf(s) == -1 && qDouble.indexOf(t) == -1)
{
ans = q;
break;
}
else if (rep.indexOf(s) == -1 && rep.indexOf(t) == -1)
{
ans = q;
allRep = true;
break;
}
}
}
}
if (!ans.isEmpty())
{
out.println("YES");
if (!allRep)
{
for (int i = 0; i < n; i++)
{
out.print(ans);
}
out.println();
}
else
{
for (char c : ans.toCharArray())
{
for (int i = 0; i < n; i++)
{
out.print(c);
}
}
out.println();
}
}
else
{
out.println("NO");
}
out.flush();
in.close();
}
public void ntok() throws IOException
{
tok = new StringTokenizer(in.readLine());
}
public int ipar()
{
return Integer.parseInt(tok.nextToken());
}
public long lpar()
{
return Long.parseLong(tok.nextToken());
}
public double dpar()
{
return Double.parseDouble(tok.nextToken());
}
public String spar()
{
return tok.nextToken();
}
public static void main(String[] args) throws IOException
{
new E().go();
}
}
| Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 831dc5f8ed36c9639e6beac656ec48ec | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | /**
* BaZ :D
*/
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
static MyScanner scan;
static PrintWriter pw;
static long MOD = 1_000_000_007;
static long INF = 1_000_000_000_000_000_000L;
static long inf = 2_000_000_000;
public static void main(String[] args) {
new Thread(null,null,"BaZ",1<<27)
{
public void run()
{
try
{
solve();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static char a[], b[];
static void solve() throws IOException
{
//initIo(true);
initIo(false);
StringBuilder sb = new StringBuilder();
int n = ni();
a = ne().toCharArray();
b = ne().toCharArray();
String choices[] = {"abca", "acba", "bacb", "bcab", "cabc", "cbac"};
for(String s : choices) {
if(check(s)) {
pl("YES");
String res = s.substring(0, 3);
for(int i=0;i<n;++i) {
pw.print(res);
}
pl();
System.exit(0);
}
}
String choices_[] = {"abc", "acb", "bac", "bca", "cab", "cba"};
for(String s : choices_) {
if(check(s)) {
pl("YES");
char a = s.charAt(0), b = s.charAt(1), c = s.charAt(2);
for(int i=0;i<n;++i) {
pw.print(a);
}
for(int i=0;i<n;++i) {
pw.print(b);
}
for(int i=0;i<n;++i) {
pw.print(c);
}
pl();
System.exit(0);
}
}
pl("NO");
pw.flush();
pw.close();
}
static boolean check(String s) {
boolean match = false;
for(int i=0;i+1<s.length();++i) {
if(s.charAt(i)==a[0] && s.charAt(i+1)==a[1]) {
match = true;
}
if(s.charAt(i)==b[0] && s.charAt(i+1)==b[1]) {
match = true;
}
}
return !match;
}
static void initIo(boolean isFileIO) throws IOException {
scan = new MyScanner(isFileIO);
if(isFileIO) {
pw = new PrintWriter("/Users/amandeep/Desktop/output.txt");
}
else {
pw = new PrintWriter(System.out, true);
}
}
static int ni() throws IOException
{
return scan.nextInt();
}
static long nl() throws IOException
{
return scan.nextLong();
}
static double nd() throws IOException
{
return scan.nextDouble();
}
static String ne() throws IOException
{
return scan.next();
}
static String nel() throws IOException
{
return scan.nextLine();
}
static void pl()
{
pw.println();
}
static void p(Object o)
{
pw.print(o+" ");
}
static void pl(Object o)
{
pw.println(o);
}
static void psb(StringBuilder sb)
{
pw.print(sb);
}
static void pa(String arrayName, Object arr[])
{
pl(arrayName+" : ");
for(Object o : arr)
p(o);
pl();
}
static void pa(String arrayName, int arr[])
{
pl(arrayName+" : ");
for(int o : arr)
p(o);
pl();
}
static void pa(String arrayName, long arr[])
{
pl(arrayName+" : ");
for(long o : arr)
p(o);
pl();
}
static void pa(String arrayName, double arr[])
{
pl(arrayName+" : ");
for(double o : arr)
p(o);
pl();
}
static void pa(String arrayName, char arr[])
{
pl(arrayName+" : ");
for(char o : arr)
p(o);
pl();
}
static void pa(String listName, List list)
{
pl(listName+" : ");
for(Object o : list)
p(o);
pl();
}
static void pa(String arrayName, Object[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(Object o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, int[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(int o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, long[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(long o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, char[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(char o : arr[i])
p(o);
pl();
}
}
static void pa(String arrayName, double[][] arr) {
pl(arrayName+" : ");
for(int i=0;i<arr.length;++i) {
for(double o : arr[i])
p(o);
pl();
}
}
static class MyScanner
{
BufferedReader br;
StringTokenizer st;
MyScanner(boolean readingFromFile) throws IOException
{
if(readingFromFile) {
br = new BufferedReader(new FileReader("/Users/amandeep/Desktop/input.txt"));
}
else {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
String nextLine()throws IOException
{
return br.readLine();
}
String next() throws IOException
{
if(st==null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
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());
}
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | 8898dbf05a8362ba34ff69fb27077b6f | train_000.jsonl | 1567175700 | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static int inf = (int) (1e9 + 7);
static char a[], b[];
static boolean check(char res[]) {
for(int i = 0;i < res.length - 1;i++) {
if (res[i] == a[0] && res[i + 1] == a[1]) return false;
if (res[i] == b[0] && res[i + 1] == b[1]) return false;
}
return true;
}
static void solve() throws IOException {
int n = sc.nextInt();
a = sc.next().toCharArray();
b = sc.next().toCharArray();
char one[][] = new char[6][3 * n];
char two[][] = new char[6][3 * n];
int p[][] = new int [6][3];
p[0][0] = 0; p[0][1] = 1; p[0][2] = 2;
p[1][0] = 0; p[1][1] = 2; p[1][2] = 1;
p[2][0] = 1; p[2][1] = 0; p[2][2] = 2;
p[3][0] = 1; p[3][1] = 2; p[3][2] = 0;
p[4][0] = 2; p[4][1] = 0; p[4][2] = 1;
p[5][0] = 2; p[5][1] = 1; p[5][2] = 0;
for(int i = 0;i < 3 * n;i++) {
for(int j = 0;j < 6;j++) {
one[j][i] = (char) ('a' + p[j][i / n]);
two[j][i] = (char) ('a' + p[j][i % 3]);
}
}
pw.println("YES");
for(int i = 0;i < 6;i++) {
if (check(one[i])) {
pw.println(one[i]);
return;
}
if (check(two[i])) {
pw.println(two[i]);
return;
}
}
}
public static void main(String[] args) throws IOException {
sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
solve();
pw.close();
}
static Scanner sc;
static PrintWriter pw;
static class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
Scanner(InputStream in) throws FileNotFoundException {
br = new BufferedReader(new InputStreamReader(in));
}
Scanner(String in) throws FileNotFoundException {
br = new BufferedReader(new FileReader(in));
}
String next() throws IOException {
while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
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());
}
}
}
class pair {
int x, y;
pair(int x, int y) {
this.x = x;
this.y = y;
}
pair() {
}
} | Java | ["2\nab\nbc", "3\naa\nbc", "1\ncb\nac"] | 2 seconds | ["YES\nacbbac", "YES\ncacbacbab", "YES\nabc"] | null | Java 8 | standard input | [
"constructive algorithms",
"brute force"
] | 7f45fba2c06fe176a2b634e8988076c2 | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. | 1,900 | If it is impossible to find the suitable string, print "NO" on the first line. Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them. | standard output | |
PASSED | a39629d614cd1f20997dd32d6439999d | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.io.*;
public class cubessorting {
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
FastScanner fs = new FastScanner();
int testcase = fs.nextInt();
//String strCurrentLine;
outer:
for (int tc = 0; tc < testcase; tc++) {
int digits = fs.nextInt();
//strCurrentLine = br.readLine();
//System.out.println(strCurrentLine);
// String[] arrays = strCurrentLine.split(" ");
int[] a = new int[digits];
for (int i = 0; i < digits; i++) {
a[i] = fs.nextInt();
// System.out.print(a[i]);
}
for (int i = 1; i < a.length; i++) {
if (a[i] >= a[i - 1]) {
System.out.println("YES");
continue outer;
}
}
System.out.println("NO");
}
out.close ();
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 8c2cb664e63a08fa089117965546bd74 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.lang.reflect.Array;
import java.util.*;
public class inser {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int t = 0; t < T; t++) {
int n = in.nextInt();
Integer a[] = new Integer[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
boolean d=true;
for(int i=0;i<n-1;i++){
if(a[i]<=a[i+1]){
System.out.println("YES");
d=false;
break;
}
}
if(d){
System.out.println("NO");
}
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 1d675ed40f93350e282266db96f035bb | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static int mod = 1000000007;
public static void solve(InputReader in, OutputWriter out) {
int n = in.readInt();
int a[] = new int[n];
for(int i = 0; i<n; i++){
a[i] = in.readInt();
}
boolean can = false;
for(int i = 1; i<n; i++){
if(a[i-1] <= a[i]) can = true;
}
if(can) System.out.println("YES");
else System.out.println("No");
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int t = in.readInt();
while (t-- > 0)
solve(in , out);
out.flush();
out.close();
}
}
class InputReader{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int 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 String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public 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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
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 println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 11e9598a82e214489346f6cd370de8fa | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.Scanner;
public class p1420A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
l: for (int t = sc.nextInt(); t-- > 0;) {
int n = sc.nextInt(), a[] = new int[n];
for (int i = 0; i < n; i++) a[i] = sc.nextInt();
for (int i = 0; i < n - 1; i++)
if (a[i] <= a[i + 1]) {
System.out.println("YES");
continue l;
}
System.out.println("No");
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 6165cace8826b9d73c0f38d0f347cc9a | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.Scanner;
public class p1420A {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
l: for (int t = sc.nextInt(); t-- > 0;) {
int n = sc.nextInt(), a[] = readArray(n);
for (int i = 0; i < n - 1; i++)
if (a[i] <= a[i + 1]) {
System.out.println("YES");
continue l;
}
System.out.println("No");
}
}
static int [] readArray(int n) {
int a[]=new int[n];
for (int i = 0; i < n; i++) a[i]=sc.nextInt();
return a;
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | ae523916f17c7f0138a811dd1a327682 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | public class TaskA {
public static void main(String []args){
java.util.Scanner scan = new java.util.Scanner(System.in);
int t = scan.nextInt();
for(int i = 0; i < t; i++) {
int N = scan.nextInt();
int[] a = new int[N];
for(int j = 0; j < N; j++) {
a[j] = scan.nextInt();
}
boolean order = true;
for(int j = 0; j < a.length-1; j++) {
if (a[j] <= a[j+1]) {
order = false;
}
}
if (!order) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | a5b43ab364466e41c4787e56b9f5d27d | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int test = scanner.nextInt();
while(test-->0){
int cubes = scanner.nextInt();
ArrayList<Integer> cubeVolume = new ArrayList<>();
for(int i=0 ; i<cubes ; i++){
cubeVolume.add(scanner.nextInt());
}
if(sort(cubeVolume)){
System.out.println("NO");
}
else
System.out.println("YES");
}
}
public static boolean sort(ArrayList<Integer> arr){
for(int i=0 ; i<(arr.size()-1); i++) {
if (arr.get(i) <= arr.get(i+1)) {
return false;
}
}
return true;
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 4133e1310e60a582c356783d8b5ba90d | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | // package Round672;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class typeA {
static long merge2(long[] A,int s, int mid, int n)
{
int i=s,j=mid,k=0;
long[] temp = new long[n-s+1];
long count=0;
while(i<mid && j<=n)
{
if(A[i]<=A[j])
{
temp[k++]=A[i++];
}
else
{
temp[k++]=A[j++];
count += mid-i;
}
}
while(i<mid){
temp[k++]=A[i++];
}
while(j<=n)
{
temp[k++]=A[j++];
}
for(i=s,k=0;i<=n;i++,k++)
{
A[i]=temp[k];
}
return count;
}
static long merge1(long[] A,int s, int n){
long count=0;
if(n>s)
{
int mid= (s+n)/2;
long left= merge1(A , s,mid);
long right= merge1( A,mid+1,n );
long merge= merge2( A, s, mid+1,n);
return merge+left+right;
}
return count;
}
public static void main(String[] args) {
FastReader s = new FastReader();
int T = s.nextInt();
while(T-- > 0) {
int i = 0;
int n = s.nextInt();
long[] arr = new long[n];
for(i=0;i<n;i++) {
arr[i]=s.nextLong();
}
for(i=1;i<n;i++) {
if(arr[i]>=arr[i-1]) break;;
}
if(i<n) {
System.out.println("YES");
}else {
System.out.println("NO");
}
// long turn = n*(n-1)/2 - 1;
// long p = merge1(arr,0,n-1);
// if(p<=turn )
// System.out.println("YES");
//
// else
// System.out.println("NO");
//
}
}
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 | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 73031d0d0d2c3c99f31cd047008fefee | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
for(int k=0;k<t;k++){
int n=Integer.parseInt(br.readLine());
String[] str=br.readLine().split(" ");
int ar[]=new int[n];
for(int i=0;i<n;i++){
ar[i]=Integer.parseInt(str[i]);
}
boolean flag=false;
for(int i=1;i<n;i++){
if(ar[i-1]<=ar[i]){
flag=true;
break;
}
}
if(flag){
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | cf04ec47505f9d59881b5e6ef51ce045 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class A {
public static void main (String[] args) throws java.lang.Exception {
InputReader in = new InputReader(System.in);
int t = in.readInt();
while(t-->0) {
int n =in.readInt();
int[]nums = new int[n];
boolean flag = false;
for(int i = 0;i<n;i++) {
int x = in.readInt();
nums[i] = x;
if(i>0) {
if(nums[i]>=nums[i-1]) {
flag = true;
}
}
}
if(flag) System.out.println("YES");
else System.out.println("NO");
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int 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 String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 03eb0053d7d34f46d175d0cc3bababd0 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
static PrintWriter out = new PrintWriter(System.out);
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().trim().split(" ");
int numTestCases = Integer.parseInt(input[0]);
while(numTestCases-- > 0){
input = br.readLine().trim().split(" ");
int n = Integer.parseInt(input[0]);
int[] arr = new int[n];
input = br.readLine().trim().split(" ");
for(int i = 0; i < n; i++){
arr[i] = Integer.parseInt(input[i]);
}
out.println(isPossible(arr));
}
out.flush();
out.close();
}
public static String isPossible(int[] arr)
{
int n = arr.length;
for(int i = 0; i < n - 1; i++){
if(arr[i] <= arr[i + 1])
{
return "YES";
}
}
return "NO";
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | fbcdfd2ce237f2488a8631c2249bd5f5 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class code4{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]){
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++){
ar[i]=sc.nextInt();
}
boolean flag=false;
for(int i=0;i<n-1;i++){
if(ar[i]<=ar[i+1]){flag=true;break;}
}
System.out.println(flag ?"YES":"NO");
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 394f9d55c75af795659a3e918c995282 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.util.regex.Pattern;
public class CubesSorting {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(); //
int count = 0;
for (int i=0; i<n; i++) { // Test cases
boolean yes = false;
int x = in.nextInt(); // number in case
// int[] a = new int[x];
int y = in.nextInt();
for (int j=1; j<x; j++) { // indiv. case
int z = in.nextInt();
if (z>=y) yes = true;
y=z;
} // end for j
System.out.println(yes? "YES": "NO");
/*
count = sort(a);
if (count < (x*(x-1)/2)){
System.out.println("YES");
} else {
System.out.println("NO");
}
*/
} // end for i
} // end main
public static int sort(int[] a) {
int n = a.length;
int counter = 0;
for (int i = 1; i < n; i++) {
// binary search to determine index j at which to insert a[i]
int v = a[i];
int lo = 0, hi = i;
while (lo < hi) {
int mid = (hi + lo) / 2;
if (v < a[mid]) hi = mid;
else lo = mid + 1;
}
// insertion sort with "half exchanges"
for (int j = i; j > lo; --j)
a[j] = a[j-1];
a[lo] = v;
counter += (i-lo);
}
return counter;
} // end sort
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 235d951e3e6a6ba9473fd322fff3d14d | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
* Always
*/
public class Always {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(reader.readLine().trim());
outer: for (int j = 0; j < t; ++j) {
int n = Integer.parseInt(reader.readLine().trim());
int[] arr = new int[n];
int i = 0;
for (String s : reader.readLine().trim().split("\\s+"))
arr[i++] = Integer.parseInt(s);
for (i = 0; i < arr.length - 1; ++i)
if (arr[i] <= arr[i + 1]) {
System.out.println("YES");
continue outer;
}
System.out.println("NO");
}
reader.close();
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 8cc3041c28cf06482c1e390a8fb10af2 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | //Written by Shagoto
import java.util.*;
import java.io.*;
public class Main
{
// -------- Generating Prime Numbers Using Bit-wise sieve --------
// static HashSet<Integer> primes = new HashSet<Integer>();
// static BitSet bs = new BitSet(10000001);
// static void sieve()
// {
// primes.add(2);
// for(int i = 4; i<=10000000; i+=2)
// {
// bs.set(i,true);
// }
//
// for(int i = 3; i<=10000000; i+=2)
// {
// if(!bs.get(i))
// {
// primes.add(i);
// for(int j = 3; i*j<=10000000; j+=2)
// {
// bs.set(i*j,true);
// }
// }
// }
// }
// -------- Lowerbound --------
// static int lowerBound(long [] arr, long x)
// {
// int low = 0;
// int high = arr.length - 1;
// int mid = 0;
// while(low < high)
// {
// mid = (start + end) / 2;
// int mid = (low + high) / 2;
//
// if(arr[mid] == x)
// {
// return mid;
// }
// else if(arr[mid] > x)
// {
// high = mid - 1;
// }
// else
// {
// low = mid + 1;
// }
// }
//
// if(arr[mid] > x)
// {
// if(mid - 1 >= 0 && arr[mid - 1] < x)
// {
// return mid - 1;
// }
// return -1;
// }
// return mid;
// }
// -------- Prefix Sum --------
// If zero indexed, add 1
// pref.add(0)
// pref.get(r) - pref.get(l - 1)
// xor(l, r) = pref[r]^pref[l - 1]
// -------- Ceil --------
// static int ceil(int n, int x)
// {
// if(n / x * x != n)
// {
// return n / x + 1;
// }
// return n / x;
// }
// -------- Phi Function --------
// static int phi(int n)
// {
// int ret = n;
// for(int i = 2; i*i <= n; i++)
// {
// if(n % i == 0)
// {
// while(n % i == 0)
// {
// n /= i;
// }
// ret -= ret / i;
// }
// }
//
// if(n > 1)
// {
// ret -= ret / n;
// }
// return ret;
// }
// -------- GCD of Two Numbers --------
// static int gcd(int a, int b)
// {
// if(b == 0)
// {
// return a;
// }
// return gcd(b, a % b);
// }
// -------- LCM of two Numbers --------
// static int lcm(int a, int b)
// {
// return (a * b) / gcd(a, b);
// }
// -------- Binary Search --------
// static int binarySearch(int [] arr, int x)
// {
// int low = 0;
// int high = arr.length - 1;
//
// while(low <= high)
// {
// int mid = (low + high) / 2;
//
// if(arr[mid] == x)
// {
// return mid;
// }
// else if(arr[mid] > x)
// {
// high = mid - 1;
// }
// else
// {
// low = mid + 1;
// }
// }
// return -1;
// }
public static void main(String[]args) throws IOException
{
/*
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader read = new BufferedReader(isr);
*/
Scanner read = new Scanner(System.in);
int t = read.nextInt();
for(int x = 1; x<=t; x++)
{
int n = read.nextInt();
int [] arr = new int[n];
int check = 0;
for(int i = 0; i<n; i++)
{
arr[i] = read.nextInt();
if(i > 0)
{
if(arr[i] < arr[i - 1])
{
check++;
}
}
}
if(check == n - 1)
{
System.out.println("NO");
}
else
{
System.out.println("YES");
}
}
}
}
// -------- Creating own Class --------
//class className
//{
// int v1;
// int v2;
// public className(int x, int y)
// {
// v1 = x;
// v2 = y;
// }
//
// public String toString()
// {
// return v1+" "+v2;
// }
//}
// -------- For Comparision or Sorting --------
// *Paste it in the main class*
//Collections.sort(arr, new Comparator<className>(){
// public int compare(className a, className b)
// {
// if(a.v1 == b.v1)
// {
// return b.v2 - a.v2;
// }
// else
// {
// return a.v1 - b.v1;
// }
// }
// }); | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | b09c98c7a7563eeddd5a0856b872cea5 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
public class CodeForces1420A{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for(int i = 0;i<t;i++){
int n = input.nextInt();
int[] a = new int[n];
int c = 0;
for(int j = 0;j<n;j++){
a[j] = input.nextInt();
}
for(int j = 0;j<n-1;j++){
if(a[j] > a[j+1]){
c++;
}
}
if(c == n-1){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | ced60e9bc24383b11769c8dc211e247a | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args){
MyScanner sc = new MyScanner();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
long[] arr = new long[n];
boolean same = false;
HashSet<Long> mp = new HashSet();
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
if(mp.contains(arr[i])){
same = true;
}
mp.add(arr[i]);
}
if(same){
System.out.println("YES");
continue;
}
boolean flag = false;
for(int i=1;i<n;i++){
if(arr[i] > arr[i-1]){
flag = true;
}
}
if(flag){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
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 | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 09608cd65b9934df8ab97fe7a745afd0 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | // package com.company;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main <E> {
public static void main(String[] args) {
Main main = new Main();
main.solve();
}
public void solve() {
Scanner in = null;
PrintWriter out = null;
try {
in = new Scanner(new File("input.txt"));
out = new PrintWriter(new File("output.txt"));
// throw new FileNotFoundException();
}
catch (FileNotFoundException e) {
in = new Scanner(System.in);
out = new PrintWriter(System.out);
}
int t = in.nextInt();
Integer a[] = new Integer[300000];
Integer b[] = new Integer[300000];
for (int ti = 0; ti < t; ti++) {
int n = in.nextInt();
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
b[i] = a[i];
}
Arrays.sort(a, 0, n, Collections.reverseOrder());
boolean equal = true;
for (int i = 0; i < n; i++) {
if (!a[i].equals(b[i])) {
equal = false;
break;
}
}
for (int i = 0; i < n - 1; i++) {
if (a[i].equals(a[i + 1])) {
equal = false;
}
}
out.println(equal ? "NO" : "YES");
}
// out.println();
// for (int i = 50000; i >= 1; i--) {
// int cur = 0;
// out.print(i + " ");
//// for (int j = 0; j < i; j++) {
//// cur= cur + j;
//// }
//// out.print( cur);
//// out.print( " ");
//// out.print(i* (i - 1) /2 - 1);
//// out.println();
// }
out.flush();
out.close();
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 8a20d3643b6bb3ec3be56e0d053c1ab6 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args){
FastReader sc=new FastReader();
long t=sc.nextLong();
StringBuilder sbf=new StringBuilder();
while(t-->0){
long n1 = sc.nextLong();
long arr[]=new long[(int)n1];
long max=0;
long index=0;
for(int i=0;i<(int)n1;i++){
arr[i]=sc.nextLong();
if(arr[i]>max) {
max=arr[i];
index=(long)i;
}
}
int n = arr.length;
boolean reversesorted=true;
for(int i=1;i<n;i++){
if((arr[i]>arr[i-1] || arr[i]==arr[i-1]) && reversesorted==true)
{
reversesorted=false;
}
}
if(reversesorted) System.out.println("NO");
else System.out.println("YES");
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 623d9ef1c5afaa6dfccfa62202a0c464 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
public class Cubesorting {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
long a[] = new long[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextLong();
}
boolean y = false;
for(int i=1;i<n;i++) {
if(a[i]>=a[i-1]) {
y=true;
break;
}
}
if(y) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 44968908e12894f3f6c1146261be4807 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
public class Cubesorting {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
long a[] = new long[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextLong();
}
boolean y = false;
for(int i=1;i<n;i++) {
if(a[i]>=a[i-1]) {
y=true;
break;
}
}
if(y) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | ca716cb00d604e69f5e1720ca783d661 | train_000.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.util.Scanner;
public class cubeSorting {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
int t = obj.nextInt();
for (int i = 0; i < t; i++) {
int n = obj.nextInt();
boolean flag = false;
int[] array = new int[n];
for (int j = 0; j < n; j++) {
array[j] = obj.nextInt();
}
for(int j = 1;j<n;j++) {
if(array[j]<array[j-1]) {
continue;
}else {
System.out.println("YES");
flag = true;
break;
}
}
if(!flag) {
System.out.println("NO");
}
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | bbafc6049d5bb6ec605436c8cca159f4 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[]=new int[n];
for (int i = 0; i <n ; i++) {
a[i]=sc.nextInt();
}if (n==1){
System.out.println(1); return;}
int k = 0;
int min =a[0];
for (int i = 0; i <n ; i++) {
if(min>=a[i])
{
min=a[i];
k=i+1;
}
}
Arrays.sort(a);
if (a[0]==a[1])
System.out.println("Still Rozdil");
else
System.out.println(k);
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 7264a47219dd22ce0682e9e69688d3b0 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class Elephant
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
int n = console.nextInt();
int min = console.nextInt();
int numRep = 1;
int numCity = 1;
int next;
for(int i = 2; i <= n; i++)
{
next = console.nextInt();
if(next < min){
min = next;
numRep = 1;
numCity = i;
}else if(next == min){
numRep ++;
}
}
if(numRep > 1){
System.out.print("Still Rozdil");
}else{
System.out.print(numCity);
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | adc80881fc945d2bf17411a600de94e1 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class privet {
public static void main(String[] args) throws IOException {
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
String kolvo = bReader.readLine();
int numb = Integer.parseInt(kolvo);
String stroka = bReader.readLine();
String s_array[] = stroka.split("\\s+");
int[] int_array = new int[numb];
for (int i = 0; i < numb; i++) {
int_array[i] = Integer.parseInt(s_array[i]);
}
int min=int_array[0], k=0, index=0;
for (int i=1; i<numb; i++)
{
if (int_array[i]==min)
{
k++;
}
else if (int_array[i]<min)
{
min=int_array[i];
index=i;
k=0;
}
}
if (k>0) System.out.println("Still Rozdil");
else if (k==0) System.out.println(index+1);
}
}
/*import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class privet {
static void swap(int[] arr, int i, int j) {
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
static void bubblesort(int[] arr) {
for (int i = arr.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (arr[j] > arr[j + 1])
swap(arr, j, j + 1);
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
String stroka2 = bReader.readLine();
String stroka = bReader.readLine();
// if(stroka != null){ }
String s_array[] = stroka.split("\\s+");// На эту строку ругается
int[] int_array = new int[s_array.length];
for (int i = 0; i < int_array.length; i++) {
int_array[i] = Integer.parseInt(s_array[i]);
}
int[] sorted = new int[int_array.length];
for (int i = 0; i < int_array.length; i++) {
sorted[i] = int_array[i];
}
// сотрировка пузарьком
bubblesort(sorted);
// если первые два эл =, то не едем, иначе ищем номер элемента в
// неотсортированном
if (int_array.length==1) System.out.println("1");
else if (sorted[0] == sorted[1]) {
System.out.println("Still Rozdil");
} else {
for (int i = 0; i < int_array.length; i++) {
if (int_array[i] == sorted[0]) {
System.out.println(i + 1);
}
}
}
}
}
*/ | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 6571c583222d47c30ae177e4c8b0bc6d | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;
/*
ID: he.andr1
LANG: JAVA
TASK: PrA
*/
public class PrA {
public static long time;
public static void main(String[] args) throws Exception {
time = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
go(br, System.out);
br.close();
System.exit(0);
}
public static void go(BufferedReader br, PrintStream out) throws Exception {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int min = Integer.MAX_VALUE;
String output = "Still Rozdil";
for(int i = 1; i <= n; i++) {
int cur = Integer.parseInt(st.nextToken());
if(cur < min) {
min = cur;
output = Integer.toString(i);
} else if (cur == min) output = "Still Rozdil";
}
out.println(output);
}
public static void checkTime() {
System.out.println(System.currentTimeMillis() - time);
time = System.currentTimeMillis();
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 7388eadfe20005984abc693f73efb8b0 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;
/*
ID: he.andr1
LANG: JAVA
TASK: PrA
*/
public class PrA {
public static long time;
public static void main(String[] args) throws Exception {
time = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
go(br, System.out);
br.close();
System.exit(0);
}
public static void go(BufferedReader br, PrintStream out) throws Exception {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int min = Integer.MAX_VALUE;
String output = "Still Rozdil";
for(int i = 1; i <= n; i++) {
int cur = Integer.parseInt(st.nextToken());
if(cur < min) {
min = cur;
output = Integer.toString(i);
} else if (cur == min) output = "Still Rozdil";
}
out.println(output);
}
public static void checkTime() {
System.out.println(System.currentTimeMillis() - time);
time = System.currentTimeMillis();
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | ff8b65d31241e4f69878c14c91449878 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
public class A {
public static void main(String[] Args) throws IOException {
new A().solve();
}
int o = 0;
void solve() throws IOException {
String s="Still Rozdil";
tok();
int n = toki();
int c =0;
long m = LINF;
int x=0;
tok();
for (int i = 1; i <= n; i++) {
long d = tokl();
if ( d < m) {
c=1;
m=d;
x =i;
} else if (d==m){
c++;
}
}
System.out.println(c>1?s: x);
}
// ----------------------- Library ------------------------
void comparator() {
Point[] v = new Point[10];
Arrays.sort(v, new Comparator<Point>() {
@Override
public int compare(Point a, Point b) {
if (a.x != b.x)
return -(a.x - b.x);
return a.y - b.y;
}
});
}
double distance(Point a, Point b) {
double dx = a.x - b.x, dy = a.y - b.y;
return Math.sqrt(dx * dx + dy * dy);
}
Scanner in = new Scanner(System.in);
String ss() {
return in.next();
}
String sline() {
return in.nextLine();
}
int si() {
return in.nextInt();
}
int[] sai(int n) {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
return a;
}
int[] sai_(int n) {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
return a;
}
BufferedReader br;
StringTokenizer tokenizer;
{
br = new BufferedReader(new InputStreamReader(System.in));
}
void tok() throws IOException {
tokenizer = new StringTokenizer(br.readLine());
}
int toki() throws IOException {
return Integer.parseInt(tokenizer.nextToken());
}
int[] rint(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++)
a[i] = Integer.parseInt(tokenizer.nextToken());
return a;
}
int[] rint_(int n) throws IOException {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++)
a[i] = Integer.parseInt(tokenizer.nextToken());
return a;
}
String[] rstrlines(int n) throws IOException {
String[] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = br.readLine();
}
return a;
}
long tokl() {
return Long.parseLong(tokenizer.nextToken());
}
double tokd() {
return Double.parseDouble(tokenizer.nextToken());
}
String toks() {
return tokenizer.nextToken();
}
String rline() throws IOException {
return br.readLine();
}
List<Integer> toList(int[] a) {
List<Integer> v = new ArrayList<Integer>();
for (int i : a)
v.add(i);
return v;
}
static void pai(int[] a) {
System.out.println(Arrays.toString(a));
}
static int toi(Object s) {
return Integer.parseInt(s.toString());
}
static int[] dx_ = { 0, 0, 1, -1 };
static int[] dy_ = { 1, -1, 0, 0 };
static int[] dx3 = { 1, -1, 0, 0, 0, 0 };
static int[] dy3 = { 0, 0, 1, -1, 0, 0 };
static int[] dz3 = { 0, 0, 0, 0, 1, -1 };
static int[] dx = { 1, 0, -1, 1, -1, 1, 0, -1 }, dy = { 1, 1, 1, 0, 0, -1,
-1, -1 };
static int INF = 2147483647; // =2^31-1 // -8
static long LINF = 922337203854775807L; // -8
static short SINF = 32767; // -32768
// finds GCD of a and b using Euclidian algorithm
public int GCD(int a, int b) {
if (b == 0)
return a;
return GCD(b, a % b);
}
static List<String> toList(String[] a) {
return Arrays.asList(a);
}
static String[] toArray(List<String> a) {
String[] o = new String[a.size()];
a.toArray(o);
return o;
}
static int[] pair(int... a) {
return a;
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | d070e5f43db06ac37f0b9ae0175ebbfa | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import static java.util.Arrays.deepToString;
import java.io.*;
import java.util.*;
public class A {
static void solve() throws Exception {
int n = nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = nextInt();
}
int min = Integer.MAX_VALUE;
int j = 0;
for(int i = 0; i < n; i++){
if(min > a[i]){
min = a[i];
j = i;
}
}
for(int i = 0; i < n; i++){
if(min == a[i] && i != j){
System.out.print("Still Rozdil");
return;
}
}
System.out.print(j + 1);
}
static BufferedReader br;
static StringTokenizer st;
static PrintWriter out;
static void debug(Object... a) {
System.err.println(deepToString(a));
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) {
try {
br = new BufferedReader(new InputStreamReader(System.in));
solve();
br.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 6b6b9e8f09b92051b6298cf2b66f1141 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Locale;
public class A205
{
public static void main(String[] args) throws IOException
{
setStandardIO();
//setFileIO("a205");
int n = nextInt();
int tab[] = new int[n];
for (int i = 0; i < n; i++)
tab[i] = nextInt();
int k = -1;
int m = Integer.MAX_VALUE;
for (int i = 0; i < tab.length; i++)
if (tab[i] < m) {
m = tab[i];
k = i;
}
int c = 0;
for (int i = 0; i < tab.length; i++)
if (tab[i] == m) ++c;
if (c > 1)
println("Still Rozdil");
else
println(k + 1);
flush();
}
// ~ -----------------------------------------------------------------------
// ~ - Auxiliary code ------------------------------------------------------
// ~ -----------------------------------------------------------------------
static InputStream in;
static PrintWriter out;
/**
* Simple buffered reader class. Reads if buffer is empty. Try to fill up
* whole buffer.
*/
public static class SimpleBufferedInputStream extends InputStream
{
// ~ Static fields / Initializers --------------------------------------
private static int defaultCharBufferSize = 16384;
private InputStream in;
byte[] buffer;
int pos = 0;
int len = 0;
// ~ Constructors ------------------------------------------------------
public SimpleBufferedInputStream(InputStream in) {
this(in, defaultCharBufferSize);
}
public SimpleBufferedInputStream(InputStream in, int size) {
this.in = in;
this.buffer = new byte[size];
}
// ~ Methods -----------------------------------------------------------
@Override
public int read() throws IOException {
if (pos < len)
return buffer[pos++];
len = in.read(buffer);
if (len == -1)
return len;
pos = 0;
if (len <= 0)
return -1;
return buffer[pos++];
}
}
public static void setStandardIO() {
in = new SimpleBufferedInputStream(System.in);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}
public static void setFileIO(String fileName) throws IOException {
in = new SimpleBufferedInputStream(new FileInputStream(fileName + ".in"));
out = new PrintWriter(new BufferedWriter(new FileWriter(fileName + ".out")));
}
public static int skipWhitespaces() throws IOException {
int c;
for (;;) {
c = in.read();
if (c == -1) throw new IOException();
if (!isWhitespace(c)) break;
}
return c;
}
public static int skipNewLines() throws IOException {
int c;
for (;;) {
c = in.read();
if (c == -1) throw new IOException();
if (!isNewLine(c)) break;
}
return c;
}
public static boolean isNewLine(int c) {
return c == '\n' || c == '\r' ? true : false;
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' ? true : false;
}
public static int nextNoWhitespace() throws IOException {
int c = in.read();
if (c == -1 || isWhitespace(c)) return -1;
return c;
}
public static int nextNoNewLine() throws IOException {
int c = in.read();
if (c == -1 || isNewLine(c)) return -1;
return c;
}
public static long nextLong() throws IOException {
int c;
for (;;) {
c = in.read();
if (!isWhitespace(c)) break;
if (c == -1) throw new RuntimeException();
}
boolean neg = false;
long val = 0;
if (c == '-')
neg = true;
else
val = c - '0';
for (;;) {
c = in.read();
if (isWhitespace(c) || c == -1)
break;
val = val * 10 + (c - '0');
}
if (neg)
return -val;
return val;
}
public static int nextInt() throws IOException {
int c;
for (;;) {
c = in.read();
if (!isWhitespace(c)) break;
if (c == -1) throw new RuntimeException();
}
boolean neg = false;
int val = 0;
if (c == '-')
neg = true;
else
val = c - '0';
for (;;) {
c = in.read();
if (isWhitespace(c) || c == -1)
break;
val = val * 10 + (c - '0');
}
if (neg)
return -val;
return val;
}
public static byte nextByte() throws IOException {
return (byte) nextInt();
}
public static String nextLine() throws IOException {
int c = (char) skipNewLines();
StringBuilder sb = new StringBuilder();
sb.append((char) c);
for (;;) {
c = nextNoNewLine();
if (c == -1)
break;
sb.append((char) c);
}
return sb.toString();
}
public static String nextString() throws IOException {
int c = (char) skipWhitespaces();
StringBuilder sb = new StringBuilder();
sb.append((char) c);
for (;;) {
c = nextNoWhitespace();
if (c == -1)
break;
sb.append((char) c);
}
return sb.toString();
}
public static double nextDouble() throws IOException {
return Double.parseDouble(nextString());
}
public static BigDecimal nextBigDecimal() throws IOException {
return new BigDecimal(nextString());
}
public static void flush() {
out.flush();
}
public static void println(Object object) {
out.println(object);
}
public static void print(Object object) {
out.print(object);
}
public static void println(double d, int precision) {
String s = "%1$." + precision + "f";
out.format(Locale.ENGLISH, s, d);
out.println();
}
public static void println(BigDecimal d, int precision) {
String s = "%1$." + precision + "f";
out.format(Locale.ENGLISH, s, d);
out.println();
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 92557fa3166ef852e94b5645871991e8 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws Exception {
new A().solve();
}
void solve() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
String[] sp = in.readLine().split(" ");
int minIdx = 0;
int min = Integer.MAX_VALUE;
int count = 0;
for (int i = 0; i < n; i++) {
int t = Integer.parseInt(sp[i]);
if (min > t) {
min = t;
count = 1;
minIdx = i;
} else if (min == t) {
count++;
}
}
if (count == 1) {
System.out.println((minIdx + 1));
} else {
System.out.println("Still Rozdil");
}
}
}
//
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 39e44b2c7a9f5cba05d815937197217f | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
import java.io.*;
public class AContest129{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int times=Integer.parseInt(br.readLine());
String[] in=br.readLine().split(" ");
long[] arr=new long[times];
for(int i=0;i<in.length;i++)
arr[i]=Long.parseLong(in[i]);
Arrays.sort(arr);
if(arr.length>1 && arr[0] == arr[1])
System.out.println("Still Rozdil");
else{
for(int i=0;i<in.length;i++){
if(in[i].equals(arr[0]+"")){
System.out.println(i+1);
}
}
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 16099556e211910b195bd91c8dd213bf | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.*;
public class RodzilElephant
{
public static void main(String[] args)
{
// Set up scanner
Scanner sc = new Scanner(System.in);
// System.out.println("Enter how many");
int n = sc.nextInt();
boolean doublemin = false;
// System.out.println("Enter first value");
int f = sc.nextInt();
int minsofar = f;
int answer = 1;
if (n==1)
{
System.out.println(1);
return;
}
// Loop over all other numbers
for (int i=2; i<=n; i++)
{
// System.out.println("Enter next value");
int x = sc.nextInt();
if (x < minsofar)
{
minsofar = x;
doublemin = false;
answer = i;
}
else if (x == minsofar)
{
doublemin = true;
}
}
if (doublemin == true)
{
System.out.println("Still Rozdil");
}
else
{
System.out.println(answer);
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 5c9329c50570d7f9542c86ecbf3ee4e9 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | /* package whatever; // 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 Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
double n = sc.nextDouble();
double min=1000000001,m;
int ctr=0,i,j=0;
for(i=0;i<n;i++)
{
m = sc.nextDouble();
if(m<min)
{
min=m;
ctr=0;
j=i;
}
else if(m==min)
{
ctr++;
}
}
if(ctr>0)
{
System.out.println("Still Rozdil");
}
else
{
System.out.println(j+1);
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 236fd491f7382366a1984031c2e49546 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package adream;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author sarah
*/
public class R129 {
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int tc = Integer.parseInt(sc.nextLine() );
String cities[] = sc.nextLine().split(" ");
if(tc == 1) {
System.out.println(1);
return;
}
LinkedList<String> org = new LinkedList<String>( Arrays.asList(cities) );
int[] ints = new int[cities.length];
for(int i = 0 ; i < tc ; i ++)
ints[i] = Integer.parseInt(cities[i]);
Arrays.sort(ints);
if(ints[0] == ints[1])
System.out.println("Still Rozdil");
else {
System.out.println(org.indexOf(""+ints[0]) + 1);
}
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 389fcc184b2d2c6b7043f6e2c647aeaa | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Scanner;
public class Elephant {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = Integer.MAX_VALUE;
int n = sc.nextInt();
int a, fin;
a = fin = 0;
boolean correcto = true;
for(int i=0; i<n; i++) {
a = sc.nextInt();
if(a < num1) {
num1 = a;
fin = i + 1;
correcto = true;
}
else if(a == num1) {
correcto = false;
}
}
if(correcto)
System.out.println(fin);
else
System.out.println("Still Rozdil");
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 766c0cf8275881b46685df8f461673ec | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.util.Scanner;
public class elehant {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int menor, cont = 0;
int pos = 0;
menor = s.nextInt();
int[] n1 = new int[n];
for (int i = 1; i < n; i++) {
n1[i] = s.nextInt();
if (n1[i] <= menor) {
if (menor == n1[i]) {
cont = 1;
} else {
cont = 0;
}
menor = n1[i];
pos = i;
}
}
if (cont != 1) {
System.out.println(pos + 1);
} else {
System.out.println("Still Rozdil");
}
}
} | Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | ea5f36754ab2842745454e353b54fce0 | train_000.jsonl | 1342020600 | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | 256 megabytes | import java.io.PrintStream;
import java.util.Scanner;
public class Main {
public static void main( String[] args ) {
new CodeForces_205A().doit();
}
}
class CodeForces_205A {
Scanner sc;
PrintStream ps;
public void doit() {
sc = new Scanner( System.in );
ps = System.out;
int n = sc.nextInt();
int res = Integer.MAX_VALUE, ans = -1, t = 0;
for ( int i = 0; i < n; i++ ) {
int temp = sc.nextInt();
if ( temp < res ) {
res = temp;
ans = i + 1;
t = 1;
}
else if ( temp == res ) {
t ++;
}
}
if ( t > 1 ) ps.println( "Still Rozdil" );
else ps.println( ans );
}
}
| Java | ["2\n7 4", "7\n7 4 47 100 4 9 12"] | 2 seconds | ["2", "Still Rozdil"] | NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | Java 6 | standard input | [
"implementation",
"brute force"
] | ce68f1171d9972a1b40b0450a05aa9cd | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities. | 900 | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | standard output | |
PASSED | 22420e63cf372c80397eb91f0adb18ce | train_000.jsonl | 1570957500 | There are $$$n$$$ chips arranged in a circle, numbered from $$$1$$$ to $$$n$$$. Initially each chip has black or white color. Then $$$k$$$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $$$i$$$, three chips are considered: chip $$$i$$$ itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip $$$i$$$ becomes white. Otherwise, the chip $$$i$$$ becomes black. Note that for each $$$i$$$ from $$$2$$$ to $$$(n - 1)$$$ two neighbouring chips have numbers $$$(i - 1)$$$ and $$$(i + 1)$$$. The neighbours for the chip $$$i = 1$$$ are $$$n$$$ and $$$2$$$. The neighbours of $$$i = n$$$ are $$$(n - 1)$$$ and $$$1$$$.The following picture describes one iteration with $$$n = 6$$$. The chips $$$1$$$, $$$3$$$ and $$$4$$$ are initially black, and the chips $$$2$$$, $$$5$$$ and $$$6$$$ are white. After the iteration $$$2$$$, $$$3$$$ and $$$4$$$ become black, and $$$1$$$, $$$5$$$ and $$$6$$$ become white. Your task is to determine the color of each chip after $$$k$$$ iterations. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author anand.oza
*/
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);
FChips solver = new FChips();
solver.solve(1, in, out);
out.close();
}
static class FChips {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(); // [3, 2e5]
int k = in.nextInt(); // [1, 1e9]
char[] input = in.next().toCharArray();
boolean[] white = new boolean[n];
for (int i = 0; i < n; i++) {
white[i] = input[i] == 'W';
}
UnionFind uf = new UnionFind(n);
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
if (white[i] == white[j]) {
uf.union(i, j);
}
}
if (uf.size(0) == n) {
out.println(printable(white));
return;
}
int offset = -1;
for (int i = 0; i < n; i++) {
if (uf.size(i) > 1 && uf.size((i + n - 1) % n) == 1) {
offset = i;
break;
}
}
if (offset == -1) {
if (k % 2 == 1) {
for (int i = 0; i < n; i++) {
white[i] ^= true;
}
}
out.println(printable(white));
return;
}
boolean[] offWhite = new boolean[n];
for (int i = 0; i < n; i++) {
offWhite[i] = white[(i + offset) % n];
}
int[] size = new int[n];
for (int i = 0; i < n; i++) {
size[i] = uf.size((i + offset) % n);
}
for (int i = 0, j = 0; i < n; i = j) {
while (j < n && size[i] == size[j])
j++;
if (size[i] > 1)
continue;
int left = (i + n - 1) % n;
int right = j % n;
for (int index = i; index < j; index++) {
int lDist = Math.abs(index - i);
int rDist = Math.abs(index - (j - 1));
if (lDist < k || rDist < k)
offWhite[index] = offWhite[lDist < rDist ? left : right];
else
offWhite[index] ^= (k % 2) == 1;
}
}
for (int i = 0; i < n; i++) {
white[i] = offWhite[(i + n - offset) % n];
}
out.println(printable(white));
}
private static String printable(boolean[] white) {
StringBuilder sb = new StringBuilder();
for (boolean x : white) {
sb.append(x ? 'W' : 'B');
}
return sb.toString();
}
}
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());
}
}
static class UnionFind {
private int[] __rep;
private int[] __size;
public UnionFind(int n) {
__rep = new int[n];
__size = new int[n];
for (int i = 0; i < n; i++) {
__rep[i] = i;
__size[i] = 1;
}
}
public int rep(int x) {
if (__rep[x] == x) {
return x;
}
int r = rep(__rep[x]);
__rep[x] = r;
return r;
}
public int size(int x) {
return __size[rep(x)];
}
public boolean union(int x, int y) {
x = rep(x);
y = rep(y);
if (x == y) {
return false;
}
if (size(x) < size(y)) {
int t = x;
x = y;
y = t;
}
// now size(x) >= size(y)
__rep[y] = x;
__size[x] += __size[y];
return true;
}
}
}
| Java | ["6 1\nBWBBWW", "7 3\nWBWBWBW", "6 4\nBWBWBW"] | 1 second | ["WBBBWW", "WWWWWWW", "BWBWBW"] | NoteThe first example is described in the statement.The second example: "WBWBWBW" $$$\rightarrow$$$ "WWBWBWW" $$$\rightarrow$$$ "WWWBWWW" $$$\rightarrow$$$ "WWWWWWW". So all chips become white.The third example: "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW". | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | 86d17fa4bac5edd0cc4b6bff1c9899b7 | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 200\,000, 1 \le k \le 10^{9})$$$ — the number of chips and the number of iterations, respectively. The second line contains a string consisting of $$$n$$$ characters "W" and "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th chip is white initially. If the $$$i$$$-th character is "B", then the $$$i$$$-th chip is black initially. | 2,300 | Print a string consisting of $$$n$$$ characters "W" and "B". If after $$$k$$$ iterations the $$$i$$$-th chip is white, then the $$$i$$$-th character should be "W". Otherwise the $$$i$$$-th character should be "B". | standard output | |
PASSED | 1e0c248b62e63b9ae405282b4472fdeb | train_000.jsonl | 1570957500 | There are $$$n$$$ chips arranged in a circle, numbered from $$$1$$$ to $$$n$$$. Initially each chip has black or white color. Then $$$k$$$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $$$i$$$, three chips are considered: chip $$$i$$$ itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip $$$i$$$ becomes white. Otherwise, the chip $$$i$$$ becomes black. Note that for each $$$i$$$ from $$$2$$$ to $$$(n - 1)$$$ two neighbouring chips have numbers $$$(i - 1)$$$ and $$$(i + 1)$$$. The neighbours for the chip $$$i = 1$$$ are $$$n$$$ and $$$2$$$. The neighbours of $$$i = n$$$ are $$$(n - 1)$$$ and $$$1$$$.The following picture describes one iteration with $$$n = 6$$$. The chips $$$1$$$, $$$3$$$ and $$$4$$$ are initially black, and the chips $$$2$$$, $$$5$$$ and $$$6$$$ are white. After the iteration $$$2$$$, $$$3$$$ and $$$4$$$ become black, and $$$1$$$, $$$5$$$ and $$$6$$$ become white. Your task is to determine the color of each chip after $$$k$$$ iterations. | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static class Task {
public String get(int[] input, int offset) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.length; i++) {
char truePos = input[(i + input.length - offset) % input.length] == 1 ? 'B': 'W';
sb.append(truePos);
}
return sb.toString();
}
public void solve(Scanner sc, PrintWriter pw) throws IOException {
int n = sc.nextInt();
int k = sc.nextInt();
int[] input = new int[n];
String s = sc.next();
for (int i = 0; i < n; i++) {
input[i] = s.charAt(i) == 'B' ? 1 : 0;
}
int offset = 0;
boolean hasDiff = false;
for (;offset < n;offset++) {
int cur = input[offset];
int next = input[(offset + 1) % n];
if (cur != next) {
hasDiff = true;
break;
}
}
if (!hasDiff) {
pw.println(get(input, 0));
return;
}
int[] shiftedInput = new int[n];
for (int i = 0; i < n; i++) {
shiftedInput[i] = input[(i + offset) % n];
}
boolean[] single = new boolean[n];
for (int i = 0; i < n; i++) {
if (shiftedInput[i] != shiftedInput[(i + n - 1) % n] && shiftedInput[(i + 1) % n] != shiftedInput[i]) {
single[i] = true;
}
}
boolean allSingle = true;
boolean allNotSingle = true;
for (int i = 0; i < n; i++) {
if (!single[i]) allSingle = false;
if (single[i]) allNotSingle = false;
}
if (allSingle) {
for (int i = 0; i < n; i++) {
shiftedInput[i] = k % 2 == 0 ? shiftedInput[i]: shiftedInput[i] ^ 1;
}
pw.println(get(shiftedInput, offset));
return;
}
if (allNotSingle) {
pw.println(get(shiftedInput, offset));
return;
}
for (int i = 0; i < n; i++) {
if (!single[i] && single[(i + 1) % n]) {
int startingPoint = i;
int prev = -1, end = -1;
for (int j = (i + 1) % n; j != startingPoint; j = (j + 1) % n) {
if (single[j]) {
if (prev == -1) {
prev = j;
end = j;
} else {
end = j;
}
} else {
if (prev != -1) {
int diff = (end + n - prev + 1) % n;
if (diff % 2 == 0) {
int lo = prev;
int hi = end;
int loColor = shiftedInput[lo] ^ 1;
int hiColor = shiftedInput[hi] ^ 1;
int y = k;
while (true) {
y--;
shiftedInput[lo] = loColor;
shiftedInput[hi] = hiColor;
if (lo == (hi + n - 1) % n) break;
if (y <= 0) {
loColor = loColor ^ 1;
hiColor = hiColor ^ 1;
}
lo = (lo + 1) % n;
hi = (hi + n - 1) % n;
}
} else {
int lo = prev;
int hi = end;
int color = shiftedInput[lo] ^ 1;
int y = k;
while (true) {
y--;
shiftedInput[lo] = color;
shiftedInput[hi] = color;
if (lo == hi) break;
if (y <= 0) color ^= 1;
lo = (lo + 1) % n;
hi = (hi + n - 1) % n;
}
}
}
prev = -1;
end = -1;
}
}
pw.println(get(shiftedInput, offset));
return;
}
}
}
}
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("input"));
PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
// PrintWriter pw = new PrintWriter(new FileOutputStream("output"));
Runtime runtime = Runtime.getRuntime();
long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
TIME_START = System.currentTimeMillis();
Task t = new Task();
t.solve(sc, pw);
TIME_END = System.currentTimeMillis();
long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
pw.close();
System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader s) throws FileNotFoundException {
br = new BufferedReader(s);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["6 1\nBWBBWW", "7 3\nWBWBWBW", "6 4\nBWBWBW"] | 1 second | ["WBBBWW", "WWWWWWW", "BWBWBW"] | NoteThe first example is described in the statement.The second example: "WBWBWBW" $$$\rightarrow$$$ "WWBWBWW" $$$\rightarrow$$$ "WWWBWWW" $$$\rightarrow$$$ "WWWWWWW". So all chips become white.The third example: "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW". | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | 86d17fa4bac5edd0cc4b6bff1c9899b7 | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 200\,000, 1 \le k \le 10^{9})$$$ — the number of chips and the number of iterations, respectively. The second line contains a string consisting of $$$n$$$ characters "W" and "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th chip is white initially. If the $$$i$$$-th character is "B", then the $$$i$$$-th chip is black initially. | 2,300 | Print a string consisting of $$$n$$$ characters "W" and "B". If after $$$k$$$ iterations the $$$i$$$-th chip is white, then the $$$i$$$-th character should be "W". Otherwise the $$$i$$$-th character should be "B". | standard output | |
PASSED | ff6d888bc7ef247f9acd0121a55c47ca | train_000.jsonl | 1570957500 | There are $$$n$$$ chips arranged in a circle, numbered from $$$1$$$ to $$$n$$$. Initially each chip has black or white color. Then $$$k$$$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $$$i$$$, three chips are considered: chip $$$i$$$ itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip $$$i$$$ becomes white. Otherwise, the chip $$$i$$$ becomes black. Note that for each $$$i$$$ from $$$2$$$ to $$$(n - 1)$$$ two neighbouring chips have numbers $$$(i - 1)$$$ and $$$(i + 1)$$$. The neighbours for the chip $$$i = 1$$$ are $$$n$$$ and $$$2$$$. The neighbours of $$$i = n$$$ are $$$(n - 1)$$$ and $$$1$$$.The following picture describes one iteration with $$$n = 6$$$. The chips $$$1$$$, $$$3$$$ and $$$4$$$ are initially black, and the chips $$$2$$$, $$$5$$$ and $$$6$$$ are white. After the iteration $$$2$$$, $$$3$$$ and $$$4$$$ become black, and $$$1$$$, $$$5$$$ and $$$6$$$ become white. Your task is to determine the color of each chip after $$$k$$$ iterations. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class F {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(reader.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
char[] b = reader.readLine().toCharArray();
boolean[] ost = new boolean[n];
long[] to = new long[n];
for(int i = 0; i < n; ++i){
to[i] = Integer.MAX_VALUE;
}
for(int i = 0; i < n; ++i){
if(b[i] == b[(i + n - 1) % n] || b[i] == b[(i + 1) % n]){
ost[i] = true;
}
}
for(int i = 2 * n; i >= 0; --i){
if(ost[i % n]) {
continue;
}
if(ost[(i + 1) % n]){
to[i % n] = 1;
}
else if(to[i % n] > to[(i + 1) % n] + 1){
to[i % n] = to[(i + 1) % n] + 1;
}
}
for(int i = 0 ; i <= 2 * n; ++i){
if(ost[i % n]) {
continue;
}
if(ost[(i - 1 + n) % n]){
to[i % n] = 1;
}
else if(to[i % n] > to[(i - 1 + n) % n] + 1){
to[i % n] = to[(i - 1 + n) % n] + 1;
}
}
for(int i = 0; i < n; ++i){
if(ost[i]){
writer.print(b[i]);
}
else if(to[i] <= k){
if(to[i] % 2 == 1){
if(b[i] == 'W'){
writer.print('B');
}
else{
writer.print('W');
}
}
else{
if(b[i] == 'W'){
writer.print('W');
}
else{
writer.print('B');
}
}
}
else{
if(k % 2 == 1){
if(b[i] == 'W'){
writer.print('B');
}
else{
writer.print('W');
}
}
else{
if(b[i] == 'W'){
writer.print('W');
}
else{
writer.print('B');
}
}
}
}
writer.close();
}
} | Java | ["6 1\nBWBBWW", "7 3\nWBWBWBW", "6 4\nBWBWBW"] | 1 second | ["WBBBWW", "WWWWWWW", "BWBWBW"] | NoteThe first example is described in the statement.The second example: "WBWBWBW" $$$\rightarrow$$$ "WWBWBWW" $$$\rightarrow$$$ "WWWBWWW" $$$\rightarrow$$$ "WWWWWWW". So all chips become white.The third example: "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW". | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | 86d17fa4bac5edd0cc4b6bff1c9899b7 | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 200\,000, 1 \le k \le 10^{9})$$$ — the number of chips and the number of iterations, respectively. The second line contains a string consisting of $$$n$$$ characters "W" and "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th chip is white initially. If the $$$i$$$-th character is "B", then the $$$i$$$-th chip is black initially. | 2,300 | Print a string consisting of $$$n$$$ characters "W" and "B". If after $$$k$$$ iterations the $$$i$$$-th chip is white, then the $$$i$$$-th character should be "W". Otherwise the $$$i$$$-th character should be "B". | standard output | |
PASSED | da2120b128705fb0b108abe1351650e2 | train_000.jsonl | 1570957500 | There are $$$n$$$ chips arranged in a circle, numbered from $$$1$$$ to $$$n$$$. Initially each chip has black or white color. Then $$$k$$$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $$$i$$$, three chips are considered: chip $$$i$$$ itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip $$$i$$$ becomes white. Otherwise, the chip $$$i$$$ becomes black. Note that for each $$$i$$$ from $$$2$$$ to $$$(n - 1)$$$ two neighbouring chips have numbers $$$(i - 1)$$$ and $$$(i + 1)$$$. The neighbours for the chip $$$i = 1$$$ are $$$n$$$ and $$$2$$$. The neighbours of $$$i = n$$$ are $$$(n - 1)$$$ and $$$1$$$.The following picture describes one iteration with $$$n = 6$$$. The chips $$$1$$$, $$$3$$$ and $$$4$$$ are initially black, and the chips $$$2$$$, $$$5$$$ and $$$6$$$ are white. After the iteration $$$2$$$, $$$3$$$ and $$$4$$$ become black, and $$$1$$$, $$$5$$$ and $$$6$$$ become white. Your task is to determine the color of each chip after $$$k$$$ iterations. | 256 megabytes | //package round592;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class F {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), K = ni();
char[] s = ns(n);
if(n % 2 == 0) {
boolean ok = s[0] != s[1];
for(int i = 0;i < n;i++) {
if(s[i] != s[i%2]) {
ok = false;
}
}
if(ok) {
if(K % 2 == 0) {
out.println(new String(s));
}else {
for(int i = 0;i < n;i++) {
s[i] = s[i] == 'B' ? 'W' : 'B';
}
out.println(new String(s));
}
return;
}
}
DJSet ds = new DJSet(n);
for(int i = 0;i < n;i++) {
if(s[i] == s[(i+1) %n]) {
ds.union(i, (i+1) % n);
}
}
// wbwbwb
// wwbwbb
// wBWb
// wWBb
// wBWBw
// wwbww
// wwwww
for(int i = 0;i < n;i++) {
if(ds.upper[ds.root(i)] == -1 && ds.upper[ds.root((i+n-1) % n)] != -1) {
int len = -1;
for(int j = 0;j < n;j++) {
if(ds.upper[ds.root((i+j) % n)] == -1) {
}else {
len = j;
break;
}
}
int lk = 0;
if(len % 2 == 0 && 2*K >= len) {
lk = Math.min(K, len/2);
}else {
lk = Math.min(K, len);
}
char l = s[(i+n-1) % n];
for(int j = 0;j < lk;j++) {
s[(i+j) % n] = l;
}
char r = s[(i+len) % n];
for(int j = 0;j < lk;j++) {
s[(i+len+n-1-j) % n] = r;
}
for(int j = lk;j < len-lk;j++) {
l = l == 'B' ? 'W' : 'B';
s[(i+j) % n] = l;
}
}
}
out.println(new String(s));
}
public static class DJSet {
public int[] upper;
public DJSet(int n) {
upper = new int[n];
Arrays.fill(upper, -1);
}
public int root(int x) {
return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
}
public boolean equiv(int x, int y) {
return root(x) == root(y);
}
public boolean union(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (upper[y] < upper[x]) {
int d = x;
x = y;
y = d;
}
upper[x] += upper[y];
upper[y] = x;
}
return x == y;
}
public int count() {
int ct = 0;
for (int u : upper)
if (u < 0)
ct++;
return ct;
}
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new F().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["6 1\nBWBBWW", "7 3\nWBWBWBW", "6 4\nBWBWBW"] | 1 second | ["WBBBWW", "WWWWWWW", "BWBWBW"] | NoteThe first example is described in the statement.The second example: "WBWBWBW" $$$\rightarrow$$$ "WWBWBWW" $$$\rightarrow$$$ "WWWBWWW" $$$\rightarrow$$$ "WWWWWWW". So all chips become white.The third example: "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW" $$$\rightarrow$$$ "WBWBWB" $$$\rightarrow$$$ "BWBWBW". | Java 8 | standard input | [
"constructive algorithms",
"implementation"
] | 86d17fa4bac5edd0cc4b6bff1c9899b7 | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 200\,000, 1 \le k \le 10^{9})$$$ — the number of chips and the number of iterations, respectively. The second line contains a string consisting of $$$n$$$ characters "W" and "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th chip is white initially. If the $$$i$$$-th character is "B", then the $$$i$$$-th chip is black initially. | 2,300 | Print a string consisting of $$$n$$$ characters "W" and "B". If after $$$k$$$ iterations the $$$i$$$-th chip is white, then the $$$i$$$-th character should be "W". Otherwise the $$$i$$$-th character should be "B". | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.